commit bafc060

Michael Forney  ·  2014-01-22 11:23:46 +0000 UTC
parent 09ae3a9
seat: Remove udev dependency
4 files changed,  +50, -67
+0, -5
 1@@ -17,13 +17,8 @@ Dependencies
 2 * libxkbcommon
 3 * pixman
 4 * [wld](http://github.com/michaelforney/wld)
 5-* libudev
 6 * linux\[>=3.12\] (for EVIOCREVOKE)
 7 
 8-libudev is currently required for input hotplugging support. I'd like to get rid
 9-of this dependency, but it seems that libudev is currently the only way to get
10-this functionality.
11-
12 For XWayland support, the following are also required:
13 * libxcb
14 * xcb-util-wm
+0, -1
1@@ -22,7 +22,6 @@ endif
2 $(dir)_PACKAGES =   \
3     libdrm          \
4     libevdev        \
5-    libudev         \
6     pixman-1        \
7     wayland-server  \
8     wld             \
+33, -33
  1@@ -1,6 +1,6 @@
  2 /* swc: libswc/seat.c
  3  *
  4- * Copyright (c) 2013 Michael Forney
  5+ * Copyright (c) 2013, 2014 Michael Forney
  6  *
  7  * Permission is hereby granted, free of charge, to any person obtaining a copy
  8  * of this software and associated documentation files (the "Software"), to deal
  9@@ -31,6 +31,7 @@
 10 #include "pointer.h"
 11 #include "util.h"
 12 
 13+#include <dirent.h>
 14 #include <stdlib.h>
 15 #include <stdio.h>
 16 #include <string.h>
 17@@ -192,25 +193,11 @@ static void bind_seat(struct wl_client * client, void * data, uint32_t version,
 18     wl_seat_send_capabilities(resource, seat.capabilities);
 19 }
 20 
 21-static void add_device(struct udev_device * udev_device)
 22+static void add_device(const char * path)
 23 {
 24-    const char * device_seat;
 25-    const char * device_path;
 26     struct swc_evdev_device * device;
 27 
 28-    device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
 29-
 30-    /* If the ID_SEAT property is not set, the device belongs to seat0. */
 31-    if (!device_seat)
 32-        device_seat = "seat0";
 33-
 34-    if (strcmp(device_seat, seat.name) != 0)
 35-        return;
 36-
 37-    device_path = udev_device_get_devnode(udev_device);
 38-    device = swc_evdev_device_new(device_path, &evdev_handler);
 39-
 40-    if (!device)
 41+    if (!(device = swc_evdev_device_new(path, &evdev_handler)))
 42     {
 43         ERROR("Could not create evdev device\n");
 44         return;
 45@@ -228,28 +215,38 @@ static void add_device(struct udev_device * udev_device)
 46     wl_list_insert(&seat.devices, &device->link);
 47 }
 48 
 49-static void add_devices()
 50+static int select_device(const struct dirent * entry)
 51+{
 52+    unsigned num;
 53+
 54+    return sscanf(entry->d_name, "event%u", &num) == 1;
 55+}
 56+
 57+static bool add_devices()
 58 {
 59-    struct udev_enumerate * enumerate;
 60-    struct udev_list_entry * entry;
 61-    const char * path;
 62-    struct udev_device * device;
 63+    struct dirent ** devices;
 64+    int num_devices;
 65+    char path[64];
 66+    unsigned index;
 67 
 68-    enumerate = udev_enumerate_new(swc.udev);
 69-    udev_enumerate_add_match_subsystem(enumerate, "input");
 70-    udev_enumerate_add_match_sysname(enumerate, "event[0-9]*");
 71+    num_devices = scandir("/dev/input", &devices, &select_device, &alphasort);
 72 
 73-    udev_enumerate_scan_devices(enumerate);
 74+    if (num_devices == -1)
 75+    {
 76+        ERROR("Failed to scan /dev/input for event devices\n");
 77+        return false;
 78+    }
 79 
 80-    udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate))
 81+    for (index = 0; index < num_devices; ++index)
 82     {
 83-        path = udev_list_entry_get_name(entry);
 84-        device = udev_device_new_from_syspath(swc.udev, path);
 85-        add_device(device);
 86-        udev_device_unref(device);
 87+        snprintf(path, sizeof path, "/dev/input/%s", devices[index]->d_name);
 88+        free(devices[index]);
 89+        add_device(path);
 90     }
 91 
 92-    udev_enumerate_unref(enumerate);
 93+    free(devices);
 94+
 95+    return true;
 96 }
 97 
 98 bool swc_seat_initialize(const char * seat_name)
 99@@ -293,10 +290,13 @@ bool swc_seat_initialize(const char * seat_name)
