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

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Tue Sep 29 00:12:09 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           |    3 
 5 files changed, 119 insertions(+), 105 deletions(-)

New commits:
commit bc530267b73c76e4a2ad8dd446e38d63bba9b07a
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Tue Sep 29 00:11:42 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 efab616..d54782b 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -277,46 +277,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(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(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
@@ -325,8 +285,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
@@ -339,43 +297,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();
+
+    SwitchCoreKeyboard(pDev);
+}
 
-    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);
-    }
 
-    SwitchCoreKeyboard(pDev);   
+        /* 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(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(MappingKeyboard, keySyms.minKeyCode,
+                                  keySyms.maxKeyCode - keySyms.minKeyCode + 1, serverClient);
+                SendDeviceMappingNotify(serverClient, MappingModifier, 0, 0, pDev);
+            }
+        }
+        XkbUpdateCoreDescription(darwinKeyboard, 0);
+    } pthread_mutex_unlock(&keyInfo_mutex);
 }
 
 //-----------------------------------------------------------------------------
commit 35dfe0bd9a77b607800436b9ef326ba898bc4dc7
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 23:56:28 2009 -0700

    XQuartz: Push kXquartzReloadKeymap into DarwinEventHandler
    (cherry picked from commit 9604e0925aac3c535ddc5f670e850230d84c46f4)

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index e9c61d4..67d38cf 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -270,6 +270,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);
@@ -322,7 +326,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 d1758ea..efab616 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -367,7 +367,7 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) {
     SwitchCoreKeyboard(pDev);   
 }
 
-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 eb79366..1aaec6e 100644
--- a/hw/xquartz/quartzKeyboard.h
+++ b/hw/xquartz/quartzKeyboard.h
@@ -53,8 +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 DarwinKeyboardInit(DeviceIntPtr pDev);
+void DarwinKeyboardReloadHandler(void);
 int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide);
 int DarwinModifierNXKeyToNXKeycode(int key, int side);
 int DarwinModifierNXKeyToNXMask(int key);
commit 3218bc7eb53fea677751932fc54a3fe8cf268f24
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 f84dfcc..b95414e 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -53,8 +53,6 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-BOOL xquartz_resetenv_display = NO;
-
 @implementation X11Controller
 
 - (void) awakeFromNib
@@ -354,7 +352,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 828672ef0d11fa2aba52a2cbb2d3b485ea8a5ee3
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