Skip to content

Commit

Permalink
Refactor MinimalWindowManager::advise_new_window according to feedback
Browse files Browse the repository at this point in the history
Mainly, reduced the calls to `Impl::prevent_focus_stealing` and
`Impl::ApplicationSelector::advise_new_window` to one call. And renamed
things to be easier to understand.
  • Loading branch information
tarek-y-ismail committed Dec 18, 2024
1 parent 82d3e77 commit 10ef673
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/miral/minimal_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ struct miral::MinimalWindowManager::Impl

void apply_resize_by(Displacement movement);

bool prevent_focus_stealing(WindowInfo const& info);
// Returns true if the window should NOT be in focus
// Relevant for focus stealing prevention where windows are focused on
// launch in specific circumstances.
bool should_prevent_focus(WindowInfo const& info);

bool advise_new_window(WindowInfo const& info);

MirInputEventModifier const pointer_drag_modifier;
FocusStealing const focus_stealing;
Expand Down Expand Up @@ -147,7 +152,7 @@ auto miral::MinimalWindowManager::place_new_window(

void miral::MinimalWindowManager::handle_window_ready(WindowInfo& window_info)
{
if (!self->prevent_focus_stealing(window_info) && window_info.can_be_active())
if (!self->should_prevent_focus(window_info) && window_info.can_be_active())
{
tools.select_active_window(window_info.window());
}
Expand Down Expand Up @@ -297,16 +302,14 @@ auto miral::MinimalWindowManager::confirm_inherited_move(WindowInfo const& windo

void miral::MinimalWindowManager::advise_new_window(miral::WindowInfo const& window_info)
{
auto should_receive_focus = self->advise_new_window(window_info);

// If the window is prevented from stealing focus, 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.
auto in_background = self->prevent_focus_stealing(window_info);

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

if (in_background)
// xdg-activation later on.
if (!should_receive_focus)
tools.swap_tree_order(tools.active_window(), window_info.window());
}

Expand Down Expand Up @@ -638,11 +641,19 @@ void miral::MinimalWindowManager::Impl::apply_resize_by(Displacement movement)
}
}

bool miral::MinimalWindowManager::Impl::prevent_focus_stealing(miral::WindowInfo const& info)
bool miral::MinimalWindowManager::Impl::should_prevent_focus(miral::WindowInfo const& info)
{
auto const without_parent = !info.parent();
auto const decoration_surface = info.type() == mir_window_type_decoration;
return (focus_stealing == FocusStealing::prevent) && tools.active_window() &&
(without_parent || decoration_surface) && info.depth_layer() == mir_depth_layer_application &&
tools.active_window().application() != info.window().application();
}

bool miral::MinimalWindowManager::Impl::advise_new_window(WindowInfo const& info)
{
auto should_receive_focus = !should_prevent_focus(info);
application_selector.advise_new_window(info, should_receive_focus);

return should_receive_focus;
}

0 comments on commit 10ef673

Please sign in to comment.