Skip to content

Commit

Permalink
Further tune focus stealing prevention in
Browse files Browse the repository at this point in the history
`MinimalWindowManager::advise_new_window`
  • Loading branch information
tarek-y-ismail committed Dec 5, 2024
1 parent 7a166fb commit 2d2107d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/miral/minimal_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,23 @@ auto miral::MinimalWindowManager::confirm_inherited_move(WindowInfo const& windo

void miral::MinimalWindowManager::advise_new_window(miral::WindowInfo const& window_info)
{
self->application_selector.advise_new_window(window_info, self->focus_stealing == FocusStealing::allow);

auto const should_be_pushed_back = [](auto const& window_info)
{
return window_info.type() == mir_window_type_normal || window_info.type() == mir_window_type_utility;
};

// If focus stealing prevention is on, swap the old focused window (now in
// the back) with the new window in the front.
//
// If it's a legitimate window, it'll be focused and raised via
// xdg-activation.
if ((self->focus_stealing == FocusStealing::prevent) && tools.active_window() &&
should_be_pushed_back(window_info))
{
//
// This is limited to a couple of window types, as well as windows in the
// "application" layer that don't have a parent.
auto in_background =
(self->focus_stealing == FocusStealing::prevent) && tools.active_window() &&
(window_info.type() == mir_window_type_normal || window_info.type() == mir_window_type_freestyle) &&
window_info.depth_layer() == mir_depth_layer_application && !window_info.parent();

self->application_selector.advise_new_window(window_info, in_background);

if (in_background)
tools.swap_tree_order(tools.active_window(), window_info.window());
}
}

void miral::MinimalWindowManager::advise_focus_gained(WindowInfo const& window_info)
Expand Down

0 comments on commit 2d2107d

Please sign in to comment.