From 6a3adc1d87a6822fc9ca3989671908940a128ae9 Mon Sep 17 00:00:00 2001 From: Tarek Ismail Date: Wed, 4 Dec 2024 13:02:56 +0200 Subject: [PATCH] Add constructor to `FloatingWindowManagerPolicy` to control focus stealing prevention. --- .../floating_window_manager.cpp | 16 ++++++++++++++-- .../example-server-lib/floating_window_manager.h | 10 ++++++++++ examples/miral-shell/shell_main.cpp | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/example-server-lib/floating_window_manager.cpp b/examples/example-server-lib/floating_window_manager.cpp index 19ed6804713..1941efcc438 100644 --- a/examples/example-server-lib/floating_window_manager.cpp +++ b/examples/example-server-lib/floating_window_manager.cpp @@ -63,6 +63,17 @@ FloatingWindowManagerPolicy::FloatingWindowManagerPolicy( active_workspace = key_to_workspace[KEY_F1]; } +FloatingWindowManagerPolicy::FloatingWindowManagerPolicy( + WindowManagerTools const& tools, + std::shared_ptr const& spinner, + miral::InternalClientLauncher const& launcher, + std::function& shutdown_hook, + bool focus_stealing_prevention) : + FloatingWindowManagerPolicy(tools, spinner, launcher, shutdown_hook) +{ + this->focus_stealing_prevention = focus_stealing_prevention; +} + FloatingWindowManagerPolicy::~FloatingWindowManagerPolicy() = default; bool FloatingWindowManagerPolicy::handle_pointer_event(MirPointerEvent const* event) @@ -232,7 +243,8 @@ void FloatingWindowManagerPolicy::advise_new_window(WindowInfo const& window_inf if (!parent) { tools.add_tree_to_workspace(window_info.window(), active_workspace); - if (tools.active_window()) + + if (focus_stealing_prevention && tools.active_window()) tools.swap_tree_order(tools.active_window(), window_info.window()); } else @@ -244,7 +256,7 @@ void FloatingWindowManagerPolicy::advise_new_window(WindowInfo const& window_inf void FloatingWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) { - if (!tools.active_window()) + if (!focus_stealing_prevention || !tools.active_window()) MinimalWindowManager::handle_window_ready(window_info); keep_spinner_on_top(); diff --git a/examples/example-server-lib/floating_window_manager.h b/examples/example-server-lib/floating_window_manager.h index 49973c9f644..a7902185bdb 100644 --- a/examples/example-server-lib/floating_window_manager.h +++ b/examples/example-server-lib/floating_window_manager.h @@ -40,6 +40,14 @@ class FloatingWindowManagerPolicy : public miral::MinimalWindowManager std::shared_ptr const& spinner, miral::InternalClientLauncher const& launcher, std::function& shutdown_hook); + + FloatingWindowManagerPolicy( + miral::WindowManagerTools const& tools, + std::shared_ptr const& spinner, + miral::InternalClientLauncher const& launcher, + std::function& shutdown_hook, + bool focus_stealing_prevention); + ~FloatingWindowManagerPolicy(); virtual miral::WindowSpecification place_new_window( @@ -118,6 +126,8 @@ class FloatingWindowManagerPolicy : public miral::MinimalWindowManager void apply_workspace_hidden_to(miral::Window const& window); void keep_spinner_on_top(); + + bool focus_stealing_prevention{true}; }; #endif //MIRAL_SHELL_FLOATING_WINDOW_MANAGER_H diff --git a/examples/miral-shell/shell_main.cpp b/examples/miral-shell/shell_main.cpp index 84ebc4ae718..2421bfbce4e 100644 --- a/examples/miral-shell/shell_main.cpp +++ b/examples/miral-shell/shell_main.cpp @@ -68,9 +68,10 @@ int main(int argc, char const* argv[]) SpinnerSplash spinner; InternalClientLauncher launcher; + bool focus_stealing_prevention = true; WindowManagerOptions window_managers { - add_window_manager_policy("floating", spinner, launcher, shutdown_hook), + add_window_manager_policy("floating", spinner, launcher, shutdown_hook, focus_stealing_prevention), add_window_manager_policy("tiling", spinner, launcher), };