x11: Simplify handling of focus-follows-mouse

Focus follows mouse is meant to avoid focusing windows that happened
to pop up under the pointer, e.g. due to mapping, workspace changes,
etc... On X11, this has been done since ancient times through a
moderately complex synchronization mechanism, so mutter would know
to ignore crossing events caused on those situations.

This mechanism is much prior to XInput 2 though, where we may know
this in a more straightforward way: If the sourceid of the crossing
event is a logical pointer (i.e. equals deviceid), the crossing event
was triggered logically, and not through user input.

Perform this simpler check, and drop the existing mechanism to
ignore logically induced crossing events.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3267>
This commit is contained in:
Carlos Garnacho 2023-09-06 15:00:33 +02:00 committed by Marge Bot
parent f23876e99e
commit 8b0da940cf
5 changed files with 1 additions and 87 deletions

View File

@ -2203,7 +2203,6 @@ meta_window_show (MetaWindow *window)
gboolean needs_stacking_adjustment;
MetaWindow *focus_window;
gboolean notify_demands_attention = FALSE;
MetaDisplay *display = window->display;
meta_topic (META_DEBUG_WINDOW_STATE,
"Showing window %s, iconic: %d placed: %d",
@ -2373,16 +2372,6 @@ meta_window_show (MetaWindow *window)
else
meta_display_queue_focus (window->display, window);
}
else if (display->x11_display)
{
/* Prevent EnterNotify events in sloppy/mouse focus from
* erroneously focusing the window that had been denied
* focus. FIXME: This introduces a race; I have a couple
* ideas for a better way to accomplish the same thing, but
* they're more involved so do it this way for now.
*/
meta_x11_display_increment_focus_sentinel (display->x11_display);
}
}
set_net_wm_state (window);

View File

@ -69,7 +69,6 @@ item(_GNOME_PANEL_ACTION)
item(_GNOME_PANEL_ACTION_RUN_DIALOG)
item(_MUTTER_TIMESTAMP_PING)
item(_MUTTER_FOCUS_SET)
item(_MUTTER_SENTINEL)
item(_MUTTER_VERSION)
item(_MUTTER_FRAME_FOR)
item(_MUTTER_FRAME_EXTENTS)

View File

@ -996,7 +996,7 @@ handle_input_xevent (MetaX11Display *x11_display,
enter_event->mode != XINotifyUngrab &&
enter_event->detail != XINotifyInferior &&
!meta_is_wayland_compositor () &&
meta_x11_display_focus_sentinel_clear (x11_display))
enter_event->sourceid != enter_event->deviceid)
{
meta_window_handle_enter (window,
enter_event->time,
@ -1640,16 +1640,6 @@ handle_other_xevent (MetaX11Display *x11_display,
else if (event->xproperty.atom ==
x11_display->atom__NET_DESKTOP_NAMES)
meta_x11_display_update_workspace_names (x11_display);
/* we just use this property as a sentinel to avoid
* certain race conditions. See the comment for the
* sentinel_counter variable declaration in display.h
*/
if (event->xproperty.atom ==
x11_display->atom__MUTTER_SENTINEL)
{
meta_x11_display_decrement_focus_sentinel (x11_display);
}
}
}
break;

View File

@ -171,11 +171,6 @@ struct _MetaX11Display
*/
unsigned long ignored_crossing_serials[N_IGNORED_CROSSING_SERIALS];
/* we use property updates as sentinels for certain window focus events
* to avoid some race conditions on EnterNotify events
*/
int sentinel_counter;
int composite_event_base;
int composite_error_base;
int composite_major_version;
@ -265,10 +260,6 @@ MetaLogicalMonitor *meta_x11_display_xinerama_index_to_logical_monitor (MetaX11D
void meta_x11_display_update_workspace_layout (MetaX11Display *x11_display);
void meta_x11_display_update_workspace_names (MetaX11Display *x11_display);
void meta_x11_display_increment_focus_sentinel (MetaX11Display *x11_display);
void meta_x11_display_decrement_focus_sentinel (MetaX11Display *x11_display);
gboolean meta_x11_display_focus_sentinel_clear (MetaX11Display *x11_display);
void meta_x11_display_update_focus_window (MetaX11Display *x11_display,
Window xwindow,
gulong serial,

View File

@ -1091,25 +1091,6 @@ open_x_display (MetaDisplay *display,
return xdisplay;
}
static void
on_window_visibility_updated (MetaDisplay *display,
GList *placed_windows,
GList *shown_windows,
GList *hidden_windows,
MetaX11Display *x11_display)
{
GList *l;
if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK)
return;
if (display->mouse_mode)
return;
for (l = shown_windows; l; l = l->next)
meta_x11_display_increment_focus_sentinel (x11_display);
}
static void
on_frames_client_died (GObject *source,
GAsyncResult *result,
@ -1285,10 +1266,6 @@ meta_x11_display_new (MetaDisplay *display,
G_CALLBACK (update_cursor_theme),
x11_display,
G_CONNECT_SWAPPED);
g_signal_connect_object (display,
"window-visibility-updated",
G_CALLBACK (on_window_visibility_updated),
x11_display, 0);
g_signal_connect_object (display,
"x11-display-opened",
@ -2356,38 +2333,6 @@ prefs_changed_callback (MetaPreference pref,
}
}
void
meta_x11_display_increment_focus_sentinel (MetaX11Display *x11_display)
{
unsigned long data[1];
data[0] = meta_display_get_current_time (x11_display->display);
XChangeProperty (x11_display->xdisplay,
x11_display->xroot,
x11_display->atom__MUTTER_SENTINEL,
XA_CARDINAL,
32, PropModeReplace, (guchar*) data, 1);
x11_display->sentinel_counter += 1;
}
void
meta_x11_display_decrement_focus_sentinel (MetaX11Display *x11_display)
{
x11_display->sentinel_counter -= 1;
if (x11_display->sentinel_counter < 0)
x11_display->sentinel_counter = 0;
}
gboolean
meta_x11_display_focus_sentinel_clear (MetaX11Display *x11_display)
{
return (x11_display->sentinel_counter == 0);
}
static void
meta_x11_display_add_ignored_crossing_serial (MetaX11Display *x11_display,
unsigned long serial)