From 9f4ae9618ae6b5d73c48c8d43976e4b0e72b9863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 11 May 2017 06:30:04 +0200 Subject: [PATCH] st-widget: Introduce widget resource scale This commit makes StWidget manage the scale of which its associated resources should be multiplied with. The resource scale is calculated by clutter, and is retrieved by clutter_actor_get_resource_scale(). Due to the resource scale not always being available, the getter may fail, and the actual widget that draws the content will have to deal with this situation. As the resource scale depends on where on the stage the widget is drawn, the resource scale will in general be available once the widget is mapped. https://bugzilla.gnome.org/show_bug.cgi?id=765011 --- src/st/st-widget.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/st/st-widget.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/st/st-widget.c b/src/st/st-widget.c index d12dbb3e2..78053804b 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -121,6 +121,7 @@ enum { STYLE_CHANGED, POPUP_MENU, + RESOURCE_SCALE_CHANGED, LAST_SIGNAL }; @@ -452,6 +453,7 @@ static void st_widget_parent_set (ClutterActor *widget, ClutterActor *old_parent) { + StWidget *self = ST_WIDGET (widget); ClutterActorClass *parent_class; ClutterActor *new_parent; @@ -463,7 +465,7 @@ st_widget_parent_set (ClutterActor *widget, /* don't send the style changed signal if we no longer have a parent actor */ if (new_parent) - st_widget_style_changed (ST_WIDGET (widget)); + st_widget_style_changed (self); } static void @@ -1019,6 +1021,21 @@ st_widget_class_init (StWidgetClass *klass) G_STRUCT_OFFSET (StWidgetClass, popup_menu), NULL, NULL, NULL, G_TYPE_NONE, 0); + + /** + * StWidget::resource-scale-changed: + * @widget: the #StWidget + * + * Emitted when the paint scale that the widget will be painted as + * changed. + */ + signals[RESOURCE_SCALE_CHANGED] = + g_signal_new ("resource-scale-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (StWidgetClass, resource_scale_changed), + NULL, NULL, NULL, + G_TYPE_NONE, 0); } /** @@ -1448,6 +1465,23 @@ st_widget_get_style (StWidget *actor) return ST_WIDGET_PRIVATE (actor)->inline_style; } +/** + * st_widget_get_resource_scale: + * @widget: A #StWidget + * @resource_scale: (out): return location for the resource scale + * + * Retrieves the resource scale for this #StWidget, if available. + * + * The resource scale refers to the scale the actor should use for its resources. + */ +gboolean +st_widget_get_resource_scale (StWidget *widget, + float *resource_scale) +{ + return clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget), + resource_scale); +} + static void st_widget_name_notify (StWidget *widget, GParamSpec *pspec, @@ -1456,6 +1490,14 @@ st_widget_name_notify (StWidget *widget, st_widget_style_changed (widget); } +static void +st_widget_resource_scale_notify (StWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + g_signal_emit (widget, signals[RESOURCE_SCALE_CHANGED], 0); +} + static void st_widget_reactive_notify (StWidget *widget, GParamSpec *pspec, @@ -1536,6 +1578,7 @@ st_widget_init (StWidget *actor) /* connect style changed */ g_signal_connect (actor, "notify::name", G_CALLBACK (st_widget_name_notify), NULL); + g_signal_connect (actor, "notify::resource-scale", G_CALLBACK (st_widget_resource_scale_notify), NULL); g_signal_connect (actor, "notify::reactive", G_CALLBACK (st_widget_reactive_notify), NULL); g_signal_connect (actor, "notify::first-child", G_CALLBACK (st_widget_first_child_notify), NULL); diff --git a/src/st/st-widget.h b/src/st/st-widget.h index 36a632567..7c76c5136 100644 --- a/src/st/st-widget.h +++ b/src/st/st-widget.h @@ -63,6 +63,7 @@ struct _StWidgetClass /* signals */ void (* style_changed) (StWidget *self); void (* popup_menu) (StWidget *self); + void (* resource_scale_changed) (StWidget *self); /* vfuncs */ @@ -137,6 +138,8 @@ StThemeNode * st_widget_peek_theme_node (StWidget *widg GList * st_widget_get_focus_chain (StWidget *widget); void st_widget_paint_background (StWidget *widget); +gboolean st_widget_get_resource_scale (StWidget *widget, + float *resource_scale); /* debug methods */ char *st_describe_actor (ClutterActor *actor);