udev-seat: Simplfy enable/disable interface a bit

We always call enable_udev_monitor and add_devices together and always
disable_udev_monitor and remove_devices together.  Let's just have one
entry point for enable and one for disable.
Kristian Høgsberg 12 years ago
parent 7e597f22d5
commit 8764466c6b
  1. 12
      src/compositor-drm.c
  2. 12
      src/compositor-fbdev.c
  3. 48
      src/udev-seat.c
  4. 6
      src/udev-seat.h

@ -2006,17 +2006,13 @@ vt_func(struct weston_compositor *compositor, int event)
compositor->state = ec->prev_state;
drm_compositor_set_modes(ec);
weston_compositor_damage_all(compositor);
wl_list_for_each(seat, &compositor->seat_list, base.link) {
udev_seat_add_devices(seat, ec->udev);
udev_seat_enable_udev_monitor(seat, ec->udev);
}
wl_list_for_each(seat, &compositor->seat_list, base.link)
udev_seat_enable(seat, ec->udev);
break;
case TTY_LEAVE_VT:
weston_log("leaving VT\n");
wl_list_for_each(seat, &compositor->seat_list, base.link) {
udev_seat_disable_udev_monitor(seat);
udev_seat_remove_devices(seat);
}
wl_list_for_each(seat, &compositor->seat_list, base.link)
udev_seat_disable(seat);
compositor->focus = 0;
ec->prev_state = compositor->state;

@ -777,17 +777,13 @@ vt_func(struct weston_compositor *base, int event)
weston_compositor_damage_all(&compositor->base);
wl_list_for_each(seat, &compositor->base.seat_list, base.link) {
udev_seat_add_devices(seat, compositor->udev);
udev_seat_enable_udev_monitor(seat, compositor->udev);
}
wl_list_for_each(seat, &compositor->base.seat_list, base.link)
udev_seat_enable(seat, compositor->udev);
break;
case TTY_LEAVE_VT:
weston_log("leaving VT\n");
wl_list_for_each(seat, &compositor->base.seat_list, base.link) {
udev_seat_disable_udev_monitor(seat);
udev_seat_remove_devices(seat);
}
wl_list_for_each(seat, &compositor->base.seat_list, base.link)
udev_seat_disable(seat);
wl_list_for_each(output, &compositor->base.output_list, link) {
fbdev_output_disable(output);

@ -99,7 +99,7 @@ device_added(struct udev_device *udev_device, struct udev_seat *master)
return 0;
}
int
static int
udev_seat_add_devices(struct udev_seat *seat, struct udev *udev)
{
struct udev_enumerate *e;
@ -186,7 +186,7 @@ out:
}
int
udev_seat_enable_udev_monitor(struct udev_seat *seat, struct udev *udev)
udev_seat_enable(struct udev_seat *seat, struct udev *udev)
{
struct wl_event_loop *loop;
struct weston_compositor *c = seat->base.compositor;
@ -195,7 +195,7 @@ udev_seat_enable_udev_monitor(struct udev_seat *seat, struct udev *udev)
seat->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
if (!seat->udev_monitor) {
weston_log("udev: failed to create the udev monitor\n");
return 0;
return -1;
}
udev_monitor_filter_add_match_subsystem_devtype(seat->udev_monitor,
@ -204,7 +204,7 @@ udev_seat_enable_udev_monitor(struct udev_seat *seat, struct udev *udev)
if (udev_monitor_enable_receiving(seat->udev_monitor)) {
weston_log("udev: failed to bind the udev monitor\n");
udev_monitor_unref(seat->udev_monitor);
return 0;
return -1;
}
loop = wl_display_get_event_loop(c->wl_display);
@ -214,14 +214,29 @@ udev_seat_enable_udev_monitor(struct udev_seat *seat, struct udev *udev)
evdev_udev_handler, seat);
if (!seat->udev_monitor_source) {
udev_monitor_unref(seat->udev_monitor);
return -1;
}
if (udev_seat_add_devices(seat, udev) < 0)
return -1;
return 0;
}
return 1;
static void
udev_seat_remove_devices(struct udev_seat *seat)
{
struct evdev_device *device, *next;
wl_list_for_each_safe(device, next, &seat->devices_list, link)
evdev_device_destroy(device);
if (seat->base.seat.keyboard)
notify_keyboard_focus_out(&seat->base);
}
void
udev_seat_disable_udev_monitor(struct udev_seat *seat)
udev_seat_disable(struct udev_seat *seat)
{
if (!seat->udev_monitor)
return;
@ -230,6 +245,8 @@ udev_seat_disable_udev_monitor(struct udev_seat *seat)
seat->udev_monitor = NULL;
wl_event_source_remove(seat->udev_monitor_source);
seat->udev_monitor_source = NULL;
udev_seat_remove_devices(seat);
}
static void
@ -258,9 +275,7 @@ udev_seat_create(struct weston_compositor *c, struct udev *udev,
wl_list_init(&seat->devices_list);
seat->seat_id = strdup(seat_id);
if (!udev_seat_enable_udev_monitor(seat, udev))
goto err;
if (udev_seat_add_devices(seat, udev) < 0)
if (udev_seat_enable(seat, udev) < 0)
goto err;
return seat;
@ -271,23 +286,10 @@ udev_seat_create(struct weston_compositor *c, struct udev *udev,
return NULL;
}
void
udev_seat_remove_devices(struct udev_seat *seat)
{
struct evdev_device *device, *next;
wl_list_for_each_safe(device, next, &seat->devices_list, link)
evdev_device_destroy(device);
if (seat->base.seat.keyboard)
notify_keyboard_focus_out(&seat->base);
}
void
udev_seat_destroy(struct udev_seat *seat)
{
udev_seat_remove_devices(seat);
udev_seat_disable_udev_monitor(seat);
udev_seat_disable(seat);
weston_seat_release(&seat->base);
free(seat->seat_id);

@ -35,13 +35,11 @@ struct udev_seat {
char *seat_id;
};
int udev_seat_add_devices(struct udev_seat *seat, struct udev *udev);
int udev_seat_enable_udev_monitor(struct udev_seat *seat, struct udev *udev);
void udev_seat_disable_udev_monitor(struct udev_seat *seat);
int udev_seat_enable(struct udev_seat *seat, struct udev *udev);
void udev_seat_disable(struct udev_seat *seat);
struct udev_seat *udev_seat_create(struct weston_compositor *c,
struct udev *udev,
const char *seat_id);
void udev_seat_remove_devices(struct udev_seat *seat);
void udev_seat_destroy(struct udev_seat *seat);
#endif

Loading…
Cancel
Save