Release a1111 (lennon): isolate nokia-argon slider from 2720 Flip cover stack

- Write /usr/share/bananarchy/lid-profile per target in apply-bananarchy-overlay.sh (slider on nokia-argon, flip on nokia-beatles, none elsewhere), disable flip runlevel services, cover udev/config, and mux module loads on non-flip builds, and exit 0 immediately in flip daemons/init scripts when lid-profile != flip
- Guard startup Escape grab cleanup when locked and gate lid-state checks in display-power-sync, locker.so, and callscreen.so on lid-profile == flip so nokia-argon keeps pure a1108 sliding-lid behaviour
- Ship active-high shared cover backlight (kernel_backlight_invert = 0), active-black internal panel isolation (kernel_internal_sleep = 0), pixel-centered 240x240 cover UI, SW_LID hall sync, and shared Screen blank timeout on nokia-beatles
- Pin verified a1111 (lennon) image hashes for both nokia-argon and nokia-beatles and synchronize docs and host tests
This commit is contained in:
Luxferre committed 2026-11-11 14:20:42 +02:00
1 parent 7a2b965ce3
commit 83c8db10f1
38 files changed
+1351 -276

No files matched your search

File diff suppressed because it is too large. Load diff
+84 -2
View File
@@ -38,11 +38,15 @@
#define COVER_SOCKET "/run/bananarchy/cover.sock"
#define LID_CLIENT_SOCKET "/run/bananarchy/lid-client.sock"
#define LID_BROADCAST_MS 2000
#define EV_SYN 0x00
#define SYN_REPORT 0x00
#define EV_SW 0x05
#define SW_LID 0x00
#define SW_KEYPAD_SLIDE 0x0a
#define CLOSED_MASK ((1u << SW_LID) | (1u << SW_KEYPAD_SLIDE))
#define BA_EVIOCGSW(len) BA_IOC(2U, 'E', 0x1bU, (unsigned int)(len))
#define COVER_MARKER "/run/bananarchy/cover-backlight"
#define MAIN_DPMS_PATH "/sys/class/drm/card0-SPI-1/dpms"
static char *const session_env[] = {
(char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
@@ -176,6 +180,70 @@ static const char *sxmo_state_path(void)
return path && *path ? path : SXMO_STATE_FILE;
}
/* On nokia-beatles, gpio92 (SW_LID) never toggles and gpio36 (SW_KEYPAD_SLIDE)
* asserts 1 when the flip closes, which the shipped dwm binary misreads as a
* slider-open event. Mirroring the authoritative hall state onto SW_LID keeps
* EVIOCGSW(SW_LID) accurate and sets dwm's internal lid_closed flag. */
static void sync_sw_lid(int closed)
{
glob_t gl;
size_t i;
if(getenv("BANANARCHY_LID_GPIO_FILE"))
return;
if(glob("/dev/input/event*", 0, NULL, &gl) != 0)
return;
for(i = 0; i < gl.gl_pathc; i++) {
int fd = open(gl.gl_pathv[i], O_RDWR | O_NONBLOCK | O_CLOEXEC);
struct input_event ev[2];
if(fd < 0)
continue;
if(!device_has_code(fd, EV_SW, SW_LID)) {
close(fd);
continue;
}
memset(ev, 0, sizeof(ev));
ev[0].type = EV_SW;
ev[0].code = SW_LID;
ev[0].value = closed ? 1 : 0;
ev[1].type = EV_SYN;
ev[1].code = SYN_REPORT;
ev[1].value = 0;
(void)!write(fd, ev, sizeof(ev));
close(fd);
}
globfree(&gl);
}
/* Self-heal if a concurrent X11 client or close-time race left the main panel
* DPMS-on while the flip is closed and the cover does not own the backlight. */
static void enforce_closed_dark(void)
{
int fd;
char dpms[16];
ssize_t got = 0;
int dpms_on = 0;
if(getenv("BANANARCHY_LID_GPIO_FILE"))
return;
if(access(COVER_MARKER, F_OK) == 0)
return;
fd = open(MAIN_DPMS_PATH, O_RDONLY | O_CLOEXEC);
if(fd >= 0) {
got = read(fd, dpms, sizeof(dpms) - 1);
close(fd);
if(got > 0) {
dpms[got] = '\0';
dpms_on = strncmp(dpms, "Off", 3) != 0;
}
}
if(!dpms_on &&
read_int_file(BRIGHTNESS, 0) == 0 &&
read_int_file(BL_POWER, 4) == 4)
return;
write_text_file(BRIGHTNESS, "0");
write_text_file(BL_POWER, "4");
run_dpms("off");
}
/* Everything user-visible happens synchronously here: no shell, no fork and
* no scheduler wait before the main panel is dark and the screen is locked.
* The Sxmo state hooks are spawned afterwards and only repeat these writes. */
@@ -188,6 +256,7 @@ static void on_transition(int closed)
write_session_file(LID_GENERATION_FILE, generation);
/* Publish first: every main-panel wake path is gated on this file. */
write_lid_state(closed);
sync_sw_lid(closed);
if(closed) {
int saved_bl = read_int_file(BRIGHTNESS, -1);
int saved_kbd = read_int_file(KBD_BACKLIGHT, -1);
@@ -359,7 +428,7 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds,
int main(void)
{
int lock_fd = lock_singleton(LID_LOCK);
int lock_fd;
struct watch_list list;
long long now;
long long last_scan = 0;
@@ -376,6 +445,9 @@ int main(void)
int hall_observed;
int edge;
int observed;
if(is_non_flip_profile())
return 0;
lock_fd = lock_singleton(LID_LOCK);
if(lock_fd < 0)
return 1;
install_reaper();
@@ -393,7 +465,12 @@ int main(void)
now = now_ms();
candidate_since = now;
write_lid_state(stable_closed);
cover_send(stable_closed ? "CLOSED" : "OPEN");
if(stable_closed)
on_transition(1);
else {
sync_sw_lid(0);
cover_send("OPEN");
}
last_broadcast = now;
while(1) {
struct pollfd fds[WATCH_MAX];
@@ -429,6 +506,8 @@ int main(void)
((switch_mask & (int)CLOSED_MASK) != 0);
last_hall_poll = now;
fast_until = now + 120;
if(hall == 1 && !(switch_mask & (int)switch_bit(SW_LID)))
sync_sw_lid(1);
} else if(now - last_hall_poll >=
(now < fast_until ? HALL_EDGE_MS : HALL_POLL_MS)) {
hall = hall_state();
@@ -451,6 +530,9 @@ int main(void)
}
if(now - last_broadcast >= LID_BROADCAST_MS) {
write_lid_state(stable_closed);
sync_sw_lid(stable_closed);
if(stable_closed)
enforce_closed_dark();
cover_send(stable_closed ? "CLOSED" : "OPEN");
last_broadcast = now;
}
@@ -26,6 +26,9 @@
#ifndef KEY_POWER
#define KEY_POWER 116
#endif
#ifndef KEY_CAMERA
#define KEY_CAMERA 212
#endif
static char *const session_env[] = {
(char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
@@ -37,10 +40,28 @@ static char *const session_env[] = {
NULL
};
static const char *lid_state_path(void)
{
const char *override = getenv("BANANARCHY_LID_STATE");
return (override && *override) ? override : LID_STATE_FILE;
}
static const char *cover_socket_path(void)
{
const char *override = getenv("BANANARCHY_COVER_SOCKET");
return (override && *override) ? override : COVER_SOCKET;
}
static const char *client_socket_path(void)
{
const char *override = getenv("BANANARCHY_VOLUME_CLIENT_SOCKET");
return (override && *override) ? override : LID_CLIENT_SOCKET;
}
static int lid_is_closed(void)
{
char buf[32] = "";
FILE *handle = fopen(LID_STATE_FILE, "r");
FILE *handle = fopen(lid_state_path(), "r");
if(!handle)
return 0;
if(!fgets(buf, sizeof(buf), handle))
@@ -54,26 +75,29 @@ static int lid_is_closed(void)
* server; a failed send just means it is not running on this target. */
static void cover_button(void)
{
const char *client_path = client_socket_path();
const char *remote_path = cover_socket_path();
int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
struct sockaddr_un local;
struct sockaddr_un remote;
if(fd < 0)
return;
mkdir("/run/bananarchy", 0755);
unlink(LID_CLIENT_SOCKET);
if(strcmp(client_path, LID_CLIENT_SOCKET) == 0)
mkdir("/run/bananarchy", 0755);
unlink(client_path);
memset(&local, 0, sizeof(local));
local.sun_family = AF_UNIX;
snprintf(local.sun_path, sizeof(local.sun_path), "%s", LID_CLIENT_SOCKET);
snprintf(local.sun_path, sizeof(local.sun_path), "%s", client_path);
if(bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
close(fd);
return;
}
memset(&remote, 0, sizeof(remote));
remote.sun_family = AF_UNIX;
snprintf(remote.sun_path, sizeof(remote.sun_path), "%s", COVER_SOCKET);
snprintf(remote.sun_path, sizeof(remote.sun_path), "%s", remote_path);
sendto(fd, "BUTTON\n", 7, 0, (struct sockaddr *)&remote, sizeof(remote));
close(fd);
unlink(LID_CLIENT_SOCKET);
unlink(client_path);
}
static void apply_volume(const char *action)
@@ -107,7 +131,7 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds)
if(ev.type != EV_KEY || ev.value != 1)
continue;
if(ev.code != KEY_VOLUMEUP && ev.code != KEY_VOLUMEDOWN &&
ev.code != KEY_POWER)
ev.code != KEY_POWER && ev.code != KEY_CAMERA)
continue;
if(lid_is_closed()) {
cover_button();
@@ -130,9 +154,14 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds)
int main(void)
{
int lock_fd = lock_singleton(VOLUME_LOCK);
const char *lock_override = getenv("BANANARCHY_VOLUME_LOCK");
int lock_fd;
struct watch_list list;
long long last_scan = 0;
if(is_non_flip_profile())
return 0;
lock_fd = lock_singleton(
(lock_override && *lock_override) ? lock_override : VOLUME_LOCK);
if(lock_fd < 0)
return 1;
install_reaper();
+39 -5
View File
@@ -37,19 +37,29 @@
#ifndef KEY_POWER
#define KEY_POWER 116
#endif
#ifndef KEY_CAMERA
#define KEY_CAMERA 212
#endif
#define BA_IOC(dir, type, nr, size) \
(((unsigned int)(dir) << 30) | ((unsigned int)(type) << 8) | \
((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16))
#define BA_EVIOCGBIT(ev, len) \
BA_IOC(2U, 'E', 0x20U + (unsigned int)(ev), (unsigned int)(len))
/* Match the kernel evdev record layout (__kernel_ulong_t sec/usec), not musl
* time64 struct timeval: on 32-bit armv7 musl, struct timeval is 16 bytes
* while the kernel writes 8-byte sec/usec (16-byte input_event total). */
struct input_event {
struct timeval time;
unsigned long tv_sec;
unsigned long tv_usec;
uint16_t type;
uint16_t code;
int32_t value;
};
typedef char ba_input_event_abi[
(sizeof(struct input_event) == 2 * sizeof(unsigned long) + 8) ? 1 : -1];
enum watch_filter {
WATCH_ALL = 0,
WATCH_SWITCHES,
@@ -170,17 +180,22 @@ static BA_UNUSED int device_has_code(int fd, unsigned int ev, unsigned int code)
static BA_UNUSED int wanted_device(int fd, enum watch_filter filter)
{
const char *glob_override = getenv("BANANARCHY_INPUT_GLOB");
if(glob_override && *glob_override)
return 1;
if(filter == WATCH_ALL)
return 1;
if(filter == WATCH_SWITCHES) {
return device_has_code(fd, EV_SW, SW_LID) ||
device_has_code(fd, EV_SW, SW_KEYPAD_SLIDE);
}
/* The End/Power key lives on a KEY_POWER-only device (pm8941_pwrkey),
* so it must be watched too or the third outer button is invisible. */
/* The End/Power key lives on a KEY_POWER-only device (pm8941_pwrkey) and
* the left-side button on 2720 Flip emits KEY_CAMERA on the matrix keypad,
* so watch both alongside the volume keys. */
return device_has_code(fd, EV_KEY, KEY_VOLUMEUP) ||
device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN) ||
device_has_code(fd, EV_KEY, KEY_POWER);
device_has_code(fd, EV_KEY, KEY_POWER) ||
device_has_code(fd, EV_KEY, KEY_CAMERA);
}
static BA_UNUSED void prune_devices(struct watch_list *list)
@@ -196,10 +211,13 @@ static BA_UNUSED void prune_devices(struct watch_list *list)
static BA_UNUSED void scan_devices(struct watch_list *list, enum watch_filter filter)
{
const char *pattern = getenv("BANANARCHY_INPUT_GLOB");
glob_t gl;
size_t i;
prune_devices(list);
if(glob("/dev/input/event*", 0, NULL, &gl) != 0)
if(!pattern || !*pattern)
pattern = "/dev/input/event*";
if(glob(pattern, 0, NULL, &gl) != 0)
return;
for(i = 0; i < gl.gl_pathc && list->count < WATCH_MAX; i++) {
const char *path = gl.gl_pathv[i];
@@ -234,6 +252,22 @@ static BA_UNUSED void scan_devices(struct watch_list *list, enum watch_filter fi
globfree(&gl);
}
static BA_UNUSED int is_non_flip_profile(void)
{
const char *override = getenv("BANANARCHY_LID_PROFILE");
const char *path = (override && *override) ? override :
"/usr/share/bananarchy/lid-profile";
FILE *handle = fopen(path, "r");
char buf[32] = "";
if(!handle)
return 0;
if(!fgets(buf, sizeof(buf), handle))
buf[0] = '\0';
fclose(handle);
buf[strcspn(buf, " \t\r\n")] = '\0';
return buf[0] != '\0' && strcmp(buf, "flip") != 0;
}
static BA_UNUSED long long now_ms(void)
{
struct timespec ts;
+19
View File
@@ -301,6 +301,25 @@ void finalizeWavHeader(const std::string& path) {
}
void wakeDisplayHardware(Display* dpy) {
int profFd = ::open("/usr/share/bananarchy/lid-profile", O_RDONLY | O_CLOEXEC);
bool isFlip = false;
if (profFd >= 0) {
char profBuf[16] {};
ssize_t pn = ::read(profFd, profBuf, sizeof(profBuf) - 1);
::close(profFd);
isFlip = (pn >= 4 && std::strncmp(profBuf, "flip", 4) == 0 &&
(profBuf[4] == '\0' || profBuf[4] == '\n' || profBuf[4] == '\r'));
}
int lidFd = isFlip ? ::open("/run/bananarchy/lid-state", O_RDONLY | O_CLOEXEC) : -1;
if (lidFd >= 0) {
char lidBuf[32] {};
ssize_t n = ::read(lidFd, lidBuf, sizeof(lidBuf) - 1);
::close(lidFd);
if (n >= 6 && std::strncmp(lidBuf, "closed", 6) == 0) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
return;
}
}
int saved = readIntFile("/tmp/sxmo_saved_brightness", -1);
if (saved <= 1) {
saved = readIntFile("/sys/class/backlight/backlight/max_brightness", 14);
+30 -4
View File
@@ -84,12 +84,26 @@ void writeSysfsStr(const char* path, const char* val) {
}
}
bool isLidClosed() {
return readSmallFileTrimmed("/usr/share/bananarchy/lid-profile") == "flip" &&
readSmallFileTrimmed("/run/bananarchy/lid-state") == "closed";
}
bool isScreenBlanked() {
if (isLidClosed()) {
return true;
}
std::string br = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness");
return (!br.empty() && std::atoi(br.c_str()) <= 0);
}
void blankScreenBacklight() {
if (isLidClosed() &&
readSmallFileTrimmed("/run/bananarchy/cover-backlight") == "1") {
writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", "0");
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "powersave");
return;
}
std::string cur = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness");
if (!cur.empty() && std::atoi(cur.c_str()) >= 1) {
std::string line = std::to_string(std::atoi(cur.c_str())) + "\n";
@@ -102,6 +116,10 @@ void blankScreenBacklight() {
}
void wakeScreenBacklight() {
if (isLidClosed()) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
return;
}
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "schedutil");
std::string cur = readSmallFileTrimmed("/tmp/sxmo_saved_brightness");
int val = std::atoi(cur.c_str());
@@ -575,7 +593,9 @@ int locker_run_main(int argc, char** argv) {
if (!visible || isCallScreenVisible()) {
return;
}
XRaiseWindow(dpy, win);
if (!isLidClosed()) {
XRaiseWindow(dpy, win);
}
XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
XFlush(dpy);
grabHeld = false;
@@ -814,10 +834,11 @@ int locker_run_main(int argc, char** argv) {
if (!visible) {
XMapRaised(dpy, win);
XMoveResizeWindow(dpy, win, 0, 0, kScreenWidth, kScreenHeight);
XSync(dpy, False);
visible = true;
}
grabLockerInput();
if (blankDisplay) {
if (blankDisplay || isLidClosed()) {
setSxmoStateFile("screenoff");
blankScreenBacklight();
wasScreenBlanked = true;
@@ -873,7 +894,7 @@ int locker_run_main(int argc, char** argv) {
};
auto handleKeyInput = [&](unsigned int kc, unsigned int state, KeySym sym) {
if (!visible) {
if (!visible || isLidClosed()) {
return;
}
int64_t now = nowMs();
@@ -1035,6 +1056,10 @@ int locker_run_main(int argc, char** argv) {
continue;
}
if (cmd == "WAKE") {
if (isLidClosed()) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
continue;
}
if (::access(kLockFlagPath, F_OK) == 0 || visible) {
if (!visible) {
lockPhone(false);
@@ -1119,7 +1144,8 @@ int locker_run_main(int argc, char** argv) {
} else if (!callNow && callWasActive) {
grabLockerInput();
render();
} else if (!callNow && !grabHeld && !isScreenBlanked()) {
} else if (!callNow && !grabHeld &&
(!isScreenBlanked() || isLidClosed())) {
grabLockerInput();
}
callWasActive = callNow;