Skip to content

Commit 003ba14

Browse files
committed
Pause filters before taking screenshots
1 parent 66f07c3 commit 003ba14

File tree

7 files changed

+66
-20
lines changed

7 files changed

+66
-20
lines changed

data/shaders/colorblindness-correction.vert

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
uniform sampler2D tex;
99
uniform int COLORBLIND_MODE;
1010
uniform float STRENGTH;
11+
uniform bool PAUSE_FOR_SCREENSHOT;
12+
1113
void main() {
1214
vec4 c = texture2D(tex, cogl_tex_coord0_in.xy);
1315

16+
if (PAUSE_FOR_SCREENSHOT) {
17+
cogl_color_out = c;
18+
return;
19+
}
20+
1421
// RGB to LMS matrix
1522
float L = (17.8824f * c.r) + (43.5161f * c.g) + (4.11935f * c.b);
1623
float M = (3.45565f * c.r) + (27.1554f * c.g) + (3.86714f * c.b);

data/shaders/monochrome.vert

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55

66
uniform sampler2D tex;
77
uniform float STRENGTH;
8+
uniform bool PAUSE_FOR_SCREENSHOT;
9+
810
void main() {
9-
vec2 uv = cogl_tex_coord0_in.xy;
10-
vec4 sample = texture2D (tex, uv);
11+
vec4 sample = texture2D (tex, cogl_tex_coord0_in.xy);
12+
13+
if (PAUSE_FOR_SCREENSHOT) {
14+
cogl_color_out = sample;
15+
return;
16+
}
17+
1118
vec3 luminance = vec3 (0.2126, 0.7512, 0.0722);
1219
float gray = luminance.r * sample.r + luminance.g * sample.g + luminance.b * sample.b;
1320
cogl_color_out = vec4 (

src/ColorFilters/ColorblindnessCorrectionEffect.vala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ public class Gala.ColorblindnessCorrectionEffect : Clutter.ShaderEffect {
1919
get { return _strength; }
2020
construct set {
2121
_strength = value;
22-
2322
set_uniform_value ("STRENGTH", value);
2423
queue_repaint ();
2524
}
2625
}
26+
public bool pause_for_screenshot {
27+
set {
28+
set_uniform_value ("PAUSE_FOR_SCREENSHOT", (int) value);
29+
queue_repaint ();
30+
}
31+
}
2732

2833
/*
2934
* Used for fading in and out the effect, since you can't add transitions to effects.
@@ -47,5 +52,7 @@ public class Gala.ColorblindnessCorrectionEffect : Clutter.ShaderEffect {
4752
} catch (Error e) {
4853
critical ("Unable to load colorblindness-correction.vert: %s", e.message);
4954
}
55+
56+
pause_for_screenshot = false;
5057
}
5158
}

src/ColorFilters/FilterManager.vala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ public class Gala.FilterManager : Object {
77
private const string TRANSITION_NAME = "strength-transition";
88
private const int TRANSITION_DURATION = 500;
99

10-
private static FilterManager instance;
11-
private static GLib.Settings settings;
1210
public WindowManager wm { get; construct; }
1311

14-
public static void init (WindowManager wm) {
15-
if (instance != null) {
16-
return;
12+
public bool pause_for_screenshot {
13+
set {
14+
foreach (unowned var _effect in wm.stage.get_effects ()) {
15+
if (_effect is ColorblindnessCorrectionEffect) {
16+
unowned var effect = (ColorblindnessCorrectionEffect) _effect;
17+
effect.pause_for_screenshot = value;
18+
} else if (_effect is MonochromeEffect) {
19+
unowned var effect = (MonochromeEffect) _effect;
20+
effect.pause_for_screenshot = value;
21+
}
22+
}
1723
}
18-
19-
instance = new FilterManager (wm);
2024
}
2125

22-
private FilterManager (WindowManager wm) {
26+
private static GLib.Settings settings;
27+
28+
public FilterManager (WindowManager wm) {
2329
Object (wm: wm);
2430
}
2531

src/ColorFilters/MonochromeEffect.vala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ public class Gala.MonochromeEffect : Clutter.ShaderEffect {
1111
get { return _strength; }
1212
construct set {
1313
_strength = value;
14-
1514
set_uniform_value ("STRENGTH", value);
1615
queue_repaint ();
1716
}
1817
}
18+
public bool pause_for_screenshot {
19+
set {
20+
set_uniform_value ("PAUSE_FOR_SCREENSHOT", (int) value);
21+
queue_repaint ();
22+
}
23+
}
1924

2025
/*
2126
* Used for fading in and out the effect, since you can't add transitions to effects.
@@ -38,5 +43,7 @@ public class Gala.MonochromeEffect : Clutter.ShaderEffect {
3843
} catch (Error e) {
3944
critical ("Unable to load monochrome.vert: %s", e.message);
4045
}
46+
47+
pause_for_screenshot = false;
4148
}
4249
}

src/ScreenshotManager.vala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class Gala.ScreenshotManager : Object {
1414
public WindowManager wm { get; construct; }
1515
[DBus (visible = false)]
1616
public NotificationsManager notifications_manager { get; construct; }
17+
[DBus (visible = false)]
18+
public FilterManager filter_manager { get; construct; }
1719

1820
private bool? _is_redacted_font_available = null;
1921
private bool is_redacted_font_available {
@@ -45,8 +47,8 @@ public class Gala.ScreenshotManager : Object {
4547
private string prev_font_mono;
4648
private uint conceal_timeout;
4749

48-
public ScreenshotManager (WindowManager wm, NotificationsManager notifications_manager) {
49-
Object (wm: wm, notifications_manager: notifications_manager);
50+
public ScreenshotManager (WindowManager wm, NotificationsManager notifications_manager, FilterManager filter_manager) {
51+
Object (wm: wm, notifications_manager: notifications_manager, filter_manager: filter_manager);
5052
}
5153

5254
construct {
@@ -266,8 +268,13 @@ public class Gala.ScreenshotManager : Object {
266268
int width, height;
267269
display.get_size (out width, out height);
268270

271+
filter_manager.pause_for_screenshot = true;
272+
273+
yield wait_stage_repaint ();
274+
269275
var image = take_screenshot (0, 0, width, height, include_cursor);
270276
unconceal_text ();
277+
filter_manager.pause_for_screenshot = false;
271278

272279
if (flash) {
273280
flash_area (0, 0, width, height);
@@ -288,10 +295,13 @@ public class Gala.ScreenshotManager : Object {
288295
public async void screenshot_area_with_cursor (int x, int y, int width, int height, bool include_cursor, bool flash, string filename, out bool success, out string filename_used) throws DBusError, IOError {
289296
debug ("Taking area screenshot");
290297

298+
filter_manager.pause_for_screenshot = true;
299+
291300
yield wait_stage_repaint ();
292301

293302
var image = take_screenshot (x, y, width, height, include_cursor);
294303
unconceal_text ();
304+
filter_manager.pause_for_screenshot = false;
295305

296306
if (flash) {
297307
flash_area (x, y, width, height);

src/WindowManager.vala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ namespace Gala {
7979

8080
public WindowTracker? window_tracker { get; private set; }
8181

82+
private FilterManager filter_manager;
83+
8284
private NotificationsManager notifications_manager;
8385

8486
private ScreenshotManager screenshot_manager;
@@ -133,6 +135,12 @@ namespace Gala {
133135

134136
AccessDialog.watch_portal ();
135137

138+
139+
filter_manager = new FilterManager (this);
140+
notifications_manager = new NotificationsManager ();
141+
screenshot_manager = new ScreenshotManager (this, notifications_manager, filter_manager);
142+
DBus.init (this, notifications_manager, screenshot_manager);
143+
136144
unowned Meta.Display display = get_display ();
137145
display.gl_video_memory_purged.connect (() => {
138146
Meta.Background.refresh_all ();
@@ -173,10 +181,6 @@ namespace Gala {
173181
private void show_stage () {
174182
unowned Meta.Display display = get_display ();
175183

176-
notifications_manager = new NotificationsManager ();
177-
screenshot_manager = new ScreenshotManager (this, notifications_manager);
178-
DBus.init (this, notifications_manager, screenshot_manager);
179-
180184
WindowListener.init (display);
181185
keyboard_manager = new KeyboardManager (display);
182186
window_tracker = new WindowTracker ();
@@ -301,8 +305,6 @@ namespace Gala {
301305
// is set to NONE when we are in locked mode
302306
screensaver.active_changed.connect (update_input_area);
303307

304-
FilterManager.init (this);
305-
306308
/*keybindings*/
307309
var keybinding_settings = new GLib.Settings ("io.elementary.desktop.wm.keybindings");
308310

0 commit comments

Comments
 (0)