Skip to content

Commit f179d59

Browse files
committed
BackgroundBlurEffect: get scale factor from stage view
1 parent 721dc02 commit f179d59

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

src/BackgroundBlurEffect.vala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class Gala.BackgroundBlurEffect : Clutter.Effect {
1010

1111
public float blur_radius { get; construct; }
1212
public float clip_radius { get; construct; }
13-
public float monitor_scale { get; construct set; }
1413

1514
public uint left { get; set; default = 0; }
1615
public uint right { get; set; default = 0; }
@@ -36,8 +35,8 @@ public class Gala.BackgroundBlurEffect : Clutter.Effect {
3635

3736
private int frame_counter = 0;
3837

39-
public BackgroundBlurEffect (float blur_radius, float clip_radius, float monitor_scale) {
40-
Object (blur_radius: blur_radius, clip_radius: clip_radius, monitor_scale: monitor_scale);
38+
public BackgroundBlurEffect (float blur_radius, float clip_radius) {
39+
Object (blur_radius: blur_radius, clip_radius: clip_radius);
4140
}
4241

4342
construct {
@@ -126,28 +125,27 @@ public class Gala.BackgroundBlurEffect : Clutter.Effect {
126125
round_actor_size_location = round_pipeline.get_uniform_location ("actor_size");
127126
}
128127

129-
private void update_actor_box (Clutter.PaintContext paint_context, ref Clutter.ActorBox source_actor_box) {
130-
float box_scale_factor = 1.0f;
131-
float origin_x, origin_y;
132-
float width, height;
128+
private float get_stage_view_scale (Clutter.PaintContext paint_context) {
129+
unowned var stage_view = paint_context.get_stage_view ();
133130

134-
var stage_view = paint_context.get_stage_view ();
131+
return stage_view != null ? stage_view.scale : 1.0f;
132+
}
135133

134+
private void update_actor_box (Clutter.PaintContext paint_context, ref Clutter.ActorBox source_actor_box) {
135+
float origin_x, origin_y, width, height;
136136
actor.get_transformed_position (out origin_x, out origin_y);
137137
actor.get_transformed_size (out width, out height);
138+
139+
float box_scale_factor = get_stage_view_scale (paint_context);
140+
var stage_view = paint_context.get_stage_view ();
138141

139142
if (stage_view != null) {
140143
Mtk.Rectangle stage_view_layout = {};
141144

142-
box_scale_factor = stage_view.get_scale ();
143145
stage_view.get_layout (ref stage_view_layout);
144146

145147
origin_x -= stage_view_layout.x;
146148
origin_y -= stage_view_layout.y;
147-
} else {
148-
/* If we're drawing off stage, just assume scale = 1, this won't work
149-
* with stage-view scaling though.
150-
*/
151149
}
152150

153151
source_actor_box.set_origin (origin_x, origin_y);
@@ -395,7 +393,7 @@ public class Gala.BackgroundBlurEffect : Clutter.Effect {
395393
}
396394

397395
var relative_opacity = (float) actor.opacity / 255.0f;
398-
real_blur_radius = blur_radius * (float) Math.pow (relative_opacity, 2) * monitor_scale * (float) total_scale;
396+
real_blur_radius = blur_radius * (float) Math.pow (relative_opacity, 2) * get_stage_view_scale (paint_context) * (float) total_scale;
399397

400398
Clutter.ActorBox source_actor_box = {};
401399
update_actor_box (paint_context, ref source_actor_box);
@@ -412,18 +410,18 @@ public class Gala.BackgroundBlurEffect : Clutter.Effect {
412410
paint_background (blur_node, paint_context, source_actor_box);
413411
add_actor_node (node);
414412

415-
update_uniforms ();
413+
update_uniforms (paint_context);
416414
}
417415

418-
private void update_uniforms () requires (round_texture != null) {
416+
private void update_uniforms (Clutter.PaintContext paint_context) requires (round_texture != null) {
419417
float[] actor_size = {
420418
round_texture.get_width (),
421419
round_texture.get_height ()
422420
};
423421
round_pipeline.set_uniform_float (round_actor_size_location, 2, 1, actor_size);
424422

425423
float[] clip_vals = {
426-
(clip_radius * monitor_scale) / downscale_factor
424+
(clip_radius * get_stage_view_scale (paint_context)) / downscale_factor
427425
};
428426
round_pipeline.set_uniform_float (round_clip_radius_location, 1, 1, clip_vals);
429427
}

src/BlurManager.vala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ public class Gala.BlurManager : Object {
4242
window.notify["mutter-hints"].connect ((obj, pspec) => parse_mutter_hints ((Meta.Window) obj));
4343
parse_mutter_hints (window);
4444
});
45-
46-
unowned var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager ();
47-
monitor_manager.monitors_changed.connect (() => {
48-
foreach (unowned var window in blurred_windows.get_keys ()) {
49-
blurred_windows[window].blur_effect.monitor_scale = window.display.get_monitor_scale (window.get_monitor ());
50-
}
51-
});
5245
}
5346

5447
/**
@@ -63,11 +56,7 @@ public class Gala.BlurManager : Object {
6356

6457
var blur_data = blurred_windows[window];
6558
if (blur_data == null) {
66-
var blur_effect = new BackgroundBlurEffect (
67-
BLUR_RADIUS,
68-
(int) clip_radius,
69-
window.display.get_monitor_scale (window.get_monitor ())
70-
);
59+
var blur_effect = new BackgroundBlurEffect (BLUR_RADIUS, (int) clip_radius);
7160

7261
window_actor.add_effect (blur_effect);
7362

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
102102
add_effect (shadow_effect);
103103

104104

105-
blur_effect = new BackgroundBlurEffect (40, 9, scaling_factor);
105+
blur_effect = new BackgroundBlurEffect (40, 9);
106106
add_effect (blur_effect);
107107

108108
scale ();
@@ -123,7 +123,6 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
123123
scaling_factor = display.get_monitor_scale (display.get_current_monitor ());
124124

125125
shadow_effect.monitor_scale = scaling_factor;
126-
blur_effect.monitor_scale = scaling_factor;
127126

128127
var margin = Utils.scale_to_int (WRAPPER_PADDING, scaling_factor);
129128

0 commit comments

Comments
 (0)