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
This commit is contained in:
Jonas Ådahl 2019-01-23 19:09:17 +01:00
parent 6372e3e4db
commit a76107a19f
3 changed files with 76 additions and 0 deletions

View File

@ -51,6 +51,22 @@ meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *scree
y_out); 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 void
meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window, meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,

View File

@ -24,6 +24,7 @@
#include <stdint.h> #include <stdint.h>
#include <glib-object.h> #include <glib-object.h>
#include "backends/meta-cursor.h"
#include "meta/boxes.h" #include "meta/boxes.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -45,6 +46,12 @@ struct _MetaScreenCastWindowInterface
double *x_out, double *x_out,
double *y_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, void (*capture_into) (MetaScreenCastWindow *screen_cast_window,
MetaRectangle *bounds, MetaRectangle *bounds,
uint8_t *data); uint8_t *data);
@ -59,6 +66,12 @@ void meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *
double *x_out, double *x_out,
double *y_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, void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
MetaRectangle *bounds, MetaRectangle *bounds,
uint8_t *data); uint8_t *data);

View File

@ -1907,6 +1907,52 @@ meta_window_actor_transform_relative_position (MetaScreenCastWindow *screen_cast
*y_out = (double) v2.y; *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 static void
meta_window_actor_capture_into (MetaScreenCastWindow *screen_cast_window, meta_window_actor_capture_into (MetaScreenCastWindow *screen_cast_window,
MetaRectangle *bounds, MetaRectangle *bounds,
@ -1966,5 +2012,6 @@ screen_cast_window_iface_init (MetaScreenCastWindowInterface *iface)
{ {
iface->get_frame_bounds = meta_window_actor_get_frame_bounds; iface->get_frame_bounds = meta_window_actor_get_frame_bounds;
iface->transform_relative_position = meta_window_actor_transform_relative_position; 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; iface->capture_into = meta_window_actor_capture_into;
} }