Implement passcode-based fullscreen phone locker (locker.so / xlocker)

This commit is contained in:
Luxferre committed 2026-10-29 21:31:00 +02:00
1 parent 32d5d2f2b4
commit 0656042f7f
56 files changed
+1264 -120

No files matched your search

+62 -10
View File
@@ -1301,6 +1301,21 @@ set_sxmo_state_str(const char *st)
}
}
static int
is_screen_off(void)
{
char buf[32];
read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf));
return (buf[0] != '\0' && atoi(buf) <= 0) ? 1 : 0;
}
static int
is_passcode_locked(void)
{
return access("/tmp/bananarchy_screen_locked", F_OK) == 0 ? 1 : 0;
}
static int
is_phone_locked(void)
{
@@ -1309,8 +1324,7 @@ is_phone_locked(void)
int fd;
ssize_t n;
read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf));
if (buf[0] != '\0' && atoi(buf) <= 0)
if (is_screen_off() || is_passcode_locked())
return 1;
snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000");
@@ -1728,7 +1742,7 @@ is_right_softkey(KeySym ks, unsigned int keycode)
#include <dlfcn.h>
#include "dwm_plugin.h"
#define MAX_DWM_PLUGINS 24
#define MAX_DWM_PLUGINS 48
typedef struct {
void *handle;
@@ -1796,7 +1810,13 @@ host_spawn_plugin(const char *plugin_name, const char *arg)
if (arg && strcmp(arg, "--preload") == 0) {
if (is_plugin_daemon_alive(plugin_name))
return;
int stagger_ms = (strcmp(plugin_name, "dmenu") == 0) ? 150 : (600 + (preload_stagger_idx++ * 220));
int stagger_ms = 600;
if (strcmp(plugin_name, "locker") == 0)
stagger_ms = 80;
else if (strcmp(plugin_name, "dmenu") == 0)
stagger_ms = 150;
else
stagger_ms = 600 + (preload_stagger_idx++ * 220);
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@@ -1807,15 +1827,24 @@ host_spawn_plugin(const char *plugin_name, const char *arg)
}
return;
}
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
if (strcmp(plugin_name, "locker") != 0) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
}
if (is_plugin_daemon_alive(plugin_name)) {
char fifopath[128], msg[128];
snprintf(fifopath, sizeof(fifopath), "/tmp/dwm_plugin_%s.fifo", plugin_name);
int fd = open(fifopath, O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (fd >= 0) {
int len;
if (strcmp(plugin_name, "xdrawer") == 0)
if (strcmp(plugin_name, "locker") == 0) {
if (arg && (strcmp(arg, "screenoff") == 0 || strcmp(arg, "blank") == 0))
len = snprintf(msg, sizeof(msg), "LOCK_BLANK\n");
else if (arg && strcmp(arg, "wake") == 0)
len = snprintf(msg, sizeof(msg), "WAKE\n");
else
len = snprintf(msg, sizeof(msg), "LOCK\n");
} else if (strcmp(plugin_name, "xdrawer") == 0)
len = snprintf(msg, sizeof(msg), "TOGGLE\n");
else if (strcmp(plugin_name, "dmenu") == 0 && arg && strcmp(arg, "close") == 0)
len = snprintf(msg, sizeof(msg), "CLOSE\n");
@@ -2086,6 +2115,7 @@ static void
lock_phone_screenoff(void)
{
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff");
int lfd;
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
@@ -2096,8 +2126,14 @@ lock_phone_screenoff(void)
star_down = 0;
pound_down = 0;
write_softkey_state(0, 0);
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);
}
if (is_plugin_loaded("dmenu"))
host_spawn_plugin("dmenu", "close");
host_spawn_plugin("locker", "screenoff");
set_sxmo_state_str("screenoff");
set_hw_backlight(0);
spawn(&offcmd);
@@ -2121,10 +2157,15 @@ wake_phone(void)
pound_down = 0;
write_softkey_state(0, 0);
write_softkey_suppress(now + SOFTKEY_SUPPRESS_MS);
set_hw_backlight(1);
if (is_passcode_locked()) {
set_sxmo_state_str("lock");
host_spawn_plugin("locker", "wake");
return;
}
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
set_sxmo_state_str("unlock");
set_hw_backlight(1);
spawn(&oncmd);
}
@@ -2138,6 +2179,14 @@ keypress(XEvent *e)
ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
if (is_screen_off()) {
wake_phone();
return;
}
if (is_passcode_locked()) {
host_spawn_plugin("locker", "wake");
return;
}
if (is_phone_locked()) {
wake_phone();
return;
@@ -2767,9 +2816,12 @@ run(void)
pound_down = (ie.value != 0);
if (ie.value == 1) {
if (is_phone_locked()) {
if (is_screen_off()) {
wake_phone();
} else if ((ie.code == 522 || ie.code == 55 ||
} else if (!is_passcode_locked() && is_phone_locked()) {
wake_phone();
} else if (!is_passcode_locked() &&
(ie.code == 522 || ie.code == 55 ||
ie.code == 523 || ie.code == 98) &&
star_down && pound_down) {
trigger_screenshot_chord(dwm_now_ms());