xserver: Branch 'master' - 3 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Tue Sep 29 00:35:01 PDT 2009


 hw/xquartz/X11Controller.m            |    4 -
 hw/xquartz/mach-startup/bundle-main.c |   82 +++++++++++++-----------
 hw/xquartz/quartzKeyboard.c           |  113 +++++++++++++++-------------------
 3 files changed, 98 insertions(+), 101 deletions(-)

New commits:
commit f11a356bcef1bc0a6440325019d5967b745a42dd
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Sep 28 17:05:29 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 d36d967..ea0ebe5 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -280,98 +280,89 @@ 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, CARD8 *modmap) {
-    DeviceIntPtr pDev;
-
-    for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
-        if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key)
-            XkbApplyMappingChange(pDev, keySyms, keySyms->minKeyCode,
-                                  keySyms->maxKeyCode - keySyms->minKeyCode + 1,
-                                  modmap, serverClient);
-}
-
-/*
  * DarwinKeyboardInit
  *      Get the Darwin keyboard map and compute an equivalent
  *      X keyboard map and modifier map. Set the new keyboard
  *      device structure.
  */
 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
     // for a kIOHIDParamConnectType connection.
     assert(darwinParamConnect = NXOpenEventStatus());
 
-    bzero(&names, sizeof(names));
-
     /* We need to really have rules... or something... */
     //XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
 
     InitKeyboardDeviceStruct(pDev, NULL, NULL, DarwinChangeKeyboardControl);
 
-    pthread_mutex_lock(&keyInfo_mutex);   
-    DarwinLoadKeyboardMapping(&keySyms);    
-    DarwinKeyboardSetDeviceKeyMap(&keySyms, keyInfo.modMap);
-    pthread_mutex_unlock(&keyInfo_mutex);
+    DarwinKeyboardReloadHandler();
 
-    /* Get our key repeat settings from GlobalPreferences */
-    (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
-    value = CFPreferencesGetAppIntegerValue(CFSTR("InitialKeyRepeat"), CFSTR(".GlobalPreferences"), &ok);
-    if(!ok)
-        value = 35;
+    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");
-//    if (pDev->key) {
-//        if (pDev->key->curKeySyms.map) xfree(pDev->key->curKeySyms.map);
-//        xfree(pDev->key);
-//    }
 
+    /* Get our key repeat settings from GlobalPreferences */
+    (void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
     
-    pthread_mutex_lock(&keyInfo_mutex);
-    DarwinLoadKeyboardMapping(&keySyms);
-    DarwinKeyboardSetDeviceKeyMap(&keySyms, keyInfo.modMap);
-    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 */
+        XkbApplyMappingChange(darwinKeyboard, &keySyms, keySyms.minKeyCode,
+                              keySyms.maxKeyCode - keySyms.minKeyCode + 1,
+                              keyInfo.modMap, serverClient);
+        DarwinKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue);
+
+        /* Apply the mappings to the core keyboard */
+        for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
+            if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
+                XkbApplyMappingChange(pDev, &keySyms, keySyms.minKeyCode,
+                                      keySyms.maxKeyCode - keySyms.minKeyCode + 1,
+                                      keyInfo.modMap, serverClient);
+                DarwinKeyboardSetRepeat(pDev, initialKeyRepeatValue, keyRepeatValue);    
+            }
+        }
+    } pthread_mutex_unlock(&keyInfo_mutex);
 }
 
 //-----------------------------------------------------------------------------
commit f3223c71cfc638e695981e527517d48ea00d124d
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 9b98b883227ed23d5470e8de689afeec4a0fd742
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