xserver: Branch 'xorg-server-1.4-apple' - 4 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Mon Dec 29 20:02:49 PST 2008


 hw/xquartz/X11Application.m |  112 +++++++++++++++++++++-----------------------
 1 file changed, 55 insertions(+), 57 deletions(-)

New commits:
commit e9963f1a4f4f12f253eae9d4f01694b6cabe35ad
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Dec 29 19:54:12 2008 -0800

    XQuartz: Better avoid stuck keys on context switches

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index f8dd458..90077fe 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -63,6 +63,9 @@ extern BOOL xpbproxy_init (void);
 #define ProximityIn    0
 #define ProximityOut   1
 
+/* Stuck modifier / button state... force release when we context switch */
+static NSEventType keyState[NUM_KEYCODES];
+
 int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
@@ -179,29 +182,37 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 
 - (void) activateX:(OSX_BOOL)state {
     /* Create a TSM document that supports full Unicode input, and
-	 have it activated while X is active */
+     have it activated while X is active */
     static TSMDocumentID x11_document;
-	DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
+    size_t i;
+    DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
     if (state) {
-		DarwinSendDDXEvent(kXquartzActivate, 0);
+        DarwinSendDDXEvent(kXquartzActivate, 0);
 
-		if (!_x_active) {
-			if (x11_document == 0) {
-				OSType types[1];
-				types[0] = kUnicodeDocument;
-				NewTSMDocument (1, types, &x11_document, 0);
-			}
+        if (!_x_active) {
+            if (x11_document == 0) {
+                OSType types[1];
+                types[0] = kUnicodeDocument;
+                NewTSMDocument (1, types, &x11_document, 0);
+            }
 
-			if (x11_document != 0)	ActivateTSMDocument (x11_document);
-		}
+            if (x11_document != 0)	ActivateTSMDocument (x11_document);
+        }
     } else {
-		DarwinSendDDXEvent(kXquartzDeactivate, 0);
 
-		if (_x_active && x11_document != 0)
-			DeactivateTSMDocument (x11_document);
-	}
+        DarwinUpdateModKeys(0);
+        for(i=0; i < NUM_KEYCODES; i++) {
+            if(keyState[i] == NSKeyDown)
+                DarwinSendKeyboardEvents(KeyRelease, i);
+        }
+        
+        DarwinSendDDXEvent(kXquartzDeactivate, 0);
 
-	_x_active = state;
+        if (_x_active && x11_document != 0)
+            DeactivateTSMDocument (x11_document);
+    }
+
+    _x_active = state;
 }
 
 - (void) became_key:(NSWindow *)win {
@@ -1126,7 +1137,12 @@ static inline int ensure_flag(int flags, int device_independent, int device_depe
                     DarwinSendDDXEvent(kXquartzReloadKeymap, 0);
                 }
             }
-            
+
+            /* Avoid stuck keys on context switch */
+            if(keyState[[e keyCode]] == [e type])
+                return;
+            keyState[[e keyCode]] = [e type];
+
             DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
             break;
             
commit bc13dda345f716bf4de9bfe4e1d85969263b60c2
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Dec 29 19:38:31 2008 -0800

    XQuartz: Workaround OSX VNC server bug for modifier key state
    
    A better approach which ensures we have a L modifier key down if we are told neither are down and atleast one is down... =/

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 2387d0d..f8dd458 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -921,6 +921,18 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
 @implementation X11Application (Private)
 extern int darwin_modifier_flags; // darwinEvents.c
 
