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

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Mon Sep 28 23:51:40 PDT 2009


 hw/xquartz/X11Controller.m            |    4 -
 hw/xquartz/darwinEvents.c             |    6 +
 hw/xquartz/mach-startup/bundle-main.c |   82 +++++++++++----------
 hw/xquartz/quartzKeyboard.c           |  129 +++++++++++++++++-----------------
 hw/xquartz/quartzKeyboard.h           |    2 
 5 files changed, 119 insertions(+), 104 deletions(-)

New commits:
commit 0ef85c8ef3aff3b71a4d523c825c2fd140ba2623
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 23:51:22 2009 -0700

    XQuartz: Cleaned up keymap setting for easier maintenance
    (cherry picked from commit b9dfed9e88389cbd29406a20d38ee4297638649b)

diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index ffbe3f6..2c5e7cd 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -280,46 +280,6 @@ static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
 }
 
 /*
- * DarwinLoadKeyboardMapping
- *  Load the keyboard map from a file or system and convert
- *  it to an equivalent X keyboard map and modifier map.
- */
-static void DarwinLoadKeyboardMapping(KeySymsRec *keySyms) {    
-    DarwinBuildModifierMaps(&keyInfo);
-
-    keySyms->map        = keyInfo.keyMap;
-    keySyms->mapWidth   = GLYPHS_PER_KEY;
-    keySyms->minKeyCode = MIN_KEYCODE;
-    keySyms->maxKeyCode = MAX_KEYCODE;
-}
-
-/*
- * DarwinKeyboardSetDeviceKeyMap
- * Load a keymap into the keyboard device
- */
-static void DarwinKeyboardSetDeviceKeyMap(KeySymsRec *keySyms) {
-    DeviceIntPtr pDev;
-
-    /* From ProcSetModifierMapping */
-    SendMappingNotify(darwinKeyboard, MappingModifier, 0, 0, serverClient);
-    for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
-        if (pDev->key && pDev->coreEvents)
-            SendDeviceMappingNotify(serverClient, MappingModifier, 0, 0, pDev);
-    
-    /* From ProcChangeKeyboardMapping */
-    for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
-        if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key)
-            assert(SetKeySymsMap(&pDev->key->curKeySyms, keySyms));
-
-    SendMappingNotify(darwinKeyboard, MappingKeyboard, keySyms->minKeyCode,
-                      keySyms->maxKeyCode - keySyms->minKeyCode + 1, serverClient);
-    for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
-        if (pDev->key && pDev->coreEvents)
-            SendDeviceMappingNotify(serverClient, MappingKeyboard, keySyms->minKeyCode,
-                                    keySyms->maxKeyCode - keySyms->minKeyCode + 1, pDev);    
-}
-
-/*
  * DarwinKeyboardInit
  *      Get the Darwin keyboard map and compute an equivalent
  *      X keyboard map and modifier map. Set the new keyboard
@@ -328,8 +288,6 @@ static void DarwinKeyboardSetDeviceKeyMap(KeySymsRec *keySyms) {
 void DarwinKeyboardInit(DeviceIntPtr pDev) {
     KeySymsRec keySyms;
     XkbComponentNamesRec names;
-    CFIndex value;
-    BOOL ok;
 
     // Open a shared connection to the HID System.
     // Note that the Event Status Driver is really just a wrapper
@@ -342,43 +300,90 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) {
     //XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
 
     pthread_mutex_lock(&keyInfo_mutex);
+
+    /* Initialize our keySyms */
+    DarwinBuildModifierMaps(&keyInfo);
+    keySyms.map = keyInfo.keyMap;
+    keySyms.mapWidth   = GLYPHS_PER_KEY;
+    keySyms.minKeyCode = MIN_KEYCODE;
+    keySyms.maxKeyCode = MAX_KEYCODE;
     
-    DarwinLoadKeyboardMapping(&keySyms);    
     XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, keyInfo.modMap,
                                 NULL, DarwinChangeKeyboardControl);
     pthread_mutex_unlock(&keyInfo_mutex);
 
-    /* Get our key repeat settings from GlobalPreferences */
-    (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
-    value = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
-    if(!ok)
-        value = 35;
+    DarwinKeyboardReloadHandler();
+
+    CopyKeyClass(pDev, inputInfo.keyboard);
+}
 
