|
| 1 | +/* |
| 2 | + * Copyright 2025 elementary, Inc. (https://elementary.io) |
| 3 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + * |
| 5 | + * Authored by: Leonhard Kargl <[email protected]> |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * This class allows to make windows system modal i.e. dim |
| 10 | + * the desktop behind them and only allow interaction with them. |
| 11 | + * Not to be confused with WindowManager.push_modal which only |
| 12 | + * works for our own Clutter.Actors. |
| 13 | + */ |
| 14 | +public class Gala.ModalGroup : Clutter.Actor { |
| 15 | + public WindowManager wm { private get; construct; } |
| 16 | + public ShellClientsManager shell_clients { private get; construct; } |
| 17 | + |
| 18 | + private Gee.Set<Clutter.Actor> dimmed; |
| 19 | + private ModalProxy? modal_proxy = null; |
| 20 | + |
| 21 | + public ModalGroup (WindowManager wm, ShellClientsManager shell_clients) { |
| 22 | + Object (wm: wm, shell_clients: shell_clients); |
| 23 | + } |
| 24 | + |
| 25 | + construct { |
| 26 | + dimmed = new Gee.HashSet<Clutter.Actor> (); |
| 27 | + |
| 28 | + visible = false; |
| 29 | + reactive = true; |
| 30 | +#if HAS_MUTTER46 |
| 31 | + child_added.connect (on_child_added); |
| 32 | + child_removed.connect (on_child_removed); |
| 33 | +#else |
| 34 | + actor_added.connect (on_child_added); |
| 35 | + actor_removed.connect (on_child_removed); |
| 36 | +#endif |
| 37 | + } |
| 38 | + |
| 39 | + private void on_child_added (Clutter.Actor child) { |
| 40 | + if (child is Meta.WindowActor && shell_clients.is_system_modal_dimmed (child.meta_window)) { |
| 41 | + dimmed.add (child); |
| 42 | + } |
| 43 | + |
| 44 | + if (get_n_children () == 1) { |
| 45 | + assert (modal_proxy == null); |
| 46 | + |
| 47 | + visible = true; |
| 48 | + modal_proxy = wm.push_modal (this, false); |
| 49 | + } |
| 50 | + |
| 51 | + if (dimmed.size == 1) { |
| 52 | + save_easing_state (); |
| 53 | + set_easing_duration (Utils.get_animation_duration (AnimationDuration.OPEN)); |
| 54 | + background_color = { 0, 0, 0, 200 }; |
| 55 | + restore_easing_state (); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + private void on_child_removed (Clutter.Actor child) { |
| 60 | + dimmed.remove (child); |
| 61 | + |
| 62 | + if (dimmed.size == 0) { |
| 63 | + save_easing_state (); |
| 64 | + set_easing_duration (Utils.get_animation_duration (AnimationDuration.CLOSE)); |
| 65 | + background_color = { 0, 0, 0, 0 }; |
| 66 | + restore_easing_state (); |
| 67 | + } |
| 68 | + |
| 69 | + if (get_n_children () == 0) { |
| 70 | + wm.pop_modal (modal_proxy); |
| 71 | + modal_proxy = null; |
| 72 | + |
| 73 | + var transition = get_transition ("background-color"); |
| 74 | + if (transition != null) { |
| 75 | + transition.completed.connect (() => visible = false); |
| 76 | + } else { |
| 77 | + visible = false; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments