Skip to content

Commit cd5ed89

Browse files
committed
window activation: Detect a couple of conditions that might cause
initial window focus and stacking to be wrong (mostly because of bad timestamps), and correct them. - a modal window with a parent that is the current input focus should never appear below that parent. - a modal window spawned via portal (rather than 'native'). Flatpak apps, along with browsers (and electron apps) are now using this portal mechanism to provide a dialog appropriate to the current environment (such as Kde, Gtk). The dialogs aren't direct descendants of their parent windows, their timestamps can/will be earlier than the most recent user time for the parents, causing muffin to refuse focus. ref: linuxmint/cinnamon#11368 linuxmint/cinnamon#10868
1 parent 0e957e1 commit cd5ed89

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/core/window.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,12 +4043,31 @@ meta_window_activate_full (MetaWindow *window,
40434043
if (timestamp != 0 &&
40444044
XSERVER_TIME_IS_BEFORE (timestamp, window->display->last_user_time))
40454045
{
4046-
meta_topic (META_DEBUG_FOCUS,
4047-
"last_user_time (%u) is more recent; ignoring "
4048-
" _NET_ACTIVE_WINDOW message.\n",
4049-
window->display->last_user_time);
4050-
meta_window_set_demands_attention(window);
4051-
return;
4046+
// If the window is modal its parent is currently the focused window, always give
4047+
// focus, even if its timestamp is wrong. Check also for an xdg-portal dialog, which
4048+
// probably won't have the correct timestamp either.
4049+
//
4050+
// Otherwise, these windows will either start below their parent window, or they may
4051+
// start above the parent, but with the parent retaining focus.
4052+
if (window->type == META_WINDOW_MODAL_DIALOG &&
4053+
((window->transient_for && window->display->focus_window == window->transient_for) ||
4054+
g_strcmp0 (window->res_class, "Xdg-desktop-portal-gtk") == 0))
4055+
{
4056+
meta_topic (META_DEBUG_FOCUS,
4057+
"Window is a modal dialog and and its parent is currently focused, or it's an xdg-desktop-portal-gtk dialog), "
4058+
"adjusting its timestamp so it will be focused and brought forward.\n");
4059+
4060+
timestamp = meta_display_get_current_time_roundtrip (window->display);
4061+
}
4062+
else
4063+
{
4064+
meta_topic (META_DEBUG_FOCUS,
4065+
"last_user_time (%u) is more recent; ignoring "
4066+
" _NET_ACTIVE_WINDOW message.\n",
4067+
window->display->last_user_time);
4068+
meta_window_set_demands_attention(window);
4069+
return;
4070+
}
40524071
}
40534072

40544073
if (timestamp == 0)

0 commit comments

Comments
 (0)