[PATCH xserver 2/3] xfree86: swap the list of paused devices to an xorg_list

Peter Hutterer peter.hutterer at who-t.net
Thu Oct 20 21:50:07 UTC 2016


No functional changes but it makes it easier to remove elements from the
middle of the list (future patch).

We don't have an init call into this file, so the list is manually
initialized.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 hw/xfree86/common/xf86Xinput.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e31aab3..0095272 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -110,8 +110,16 @@
 static int
  xf86InputDevicePostInit(DeviceIntPtr dev);
 
-static InputInfoPtr *new_input_devices;
-static int new_input_devices_count;
+typedef struct {
+    struct xorg_list node;
+    InputInfoPtr pInfo;
+} PausedInputDeviceRec;
+typedef PausedInputDeviceRec *PausedInputDevicePtr;
+
+static struct xorg_list new_input_devices_list = {
+    .next = &new_input_devices_list,
+    .prev = &new_input_devices_list,
+};
 
 /**
  * Eval config and modify DeviceVelocityRec accordingly
@@ -907,11 +915,10 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
         if (fd != -1) {
             if (paused) {
                 /* Put on new_input_devices list for delayed probe */
-                new_input_devices = xnfreallocarray(new_input_devices,
-                                                    new_input_devices_count + 1,
-                                                    sizeof(pInfo));
-                new_input_devices[new_input_devices_count] = pInfo;
-                new_input_devices_count++;
+                PausedInputDevicePtr new_device = xnfalloc(sizeof *new_device);
+                new_device->pInfo = pInfo;
+
+                xorg_list_append(&new_device->node, &new_input_devices_list);
                 systemd_logind_release_fd(pInfo->major, pInfo->minor, fd);
                 free(path);
                 return BadMatch;
@@ -1540,11 +1547,12 @@ xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid, uint16_t type,
 void
 xf86InputEnableVTProbe(void)
 {
-    int i, is_auto = 0;
+    int is_auto = 0;
     DeviceIntPtr pdev;
+    PausedInputDevicePtr d, tmp;
 
-    for (i = 0; i < new_input_devices_count; i++) {
-        InputInfoPtr pInfo = new_input_devices[i];
+    xorg_list_for_each_entry_safe(d, tmp, &new_input_devices_list, node) {
+        InputInfoPtr pInfo = d->pInfo;
         const char *value = xf86findOptionValue(pInfo->options, "_source");
 
         is_auto = 0;
@@ -1557,8 +1565,9 @@ xf86InputEnableVTProbe(void)
         xf86NewInputDevice(pInfo, &pdev,
                                   (!is_auto ||
                                    (is_auto && xf86Info.autoEnableDevices)));
+        xorg_list_del(&d->node);
+        free(d);
     }
-    new_input_devices_count = 0;
 }
 
 /* end of xf86Xinput.c */
-- 
2.9.3



More information about the xorg-devel mailing list