+#ifdef NX_DEVICELCMDKEYMASK
+/* This is to workaround a bug in the VNC server where we sometimes see the L
+ * modifier and sometimes see no "side"
+ */
+static inline int ensure_flag(int flags, int device_independent, int device_dependents, int device_dependent_default) {
+    if( (flags & device_independent) &&
+       !(flags & device_dependents))
+        flags |= device_dependent_default;
+    return flags;
+}
+#endif
+
 - (void) sendX11NSEvent:(NSEvent *)e {
     NSRect screen;
     NSPoint location;
@@ -928,6 +940,7 @@ extern int darwin_modifier_flags; // darwinEvents.c
     int ev_button, ev_type;
     float pointer_x, pointer_y, pressure, tilt_x, tilt_y;
     DeviceIntPtr pDev;
+    int modifierFlags;
 
     /* convert location to be relative to top-left of primary display */
     location = [e locationInWindow];
@@ -949,12 +962,32 @@ extern int darwin_modifier_flags; // darwinEvents.c
     tilt_x = 0;
     tilt_y = 0;
     
+    modifierFlags = [e modifierFlags];
+    
+    /* These are the "only" modifier keys we care about */
+    modifierFlags &= (NX_COMMANDMASK | NX_CONTROLMASK | NX_ALTERNATEMASK | NX_SHIFTMASK |
+                      NX_SECONDARYFNMASK | NX_ALPHASHIFTMASK | NX_NUMERICPADMASK |
+                      NX_HELPMASK | NX_DEVICELCTLKEYMASK | NX_DEVICELSHIFTKEYMASK |
+                      NX_DEVICERSHIFTKEYMASK | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK |
+                      NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK | NX_DEVICERCTLKEYMASK);
+    
+#ifdef NX_DEVICELCMDKEYMASK
+    /* This is to workaround a bug in the VNC server where we sometimes see the L
+     * modifier and sometimes see no "side"
+     */
+    modifierFlags = ensure_flag(modifierFlags, NX_CONTROLMASK,   NX_DEVICELCTLKEYMASK   | NX_DEVICERCTLKEYMASK,     NX_DEVICELCTLKEYMASK);
+    modifierFlags = ensure_flag(modifierFlags, NX_SHIFTMASK,     NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK,   NX_DEVICELSHIFTKEYMASK);
+    modifierFlags = ensure_flag(modifierFlags, NX_COMMANDMASK,   NX_DEVICELCMDKEYMASK   | NX_DEVICERCMDKEYMASK,     NX_DEVICELCMDKEYMASK);
+    modifierFlags = ensure_flag(modifierFlags, NX_ALTERNATEMASK, NX_DEVICELALTKEYMASK   | NX_DEVICERALTKEYMASK,     NX_DEVICELALTKEYMASK);
+#endif
+
     /* We don't receive modifier key events while out of focus, and 3button
      * emulation mucks this up, so we need to check our modifier flag state
      * on every event... ugg
      */
-    if(darwin_modifier_flags != [e modifierFlags])
-        DarwinUpdateModKeys([e modifierFlags]);
+    
+    if(darwin_modifier_flags != modifierFlags)
+        DarwinUpdateModKeys(modifierFlags);
     
 	switch ([e type]) {
 		case NSLeftMouseDown:     ev_button=1; ev_type=ButtonPress;   goto handle_mouse;
commit 10c7441046ff5575dd9d8ad9e993af45a6813774
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Dec 29 19:12:21 2008 -0800

    Revert "XQuartz: Workaround OSX VNC server bug for modifier key state"
    
    This reverts commit cbb0a8a3fb3ac1131be7e6219bb912602bc9afc0.

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index ed41b3c..2387d0d 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -63,13 +63,6 @@ extern BOOL xpbproxy_init (void);
 #define ProximityIn    0
 #define ProximityOut   1
 
-/* workaround a bug in vnc for those hit by a bug in Remote Desktop on OSX */
-#define VNCMODIFIERBUGWORKAROUND 1 
-
-#ifdef VNCMODIFIERBUGWORKAROUND
-static NSEventType keyState[NUM_KEYCODES];
-#endif
-
 int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
@@ -186,40 +179,29 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 
 - (void) activateX:(OSX_BOOL)state {
     /* Create a TSM document that supports full Unicode input, and
-     * have it activated while X is active
-     */
+	 have it activated while X is active */
     static TSMDocumentID x11_document;
-#ifdef VNCMODIFIERBUGWORKAROUND
-    size_t i;
-#endif
-    DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
+	DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
     if (state) {
-        DarwinSendDDXEvent(kXquartzActivate, 0);
-        
-        if (!_x_active) {
-            if (x11_document == 0) {
-                OSType types[1];
-                types[0] = kUnicodeDocument;
-                NewTSMDocument (1, types, &x11_document, 0);
-            }
-            
-            if (x11_document != 0)	ActivateTSMDocument (x11_document);
-        }
+		DarwinSendDDXEvent(kXquartzActivate, 0);
+
+		if (!_x_active) {
+			if (x11_document == 0) {
+				OSType types[1];
+				types[0] = kUnicodeDocument;
+				NewTSMDocument (1, types, &x11_document, 0);
+			}
+
+			if (x11_document != 0)	ActivateTSMDocument (x11_document);
+		}
     } else {
-#ifdef VNCMODIFIERBUGWORKAROUND
-        DarwinUpdateModKeys(0);
-        for(i=0; i < NUM_KEYCODES; i++) {
-            if(keyState[i] == NSKeyDown)
-                DarwinSendKeyboardEvents(KeyRelease, i);
-        }
-#endif
-        DarwinSendDDXEvent(kXquartzDeactivate, 0);
-        
-        if (_x_active && x11_document != 0)
-            DeactivateTSMDocument (x11_document);
-    }
-    
-    _x_active = state;
+		DarwinSendDDXEvent(kXquartzDeactivate, 0);
+
+		if (_x_active && x11_document != 0)
+			DeactivateTSMDocument (x11_document);
+	}
+
+	_x_active = state;
 }
 
 - (void) became_key:(NSWindow *)win {
@@ -877,10 +859,7 @@ environment the next time you start X11?", @"Startup xinitrc dialog");
 
 void X11ApplicationMain (int argc, char **argv, char **envp) {
     NSAutoreleasePool *pool;
-#ifdef VNCMODIFIERBUGWORKAROUND
-    size_t i;
-#endif
-    
+
 #ifdef DEBUG
     while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
 #endif
@@ -897,12 +876,6 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
 					selector:@selector (became_key:)
 					name:NSWindowDidBecomeKeyNotification object:nil];
 
-#ifdef VNCMODIFIERBUGWORKAROUND
-    for(i=0; i < NUM_KEYCODES; i++) {
-        keyState[i] = NSKeyUp;
-    }
-#endif
-
     /*
      * The xpr Quartz mode is statically linked into this server.
      * Initialize all the Quartz functions.
@@ -975,16 +948,14 @@ extern int darwin_modifier_flags; // darwinEvents.c
     pressure = 0;
     tilt_x = 0;
     tilt_y = 0;
-
-#ifndef VNCMODIFIERBUGWORKAROUND
+    
     /* We don't receive modifier key events while out of focus, and 3button
      * emulation mucks this up, so we need to check our modifier flag state
      * on every event... ugg
      */
     if(darwin_modifier_flags != [e modifierFlags])
         DarwinUpdateModKeys([e modifierFlags]);
-#endif
-
+    
 	switch ([e type]) {
 		case NSLeftMouseDown:     ev_button=1; ev_type=ButtonPress;   goto handle_mouse;
 		case NSOtherMouseDown:    ev_button=2; ev_type=ButtonPress;   goto handle_mouse;
@@ -1122,20 +1093,10 @@ extern int darwin_modifier_flags; // darwinEvents.c
                     DarwinSendDDXEvent(kXquartzReloadKeymap, 0);
                 }
             }
-
-#ifdef VNCMODIFIERBUGWORKAROUND
-            keyState[[e keyCode]] == [e type];
-#endif
-
+            
             DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
             break;
-
-#ifdef VNCMODIFIERBUGWORKAROUND
-        case NSFlagsChanged:
-            DarwinUpdateModKeys([e modifierFlags]);
-            break;
-#endif
-
+            
         default: break; /* for gcc */
 	}	
 }
