When an application calls XKeyboardUngrab as per the X11 specifications, a `FocusOut` event is generated with the mode set to `NotifyUngrab`. kwin incorrectly processes this event and unhighlights the application caption bar as well as the icon on the task bar. STEPS TO REPRODUCE 1. Compile the following application using: gcc reproduce.c -L/usr/X11R6/lib -lX11 -o reproduce #include <X11/Xlib.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> int main(void) { Display *d; Window w; XEvent e; const char *msg = "Hello, World!"; int s; bool toggle = false; d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } s = DefaultScreen(d); w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s)); XSelectInput(d, w, ExposureMask | KeyPressMask); XMapWindow(d, w); while (1) { XNextEvent(d, &e); if (e.type == Expose) { XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10); XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)); } if (e.type == KeyPress) { toggle = !toggle; if (toggle) XGrabKeyboard( d, w, true, GrabModeAsync, GrabModeAsync, CurrentTime); else XUngrabKeyboard(d, CurrentTime); } } XCloseDisplay(d); return 0; } 2. Run the resulting application 3. Press any key on the keyboard to toggle the keyboard grab/ungrab OBSERVED RESULT The application shows that it has lost focus and the taskbar panel, and in the case of a full-screen application the taskbar will overlap the application. EXPECTED RESULT The application to show it still has focus and the taskbar panel to remain behind the application.
> `FocusOut` event is generated with the mode set to `NotifyUngrab` Shouldn't it be NotifyGrab?
As per: https://tronche.com/gui/x/xlib/input/XUngrabKeyboard.html > The XUngrabKeyboard() function releases the keyboard and any queued events if this client has it actively grabbed from either XGrabKeyboard() or XGrabKey(). XUngrabKeyboard() does not release the keyboard and any queued events if the specified time is earlier than the last-keyboard-grab time or is later than the current X server time. It also generates FocusIn and FocusOut events. The X server automatically performs an UngrabKeyboard request if the event window for an active keyboard grab becomes not viewable.
Sorry I misread what you stated. The problem is when the application calls XKeyboardUngrab, which sends the FocusOut event with NotifyUngrab as far as I am aware. Either way, the sample application provided reliably replicates the problem.
This bug was reported against an outdated version of KWin. We have made many changes since the. If the issue persists in newer versions can you reopen the bug report updating the version number.
Or, you could use the minimal code I produced and check if it's still an issue instead of just flat out closing an issue that is years old because of your inaction. When this was opened it was the most current version.
Confirmed still bugged on 5.27.7. Minimum viable sample still reproduces the issue. Application incorrectly looses focus when `XKeyboardUngrab` is called.
Thanks