From 9641704ec7f8097adc96616b1ff2a64290023d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 21 Apr 2022 22:33:24 +0000 Subject: [PATCH] Use Clutter.Grab with Mutter 42 (#1407) --- lib/WindowManager.vala | 5 ++++- plugins/pip/SelectionArea.vala | 2 +- src/Widgets/MultitaskingView.vala | 2 +- src/Widgets/PixelPicker.vala | 2 +- src/Widgets/ScreenShield.vala | 2 +- src/Widgets/SelectionArea.vala | 2 +- src/Widgets/WindowOverview.vala | 2 +- src/Widgets/WindowSwitcher.vala | 2 +- src/WindowManager.vala | 18 ++++++++++++++---- vapi/mutter-clutter.vapi | 2 +- 10 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/WindowManager.vala b/lib/WindowManager.vala index 08f29eabc..199731ce9 100644 --- a/lib/WindowManager.vala +++ b/lib/WindowManager.vala @@ -60,6 +60,9 @@ namespace Gala { * to end your modal mode again with {@link WindowManager.pop_modal} */ public class ModalProxy : Object { +#if HAS_MUTTER42 + public Clutter.Grab? grab { get; set; } +#endif /** * A function which is called whenever a keybinding is pressed. If you supply a custom * one you can filter out those that'd you like to be passed through and block all others. @@ -132,7 +135,7 @@ namespace Gala { * @return a {@link ModalProxy} which is needed to end the modal mode again and provides some * some basic control on the behavior of the window manager while it is in modal mode. */ - public abstract ModalProxy push_modal (); + public abstract ModalProxy push_modal (Clutter.Actor actor); /** * May exit the modal mode again, unless another component has called {@link push_modal} diff --git a/plugins/pip/SelectionArea.vala b/plugins/pip/SelectionArea.vala index 5eb1d2718..7a7e7b82e 100644 --- a/plugins/pip/SelectionArea.vala +++ b/plugins/pip/SelectionArea.vala @@ -129,7 +129,7 @@ public class Gala.Plugins.PIP.SelectionArea : Clutter.Actor { wm.get_display ().set_cursor (Meta.Cursor.CROSSHAIR); grab_key_focus (); - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); } private void get_selection_rectangle (out int x, out int y, out int width, out int height) { diff --git a/src/Widgets/MultitaskingView.vala b/src/Widgets/MultitaskingView.vala index ba1364ae0..cfaa9ff29 100644 --- a/src/Widgets/MultitaskingView.vala +++ b/src/Widgets/MultitaskingView.vala @@ -592,7 +592,7 @@ namespace Gala { } if (opening) { - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); modal_proxy.set_keybinding_filter (keybinding_filter); wm.background_group.hide (); diff --git a/src/Widgets/PixelPicker.vala b/src/Widgets/PixelPicker.vala index 0490f5764..649ee7661 100644 --- a/src/Widgets/PixelPicker.vala +++ b/src/Widgets/PixelPicker.vala @@ -83,7 +83,7 @@ namespace Gala { wm.get_display ().set_cursor (Meta.Cursor.CROSSHAIR); grab_key_focus (); - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); } public void get_point (out int x, out int y) { diff --git a/src/Widgets/ScreenShield.vala b/src/Widgets/ScreenShield.vala index 05e55aad4..ce873f8a7 100644 --- a/src/Widgets/ScreenShield.vala +++ b/src/Widgets/ScreenShield.vala @@ -334,7 +334,7 @@ namespace Gala { wm.get_display ().get_cursor_tracker ().set_pointer_visible (false); visible = true; grab_key_focus (); - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); if (animate) { animate_and_lock (animation_time); diff --git a/src/Widgets/SelectionArea.vala b/src/Widgets/SelectionArea.vala index d3053f00a..f776c4b73 100644 --- a/src/Widgets/SelectionArea.vala +++ b/src/Widgets/SelectionArea.vala @@ -127,7 +127,7 @@ namespace Gala { wm.get_display ().set_cursor (Meta.Cursor.CROSSHAIR); grab_key_focus (); - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); } public void get_selection_rectangle (out int x, out int y, out int width, out int height) { diff --git a/src/Widgets/WindowOverview.vala b/src/Widgets/WindowOverview.vala index d17497ac0..ba55323ab 100644 --- a/src/Widgets/WindowOverview.vala +++ b/src/Widgets/WindowOverview.vala @@ -157,7 +157,7 @@ namespace Gala { grab_key_focus (); - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); modal_proxy.set_keybinding_filter (keybinding_filter); visible = true; diff --git a/src/Widgets/WindowSwitcher.vala b/src/Widgets/WindowSwitcher.vala index 9297d314f..847f2ced3 100644 --- a/src/Widgets/WindowSwitcher.vala +++ b/src/Widgets/WindowSwitcher.vala @@ -331,7 +331,7 @@ namespace Gala { } void push_modal () { - modal_proxy = wm.push_modal (); + modal_proxy = wm.push_modal (this); modal_proxy.set_keybinding_filter ((binding) => { // if it's not built-in, we can block it right away if (!binding.is_builtin ()) diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 0a23c9271..90a67b18c 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -664,7 +664,7 @@ namespace Gala { /** * {@inheritDoc} */ - public ModalProxy push_modal () { + public ModalProxy push_modal (Clutter.Actor actor) { var proxy = new ModalProxy (); modal_stack.offer_head (proxy); @@ -674,14 +674,20 @@ namespace Gala { return proxy; unowned Meta.Display display = get_display (); +#if !HAS_MUTTER42 var time = display.get_current_time (); +#endif update_input_area (); -#if !HAS_MUTTER42 +#if HAS_MUTTER42 + proxy.grab = stage.grab (actor); +#else begin_modal (0, time); #endif - display.disable_unredirect (); + if (modal_stack.size == 1) { + display.disable_unredirect (); + } return proxy; } @@ -695,6 +701,10 @@ namespace Gala { return; } +#if HAS_MUTTER42 + proxy.grab.dismiss (); +#endif + if (is_modal ()) return; @@ -712,7 +722,7 @@ namespace Gala { * {@inheritDoc} */ public bool is_modal () { - return (modal_stack.size > 0); + return !modal_stack.is_empty; } /** diff --git a/vapi/mutter-clutter.vapi b/vapi/mutter-clutter.vapi index 0c364f83f..c2a63a093 100644 --- a/vapi/mutter-clutter.vapi +++ b/vapi/mutter-clutter.vapi @@ -7412,7 +7412,7 @@ namespace Clutter { [Version (since = "0.4")] public unowned string get_title (); #if HAS_MUTTER42 - public unowned Clutter.Grab grab (Clutter.Actor actor); + public Clutter.Grab grab (Clutter.Actor actor); #endif #if !HAS_MUTTER42 [Version (since = "1.2")]