evdev: Disable the udev monitor when another vt becomes active

We dont want to receive hotplug events while being inactive.
When getting back active we enumerate all devices and would end up
with two sources for one device that may be hotplugged in the mean time.
dev
Benjamin Franzke 13 years ago
parent bfeda130de
commit 78d3afe21c
  1. 8
      src/compositor-drm.c
  2. 25
      src/evdev.c
  3. 6
      src/evdev.h

@ -1498,8 +1498,10 @@ vt_func(struct weston_compositor *compositor, int event)
compositor->state = ec->prev_state; compositor->state = ec->prev_state;
drm_compositor_set_modes(ec); drm_compositor_set_modes(ec);
weston_compositor_damage_all(compositor); weston_compositor_damage_all(compositor);
wl_list_for_each(input, &compositor->input_device_list, link) wl_list_for_each(input, &compositor->input_device_list, link) {
evdev_add_devices(ec->udev, input); evdev_add_devices(ec->udev, input);
evdev_enable_udev_monitor(ec->udev, input);
}
break; break;
case TTY_LEAVE_VT: case TTY_LEAVE_VT:
compositor->focus = 0; compositor->focus = 0;
@ -1528,8 +1530,10 @@ vt_func(struct weston_compositor *compositor, int event)
drm_output->crtc_id, 0, 0, drm_output->crtc_id, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0); 0, 0, 0, 0, 0, 0, 0, 0);
wl_list_for_each(input, &compositor->input_device_list, link) wl_list_for_each(input, &compositor->input_device_list, link) {
evdev_disable_udev_monitor(input);
evdev_remove_devices(input); evdev_remove_devices(input);
}
if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0) if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0)
fprintf(stderr, "failed to drop master: %m\n"); fprintf(stderr, "failed to drop master: %m\n");

@ -632,9 +632,10 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
return 0; return 0;
} }
static int int
evdev_config_udev_monitor(struct udev *udev, struct evdev_input *master) evdev_enable_udev_monitor(struct udev *udev, struct weston_input_device *input_base)
{ {
struct evdev_input *master = (struct evdev_input *) input_base;
struct wl_event_loop *loop; struct wl_event_loop *loop;
struct weston_compositor *c = master->base.compositor; struct weston_compositor *c = master->base.compositor;
int fd; int fd;
@ -667,6 +668,20 @@ evdev_config_udev_monitor(struct udev *udev, struct evdev_input *master)
return 1; return 1;
} }
void
evdev_disable_udev_monitor(struct weston_input_device *input_base)
{
struct evdev_input *input = (struct evdev_input *) input_base;
if (!input->udev_monitor)
return;
udev_monitor_unref(input->udev_monitor);
input->udev_monitor = NULL;
wl_event_source_remove(input->udev_monitor_source);
input->udev_monitor_source = NULL;
}
void void
evdev_input_create(struct weston_compositor *c, struct udev *udev, evdev_input_create(struct weston_compositor *c, struct udev *udev,
const char *seat) const char *seat)
@ -682,7 +697,7 @@ evdev_input_create(struct weston_compositor *c, struct udev *udev,
wl_list_init(&input->devices_list); wl_list_init(&input->devices_list);
input->seat_id = strdup(seat); input->seat_id = strdup(seat);
if (!evdev_config_udev_monitor(udev, input)) { if (!evdev_enable_udev_monitor(udev, &input->base)) {
free(input->seat_id); free(input->seat_id);
free(input); free(input);
return; return;
@ -709,9 +724,7 @@ evdev_input_destroy(struct weston_input_device *input_base)
struct evdev_input *input = (struct evdev_input *) input_base; struct evdev_input *input = (struct evdev_input *) input_base;
evdev_remove_devices(input_base); evdev_remove_devices(input_base);
evdev_disable_udev_monitor(&input->base);
udev_monitor_unref(input->udev_monitor);
wl_event_source_remove(input->udev_monitor_source);
wl_list_remove(&input->base.link); wl_list_remove(&input->base.link);
free(input->seat_id); free(input->seat_id);

@ -33,3 +33,9 @@ evdev_input_create(struct weston_compositor *c, struct udev *udev,
void void
evdev_input_destroy(struct weston_input_device *input_base); evdev_input_destroy(struct weston_input_device *input_base);
int
evdev_enable_udev_monitor(struct udev *udev, struct weston_input_device *input_base);
void
evdev_disable_udev_monitor(struct weston_input_device *input_base);

Loading…
Cancel
Save