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

+9
View File
@@ -297,6 +297,15 @@ int engmenu_run_main(int argc, char** argv) {
if (visible && ev.xexpose.count == 0) {
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) {
if (!visible) {
continue;
+13 -4
View File
@@ -420,7 +420,9 @@ int locker_run_main(int argc, char** argv) {
}
XRaiseWindow(dpy, win);
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,
CurrentTime) == GrabSuccess) {
grabHeld = true;
@@ -895,12 +897,19 @@ int locker_run_main(int argc, char** argv) {
}
}
if (visible && !isScreenBlanked()) {
render();
if (visible) {
if (!isCallActiveOrRingingFast() && !grabHeld) {
grabLockerInput();
}
if (!isScreenBlanked()) {
render();
}
}
int timeoutMs = -1;
if (visible && !isScreenBlanked()) {
if (visible && !isCallActiveOrRingingFast() && !grabHeld) {
timeoutMs = 35;
} else if (visible && !isScreenBlanked()) {
int64_t now = nowMs();
if (cooldownUntilMs > now) {
timeoutMs = 250;
+9
View File
@@ -564,6 +564,15 @@ int passcode_run_main(int argc, char** argv) {
if (visible && ev.xexpose.count == 0) {
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) {
if (!visible) {
continue;
+10
View File
@@ -1893,6 +1893,10 @@ inline void closeOtherPlugins(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 {
const char* pidFile;
const char* name;
@@ -1939,6 +1943,12 @@ inline bool isAnotherPluginActive(const char* selfPluginName) {
}
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) {
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) {
+19 -1
View File
@@ -1094,7 +1094,7 @@ int webarchy_run_main(int argc, char** argv) {
auto syncWebkitVisibility = [&]() {
if (!br.initialized || br.webkitXid == None) return;
if (visible && !anyModalOpen()) {
if (visible && !anyModalOpen() && !isPhonePasscodeLocked()) {
XMoveResizeWindow(neo.dpy, br.webkitXid, 0, 35, 240, 217);
XMapRaised(neo.dpy, br.webkitXid);
} else if (visible) {
@@ -1358,6 +1358,7 @@ int webarchy_run_main(int argc, char** argv) {
openWindow();
}
bool mutedByLock = false;
while (gRunning) {
for (const std::string& cmd : readFifoLines(fifoFd)) {
if (cmd == "NOP") continue;
@@ -1407,6 +1408,23 @@ int webarchy_run_main(int argc, char** argv) {
}
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();
int ev = neoui_poll_event(0);
while (ev != NEO_EV_NONE) {
+14 -1
View File
@@ -285,10 +285,14 @@ bool isPidAliveFile(const std::string& path) {
}
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;
}
static const char* kOverlayPids[] = {
"xlocker.pid",
"xdrawer.pid",
"xcallscreen.pid",
"xdialer.pid",
@@ -303,6 +307,15 @@ bool isExternalOverlayActive() {
"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",
+140 -30
View File
@@ -18,6 +18,7 @@
#endif
#include <algorithm>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -205,6 +206,72 @@ class RemedyEmulator {
int pendingSoftkey = 0; // 1=left, 2=right
int64_t pendingSoftkeyDeadlineMs = 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
// (e.g. 58ms sleep in Castlevania / Tomb Raider) never miss brisk key taps
@@ -282,13 +349,21 @@ class RemedyEmulator {
void grabKeyboard() {
if (!neoWin.dpy || neoWin.win == None) return;
if (isExternalOverlayActive()) {
ungrabKeyboard();
return;
}
bool grabbed = false;
for (int i = 0; i < 15; ++i) {
if (XGrabKeyboard(neoWin.dpy, neoWin.win, True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) {
grabbed = true;
break;
}
usleep(10000);
}
grabYielded = !grabbed;
XFlush(neoWin.dpy);
}
void ungrabKeyboard() {
@@ -296,27 +371,21 @@ class RemedyEmulator {
XUngrabKeyboard(neoWin.dpy, CurrentTime);
XFlush(neoWin.dpy);
}
grabYielded = true;
}
void openXdrawerAndRestoreGrab() {
cldcRuntime.sound.setPaused(true);
ungrabKeyboard();
std::system("dwm-plugin xdrawer >/dev/null 2>&1");
usleep(120000);
for (int wait = 0; wait < 600; ++wait) {
usleep(50000);
Window foc = None;
int rev = 0;
XGetInputFocus(neoWin.dpy, &foc, &rev);
if (foc == neoWin.win || foc == PointerRoot || foc == None) break;
overlayGraceUntilMs = Jvm::NowMs() + 300;
int ffd = ::open("/tmp/dwm_plugin_xdrawer.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) {
(void)::write(ffd, "TOGGLE\n", 7);
::close(ffd);
} else {
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() {
@@ -1224,23 +1293,15 @@ class RemedyEmulator {
} else if (keycode == 124 || ks == XF86XK_PowerOff) {
cldcRuntime.sound.setPaused(true);
ungrabKeyboard();
overlayGraceUntilMs = Jvm::NowMs() + 300;
int ffd = ::open("/tmp/dwm_plugin_dmenu.fifo",
O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (ffd >= 0) {
(void)::write(ffd, "OPEN power\n", 11);
::close(ffd);
} 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;
}
@@ -1598,7 +1659,32 @@ class RemedyEmulator {
bool running = true;
while (running) {
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) {
XEvent ev;
XNextEvent(neoWin.dpy, &ev);
@@ -1609,13 +1695,36 @@ class RemedyEmulator {
else if (mode == EmuUiMode::CONTROLS || mode == EmuUiMode::WAITING_KEY) {
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) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
continue;
}
KeySym ks = XLookupKeysym(&ev.xkey, 0);
if (!handleKeyPress(ks, ev.xkey.keycode)) {
running = false;
break;
}
} else if (ev.type == KeyRelease) {
if (isExternalOverlayActive() || (Jvm::NowMs() < overlayGraceUntilMs)) {
ungrabKeyboard();
cldcRuntime.sound.setPaused(true);
continue;
}
if (XEventsQueued(neoWin.dpy, QueuedAfterReading)) {
XEvent nev;
XPeekEvent(neoWin.dpy, &nev);
@@ -1645,8 +1754,8 @@ class RemedyEmulator {
}
if (!running) break;
if (mode == EmuUiMode::RUNNING && rightSoftDown && !leftSoftDown &&
!chordTriggered && !rightSoftLongTriggered &&
if (!overlayNow && mode == EmuUiMode::RUNNING && rightSoftDown &&
!leftSoftDown && !chordTriggered && !rightSoftLongTriggered &&
Jvm::NowMs() - rightSoftPressMs >= 500) {
rightSoftLongTriggered = true;
pendingSoftkey = 0;
@@ -1657,7 +1766,8 @@ class RemedyEmulator {
renderPauseMenu();
}
if (pendingSoftkey != 0 && Jvm::NowMs() >= pendingSoftkeyDeadlineMs) {
if (!overlayNow && pendingSoftkey != 0 &&
Jvm::NowMs() >= pendingSoftkeyDeadlineMs) {
int s = pendingSoftkey;
pendingSoftkey = 0;
if (!chordTriggered && !dispatchSoftkeyAction(s)) {
@@ -1676,7 +1786,7 @@ class RemedyEmulator {
uint64_t exp = 0;
if (read(tfd, &exp, sizeof(exp)) < 0) {}
neoWin.checkReloadTheme();
if (mode == EmuUiMode::RUNNING) {
if (mode == EmuUiMode::RUNNING && !overlayNow) {
tickRunningMidlet();
frameCounter++;
int64_t now = Jvm::NowMs();
+4 -2
View File
@@ -996,7 +996,8 @@ int main() {
if (neoui_event_keysym() == XF86XK_PowerOff ||
neoui_event_keycode() == 124) {
::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);
}
neoui_raise_and_grab();
@@ -1017,7 +1018,8 @@ int main() {
if (evType == NEO_EV_SOFTKEY_CHORD) {
::usleep(80000);
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);
}
neoui_raise_and_grab();
+3 -1
View File
@@ -486,7 +486,9 @@ static void handle_event(XEvent& e) {
} else if (e.type == Expose) {
if (e.xexpose.count == 0) dirty = true;
} 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;
dirty = true;
}
+3 -1
View File
@@ -628,7 +628,9 @@ static void handle_event(XEvent& e) {
} else if (e.type == Expose) {
if (e.xexpose.count == 0) dirty = true;
} 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;
dirty = true;
}
+156 -6
View File
@@ -179,6 +179,59 @@ bool isCallActiveOrRingingInNeoui() {
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) {
if (keycode == 135 || sym == XK_Super_L || sym == XK_Menu ||
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.background_pixel = 0x222222;
swa.border_pixel = 0x005577;
swa.event_mask = eventMask;
swa.event_mask = eventMask | VisibilityChangeMask | FocusChangeMask;
win = XCreateWindow(
dpy, root, x, y, width, height, 0, DefaultDepth(dpy, screen),
@@ -1502,6 +1555,8 @@ struct NeoContext {
bool initialSoftkeysReleased = true;
int softkeyPending = 0;
int64_t softkeyDeadlineMs = 0;
bool grabYielded = false;
int64_t overlayGraceUntilMs = 0;
// Last polled event
int lastEventType = NEO_EV_NONE;
@@ -1587,6 +1642,16 @@ namespace bananarchy {
void NeoWindow::bindAsActiveContext() {
NeoContext* ctx = ensureCtx();
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
@@ -1698,16 +1763,26 @@ int neoui_is_visible(void) {
int neoui_raise_and_grab(void) {
NeoContext* ctx = ensureCtx();
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);
XSetInputFocus(ctx->w->dpy, ctx->w->win, RevertToPointerRoot, CurrentTime);
bool grabbed = false;
for (int i = 0; i < 8; ++i) {
if (XGrabKeyboard(ctx->w->dpy, ctx->w->win, True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) {
grabbed = true;
break;
}
::usleep(12000);
}
return 1;
ctx->grabYielded = !grabbed;
XFlush(ctx->w->dpy);
return grabbed ? 1 : 0;
}
int neoui_ungrab(void) {
@@ -1715,6 +1790,8 @@ int neoui_ungrab(void) {
if (!ctx->w || !ctx->w->dpy) return 0;
XUngrabKeyboard(ctx->w->dpy, CurrentTime);
XSetInputFocus(ctx->w->dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
ctx->grabYielded = true;
XFlush(ctx->w->dpy);
return 1;
}
@@ -2645,6 +2722,38 @@ int neoui_poll_event(int timeout_ms) {
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
if (ctx->tapActive && (now - ctx->lastTapMs >= 850)) {
ctx->tapActive = false;
@@ -2693,6 +2802,11 @@ int neoui_poll_event(int timeout_ms) {
XNextEvent(dpy, &ev);
if (ev.type == Expose) {
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;
return NEO_EV_EXPOSE;
}
@@ -2705,13 +2819,42 @@ int neoui_poll_event(int timeout_ms) {
continue;
}
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);
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;
}
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);
unsigned int kc = ev.xkey.keycode;
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) {
neoui_ungrab();
ctx->overlayGraceUntilMs = tNow + 250;
XFlush(dpy);
bananarchy::sendPluginFifoMsg("dmenu", "OPEN power");
ctx->lastEventType = NEO_EV_CLOSE_REQ;
return NEO_EV_CLOSE_REQ;
continue;
}
}
if (ctx->chordXdrawer &&
@@ -2754,6 +2897,7 @@ int neoui_poll_event(int timeout_ms) {
if (ctx->softkeyPending == otherBit || (kmMask & otherBit)) {
ctx->softkeyPending = 0;
neoui_ungrab();
ctx->overlayGraceUntilMs = tNow + 250;
bananarchy::sendPluginFifoMsg("xdrawer", "TOGGLE");
ctx->lastEventType = NEO_EV_SOFTKEY_CHORD;
return NEO_EV_SOFTKEY_CHORD;
@@ -2789,6 +2933,9 @@ int neoui_poll_event(int timeout_ms) {
// Calculate effective poll timeout
int waitMs = timeout_ms;
if (ctx->visible && ctx->grabYielded && waitMs != 0) {
if (waitMs < 0 || waitMs > 100) waitMs = 100;
}
if (ctx->softkeyPending != 0) {
int rem = static_cast<int>(
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 processNextXEvent();
ovEv = syncOverlayGrabState();
int postEv = processNextXEvent();
if (postEv != NEO_EV_NONE) return postEv;
return ovEv;
}
int neoui_event_key(void) {
+1 -1
View File
@@ -513,7 +513,7 @@ class NeoWindow {
bool overrideRedirect = true,
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | VisibilityChangeMask |
StructureNotifyMask);
FocusChangeMask | StructureNotifyMask);
void destroy();
void bindAsActiveContext();
+19 -3
View File
@@ -1270,6 +1270,15 @@ activate_selection(unsigned int ev_state)
return;
}
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();
menu_mode = MODE_NONE;
trigger_plugin_open(act + 8);
@@ -3278,10 +3287,15 @@ show_menu(void)
if (!engage_ime)
update_t9_status_indicator();
int keep_plugins_open =
(strcmp(current_builtin_menu, "power") == 0 ||
strncmp(current_builtin_menu, "confirm_", 8) == 0);
if (!menu_active) {
menu_active = 1;
mark_menu_active(1);
close_other_active_plugins();
if (!keep_plugins_open)
close_other_active_plugins();
prevfocuswin = None;
Window fw = None;
int rev = 0;
@@ -3322,7 +3336,8 @@ show_menu(void)
XSetICFocus(xic);
XFlush(dpy);
} else {
close_other_active_plugins();
if (!keep_plugins_open)
close_other_active_plugins();
init_soft_mask = 0;
init_soft_ms = 0;
start_ignore = dmenu_now_ms() + 60;
@@ -3357,7 +3372,8 @@ hide_menu(void)
}
XUngrabKeyboard(dpy, CurrentTime);
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;
if (XGetWindowAttributes(dpy, prevfocuswin, &wa) && wa.map_state == IsViewable)
XSetInputFocus(dpy, prevfocuswin, RevertToParent, CurrentTime);