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.hutte...@who-t.net>
---
 src/evdev-mt-touchpad.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file 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,
-- 
2.14.3

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to