diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2018-05-16 10:03:35 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2018-05-18 12:05:02 +1000 |
commit | a9d78e99ea854a212dd46e361683b0cda4bfc229 (patch) | |
tree | 5b818b7bce1977e5cbacaaef7e1a3bfddc7d58b9 | |
parent | 6dcdfdd513fd8158bc7bacbad8c5c8ba987565a0 (diff) |
touchpad: split the switch event handlers up
Because we register the handler separately (once for lid, once for
tablet-mode) the handler is called twice for the same event. This causes a
double-suspend of the touchpad, though it doesn't seem to have any real
effect.
Split it up so that each handler function only does one thing.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/evdev-mt-touchpad.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 47bfe228..ba19d842 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -2201,34 +2201,54 @@ tp_pair_trackpoint(struct evdev_device *touchpad, } static void -tp_switch_event(uint64_t time, struct libinput_event *event, void *data) +tp_lid_switch_event(uint64_t time, struct libinput_event *event, void *data) { struct tp_dispatch *tp = data; struct libinput_event_switch *swev; - const char *which = NULL; if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) return; swev = libinput_event_get_switch_event(event); + if (libinput_event_switch_get_switch(swev) != LIBINPUT_SWITCH_LID) + return; - switch (libinput_event_switch_get_switch(swev)) { - case LIBINPUT_SWITCH_LID: - which = "lid"; + switch (libinput_event_switch_get_switch_state(swev)) { + case LIBINPUT_SWITCH_STATE_OFF: + tp_resume_conditional(tp, tp->device, NO_EXCLUDED_DEVICE); + evdev_log_debug(tp->device, "lid: resume touchpad\n"); break; - case LIBINPUT_SWITCH_TABLET_MODE: - which = "tablet-mode"; + case LIBINPUT_SWITCH_STATE_ON: + tp_suspend(tp, tp->device); + evdev_log_debug(tp->device, "lid: suspending touchpad\n"); break; } +} + +static void +tp_tablet_mode_switch_event(uint64_t time, + struct libinput_event *event, + void *data) +{ + struct tp_dispatch *tp = data; + struct libinput_event_switch *swev; + + if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) + return; + + swev = libinput_event_get_switch_event(event); + if (libinput_event_switch_get_switch(swev) != + LIBINPUT_SWITCH_TABLET_MODE) + return; switch (libinput_event_switch_get_switch_state(swev)) { case LIBINPUT_SWITCH_STATE_OFF: tp_resume_conditional(tp, tp->device, NO_EXCLUDED_DEVICE); - evdev_log_debug(tp->device, "%s: resume touchpad\n", which); + evdev_log_debug(tp->device, "tablet-mode: resume touchpad\n"); break; case LIBINPUT_SWITCH_STATE_ON: tp_suspend(tp, tp->device); - evdev_log_debug(tp->device, "%s: suspending touchpad\n", which); + evdev_log_debug(tp->device, "tablet-mode: suspending touchpad\n"); break; } } @@ -2250,7 +2270,7 @@ tp_pair_lid_switch(struct evdev_device *touchpad, libinput_device_add_event_listener(&lid_switch->base, &tp->lid_switch.listener, - tp_switch_event, tp); + tp_lid_switch_event, tp); tp->lid_switch.lid_switch = lid_switch; } } @@ -2274,7 +2294,7 @@ tp_pair_tablet_mode_switch(struct evdev_device *touchpad, libinput_device_add_event_listener(&tablet_mode_switch->base, &tp->tablet_mode_switch.listener, - tp_switch_event, tp); + tp_tablet_mode_switch_event, tp); tp->tablet_mode_switch.tablet_mode_switch = tablet_mode_switch; if (evdev_device_switch_get_state(tablet_mode_switch, |