[PATCH weston 05/17] evdev: split udev members from struct evdev_seat
Pekka Paalanen
ppaalanen at gmail.com
Thu Jul 5 03:33:02 PDT 2012
Make evdev.c completely independent of udev.
Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
src/evdev.c | 20 ++++++++++++++++-
src/evdev.h | 13 +++++++----
src/udev-evdev.c | 61 ++++++++++++++++++++++++++++-------------------------
3 files changed, 59 insertions(+), 35 deletions(-)
diff --git a/src/evdev.c b/src/evdev.c
index d0771c0..db4e58b 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -32,7 +32,7 @@
#include "launcher-util.h"
#include "log.h"
-void
+static void
evdev_led_update(struct weston_seat *seat_base, enum weston_led leds)
{
static const struct {
@@ -61,6 +61,24 @@ evdev_led_update(struct weston_seat *seat_base, enum weston_led leds)
}
}
+void
+evdev_seat_init(struct evdev_seat *seat, struct weston_compositor *compositor,
+ const char *seat_id)
+{
+ weston_seat_init(&seat->base, compositor);
+ seat->base.led_update = evdev_led_update;
+
+ wl_list_init(&seat->devices_list);
+ seat->seat_id = strdup(seat_id);
+}
+
+void
+evdev_seat_release(struct evdev_seat *seat)
+{
+ free(seat->seat_id);
+ weston_seat_release(&seat->base);
+}
+
static inline void
evdev_process_key(struct evdev_input_device *device,
struct input_event *e, int time)
diff --git a/src/evdev.h b/src/evdev.h
index 3980601..f75e115 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -28,9 +28,8 @@
struct evdev_seat {
struct weston_seat base;
+
struct wl_list devices_list;
- struct udev_monitor *udev_monitor;
- struct wl_event_source *udev_monitor_source;
char *seat_id;
};
@@ -112,6 +111,13 @@ struct evdev_dispatch {
struct evdev_dispatch *
evdev_touchpad_create(struct evdev_input_device *device);
+void
+evdev_seat_init(struct evdev_seat *seat, struct weston_compositor *compositor,
+ const char *seat_id);
+
+void
+evdev_seat_release(struct evdev_seat *seat);
+
struct evdev_input_device *
evdev_input_device_create(struct evdev_seat *master,
struct wl_display *display, const char *path);
@@ -119,7 +125,4 @@ evdev_input_device_create(struct evdev_seat *master,
void
evdev_notify_keyboard_focus(struct evdev_seat *seat);
-void
-evdev_led_update(struct weston_seat *seat_base, enum weston_led leds);
-
#endif /* WESTON_EVDEV_H */
diff --git a/src/udev-evdev.c b/src/udev-evdev.c
index 0f67169..4660409 100644
--- a/src/udev-evdev.c
+++ b/src/udev-evdev.c
@@ -30,11 +30,17 @@
#include "udev-evdev.h"
#include "log.h"
+struct uevdev_seat {
+ struct evdev_seat evdev;
+
+ struct udev_monitor *udev_monitor;
+ struct wl_event_source *udev_monitor_source;
+};
static const char default_seat[] = "seat0";
static void
-device_added(struct udev_device *udev_device, struct evdev_seat *master)
+device_added(struct udev_device *udev_device, struct uevdev_seat *master)
{
struct weston_compositor *c;
const char *devnode;
@@ -44,12 +50,12 @@ device_added(struct udev_device *udev_device, struct evdev_seat *master)
if (!device_seat)
device_seat = default_seat;
- if (strcmp(device_seat, master->seat_id))
+ if (strcmp(device_seat, master->evdev.seat_id))
return;
- c = master->base.compositor;
+ c = master->evdev.base.compositor;
devnode = udev_device_get_devnode(udev_device);
- evdev_input_device_create(master, c->wl_display, devnode);
+ evdev_input_device_create(&master->evdev, c->wl_display, devnode);
}
static void
@@ -73,7 +79,7 @@ device_removed(struct evdev_input_device *device)
void
uevdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
{
- struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+ struct uevdev_seat *seat = (struct uevdev_seat *) seat_base;
struct udev_enumerate *e;
struct udev_list_entry *entry;
struct udev_device *device;
@@ -98,9 +104,9 @@ uevdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
}
udev_enumerate_unref(e);
- evdev_notify_keyboard_focus(seat);
+ evdev_notify_keyboard_focus(&seat->evdev);
- if (wl_list_empty(&seat->devices_list)) {
+ if (wl_list_empty(&seat->evdev.devices_list)) {
weston_log(
"warning: no input devices on entering Weston. "
"Possible causes:\n"
@@ -114,7 +120,7 @@ uevdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
static int
evdev_udev_handler(int fd, uint32_t mask, void *data)
{
- struct evdev_seat *master = data;
+ struct uevdev_seat *master = data;
struct udev_device *udev_device;
struct evdev_input_device *device, *next;
const char *action;
@@ -135,7 +141,8 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
else if (!strcmp(action, "remove")) {
devnode = udev_device_get_devnode(udev_device);
wl_list_for_each_safe(device, next,
- &master->devices_list, link)
+ &master->evdev.devices_list,
+ link)
if (!strcmp(device->devnode, devnode)) {
device_removed(device);
break;
@@ -150,9 +157,9 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
int
uevdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
{
- struct evdev_seat *master = (struct evdev_seat *) seat_base;
+ struct uevdev_seat *master = (struct uevdev_seat *) seat_base;
struct wl_event_loop *loop;
- struct weston_compositor *c = master->base.compositor;
+ struct weston_compositor *c = master->evdev.base.compositor;
int fd;
master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
@@ -186,7 +193,7 @@ uevdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
void
uevdev_disable_udev_monitor(struct weston_seat *seat_base)
{
- struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+ struct uevdev_seat *seat = (struct uevdev_seat *) seat_base;
if (!seat->udev_monitor)
return;
@@ -201,50 +208,46 @@ void
uevdev_input_create(struct weston_compositor *c, struct udev *udev,
const char *seat_id)
{
- struct evdev_seat *seat;
+ struct uevdev_seat *seat;
seat = malloc(sizeof *seat);
if (seat == NULL)
return;
memset(seat, 0, sizeof *seat);
- weston_seat_init(&seat->base, c);
- seat->base.led_update = evdev_led_update;
+ evdev_seat_init(&seat->evdev, c, seat_id);
- wl_list_init(&seat->devices_list);
- seat->seat_id = strdup(seat_id);
- if (!uevdev_enable_udev_monitor(udev, &seat->base)) {
- free(seat->seat_id);
+ if (!uevdev_enable_udev_monitor(udev, &seat->evdev.base)) {
+ free(seat->evdev.seat_id);
free(seat);
return;
}
- uevdev_add_devices(udev, &seat->base);
+ uevdev_add_devices(udev, &seat->evdev.base);
- c->seat = &seat->base;
+ c->seat = &seat->evdev.base;
}
void
uevdev_remove_devices(struct weston_seat *seat_base)
{
- struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+ struct uevdev_seat *seat = (struct uevdev_seat *) seat_base;
struct evdev_input_device *device, *next;
- wl_list_for_each_safe(device, next, &seat->devices_list, link)
+ wl_list_for_each_safe(device, next, &seat->evdev.devices_list, link)
device_removed(device);
- notify_keyboard_focus_out(&seat->base.seat);
+ notify_keyboard_focus_out(&seat->evdev.base.seat);
}
void
uevdev_input_destroy(struct weston_seat *seat_base)
{
- struct evdev_seat *seat = (struct evdev_seat *) seat_base;
+ struct uevdev_seat *seat = (struct uevdev_seat *) seat_base;
- uevdev_remove_devices(seat_base);
- uevdev_disable_udev_monitor(&seat->base);
+ uevdev_remove_devices(&seat->evdev.base);
+ uevdev_disable_udev_monitor(&seat->evdev.base);
- wl_list_remove(&seat->base.link);
- free(seat->seat_id);
+ evdev_seat_release(&seat->evdev);
free(seat);
}
--
1.7.8.6
More information about the wayland-devel
mailing list