[mutter] screen-cast-window: Add API to transform cursor state



commit a76107a19fea1162c31665d26d7427b298527ed8
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Jan 23 19:09:17 2019 +0100

    screen-cast-window: Add API to transform cursor state
    
    To be used to translate absolute cursor positions to relative positions,
    as well as to determine whether a cursor sprite is inside the stream or
    not. It also helps calculating the scale the cursor sprite needs to be
    scaled with to be in stream coordinate space.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/413

 src/backends/meta-screen-cast-window.c | 16 ++++++++++++
 src/backends/meta-screen-cast-window.h | 13 ++++++++++
 src/compositor/meta-window-actor.c     | 47 ++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
---
diff --git a/src/backends/meta-screen-cast-window.c b/src/backends/meta-screen-cast-window.c
index 9878b223f..5df8a3416 100644
--- a/src/backends/meta-screen-cast-window.c
+++ b/src/backends/meta-screen-cast-window.c
@@ -51,6 +51,22 @@ meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *scree
                                                                                        y_out);
 }
 
+gboolean
+meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window,
+                                                   MetaCursorSprite     *cursor_sprite,
+                                                   ClutterPoint         *cursor_position,
+                                                   float                *out_cursor_scale,
+                                                   ClutterPoint         *out_relative_cursor_position)
+{
+  MetaScreenCastWindowInterface *iface =
+    META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window);
+
+  return iface->transform_cursor_position (screen_cast_window,
+                                           cursor_sprite,
+                                           cursor_position,
+                                           out_cursor_scale,
+                                           out_relative_cursor_position);
+}
 
 void
 meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
diff --git a/src/backends/meta-screen-cast-window.h b/src/backends/meta-screen-cast-window.h
index ba70f9b85..447fade7b 100644
--- a/src/backends/meta-screen-cast-window.h
+++ b/src/backends/meta-screen-cast-window.h
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <glib-object.h>
 
+#include "backends/meta-cursor.h"
 #include "meta/boxes.h"
 
 G_BEGIN_DECLS
@@ -45,6 +46,12 @@ struct _MetaScreenCastWindowInterface
                                        double               *x_out,
                                        double               *y_out);
 
+  gboolean (*transform_cursor_position) (MetaScreenCastWindow *screen_cast_window,
+                                         MetaCursorSprite     *cursor_sprite,
+                                         ClutterPoint         *cursor_position,
+                                         float                *out_cursor_scale,
+                                         ClutterPoint         *out_relative_cursor_position);
+
   void (*capture_into) (MetaScreenCastWindow *screen_cast_window,
                         MetaRectangle        *bounds,
                         uint8_t              *data);
@@ -59,6 +66,12 @@ void meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *
                                                           double               *x_out,
                                                           double               *y_out);
 
+gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window,
+                                                            MetaCursorSprite     *cursor_sprite,
+                                                            ClutterPoint         *cursor_position,
+                                                            float                *out_cursor_scale,
+                                                            ClutterPoint         
*out_relative_cursor_position);
+
 void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
                                            MetaRectangle        *bounds,
                                            uint8_t              *data);
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index 0af96beca..616739223 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1907,6 +1907,52 @@ meta_window_actor_transform_relative_position (MetaScreenCastWindow *screen_cast
   *y_out = (double) v2.y;
 }
 
+static gboolean
+meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_window,
+                                             MetaCursorSprite     *cursor_sprite,
+                                             ClutterPoint         *cursor_position,
+                                             float                *out_cursor_scale,
+                                             ClutterPoint         *out_relative_cursor_position)
+{
+  MetaWindowActor *window_actor = META_WINDOW_ACTOR (screen_cast_window);
+  MetaWindowActorPrivate *priv =
+    meta_window_actor_get_instance_private (window_actor);
+  MetaWindow *window;
+
+  window = priv->window;
+  if (!meta_window_has_pointer (window))
+    return FALSE;
+
+  if (cursor_sprite &&
+      meta_cursor_sprite_get_cogl_texture (cursor_sprite) &&
+      out_cursor_scale)
+    {
+      MetaShapedTexture *stex;
+      double actor_scale;
+      float cursor_texture_scale;
+
+      stex = meta_surface_actor_get_texture (priv->surface);
+      clutter_actor_get_scale (CLUTTER_ACTOR (stex), &actor_scale, NULL);
+      cursor_texture_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
+
+      *out_cursor_scale = actor_scale / cursor_texture_scale;
+    }
+
+  if (out_relative_cursor_position)
+    {
+      MetaShapedTexture *stex;
+
+      stex = meta_surface_actor_get_texture (priv->surface);
+      clutter_actor_transform_stage_point (CLUTTER_ACTOR (stex),
+                                           cursor_position->x,
+                                           cursor_position->y,
+                                           &out_relative_cursor_position->x,
+                                           &out_relative_cursor_position->y);
+    }
+
+  return TRUE;
+}
+
 static void
 meta_window_actor_capture_into (MetaScreenCastWindow *screen_cast_window,
                                 MetaRectangle        *bounds,
@@ -1966,5 +2012,6 @@ screen_cast_window_iface_init (MetaScreenCastWindowInterface *iface)
 {
   iface->get_frame_bounds = meta_window_actor_get_frame_bounds;
   iface->transform_relative_position = meta_window_actor_transform_relative_position;
+  iface->transform_cursor_position = meta_window_actor_transform_cursor_position;
   iface->capture_into = meta_window_actor_capture_into;
 }


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