diff --git a/krita/main.cc b/krita/main.cc --- a/krita/main.cc +++ b/krita/main.cc @@ -55,6 +55,7 @@ #include #include #include +#include #elif defined HAVE_X11 #include @@ -321,23 +322,42 @@ #if defined Q_OS_WIN { KisConfig cfg; - bool isUsingWin8PointerInput = false; + if (cfg.useWin8PointerInput() && !KisTabletSupportWin8::isAvailable()) { + cfg.setUseWin8PointerInput(false); + } + if (!cfg.useWin8PointerInput()) { + bool hasWinTab = KisTabletSupportWin::init(); + if (!hasWinTab) { + if (KisTabletSupportWin8::isPenDeviceAvailable()) { + // Use WinInk automatically + cfg.setUseWin8PointerInput(true); + } else if (!cfg.readEntry("WarnedAboutMissingWinTab", false)) { + if (KisTabletSupportWin8::isAvailable()) { + QMessageBox::information(nullptr, + i18n("Krita Tablet Support"), + i18n("Cannot load WinTab driver and no Windows Ink pen devices are found. If you have a drawing tablet, please make sure the tablet driver is properly installed."), + QMessageBox::Ok, QMessageBox::Ok); + } else { + QMessageBox::information(nullptr, + i18n("Krita Tablet Support"), + i18n("Cannot load WinTab driver. If you have a drawing tablet, please make sure the tablet driver is properly installed."), + QMessageBox::Ok, QMessageBox::Ok); + } + cfg.writeEntry("WarnedAboutMissingWinTab", true); + } + } + } if (cfg.useWin8PointerInput()) { KisTabletSupportWin8 *penFilter = new KisTabletSupportWin8(); if (penFilter->init()) { // penFilter.registerPointerDeviceNotifications(); app.installNativeEventFilter(penFilter); - isUsingWin8PointerInput = true; qDebug() << "Using Win8 Pointer Input for tablet support"; } else { qDebug() << "No Win8 Pointer Input available"; delete penFilter; } } - if (!isUsingWin8PointerInput) { - KisTabletSupportWin::init(); - // app.installNativeEventFilter(new KisTabletSupportWin()); - } } #endif @@ -365,4 +385,3 @@ return state; } - diff --git a/libs/ui/input/wintab/kis_tablet_support_win.h b/libs/ui/input/wintab/kis_tablet_support_win.h --- a/libs/ui/input/wintab/kis_tablet_support_win.h +++ b/libs/ui/input/wintab/kis_tablet_support_win.h @@ -26,7 +26,7 @@ class KRITAUI_EXPORT KisTabletSupportWin { public: - static void init(); + static bool init(); }; diff --git a/libs/ui/input/wintab/kis_tablet_support_win.cpp b/libs/ui/input/wintab/kis_tablet_support_win.cpp --- a/libs/ui/input/wintab/kis_tablet_support_win.cpp +++ b/libs/ui/input/wintab/kis_tablet_support_win.cpp @@ -162,11 +162,11 @@ QWindowsWinTab32DLL QWindowsTabletSupport::m_winTab32DLL; -void KisTabletSupportWin::init() +bool KisTabletSupportWin::init() { if (!QWindowsTabletSupport::m_winTab32DLL.init()) { qWarning() << "Failed to initialize Wintab"; - return; + return false; } QTAB = QWindowsTabletSupport::create(); @@ -177,6 +177,7 @@ delete QTAB; QTAB = QWindowsTabletSupport::create(); }); + return true; } diff --git a/libs/ui/input/wintab/kis_tablet_support_win8.h b/libs/ui/input/wintab/kis_tablet_support_win8.h --- a/libs/ui/input/wintab/kis_tablet_support_win8.h +++ b/libs/ui/input/wintab/kis_tablet_support_win8.h @@ -29,6 +29,7 @@ public: static bool isAvailable(); + static bool isPenDeviceAvailable(); KisTabletSupportWin8() = default; ~KisTabletSupportWin8() = default; diff --git a/libs/ui/input/wintab/kis_tablet_support_win8.cpp b/libs/ui/input/wintab/kis_tablet_support_win8.cpp --- a/libs/ui/input/wintab/kis_tablet_support_win8.cpp +++ b/libs/ui/input/wintab/kis_tablet_support_win8.cpp @@ -60,7 +60,7 @@ FUNC(GetPointerPenInfoHistory) \ FUNC(GetPointerType) \ /* Pointer Device Functions */ \ - /*FUNC(GetPointerDevices)*/ \ + FUNC(GetPointerDevices) \ /*FUNC(GetPointerDeviceProperties)*/ \ FUNC(GetPointerDevice) \ FUNC(GetPointerDeviceRects) \ @@ -340,6 +340,39 @@ return api.init(); } +bool KisTabletSupportWin8::isPenDeviceAvailable() +{ + if (!api.init()) { + return false; + } + UINT32 deviceCount = 0; + if (!api.GetPointerDevices(&deviceCount, nullptr)) { + dbgTablet << "GetPointerDevices failed"; + return false; + } + if (deviceCount == 0) { + dbgTablet << "No pointer devices"; + return false; + } + QVector devices(deviceCount); + if (!api.GetPointerDevices(&deviceCount, devices.data())) { + dbgTablet << "GetPointerDevices failed"; + return false; + } + bool hasPenDevice = false; + Q_FOREACH (const POINTER_DEVICE_INFO &device, devices) { + dbgTablet << "Found pointer device" << static_cast(device.device) + << QString::fromWCharArray(device.productString) + << "type:" << device.pointerDeviceType; + if (device.pointerDeviceType == POINTER_DEVICE_TYPE_INTEGRATED_PEN || + device.pointerDeviceType == POINTER_DEVICE_TYPE_EXTERNAL_PEN) { + hasPenDevice = true; + } + } + dbgTablet << "hasPenDevice:" << hasPenDevice; + return hasPenDevice; +} + bool KisTabletSupportWin8::init() { return api.init();