commit 963aeee80aaebd5a87fd933746dda6a2cb1606e7
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Dec 29 19:12:08 2008 -0800

    Revert "XQuartz: Enable a defaults option to toggle off the vnc bug workaround"
    
    This reverts commit 4af2acc5fd7d55bc7aece69b426f055cdc2b619f.

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 990c008..ed41b3c 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -67,7 +67,6 @@ extern BOOL xpbproxy_init (void);
 #define VNCMODIFIERBUGWORKAROUND 1 
 
 #ifdef VNCMODIFIERBUGWORKAROUND
-static BOOL vncModifierBugWorkaround = YES;
 static NSEventType keyState[NUM_KEYCODES];
 #endif
 
@@ -208,12 +207,10 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
         }
     } else {
 #ifdef VNCMODIFIERBUGWORKAROUND
-        if(vncModifierBugWorkaround) {
-            DarwinUpdateModKeys(0);
-            for(i=0; i < NUM_KEYCODES; i++) {
-                if(keyState[i] == NSKeyDown)
-                    DarwinSendKeyboardEvents(KeyRelease, i);
-            }
+        DarwinUpdateModKeys(0);
+        for(i=0; i < NUM_KEYCODES; i++) {
+            if(keyState[i] == NSKeyDown)
+                DarwinSendKeyboardEvents(KeyRelease, i);
         }
 #endif
         DarwinSendDDXEvent(kXquartzDeactivate, 0);
@@ -697,11 +694,7 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
 {
     NSString *nsstr;
     const char *tem;
-
-#ifdef VNCMODIFIERBUGWORKAROUND
-    vncModifierBugWorkaround = [self prefs_get_boolean:@"vncModifierBugWorkaround" default:vncModifierBugWorkaround];
-#endif
-    
+	
     quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
                                        default:quartzUseSysBeep];
     quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
@@ -905,10 +898,8 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
 					name:NSWindowDidBecomeKeyNotification object:nil];
 
 #ifdef VNCMODIFIERBUGWORKAROUND
-    if(vncModifierBugWorkaround) {
-        for(i=0; i < NUM_KEYCODES; i++) {
-            keyState[i] = NSKeyUp;
-        }
+    for(i=0; i < NUM_KEYCODES; i++) {
+        keyState[i] = NSKeyUp;
     }
 #endif
 
@@ -985,15 +976,14 @@ extern int darwin_modifier_flags; // darwinEvents.c
     tilt_x = 0;
     tilt_y = 0;
 
+#ifndef VNCMODIFIERBUGWORKAROUND
     /* We don't receive modifier key events while out of focus, and 3button
      * emulation mucks this up, so we need to check our modifier flag state
      * on every event... ugg
      */
-#ifdef VNCMODIFIERBUGWORKAROUND
-    if(!vncModifierBugWorkaround)
-#endif
     if(darwin_modifier_flags != [e modifierFlags])
         DarwinUpdateModKeys([e modifierFlags]);
+#endif
 
 	switch ([e type]) {
 		case NSLeftMouseDown:     ev_button=1; ev_type=ButtonPress;   goto handle_mouse;
@@ -1134,8 +1124,7 @@ extern int darwin_modifier_flags; // darwinEvents.c
             }
 
 #ifdef VNCMODIFIERBUGWORKAROUND
-            if(vncModifierBugWorkaround)
-                keyState[[e keyCode]] == [e type];
+            keyState[[e keyCode]] == [e type];
 #endif
 
             DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
@@ -1143,8 +1132,7 @@ extern int darwin_modifier_flags; // darwinEvents.c
 
 #ifdef VNCMODIFIERBUGWORKAROUND
         case NSFlagsChanged:
-            if(vncModifierBugWorkaround)
-                DarwinUpdateModKeys([e modifierFlags]);
+            DarwinUpdateModKeys([e modifierFlags]);
             break;
 #endif
 


More information about the xorg-commit mailing list