From 95cda44f9fdf4c77677b89058adebfb1122dbf0b Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Sat, 10 Dec 2022 14:49:42 -0800 Subject: [PATCH] Improve DISPLAY_SWITCH_IN/OUT events on Linux. There were two issues. - GNOME sends a different event type when alt-tabbing, at least on Ubuntu 22.04. Adjusted the code to use this alternate event type. - When GTK_TOPLEVEL flag is on, we were getting duplicate events with Wayland. Adjusted the code to not listen to the duplicate events. Fixes #1390, #1367 --- src/x/xdisplay.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/x/xdisplay.c b/src/x/xdisplay.c index 81e83398df..cc297d1b5d 100644 --- a/src/x/xdisplay.c +++ b/src/x/xdisplay.c @@ -181,13 +181,17 @@ static bool xdpy_create_display_window(ALLEGRO_SYSTEM_XGLX *system, StructureNotifyMask | EnterWindowMask | LeaveWindowMask | - FocusChangeMask | ExposureMask | PropertyChangeMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; + /* We handle these events via GTK-sent XEmbed events. */ + if (!(display->flags & ALLEGRO_GTK_TOPLEVEL_INTERNAL)) { + swa.event_mask |= FocusChangeMask; + } + /* For a non-compositing window manager, a black background can look * less broken if the application doesn't react to expose events fast * enough. However in some cases like resizing, the black background @@ -1105,13 +1109,13 @@ void _al_xglx_display_configure_event(ALLEGRO_DISPLAY *d, XEvent *xevent) void _al_xwin_display_switch_handler(ALLEGRO_DISPLAY *display, XFocusChangeEvent *xevent) { - /* Anything but NotifyNormal seem to indicate the switch is not "real". - * TODO: Find out details? + /* Mouse click in/out tend to set NotifyNormal events. For Alt-Tab, + * there are also accompanying NotifyGrab/NotifyUngrab events which we don't + * care about. At this point, some WMs either send NotifyNormal (KDE) or + * NotifyWhileGrabbed (GNOME). */ - if (xevent->mode != NotifyNormal) - return; - - _al_xwin_display_switch_handler_inner(display, (xevent->type == FocusIn)); + if (xevent->mode == NotifyNormal || xevent->mode == NotifyWhileGrabbed) + _al_xwin_display_switch_handler_inner(display, (xevent->type == FocusIn)); }