[mutter] seat-native: Add support for tablet-mode-switch being hot-unplugged



commit 21c714a0f25fedcd8f8511ab5e733aa5b8b09b07
Author: Hans de Goede <hdegoede redhat com>
Date:   Thu Oct 15 10:43:32 2020 +0200

    seat-native: Add support for tablet-mode-switch being hot-unplugged
    
    Add support for the (mostly theoretical) case of an input-device
    offering tablet-mode-switch functionality being unplugged.
    
    This makes the has_tablet_switch handling identical to the has_touchscreen
    handling, leading to more consistent code.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1506

 src/backends/native/meta-seat-native.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index b96ae3a250..5ae9c9b3ce 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -1461,31 +1461,33 @@ meta_seat_native_handle_device_event (ClutterSeat  *seat,
   MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
   ClutterInputDevice *device = event->device.device;
   MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
-  gboolean check_touch_mode;
+  gboolean is_touchscreen, is_tablet_switch;
 
-  check_touch_mode =
+  is_touchscreen =
     clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE;
+  is_tablet_switch =
+    libinput_device_has_capability (device_native->libinput_device,
+                                    LIBINPUT_DEVICE_CAP_SWITCH) &&
+    libinput_device_switch_has_switch (device_native->libinput_device,
+                                       LIBINPUT_SWITCH_TABLET_MODE);
 
   switch (event->type)
     {
       case CLUTTER_DEVICE_ADDED:
-        if (check_touch_mode)
+        if (is_touchscreen)
           seat_native->has_touchscreen = TRUE;
 
-        if (libinput_device_has_capability (device_native->libinput_device,
-                                            LIBINPUT_DEVICE_CAP_SWITCH) &&
-            libinput_device_switch_has_switch (device_native->libinput_device,
-                                               LIBINPUT_SWITCH_TABLET_MODE))
-          {
-            seat_native->has_tablet_switch = TRUE;
-            check_touch_mode = TRUE;
-          }
+        if (is_tablet_switch)
+          seat_native->has_tablet_switch = TRUE;
         break;
 
       case CLUTTER_DEVICE_REMOVED:
-        if (check_touch_mode)
+        if (is_touchscreen)
           seat_native->has_touchscreen = has_touchscreen (seat_native);
 
+        if (is_tablet_switch)
+          seat_native->has_tablet_switch = has_tablet_switch (seat_native);
+
         if (seat_native->repeat_timer && seat_native->repeat_device == device)
           meta_seat_native_clear_repeat_timer (seat_native);
         break;
@@ -1494,7 +1496,7 @@ meta_seat_native_handle_device_event (ClutterSeat  *seat,
         break;
     }
 
-  if (check_touch_mode)
+  if (is_touchscreen || is_tablet_switch)
     update_touch_mode (seat_native);
 
   return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]