100         goto error4;
101     }
102 
103-    add_devices();
104+    if (!add_devices())
105+        goto error5;
106 
107     return true;
108 
109+  error5:
110+    swc_pointer_finalize(&seat.pointer);
111   error4:
112     swc_keyboard_finalize(&seat.keyboard);
113   error3:
+17, -28
  1@@ -40,8 +40,6 @@
  2 # include "xserver.h"
  3 #endif
  4 
  5-#include <libudev.h>
  6-
  7 extern struct swc_launch swc_launch;
  8 extern const struct swc_seat swc_seat;
  9 extern const struct swc_bindings swc_bindings;
 10@@ -101,65 +99,59 @@ bool swc_initialize(struct wl_display * display,
 11         goto error0;
 12     }
 13 
 14-    if (!(swc.udev = udev_new()))
 15-    {
 16-        ERROR("Could not initialize udev\n");
 17-        goto error1;
 18-    }
 19-
 20     if (!swc_drm_initialize())
 21     {
 22         ERROR("Could not initialize DRM\n");
 23-        goto error2;
 24+        goto error1;
 25     }
 26 
 27     if (!swc_shm_initialize())
 28     {
 29         ERROR("Could not initialize SHM\n");
 30-        goto error3;
 31+        goto error2;
 32     }
 33 
 34     if (!swc_bindings_initialize())
 35     {
 36         ERROR("Could not initialize bindings\n");
 37-        goto error4;
 38+        goto error3;
 39     }
 40 
 41     if (!swc_screens_initialize())
 42     {
 43         ERROR("Could not initialize screens\n");
 44-        goto error5;
 45+        goto error4;
 46     }
 47 
 48     if (!swc_compositor_initialize())
 49     {
 50         ERROR("Could not initialize compositor\n");
 51-        goto error6;
 52+        goto error5;
 53     }
 54 
 55     if (!swc_data_device_manager_initialize())
 56     {
 57         ERROR("Could not initialize data device manager\n");
 58-        goto error7;
 59+        goto error6;
 60     }
 61 
 62     if (!swc_seat_initialize(default_seat))
 63     {
 64         ERROR("Could not initialize seat\n");
 65-        goto error8;
 66+        goto error7;
 67     }
 68 
 69     if (!swc_shell_initialize())
 70     {
 71         ERROR("Could not initialize shell\n");
 72-        goto error9;
 73+        goto error8;
 74     }
 75 
 76 #ifdef ENABLE_XWAYLAND
 77     if (!swc_xserver_initialize())
 78     {
 79         ERROR("Could not initialize xwayland\n");
 80-        goto error10;
 81+        goto error9;
 82     }
 83 #endif
 84 
 85@@ -167,24 +159,22 @@ bool swc_initialize(struct wl_display * display,
 86 
 87     return true;
 88 
 89-  error10:
 90-    swc_shell_finalize();
 91   error9:
 92-    swc_seat_finalize();
 93+    swc_shell_finalize();
 94   error8:
 95-    swc_data_device_manager_finalize();
 96+    swc_seat_finalize();
 97   error7:
 98-    swc_compositor_finalize();
 99+    swc_data_device_manager_finalize();
100   error6:
101-    swc_screens_finalize();
102+    swc_compositor_finalize();
103   error5:
104-    swc_bindings_finalize();
105+    swc_screens_finalize();
106   error4:
107-    swc_shm_finalize();
108+    swc_bindings_finalize();
109   error3:
110-    swc_drm_finalize();
111+    swc_shm_finalize();
112   error2:
113-    udev_unref(swc.udev);
114+    swc_drm_finalize();
115   error1:
116     swc_launch_finalize();
117   error0:
118@@ -205,7 +195,6 @@ void swc_finalize()
119     swc_bindings_finalize();
120     swc_shm_finalize();
121     swc_drm_finalize();
122-    udev_unref(swc.udev);
123     swc_launch_finalize();
124 }
125