xserver: Branch 'master' - 8 commits

Daniel Stone daniels at kemper.freedesktop.org
Tue Apr 10 23:58:49 EEST 2007


 Xi/stubs.c                           |   12 ++++
 config/config.c                      |   29 +++++------
 dix/devices.c                        |   24 ++++++++-
 dix/getevents.c                      |   20 +++++++
 hw/kdrive/src/kinput.c               |    5 +
 hw/xfree86/common/xf86Config.c       |    6 +-
 hw/xfree86/common/xf86Configure.c    |   15 +++--
 hw/xfree86/common/xf86Helper.c       |    3 +
 hw/xfree86/common/xf86Option.c       |    4 -
 hw/xfree86/common/xf86Xinput.c       |   88 +++++++++++++++++++++++++++++------
 hw/xfree86/parser/Flags.c            |   28 +++++------
 hw/xfree86/utils/xorgcfg/text-mode.c |    4 -
 include/input.h                      |    2 
 mi/mieq.c                            |    2 
 14 files changed, 180 insertions(+), 62 deletions(-)

New commits:
diff-tree 4f05f9591e5492c72f3856bd7a2ff13378f59f2b (from 20674dcbb2373a0af287883bc008fb6fb23d4466)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:57:48 2007 +0300

    Input: Always add devices with first available ID
    
    Scan the device list when adding a new device, and make sure we can use
    the first available ID, instead of always incrementing.