-    if(value == 300000) { // off
+/* Set the repeat rates based on global preferences and keycodes for modifiers.
+ * Precondition: Has the keyInfo_mutex lock.
+ */
+static void DarwinKeyboardSetRepeat(DeviceIntPtr pDev, CFIndex initialKeyRepeatValue, CFIndex keyRepeatValue) {
+    if(initialKeyRepeatValue == 300000) { // off
         XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOff);
     } else {
-        pDev->key->xkbInfo->desc->ctrls->repeat_delay = value * 15;
-
-        value = CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
-        if(!ok)
-            value = 6;
-        pDev->key->xkbInfo->desc->ctrls->repeat_interval = value * 15;
+        pDev->key->xkbInfo->desc->ctrls->repeat_delay = initialKeyRepeatValue * 15;
+        pDev->key->xkbInfo->desc->ctrls->repeat_interval = keyRepeatValue * 15;
 
         XkbSetRepeatKeys(pDev, -1, AutoRepeatModeOn);
-    }
 
-    CopyKeyClass(pDev, inputInfo.keyboard);
+        /* TODO: Turn off key-repeat for modifier keys, on for others */
+        // Test: Shouldn't this turn off all the key repeats???
+        //for(i=MIN_KEYCODE; i <= MAX_KEYCODE; i++)
+        //    XkbSetRepeatKeys(pDev, i, AutoRepeatModeOff);
+    }
 }
 
 void DarwinKeyboardReloadHandler(void) {
     KeySymsRec keySyms;
+    CFIndex initialKeyRepeatValue, keyRepeatValue;
+    BOOL ok;
+    DeviceIntPtr pDev = darwinKeyboard;
 
     DEBUG_LOG("DarwinKeyboardReloadHandler\n");
+
+    /* Get our key repeat settings from GlobalPreferences */
+    (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
     
-    pthread_mutex_lock(&keyInfo_mutex);
-    DarwinLoadKeyboardMapping(&keySyms);
-    DarwinKeyboardSetDeviceKeyMap(&keySyms);
-    pthread_mutex_unlock(&keyInfo_mutex);
+    initialKeyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
+    if(!ok)
+        initialKeyRepeatValue = 35;
+    
+    keyRepeatValue = CFPreferencesGetAppIntegerValue(CFSTR("KeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
+    if(!ok)
+        keyRepeatValue = 6;
+    
+    pthread_mutex_lock(&keyInfo_mutex); {
+        /* Initialize our keySyms */
+        DarwinBuildModifierMaps(&keyInfo);
+        keySyms.map = keyInfo.keyMap;
+        keySyms.mapWidth   = GLYPHS_PER_KEY;
+        keySyms.minKeyCode = MIN_KEYCODE;
+        keySyms.maxKeyCode = MAX_KEYCODE;
+
+        /* Apply the mappings to darwinKeyboard */
+        SetKeySymsMap(&darwinKeyboard->key->curKeySyms, &keySyms);
+        memcpy(darwinKeyboard->key->modifierMap, keyInfo.modMap, sizeof(keyInfo.modMap));
+        DarwinKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue);
+        SendMappingNotify(darwinKeyboard, MappingKeyboard, keySyms.minKeyCode,
+                          keySyms.maxKeyCode - keySyms.minKeyCode + 1, serverClient);
+        SendDeviceMappingNotify(serverClient, MappingModifier, 0, 0, darwinKeyboard);
+        
+        /* Apply the mappings to the core keyboard */
+        for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
+            if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
+                SetKeySymsMap(&pDev->key->curKeySyms, &keySyms);
+                memcpy(pDev->key->modifierMap, keyInfo.modMap, sizeof(keyInfo.modMap));
+                DarwinKeyboardSetRepeat(pDev, initialKeyRepeatValue, keyRepeatValue);    
+                SendMappingNotify(pDev, MappingKeyboard, keySyms.minKeyCode,
+                                  keySyms.maxKeyCode - keySyms.minKeyCode + 1, serverClient);
+                SendDeviceMappingNotify(serverClient, MappingModifier, 0, 0, pDev);
+            }
+        }
+        XkbUpdateCoreDescription(darwinKeyboard, 0);
+    } pthread_mutex_unlock(&keyInfo_mutex);
 }
 
 //-----------------------------------------------------------------------------
