Harden DWM plugins against X11 stacking/keyboard grab races and speed up QMI status

This commit is contained in:
Luxferre
2026-10-25 14:14:21 +02:00
parent b2216c186f
commit e77be498bf
44 changed files with 432 additions and 211 deletions
+11 -9
View File
@@ -862,6 +862,7 @@ int runSmsApp(int argc, char** argv) {
};
auto showWindow = [&](const std::string& argStr) {
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("sms");
reloadAllData(true);
lastTapDigit = -1;
@@ -881,21 +882,13 @@ int runSmsApp(int argc, char** argv) {
selectedThread = 0;
}
writeIntFile(activePidPath, static_cast<int>(::getpid()));
if (!visible) {
visible = true;
XMapRaised(dpy, win);
for (int i = 0; i < 20; ++i) {
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) {
break;
}
usleep(2000);
}
} else {
XRaiseWindow(dpy, win);
}
XSetInputFocus(dpy, win, RevertToPointerRoot, CurrentTime);
grabPluginKeyboard(dpy, win);
openStartMs = nowMs();
startupIgnoreUntilMs = openStartMs + 180;
initialSoftkeysReleased = (querySoftkeysDown(dpy) == 0);
@@ -1117,6 +1110,15 @@ int runSmsApp(int argc, char** argv) {
if (ev.type == Expose && ev.xexpose.count == 0) {
drawUI();
} else if (ev.type == VisibilityNotify &&
ev.xvisibility.state != VisibilityUnobscured) {
if (isAnotherPluginActive("sms")) {
hideWindow();
} else {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
drawUI();
}
} else if (ev.type == KeyRelease) {
unsigned int kc = ev.xkey.keycode;
KeySym sym = XLookupKeysym(&ev.xkey, 0);