Persist screen brightness, enable universal evdev key/lid wake, and add *+# screenshot combo

This commit is contained in:
Luxferre committed 2026-10-27 22:24:39 +02:00
1 parent eef8584a8d
commit 2e2adcc7f2
38 files changed
+574 -161

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) optimized for `< 2 ms` UI wakeup latency and `< 95 MB` idle RAM on 512 MB devices.
## 2. Repository layout
- `src/sxmo-dwm/`: patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `SW_LID` slider and locked-key wake handling, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`).
- `src/sxmo-dwm/`: patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `evdev` `SW_LID` slider and universal key wake handling, `*` + `#` screenshot chord via `bananarchy-screenshot`, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`).
- `src/sxmo-dmenu/`: zero-lag resident DWM menu plugin (`dmenu.so`) and `/tmp/dwm_plugin_dmenu.sock` client (`dmenu` / `xdmenu`), featuring built-in Sxmo menus (`sys`, `applications`, `scripts`, `modem`, `config`, `power`, `audio`, `notifications`, `wm`, `timezone`, `games`, `st`, `nano`, `sthotkeys`) and `fcitx5-t9` XIM input.
- `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input (paired with Yabasic FFI libraries `neoui.yab` and `neonet.yab` + demos `neoui_demo.yab` and `neonet_demo.yab` in `overlay/rootfs/home/user/Projects/`).
- `src/dwm-plugins/`: preloaded C++20 `240x320` DWM plugins linked against `libneoui.so` and shared headers:
+4
View File
@@ -39,6 +39,10 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
- **Camera sensor support and orientation fix (`msm8905-cam`, `xcamera`, and `bananarchy-photo`)**:
- Extended `msm8905-cam` (`/dev/video0`) to support the GalaxyCore `GC2385` (`0x2385`, used on Nokia 8110 4G `TA-1059`) and `GC2365` (`0x2365`) 2MP MIPI CSI-2 camera sensors alongside `GC2395` (`0x2395`, used on `TA-1048`).
- Rotated the raw `800x600` `GC2395`/`GC2385`/`GC2365` sensor frames 90 degrees clockwise in both the live `240x180` 4:3 viewfinder (`downscaleViewfinder800x600To240x180`) and captured JPEG photos (`600x800` portrait output in `xcamera` and `bananarchy-photo`).
- **Screen brightness persistence, universal evdev wake, and `*` + `#` screenshot combo**:
- Persisted screen and keypad backlight brightness across slider open/close, lock/unlock, and X11 session restarts (`~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` across `dwm`, `xdrawer`, `dmenu`, `sxmo_wm.sh`, `sxmo_brightness.sh`, and `bananarchy-x11-session.sh`).
- Added direct kernel `evdev` key and lid polling (`event0`–`event3`) in `dwm` and disabled deep system suspend (`sxmo_autosuspend`, `sxmo_suspend.sh`, and `elogind` `AllowSuspend=no`) so the phone never enters an unwakeable state and wakes immediately on any keypad key, the power key, or opening the slider even when a plugin holds `XGrabKeyboard`.
- Added a global **`*` + `#`** simultaneous key combo (`KEY_NUMERIC_STAR` + `KEY_NUMERIC_POUND` in `dwm` via `/usr/bin/bananarchy-screenshot` and `scrot`) to capture `240x320` PNG screenshots into `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png` from anywhere with haptic and toast feedback.
- **Window management, context menu, and `fcitx5` XIM stability fixes**:
- Added direct C-level `_BANANARCHY_DWM_CMD` IPC between `dmenu` and `dwm` for instant window management (`Kill window`, `Close Terminal`, `Move to WS 1..4`, `Go to WS 1..4`, `Shift stack`, `Swap stack`, `Toggle Layout`) and restored application context menus (`Right softkey` inside `st`, `nano`, and X11 apps).
- Updated the `fcitx5` `superd` service wrapper (`bananarchy-fcitx5.sh`) and XIM environment propagation across `st`, `dmenu`, and `dwm-plugin` so T9 keypad input stays supervised and active across all terminal and menu sessions.
+13 -3
View File
@@ -91,6 +91,7 @@ sudo dd if=./images/bananarchy-nokia-argon.img of=/dev/sdX bs=4M status=progress
| **Left softkey (`Menu`)** | `XF86KbdLcdMenu1` (`KEY_MENU`) | Open **System menu**, close open menu, or wake and unlock when locked |
| **Right softkey (`Names` / `Back`)** | `XF86KbdLcdMenu2` / `BackSpace` (`KEY_BACK`) | On empty desktop: open **Contacts (`Names`)**; inside apps: open **App context menu** (or close menu if open); in T9 preedit: `BackSpace` |
| **Both softkeys together** | `KEY_MENU` + `KEY_BACK` | Toggle **XDrawer** (`xdrawer`) global phone controls overlay from anywhere |
| **`*` + `#` together** | `KEY_NUMERIC_STAR` + `KEY_NUMERIC_POUND` | Capture a `240x320` screenshot (`scrot` via `bananarchy-screenshot`) to `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png` |
| **Digits `0`–`9`, `*`, `#` (on idle desktop)** | `0`–`9`, `asterisk`, `numbersign` | Open **Dialer** (`xdialer`) and immediately insert the pressed digit, `*`, or `#` |
| **Call (green)** | `XF86PickupPhone` / `XF86Phone` (`KEY_SEND`) | Answer incoming call when ringing; on empty desktop: open **Call Log** (`xcalllog`); when locked: wake and unlock; in menus: confirm (`Return`); in apps: **2x** focus next window, **3x** cycle tiling layout |
| **End / Power (red)** | `XF86PowerOff` | Wake and unlock when locked, close open plugin/menu, or: **1x** open **Power menu**, **2x** cycle screen state, **3x** (or hold `400ms`) launch a new terminal |
@@ -99,8 +100,8 @@ sudo dd if=./images/bananarchy-nokia-argon.img of=/dev/sdX bs=4M status=progress
| **Center OK** | `Return` (`KEY_OK`) | Confirm / Enter, or commit active T9 preedit candidate immediately |
| **Slider close / open** | `SW_LID` (`lid:on` / `lid:off`) | **Close**: close open menu, turn off keypad backlight, and lock/turn screen off; **Open**: restore keypad backlight, unlock, and turn screen on |
> **Screen blanking, locking, and waking**:
> X11 screensaver/DPMS blanking is disabled so screen state is controlled cleanly by Sxmo. Automatic idle locking is disabled so the phone only locks when you explicitly ask it to (`Power -> Lock`, `XDrawer -> Lock`, `2x End / Power`, or closing the physical slider). To save battery, the display blanks after inactivity (`SXMO_UNLOCK_IDLE_TIME`, default 30s; `SXMO_LOCK_IDLE_TIME`, default 8s once locked) without locking. When the screen is off, wake and unlock in a single action by opening the slider or pressing **End / Power**, **Left softkey**, **Right softkey**, or **Call (green)**.
> **Screen blanking, locking, waking, and brightness persistence**:
> X11 screensaver/DPMS blanking and deep system suspend are disabled so screen state is controlled cleanly and the phone always wakes immediately. The phone only locks or blanks the screen when you explicitly ask it to (`Power -> Lock`, `Power -> Lock (Screen off)`, `2x End / Power`, or closing the physical slider). Screen and keypad brightness levels configured in **XDrawer** or **Config -> Brightness** are persisted in `~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` and restored on every wake or unlock. When the screen is off or locked, wake and unlock in a single action by opening the slider or pressing **any key on the keypad** or **End / Power**.
#### 3.1.1 Window tiling modes and switching combos
By default, `dwm` uses the **vertical bottom-stack (`bstack`, `TTT`)** layout so multiple `st` terminals stack **vertically (one under another)** to preserve full line width on the `240x320` portrait screen.
@@ -328,7 +329,16 @@ Two classic X11 games (`/usr/bin/snake` and `/usr/bin/tetris`) and the full-feat
## 5. Command-line hardware reference
### 5.1 Taking photos from the CLI (`bananarchy-photo` and `/dev/video0`)
### 5.1 Taking photos and screenshots (`bananarchy-photo`, `bananarchy-screenshot`, and `/dev/video0`)
Pressing **`*` and `#` simultaneously** from anywhere (desktop, menus, plugins, terminal, or games) captures a `240x320` screenshot using `scrot` (`/usr/bin/bananarchy-screenshot`), saves it to `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png`, and triggers a brief haptic pulse and notification toast. You can also take screenshots from the CLI or via **System menu -> Scripts -> Screenshot**:
```bash
# Capture a 240x320 PNG screenshot to ~/Pictures/screenshot-YYYYMMDD-HHMMSS.png
bananarchy-screenshot
# Capture to a custom PNG path
bananarchy-screenshot ~/my-screen.png
```
The `msm8905-cam` kernel module drives the rear 2MP GalaxyCore `GC2395` (TA-1048), `GC2385` (TA-1059), and `GC2365` sensors through MSM8909 `CAMSS` and registers `/dev/video0` (`800x600` 24-bit `RGB3`).
+1 -1
View File
@@ -23,7 +23,7 @@
### Keypad-first user experience and native DWM plugins
Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs a suite of preloaded C/C++ plugins inside DWM that sleep at 0% CPU and open in `< 2 ms`:
- **System and context menus (`dmenu`)**: instant full-screen 10-line vertical menus with live T9 filtering, built-in submenus, and hardware toggles.
- **Global controls drawer (`xdrawer`)**: press **both softkeys together** from anywhere to adjust speaker, earpiece, and ringtone volume, ringer mode (`Ring+Vib` / `Vibrate` / `Silent` / `DND`), 3-level vibration intensity (`Light` / `Medium` / `Strong`), flashlight, sound and microphone mute, screen brightness, and keypad backlight.
- **Global controls drawer (`xdrawer`) and `*` + `#` screenshot combo**: press **both softkeys together** from anywhere to adjust speaker, earpiece, and ringtone volume, ringer mode (`Ring+Vib` / `Vibrate` / `Silent` / `DND`), 3-level vibration intensity (`Light` / `Medium` / `Strong`), flashlight, sound and microphone mute, screen brightness, and keypad backlight; press **`*` and `#` together** from anywhere to capture a `240x320` PNG screenshot (`scrot` via `bananarchy-screenshot`) to `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png`.
- **Phone dialer (`xdialer`), call log (`xcalllog`), and call screen (`xcallscreen`)**: press any digit on the home screen to start dialing with live T9 contact matching, run interactive carrier USSD codes (`*100#`, etc.), or type `*#06#` to inspect both IMEIs. When two SIM cards are active in Dual-SIM Dual Standby (DSDS), placing a call or running a USSD code prompts to choose between `SIM 1` and `SIM 2`. Incoming and active calls on either SIM open a dedicated call screen with an active `[SIM 1]`/`[SIM 2]` badge, earpiece/speaker switching, microphone mute, DTMF keypad, and one-key normalized WAV call recording (`~/Recordings/rec_HHMMSS_<caller>.wav`). The call log includes a 5-tab view (`All`, `Miss`, `In`, `Out`, `Spam`) with integrated anti-spam number blocking (`~/.config/sxmo/block.tsv`) that automatically hangs up blocked callers and logs them to the `Spam` tab without triggering missed-call notifications.
- **Contacts (`xcontacts`) and SMS manager (`xsms`)**: full phonebook editor with direct Qualcomm QMI SIM card contact import and export across SIM 1 and SIM 2, paired with a threaded SMS conversation view, multi-tap message composer with outgoing `SIM 1` / `SIM 2` selection when two SIMs are active, and built-in anti-spam blocklist / spam folder (`~/.local/share/sxmo/block`) with one-key thread blocking and restoration.
- **Modem and Dual-SIM manager (`xmodem`)**: 4-tab cellular control center (`SIMs`, `Radio`, `AT`, `Log`) supporting Dual-SIM Dual Standby (DSDS) with simultaneous network registration on both SIM slots, instant default SIM switching (`Set as Default SIM (Calls/SMS)`), full Primary/Secondary GW (`4G/Data`) slot swapping (`Make Primary GW (4G/Data Swap)`), SIM PIN unlock and PUK unblock wizards, 2G/3G/4G radio mode selection, interactive USSD sessions, and a live AT command console.
+1 -3
View File
@@ -5,6 +5,4 @@ HandleHibernateKey=ignore
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
[Sleep]
AllowSuspendInterrupts=yes
IdleAction=ignore
+6
View File
@@ -0,0 +1,6 @@
[Sleep]
AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no
AllowSuspendInterrupts=yes
@@ -19,7 +19,8 @@ stop_proximity_lock() {
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then
read -r CURRENT_STATE < "$STATE_FILE" || CURRENT_STATE=""
CURRENT_STATE=""
read -r CURRENT_STATE < "$STATE_FILE" 2>/dev/null || true
else
CURRENT_STATE="$(sxmo_state.sh get)"
fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else
sxmo_wm.sh display on
fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '255' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
else
brightnessctl -d white:kbd_backlight set 255 >/dev/null 2>&1 || true
fi
sxmo_state.sh set unlock &
exit 0
;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0
;;
"powerbutton_two")
sxmo_state.sh click 2
sxmo_state.sh set screenoff
exit 0
;;
"powerbutton_three")
@@ -1 +1 @@
SUBSYSTEM=="power_supply", ACTION=="change", RUN+="/bin/sh -c 'su - user -c \"DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/share/sxmo/default_hooks/sxmo_hook_battery.sh udev\" >/dev/null 2>&1 &'"
SUBSYSTEM=="power_supply", ACTION=="change", RUN+="/bin/sh -c 'DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/share/sxmo/default_hooks/sxmo_hook_battery.sh udev >/dev/null 2>&1 &'"
@@ -19,7 +19,8 @@ stop_proximity_lock() {
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then
read -r CURRENT_STATE < "$STATE_FILE" || CURRENT_STATE=""
CURRENT_STATE=""
read -r CURRENT_STATE < "$STATE_FILE" 2>/dev/null || true
else
CURRENT_STATE="$(sxmo_state.sh get)"
fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else
sxmo_wm.sh display on
fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '255' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
else
brightnessctl -d white:kbd_backlight set 255 >/dev/null 2>&1 || true
fi
sxmo_state.sh set unlock &
exit 0
;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0
;;
"powerbutton_two")
sxmo_state.sh click 2
sxmo_state.sh set screenoff
exit 0
;;
"powerbutton_three")
@@ -84,10 +84,11 @@ if [ "$(command -v fcitx5)" ]; then
fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary
# Turn on auto-suspend
# Keep system awake so keypad, lid, and power keys always wake the screen immediately
mkdir -p "$XDG_CACHE_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite
superctl start sxmo_autosuspend
fi
# To setup initial unlock state
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
# Capture a 240x320 X11 screenshot using scrot and notify the user.
export DISPLAY="${DISPLAY:-:0}"
export HOME="${HOME:-/home/user}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
PIC_DIR="${XDG_PICTURES_DIR:-$HOME/Pictures}"
mkdir -p "$PIC_DIR" 2>/dev/null || true
TS="$(date +%Y%m%d-%H%M%S)"
OUT_FILE="${1:-$PIC_DIR/screenshot-$TS.png}"
if [ -e "$OUT_FILE" ]; then
i=1
while [ -e "${OUT_FILE%.png}-$i.png" ]; do
i=$((i + 1))
done
OUT_FILE="${OUT_FILE%.png}-$i.png"
fi
if scrot "$OUT_FILE" >/dev/null 2>&1; then
printf '%s\n' "$OUT_FILE"
if command -v sxmo_vibrate >/dev/null 2>&1; then
sxmo_vibrate 60 >/dev/null 2>&1 &
fi
if command -v sxmo_notify_user.sh >/dev/null 2>&1; then
sxmo_notify_user.sh -t 1500 "Saved $(basename "$OUT_FILE")" >/dev/null 2>&1 &
fi
exit 0
fi
exit 1
@@ -52,14 +52,32 @@ fi
unset WAYLAND_DISPLAY
unset SWAYSOCK
mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.noidle"
mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/sxmo" "$XDG_CONFIG_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.noidle" "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ] && printf "%s\n" "$DBUS_SESSION_BUS_ADDRESS" > "$XDG_RUNTIME_DIR/dbus.bus"
printf "unlock\n" > "$XDG_RUNTIME_DIR/sxmo.state"
printf "14" > /tmp/sxmo_saved_brightness
printf "14" > /sys/class/backlight/backlight/brightness 2>/dev/null || true
printf "255" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
_init_bl=""
if [ -r "$XDG_CONFIG_HOME/sxmo/brightness" ]; then
read -r _init_bl < "$XDG_CONFIG_HOME/sxmo/brightness" 2>/dev/null || true
elif [ -r /tmp/sxmo_saved_brightness ]; then
read -r _init_bl < /tmp/sxmo_saved_brightness 2>/dev/null || true
fi
if [ -z "$_init_bl" ] || [ "${_init_bl:-0}" -lt 1 ] 2>/dev/null; then
_init_bl="14"
fi
printf "%s\n" "$_init_bl" > /tmp/sxmo_saved_brightness
printf "%s\n" "$_init_bl" > "$XDG_CONFIG_HOME/sxmo/brightness" 2>/dev/null || true
printf "%s\n" "$_init_bl" > /sys/class/backlight/backlight/brightness 2>/dev/null || true
_init_kbd="255"
if [ -r "$XDG_CONFIG_HOME/sxmo/kbd_brightness" ]; then
read -r _init_kbd < "$XDG_CONFIG_HOME/sxmo/kbd_brightness" 2>/dev/null || true
elif [ -r /tmp/sxmo_saved_kbd_brightness ]; then
read -r _init_kbd < /tmp/sxmo_saved_kbd_brightness 2>/dev/null || true
fi
printf "%s\n" "${_init_kbd:-255}" > /tmp/sxmo_saved_kbd_brightness
printf "%s\n" "${_init_kbd:-255}" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
XORG_BIN="Xorg"
[ -x /tmp/x11/usr/bin/Xorg ] && XORG_BIN="/tmp/x11/usr/bin/Xorg"
@@ -74,14 +92,14 @@ if ! pidof -s Xorg >/dev/null 2>&1; then
"$XORG_BIN" :0 -s 0 -dpms -nocursor -nolisten tcp -config "$XORG_CONFIG" -modulepath "$XORG_MODPATH" -logfile /tmp/Xorg.0.log >/dev/null 2>&1 </dev/null &
i=0
while [ "$i" -lt 40 ]; do
if xset s off s noblank s 0 0 -dpms >/dev/null 2>&1; then
if xset s off s noblank s 0 0 >/dev/null 2>&1; then
break
fi
sleep 0.05
i=$((i + 1))
done
else
xset s off s noblank s 0 0 -dpms >/dev/null 2>&1 || true
xset s off s noblank s 0 0 >/dev/null 2>&1 || true
fi
SESSION_PID_FILE="/tmp/bananarchy-x11-session.pid"
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
# Autosuspend is disabled on Bananarchy so keypad, lid, and power keys always wake the screen immediately.
exit 0
+55
View File
@@ -0,0 +1,55 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
BPATH="/sys/class/backlight/backlight/brightness"
MPATH="/sys/class/backlight/backlight/max_brightness"
CFGDIR="${XDG_CONFIG_HOME:-${HOME:-/home/user}/.config}/sxmo"
CFGFILE="$CFGDIR/brightness"
MAX_BL=14
[ -r "$MPATH" ] && { read -r MAX_BL < "$MPATH" 2>/dev/null || true; }
[ "${MAX_BL:-0}" -ge 1 ] 2>/dev/null || MAX_BL=14
CUR_BL="$MAX_BL"
if [ -r "$BPATH" ]; then
read -r CUR_BL < "$BPATH" 2>/dev/null || true
fi
if [ "${CUR_BL:-0}" -lt 1 ] 2>/dev/null; then
if [ -r /tmp/sxmo_saved_brightness ]; then
read -r CUR_BL < /tmp/sxmo_saved_brightness 2>/dev/null || true
elif [ -r "$CFGFILE" ]; then
read -r CUR_BL < "$CFGFILE" 2>/dev/null || true
fi
fi
[ "${CUR_BL:-0}" -ge 1 ] 2>/dev/null || CUR_BL="$MAX_BL"
STEP=$(( MAX_BL / 14 ))
[ "$STEP" -lt 1 ] && STEP=1
case "${1:-}" in
up)
NEXT_BL=$(( CUR_BL + STEP ))
;;
down)
NEXT_BL=$(( CUR_BL - STEP ))
;;
set)
NEXT_BL="${2:-$CUR_BL}"
;;
get|"")
printf '%s\n' "$CUR_BL"
exit 0
;;
*)
NEXT_BL="$CUR_BL"
;;
esac
[ "$NEXT_BL" -gt "$MAX_BL" ] 2>/dev/null && NEXT_BL="$MAX_BL"
[ "$NEXT_BL" -lt 1 ] 2>/dev/null && NEXT_BL=1
mkdir -p "$CFGDIR" 2>/dev/null || true
printf '%s\n' "$NEXT_BL" > /tmp/sxmo_saved_brightness 2>/dev/null || true
printf '%s\n' "$NEXT_BL" > "$CFGFILE" 2>/dev/null || true
printf '0\n' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
printf '%s\n' "$NEXT_BL" > "$BPATH" 2>/dev/null || true
+4
View File
@@ -20,6 +20,10 @@ export LC_ALL="${LC_ALL:-C.UTF-8}"
export XMODIFIERS="${XMODIFIERS:-@im=fcitx}"
export GTK_IM_MODULE="${GTK_IM_MODULE:-fcitx}"
export QT_IM_MODULE="${QT_IM_MODULE:-fcitx}"
case ":${PATH:-}:" in
*:/usr/share/sxmo/default_hooks:*) ;;
*) export PATH="$XDG_CONFIG_HOME/sxmo/hooks:/usr/share/sxmo/default_hooks:${PATH:-/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin}" ;;
esac
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && [ -r "$XDG_RUNTIME_DIR/dbus.bus" ]; then
read -r DBUS_SESSION_BUS_ADDRESS < "$XDG_RUNTIME_DIR/dbus.bus" 2>/dev/null || true
+8 -5
View File
@@ -16,8 +16,9 @@ threshold="${SXMO_THRESHOLD:-0.15}"
# all wake and unlock the phone, so execute immediately without waiting 300ms.
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then
read -r cur_state < "$STATE_FILE" 2>/dev/null || cur_state=""
if [ "$cur_state" != "unlock" ]; then
cur_state=""
read -r cur_state < "$STATE_FILE" 2>/dev/null || true
if [ -n "$cur_state" ] && [ "$cur_state" != "unlock" ]; then
case "$identifier" in
powerbutton|pickup)
rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
@@ -30,13 +31,14 @@ fi
count_file="$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
if [ -f "$count_file" ]; then
read -r old_counter < "$count_file" 2>/dev/null || old_counter=0
old_counter=0
read -r old_counter < "$count_file" 2>/dev/null || true
counter="$((old_counter+1))"
else
counter=1
fi
printf %s "$counter" > "$count_file"
printf '%s\n' "$counter" > "$count_file"
shift "$counter"
if [ "$#" -eq 0 ]; then
@@ -45,7 +47,8 @@ fi
sleep "$threshold"
read -r new_counter < "$count_file" 2>/dev/null || new_counter="$counter"
new_counter="$counter"
read -r new_counter < "$count_file" 2>/dev/null || true
if [ "$counter" != "$new_counter" ] && [ "$#" -ne 1 ]; then # Only the last count can overflow
exit
fi
+19 -17
View File
@@ -38,12 +38,13 @@ restart_sxmo_hook_lisgd() {
xorgisrotated() {
if [ -r "$ROT_STATE_FILE" ]; then
read -r rotation < "$ROT_STATE_FILE" 2>/dev/null || rotation="normal"
rotation="normal"
read -r rotation < "$ROT_STATE_FILE" 2>/dev/null || true
else
rotation="$(
xrandr | grep primary | cut -d' ' -f 5 | sed s/\(//
)"
printf %s "${rotation:-normal}" > "$ROT_STATE_FILE"
printf '%s\n' "${rotation:-normal}" > "$ROT_STATE_FILE"
fi
if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then
return 1;
@@ -54,12 +55,13 @@ xorgisrotated() {
swayisrotated() {
if [ -r "$ROT_STATE_FILE" ]; then
read -r rotation < "$ROT_STATE_FILE" 2>/dev/null || rotation="normal"
rotation="normal"
read -r rotation < "$ROT_STATE_FILE" 2>/dev/null || true
else
rotation="$(
swayfocusedtransform | sed -e s/90/right/ -e s/270/left/ -e s/180/reverse/
)"
printf %s "${rotation:-normal}" > "$ROT_STATE_FILE"
printf '%s\n' "${rotation:-normal}" > "$ROT_STATE_FILE"
fi
if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then
return 1
@@ -72,7 +74,7 @@ riverisrotated() {
rotation="$(
riverfocusedtransform | sed -e s/270/right/ -e s/90/left/ -e s/180/reverse/
)"
printf %s "$rotation" > "$ROT_STATE_FILE"
printf '%s\n' "$rotation" > "$ROT_STATE_FILE"
if [ "$rotation" = "normal" ]; then
return 1
fi
@@ -83,7 +85,7 @@ riverisrotated() {
xorgrotinvert() {
sxmo_keyboard.sh close
xrandr -o inverted
printf %s "reverse" > "$ROT_STATE_FILE"
printf '%s\n' "reverse" > "$ROT_STATE_FILE"
applyptrmatrix -1 0 1 0 -1 1 0 0 1
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert
@@ -92,7 +94,7 @@ xorgrotinvert() {
swayrotinvert() {
swaymsg -- output "-" transform 180
printf %s "reverse" > "$ROT_STATE_FILE"
printf '%s\n' "reverse" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert
exit 0
@@ -101,7 +103,7 @@ swayrotinvert() {
riverrotinvert() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 180
printf %s "reverse" > "$ROT_STATE_FILE"
printf '%s\n' "reverse" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert
exit 0
@@ -110,7 +112,7 @@ riverrotinvert() {
xorgrotnormal() {
sxmo_keyboard.sh close
xrandr -o normal
printf %s "normal" > "$ROT_STATE_FILE"
printf '%s\n' "normal" > "$ROT_STATE_FILE"
applyptrmatrix 0 0 0 0 0 0 0 0 0
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal
@@ -119,7 +121,7 @@ xorgrotnormal() {
swayrotnormal() {
swaymsg -- output "-" transform 0
printf %s "normal" > "$ROT_STATE_FILE"
printf '%s\n' "normal" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal
exit 0
@@ -128,7 +130,7 @@ swayrotnormal() {
riverrotnormal() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform normal
printf %s "normal" > "$ROT_STATE_FILE"
printf '%s\n' "normal" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal
exit 0
@@ -137,7 +139,7 @@ riverrotnormal() {
xorgrotright() {
sxmo_keyboard.sh close
xrandr -o right
printf %s "right" > "$ROT_STATE_FILE"
printf '%s\n' "right" > "$ROT_STATE_FILE"
applyptrmatrix 0 1 0 -1 0 1 0 0 1
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right
@@ -146,7 +148,7 @@ xorgrotright() {
swayrotright() {
swaymsg -- output "-" transform 90
printf %s "right" > "$ROT_STATE_FILE"
printf '%s\n' "right" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right
exit 0
@@ -155,7 +157,7 @@ swayrotright() {
riverrotright() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 270
printf %s "right" > "$ROT_STATE_FILE"
printf '%s\n' "right" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right
exit 0
@@ -164,7 +166,7 @@ riverrotright() {
xorgrotleft() {
sxmo_keyboard.sh close
xrandr -o left
printf %s "left" > "$ROT_STATE_FILE"
printf '%s\n' "left" > "$ROT_STATE_FILE"
applyptrmatrix 0 -1 1 1 0 0 0 0 1
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left
@@ -173,7 +175,7 @@ xorgrotleft() {
swayrotleft() {
swaymsg -- output "-" transform 270
printf %s "left" > "$ROT_STATE_FILE"
printf '%s\n' "left" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left
exit 0
@@ -182,7 +184,7 @@ swayrotleft() {
riverrotleft() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 90
printf %s "left" > "$ROT_STATE_FILE"
printf '%s\n' "left" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left
exit 0
+4 -3
View File
@@ -23,7 +23,7 @@ transition() {
state="$1"
sxmo_log "transitioning to stage $state"
printf %s "$state" > "$SXMO_STATE"
printf '%s\n' "$state" > "$SXMO_STATE"
lock_shared
@@ -76,7 +76,7 @@ idle() {
store() {
storeid="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
printf %s "$state" > "$SXMO_STATE.stored.$storeid"
printf '%s\n' "$state" > "$SXMO_STATE.stored.$storeid"
printf %s "$storeid"
}
@@ -87,7 +87,8 @@ flushstored() {
restore() {
storeid="$1"
if [ -f "$SXMO_STATE.stored.$storeid" ]; then
read -r state < "$SXMO_STATE.stored.$storeid" 2>/dev/null || state=""
state=""
read -r state < "$SXMO_STATE.stored.$storeid" 2>/dev/null || true
transition "$state"
flushstored
fi
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
# System suspend is disabled on Bananarchy so keypad, lid, and power keys always wake the screen immediately.
exit 0
+29 -13
View File
@@ -32,36 +32,52 @@ xorgdisplay() {
case "$1" in
off)
if [ -r /sys/class/backlight/backlight/brightness ]; then
read -r _cur_bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _cur_bl=0
if [ "${_cur_bl:-0}" -gt 1 ] 2>/dev/null; then
printf '%s' "$_cur_bl" > /tmp/sxmo_saved_brightness 2>/dev/null || true
_cur_bl=0
read -r _cur_bl < /sys/class/backlight/backlight/brightness 2>/dev/null || true
if [ "${_cur_bl:-0}" -ge 1 ] 2>/dev/null; then
printf '%s\n' "$_cur_bl" > /tmp/sxmo_saved_brightness 2>/dev/null || true
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo" 2>/dev/null || true
printf '%s\n' "$_cur_bl" > "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/brightness" 2>/dev/null || true
fi
fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '0' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
printf '0\n' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
fi
if [ -w /sys/class/backlight/backlight/brightness ]; then
printf '0' > /sys/class/backlight/backlight/brightness 2>/dev/null || true
printf '0\n' > /sys/class/backlight/backlight/brightness 2>/dev/null || true
fi
xset s off s noblank -dpms >/dev/null 2>&1 || true
xset s off s noblank >/dev/null 2>&1 || true
;;
on)
xset s off s noblank -dpms >/dev/null 2>&1 || true
xset s off s noblank >/dev/null 2>&1 || true
if [ -w /sys/class/backlight/backlight/bl_power ]; then
printf '0' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
printf '0\n' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
fi
if [ -w /sys/class/backlight/backlight/brightness ]; then
_restore_bl=""
if [ -r /tmp/sxmo_saved_brightness ]; then
read -r _restore_bl < /tmp/sxmo_saved_brightness 2>/dev/null || _restore_bl=""
read -r _restore_bl < /tmp/sxmo_saved_brightness 2>/dev/null || true
fi
if [ -z "$_restore_bl" ] || [ "${_restore_bl:-0}" -le 1 ] 2>/dev/null; then
read -r _restore_bl < /sys/class/backlight/backlight/max_brightness 2>/dev/null || _restore_bl=14
if [ -z "$_restore_bl" ] || [ "${_restore_bl:-0}" -lt 1 ] 2>/dev/null; then
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/brightness" ]; then
read -r _restore_bl < "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/brightness" 2>/dev/null || true
fi
fi
printf '%s' "${_restore_bl:-14}" > /sys/class/backlight/backlight/brightness 2>/dev/null || true
if [ -z "$_restore_bl" ] || [ "${_restore_bl:-0}" -lt 1 ] 2>/dev/null; then
_restore_bl=14
read -r _restore_bl < /sys/class/backlight/backlight/max_brightness 2>/dev/null || true
fi
printf '%s\n' "${_restore_bl:-14}" > /tmp/sxmo_saved_brightness 2>/dev/null || true
printf '%s\n' "${_restore_bl:-14}" > /sys/class/backlight/backlight/brightness 2>/dev/null || true
fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '255' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
_restore_kbd="255"
if [ -r /tmp/sxmo_saved_kbd_brightness ]; then
read -r _restore_kbd < /tmp/sxmo_saved_kbd_brightness 2>/dev/null || true
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/kbd_brightness" ]; then
read -r _restore_kbd < "${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/kbd_brightness" 2>/dev/null || true
fi
printf '%s\n' "${_restore_kbd:-255}" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
fi
;;
"")
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
#!/bin/sh
# title="$icon_cam Screenshot"
exec /usr/bin/bananarchy-screenshot "$@"
@@ -110,11 +110,14 @@ CACHE_FILE="${XDG_RUNTIME_DIR:-/tmp}/sxmo_bat_state_${name}"
ICON_FILE="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status/${SXMO_STATUS_NAME:-default}/040-battery-icon-${name}"
NEW_VAL="${state}:${percentage}"
if [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || OLD_VAL=""
OLD_VAL=""
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || true
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
exit 0
fi
fi
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE"
chown 10000:10000 "$CACHE_FILE" 2>/dev/null || true
sxmo_hook_statusbar.sh battery "$name" "$state" "$percentage"
chown -R 10000:10000 "${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status" 2>/dev/null || true
@@ -19,7 +19,8 @@ stop_proximity_lock() {
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then
read -r CURRENT_STATE < "$STATE_FILE" || CURRENT_STATE=""
CURRENT_STATE=""
read -r CURRENT_STATE < "$STATE_FILE" 2>/dev/null || true
else
CURRENT_STATE="$(sxmo_state.sh get)"
fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else
sxmo_wm.sh display on
fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '255' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
else
brightnessctl -d white:kbd_backlight set 255 >/dev/null 2>&1 || true
fi
sxmo_state.sh set unlock &
exit 0
;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0
;;
"powerbutton_two")
sxmo_state.sh click 2
sxmo_state.sh set screenoff
exit 0
;;
"powerbutton_three")
@@ -17,29 +17,37 @@
# This hook is called when the system reaches a locked state
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
cur_state=""
[ -r "$STATE_FILE" ] && { read -r cur_state < "$STATE_FILE" 2>/dev/null || true; }
[ "$cur_state" = "unlock" ] && exit 0
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink blue &
fi
[ "$SXMO_WM" = "sway" ] && swaymsg mode default
sxmo_wm.sh display on
cur_state=""
[ -r "$STATE_FILE" ] && { read -r cur_state < "$STATE_FILE" 2>/dev/null || true; }
if [ "$cur_state" != "unlock" ]; then
sxmo_wm.sh display off
fi
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen off
fi
case "$SXMO_WM" in
dwm)
if ! sxmo_jobs.sh running proximity_lock -q; then
sxmo_dmenu.sh close
fi
;;
esac
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_jobs.sh stop periodic_blink
fi
sxmo_jobs.sh stop periodic_wakelock_check
# Re-enable automatic screen-off on idle to save battery. The phone only
# locks on explicit request; once locked we blank the screen after a short
# idle period.
if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_LOCK_IDLE_TIME:-8}" 'sh -c "sxmo_state.sh set screenoff"'
fi
sxmo_jobs.sh stop idle_locker
wait
@@ -17,15 +17,21 @@
# This hook is called when the system reaches a off state (screen off)
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
cur_state=""
[ -r "$STATE_FILE" ] && { read -r cur_state < "$STATE_FILE" 2>/dev/null || true; }
[ "$cur_state" = "unlock" ] && exit 0
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink red blue &
fi
[ "$SXMO_WM" = "sway" ] && swaymsg mode default
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '0' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
cur_state=""
[ -r "$STATE_FILE" ] && { read -r cur_state < "$STATE_FILE" 2>/dev/null || true; }
if [ "$cur_state" != "unlock" ]; then
sxmo_wm.sh display off
fi
sxmo_wm.sh display off
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen off
fi
@@ -84,10 +84,11 @@ if [ "$(command -v fcitx5)" ]; then
fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary
# Turn on auto-suspend
# Keep system awake so keypad, lid, and power keys always wake the screen immediately
mkdir -p "$XDG_CACHE_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite
superctl start sxmo_autosuspend
fi
# To setup initial unlock state
@@ -76,7 +76,8 @@ set_state() {
return
fi
read -r cur_state < "$SXMO_STATE" 2>/dev/null || cur_state=""
cur_state=""
read -r cur_state < "$SXMO_STATE" 2>/dev/null || true
case "$cur_state" in
screenoff)
sxmobar -a -e bold -f red state 90 "$icon_state_screenoff" # filled circle
@@ -14,9 +14,6 @@ if [ -z "$SXMO_DISABLE_LEDS" ]; then
fi
sxmo_wm.sh display on
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then
printf '255' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
fi
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen on
fi
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -105,7 +105,6 @@ rm -rf \
"$TARGET_ROOTFS/usr/share/sxmo/services/sxmo_riverbar.service" \
"$TARGET_ROOTFS/usr/share/sxmo/services/sxmo_wob.service" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_record.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_screenshot.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_websearch.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_youtube.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_youtube_audio.sh" \
@@ -141,6 +140,7 @@ rm -rf \
"$TARGET_ROOTFS/etc/runlevels/default/nftables" \
"$TARGET_ROOTFS/etc/runlevels/boot/logbookd" \
"$TARGET_ROOTFS/usr/share/superd/services/sxmo_battery_monitor.service" \
"$TARGET_ROOTFS/usr/share/superd/services/sxmo_autosuspend.service" \
"$TARGET_ROOTFS/usr/share/superd/services/sxmo-x11-status.service" \
"$TARGET_ROOTFS/swapfile" \
"$TARGET_ROOTFS/var/log/logbookd.db"*
+10 -8
View File
@@ -1081,10 +1081,19 @@ handle_builtin_toggle(const char *toggle_name)
int maxv = atoi(max_s);
if (maxv <= 0)
maxv = 255;
int step = MAX(1, maxv / 10);
int step = MAX(1, maxv / 14);
int nextv = (strcmp(toggle_name, "bright_up") == 0) ? MIN(maxv, cur + step) : MAX(1, cur - step);
char out[32];
snprintf(out, sizeof(out), "%d\n", nextv);
write_str_file("/tmp/sxmo_saved_brightness", out);
const char *home = getenv("HOME");
if (!home || !home[0])
home = "/home/user";
char cfgdir[256], cfgpath[256];
snprintf(cfgdir, sizeof(cfgdir), "%s/.config/sxmo", home);
mkdir(cfgdir, 0755);
snprintf(cfgpath, sizeof(cfgpath), "%s/brightness", cfgdir);
write_str_file(cfgpath, out);
if (!write_str_file(bpath, out))
spawn_detached_sh(strcmp(toggle_name, "bright_up") == 0 ? "sxmo_brightness.sh up" : "sxmo_brightness.sh down");
} else {
@@ -2584,7 +2593,6 @@ open_builtin_menu(const char *menu_name, int keep_idx)
const char *home = getenv("HOME");
if (!home || !home[0])
home = "/home/user";
char pbuf[256];
snprintf(label, sizeof(label), "%s Themes", ICON_THM);
add_menu_item(label, "@plugin:themes", 0);
@@ -2603,14 +2611,8 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Change Timezone", ICON_CLK);
add_menu_item(label, "@menu:timezone", 1);
snprintf(pbuf, sizeof(pbuf), "%s/.cache/sxmo/sxmo.nosuspend", home);
snprintf(label, sizeof(label), "%s Auto-suspend %s", ICON_ZZZ, (access(pbuf, F_OK) == 0) ? ICON_TOF : ICON_TON);
add_menu_item(label, "@toggle:autosuspend", 1);
snprintf(label, sizeof(label), "%s Hooks", ICON_TRM);
add_menu_item(label, "sxmo_hookmenu.sh", 0);
snprintf(label, sizeof(label), "%s Suspend Blockers", ICON_CFG);
add_menu_item(label, "sxmo_terminal.sh sxmo_debug_suspend.sh", 0);
snprintf(label, sizeof(label), "%s Log", ICON_INF);
snprintf(cmd, sizeof(cmd), "sxmo_terminal.sh tail -n 100 -f %s/sxmo.log", home);
add_menu_item(label, cmd, 0);
+278 -52
View File
@@ -32,6 +32,7 @@
#include <string.h>
#include <unistd.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <X11/cursorfont.h>
@@ -328,6 +329,18 @@ static xcb_connection_t *xcon;
static struct HoldKey *holdkeyroot = NULL;
#define MAX_INPUT_FDS 8
static int input_fds[MAX_INPUT_FDS];
static int num_input_fds = 0;
static long long last_wake_ms = 0;
static int star_down = 0;
static int pound_down = 0;
static long long last_screenshot_ms = 0;
static int starpound_pending = 0;
static long long starpound_deadline_ms = 0;
static KeySym starpound_keysym = NoSymbol;
static unsigned int starpound_keycode = 0;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -706,6 +719,11 @@ cleanup(void)
for (i = 0; i < LENGTH(colors); i++)
free(scheme[i]);
unload_plugins();
for (i = 0; i < (size_t)num_input_fds; i++) {
if (input_fds[i] >= 0)
close(input_fds[i]);
}
num_input_fds = 0;
XDestroyWindow(dpy, wmcheckwin);
drw_free(drw);
XSync(dpy, False);
@@ -1192,38 +1210,97 @@ read_sysfs_str(const char *path, char *buf, size_t len)
buf[0] = '\0';
}
static void
get_brightness_cfg_path(char *path, size_t len, const char *filename)
{
const char *xdg = getenv("XDG_CONFIG_HOME");
const char *home = getenv("HOME");
if (xdg && xdg[0])
snprintf(path, len, "%s/sxmo/%s", xdg, filename);
else if (home && home[0])
snprintf(path, len, "%s/.config/sxmo/%s", home, filename);
else
snprintf(path, len, "/home/user/.config/sxmo/%s", filename);
}
static void
save_brightness_str(const char *val)
{
char line[24], cfgpath[256];
int fd, len;
if (!val || atoi(val) < 1)
return;
len = snprintf(line, sizeof(line), "%d\n", atoi(val));
fd = open("/tmp/sxmo_saved_brightness", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd >= 0) {
(void)write(fd, line, len);
close(fd);
}
get_brightness_cfg_path(cfgpath, sizeof(cfgpath), "brightness");
fd = open(cfgpath, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd >= 0) {
(void)write(fd, line, len);
close(fd);
}
}
static void
set_hw_backlight(int on)
{
static char saved_brightness[16] = "14";
char cur[16] = "";
char cur[16] = "", cfgpath[256];
if (on) {
read_sysfs_str("/tmp/sxmo_saved_brightness", cur, sizeof(cur));
if (atoi(cur) > 1)
snprintf(saved_brightness, sizeof(saved_brightness), "%s", cur);
else if (atoi(saved_brightness) <= 1) {
read_sysfs_str("/sys/class/backlight/backlight/max_brightness", cur, sizeof(cur));
snprintf(saved_brightness, sizeof(saved_brightness), "%s", (atoi(cur) > 1) ? cur : "14");
if (atoi(cur) < 1) {
get_brightness_cfg_path(cfgpath, sizeof(cfgpath), "brightness");
read_sysfs_str(cfgpath, cur, sizeof(cur));
}
if (atoi(cur) >= 1) {
snprintf(saved_brightness, sizeof(saved_brightness), "%d", atoi(cur));
} else if (atoi(saved_brightness) < 1) {
read_sysfs_str("/sys/class/backlight/backlight/max_brightness", cur, sizeof(cur));
snprintf(saved_brightness, sizeof(saved_brightness), "%d", (atoi(cur) >= 1) ? atoi(cur) : 14);
}
save_brightness_str(saved_brightness);
write_sysfs_str("/sys/class/backlight/backlight/bl_power", "0");
write_sysfs_str("/sys/class/backlight/backlight/brightness", saved_brightness);
write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", "255");
cur[0] = '\0';
read_sysfs_str("/tmp/sxmo_saved_kbd_brightness", cur, sizeof(cur));
if (cur[0] == '\0') {
get_brightness_cfg_path(cfgpath, sizeof(cfgpath), "kbd_brightness");
read_sysfs_str(cfgpath, cur, sizeof(cur));
}
write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", (cur[0] != '\0') ? cur : "255");
} else {
read_sysfs_str("/sys/class/backlight/backlight/brightness", cur, sizeof(cur));
if (atoi(cur) > 1) {
snprintf(saved_brightness, sizeof(saved_brightness), "%s", cur);
int fd = open("/tmp/sxmo_saved_brightness", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd >= 0) {
(void)write(fd, saved_brightness, strlen(saved_brightness));
close(fd);
}
if (atoi(cur) >= 1) {
snprintf(saved_brightness, sizeof(saved_brightness), "%d", atoi(cur));
save_brightness_str(saved_brightness);
}
write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", "0");
write_sysfs_str("/sys/class/backlight/backlight/brightness", "0");
}
}
static void
set_sxmo_state_str(const char *st)
{
const char *rdir = getenv("XDG_RUNTIME_DIR");
char path[256], line[32];
int fd, len;
snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000");
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd >= 0) {
len = snprintf(line, sizeof(line), "%s\n", st);
(void)write(fd, line, len);
close(fd);
}
}
static int
is_phone_locked(void)
{
@@ -1232,6 +1309,10 @@ 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)
return 1;
snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000");
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
@@ -1275,8 +1356,6 @@ writefocusedwin(Client *c)
}
}
static int lidfd = -1;
void
focus(Client *c)
{
@@ -1962,6 +2041,93 @@ flush_pending_softkey(void)
}
}
static int
is_star_key(KeySym ks, unsigned int keycode)
{
return keycode == 63 || keycode == 530 || ks == XK_asterisk || ks == XK_KP_Multiply;
}
static int
is_pound_key(KeySym ks, unsigned int keycode)
{
return keycode == 106 || keycode == 531 || ks == XK_numbersign || ks == XK_KP_Divide;
}
static void
trigger_screenshot_chord(long long now)
{
const Arg shotcmd = { .v = (const char*[]){ "bananarchy-screenshot", NULL } };
starpound_pending = 0;
starpound_deadline_ms = 0;
if ((now - last_screenshot_ms) < 400)
return;
last_screenshot_ms = now;
spawn(&shotcmd);
}
static void
flush_pending_starpound(void)
{
int pending = starpound_pending;
KeySym ks = starpound_keysym;
unsigned int kc = starpound_keycode;
starpound_pending = 0;
starpound_deadline_ms = 0;
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
if (!pending || (dwm_now_ms() - last_screenshot_ms) < 400)
return;
if (!selmon->sel && !is_phone_locked())
(void)dispatch_plugin_idle_key(ks, kc, 0);
}
static void
lock_phone_screenoff(void)
{
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff");
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
last_softkey_mask = 0;
last_softkey_ms = 0;
starpound_pending = 0;
starpound_deadline_ms = 0;
star_down = 0;
pound_down = 0;
write_softkey_state(0, 0);
if (is_plugin_loaded("dmenu"))
host_spawn_plugin("dmenu", "close");
set_sxmo_state_str("screenoff");
set_hw_backlight(0);
spawn(&offcmd);
}
static void
wake_phone(void)
{
const Arg oncmd = SHCMD("sxmo_state.sh set unlock");
long long now = dwm_now_ms();
last_wake_ms = now;
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
last_softkey_mask = 0;
last_softkey_ms = 0;
starpound_pending = 0;
starpound_deadline_ms = 0;
star_down = 0;
pound_down = 0;
write_softkey_state(0, 0);
write_softkey_suppress(now + SOFTKEY_SUPPRESS_MS);
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
set_sxmo_state_str("unlock");
set_hw_backlight(1);
spawn(&oncmd);
}
void
keypress(XEvent *e)
{
@@ -1972,26 +2138,43 @@ keypress(XEvent *e)
ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
if ((keysym == XF86XK_PowerOff || keysym == XF86XK_PickupPhone ||
keysym == XF86XK_Phone || keysym == XK_Menu || keysym == XF86XK_Back ||
keysym == XK_Return ||
keysym == XF86XK_KbdLcdMenu1 || keysym == XF86XK_KbdLcdMenu2) &&
is_phone_locked()) {
const Arg unlockcmd = SHCMD("xset s off s noblank -dpms; sxmo_state.sh set unlock");
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
last_softkey_mask = 0;
last_softkey_ms = 0;
write_softkey_state(0, 0);
write_softkey_suppress(dwm_now_ms() + SOFTKEY_SUPPRESS_MS);
if (is_phone_locked()) {
wake_phone();
return;
}
if ((dwm_now_ms() - last_wake_ms) < 350) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
set_hw_backlight(1);
spawn(&unlockcmd);
return;
}
if (CLEANMASK(ev->state) == 0 &&
(is_star_key(keysym, ev->keycode) || is_pound_key(keysym, ev->keycode))) {
long long now = dwm_now_ms();
if ((now - last_screenshot_ms) < 400) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
return;
}
if (star_down && pound_down) {
trigger_screenshot_chord(now);
return;
}
if (!selmon->sel && !is_phone_locked()) {
int which = is_star_key(keysym, ev->keycode) ? 1 : 2;
starpound_pending |= which;
if (starpound_pending == 3) {
trigger_screenshot_chord(now);
} else {
starpound_keysym = keysym;
starpound_keycode = ev->keycode;
if (starpound_deadline_ms == 0)
starpound_deadline_ms = now + 100;
}
return;
}
}
if (CLEANMASK(ev->state) == 0 &&
(is_left_softkey(keysym, ev->keycode) || is_right_softkey(keysym, ev->keycode))) {
long long now = dwm_now_ms();
@@ -2079,6 +2262,9 @@ keyrelease(XEvent *e)
markreleased(keysym);
if (is_phone_locked() || (dwm_now_ms() - last_wake_ms) < 350)
return;
if (is_left_softkey(keysym, ev->keycode) || is_right_softkey(keysym, ev->keycode)) {
return;
}
@@ -2503,9 +2689,9 @@ void
run(void)
{
XEvent ev;
struct pollfd fds[2];
struct pollfd fds[1 + MAX_INPUT_FDS];
struct input_event ie;
int nfds, xfd;
int nfds, xfd, i;
/* main event loop */
XSync(dpy, False);
@@ -2523,11 +2709,11 @@ run(void)
fds[0].events = POLLIN;
fds[0].revents = 0;
nfds = 1;
if (lidfd >= 0) {
fds[1].fd = lidfd;
fds[1].events = POLLIN;
fds[1].revents = 0;
nfds = 2;
for (i = 0; i < num_input_fds; i++) {
fds[nfds].fd = input_fds[i];
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
int timeout_ms = -1;
if (softkey_pending && softkey_deadline_ms > 0) {
@@ -2546,22 +2732,51 @@ run(void)
timeout_ms = (int)rem;
}
}
if (starpound_pending && starpound_deadline_ms > 0) {
long long now = dwm_now_ms();
if (star_down && pound_down) {
trigger_screenshot_chord(now);
continue;
}
long long rem = starpound_deadline_ms - now;
if (rem <= 0) {
flush_pending_starpound();
continue;
} else if (timeout_ms < 0 || rem < timeout_ms) {
timeout_ms = (int)rem;
}
}
if (poll(fds, nfds, timeout_ms) < 0) {
if (errno == EINTR)
continue;
break;
}
if (nfds == 2 && (fds[1].revents & POLLIN)) {
while (read(lidfd, &ie, sizeof(ie)) == (ssize_t)sizeof(ie)) {
if (ie.type == EV_SW && ie.code == SW_LID) {
if (ie.value == 1) {
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff");
set_hw_backlight(0);
spawn(&offcmd);
} else if (ie.value == 0) {
const Arg oncmd = SHCMD("xset s off s noblank -dpms; sxmo_state.sh set unlock");
set_hw_backlight(1);
spawn(&oncmd);
for (i = 0; i < num_input_fds; i++) {
if (fds[1 + i].revents & POLLIN) {
while (read(input_fds[i], &ie, sizeof(ie)) == (ssize_t)sizeof(ie)) {
if (ie.type == EV_SW && ie.code == SW_LID) {
if (ie.value == 1) {
lock_phone_screenoff();
} else if (ie.value == 0) {
wake_phone();
}
} else if (ie.type == EV_KEY) {
if (ie.code == 522 || ie.code == 55)
star_down = (ie.value != 0);
else if (ie.code == 523 || ie.code == 98)
pound_down = (ie.value != 0);
if (ie.value == 1) {
if (is_phone_locked()) {
wake_phone();
} else if ((ie.code == 522 || ie.code == 55 ||
ie.code == 523 || ie.code == 98) &&
star_down && pound_down) {
trigger_screenshot_chord(dwm_now_ms());
}
} else if (ie.value == 0 && !star_down && !pound_down && starpound_pending) {
flush_pending_starpound();
}
}
}
}
@@ -2799,9 +3014,20 @@ setup(void)
|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask|KeyReleaseMask;
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask);
lidfd = open("/dev/input/by-path/platform-gpio-keys-event", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (lidfd < 0)
lidfd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
num_input_fds = 0;
for (i = 0; i < MAX_INPUT_FDS; i++) {
char evpath[64], evname[128] = "";
int evfd;
snprintf(evpath, sizeof(evpath), "/dev/input/event%d", i);
evfd = open(evpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (evfd < 0)
continue;
if (ioctl(evfd, EVIOCGNAME(sizeof(evname)), evname) >= 0 && strstr(evname, "Jack") != NULL) {
close(evfd);
continue;
}
input_fds[num_input_fds++] = evfd;
}
unlink("/tmp/sxmo_softkey_suppress");
unlink("/tmp/sxmo_softkey_state");
load_plugins();
+23 -2
View File
@@ -357,13 +357,27 @@ class PhoneController {
"Microphone", false, 0, 1, 1, (dec1 > 0) ? 1 : 0});
// 8. Screen brightness (slider 1..screenMax_)
int scrCur = std::clamp(readIntFile(backlightDir_ + "/brightness", screenMax_), 1, screenMax_);
int rawScr = readIntFile(backlightDir_ + "/brightness", -1);
if (rawScr < 1) {
rawScr = readIntFile("/tmp/sxmo_saved_brightness", -1);
}
if (rawScr < 1) {
rawScr = readIntFile(getSxmoCfgDir() + "/brightness", screenMax_);
}
int scrCur = std::clamp(rawScr, 1, screenMax_);
int scrStep = std::max(1, screenMax_ / 14);
items_.push_back({ControlId::ScreenBright, kIconBrightness, kIconBrightness,
"Screen", true, 1, screenMax_, scrStep, scrCur});
// 9. Keyboard brightness (slider if max_brightness > 1, toggle otherwise)
int kbdCur = std::clamp(readIntFile(kbdDir_ + "/brightness", 0), 0, kbdMax_);
int rawKbd = readIntFile(kbdDir_ + "/brightness", -1);
if (rawKbd < 0) {
rawKbd = readIntFile("/tmp/sxmo_saved_kbd_brightness", -1);
}
if (rawKbd < 0) {
rawKbd = readIntFile(getSxmoCfgDir() + "/kbd_brightness", 0);
}
int kbdCur = std::clamp(rawKbd, 0, kbdMax_);
if (kbdSupportsSlider_) {
int kbdStep = std::max(1, kbdMax_ / 10);
items_.push_back({ControlId::KbdBright, kIconKeyboard, kIconKeyboard,
@@ -593,13 +607,20 @@ class PhoneController {
break;
}
case ControlId::ScreenBright: {
std::string cfg = getSxmoCfgDir();
::mkdir(cfg.c_str(), 0755);
writeIntFile(backlightDir_ + "/bl_power", 0);
writeIntFile(backlightDir_ + "/brightness", it.value);
writeIntFile("/tmp/sxmo_saved_brightness", it.value);
writeIntFile(cfg + "/brightness", it.value);
break;
}
case ControlId::KbdBright: {
int v = kbdSupportsSlider_ ? it.value : (it.value ? kbdMax_ : 0);
std::string cfg = getSxmoCfgDir();
::mkdir(cfg.c_str(), 0755);
writeIntFile("/tmp/sxmo_saved_kbd_brightness", v);
writeIntFile(cfg + "/kbd_brightness", v);
if (!writeIntFile(kbdDir_ + "/brightness", v)) {
char cmd[128];
std::snprintf(cmd, sizeof(cmd),