evdev: introduce a touch arbitration enum
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 19 Sep 2018 02:02:51 +0000 (12:02 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 31 Jan 2019 05:17:28 +0000 (05:17 +0000)
This enables us to change the types of touch arbitration, with the focus on
allowing location-based touch arbitration as well as the more generic "disable
everything".

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev-fallback.c
src/evdev-fallback.h
src/evdev-mt-touchpad.c
src/evdev-mt-touchpad.h
src/evdev-tablet.c
src/evdev.h

index c584e095271000973a985efed871ec8ca1050325..4f607d2facdf31e2a39a3d026dc9b4a516d33a76 100644 (file)
@@ -1196,20 +1196,16 @@ fallback_interface_sync_initial_state(struct evdev_device *device,
 static void
 fallback_interface_toggle_touch(struct evdev_dispatch *evdev_dispatch,
                                struct evdev_device *device,
-                               bool enable,
+                               enum evdev_arbitration_state which,
                                uint64_t time)
 {
        struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
-       bool ignore_events = !enable;
 
-       if (ignore_events == dispatch->arbitration.ignore_events)
+       if (which == dispatch->arbitration.state)
                return;
 
-       if (ignore_events) {
-               libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
-               fallback_return_to_neutral_state(dispatch, device);
-               dispatch->arbitration.in_arbitration = true;
-       } else {
+       switch (which) {
+       case ARBITRATION_NOT_ACTIVE:
                /* if in-kernel arbitration is in use and there is a touch
                 * and a pen in proximity, lifting the pen out of proximity
                 * causes a touch begin for the touch. On a hand-lift the
@@ -1219,9 +1215,15 @@ fallback_interface_toggle_touch(struct evdev_dispatch *evdev_dispatch,
                 * event is caught as palm touch. */
                libinput_timer_set(&dispatch->arbitration.arbitration_timer,
                                   time + ms2us(90));
+               break;
+       case ARBITRATION_IGNORE_ALL:
+               libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
+               fallback_return_to_neutral_state(dispatch, device);
+               dispatch->arbitration.in_arbitration = true;
+               break;
        }
 
-       dispatch->arbitration.ignore_events = ignore_events;
+       dispatch->arbitration.state = which;
 }
 
 static void
index 47f9f5e178a5193d70d2ae0c12c7859f16cfca6a..58694dcc04e5c36c535ad671fea9cb8482c6b92b 100644 (file)
@@ -141,11 +141,11 @@ struct fallback_dispatch {
                struct list paired_keyboard_list;
        } lid;
 
-       /* pen/touch arbitration has a delayed state, if ignore_events is
-        * true we want to ignore events, in_arbitration actually filters.
+       /* pen/touch arbitration has a delayed state,
+        * in_arbitration is what decides when to filter.
         */
        struct {
-               bool ignore_events;
+               enum evdev_arbitration_state state;
                bool in_arbitration;
                struct libinput_timer arbitration_timer;
        } arbitration;
index 650a193e779258f7c07acb6b53eacc73690ac2e6..7385ab5709816e20d780a4cc1983ccabfdc53394 100644 (file)
@@ -1028,7 +1028,7 @@ tp_palm_detect_arbitration_triggered(struct tp_dispatch *tp,
                                     struct tp_touch *t,
                                     uint64_t time)
 {
-       if (!tp->arbitration.in_arbitration)
+       if (tp->arbitration.state == ARBITRATION_NOT_ACTIVE)
                return false;
 
        t->palm.state = PALM_ARBITRATION;
@@ -2685,27 +2685,28 @@ tp_arbitration_timeout(uint64_t now, void *data)
 {
        struct tp_dispatch *tp = data;
 
-       if (tp->arbitration.in_arbitration)
-               tp->arbitration.in_arbitration = false;
+       if (tp->arbitration.state != ARBITRATION_NOT_ACTIVE)
+               tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
 }
 
 static void
 tp_interface_toggle_touch(struct evdev_dispatch *dispatch,
                          struct evdev_device *device,
-                         bool enable,
+                         enum evdev_arbitration_state which,
                          uint64_t time)
 {
        struct tp_dispatch *tp = tp_dispatch(dispatch);
-       bool arbitrate = !enable;
 
-       if (arbitrate == tp->arbitration.in_arbitration)
+       if (which == tp->arbitration.state)
                return;
 
-       if (arbitrate) {
+       switch (which) {
+       case ARBITRATION_IGNORE_ALL:
                libinput_timer_cancel(&tp->arbitration.arbitration_timer);
                tp_clear_state(tp);
-               tp->arbitration.in_arbitration = true;
-       } else {
+               tp->arbitration.state = which;
+               break;
+       case ARBITRATION_NOT_ACTIVE:
                /* if in-kernel arbitration is in use and there is a touch
                 * and a pen in proximity, lifting the pen out of proximity
                 * causes a touch begin for the touch. On a hand-lift the
@@ -2715,6 +2716,7 @@ tp_interface_toggle_touch(struct evdev_dispatch *dispatch,
                 * event is caught as palm touch. */
                libinput_timer_set(&tp->arbitration.arbitration_timer,
                                   time + ms2us(90));
+               break;
        }
 }
 
@@ -3231,7 +3233,7 @@ tp_init_palmdetect_arbitration(struct tp_dispatch *tp,
                            tp_libinput_context(tp),
                            timer_name,
                            tp_arbitration_timeout, tp);
-       tp->arbitration.in_arbitration = false;
+       tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
 }
 
 static void
index 93857ae49be5f1fb3a2f3883f11317a9ff628306..61db33a4331e8778eb760a046c50b8f0fe02c8fd 100644 (file)
@@ -270,7 +270,7 @@ struct tp_dispatch {
 
        /* pen/touch arbitration */
        struct {
-               bool in_arbitration;
+               enum evdev_arbitration_state state;
                struct libinput_timer arbitration_timer;
        } arbitration;
 
index 899a3f97c797cc619059c17d3df27d9b543f1589..6d177e183cdf3d822c1af6fd7863e4007b03c03b 100644 (file)
@@ -1623,15 +1623,21 @@ tablet_set_touch_device_enabled(struct evdev_device *touch_device,
                                uint64_t time)
 {
        struct evdev_dispatch *dispatch;
+       enum evdev_arbitration_state which;
 
        if (touch_device == NULL)
                return;
 
+       if (enable)
+               which = ARBITRATION_NOT_ACTIVE;
+       else
+               which = ARBITRATION_IGNORE_ALL;
+
        dispatch = touch_device->dispatch;
        if (dispatch->interface->toggle_touch)
                dispatch->interface->toggle_touch(dispatch,
                                                  touch_device,
-                                                 enable,
+                                                 which,
                                                  time);
 }
 
index 3a613eb54e6be04334674056d2d171e81b513f8e..e983fb1de88e55438d7fcfe1b18e40bcefb69cb3 100644 (file)
@@ -144,6 +144,11 @@ enum evdev_debounce_state {
        DEBOUNCE_ACTIVE,
 };
 
+enum evdev_arbitration_state {
+       ARBITRATION_NOT_ACTIVE,
+       ARBITRATION_IGNORE_ALL,
+};
+
 struct evdev_device {
        struct libinput_device base;
 
@@ -301,7 +306,7 @@ struct evdev_dispatch_interface {
         * enable/disable touch capabilities */
        void (*toggle_touch)(struct evdev_dispatch *dispatch,
                             struct evdev_device *device,
-                            bool enable,
+                            enum evdev_arbitration_state which,
                             uint64_t now);
 
        /* Return the state of the given switch */