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

This commit is contained in:
Luxferre committed 2026-10-25 14:14:21 +02:00
1 parent b2216c186f
commit e77be498bf
44 files changed
+432 -211

No files matched your search

+23 -21
View File
@@ -530,6 +530,16 @@ int runFilesApp(int argc, char** argv) {
actionSelected = 0;
};
auto hideWindow = [&]() {
if (!visible) return;
writeSoftkeySuppress(nowMs() + 450);
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
visible = false;
::unlink(activePidPath.c_str());
};
auto openSelectedItem = [&]() {
if (filteredItems.empty()) return;
const FileItem item = filteredItems[selected];
@@ -549,9 +559,9 @@ int runFilesApp(int argc, char** argv) {
if (isImageExt(ext)) {
openImageViewer(item);
} else if (isMediaExt(ext)) {
hideWindow();
runAsyncArgv("sxmo_open.sh", item.fullPath.c_str());
statusBanner = "Opening in media player...";
statusBannerUntilMs = nowMs() + 1800;
return;
} else if (isLikelyTextFile(item.fullPath, item.size)) {
openTextViewer(item);
} else {
@@ -889,24 +899,17 @@ int runFilesApp(int argc, char** argv) {
};
auto showWindow = [&](const std::string& dirArg) {
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("files");
mode = ViewMode::Browser;
loadDirectory(dirArg.empty() ? currentDir : dirArg);
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);
@@ -914,16 +917,6 @@ int runFilesApp(int argc, char** argv) {
drawUI();
};
auto hideWindow = [&]() {
if (!visible) return;
writeSoftkeySuppress(nowMs() + 450);
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
visible = false;
::unlink(activePidPath.c_str());
};
auto commitModalTap = [&](int digit) {
const char* chars = kMultiTapFile[digit];
int len = static_cast<int>(std::strlen(chars));
@@ -1157,6 +1150,15 @@ int runFilesApp(int argc, char** argv) {
if (ev.type == Expose && ev.xexpose.count == 0) {
drawUI();
} else if (ev.type == VisibilityNotify &&
ev.xvisibility.state != VisibilityUnobscured) {
if (isAnotherPluginActive("files")) {
hideWindow();
} else {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
drawUI();
}
} else if (ev.type == KeyPress) {
int64_t tNow = nowMs();
unsigned int kc = ev.xkey.keycode;