Preempt X11 keyboard grabs and window stacking when lockscreen is active

This commit is contained in:
Luxferre committed 2026-11-01 10:39:40 +02:00
1 parent 83dd79fe76
commit f112b6ae72
78 files changed
+403 -53

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
- **Passcode-based fullscreen phone locker (`locker.so` / `xlocker`) and GUI passcode configurator (`passcode.so` / `xpasscode`)**: - **Passcode-based fullscreen phone locker (`locker.so` / `xlocker`) and GUI passcode configurator (`passcode.so` / `xpasscode`)**:
- Added a fullscreen `240x320` (`X=0, Y=0`) override-redirect numeric passcode lock screen (`xlocker` / `locker.so`) verified against the current user's shadow password (`147147` by default, supporting any numeric passcode of `4+` digits) via `/usr/bin/bananarchy-verify-passcode`, activating automatically upon GUI startup on device boot. - Added a fullscreen `240x320` (`X=0, Y=0`) override-redirect numeric passcode lock screen (`xlocker` / `locker.so`) verified against the current user's shadow password (`147147` by default, supporting any numeric passcode of `4+` digits) via `/usr/bin/bananarchy-verify-passcode`, activating automatically upon GUI startup on device boot.
- Added a NeoUI-based **Passcode & Duress Configurator (`passcode.so` / `xpasscode`)** in the **Config** and **Applications** menus with two tabs (`User PIN` and `Duress PIN`) to change the real Linux `user` password in `/etc/shadow` (`4+` numeric digits, immediately updating `/etc/shadow` for SSH, TTY, and `doas`/`sudo` authentication after verifying the current PIN) and configure or clear a separate numeric duress passcode (`/etc/bananarchy/duress.hash`, rejecting collisions with the real user passcode). - Added a NeoUI-based **Passcode & Duress Configurator (`passcode.so` / `xpasscode`)** in the **Config** and **Applications** menus with two tabs (`User PIN` and `Duress PIN`) to change the real Linux `user` password in `/etc/shadow` (`4+` numeric digits, immediately updating `/etc/shadow` for SSH, TTY, and `doas`/`sudo` authentication after verifying the current PIN) and configure or clear a separate numeric duress passcode (`/etc/bananarchy/duress.hash`, rejecting collisions with the real user passcode).
- Enforced zero keypad, softkey, slider, or power-button bypass across `dwm`, `dmenu`, `xdrawer`, `neoui`, and `sxmo_hook_inputhandler.sh` while locked (`/tmp/bananarchy_screen_locked`), allowing only incoming calls to temporarily raise `xcallscreen` and immediately restoring the passcode lock screen when the call ends. - Enforced zero keypad, softkey, slider, or power-button bypass across `dwm`, `dmenu`, `xdrawer`, `neoui`, and `sxmo_hook_inputhandler.sh` while locked (`/tmp/bananarchy_screen_locked`), preempting active X11 keyboard grabs and window stacking over any running application (`webarchy`, `remedy`, `gambatte`, `scoundrel`, `snake`, `tetris`, and all NeoUI plugins), allowing only incoming calls to temporarily raise `xcallscreen` and cleanly restoring the previously focused application upon unlock.
- **Plausible-deniability duress mode (`bananarchy-duress-activate`)**: - **Plausible-deniability duress mode (`bananarchy-duress-activate`)**:
- Entering the configured duress passcode on the `xlocker` lock screen returns exit code `2` from `/usr/bin/bananarchy-verify-passcode` and triggers `/usr/bin/bananarchy-duress-activate`, transparently unlocking the phone into an isolated, non-destructive clean session (`/tmp/bananarchy_duress_mode` and RAM-backed profile `/tmp/duress_home`) that persists until the next reboot or poweroff. - Entering the configured duress passcode on the `xlocker` lock screen returns exit code `2` from `/usr/bin/bananarchy-verify-passcode` and triggers `/usr/bin/bananarchy-duress-activate`, transparently unlocking the phone into an isolated, non-destructive clean session (`/tmp/bananarchy_duress_mode` and RAM-backed profile `/tmp/duress_home`) that persists until the next reboot or poweroff.
- Redirects `getHomeDir()` across all DWM plugins and games to `/tmp/duress_home` so **Contacts (`xcontacts`)**, **SMS (`xsms`)**, **Call Log (`xcalllog`)**, **Email (`xemail`)**, **Kopher (`xkopher`)**, **GPS waypoints (`xgps`)**, **Camera (`xcamera`)**, **Music (`xmusic`)**, and **Ringtones (`xringtones`)** operate against an empty profile with zero personal data while leaving the real `/home/user` untouched on disk. - Redirects `getHomeDir()` across all DWM plugins and games to `/tmp/duress_home` so **Contacts (`xcontacts`)**, **SMS (`xsms`)**, **Call Log (`xcalllog`)**, **Email (`xemail`)**, **Kopher (`xkopher`)**, **GPS waypoints (`xgps`)**, **Camera (`xcamera`)**, **Music (`xmusic`)**, and **Ringtones (`xringtones`)** operate against an empty profile with zero personal data while leaving the real `/home/user` untouched on disk.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -513,7 +513,7 @@ class NeoWindow {
bool overrideRedirect = true, bool overrideRedirect = true,
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask | long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | VisibilityChangeMask | ButtonPressMask | VisibilityChangeMask |
StructureNotifyMask); FocusChangeMask | StructureNotifyMask);
void destroy(); void destroy();
void bindAsActiveContext(); void bindAsActiveContext();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -513,7 +513,7 @@ class NeoWindow {
bool overrideRedirect = true, bool overrideRedirect = true,
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask | long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | VisibilityChangeMask | ButtonPressMask | VisibilityChangeMask |
StructureNotifyMask); FocusChangeMask | StructureNotifyMask);
void destroy(); void destroy();
void bindAsActiveContext(); void bindAsActiveContext();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+9
View File
@@ -297,6 +297,15 @@ int engmenu_run_main(int argc, char** argv) {
if (visible && ev.xexpose.count == 0) { if (visible && ev.xexpose.count == 0) {
render(); render();
} }
} else if (ev.type == VisibilityNotify && visible &&
ev.xvisibility.state != VisibilityUnobscured) {
if (isAnotherPluginActive("engmenu")) {
closeWindow();
} else {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
render();
}
} else if (ev.type == KeyPress) { } else if (ev.type == KeyPress) {
if (!visible) { if (!visible) {
continue; continue;
+13 -4
View File
@@ -420,7 +420,9 @@ int locker_run_main(int argc, char** argv) {
} }
XRaiseWindow(dpy, win); XRaiseWindow(dpy, win);
XSetInputFocus(dpy, win, RevertToParent, CurrentTime); XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
for (int attempt = 0; attempt < 5; ++attempt) { XFlush(dpy);
grabHeld = false;
for (int attempt = 0; attempt < 15; ++attempt) {
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync, if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) { CurrentTime) == GrabSuccess) {
grabHeld = true; grabHeld = true;
@@ -895,12 +897,19 @@ int locker_run_main(int argc, char** argv) {
} }
} }
if (visible && !isScreenBlanked()) { if (visible) {
render(); if (!isCallActiveOrRingingFast() && !grabHeld) {
grabLockerInput();
}
if (!isScreenBlanked()) {
render();
}
} }
int timeoutMs = -1; int timeoutMs = -1;
if (visible && !isScreenBlanked()) { if (visible && !isCallActiveOrRingingFast() && !grabHeld) {
timeoutMs = 35;
} else if (visible && !isScreenBlanked()) {
int64_t now = nowMs(); int64_t now = nowMs();
if (cooldownUntilMs > now) { if (cooldownUntilMs > now) {
timeoutMs = 250; timeoutMs = 250;
+9
View File
@@ -564,6 +564,15 @@ int passcode_run_main(int argc, char** argv) {
if (visible && ev.xexpose.count == 0) { if (visible && ev.xexpose.count == 0) {
render(); render();
} }
} else if (ev.type == VisibilityNotify && visible &&
ev.xvisibility.state != VisibilityUnobscured) {
if (isAnotherPluginActive("passcode")) {
closeWindow();
} else {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
render();
}
} else if (ev.type == KeyPress) { } else if (ev.type == KeyPress) {
if (!visible) { if (!visible) {
continue; continue;
+10
View File
@@ -1893,6 +1893,10 @@ inline void closeOtherPlugins(const char* selfPluginName) {
} }
inline bool isAnotherPluginActive(const char* selfPluginName) { inline bool isAnotherPluginActive(const char* selfPluginName) {
if ((!selfPluginName || std::strcmp(selfPluginName, "locker") != 0) &&
::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
return true;
}
struct PluginRef { struct PluginRef {
const char* pidFile; const char* pidFile;
const char* name; const char* name;
@@ -1939,6 +1943,12 @@ inline bool isAnotherPluginActive(const char* selfPluginName) {
} }
inline void grabPluginKeyboard(Display* dpy, Window win) { inline void grabPluginKeyboard(Display* dpy, Window win) {
if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0 &&
!isCallActiveOrRingingFast()) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
return;
}
for (int i = 0; i < 40; ++i) { for (int i = 0; i < 40; ++i) {
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync, if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) { CurrentTime) == GrabSuccess) {
+19 -1
View File
@@ -1094,7 +1094,7 @@ int webarchy_run_main(int argc, char** argv) {
auto syncWebkitVisibility = [&]() { auto syncWebkitVisibility = [&]() {
if (!br.initialized || br.webkitXid == None) return; if (!br.initialized || br.webkitXid == None) return;
if (visible && !anyModalOpen()) { if (visible && !anyModalOpen() && !isPhonePasscodeLocked()) {
XMoveResizeWindow(neo.dpy, br.webkitXid, 0, 35, 240, 217); XMoveResizeWindow(neo.dpy, br.webkitXid, 0, 35, 240, 217);
XMapRaised(neo.dpy, br.webkitXid); XMapRaised(neo.dpy, br.webkitXid);
} else if (visible) { } else if (visible) {
@@ -1358,6 +1358,7 @@ int webarchy_run_main(int argc, char** argv) {
openWindow(); openWindow();
} }
bool mutedByLock = false;
while (gRunning) { while (gRunning) {
for (const std::string& cmd : readFifoLines(fifoFd)) { for (const std::string& cmd : readFifoLines(fifoFd)) {
if (cmd == "NOP") continue; if (cmd == "NOP") continue;
@@ -1407,6 +1408,23 @@ int webarchy_run_main(int argc, char** argv) {
} }
if (visible) { if (visible) {
if (isPhonePasscodeLocked()) {
if (!mutedByLock) {
mutedByLock = true;
XUngrabKeyboard(neo.dpy, CurrentTime);
XFlush(neo.dpy);
if (br.initialized && br.webView) {
webkit_web_view_set_is_muted(br.webView, TRUE);
}
syncWebkitVisibility();
}
} else if (mutedByLock) {
mutedByLock = false;
if (br.initialized && br.webView) {
webkit_web_view_set_is_muted(br.webView, FALSE);
}
render();
}
neo.bindAsActiveContext(); neo.bindAsActiveContext();
int ev = neoui_poll_event(0); int ev = neoui_poll_event(0);
while (ev != NEO_EV_NONE) { while (ev != NEO_EV_NONE) {
+14 -1
View File
@@ -285,10 +285,14 @@ bool isPidAliveFile(const std::string& path) {
} }
bool isExternalOverlayActive() { bool isExternalOverlayActive() {
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) { if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0 ||
::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0 ||
::access("/tmp/sxmo_call_ringing", F_OK) == 0 ||
::access("/tmp/sxmo_active_call", F_OK) == 0) {
return true; return true;
} }
static const char* kOverlayPids[] = { static const char* kOverlayPids[] = {
"xlocker.pid",
"xdrawer.pid", "xdrawer.pid",
"xcallscreen.pid", "xcallscreen.pid",
"xdialer.pid", "xdialer.pid",
@@ -303,6 +307,15 @@ bool isExternalOverlayActive() {
"xringtones.pid", "xringtones.pid",
"xwallpapers.pid", "xwallpapers.pid",
"xmusic.pid", "xmusic.pid",
"xsip.pid",
"xemail.pid",
"xirc.pid",
"xtox.pid",
"xsmallweb.pid",
"xwebarchy.pid",
"xgps.pid",
"xpasscode.pid",
"xengmenu.pid",
}; };
char uidDir[64]; char uidDir[64];
std::snprintf(uidDir, sizeof(uidDir), "/run/user/%u", std::snprintf(uidDir, sizeof(uidDir), "/run/user/%u",
+140 -30
View File
@@ -18,6 +18,7 @@
#endif #endif
#include <algorithm> #include <algorithm>
#include <csignal>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@@ -205,6 +206,72 @@ class RemedyEmulator {
int pendingSoftkey = 0; // 1=left, 2=right int pendingSoftkey = 0; // 1=left, 2=right
int64_t pendingSoftkeyDeadlineMs = 0; int64_t pendingSoftkeyDeadlineMs = 0;
int64_t rightSoftPressMs = 0; int64_t rightSoftPressMs = 0;
bool grabYielded = false;
int64_t overlayGraceUntilMs = 0;
static bool isPidAliveFile(const std::string& path) {
int fd = ::open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd < 0) return false;
char buf[32];
ssize_t n = ::read(fd, buf, sizeof(buf) - 1);
::close(fd);
if (n <= 0) return false;
buf[n] = '\0';
int pid = std::atoi(buf);
return (pid > 0 && ::kill(pid, 0) == 0);
}
static bool isExternalOverlayActive() {
if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0 ||
::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0 ||
::access("/tmp/sxmo_call_ringing", F_OK) == 0 ||
::access("/tmp/sxmo_active_call", F_OK) == 0) {
return true;
}
static const char* kOverlayPids[] = {
"xlocker.pid",
"xdrawer.pid",
"xcallscreen.pid",
"xdialer.pid",
"xcalllog.pid",
"xcontacts.pid",
"xsms.pid",
"xfiles.pid",
"xcamera.pid",
"xthemes.pid",
"xmodem.pid",
"xnetworks.pid",
"xringtones.pid",
"xwallpapers.pid",
"xmusic.pid",
"xsip.pid",
"xemail.pid",
"xirc.pid",
"xtox.pid",
"xsmallweb.pid",
"xwebarchy.pid",
"xgps.pid",
"xpasscode.pid",
"xengmenu.pid",
};
char uidDir[64];
std::snprintf(uidDir, sizeof(uidDir), "/run/user/%u",
static_cast<unsigned>(::getuid()));
const char* envRdir = std::getenv("XDG_RUNTIME_DIR");
for (const char* pf : kOverlayPids) {
if (envRdir && envRdir[0] &&
isPidAliveFile(std::string(envRdir) + "/" + pf)) {
return true;
}
if (isPidAliveFile(std::string(uidDir) + "/" + pf)) {
return true;
}
if (isPidAliveFile(std::string("/tmp/") + pf)) {
return true;
}
}
return false;
}
// Minimum 80ms / 2-tick hold for Canvas key presses so polling game loops // Minimum 80ms / 2-tick hold for Canvas key presses so polling game loops
// (e.g. 58ms sleep in Castlevania / Tomb Raider) never miss brisk key taps // (e.g. 58ms sleep in Castlevania / Tomb Raider) never miss brisk key taps
@@ -282,13 +349,21 @@ class RemedyEmulator {
void grabKeyboard() { void grabKeyboard() {
if (!neoWin.dpy || neoWin.win == None) return; if (!neoWin.dpy || neoWin.win == None) return;
if (isExternalOverlayActive()) {
ungrabKeyboard();
return;
}
bool grabbed = false;
for (int i = 0; i < 15; ++i) { for (int i = 0; i < 15; ++i) {
if (XGrabKeyboard(neoWin.dpy, neoWin.win, True, GrabModeAsync, if (XGrabKeyboard(neoWin.dpy, neoWin.win, True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) { GrabModeAsync, CurrentTime) == GrabSuccess) {
grabbed = true;
break; break;
} }
usleep(10000); usleep(10000);
} }
grabYielded = !grabbed;
XFlush(neoWin.dpy);
} }
void ungrabKeyboard() { void ungrabKeyboard() {
@@ -296,27 +371,21 @@ class RemedyEmulator {
XUngrabKeyboard(neoWin.dpy, CurrentTime); XUngrabKeyboard(neoWin.dpy, CurrentTime);
XFlush(neoWin.dpy); XFlush(neoWin.dpy);
} }
grabYielded = true;
} }
void openXdrawerAndRestoreGrab() { void openXdrawerAndRestoreGrab() {
cldcRuntime.sound.setPaused(true); cldcRuntime.sound.setPaused(true);
ungrabKeyboard(); ungrabKeyboard();
std::system("dwm-plugin xdrawer >/dev/null 2>&1"); overlayGraceUntilMs = Jvm::NowMs() + 300;
usleep(120000); int ffd = ::open("/tmp/dwm_plugin_xdrawer.fifo",
for (int wait = 0; wait < 600; ++wait) { O_WRONLY | O_NONBLOCK | O_CLOEXEC);
usleep(50000); if (ffd >= 0) {
Window foc = None; (void)::write(ffd, "TOGGLE\n", 7);
int rev = 0; ::close(ffd);
XGetInputFocus(neoWin.dpy, &foc, &rev); } else {
if (foc == neoWin.win || foc == PointerRoot || foc == None) break; std::system("dwm-plugin xdrawer >/dev/null 2>&1 &");
} }
XRaiseWindow(neoWin.dpy, neoWin.win);
XSetInputFocus(neoWin.dpy, neoWin.win, RevertToParent, CurrentTime);
grabKeyboard();
cldcRuntime.sound.refreshSystemVolume(true);
cldcRuntime.sound.setPaused(mode != EmuUiMode::RUNNING);
neoWin.checkReloadTheme();
appCtx.repaintPending = true;
} }
void scanBrowser() { void scanBrowser() {
@@ -1224,23 +1293,15 @@ class RemedyEmulator {
} else if (keycode == 124 || ks == XF86XK_PowerOff) { } else if (keycode == 124 || ks == XF86XK_PowerOff) {
cldcRuntime.sound.setPaused(true); cldcRuntime.sound.setPaused(true);
ungrabKeyboard(); ungrabKeyboard();
overlayGraceUntilMs = Jvm::NowMs() + 300;
int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo", int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC); O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) { if (ffd >= 0) {
(void)::write(ffd, "OPEN power\n", 11); (void)::write(ffd, "OPEN power\n", 11);
::close(ffd); ::close(ffd);
} else { } else {
std::system("dmenu power >/dev/null 2>&1"); std::system("dmenu power >/dev/null 2>&1 &");
} }
usleep(120000);
for (int wait = 0; wait < 600; ++wait) {
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) != 0) break;
usleep(50000);
}
XRaiseWindow(neoWin.dpy, neoWin.win);
XSetInputFocus(neoWin.dpy, neoWin.win, RevertToParent, CurrentTime);
grabKeyboard();
appCtx.repaintPending = true;
return true; return true;
} }
@@ -1598,7 +1659,32 @@ class RemedyEmulator {
bool running = true; bool running = true;
while (running) { while (running) {
updateTimer(cfg.fpsLimit); updateTimer(cfg.fpsLimit);
cldcRuntime.sound.setPaused(mode != EmuUiMode::RUNNING); bool overlayNow =
isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs);
if (overlayNow) {
if (!grabYielded) {
ungrabKeyboard();
}
leftSoftDown = false;
rightSoftDown = false;
pendingSoftkey = 0;
cldcRuntime.sound.setPaused(true);
} else if (grabYielded) {
XRaiseWindow(neoWin.dpy, neoWin.win);
XSetInputFocus(neoWin.dpy, neoWin.win, RevertToParent, CurrentTime);
grabKeyboard();
cldcRuntime.sound.refreshSystemVolume(true);
cldcRuntime.sound.setPaused(mode != EmuUiMode::RUNNING);
neoWin.checkReloadTheme();
appCtx.repaintPending = true;
if (mode == EmuUiMode::BROWSER) renderBrowserMenu();
else if (mode == EmuUiMode::PAUSED) renderPauseMenu();
else if (mode == EmuUiMode::CONTROLS || mode == EmuUiMode::WAITING_KEY) {
renderControlsMenu();
}
} else {
cldcRuntime.sound.setPaused(mode != EmuUiMode::RUNNING);
}
while (XPending(neoWin.dpy) > 0) { while (XPending(neoWin.dpy) > 0) {
XEvent ev; XEvent ev;
XNextEvent(neoWin.dpy, &ev); XNextEvent(neoWin.dpy, &ev);
@@ -1609,13 +1695,36 @@ class RemedyEmulator {
else if (mode == EmuUiMode::CONTROLS || mode == EmuUiMode::WAITING_KEY) { else if (mode == EmuUiMode::CONTROLS || mode == EmuUiMode::WAITING_KEY) {
renderControlsMenu(); renderControlsMenu();
} }
} else if (ev.type == VisibilityNotify) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
} else if (ev.xvisibility.state != VisibilityUnobscured) {
XRaiseWindow(neoWin.dpy, neoWin.win);
XFlush(neoWin.dpy);
}
} else if (ev.type == FocusOut) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
}
} else if (ev.type == KeyPress) { } else if (ev.type == KeyPress) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
continue;
}
KeySym ks = XLookupKeysym(&ev.xkey, 0); KeySym ks = XLookupKeysym(&ev.xkey, 0);
if (!handleKeyPress(ks, ev.xkey.keycode)) { if (!handleKeyPress(ks, ev.xkey.keycode)) {
running = false; running = false;
break; break;
} }
} else if (ev.type == KeyRelease) { } else if (ev.type == KeyRelease) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
continue;
}
if (XEventsQueued(neoWin.dpy, QueuedAfterReading)) { if (XEventsQueued(neoWin.dpy, QueuedAfterReading)) {
XEvent nev; XEvent nev;
XPeekEvent(neoWin.dpy, &nev); XPeekEvent(neoWin.dpy, &nev);
@@ -1645,8 +1754,8 @@ class RemedyEmulator {
} }
if (!running) break; if (!running) break;
if (mode == EmuUiMode::RUNNING && rightSoftDown && !leftSoftDown && if (!overlayNow && mode == EmuUiMode::RUNNING && rightSoftDown &&
!chordTriggered && !rightSoftLongTriggered && !leftSoftDown && !chordTriggered && !rightSoftLongTriggered &&
Jvm::NowMs() - rightSoftPressMs >= 500) { Jvm::NowMs() - rightSoftPressMs >= 500) {
rightSoftLongTriggered = true; rightSoftLongTriggered = true;
pendingSoftkey = 0; pendingSoftkey = 0;
@@ -1657,7 +1766,8 @@ class RemedyEmulator {
renderPauseMenu(); renderPauseMenu();
} }
if (pendingSoftkey != 0 && Jvm::NowMs() >= pendingSoftkeyDeadlineMs) { if (!overlayNow && pendingSoftkey != 0 &&
Jvm::NowMs() >= pendingSoftkeyDeadlineMs) {
int s = pendingSoftkey; int s = pendingSoftkey;
pendingSoftkey = 0; pendingSoftkey = 0;
if (!chordTriggered && !dispatchSoftkeyAction(s)) { if (!chordTriggered && !dispatchSoftkeyAction(s)) {
@@ -1676,7 +1786,7 @@ class RemedyEmulator {
uint64_t exp = 0; uint64_t exp = 0;
if (read(tfd, &exp, sizeof(exp)) < 0) {} if (read(tfd, &exp, sizeof(exp)) < 0) {}
neoWin.checkReloadTheme(); neoWin.checkReloadTheme();
if (mode == EmuUiMode::RUNNING) { if (mode == EmuUiMode::RUNNING && !overlayNow) {
tickRunningMidlet(); tickRunningMidlet();
frameCounter++; frameCounter++;
int64_t now = Jvm::NowMs(); int64_t now = Jvm::NowMs();
+4 -2
View File
@@ -996,7 +996,8 @@ int main() {
if (neoui_event_keysym() == XF86XK_PowerOff || if (neoui_event_keysym() == XF86XK_PowerOff ||
neoui_event_keycode() == 124) { neoui_event_keycode() == 124) {
::usleep(80000); ::usleep(80000);
while (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) { while (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0 ||
::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
::usleep(50000); ::usleep(50000);
} }
neoui_raise_and_grab(); neoui_raise_and_grab();
@@ -1017,7 +1018,8 @@ int main() {
if (evType == NEO_EV_SOFTKEY_CHORD) { if (evType == NEO_EV_SOFTKEY_CHORD) {
::usleep(80000); ::usleep(80000);
while (::access("/run/user/10000/xdrawer.pid", F_OK) == 0 || while (::access("/run/user/10000/xdrawer.pid", F_OK) == 0 ||
::access("/tmp/xdrawer.pid", F_OK) == 0) { ::access("/tmp/xdrawer.pid", F_OK) == 0 ||
::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
::usleep(50000); ::usleep(50000);
} }
neoui_raise_and_grab(); neoui_raise_and_grab();
+3 -1
View File
@@ -486,7 +486,9 @@ static void handle_event(XEvent& e) {
} else if (e.type == Expose) { } else if (e.type == Expose) {
if (e.xexpose.count == 0) dirty = true; if (e.xexpose.count == 0) dirty = true;
} else if (e.type == FocusOut) { } else if (e.type == FocusOut) {
if (e.xfocus.mode == NotifyNormal && state == PLAYING) { if ((e.xfocus.mode == NotifyNormal || e.xfocus.mode == NotifyGrab ||
e.xfocus.mode == NotifyWhileGrabbed) &&
state == PLAYING) {
state = PAUSED; state = PAUSED;
dirty = true; dirty = true;
} }
+3 -1
View File
@@ -628,7 +628,9 @@ static void handle_event(XEvent& e) {
} else if (e.type == Expose) { } else if (e.type == Expose) {
if (e.xexpose.count == 0) dirty = true; if (e.xexpose.count == 0) dirty = true;
} else if (e.type == FocusOut) { } else if (e.type == FocusOut) {
if (e.xfocus.mode == NotifyNormal && state == PLAYING) { if ((e.xfocus.mode == NotifyNormal || e.xfocus.mode == NotifyGrab ||
e.xfocus.mode == NotifyWhileGrabbed) &&
state == PLAYING) {
state = PAUSED; state = PAUSED;
dirty = true; dirty = true;
} }
+156 -6
View File
@@ -179,6 +179,59 @@ bool isCallActiveOrRingingInNeoui() {
return false; return false;
} }
bool isPidFileAliveNeoui(const std::string& path) {
int fd = ::open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd < 0) return false;
char buf[32];
ssize_t n = ::read(fd, buf, sizeof(buf) - 1);
::close(fd);
if (n <= 0) return false;
buf[n] = '\0';
int pid = std::atoi(buf);
return (pid > 0 && ::kill(pid, 0) == 0);
}
bool isRuntimePidAliveNeoui(const char* pidFile) {
const char* envRdir = std::getenv("XDG_RUNTIME_DIR");
if (envRdir && envRdir[0] &&
isPidFileAliveNeoui(std::string(envRdir) + "/" + pidFile)) {
return true;
}
char uidDir[64];
std::snprintf(uidDir, sizeof(uidDir), "/run/user/%u/%s",
static_cast<unsigned>(::getuid()), pidFile);
if (isPidFileAliveNeoui(uidDir)) {
return true;
}
return isPidFileAliveNeoui(std::string("/tmp/") + pidFile);
}
bool isExternalOverlayOrLockActive(const std::string& appName) {
if (appName != "callscreen" && appName != "xcallscreen") {
if (isCallActiveOrRingingInNeoui() ||
isRuntimePidAliveNeoui("xcallscreen.pid")) {
return true;
}
}
if (appName != "locker" && appName != "xlocker") {
if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0 ||
isRuntimePidAliveNeoui("xlocker.pid")) {
return true;
}
}
if (appName != "xdrawer") {
if (isRuntimePidAliveNeoui("xdrawer.pid")) {
return true;
}
}
if (appName != "dmenu" && appName != "xdmenu") {
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) {
return true;
}
}
return false;
}
int mapHardwareKey(KeySym sym, unsigned int keycode, unsigned int state) { int mapHardwareKey(KeySym sym, unsigned int keycode, unsigned int state) {
if (keycode == 135 || sym == XK_Super_L || sym == XK_Menu || if (keycode == 135 || sym == XK_Super_L || sym == XK_Menu ||
static_cast<uint32_t>(sym) == _EVDEVK(0x8b)) { static_cast<uint32_t>(sym) == _EVDEVK(0x8b)) {
@@ -1406,7 +1459,7 @@ bool NeoWindow::create(const char* resName, const char* resClass,
swa.override_redirect = overrideRedirect ? True : False; swa.override_redirect = overrideRedirect ? True : False;
swa.background_pixel = 0x222222; swa.background_pixel = 0x222222;
swa.border_pixel = 0x005577; swa.border_pixel = 0x005577;
swa.event_mask = eventMask; swa.event_mask = eventMask | VisibilityChangeMask | FocusChangeMask;
win = XCreateWindow( win = XCreateWindow(
dpy, root, x, y, width, height, 0, DefaultDepth(dpy, screen), dpy, root, x, y, width, height, 0, DefaultDepth(dpy, screen),
@@ -1502,6 +1555,8 @@ struct NeoContext {
bool initialSoftkeysReleased = true; bool initialSoftkeysReleased = true;
int softkeyPending = 0; int softkeyPending = 0;
int64_t softkeyDeadlineMs = 0; int64_t softkeyDeadlineMs = 0;
bool grabYielded = false;
int64_t overlayGraceUntilMs = 0;
// Last polled event // Last polled event
int lastEventType = NEO_EV_NONE; int lastEventType = NEO_EV_NONE;
@@ -1587,6 +1642,16 @@ namespace bananarchy {
void NeoWindow::bindAsActiveContext() { void NeoWindow::bindAsActiveContext() {
NeoContext* ctx = ensureCtx(); NeoContext* ctx = ensureCtx();
ctx->w = this; ctx->w = this;
if (ctx->appName.empty() && dpy && win != None) {
XClassHint ch{};
if (XGetClassHint(dpy, win, &ch)) {
if (ch.res_name && ch.res_name[0]) {
ctx->appName = ch.res_name;
}
if (ch.res_name) XFree(ch.res_name);
if (ch.res_class) XFree(ch.res_class);
}
}
} }
} // namespace bananarchy } // namespace bananarchy
@@ -1698,16 +1763,26 @@ int neoui_is_visible(void) {
int neoui_raise_and_grab(void) { int neoui_raise_and_grab(void) {
NeoContext* ctx = ensureCtx(); NeoContext* ctx = ensureCtx();
if (!ctx->w || !ctx->w->dpy || ctx->w->win == None) return 0; if (!ctx->w || !ctx->w->dpy || ctx->w->win == None) return 0;
if (bananarchy::isExternalOverlayOrLockActive(ctx->appName)) {
XUngrabKeyboard(ctx->w->dpy, CurrentTime);
XFlush(ctx->w->dpy);
ctx->grabYielded = true;
return 0;
}
XRaiseWindow(ctx->w->dpy, ctx->w->win); XRaiseWindow(ctx->w->dpy, ctx->w->win);
XSetInputFocus(ctx->w->dpy, ctx->w->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(ctx->w->dpy, ctx->w->win, RevertToPointerRoot, CurrentTime);
bool grabbed = false;
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
if (XGrabKeyboard(ctx->w->dpy, ctx->w->win, True, GrabModeAsync, if (XGrabKeyboard(ctx->w->dpy, ctx->w->win, True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) { GrabModeAsync, CurrentTime) == GrabSuccess) {
grabbed = true;
break; break;
} }
::usleep(12000); ::usleep(12000);
} }
return 1; ctx->grabYielded = !grabbed;
XFlush(ctx->w->dpy);
return grabbed ? 1 : 0;
} }
int neoui_ungrab(void) { int neoui_ungrab(void) {
@@ -1715,6 +1790,8 @@ int neoui_ungrab(void) {
if (!ctx->w || !ctx->w->dpy) return 0; if (!ctx->w || !ctx->w->dpy) return 0;
XUngrabKeyboard(ctx->w->dpy, CurrentTime); XUngrabKeyboard(ctx->w->dpy, CurrentTime);
XSetInputFocus(ctx->w->dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSetInputFocus(ctx->w->dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
ctx->grabYielded = true;
XFlush(ctx->w->dpy);
return 1; return 1;
} }
@@ -2645,6 +2722,38 @@ int neoui_poll_event(int timeout_ms) {
int64_t now = bananarchy::monotonicMs(); int64_t now = bananarchy::monotonicMs();
auto syncOverlayGrabState = [&]() -> int {
int64_t tNow = bananarchy::monotonicMs();
bool overlayActive =
ctx->visible &&
(bananarchy::isExternalOverlayOrLockActive(ctx->appName) ||
tNow < ctx->overlayGraceUntilMs);
if (overlayActive) {
if (!ctx->grabYielded) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
ctx->grabYielded = true;
}
ctx->softkeyPending = 0;
return NEO_EV_NONE;
}
if (ctx->visible && ctx->grabYielded) {
neoui_raise_and_grab();
if (!ctx->grabYielded) {
ctx->startupIgnoreUntilMs = tNow + 200;
ctx->initialSoftkeysReleased =
(bananarchy::querySoftkeysMask(dpy) == 0);
ctx->softkeyPending = 0;
ctx->lastEventType = NEO_EV_EXPOSE;
return NEO_EV_EXPOSE;
}
}
return NEO_EV_NONE;
};
int ovEv = syncOverlayGrabState();
if (ovEv != NEO_EV_NONE) return ovEv;
// Check if multi-tap timer expired // Check if multi-tap timer expired
if (ctx->tapActive && (now - ctx->lastTapMs >= 850)) { if (ctx->tapActive && (now - ctx->lastTapMs >= 850)) {
ctx->tapActive = false; ctx->tapActive = false;
@@ -2693,6 +2802,11 @@ int neoui_poll_event(int timeout_ms) {
XNextEvent(dpy, &ev); XNextEvent(dpy, &ev);
if (ev.type == Expose) { if (ev.type == Expose) {
while (XCheckTypedWindowEvent(dpy, ctx->w->win, Expose, &ev)) {} while (XCheckTypedWindowEvent(dpy, ctx->w->win, Expose, &ev)) {}
if (ctx->visible && ctx->grabYielded &&
!bananarchy::isExternalOverlayOrLockActive(ctx->appName) &&
bananarchy::monotonicMs() >= ctx->overlayGraceUntilMs) {
neoui_raise_and_grab();
}
ctx->lastEventType = NEO_EV_EXPOSE; ctx->lastEventType = NEO_EV_EXPOSE;
return NEO_EV_EXPOSE; return NEO_EV_EXPOSE;
} }
@@ -2705,13 +2819,42 @@ int neoui_poll_event(int timeout_ms) {
continue; continue;
} }
if (ev.type == VisibilityNotify && ctx->visible) { if (ev.type == VisibilityNotify && ctx->visible) {
if (ev.xvisibility.state != VisibilityUnobscured) { if (bananarchy::isExternalOverlayOrLockActive(ctx->appName) ||
bananarchy::monotonicMs() < ctx->overlayGraceUntilMs) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
ctx->grabYielded = true;
} else if (ev.xvisibility.state != VisibilityUnobscured) {
XRaiseWindow(dpy, ctx->w->win); XRaiseWindow(dpy, ctx->w->win);
XFlush(dpy); XFlush(dpy);
} else if (ctx->grabYielded) {
neoui_raise_and_grab();
ctx->startupIgnoreUntilMs = bananarchy::monotonicMs() + 200;
ctx->initialSoftkeysReleased =
(bananarchy::querySoftkeysMask(dpy) == 0);
ctx->softkeyPending = 0;
ctx->lastEventType = NEO_EV_EXPOSE;
return NEO_EV_EXPOSE;
}
continue;
}
if (ev.type == FocusOut && ctx->visible) {
if (bananarchy::isExternalOverlayOrLockActive(ctx->appName) ||
bananarchy::monotonicMs() < ctx->overlayGraceUntilMs) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
ctx->grabYielded = true;
} }
continue; continue;
} }
if (ev.type == KeyPress || ev.type == KeyRelease) { if (ev.type == KeyPress || ev.type == KeyRelease) {
if (bananarchy::isExternalOverlayOrLockActive(ctx->appName) ||
bananarchy::monotonicMs() < ctx->overlayGraceUntilMs) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
ctx->grabYielded = true;
continue;
}
KeySym sym = XLookupKeysym(&ev.xkey, 0); KeySym sym = XLookupKeysym(&ev.xkey, 0);
unsigned int kc = ev.xkey.keycode; unsigned int kc = ev.xkey.keycode;
int nkey = bananarchy::mapHardwareKey(sym, kc, ev.xkey.state); int nkey = bananarchy::mapHardwareKey(sym, kc, ev.xkey.state);
@@ -2740,10 +2883,10 @@ int neoui_poll_event(int timeout_ms) {
} }
if (::access("/tmp/bananarchy_screen_locked", F_OK) != 0) { if (::access("/tmp/bananarchy_screen_locked", F_OK) != 0) {
neoui_ungrab(); neoui_ungrab();
ctx->overlayGraceUntilMs = tNow + 250;
XFlush(dpy); XFlush(dpy);
bananarchy::sendPluginFifoMsg("dmenu", "OPEN power"); bananarchy::sendPluginFifoMsg("dmenu", "OPEN power");
ctx->lastEventType = NEO_EV_CLOSE_REQ; continue;
return NEO_EV_CLOSE_REQ;
} }
} }
if (ctx->chordXdrawer && if (ctx->chordXdrawer &&
@@ -2754,6 +2897,7 @@ int neoui_poll_event(int timeout_ms) {
if (ctx->softkeyPending == otherBit || (kmMask & otherBit)) { if (ctx->softkeyPending == otherBit || (kmMask & otherBit)) {
ctx->softkeyPending = 0; ctx->softkeyPending = 0;
neoui_ungrab(); neoui_ungrab();
ctx->overlayGraceUntilMs = tNow + 250;
bananarchy::sendPluginFifoMsg("xdrawer", "TOGGLE"); bananarchy::sendPluginFifoMsg("xdrawer", "TOGGLE");
ctx->lastEventType = NEO_EV_SOFTKEY_CHORD; ctx->lastEventType = NEO_EV_SOFTKEY_CHORD;
return NEO_EV_SOFTKEY_CHORD; return NEO_EV_SOFTKEY_CHORD;
@@ -2789,6 +2933,9 @@ int neoui_poll_event(int timeout_ms) {
// Calculate effective poll timeout // Calculate effective poll timeout
int waitMs = timeout_ms; int waitMs = timeout_ms;
if (ctx->visible && ctx->grabYielded && waitMs != 0) {
if (waitMs < 0 || waitMs > 100) waitMs = 100;
}
if (ctx->softkeyPending != 0) { if (ctx->softkeyPending != 0) {
int rem = static_cast<int>( int rem = static_cast<int>(
std::max<int64_t>(1, ctx->softkeyDeadlineMs - bananarchy::monotonicMs())); std::max<int64_t>(1, ctx->softkeyDeadlineMs - bananarchy::monotonicMs()));
@@ -2857,7 +3004,10 @@ int neoui_poll_event(int timeout_ms) {
return NEO_EV_EXPOSE; return NEO_EV_EXPOSE;
} }
return processNextXEvent(); ovEv = syncOverlayGrabState();
int postEv = processNextXEvent();
if (postEv != NEO_EV_NONE) return postEv;
return ovEv;
} }
int neoui_event_key(void) { int neoui_event_key(void) {
+1 -1
View File
@@ -513,7 +513,7 @@ class NeoWindow {
bool overrideRedirect = true, bool overrideRedirect = true,
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask | long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | VisibilityChangeMask | ButtonPressMask | VisibilityChangeMask |
StructureNotifyMask); FocusChangeMask | StructureNotifyMask);
void destroy(); void destroy();
void bindAsActiveContext(); void bindAsActiveContext();
+19 -3
View File
@@ -1270,6 +1270,15 @@ activate_selection(unsigned int ev_state)
return; return;
} }
if (strncmp(act, "@plugin:", 8) == 0) { if (strncmp(act, "@plugin:", 8) == 0) {
if (strncmp(act + 8, "locker", 6) == 0) {
int lfd = open("/tmp/bananarchy_screen_locked",
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (lfd >= 0) {
(void)write(lfd, "1\n", 2);
close(lfd);
}
prevfocuswin = None;
}
hide_menu(); hide_menu();
menu_mode = MODE_NONE; menu_mode = MODE_NONE;
trigger_plugin_open(act + 8); trigger_plugin_open(act + 8);
@@ -3278,10 +3287,15 @@ show_menu(void)
if (!engage_ime) if (!engage_ime)
update_t9_status_indicator(); update_t9_status_indicator();
int keep_plugins_open =
(strcmp(current_builtin_menu, "power") == 0 ||
strncmp(current_builtin_menu, "confirm_", 8) == 0);
if (!menu_active) { if (!menu_active) {
menu_active = 1; menu_active = 1;
mark_menu_active(1); mark_menu_active(1);
close_other_active_plugins(); if (!keep_plugins_open)
close_other_active_plugins();
prevfocuswin = None; prevfocuswin = None;
Window fw = None; Window fw = None;
int rev = 0; int rev = 0;
@@ -3322,7 +3336,8 @@ show_menu(void)
XSetICFocus(xic); XSetICFocus(xic);
XFlush(dpy); XFlush(dpy);
} else { } else {
close_other_active_plugins(); if (!keep_plugins_open)
close_other_active_plugins();
init_soft_mask = 0; init_soft_mask = 0;
init_soft_ms = 0; init_soft_ms = 0;
start_ignore = dmenu_now_ms() + 60; start_ignore = dmenu_now_ms() + 60;
@@ -3357,7 +3372,8 @@ hide_menu(void)
} }
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
XSetErrorHandler(ignore_xerror); XSetErrorHandler(ignore_xerror);
if (prevfocuswin && prevfocuswin != win && prevfocuswin != PointerRoot) { if (prevfocuswin && prevfocuswin != win && prevfocuswin != PointerRoot &&
access("/tmp/bananarchy_screen_locked", F_OK) != 0) {
XWindowAttributes wa; XWindowAttributes wa;
if (XGetWindowAttributes(dpy, prevfocuswin, &wa) && wa.map_state == IsViewable) if (XGetWindowAttributes(dpy, prevfocuswin, &wa) && wa.map_state == IsViewable)
XSetInputFocus(dpy, prevfocuswin, RevertToParent, CurrentTime); XSetInputFocus(dpy, prevfocuswin, RevertToParent, CurrentTime);