[Bf-blender-cvs] [31c99c0c4e4] master: Fix pen tablet stuck on Windows for some non-Wacom tablets.

Colby Klein noreply at git.blender.org
Sun Aug 26 23:59:20 CEST 2018


Commit: 31c99c0c4e4d3edf3d18a44c1da01d6ac15994bd
Author: Colby Klein
Date:   Sun Aug 26 23:16:43 2018 +0200
Branches: master
https://developer.blender.org/rB31c99c0c4e4d3edf3d18a44c1da01d6ac15994bd

Fix pen tablet stuck on Windows for some non-Wacom tablets.

Differential Revision: https://developer.blender.org/D3573

===================================================================

M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 1e0c17f8b72..ae4aae380c5 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1248,7 +1248,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
 					 * will not be dispatched to OUR active window if we minimize one of OUR windows. */
 					if (LOWORD(wParam) == WA_INACTIVE)
 						window->lostMouseCapture();
-
+					window->processWin32TabletActivateEvent(GET_WM_ACTIVATE_STATE(wParam, lParam));
 					lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
 					break;
 				}
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index 6e89299e1ca..92de41a859b 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -265,23 +265,22 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
 		GHOST_WIN32_WTInfo fpWTInfo = (GHOST_WIN32_WTInfo) ::GetProcAddress(m_wintab, "WTInfoA");
 		GHOST_WIN32_WTOpen fpWTOpen = (GHOST_WIN32_WTOpen) ::GetProcAddress(m_wintab, "WTOpenA");
 
-		// let's see if we can initialize tablet here
-		/* check if WinTab available. */
-		if (fpWTInfo && fpWTInfo(0, 0, NULL)) {
+		// Let's see if we can initialize tablet here.
+		// Check if WinTab available by getting system context info.
+		LOGCONTEXT lc = { 0 };
+		lc.lcOptions |= CXO_SYSTEM;
+		if (fpWTInfo && fpWTInfo(WTI_DEFSYSCTX, 0, &lc)) {
 			// Now init the tablet
-			LOGCONTEXT lc;
 			/* The maximum tablet size, pressure and orientation (tilt) */
 			AXIS TabletX, TabletY, Pressure, Orientation[3];
 
 			// Open a Wintab context
 
-			// Get default context information
-			fpWTInfo(WTI_DEFCONTEXT, 0, &lc);
-
 			// Open the context
 			lc.lcPktData = PACKETDATA;
 			lc.lcPktMode = PACKETMODE;
-			lc.lcOptions |= CXO_MESSAGES | CXO_SYSTEM;
+			lc.lcOptions |= CXO_MESSAGES;
+			lc.lcMoveMask = PACKETDATA;
 
 			/* Set the entire tablet as active */
 			fpWTInfo(WTI_DEVICES, DVC_X, &TabletX);
@@ -309,11 +308,17 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
 			}
 
 			if (fpWTOpen) {
-				m_tablet = fpWTOpen(m_hWnd, &lc, TRUE);
+				// The Wintab spec says we must open the context disabled if we are using cursor masks.
+				m_tablet = fpWTOpen(m_hWnd, &lc, FALSE);
 				if (m_tablet) {
 					m_tabletData = new GHOST_TabletData();
 					m_tabletData->Active = GHOST_kTabletModeNone;
 				}
+
+				GHOST_WIN32_WTEnable fpWTEnable = (GHOST_WIN32_WTEnable) ::GetProcAddress(m_wintab, "WTEnable");
+				if (fpWTEnable) {
+					fpWTEnable(m_tablet, TRUE);
+				}
 			}
 		}
 	}
@@ -857,6 +862,23 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCursorShape(GHOST_TStandardCursor cur
 	return GHOST_kSuccess;
 }
 
+void GHOST_WindowWin32::processWin32TabletActivateEvent(WORD state)
+{
+	if (!m_tablet) {
+		return;
+	}
+
+	GHOST_WIN32_WTEnable fpWTEnable = (GHOST_WIN32_WTEnable) ::GetProcAddress(m_wintab, "WTEnable");
+	GHOST_WIN32_WTOverlap fpWTOverlap = (GHOST_WIN32_WTOverlap) ::GetProcAddress(m_wintab, "WTOverlap");
+
+	if (fpWTEnable) {
+		fpWTEnable(m_tablet, state);
+		if (fpWTOverlap && state) {
+			fpWTOverlap(m_tablet, TRUE);
+		}
+	}
+}
+
 void GHOST_WindowWin32::processWin32TabletInitEvent()
 {
 	if (m_wintab && m_tabletData) {
diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h
index d998e86c9b1..c72669ed898 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.h
+++ b/intern/ghost/intern/GHOST_WindowWin32.h
@@ -56,6 +56,7 @@ typedef UINT (API * GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID);
 typedef HCTX (API * GHOST_WIN32_WTOpen)(HWND, LPLOGCONTEXTA, BOOL);
 typedef BOOL (API * GHOST_WIN32_WTClose)(HCTX);
 typedef BOOL (API * GHOST_WIN32_WTPacket)(HCTX, UINT, LPVOID);
+typedef BOOL (API * GHOST_WIN32_WTEnable)(HCTX, BOOL);
 typedef BOOL (API * GHOST_WIN32_WTOverlap)(HCTX, BOOL);
 
 // typedefs for user32 functions to allow dynamic loading of Windows 10 DPI scaling functions
@@ -249,6 +250,7 @@ public:
 		return m_tabletData;
 	}
 
+	void processWin32TabletActivateEvent(WORD state);
 	void processWin32TabletInitEvent();
 	void processWin32TabletEvent(WPARAM wParam, LPARAM lParam);
 	void bringTabletContextToFront();



More information about the Bf-blender-cvs mailing list