diff --git a/dix/devices.c b/dix/devices.c
index 004cb13..c2d4f22 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -86,15 +86,27 @@ DeviceIntPtr
 AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 {
     DeviceIntPtr dev, *prev; /* not a typo */
+    DeviceIntPtr devtmp;
+    int devid;
+    char devind[MAX_DEVICES];
+
+    /* Find next available id */
+    memset(devind, 0, sizeof(char)*MAX_DEVICES);
+    for (devtmp = inputInfo.devices; devtmp; devtmp = devtmp->next)
+	devind[devtmp->id]++;
+    for (devtmp = inputInfo.off_devices; devtmp; devtmp = devtmp->next)
+	devind[devtmp->id]++;
+    for (devid = 0; devid < MAX_DEVICES && devind[devid]; devid++)
+	;
 
-    if (inputInfo.numDevices >= MAX_DEVICES)
+    if (devid >= MAX_DEVICES)
 	return (DeviceIntPtr)NULL;
     dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
     if (!dev)
 	return (DeviceIntPtr)NULL;
     dev->name = (char *)NULL;
     dev->type = 0;
-    dev->id = inputInfo.numDevices;
+    dev->id = devid;
     inputInfo.numDevices++;
     dev->public.on = FALSE;
     dev->public.processInputProc = (ProcessInputProc)NoopDDA;
@@ -572,6 +584,7 @@ RemoveDevice(DeviceIntPtr dev)
     }
     
     if (ret == Success) {
+        inputInfo.numDevices--;
         ev.type = DevicePresenceNotify;
         ev.time = currentTime.milliseconds;
         ev.devchange = 0;
diff-tree 20674dcbb2373a0af287883bc008fb6fb23d4466 (from 82962bbae2b4fda274625d1712ef839ce1ab9dc8)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:55:36 2007 +0300

    Config: Fix memory leaks
    
    Fix memory leaks that could occur along the error path.

diff --git a/config/config.c b/config/config.c
index b8d2428..aae5c6e 100644
--- a/config/config.c
+++ b/config/config.c
@@ -110,6 +110,11 @@ configAddDevice(DBusMessage *message, DB
 
     options->key = xstrdup("_source");
     options->value = xstrdup("client/dbus");
+    if(!options->key || !options->value) {
+        ErrorF("[config] couldn't allocate first key/value pair\n");
+        ret = BadAlloc;
+        goto unwind;
+    }
 
     while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY) {
         tmpo = (InputOption *) xcalloc(sizeof(InputOption), 1);
@@ -118,6 +123,8 @@ configAddDevice(DBusMessage *message, DB
             ret = BadAlloc;
             goto unwind;
         }
+        tmpo->next = options;
+        options = tmpo;
 
         dbus_message_iter_recurse(iter, &subiter);
 
@@ -132,8 +139,8 @@ configAddDevice(DBusMessage *message, DB
                    tmp);
             MALFORMED_MESSAGE();
         }
-        tmpo->key = xstrdup(tmp);
-        if (!tmpo->key) {
+        options->key = xstrdup(tmp);
+        if (!options->key) {
             ErrorF("[config] couldn't duplicate key!\n");
             ret = BadAlloc;
             goto unwind;
@@ -148,15 +155,13 @@ configAddDevice(DBusMessage *message, DB
         dbus_message_iter_get_basic(&subiter, &tmp);
         if (!tmp)
             MALFORMED_MESSAGE();
-        tmpo->value = xstrdup(tmp);
-        if (!tmpo->value) {
+        options->value = xstrdup(tmp);
+        if (!options->value) {
             ErrorF("[config] couldn't duplicate option!\n");
             ret = BadAlloc;
             goto unwind;
         }
 
-        tmpo->next = options;
-        options = tmpo;
         dbus_message_iter_next(iter);
     }
 
@@ -164,16 +169,8 @@ configAddDevice(DBusMessage *message, DB
     if (ret != Success)
         DebugF("[config] NewInputDeviceRequest failed\n");
 
-    return ret;
-
+    /* Fall through, must deallocate memory we've allocated */
 unwind:
-    if (tmpo->key)
-        xfree(tmpo->key);
-    if (tmpo->value)
-        xfree(tmpo->value);
-    if (tmpo)
-        xfree(tmpo);
-
     while (options) {
         tmpo = options;
         options = options->next;
diff-tree 82962bbae2b4fda274625d1712ef839ce1ab9dc8 (from 7b82a836c66ba88566255052caff63577e1a0384)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:54:32 2007 +0300

    Input: Add DeleteInputDeviceRequest
    
    Add DIDR, which asks the DDX to remove a device, analogous to
    NewInputDeviceRequest.  Only implemented for XFree86 at the moment.

diff --git a/Xi/stubs.c b/Xi/stubs.c
index ed041b8..d425fe9 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -230,3 +230,15 @@ NewInputDeviceRequest(InputOption *optio
 {
     return BadValue;
 }
+
+/****************************************************************************
+ *
+ * Caller: configRemoveDevice (and others)
+ *
+ * Remove the specified device previously added.
+ *
+ */
+void
+DeleteInputDeviceRequest(DeviceIntPtr dev)
+{
+}
diff --git a/config/config.c b/config/config.c
index d72b588..b8d2428 100644
--- a/config/config.c
+++ b/config/config.c
@@ -212,7 +212,7 @@ configRemoveDevice(DBusMessage *message,
      * already been removed. */
     OsBlockSignals();
     ProcessInputEvents();
-    RemoveDevice(pDev);
+    DeleteInputDeviceRequest(pDev);
     OsReleaseSignals();
 
     return Success;
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 857f04f..a9a743b 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -2374,3 +2374,8 @@ NewInputDeviceRequest(InputOption *optio
 
     return Success;
 }
+
+void
+DeleteInputDeviceRequest(DeviceIntPtr pDev)
+{
+}
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 913735b..e0b758f 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -371,8 +371,11 @@ xf86DeleteInput(InputInfoPtr pInp, int f
     if (pInp->drv)
 	pInp->drv->refCount--;
 
+    /* This should *really* be handled in drv->UnInit(dev) call instead */
+#if 0
     if (pInp->private)
 	xfree(pInp->private);
+#endif
 
     /* Remove the entry from the list. */
     if (pInp == xf86InputDevs)
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 3800d9a..f662c17 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -427,6 +427,26 @@ unwind:
     return rval;
 }
 
+void
+DeleteInputDeviceRequest(DeviceIntPtr pDev)
+{
+    LocalDevicePtr pInfo = (LocalDevicePtr) pDev->public.devicePrivate;
+    InputDriverPtr drv = pInfo->drv;
+    IDevRec *idev = pInfo->conf_idev;
+
+    RemoveDevice(pDev);
+
+    if(drv->UnInit)
+        drv->UnInit(drv, pInfo, 0);
+    else
+        xf86DeleteInput(pInfo, 0);
+
+    xfree(idev->driver);
+    xfree(idev->identifier);
+    xf86optionListFree(idev->commonOptions);
+    xfree(idev);
+}
+
 /* 
  * convenient functions to post events
  */
diff --git a/include/input.h b/include/input.h
index fc607d3..1e65709 100644
--- a/include/input.h
+++ b/include/input.h
@@ -446,6 +446,8 @@ extern DeviceIntPtr LookupDeviceIntRec(
 /* Implemented by the DDX. */
 extern int NewInputDeviceRequest(
     InputOption *options);
+extern void DeleteInputDeviceRequest(
+    DeviceIntPtr dev);
 
 extern void DDXRingBell(
     int volume,
diff-tree 7b82a836c66ba88566255052caff63577e1a0384 (from 4771fa8747791498e504d73afccfb5833499a38b)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:52:08 2007 +0300

    XFree86: Fix memory leaks, option parsing, in NewInputDeviceRequest
    
    Plugged some possible memory leaks, and added some more checks on the
    options, particular for driver/identifier.  Added an unwind.

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 17ffed8..3800d9a 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -322,6 +322,7 @@ NewInputDeviceRequest (InputOption *opti
     InputInfoPtr pInfo = NULL;
     InputOption *option = NULL;
     DeviceIntPtr dev = NULL;
+    int rval = Success;
 
     idev = xcalloc(sizeof(*idev), 1);
     if (!idev)
@@ -329,64 +330,101 @@ NewInputDeviceRequest (InputOption *opti
 
     for (option = options; option; option = option->next) {
         if (strcmp(option->key, "driver") == 0) {
-            if (!xf86LoadOneModule(option->value, NULL))
-                return BadName;
+            if (idev->driver) {
+                rval = BadRequest;
+                goto unwind;
+            }
+            /* Memory leak for every attached device if we don't
+             * test if the module is already loaded first */
             drv = xf86LookupInputDriver(option->value);
+            if (!drv)
+                if(xf86LoadOneModule(option->value, NULL))
+                    drv = xf86LookupInputDriver(option->value);
             if (!drv) {
                 xf86Msg(X_ERROR, "No input driver matching `%s'\n",
                         option->value);
-                return BadName;
+                rval = BadName;
+                goto unwind;
             }
             idev->driver = xstrdup(option->value);
             if (!idev->driver) {
-                xfree(idev);
-                return BadAlloc;
+                rval = BadAlloc;
+                goto unwind;
             }
         }
         if (strcmp(option->key, "name") == 0 ||
             strcmp(option->key, "identifier") == 0) {
+            if (idev->identifier) {
+                rval = BadRequest;
+                goto unwind;
+            }
             idev->identifier = xstrdup(option->value);
             if (!idev->identifier) {
-                xfree(idev);
-                return BadAlloc;
+                rval = BadAlloc;
+                goto unwind;
             }
         }
     }
+    if(!idev->driver || !idev->identifier) {
+        xf86Msg(X_ERROR, "No input driver/identifier specified (ignoring)\n");
+        rval = BadRequest;
+        goto unwind;
+    }
 
     if (!drv->PreInit) {
         xf86Msg(X_ERROR,
                 "Input driver `%s' has no PreInit function (ignoring)\n",
                 drv->driverName);
-        return BadImplementation;
+        rval = BadImplementation;
+        goto unwind;
     }
 
-    idev->commonOptions = NULL;
-    for (option = options; option; option = option->next)
+    for (option = options; option; option = option->next) {
+        /* Steal option key/value strings from the provided list.
+         * We need those strings, the InputOption list doesn't. */
         idev->commonOptions = xf86addNewOption(idev->commonOptions,
                                                option->key, option->value);
-    idev->extraOptions = NULL;
+        option->key = NULL;
+        option->value = NULL;
+    }
 
     pInfo = drv->PreInit(drv, idev, 0);
 
     if (!pInfo) {
         xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n", idev->identifier);
-        return BadMatch;
+        rval = BadMatch;
+        goto unwind;
     }
     else if (!(pInfo->flags & XI86_CONFIGURED)) {
         xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
                 idev->identifier);
-        xf86DeleteInput(pInfo, 0);
-        return BadMatch;
+        rval = BadMatch;
+        goto unwind;
     }
 
     xf86ActivateDevice(pInfo);
 
     dev = pInfo->dev;
-    dev->inited = ((*dev->deviceProc)(dev, DEVICE_INIT) == Success);
+    ActivateDevice(dev);
     if (dev->inited && dev->startup)
         EnableDevice(dev);
 
     return Success;
+
+unwind:
+    if(pInfo) {
+        if(drv->UnInit)
+            drv->UnInit(drv, pInfo, 0);
+        else
+            xf86DeleteInput(pInfo, 0);
+    }
+    if(idev->driver)
+        xfree(idev->driver);
+    if(idev->identifier)
+        xfree(idev->identifier);
+    xf86optionListFree(idev->commonOptions);
+    xfree(idev);
+    return rval;
 }
 
 /* 
diff-tree 4771fa8747791498e504d73afccfb5833499a38b (from 07c56abf84080c020a3e7b7703a447c7f996975c)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:48:00 2007 +0300

    XFree86: Fix memory leak in option parsing
    
    Fix option parsing functions and callers thereof to not leak memory.

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index cbeda0b..0421bf9 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1271,7 +1271,7 @@ checkCoreInputDevices(serverLayoutPtr se
 			      (count + 1) * sizeof(IDevRec));
 	    indp[count - 1] = Pointer;
 	    indp[count - 1].extraOptions =
-				xf86addNewOption(NULL, "CorePointer", NULL);
+				xf86addNewOption(NULL, xnfstrdup("CorePointer"), NULL);
 	    indp[count].identifier = NULL;
 	    servlayoutp->inputs = indp;
 	}
@@ -1310,7 +1310,7 @@ checkCoreInputDevices(serverLayoutPtr se
 			      (count + 1) * sizeof(IDevRec));
 	    indp[count - 1] = Pointer;
 	    indp[count - 1].extraOptions =
-				xf86addNewOption(NULL, "AlwaysCore", NULL);
+				xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), NULL);
 	    indp[count].identifier = NULL;
 	    servlayoutp->inputs = indp;
 	}
@@ -1401,7 +1401,7 @@ checkCoreInputDevices(serverLayoutPtr se
 			      (count + 1) * sizeof(IDevRec));
 	    indp[count - 1] = Keyboard;
 	    indp[count - 1].extraOptions =
-				xf86addNewOption(NULL, "CoreKeyboard", NULL);
+				xf86addNewOption(NULL, xnfstrdup("CoreKeyboard"), NULL);
 	    indp[count].identifier = NULL;
 	    servlayoutp->inputs = indp;
 	}
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index 4b482df..7b04bd6 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -309,13 +309,16 @@ configureInputSection (void)
     mouse->inp_identifier = "Mouse0";
     mouse->inp_driver = "mouse";
     mouse->inp_option_lst = 
-		xf86addNewOption(mouse->inp_option_lst, "Protocol", DFLT_MOUSE_PROTO);
+		xf86addNewOption(mouse->inp_option_lst, xstrdup("Protocol"),
+				xstrdup(DFLT_MOUSE_PROTO));
 #ifndef __SCO__
     mouse->inp_option_lst = 
-		xf86addNewOption(mouse->inp_option_lst, "Device", DFLT_MOUSE_DEV);
+		xf86addNewOption(mouse->inp_option_lst, xstrdup("Device"),
+				xstrdup(DFLT_MOUSE_DEV));
 #endif
     mouse->inp_option_lst = 
-		xf86addNewOption(mouse->inp_option_lst, "ZAxisMapping", "4 5 6 7");
+		xf86addNewOption(mouse->inp_option_lst, xstrdup("ZAxisMapping"),
+				xstrdup("4 5 6 7"));
     ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse);
     return ptr;
 }
@@ -519,7 +522,7 @@ configureLayoutSection (void)
 	iptr->iref_option_lst = NULL;
 	iptr->iref_inputdev_str = "Mouse0";
 	iptr->iref_option_lst =
-		xf86addNewOption (iptr->iref_option_lst, "CorePointer", NULL);
+		xf86addNewOption (iptr->iref_option_lst, xstrdup("CorePointer"), NULL);
 	ptr->lay_input_lst = (XF86ConfInputrefPtr)
 		xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
     }
@@ -532,7 +535,7 @@ configureLayoutSection (void)
 	iptr->iref_option_lst = NULL;
 	iptr->iref_inputdev_str = "Keyboard0";
 	iptr->iref_option_lst =
-		xf86addNewOption (iptr->iref_option_lst, "CoreKeyboard", NULL);
+		xf86addNewOption (iptr->iref_option_lst, xstrdup("CoreKeyboard"), NULL);
 	ptr->lay_input_lst = (XF86ConfInputrefPtr)
 		xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
     }
@@ -751,7 +754,7 @@ configureDDCMonitorSection (int screennu
     }
 
     if (ConfiguredMonitor->features.dpms) {
-      ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, "DPMS", NULL);
+      ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, xstrdup("DPMS"), NULL);
     }
 
     return ptr;
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index 7afb63a..50a7d9c 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -289,7 +289,7 @@ xf86CheckBoolOption(pointer optlist, con
 _X_EXPORT pointer
 xf86ReplaceIntOption(pointer optlist, const char *name, const int val)
 {
-    char *tmp = xnfalloc(16);
+    char tmp[16];
     sprintf(tmp,"%i",val);
     return xf86AddNewOption(optlist,name,tmp);
 }
@@ -297,7 +297,7 @@ xf86ReplaceIntOption(pointer optlist, co
 _X_EXPORT pointer
 xf86ReplaceRealOption(pointer optlist, const char *name, const double val)
 {
-    char *tmp = xnfalloc(32);
+    char tmp[32];
     snprintf(tmp,32,"%f",val);
     return xf86AddNewOption(optlist,name,tmp);
 }
diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index 4adea1a..5b60a51 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -198,21 +198,21 @@ addNewOption2 (XF86OptionPtr head, char 
 {
 	XF86OptionPtr new, old = NULL;
 
-	/* Don't allow duplicates */
- 	if (head != NULL && (old = xf86findOption(head, name)) != NULL)
- 		new = old;
- 	else {
+	/* Don't allow duplicates, free old strings */
+	if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
+		new = old;
+		xf86conffree(new->opt_name);
+		xf86conffree(new->opt_val);
+	}
+	else
 		new = xf86confcalloc (1, sizeof (XF86OptionRec));
- 		new->list.next = NULL;
- 	}
- 	new->opt_name = name;
- 	new->opt_val = val;
- 	new->opt_used = used;
-	
-  	if (old == NULL)
-		return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
- 	else 
- 		return head;
+	new->opt_name = name;
+	new->opt_val = val;
+	new->opt_used = used;
+
+	if (old)
+		return head;
+	return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
 }
 
 XF86OptionPtr
diff --git a/hw/xfree86/utils/xorgcfg/text-mode.c b/hw/xfree86/utils/xorgcfg/text-mode.c
index 9797ca2..8800c29 100644
--- a/hw/xfree86/utils/xorgcfg/text-mode.c
+++ b/hw/xfree86/utils/xorgcfg/text-mode.c
@@ -2111,7 +2111,7 @@ LayoutConfig(void)
 		    else
 			iref->iref_option_lst =
 			    xf86addNewOption(iref->iref_option_lst,
-					  "CorePointer", NULL);
+					  XtNewString("CorePointer"), NULL);
 		    option = xf86findOption(mref->iref_option_lst,
 					    "CorePointer");
 		    XtFree(option->opt_name);
@@ -2209,7 +2209,7 @@ LayoutConfig(void)
 		    else
 			iref->iref_option_lst =
 			    xf86addNewOption(iref->iref_option_lst,
-					  "CoreKeyboard", NULL);
+					  XtNewString("CoreKeyboard"), NULL);
 		    option = xf86findOption(kref->iref_option_lst,
 					    "CoreKeyboard");
 		    XtFree(option->opt_name);
diff-tree 07c56abf84080c020a3e7b7703a447c7f996975c (from e92743bc9839c36914a44f3e5bc8cd85773ac794)
Author: Magnus Vigerlöf <Magnus.Vigerlof at home.se>
Date:   Tue Apr 10 23:43:58 2007 +0300

    Input: Plug memory leak in device free
    
    Remember to also free the motion history, if we're using the DIX-managed
    history.

diff --git a/dix/devices.c b/dix/devices.c
index 9631c86..004cb13 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -431,8 +431,13 @@ CloseDevice(DeviceIntPtr dev)
 	xfree(dev->key);
     }
 
-    if (dev->valuator)
+    if (dev->valuator) {
+        /* Counterpart to 'biggest hack ever' in init. */
+        if (dev->valuator->motion &&
+            dev->valuator->GetMotionProc == GetMotionHistory)
+            xfree(dev->valuator->motion);
         xfree(dev->valuator);
+    }
 
     if (dev->button) {
 #ifdef XKB
diff-tree e92743bc9839c36914a44f3e5bc8cd85773ac794 (from e49f836d6fa2768cd6d2a6d0227b5dbf516013dc)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sun Apr 8 14:02:02 2007 +0300

    getevents: Copy modifier state from extended to core devices
    
    Make core events carry the same modifier state as the extended events, so
    that holding down Ctrl on keyboard A and pressing Q on keyboard B won't
    cause your app to quit.

diff --git a/dix/getevents.c b/dix/getevents.c
index 62f3bcb..6969f78 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -714,6 +714,7 @@ _X_EXPORT void
 SwitchCoreKeyboard(DeviceIntPtr pDev)
 {
     KeyClassPtr ckeyc = inputInfo.keyboard->key;
+    int i = 0;
 
     if (inputInfo.keyboard->devPrivates[CoreDevicePrivatesIndex].ptr != pDev) {
         memcpy(ckeyc->modifierMap, pDev->key->modifierMap, MAP_LENGTH);
@@ -728,6 +729,25 @@ SwitchCoreKeyboard(DeviceIntPtr pDev)
         ckeyc->curKeySyms.maxKeyCode = pDev->key->curKeySyms.maxKeyCode;
         SetKeySymsMap(&ckeyc->curKeySyms, &pDev->key->curKeySyms);
 
+        /*
+         * Copy state from the extended keyboard to core.  If you omit this,
+         * holding Ctrl on keyboard one, and pressing Q on keyboard two, will
+         * cause your app to quit.  This feels wrong to me, hence the below
+         * code.
+         *
+         * XXX: If you synthesise core modifier events, the state will get
+         *      clobbered here.  You'll have to work out something sensible
+         *      to fix that.  Good luck.
+         */
+
+#define KEYBOARD_MASK (ShiftMask | LockMask | ControlMask | Mod1Mask | \
+                       Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask)
+        ckeyc->state &= ~(KEYBOARD_MASK);
+        ckeyc->state |= (pDev->key->state & KEYBOARD_MASK);
+#undef KEYBOARD_MASK
+        for (i = 0; i < 8; i++)
+            ckeyc->modifierKeyCount[i] = pDev->key->modifierKeyCount[i];
+
 #ifdef XKB
         if (!noXkbExtension && pDev->key->xkbInfo && pDev->key->xkbInfo->desc) {
             if (!XkbCopyKeymap(pDev->key->xkbInfo->desc, ckeyc->xkbInfo->desc,
diff-tree e49f836d6fa2768cd6d2a6d0227b5dbf516013dc (from 4aae2de74b9224bac2b2e2522637dac09abc3837)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sun Apr 8 13:56:41 2007 +0300

    mieq: Use larger default queue size
    
    Use a default queue size of 512 rather than 256, else Xephyr is too slow
    without a host cursor, so events get stuck in the queue.

diff --git a/mi/mieq.c b/mi/mieq.c
index 34509cd..a03fff1 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -58,7 +58,7 @@ in this Software without prior written a
 # include <X11/extensions/dpms.h>
 #endif
 
-#define QUEUE_SIZE  256
+#define QUEUE_SIZE  512
 
 typedef struct _Event {
     xEvent          event[7];



More information about the xorg-commit mailing list