st/icon: Store paint scaled icon size instead of normal size

This makes it easier to track size changes when the paint scale changes,
since in those cases we basically want to do the same thing as when the
normal icon size changes: Request a new texture from the cache.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/953>
This commit is contained in:
Jonas Dreßler 2019-11-21 18:01:06 +07:00 committed by Marge Bot
parent 67596e7c83
commit 13562033d7

View File

@ -334,7 +334,9 @@ st_icon_init (StIcon *self)
CLUTTER_BIN_ALIGNMENT_FILL); CLUTTER_BIN_ALIGNMENT_FILL);
clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout_manager); clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout_manager);
self->priv->icon_size = DEFAULT_ICON_SIZE; /* Set the icon size to -1 here to make sure we apply the scale to the
* default size on the first "style-changed" signal. */
self->priv->icon_size = -1;
self->priv->prop_icon_size = -1; self->priv->prop_icon_size = -1;
self->priv->shadow_pipeline = NULL; self->priv->shadow_pipeline = NULL;
@ -462,6 +464,9 @@ st_icon_update (StIcon *icon)
if (theme_node == NULL) if (theme_node == NULL)
return; return;
if (priv->icon_size <= 0)
return;
stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon)); stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon));
context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage)); context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage));
g_object_get (context, "scale-factor", &paint_scale, NULL); g_object_get (context, "scale-factor", &paint_scale, NULL);
@ -472,7 +477,7 @@ st_icon_update (StIcon *icon)
priv->pending_texture = st_texture_cache_load_gicon (cache, priv->pending_texture = st_texture_cache_load_gicon (cache,
theme_node, theme_node,
priv->gicon, priv->gicon,
priv->icon_size, priv->icon_size / paint_scale,
paint_scale, paint_scale,
resource_scale); resource_scale);
@ -480,7 +485,7 @@ st_icon_update (StIcon *icon)
priv->pending_texture = st_texture_cache_load_gicon (cache, priv->pending_texture = st_texture_cache_load_gicon (cache,
theme_node, theme_node,
priv->fallback_gicon, priv->fallback_gicon,
priv->icon_size, priv->icon_size / paint_scale,
paint_scale, paint_scale,
resource_scale); resource_scale);
@ -488,7 +493,7 @@ st_icon_update (StIcon *icon)
priv->pending_texture = st_texture_cache_load_gicon (cache, priv->pending_texture = st_texture_cache_load_gicon (cache,
theme_node, theme_node,
default_gicon, default_gicon,
priv->icon_size, priv->icon_size / paint_scale,
paint_scale, paint_scale,
resource_scale); resource_scale);
@ -519,33 +524,30 @@ st_icon_update_icon_size (StIcon *icon)
{ {
StIconPrivate *priv = icon->priv; StIconPrivate *priv = icon->priv;
int new_size; int new_size;
gint scale = 1;
if (priv->prop_icon_size > 0)
new_size = priv->prop_icon_size;
else if (priv->theme_icon_size > 0)
{
gint scale;
ClutterActor *stage; ClutterActor *stage;
StThemeContext *context; StThemeContext *context;
/* The theme will give us an already-scaled size, so we
* undo it here, as priv->icon_size is in unscaled pixels.
*/
stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon)); stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon));
if (stage != NULL)
{
context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage)); context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage));
g_object_get (context, "scale-factor", &scale, NULL); g_object_get (context, "scale-factor", &scale, NULL);
new_size = (gint) (priv->theme_icon_size / scale);
} }
if (priv->prop_icon_size > 0)
new_size = priv->prop_icon_size * scale;
else if (priv->theme_icon_size > 0)
new_size = priv->theme_icon_size;
else else
new_size = DEFAULT_ICON_SIZE; new_size = DEFAULT_ICON_SIZE * scale;
if (new_size != priv->icon_size) if (new_size != priv->icon_size)
{ {
clutter_actor_queue_relayout (CLUTTER_ACTOR (icon));
priv->icon_size = new_size; priv->icon_size = new_size;
return TRUE; return TRUE;
} }
else
return FALSE; return FALSE;
} }