From bd347ef9efff76e2d14846214860109f5539d86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bie=C5=84kowski?= Date: Mon, 5 Aug 2019 21:34:44 +0200 Subject: [PATCH] Add setting for greyscale --- data/org.pantheon.desktop.gala.gschema.xml.in | 4 +++ src/Settings.vala | 1 + src/WindowManager.vala | 35 +++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/data/org.pantheon.desktop.gala.gschema.xml.in b/data/org.pantheon.desktop.gala.gschema.xml.in index 6e5ecb05..4d443397 100644 --- a/data/org.pantheon.desktop.gala.gschema.xml.in +++ b/data/org.pantheon.desktop.gala.gschema.xml.in @@ -155,6 +155,10 @@ Attach modal dialogs When true, instead of having independent titlebars, modal dialogs appear attached to the titlebar of the parent window and are moved together with the parent window. + + false + If the display should be greyscale + 'close:maximize' Arrangement of buttons on the titlebar diff --git a/src/Settings.vala b/src/Settings.vala index d19d3e2d..26c2d7b1 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -74,6 +74,7 @@ namespace Gala public bool attach_modal_dialogs { get; set; } public bool dim_parents { get; set; } public string workspace_switcher_background { get; set; } + public bool greyscale { get; set; } static AppearanceSettings? instance = null; diff --git a/src/WindowManager.vala b/src/WindowManager.vala index b15c32fa..5d9f5f91 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -70,7 +70,9 @@ namespace Gala Clutter.Actor? last_hotcorner; ScreenSaver? screensaver; - Clutter.Actor? tile_preview; + Clutter.Actor? tile_preview; + + Clutter.ShaderEffect? greyscale_effect; Window? moving; //place for the window that is being moved over @@ -310,7 +312,9 @@ namespace Gala update_input_area (); - stage.show (); + stage.show (); + toggle_greyscale (); + AppearanceSettings.get_default ().notify["greyscale"].connect (toggle_greyscale); // let the session manager move to the next phase Meta.register_with_session (); @@ -323,6 +327,33 @@ namespace Gala return false; } + void toggle_greyscale () + { + if (greyscale_effect == null) { + greyscale_effect = new Clutter.ShaderEffect (Clutter.ShaderType.FRAGMENT_SHADER); + greyscale_effect.set_name ("greyscale"); + greyscale_effect.set_shader_source (""" + uniform sampler2D texture; + void main () { + vec4 color = texture2D (texture, cogl_tex_coord0_in.xy); + float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114)); + cogl_color_out = vec4(vec3(gray), 1.0); + } + """); + greyscale_effect.set_uniform_value ("texture", 0); + } + + if (AppearanceSettings.get_default ().greyscale) { + if (ui_group.get_effect ("greyscale") == null) { + ui_group.add_effect (greyscale_effect); + } + } else { + if (ui_group.get_effect ("greyscale") != null) { + ui_group.remove_effect (greyscale_effect); + } + } + } + void configure_hotcorners () { var geometry = get_screen ().get_monitor_geometry (get_screen ().get_primary_monitor ());