cursor-renderer: Add a cursor painted signal

This signal allows interested parties to be notified of a new cursor
frame being painted regardless of whether it's being painted by the
backend directly or if it's a software rendered cursor frame handled
by clutter.

https://bugzilla.gnome.org/show_bug.cgi?id=749913
This commit is contained in:
Rui Matos 2016-01-10 17:28:54 +01:00
parent 262e184fe7
commit 2c1d3e5b70
3 changed files with 53 additions and 0 deletions

View File

@ -42,11 +42,25 @@ struct _MetaCursorRendererPrivate
MetaCursorSprite *displayed_cursor;
MetaOverlay *stage_overlay;
gboolean handled_by_backend;
guint post_paint_func_id;
};
typedef struct _MetaCursorRendererPrivate MetaCursorRendererPrivate;
enum {
CURSOR_PAINTED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRenderer, meta_cursor_renderer, G_TYPE_OBJECT);
void
meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
{
g_signal_emit (renderer, signals[CURSOR_PAINTED], 0, cursor_sprite);
}
static void
queue_redraw (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
@ -76,6 +90,19 @@ queue_redraw (MetaCursorRenderer *renderer,
texture, &rect);
}
static gboolean
meta_cursor_renderer_post_paint (gpointer data)
{
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (data);
MetaCursorRendererPrivate *priv =
meta_cursor_renderer_get_instance_private (renderer);
if (priv->displayed_cursor && !priv->handled_by_backend)
meta_cursor_renderer_emit_painted (renderer, priv->displayed_cursor);
return TRUE;
}
static gboolean
meta_cursor_renderer_real_update_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
@ -97,6 +124,8 @@ meta_cursor_renderer_finalize (GObject *object)
if (priv->stage_overlay)
meta_stage_remove_cursor_overlay (META_STAGE (stage), priv->stage_overlay);
clutter_threads_remove_repaint_func (priv->post_paint_func_id);
G_OBJECT_CLASS (meta_cursor_renderer_parent_class)->finalize (object);
}
@ -107,11 +136,27 @@ meta_cursor_renderer_class_init (MetaCursorRendererClass *klass)
object_class->finalize = meta_cursor_renderer_finalize;
klass->update_cursor = meta_cursor_renderer_real_update_cursor;
signals[CURSOR_PAINTED] = g_signal_new ("cursor-painted",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
}
static void
meta_cursor_renderer_init (MetaCursorRenderer *renderer)
{
MetaCursorRendererPrivate *priv =
meta_cursor_renderer_get_instance_private (renderer);
priv->post_paint_func_id =
clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
meta_cursor_renderer_post_paint,
renderer,
NULL);
}
MetaRectangle

View File

@ -78,4 +78,7 @@ void meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *rende
MetaCursorSprite *cursor_sprite,
XcursorImage *xc_image);
void meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);
#endif /* META_CURSOR_RENDERER_H */

View File

@ -216,6 +216,7 @@ update_hw_cursor (MetaCursorRendererNative *native,
MetaCRTC *crtcs;
unsigned int i, n_crtcs;
MetaRectangle rect;
gboolean painted = FALSE;
monitors = meta_monitor_manager_get ();
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
@ -247,8 +248,12 @@ update_hw_cursor (MetaCursorRendererNative *native,
drmModeMoveCursor (priv->drm_fd, crtcs[i].crtc_id,
rect.x - crtc_rect->x,
rect.y - crtc_rect->y);
painted = TRUE;
}
}
if (painted)
meta_cursor_renderer_emit_painted (renderer, cursor_sprite);
}
static gboolean