[mutter/wip/tablet-protocol: 1/15] wayland: Refactor MetaWaylandSurfaceRoleCursor
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/tablet-protocol: 1/15] wayland: Refactor MetaWaylandSurfaceRoleCursor
- Date: Wed, 21 Oct 2015 18:04:57 +0000 (UTC)
commit c5cf2deb693aab66f31c9f8af9a0b88926a8b619
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Oct 21 16:36:44 2015 +0200
wayland: Refactor MetaWaylandSurfaceRoleCursor
Move into meta-wayland-surface.[ch], with the rest of the role
declarations, and make generic enough to work for pointer and
additional (eg. tablet) cursors.
src/wayland/meta-wayland-pointer.c | 200 ++------------------------------
src/wayland/meta-wayland-pointer.h | 10 +-
src/wayland/meta-wayland-surface.c | 225 ++++++++++++++++++++++++++++++++++++
src/wayland/meta-wayland-surface.h | 20 +++
4 files changed, 259 insertions(+), 196 deletions(-)
---
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 894a64d..20002b6 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -66,22 +66,6 @@
#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int (10)
-struct _MetaWaylandSurfaceRoleCursor
-{
- MetaWaylandSurfaceRole parent;
-
- int hot_x;
- int hot_y;
- MetaCursorSprite *cursor_sprite;
-};
-
-G_DEFINE_TYPE (MetaWaylandSurfaceRoleCursor,
- meta_wayland_surface_role_cursor,
- META_TYPE_WAYLAND_SURFACE_ROLE);
-
-static void
-meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer);
-
static MetaWaylandPointerClient *
meta_wayland_pointer_client_new (void)
{
@@ -742,7 +726,7 @@ meta_wayland_pointer_get_relative_coordinates (MetaWaylandPointer *pointer,
*sy = wl_fixed_from_double (yf) / surface->scale;
}
-static void
+void
meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
{
MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
@@ -756,7 +740,7 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (pointer->cursor_surface->role);
- cursor_sprite = cursor_role->cursor_sprite;
+ cursor_sprite = meta_wayland_surface_role_cursor_get_sprite (cursor_role, NULL, NULL);
}
meta_cursor_tracker_set_window_cursor (cursor_tracker, cursor_sprite);
@@ -768,68 +752,6 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
}
static void
-update_cursor_sprite_texture (MetaWaylandSurface *surface)
-{
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (meta_get_backend ());
- MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
- MetaWaylandSurfaceRoleCursor *cursor_role =
- META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
- MetaCursorSprite *cursor_sprite = cursor_role->cursor_sprite;
- ClutterBackend *clutter_backend = clutter_get_default_backend ();
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglTexture *texture;
-
- if (surface->buffer)
- {
- struct wl_resource *buffer;
-
- buffer = surface->buffer->resource;
- texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context,
- buffer,
- NULL);
-
- meta_cursor_sprite_set_texture (cursor_sprite,
- texture,
- cursor_role->hot_x * surface->scale,
- cursor_role->hot_y * surface->scale);
- meta_cursor_renderer_realize_cursor_from_wl_buffer (cursor_renderer,
- cursor_sprite,
- buffer);
- cogl_object_unref (texture);
- }
- else
- {
- meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
- }
-
- if (cursor_sprite == meta_cursor_tracker_get_displayed_cursor (cursor_tracker))
- meta_cursor_renderer_force_update (cursor_renderer);
-}
-
-static void
-cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
- int x,
- int y,
- MetaWaylandSurfaceRoleCursor *cursor_role)
-{
- MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_role);
- MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
- MetaDisplay *display = meta_get_display ();
- MetaScreen *screen = display->screen;
- const MetaMonitorInfo *monitor;
-
- if (!meta_xwayland_is_xwayland_surface (surface))
- {
- monitor = meta_screen_get_monitor_for_point (screen, x, y);
- meta_cursor_sprite_set_texture_scale (cursor_sprite,
- (float)monitor->scale / surface->scale);
- }
- meta_wayland_surface_update_outputs (surface);
-}
-
-static void
meta_wayland_pointer_set_cursor_surface (MetaWaylandPointer *pointer,
MetaWaylandSurface *cursor_surface)
{
@@ -877,23 +799,17 @@ pointer_set_cursor (struct wl_client *client,
if (surface)
{
+ MetaCursorRenderer *cursor_renderer =
+ meta_backend_get_cursor_renderer (meta_get_backend ());
MetaWaylandSurfaceRoleCursor *cursor_role;
+ MetaCursorSprite *sprite;
cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
- if (!cursor_role->cursor_sprite)
- {
- cursor_role->cursor_sprite = meta_cursor_sprite_new ();
- g_signal_connect_object (cursor_role->cursor_sprite,
- "prepare-at",
- G_CALLBACK (cursor_sprite_prepare_at),
- cursor_role,
- 0);
- }
-
- cursor_role->hot_x = hot_x;
- cursor_role->hot_y = hot_y;
-
- update_cursor_sprite_texture (surface);
+ sprite = meta_cursor_sprite_new ();
+ meta_wayland_surface_role_cursor_set_renderer (cursor_role,
+ cursor_renderer);
+ meta_wayland_surface_role_cursor_set_sprite (cursor_role, sprite,
+ hot_x, hot_y);
}
meta_wayland_pointer_set_cursor_surface (pointer, surface);
@@ -960,99 +876,3 @@ meta_wayland_pointer_get_top_popup (MetaWaylandPointer *pointer)
grab = (MetaWaylandPopupGrab*)pointer->grab;
return meta_wayland_popup_grab_get_top_popup(grab);
}
-
-static void
-cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
-{
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (surface_role);
-
- meta_wayland_surface_queue_pending_frame_callbacks (surface);
-}
-
-static void
-cursor_surface_role_commit (MetaWaylandSurfaceRole *surface_role,
- MetaWaylandPendingState *pending)
-{
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (surface_role);
-
- meta_wayland_surface_queue_pending_state_frame_callbacks (surface, pending);
-
- if (pending->newly_attached)
- update_cursor_sprite_texture (surface);
-}
-
-static gboolean
-cursor_surface_role_is_on_output (MetaWaylandSurfaceRole *role,
- MetaMonitorInfo *monitor)
-{
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (role);
- MetaWaylandPointer *pointer = &surface->compositor->seat->pointer;
- MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (meta_get_backend ());
- MetaWaylandSurfaceRoleCursor *cursor_role =
- META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
- MetaCursorSprite *displayed_cursor_sprite;
- MetaRectangle rect;
-
- if (surface != pointer->cursor_surface)
- return FALSE;
-
- displayed_cursor_sprite =
- meta_cursor_tracker_get_displayed_cursor (cursor_tracker);
- if (!displayed_cursor_sprite)
- return FALSE;
-
- if (cursor_role->cursor_sprite != displayed_cursor_sprite)
- return FALSE;
-
- rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_role->cursor_sprite);
- return meta_rectangle_overlap (&rect, &monitor->rect);
-}
-
-static void
-cursor_surface_role_dispose (GObject *object)
-{
- MetaWaylandSurfaceRoleCursor *cursor_role =
- META_WAYLAND_SURFACE_ROLE_CURSOR (object);
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
- MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
- MetaWaylandPointer *pointer = &compositor->seat->pointer;
- MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
-
- g_signal_handlers_disconnect_by_func (cursor_tracker,
- (gpointer) cursor_sprite_prepare_at,
- cursor_role);
-
- if (pointer->cursor_surface == surface)
- pointer->cursor_surface = NULL;
- meta_wayland_pointer_update_cursor_surface (pointer);
-
- g_clear_object (&cursor_role->cursor_sprite);
-
- G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
-}
-
-static void
-meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
-{
-}
-
-static void
-meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *klass)
-{
- MetaWaylandSurfaceRoleClass *surface_role_class =
- META_WAYLAND_SURFACE_ROLE_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- surface_role_class->assigned = cursor_surface_role_assigned;
- surface_role_class->commit = cursor_surface_role_commit;
- surface_role_class->is_on_output = cursor_surface_role_is_on_output;
-
- object_class->dispose = cursor_surface_role_dispose;
-}
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 7e31da9..d14e1ad 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -31,12 +31,6 @@
#include <meta/meta-cursor-tracker.h>
-#define META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR (meta_wayland_surface_role_cursor_get_type ())
-G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleCursor,
- meta_wayland_surface_role_cursor,
- META, WAYLAND_SURFACE_ROLE_CURSOR,
- MetaWaylandSurfaceRole);
-
struct _MetaWaylandPointerGrabInterface
{
void (*focus) (MetaWaylandPointerGrab *grab,
@@ -142,4 +136,8 @@ MetaWaylandPointerClient * meta_wayland_pointer_get_pointer_client (MetaWaylandP
struct wl_client *client);
void meta_wayland_pointer_unbind_pointer_client_resource (struct wl_resource *resource);
+void meta_wayland_surface_cursor_update (MetaWaylandSurface *cursor_surface);
+
+void meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer);
+
#endif /* META_WAYLAND_POINTER_H */
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index f8f6ffc..d63a8fa 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -54,6 +54,7 @@
#include "meta-surface-actor.h"
#include "meta-surface-actor-wayland.h"
#include "meta-xwayland-private.h"
+#include "meta-xwayland.h"
typedef struct _MetaWaylandSurfaceRolePrivate
{
@@ -124,6 +125,20 @@ G_DEFINE_TYPE (MetaWaylandSurfaceRoleDND,
meta_wayland_surface_role_dnd,
META_TYPE_WAYLAND_SURFACE_ROLE);
+struct _MetaWaylandSurfaceRoleCursor
+{
+ MetaWaylandSurfaceRole parent;
+
+ int hot_x;
+ int hot_y;
+ MetaCursorSprite *cursor_sprite;
+ MetaCursorRenderer *cursor_renderer;
+};
+
+G_DEFINE_TYPE (MetaWaylandSurfaceRoleCursor,
+ meta_wayland_surface_role_cursor,
+ META_TYPE_WAYLAND_SURFACE_ROLE);
+
static void
meta_wayland_surface_role_assigned (MetaWaylandSurfaceRole *surface_role);
@@ -2570,3 +2585,213 @@ meta_wayland_surface_role_subsurface_class_init (MetaWaylandSurfaceRoleSubsurfac
surface_role_class->commit = subsurface_surface_commit;
surface_role_class->is_on_output = actor_surface_is_on_output;
}
+
+static void
+update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+ MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE
(cursor_role));
+ MetaCursorSprite *cursor_sprite = cursor_role->cursor_sprite;
+ ClutterBackend *clutter_backend = clutter_get_default_backend ();
+ CoglContext *cogl_context =
+ clutter_backend_get_cogl_context (clutter_backend);
+ CoglTexture *texture;
+
+ if (!cursor_role->cursor_renderer || !cursor_role->cursor_sprite)
+ return;
+
+ if (surface->buffer)
+ {
+ struct wl_resource *buffer;
+
+ buffer = surface->buffer->resource;
+ texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context,
+ buffer,
+ NULL);
+
+ meta_cursor_sprite_set_texture (cursor_sprite,
+ texture,
+ cursor_role->hot_x * surface->scale,
+ cursor_role->hot_y * surface->scale);
+ meta_cursor_renderer_realize_cursor_from_wl_buffer (cursor_role->cursor_renderer,
+ cursor_sprite,
+ buffer);
+ cogl_object_unref (texture);
+ }
+ else
+ {
+ meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
+ }
+
+ meta_cursor_renderer_force_update (cursor_role->cursor_renderer);
+}
+
+static void
+cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
+ int x,
+ int y,
+ MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+ MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_role);
+ MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
+ MetaDisplay *display = meta_get_display ();
+ MetaScreen *screen = display->screen;
+ const MetaMonitorInfo *monitor;
+
+ if (!meta_xwayland_is_xwayland_surface (surface))
+ {
+ monitor = meta_screen_get_monitor_for_point (screen, x, y);
+ meta_cursor_sprite_set_texture_scale (cursor_sprite,
+ (float)monitor->scale / surface->scale);
+ }
+ meta_wayland_surface_update_outputs (surface);
+}
+
+static void
+cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
+{
+ MetaWaylandSurface *surface =
+ meta_wayland_surface_role_get_surface (surface_role);
+
+ meta_wayland_surface_queue_pending_frame_callbacks (surface);
+}
+
+static void
+cursor_surface_role_commit (MetaWaylandSurfaceRole *surface_role,
+ MetaWaylandPendingState *pending)
+{
+ MetaWaylandSurface *surface =
+ meta_wayland_surface_role_get_surface (surface_role);
+
+ meta_wayland_surface_queue_pending_state_frame_callbacks (surface, pending);
+
+ if (pending->newly_attached)
+ update_cursor_sprite_texture (META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role));
+}
+
+static gboolean
+cursor_surface_role_is_on_output (MetaWaylandSurfaceRole *role,
+ MetaMonitorInfo *monitor)
+{
+ MetaWaylandSurface *surface =
+ meta_wayland_surface_role_get_surface (role);
+ MetaWaylandSurfaceRoleCursor *cursor_role =
+ META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
+ MetaRectangle rect;
+
+ rect = meta_cursor_renderer_calculate_rect (cursor_role->cursor_renderer,
+ cursor_role->cursor_sprite);
+ return meta_rectangle_overlap (&rect, &monitor->rect);
+}
+
+static void
+cursor_surface_role_dispose (GObject *object)
+{
+ MetaWaylandSurfaceRoleCursor *cursor_role =
+ META_WAYLAND_SURFACE_ROLE_CURSOR (object);
+ MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
+ MetaWaylandPointer *pointer = &compositor->seat->pointer;
+ MetaWaylandSurface *surface =
+ meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
+
+ meta_wayland_surface_role_cursor_set_sprite (cursor_role, NULL, 0, 0);
+
+ if (pointer->cursor_surface == surface)
+ pointer->cursor_surface = NULL;
+ meta_wayland_pointer_update_cursor_surface (pointer);
+
+ G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
+}
+
+static void
+meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
+{
+}
+
+static void
+meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *klass)
+{
+ MetaWaylandSurfaceRoleClass *surface_role_class =
+ META_WAYLAND_SURFACE_ROLE_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ surface_role_class->assigned = cursor_surface_role_assigned;
+ surface_role_class->commit = cursor_surface_role_commit;
+ surface_role_class->is_on_output = cursor_surface_role_is_on_output;
+
+ object_class->dispose = cursor_surface_role_dispose;
+}
+
+void
+meta_wayland_surface_role_cursor_set_sprite (MetaWaylandSurfaceRoleCursor *cursor_role,
+ MetaCursorSprite *cursor_sprite,
+ gint hotspot_x,
+ gint hotspot_y)
+{
+ if (cursor_role->cursor_sprite == cursor_sprite &&
+ cursor_role->hot_x == hotspot_x &&
+ cursor_role->hot_y == hotspot_y)
+ return;
+
+ if (cursor_role->cursor_sprite != cursor_sprite)
+ {
+ if (cursor_role->cursor_sprite)
+ {
+ g_signal_handlers_disconnect_by_func (cursor_role->cursor_sprite,
+ cursor_sprite_prepare_at,
+ cursor_role);
+ g_object_unref (cursor_role->cursor_sprite);
+ }
+
+ if (cursor_sprite)
+ {
+ g_object_ref (cursor_sprite);
+ g_signal_connect_object (cursor_sprite,
+ "prepare-at",
+ G_CALLBACK (cursor_sprite_prepare_at),
+ cursor_role,
+ 0);
+ }
+
+ cursor_role->cursor_sprite = cursor_sprite;
+ }
+
+ cursor_role->hot_x = hotspot_x;
+ cursor_role->hot_y = hotspot_y;
+
+ update_cursor_sprite_texture (cursor_role);
+}
+
+MetaCursorSprite *
+meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor *cursor_role,
+ gint *hotspot_x,
+ gint *hotspot_y)
+{
+ if (hotspot_x)
+ *hotspot_x = cursor_role->hot_x;
+ if (hotspot_y)
+ *hotspot_y = cursor_role->hot_y;
+
+ return cursor_role->cursor_sprite;
+}
+
+void
+meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role,
+ MetaCursorRenderer *renderer)
+{
+ if (cursor_role->cursor_renderer == renderer)
+ return;
+
+ if (renderer)
+ g_object_ref (renderer);
+ if (cursor_role->cursor_renderer)
+ g_object_unref (cursor_role->cursor_renderer);
+
+ cursor_role->cursor_renderer = renderer;
+ update_cursor_sprite_texture (cursor_role);
+}
+
+MetaCursorRenderer *
+meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+ return cursor_role->cursor_renderer;
+}
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index 94ba100..0846c22 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -31,6 +31,7 @@
#include "meta-wayland-types.h"
#include "meta-surface-actor.h"
#include "backends/meta-monitor-manager-private.h"
+#include "backends/meta-cursor-renderer.h"
typedef struct _MetaWaylandPendingState MetaWaylandPendingState;
@@ -90,6 +91,12 @@ G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleDND,
META, WAYLAND_SURFACE_ROLE_DND,
MetaWaylandSurfaceRole);
+#define META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR (meta_wayland_surface_role_cursor_get_type ())
+G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleCursor,
+ meta_wayland_surface_role_cursor,
+ META, WAYLAND_SURFACE_ROLE_CURSOR,
+ MetaWaylandSurfaceRole);
+
struct _MetaWaylandPendingState
{
/* wl_surface.attach */
@@ -252,4 +259,17 @@ void meta_wayland_surface_queue_pending_state_frame_callbacks (Me
MetaWaylandSurface * meta_wayland_surface_role_get_surface (MetaWaylandSurfaceRole *role);
+
+void meta_wayland_surface_role_cursor_set_sprite (MetaWaylandSurfaceRoleCursor
*cursor_role,
+ MetaCursorSprite
*cursor_sprite,
+ gint hotspot_x,
+ gint hotspot_y);
+MetaCursorSprite * meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor
*cursor_role,
+ gint *hotspot_x,
+ gint *hotspot_y);
+void meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor
*cursor_role,
+ MetaCursorRenderer *renderer);
+MetaCursorRenderer * meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor
*cursor_role);
+
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]