[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54199] trunk/blender/intern/ghost/intern: patch [#34039] Fix Alt key glitch on Unity desktop

Campbell Barton ideasman42 at gmail.com
Wed Jan 30 05:12:36 CET 2013


Revision: 54199
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54199
Author:   campbellbarton
Date:     2013-01-30 04:12:32 +0000 (Wed, 30 Jan 2013)
Log Message:
-----------
patch [#34039] Fix Alt key glitch on Unity desktop
by Shinsuke Irie (irie) with own minor changes.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
    trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2013-01-30 03:12:19 UTC (rev 54198)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2013-01-30 04:12:32 UTC (rev 54199)
@@ -72,6 +72,9 @@
 /* for debugging - so we can breakpoint X11 errors */
 // #define USE_X11_ERROR_HANDLERS
 
+/* see [#34039] Fix Alt key glitch on Unity desktop */
+#define USE_UNITY_WORKAROUND
+
 static GHOST_TKey convertXKey(KeySym key);
 
 /* these are for copy and select copy */
@@ -496,6 +499,46 @@
 
 			processEvent(&xevent);
 			anyProcessed = true;
+
+
+#ifdef USE_UNITY_WORKAROUND
+			/* note: processEvent() can't include this code because
+			 * KeymapNotify event have no valid window information. */
+
+			/* the X server generates KeymapNotify event immediately after
+			 * every EnterNotify and FocusIn event.  we handle this event
+			 * to correct modifier states. */
+			if ((xevent.type == FocusIn || xevent.type == EnterNotify)) {
+				/* use previous event's window, because KeymapNotify event
+				 * has no window information. */
+				GHOST_WindowX11 *window = findGhostWindow(xevent.xany.window);
+				if (window) {
+					XNextEvent(m_display, &xevent);
+
+					if (xevent.type == KeymapNotify) {
+						/* XK_Hyper_L/R currently unused */
+						const static KeySym modifiers[8] = {XK_Shift_L, XK_Shift_R,
+						                                    XK_Control_L, XK_Control_R,
+						                                    XK_Alt_L, XK_Alt_R,
+						                                    XK_Super_L, XK_Super_R};
+
+						for (int i = 0; i < (sizeof(modifiers) / sizeof(*modifiers)); i++) {
+							KeyCode kc = XKeysymToKeycode(m_display, modifiers[i]);
+							if (((xevent.xkeymap.key_vector[kc >> 3] >> (kc & 7)) & 1) != 0) {
+								pushEvent(new GHOST_EventKey(
+								              getMilliSeconds(),
+								              GHOST_kEventKeyDown,
+								              window,
+								              convertXKey(modifiers[i]),
+								              '\0',
+								              NULL));
+							}
+						}
+					}
+				}
+			}
+#endif  /* USE_UNITY_WORKAROUND */
+
 		}
 		
 		if (generateWindowExposeEvents()) {

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2013-01-30 03:12:19 UTC (rev 54198)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2013-01-30 04:12:32 UTC (rev 54199)
@@ -266,15 +266,14 @@
 	/* Specify which events we are interested in hearing. */
 
 	xattributes.event_mask =
-	    ExposureMask | StructureNotifyMask |
-	    KeyPressMask | KeyReleaseMask |
-	    EnterWindowMask | LeaveWindowMask |
-	    ButtonPressMask | ButtonReleaseMask |
-	    PointerMotionMask | FocusChangeMask | PropertyChangeMask;
+	        ExposureMask | StructureNotifyMask |
+	        KeyPressMask | KeyReleaseMask |
+	        EnterWindowMask | LeaveWindowMask |
+	        ButtonPressMask | ButtonReleaseMask |
+	        PointerMotionMask | FocusChangeMask |
+	        PropertyChangeMask | KeymapStateMask;
 
 	/* create the window! */
-
-	;
 	if (parentWindow == 0) {
 		m_window =  XCreateWindow(m_display,
 		                          RootWindow(m_display, m_visual->screen),
@@ -508,7 +507,7 @@
 	             EnterWindowMask | LeaveWindowMask |
 	             ButtonPressMask | ButtonReleaseMask |
 	             PointerMotionMask | FocusChangeMask |
-	             PropertyChangeMask | fevent);
+	             PropertyChangeMask | KeymapStateMask | fevent);
 	return true;
 }
 #endif




More information about the Bf-blender-cvs mailing list