[mutter/wip/carlosg/input-thread: 67/97] backends/native: Use viewport info to find out stage extents




commit 6298928065af927b7c11e310930f1916466c775a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jul 31 19:11:32 2020 +0200

    backends/native: Use viewport info to find out stage extents
    
    This information is equivalent to the stage extents, this just
    leaves meta_seat_native_get_stage() used for setting event->any.stage,
    which is a tiny lame excuse.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/native/meta-input-device-native.c |  7 ++---
 src/backends/native/meta-input-device-native.h |  2 +-
 src/backends/native/meta-seat-native.c         | 39 +++++++++++++-------------
 3 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
index b8ae09baf5..4c70f2c6c8 100644
--- a/src/backends/native/meta-input-device-native.c
+++ b/src/backends/native/meta-input-device-native.c
@@ -1437,17 +1437,16 @@ meta_input_device_native_get_libinput_device (ClutterInputDevice *device)
 
 void
 meta_input_device_native_translate_coordinates (ClutterInputDevice *device,
-                                                ClutterStage       *stage,
+                                                MetaViewportInfo   *viewports,
                                                 float              *x,
                                                 float              *y)
 {
   MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (device);
   double min_x = 0, min_y = 0, max_x = 1, max_y = 1;
-  double stage_width, stage_height;
+  float stage_width, stage_height;
   double x_d, y_d;
 
-  stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
-  stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
+  meta_viewport_info_get_extents (viewports, &stage_width, &stage_height);
   x_d = *x / stage_width;
   y_d = *y / stage_height;
 
diff --git a/src/backends/native/meta-input-device-native.h b/src/backends/native/meta-input-device-native.h
index fa5b3260e4..25b50d1059 100644
--- a/src/backends/native/meta-input-device-native.h
+++ b/src/backends/native/meta-input-device-native.h
@@ -126,7 +126,7 @@ ClutterInputDeviceType    meta_input_device_native_determine_type  (struct libin
 
 
 void                      meta_input_device_native_translate_coordinates (ClutterInputDevice *device,
-                                                                          ClutterStage       *stage,
+                                                                          MetaViewportInfo   *viewports,
                                                                           float              *x,
                                                                           float              *y);
 
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 7f6be0ff34..0194e9fbb5 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -391,7 +391,6 @@ new_absolute_motion_event (MetaSeatNative     *seat,
                            float               y,
                            double             *axes)
 {
-  ClutterStage *stage = meta_seat_native_get_stage (seat);
   ClutterEvent *event;
 
   event = clutter_event_new (CLUTTER_MOTION);
@@ -411,9 +410,16 @@ new_absolute_motion_event (MetaSeatNative     *seat,
   meta_xkb_translate_state (event, seat->xkb, seat->button_state);
   event->motion.x = x;
   event->motion.y = y;
-  meta_input_device_native_translate_coordinates (input_device, stage,
-                                                  &event->motion.x,
-                                                  &event->motion.y);
+
+  /* This may happen early at startup */
+  if (seat->viewports)
+    {
+      meta_input_device_native_translate_coordinates (input_device,
+                                                      seat->viewports,
+                                                      &event->motion.x,
+                                                      &event->motion.y);
+    }
+
   event->motion.axes = axes;
   clutter_event_set_device (event, seat->core_pointer);
   clutter_event_set_source_device (event, input_device);
@@ -799,7 +805,6 @@ meta_seat_native_notify_touch_event (MetaSeatNative     *seat,
                                      double              x,
                                      double              y)
 {
-  ClutterStage *stage = meta_seat_native_get_stage (seat);
   ClutterEvent *event = NULL;
 
   event = clutter_event_new (evtype);
@@ -808,7 +813,8 @@ meta_seat_native_notify_touch_event (MetaSeatNative     *seat,
   event->touch.time = us2ms (time_us);
   event->touch.x = x;
   event->touch.y = y;
-  meta_input_device_native_translate_coordinates (input_device, stage,
+  meta_input_device_native_translate_coordinates (input_device,
+                                                  seat->viewports,
                                                   &event->touch.x,
                                                   &event->touch.y);
 
@@ -1819,7 +1825,6 @@ process_tablet_axis (MetaSeatNative        *seat,
                      struct libinput_event *event)
 {
   struct libinput_device *libinput_device = libinput_event_get_device (event);
-  ClutterStage *stage = meta_seat_native_get_stage (seat);
   uint64_t time;
   double x, y, dx, dy, *axes;
   float stage_width, stage_height;
@@ -1836,8 +1841,7 @@ process_tablet_axis (MetaSeatNative        *seat,
   if (!axes)
     return;
 
-  stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
-  stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
+  meta_viewport_info_get_extents (seat->viewports, &stage_width, &stage_height);
 
   time = libinput_event_tablet_tool_get_time_usec (tablet_event);
 
@@ -1960,13 +1964,12 @@ process_device_event (MetaSeatNative        *seat,
         uint64_t time_us;
         double x, y;
         float stage_width, stage_height;
-        ClutterStage *stage = meta_seat_native_get_stage (seat);
         struct libinput_event_pointer *motion_event =
           libinput_event_get_pointer_event (event);
         device = libinput_device_get_user_data (libinput_device);
 
-        stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
-        stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
+        meta_viewport_info_get_extents (seat->viewports,
+                                        &stage_width, &stage_height);
 
         time_us = libinput_event_pointer_get_time_usec (motion_event);
         x = libinput_event_pointer_get_absolute_x_transformed (motion_event,
@@ -2061,7 +2064,6 @@ process_device_event (MetaSeatNative        *seat,
         double x, y;
         float stage_width, stage_height;
         MetaSeatNative *seat;
-        ClutterStage *stage;
         MetaTouchState *touch_state;
         struct libinput_event_touch *touch_event =
           libinput_event_get_touch_event (event);
@@ -2069,10 +2071,9 @@ process_device_event (MetaSeatNative        *seat,
         device = libinput_device_get_user_data (libinput_device);
         device_evdev = META_INPUT_DEVICE_NATIVE (device);
         seat = meta_input_device_native_get_seat (device_evdev);
-        stage = meta_seat_native_get_stage (seat);
 
-        stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
-        stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
+        meta_viewport_info_get_extents (seat->viewports,
+                                        &stage_width, &stage_height);
 
         seat_slot = libinput_event_touch_get_seat_slot (touch_event);
         time_us = libinput_event_touch_get_time_usec (touch_event);
@@ -2129,7 +2130,6 @@ process_device_event (MetaSeatNative        *seat,
         double x, y;
         float stage_width, stage_height;
         MetaSeatNative *seat;
-        ClutterStage *stage;
         MetaTouchState *touch_state;
         struct libinput_event_touch *touch_event =
           libinput_event_get_touch_event (event);
@@ -2137,10 +2137,9 @@ process_device_event (MetaSeatNative        *seat,
         device = libinput_device_get_user_data (libinput_device);
         device_evdev = META_INPUT_DEVICE_NATIVE (device);
         seat = meta_input_device_native_get_seat (device_evdev);
-        stage = meta_seat_native_get_stage (seat);
 
-        stage_width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
-        stage_height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
+        meta_viewport_info_get_extents (seat->viewports,
+                                        &stage_width, &stage_height);
 
         seat_slot = libinput_event_touch_get_seat_slot (touch_event);
         time_us = libinput_event_touch_get_time_usec (touch_event);


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