From 3f843fa8c49323e440162a8bc1a6e191f00c3d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bie=C5=84kowski?= Date: Mon, 5 Aug 2019 23:04:14 +0200 Subject: [PATCH] Add fade-in / fade-out --- src/Widgets/IconGroup.vala | 2 +- src/WindowManager.vala | 45 +++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Widgets/IconGroup.vala b/src/Widgets/IconGroup.vala index 41fa5414..2b773d1d 100644 --- a/src/Widgets/IconGroup.vala +++ b/src/Widgets/IconGroup.vala @@ -545,7 +545,7 @@ namespace Gala get_parent ().remove_child (this); unowned WorkspaceInsertThumb inserter = (WorkspaceInsertThumb) destination; - workspace.get_screen ().reorder_workspace (workspace, inserter.workspace_index); + // workspace.get_screen ().reorder_workspace (workspace, inserter.workspace_index); restore_group (); } else { diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 5d9f5f91..7a71177d 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -327,6 +327,9 @@ namespace Gala return false; } + float greyscale_opacity = 0.0f; + uint fade_in_id = 0U; + uint fade_out_id = 0U; void toggle_greyscale () { if (greyscale_effect == null) { @@ -334,22 +337,58 @@ namespace Gala greyscale_effect.set_name ("greyscale"); greyscale_effect.set_shader_source (""" uniform sampler2D texture; + uniform float opacity; + 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); + cogl_color_out = mix (color, vec4(vec3(gray), 1.0), opacity); } """); + greyscale_effect.set_uniform_value ("texture", 0); + greyscale_effect.set_uniform_value ("opacity", 0.0f); } + const uint FADE_TIMEOUT = 300 / 100; if (AppearanceSettings.get_default ().greyscale) { - if (ui_group.get_effect ("greyscale") == null) { + bool animates_out = fade_out_id > 0U; + if (ui_group.get_effect ("greyscale") == null || animates_out) { ui_group.add_effect (greyscale_effect); + if (animates_out) { + Source.remove (fade_out_id); + } + + fade_in_id = Timeout.add (FADE_TIMEOUT, () => { + greyscale_effect.set_uniform_value ("opacity", greyscale_opacity); + greyscale_opacity += 0.01f; + + bool stop = greyscale_opacity > 1.0f; + if (stop) { + fade_in_id = 0U; + } + + return !stop; + }); } } else { if (ui_group.get_effect ("greyscale") != null) { - ui_group.remove_effect (greyscale_effect); + if (fade_in_id > 0U) { + Source.remove (fade_in_id); + } + + fade_out_id = Timeout.add (FADE_TIMEOUT, () => { + greyscale_opacity -= 0.01f; + greyscale_effect.set_uniform_value ("opacity", greyscale_opacity); + + bool stop = greyscale_opacity <= 0.0f; + if (stop) { + ui_group.remove_effect (greyscale_effect); + fade_out_id = 0U; + } + + return !stop; + }); } } }