commit 9604e0925aac3c535ddc5f670e850230d84c46f4
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 23:20:03 2009 -0700

    XQuartz: Push kXquartzReloadKeymap into DarwinEventHandler

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index c4ed57f..de2a60e 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -269,6 +269,10 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
                 DEBUG_LOG("kXquartzSpaceChanged\n");
                 QuartzSpaceChanged(xe[i].u.clientMessage.u.l.longs0);
                 break;
+                
+            case kXquartzReloadKeymap:
+                DarwinKeyboardReloadHandler();
+                break;
 
             default:
                 ErrorF("Unknown application defined event type %d.\n", xe[i].u.u.type);
@@ -321,7 +325,7 @@ Bool DarwinEQInit(void) {
     }
     
     mieqInit();
-    mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
+    mieqSetHandler(kXquartzReloadKeymap, DarwinEventHandler);
     mieqSetHandler(kXquartzActivate, DarwinEventHandler);
     mieqSetHandler(kXquartzDeactivate, DarwinEventHandler);
     mieqSetHandler(kXquartzReloadPreferences, DarwinEventHandler);
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 4a52df7..ffbe3f6 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -370,7 +370,7 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) {
     CopyKeyClass(pDev, inputInfo.keyboard);
 }
 
-void DarwinKeyboardReloadHandler(int screenNum, xEventPtr xe, DeviceIntPtr pDev, int nevents) {
+void DarwinKeyboardReloadHandler(void) {
     KeySymsRec keySyms;
 
     DEBUG_LOG("DarwinKeyboardReloadHandler\n");
diff --git a/hw/xquartz/quartzKeyboard.h b/hw/xquartz/quartzKeyboard.h
index 215a4a9..1aaec6e 100644
--- a/hw/xquartz/quartzKeyboard.h
+++ b/hw/xquartz/quartzKeyboard.h
@@ -53,7 +53,7 @@ Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info);
 /* Provided for darwinEvents.c */
 extern darwinKeyboardInfo keyInfo;
 extern pthread_mutex_t keyInfo_mutex;
-void DarwinKeyboardReloadHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents);
+void DarwinKeyboardReloadHandler(void);
 int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide);
 int DarwinModifierNXKeyToNXKeycode(int key, int side);
 int DarwinModifierNXKeyToNXMask(int key);
commit e60fbd976c2d2705e516950789283b5ab3c33189
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 23:01:59 2009 -0700

    XQuartz: Remove the redundant xquartz_resetenv_display
      unsetenv(DISPLAY) takes care of this for us anyway
    (cherry picked from commit d2263645d839c9edeedea0835d26f1f41b37f70e)

diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index d8d23ec..1191547 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -52,8 +52,6 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-BOOL xquartz_resetenv_display = NO;
-
 @implementation X11Controller
 
 - (void) awakeFromNib
@@ -353,7 +351,7 @@ BOOL xquartz_resetenv_display = NO;
     newargv[3] = NULL;
     
     s = getenv("DISPLAY");
