st/scroll-view-fade: Add :extend-fade-area property

Since commit f60a469a34, everything outside the fade area is painted
fully transparent. That is required for the fade effect during app
grid navigation, to prevent unfaded parts of surrounding pages
becoming visible on wide-screen displays.

However in most other cases, that behavior is the exact opposite
of what we want: Elements outside the fade area (like scroll bars)
should never fade.

In order to fix the regular case, hide the new behavior behind a
property.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4234

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1831>
This commit is contained in:
Florian Müllner 2021-05-03 19:39:06 +02:00 committed by Marge Bot
parent 2b2a71832a
commit 3eda672929
2 changed files with 47 additions and 5 deletions

View File

@ -45,6 +45,7 @@ struct _StScrollViewFade
StAdjustment *hadjustment;
guint fade_edges : 1;
guint extend_fade_area: 1;
ClutterMargin fade_margins;
};
@ -58,6 +59,7 @@ enum {
PROP_FADE_MARGINS,
PROP_FADE_EDGES,
PROP_EXTEND_FADE_AREA,
N_PROPS
};
@ -168,6 +170,7 @@ st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect,
value <= 1.0 :
(rtl ? value > 0.0 : value < 1.0));
clutter_shader_effect_set_uniform (shader, "extend_fade_area", G_TYPE_INT, 1, self->extend_fade_area);
clutter_shader_effect_set_uniform (shader, "fade_offset_top", G_TYPE_FLOAT, 1, ABS (self->fade_margins.top));
clutter_shader_effect_set_uniform (shader, "fade_offset_bottom", G_TYPE_FLOAT, 1, ABS (self->fade_margins.bottom));
clutter_shader_effect_set_uniform (shader, "fade_offset_left", G_TYPE_FLOAT, 1, ABS (self->fade_margins.left));
@ -325,6 +328,21 @@ st_scroll_view_fade_set_fade_edges (StScrollViewFade *self,
g_object_thaw_notify (G_OBJECT (self));
}
static void
st_scroll_view_fade_set_extend_fade_area (StScrollViewFade *self,
gboolean extend_fade_area)
{
if (self->extend_fade_area == extend_fade_area)
return;
self->extend_fade_area = extend_fade_area;
if (self->actor != NULL)
clutter_actor_queue_redraw (self->actor);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_EXTEND_FADE_AREA]);
}
static void
st_scroll_view_fade_set_property (GObject *object,
guint prop_id,
@ -341,6 +359,9 @@ st_scroll_view_fade_set_property (GObject *object,
case PROP_FADE_EDGES:
st_scroll_view_fade_set_fade_edges (self, g_value_get_boolean (value));
break;
case PROP_EXTEND_FADE_AREA:
st_scroll_view_fade_set_extend_fade_area (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -363,6 +384,9 @@ st_scroll_view_fade_get_property (GObject *object,
case PROP_FADE_EDGES:
g_value_set_boolean (value, self->fade_edges);
break;
case PROP_EXTEND_FADE_AREA:
g_value_set_boolean (value, self->extend_fade_area);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -414,6 +438,18 @@ st_scroll_view_fade_class_init (StScrollViewFadeClass *klass)
FALSE,
ST_PARAM_READWRITE);
/**
* StScrollViewFade:extend-fade-area:
*
* Whether faded edges should extend beyond the faded area of the #StScrollViewFade.
*/
props[PROP_EXTEND_FADE_AREA] =
g_param_spec_boolean ("extend-fade-area",
"Extend Fade Area",
"Whether faded edges should extend beyond the faded area",
FALSE,
ST_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, N_PROPS, props);
}

View File

@ -28,6 +28,7 @@ uniform bool fade_edges_top;
uniform bool fade_edges_right;
uniform bool fade_edges_bottom;
uniform bool fade_edges_left;
uniform bool extend_fade_area;
uniform vec2 fade_area_topleft;
uniform vec2 fade_area_bottomright;
@ -38,11 +39,11 @@ void main ()
float y = height * cogl_tex_coord_in[0].y;
float x = width * cogl_tex_coord_in[0].x;
float ratio = 1.0;
if (x > fade_area_topleft[0] && x < fade_area_bottomright[0] &&
y > fade_area_topleft[1] && y < fade_area_bottomright[1])
{
float ratio = 1.0;
float fade_top_start = fade_area_topleft[1] + fade_offset_top;
float fade_left_start = fade_area_topleft[0] + fade_offset_left;
float fade_bottom_start = fade_area_bottomright[1] - fade_offset_bottom;
@ -67,9 +68,14 @@ void main ()
if (fade_right) {
ratio *= (fade_area_bottomright[0] - x) / (fade_area_bottomright[0] - fade_right_start);
}
cogl_color_out *= ratio;
} else {
cogl_color_out *= 0.0;
} else if (extend_fade_area) {
if (x <= fade_area_topleft[0] && fade_edges_left ||
x >= fade_area_bottomright[0] && fade_edges_right ||
y <= fade_area_topleft[1] && fade_edges_top ||
y >= fade_area_bottomright[1] && fade_edges_bottom) {
ratio = 0.0;
}
}
cogl_color_out *= ratio;
}