Skip to content

Commit

Permalink
Add constructor to FloatingWindowManagerPolicy to control focus
Browse files Browse the repository at this point in the history
stealing prevention.
  • Loading branch information
tarek-y-ismail committed Dec 4, 2024
1 parent 2a9e5e5 commit 6a3adc1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
16 changes: 14 additions & 2 deletions examples/example-server-lib/floating_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ FloatingWindowManagerPolicy::FloatingWindowManagerPolicy(
active_workspace = key_to_workspace[KEY_F1];
}

FloatingWindowManagerPolicy::FloatingWindowManagerPolicy(
WindowManagerTools const& tools,
std::shared_ptr<SplashSession> const& spinner,
miral::InternalClientLauncher const& launcher,
std::function<void()>& 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)
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions examples/example-server-lib/floating_window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class FloatingWindowManagerPolicy : public miral::MinimalWindowManager
std::shared_ptr<SplashSession> const& spinner,
miral::InternalClientLauncher const& launcher,
std::function<void()>& shutdown_hook);

FloatingWindowManagerPolicy(
miral::WindowManagerTools const& tools,
std::shared_ptr<SplashSession> const& spinner,
miral::InternalClientLauncher const& launcher,
std::function<void()>& shutdown_hook,
bool focus_stealing_prevention);

~FloatingWindowManagerPolicy();

virtual miral::WindowSpecification place_new_window(
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion examples/miral-shell/shell_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FloatingWindowManagerPolicy>("floating", spinner, launcher, shutdown_hook),
add_window_manager_policy<FloatingWindowManagerPolicy>("floating", spinner, launcher, shutdown_hook, focus_stealing_prevention),
add_window_manager_policy<TilingWindowManagerPolicy>("tiling", spinner, launcher),
};

Expand Down

0 comments on commit 6a3adc1

Please sign in to comment.