workspace: Refactor focus_default_window

The existing nested if-else statements are hard to follow. Handle cases
and return as early as possible.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3258>
This commit is contained in:
Sebastian Wick 2023-09-08 16:14:18 +02:00 committed by Marge Bot
parent 8a1388c930
commit c73e178a2d

View File

@ -1350,19 +1350,32 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
!workspace->display->mouse_mode) !workspace->display->mouse_mode)
{ {
focus_ancestor_or_mru_window (workspace, not_this_one, timestamp); focus_ancestor_or_mru_window (workspace, not_this_one, timestamp);
return;
} }
else
{
MetaWindow * window;
window = get_pointer_window (workspace, not_this_one); window = get_pointer_window (workspace, not_this_one);
if (window &&
window->type != META_WINDOW_DOCK && if (!window ||
window->type != META_WINDOW_DESKTOP) window->type == META_WINDOW_DOCK ||
window->type == META_WINDOW_DESKTOP)
{ {
if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_MOUSE)
{
meta_topic (META_DEBUG_FOCUS,
"Setting focus to no_focus_window, since no valid "
"window to focus found.");
meta_display_unset_input_focus (workspace->display, timestamp);
}
else /* G_DESKTOP_FOCUS_MODE_SLOPPY */
{
focus_ancestor_or_mru_window (workspace, not_this_one, timestamp);
}
return;
}
if (timestamp == META_CURRENT_TIME) if (timestamp == META_CURRENT_TIME)
{ {
/* We would like for this to never happen. However, if /* We would like for this to never happen. However, if
* it does happen then we kludge since using META_CURRENT_TIME * it does happen then we kludge since using META_CURRENT_TIME
* can mean ugly race conditions--and we can avoid these * can mean ugly race conditions--and we can avoid these
@ -1386,19 +1399,6 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
{ {
meta_display_queue_autoraise_callback (workspace->display, window); meta_display_queue_autoraise_callback (workspace->display, window);
} }
}
else if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_SLOPPY)
{
focus_ancestor_or_mru_window (workspace, not_this_one, timestamp);
}
else if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_MOUSE)
{
meta_topic (META_DEBUG_FOCUS,
"Setting focus to no_focus_window, since no valid "
"window to focus found.");
meta_display_unset_input_focus (workspace->display, timestamp);
}
}
} }
static gboolean static gboolean