Skip to content

Commit 634fdc8

Browse files
SiegeLordExSiegeLord
authored andcommitted
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
1 parent 2ed7ded commit 634fdc8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/x/xdisplay.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,17 @@ static bool xdpy_create_display_window(ALLEGRO_SYSTEM_XGLX *system,
178178
StructureNotifyMask |
179179
EnterWindowMask |
180180
LeaveWindowMask |
181-
FocusChangeMask |
182181
ExposureMask |
183182
PropertyChangeMask |
184183
ButtonPressMask |
185184
ButtonReleaseMask |
186185
PointerMotionMask;
187186

187+
/* We handle these events via GTK-sent XEmbed events. */
188+
if (!(display->flags & ALLEGRO_GTK_TOPLEVEL_INTERNAL)) {
189+
swa.event_mask |= FocusChangeMask;
190+
}
191+
188192
/* For a non-compositing window manager, a black background can look
189193
* less broken if the application doesn't react to expose events fast
190194
* enough. However in some cases like resizing, the black background
@@ -1098,13 +1102,13 @@ void _al_xglx_display_configure_event(ALLEGRO_DISPLAY *d, XEvent *xevent)
10981102
void _al_xwin_display_switch_handler(ALLEGRO_DISPLAY *display,
10991103
XFocusChangeEvent *xevent)
11001104
{
1101-
/* Anything but NotifyNormal seem to indicate the switch is not "real".
1102-
* TODO: Find out details?
1105+
/* Mouse click in/out tend to set NotifyNormal events. For Alt-Tab,
1106+
* there are also accompanying NotifyGrab/NotifyUngrab events which we don't
1107+
* care about. At this point, some WMs either send NotifyNormal (KDE) or
1108+
* NotifyWhileGrabbed (GNOME).
11031109
*/
1104-
if (xevent->mode != NotifyNormal)
1105-
return;
1106-
1107-
_al_xwin_display_switch_handler_inner(display, (xevent->type == FocusIn));
1110+
if (xevent->mode == NotifyNormal || xevent->mode == NotifyWhileGrabbed)
1111+
_al_xwin_display_switch_handler_inner(display, (xevent->type == FocusIn));
11081112
}
11091113

11101114

0 commit comments

Comments
 (0)