-    if (xquartz_resetenv_display || s == NULL || s[0] == 0) {
+    if (s == NULL || s[0] == 0) {
         snprintf(buf, sizeof(buf), ":%s", display);
         setenv("DISPLAY", buf, TRUE);
     }
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 146ea11..691b555 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -62,8 +62,6 @@ void DarwinListenOnOpenFD(int fd);
 
 extern int noPanoramiXExtension;
 
-extern int xquartz_resetenv_display;
-
 #define DEFAULT_CLIENT X11BINDIR "/xterm"
 #define DEFAULT_STARTX X11BINDIR "/startx"
 #define DEFAULT_SHELL  "/bin/sh"
@@ -429,9 +427,6 @@ static int startup_trigger(int argc, char **argv, char **envp) {
     if((s = getenv("DISPLAY"))) {
         fprintf(stderr, "X11.app: Could not connect to server (DISPLAY=\"%s\", unsetting).  Starting X server.\n", s);
         unsetenv("DISPLAY");
-        
-        /* This tells X11Controller to not use the environment's DISPLAY and reset it based on the server's display */
-        xquartz_resetenv_display = 1;
     } else {
         fprintf(stderr, "X11.app: Could not connect to server (DISPLAY is not set).  Starting X server.\n");
     }
commit 30b5b180595ae6e90fdd14d9a6e77f909fdad904
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 17:47:31 2009 -0700

    XQuartz: Query the BundleIdentifier from the bundle in X11.bin rather than using the configure option.
    
    This lets X11.bin drop into any .app ... the Info.plist and Xquartz binary need to have it hardcoded still.
    (cherry picked from commit 9ad16b8e50b13eb6d0cd20386d07aa8d7320f671)

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 917bbaf..146ea11 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -80,7 +80,8 @@ const char *__crashreporter_info__base = "X.Org X Server " XSERVER_VERSION " Bui
 char __crashreporter_info__buf[4096];
 char *__crashreporter_info__ = __crashreporter_info__buf;
 
-static char *server_bootstrap_name = LAUNCHD_ID_PREFIX".X11";
+static char *launchd_id_prefix = NULL;
+static char *server_bootstrap_name = NULL;
 
 #define DEBUG 1
 
@@ -456,6 +457,7 @@ static void setup_env(void) {
     char *temp;
     const char *pds = NULL;
     const char *disp = getenv("DISPLAY");
+    size_t len;
 
     /* Pass on our prefs domain to startx and its inheritors (mainly for
      * quartz-wm and the Xquartz stub's MachIPC)
@@ -465,45 +467,56 @@ static void setup_env(void) {
         CFStringRef pd = CFBundleGetIdentifier(bundle);
         if(pd) {
             pds = CFStringGetCStringPtr(pd, 0);
-            if(pds) {
-                server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1));
-                strcpy(server_bootstrap_name, pds);
-                setenv("X11_PREFS_DOMAIN", pds, 1);
-            }
         }
     }
+
+    /* fallback to hardcoded value if we can't discover it */
+    if(!pds) {
+        pds = LAUNCHD_ID_PREFIX".X11";
+    }
+
+    server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1));
+    if(!server_bootstrap_name) {
+        fprintf(stderr, "Memory allocation error.\n");
+        exit(1);
+    }
+    strcpy(server_bootstrap_name, pds);
+    setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1);
+    
+    len = strlen(server_bootstrap_name);
+    launchd_id_prefix = malloc(sizeof(char) * (len - 3));
+    if(!launchd_id_prefix) {
+        fprintf(stderr, "Memory allocation error.\n");
+        exit(1);
+    }
+    strlcpy(launchd_id_prefix, server_bootstrap_name, len - 3);
+    
     /* We need to unset DISPLAY if it is not our socket */
     if(disp) {
-        if(!pds) {
-            /* If we can't detet our id, we are beyond hope and need to just
-             * revert to the non-launchd startup */
-            unsetenv("DISPLAY");
-        } else {
-            /* s = basename(disp) */
-            const char *d, *s;
+        /* s = basename(disp) */
+        const char *d, *s;
 	    for(s = NULL, d = disp; *d; d++) {
-                if(*d == '/')
-                     s = d + 1;
-            }
-
-            if(s && *s) {
-                size_t pds_len = strlen(pds);
-                temp = (char *)malloc(sizeof(char) * pds_len);
-                if(!temp) {
-                    fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
-                }
-                strlcpy(temp, pds, pds_len - 3);
-                strlcat(temp, ":0", pds_len);
+            if(*d == '/')
+                s = d + 1;
+        }
 
-                if(strcmp(temp, s) != 0) {
-                    /* If we don't have a match, unset it. */
-                    unsetenv("DISPLAY");
-                }
-                free(temp);
-            } else {
-                /* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */
+        if(s && *s) {
+            temp = (char *)malloc(sizeof(char) * len);
+            if(!temp) {
+                fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
+                exit(1);
+            }
+            strlcpy(temp, launchd_id_prefix, len);
+            strlcat(temp, ":0", len);
+            
+            if(strcmp(temp, s) != 0) {
+                /* If we don't have a match, unset it. */
                 unsetenv("DISPLAY");
             }
+            free(temp);
+        } else {
+            /* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */
+            unsetenv("DISPLAY");
         }
     }
 


More information about the xorg-commit mailing list