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
+576 -163

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. 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 ## 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/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/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: - `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`)**: - **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`). - 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`). - 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**: - **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). - 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. - 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 | | **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` | | **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 | | **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 `#` | | **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 | | **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 | | **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 | | **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 | | **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**: > **Screen blanking, locking, waking, and brightness persistence**:
> 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)**. > 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 #### 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. 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. 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`). 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 ### 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`: 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. - **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. - **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. - **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. - **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 HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore HandleLidSwitchDocked=ignore
IdleAction=ignore
[Sleep]
AllowSuspendInterrupts=yes
+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}" STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then 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 else
CURRENT_STATE="$(sxmo_state.sh get)" CURRENT_STATE="$(sxmo_state.sh get)"
fi fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else else
sxmo_wm.sh display on sxmo_wm.sh display on
fi 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 & sxmo_state.sh set unlock &
exit 0 exit 0
;; ;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0 exit 0
;; ;;
"powerbutton_two") "powerbutton_two")
sxmo_state.sh click 2 sxmo_state.sh set screenoff
exit 0 exit 0
;; ;;
"powerbutton_three") "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}" STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then 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 else
CURRENT_STATE="$(sxmo_state.sh get)" CURRENT_STATE="$(sxmo_state.sh get)"
fi fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else else
sxmo_wm.sh display on sxmo_wm.sh display on
fi 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 & sxmo_state.sh set unlock &
exit 0 exit 0
;; ;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0 exit 0
;; ;;
"powerbutton_two") "powerbutton_two")
sxmo_state.sh click 2 sxmo_state.sh set screenoff
exit 0 exit 0
;; ;;
"powerbutton_three") "powerbutton_three")
@@ -84,10 +84,11 @@ if [ "$(command -v fcitx5)" ]; then
fi fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary [ -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 if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite sxmo_wakelock.sh lock sxmo_not_suspendable infinite
superctl start sxmo_autosuspend
fi fi
# To setup initial unlock state # 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 WAYLAND_DISPLAY
unset SWAYSOCK unset SWAYSOCK
mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/sxmo" mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/sxmo" "$XDG_CONFIG_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.noidle" 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" [ -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 "unlock\n" > "$XDG_RUNTIME_DIR/sxmo.state"
printf "14" > /tmp/sxmo_saved_brightness _init_bl=""
printf "14" > /sys/class/backlight/backlight/brightness 2>/dev/null || true if [ -r "$XDG_CONFIG_HOME/sxmo/brightness" ]; then
printf "255" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true 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" XORG_BIN="Xorg"
[ -x /tmp/x11/usr/bin/Xorg ] && XORG_BIN="/tmp/x11/usr/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 & "$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 i=0
while [ "$i" -lt 40 ]; do 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 break
fi fi
sleep 0.05 sleep 0.05
i=$((i + 1)) i=$((i + 1))
done done
else 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 fi
SESSION_PID_FILE="/tmp/bananarchy-x11-session.pid" 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 XMODIFIERS="${XMODIFIERS:-@im=fcitx}"
export GTK_IM_MODULE="${GTK_IM_MODULE:-fcitx}" export GTK_IM_MODULE="${GTK_IM_MODULE:-fcitx}"
export QT_IM_MODULE="${QT_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 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 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. # all wake and unlock the phone, so execute immediately without waiting 300ms.
STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}" STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then if [ -r "$STATE_FILE" ]; then
read -r cur_state < "$STATE_FILE" 2>/dev/null || cur_state="" cur_state=""
if [ "$cur_state" != "unlock" ]; then read -r cur_state < "$STATE_FILE" 2>/dev/null || true
if [ -n "$cur_state" ] && [ "$cur_state" != "unlock" ]; then
case "$identifier" in case "$identifier" in
powerbutton|pickup) powerbutton|pickup)
rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier" rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
@@ -30,13 +31,14 @@ fi
count_file="$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier" count_file="$XDG_RUNTIME_DIR"/sxmo.multikey.count."$identifier"
if [ -f "$count_file" ]; then 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))" counter="$((old_counter+1))"
else else
counter=1 counter=1
fi fi
printf %s "$counter" > "$count_file" printf '%s\n' "$counter" > "$count_file"
shift "$counter" shift "$counter"
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
@@ -45,7 +47,8 @@ fi
sleep "$threshold" 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 if [ "$counter" != "$new_counter" ] && [ "$#" -ne 1 ]; then # Only the last count can overflow
exit exit
fi fi
+19 -17
View File
@@ -38,12 +38,13 @@ restart_sxmo_hook_lisgd() {
xorgisrotated() { xorgisrotated() {
if [ -r "$ROT_STATE_FILE" ]; then 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 else
rotation="$( rotation="$(
xrandr | grep primary | cut -d' ' -f 5 | sed s/\(// 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 fi
if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then
return 1; return 1;
@@ -54,12 +55,13 @@ xorgisrotated() {
swayisrotated() { swayisrotated() {
if [ -r "$ROT_STATE_FILE" ]; then 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 else
rotation="$( rotation="$(
swayfocusedtransform | sed -e s/90/right/ -e s/270/left/ -e s/180/reverse/ 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 fi
if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then if [ "$rotation" = "normal" ] || [ -z "$rotation" ]; then
return 1 return 1
@@ -72,7 +74,7 @@ riverisrotated() {
rotation="$( rotation="$(
riverfocusedtransform | sed -e s/270/right/ -e s/90/left/ -e s/180/reverse/ 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 if [ "$rotation" = "normal" ]; then
return 1 return 1
fi fi
@@ -83,7 +85,7 @@ riverisrotated() {
xorgrotinvert() { xorgrotinvert() {
sxmo_keyboard.sh close sxmo_keyboard.sh close
xrandr -o inverted 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 applyptrmatrix -1 0 1 0 -1 1 0 0 1
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert sxmo_hook_rotate.sh invert
@@ -92,7 +94,7 @@ xorgrotinvert() {
swayrotinvert() { swayrotinvert() {
swaymsg -- output "-" transform 180 swaymsg -- output "-" transform 180
printf %s "reverse" > "$ROT_STATE_FILE" printf '%s\n' "reverse" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert sxmo_hook_rotate.sh invert
exit 0 exit 0
@@ -101,7 +103,7 @@ swayrotinvert() {
riverrotinvert() { riverrotinvert() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name") focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 180 wlr-randr --output "$focused_output" --transform 180
printf %s "reverse" > "$ROT_STATE_FILE" printf '%s\n' "reverse" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh invert sxmo_hook_rotate.sh invert
exit 0 exit 0
@@ -110,7 +112,7 @@ riverrotinvert() {
xorgrotnormal() { xorgrotnormal() {
sxmo_keyboard.sh close sxmo_keyboard.sh close
xrandr -o normal 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 applyptrmatrix 0 0 0 0 0 0 0 0 0
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal sxmo_hook_rotate.sh normal
@@ -119,7 +121,7 @@ xorgrotnormal() {
swayrotnormal() { swayrotnormal() {
swaymsg -- output "-" transform 0 swaymsg -- output "-" transform 0
printf %s "normal" > "$ROT_STATE_FILE" printf '%s\n' "normal" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal sxmo_hook_rotate.sh normal
exit 0 exit 0
@@ -128,7 +130,7 @@ swayrotnormal() {
riverrotnormal() { riverrotnormal() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name") focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform normal wlr-randr --output "$focused_output" --transform normal
printf %s "normal" > "$ROT_STATE_FILE" printf '%s\n' "normal" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh normal sxmo_hook_rotate.sh normal
exit 0 exit 0
@@ -137,7 +139,7 @@ riverrotnormal() {
xorgrotright() { xorgrotright() {
sxmo_keyboard.sh close sxmo_keyboard.sh close
xrandr -o right 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 applyptrmatrix 0 1 0 -1 0 1 0 0 1
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right sxmo_hook_rotate.sh right
@@ -146,7 +148,7 @@ xorgrotright() {
swayrotright() { swayrotright() {
swaymsg -- output "-" transform 90 swaymsg -- output "-" transform 90
printf %s "right" > "$ROT_STATE_FILE" printf '%s\n' "right" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right sxmo_hook_rotate.sh right
exit 0 exit 0
@@ -155,7 +157,7 @@ swayrotright() {
riverrotright() { riverrotright() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name") focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 270 wlr-randr --output "$focused_output" --transform 270
printf %s "right" > "$ROT_STATE_FILE" printf '%s\n' "right" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh right sxmo_hook_rotate.sh right
exit 0 exit 0
@@ -164,7 +166,7 @@ riverrotright() {
xorgrotleft() { xorgrotleft() {
sxmo_keyboard.sh close sxmo_keyboard.sh close
xrandr -o left 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 applyptrmatrix 0 -1 1 1 0 0 0 0 1
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left sxmo_hook_rotate.sh left
@@ -173,7 +175,7 @@ xorgrotleft() {
swayrotleft() { swayrotleft() {
swaymsg -- output "-" transform 270 swaymsg -- output "-" transform 270
printf %s "left" > "$ROT_STATE_FILE" printf '%s\n' "left" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left sxmo_hook_rotate.sh left
exit 0 exit 0
@@ -182,7 +184,7 @@ swayrotleft() {
riverrotleft() { riverrotleft() {
focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name") focused_output=$(river-bedload -print outputs | jq -r ".[] | select(.focused).name")
wlr-randr --output "$focused_output" --transform 90 wlr-randr --output "$focused_output" --transform 90
printf %s "left" > "$ROT_STATE_FILE" printf '%s\n' "left" > "$ROT_STATE_FILE"
restart_sxmo_hook_lisgd restart_sxmo_hook_lisgd
sxmo_hook_rotate.sh left sxmo_hook_rotate.sh left
exit 0 exit 0
+4 -3
View File
@@ -23,7 +23,7 @@ transition() {
state="$1" state="$1"
sxmo_log "transitioning to stage $state" sxmo_log "transitioning to stage $state"
printf %s "$state" > "$SXMO_STATE" printf '%s\n' "$state" > "$SXMO_STATE"
lock_shared lock_shared
@@ -76,7 +76,7 @@ idle() {
store() { store() {
storeid="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)" 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" printf %s "$storeid"
} }
@@ -87,7 +87,8 @@ flushstored() {
restore() { restore() {
storeid="$1" storeid="$1"
if [ -f "$SXMO_STATE.stored.$storeid" ]; then 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" transition "$state"
flushstored flushstored
fi 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 case "$1" in
off) off)
if [ -r /sys/class/backlight/backlight/brightness ]; then if [ -r /sys/class/backlight/backlight/brightness ]; then
read -r _cur_bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _cur_bl=0 _cur_bl=0
if [ "${_cur_bl:-0}" -gt 1 ] 2>/dev/null; then read -r _cur_bl < /sys/class/backlight/backlight/brightness 2>/dev/null || true
printf '%s' "$_cur_bl" > /tmp/sxmo_saved_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
fi fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then 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 fi
if [ -w /sys/class/backlight/backlight/brightness ]; then 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 fi
xset s off s noblank -dpms >/dev/null 2>&1 || true xset s off s noblank >/dev/null 2>&1 || true
;; ;;
on) 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 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 fi
if [ -w /sys/class/backlight/backlight/brightness ]; then if [ -w /sys/class/backlight/backlight/brightness ]; then
_restore_bl="" _restore_bl=""
if [ -r /tmp/sxmo_saved_brightness ]; then 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 fi
if [ -z "$_restore_bl" ] || [ "${_restore_bl:-0}" -le 1 ] 2>/dev/null; then if [ -z "$_restore_bl" ] || [ "${_restore_bl:-0}" -lt 1 ] 2>/dev/null; then
read -r _restore_bl < /sys/class/backlight/backlight/max_brightness 2>/dev/null || _restore_bl=14 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 fi
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 fi
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then 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 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}" ICON_FILE="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status/${SXMO_STATUS_NAME:-default}/040-battery-icon-${name}"
NEW_VAL="${state}:${percentage}" NEW_VAL="${state}:${percentage}"
if [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then 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 if [ "$OLD_VAL" = "$NEW_VAL" ]; then
exit 0 exit 0
fi fi
fi fi
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE" printf '%s\n' "$NEW_VAL" > "$CACHE_FILE"
chown 10000:10000 "$CACHE_FILE" 2>/dev/null || true
sxmo_hook_statusbar.sh battery "$name" "$state" "$percentage" 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}" STATE_FILE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -r "$STATE_FILE" ]; then 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 else
CURRENT_STATE="$(sxmo_state.sh get)" CURRENT_STATE="$(sxmo_state.sh get)"
fi fi
@@ -32,11 +33,6 @@ if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then
else else
sxmo_wm.sh display on sxmo_wm.sh display on
fi 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 & sxmo_state.sh set unlock &
exit 0 exit 0
;; ;;
@@ -431,7 +427,7 @@ case "$ACTION" in
exit 0 exit 0
;; ;;
"powerbutton_two") "powerbutton_two")
sxmo_state.sh click 2 sxmo_state.sh set screenoff
exit 0 exit 0
;; ;;
"powerbutton_three") "powerbutton_three")
@@ -17,29 +17,37 @@
# This hook is called when the system reaches a locked state # 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 if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink blue & sxmo_led.sh blink blue &
fi fi
[ "$SXMO_WM" = "sway" ] && swaymsg mode default [ "$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 if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen off sxmo_wm.sh inputevent touchscreen off
fi 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 if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_jobs.sh stop periodic_blink sxmo_jobs.sh stop periodic_blink
fi fi
sxmo_jobs.sh stop periodic_wakelock_check 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 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
wait wait
@@ -17,15 +17,21 @@
# This hook is called when the system reaches a off state (screen off) # 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 if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink red blue & sxmo_led.sh blink red blue &
fi fi
[ "$SXMO_WM" = "sway" ] && swaymsg mode default [ "$SXMO_WM" = "sway" ] && swaymsg mode default
if [ -w /sys/class/leds/white:kbd_backlight/brightness ]; then cur_state=""
printf '0' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true [ -r "$STATE_FILE" ] && { read -r cur_state < "$STATE_FILE" 2>/dev/null || true; }
fi if [ "$cur_state" != "unlock" ]; then
sxmo_wm.sh display off sxmo_wm.sh display off
fi
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen off sxmo_wm.sh inputevent touchscreen off
fi fi
@@ -84,10 +84,11 @@ if [ "$(command -v fcitx5)" ]; then
fi fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary [ -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 if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite sxmo_wakelock.sh lock sxmo_not_suspendable infinite
superctl start sxmo_autosuspend
fi fi
# To setup initial unlock state # To setup initial unlock state
@@ -76,7 +76,8 @@ set_state() {
return return
fi 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 case "$cur_state" in
screenoff) screenoff)
sxmobar -a -e bold -f red state 90 "$icon_state_screenoff" # filled circle sxmobar -a -e bold -f red state 90 "$icon_state_screenoff" # filled circle
@@ -14,9 +14,6 @@ if [ -z "$SXMO_DISABLE_LEDS" ]; then
fi fi
sxmo_wm.sh display on 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 if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen on sxmo_wm.sh inputevent touchscreen on
fi 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_riverbar.service" \
"$TARGET_ROOTFS/usr/share/sxmo/services/sxmo_wob.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_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_websearch.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_youtube.sh" \ "$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_youtube.sh" \
"$TARGET_ROOTFS/usr/share/sxmo/appscripts/sxmo_youtube_audio.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/default/nftables" \
"$TARGET_ROOTFS/etc/runlevels/boot/logbookd" \ "$TARGET_ROOTFS/etc/runlevels/boot/logbookd" \
"$TARGET_ROOTFS/usr/share/superd/services/sxmo_battery_monitor.service" \ "$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/usr/share/superd/services/sxmo-x11-status.service" \
"$TARGET_ROOTFS/swapfile" \ "$TARGET_ROOTFS/swapfile" \
"$TARGET_ROOTFS/var/log/logbookd.db"* "$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); int maxv = atoi(max_s);
if (maxv <= 0) if (maxv <= 0)
maxv = 255; 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); int nextv = (strcmp(toggle_name, "bright_up") == 0) ? MIN(maxv, cur + step) : MAX(1, cur - step);
char out[32]; char out[32];
snprintf(out, sizeof(out), "%d\n", nextv); 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)) if (!write_str_file(bpath, out))
spawn_detached_sh(strcmp(toggle_name, "bright_up") == 0 ? "sxmo_brightness.sh up" : "sxmo_brightness.sh down"); spawn_detached_sh(strcmp(toggle_name, "bright_up") == 0 ? "sxmo_brightness.sh up" : "sxmo_brightness.sh down");
} else { } else {
@@ -2584,7 +2593,6 @@ open_builtin_menu(const char *menu_name, int keep_idx)
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (!home || !home[0]) if (!home || !home[0])
home = "/home/user"; home = "/home/user";
char pbuf[256];
snprintf(label, sizeof(label), "%s Themes", ICON_THM); snprintf(label, sizeof(label), "%s Themes", ICON_THM);
add_menu_item(label, "@plugin:themes", 0); 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); snprintf(label, sizeof(label), "%s Change Timezone", ICON_CLK);
add_menu_item(label, "@menu:timezone", 1); 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); snprintf(label, sizeof(label), "%s Hooks", ICON_TRM);
add_menu_item(label, "sxmo_hookmenu.sh", 0); 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(label, sizeof(label), "%s Log", ICON_INF);
snprintf(cmd, sizeof(cmd), "sxmo_terminal.sh tail -n 100 -f %s/sxmo.log", home); snprintf(cmd, sizeof(cmd), "sxmo_terminal.sh tail -n 100 -f %s/sxmo.log", home);
add_menu_item(label, cmd, 0); add_menu_item(label, cmd, 0);
+281 -55
View File
@@ -32,6 +32,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <linux/input.h> #include <linux/input.h>
#include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
@@ -328,6 +329,18 @@ static xcb_connection_t *xcon;
static struct HoldKey *holdkeyroot = NULL; 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 */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
@@ -706,6 +719,11 @@ cleanup(void)
for (i = 0; i < LENGTH(colors); i++) for (i = 0; i < LENGTH(colors); i++)
free(scheme[i]); free(scheme[i]);
unload_plugins(); 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); XDestroyWindow(dpy, wmcheckwin);
drw_free(drw); drw_free(drw);
XSync(dpy, False); XSync(dpy, False);
@@ -1193,37 +1211,96 @@ read_sysfs_str(const char *path, char *buf, size_t len)
} }
static void static void
set_hw_backlight(int on) get_brightness_cfg_path(char *path, size_t len, const char *filename)
{ {
static char saved_brightness[16] = "14"; const char *xdg = getenv("XDG_CONFIG_HOME");
char cur[16] = ""; const char *home = getenv("HOME");
if (xdg && xdg[0])
if (on) { snprintf(path, len, "%s/sxmo/%s", xdg, filename);
read_sysfs_str("/tmp/sxmo_saved_brightness", cur, sizeof(cur)); else if (home && home[0])
if (atoi(cur) > 1) snprintf(path, len, "%s/.config/sxmo/%s", home, filename);
snprintf(saved_brightness, sizeof(saved_brightness), "%s", cur); else
else if (atoi(saved_brightness) <= 1) { snprintf(path, len, "/home/user/.config/sxmo/%s", filename);
read_sysfs_str("/sys/class/backlight/backlight/max_brightness", cur, sizeof(cur));
snprintf(saved_brightness, sizeof(saved_brightness), "%s", (atoi(cur) > 1) ? cur : "14");
} }
write_sysfs_str("/sys/class/backlight/backlight/bl_power", "0");
write_sysfs_str("/sys/class/backlight/backlight/brightness", saved_brightness); static void
write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", "255"); save_brightness_str(const char *val)
} else { {
read_sysfs_str("/sys/class/backlight/backlight/brightness", cur, sizeof(cur)); char line[24], cfgpath[256];
if (atoi(cur) > 1) { int fd, len;
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 (!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) { if (fd >= 0) {
(void)write(fd, saved_brightness, strlen(saved_brightness)); (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); close(fd);
} }
} }
static void
set_hw_backlight(int on)
{
static char saved_brightness[16] = "14";
char cur[16] = "", cfgpath[256];
if (on) {
read_sysfs_str("/tmp/sxmo_saved_brightness", cur, sizeof(cur));
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);
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), "%d", atoi(cur));
save_brightness_str(saved_brightness);
}
write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", "0"); write_sysfs_str("/sys/class/leds/white:kbd_backlight/brightness", "0");
write_sysfs_str("/sys/class/backlight/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 static int
is_phone_locked(void) is_phone_locked(void)
{ {
@@ -1232,6 +1309,10 @@ is_phone_locked(void)
int fd; int fd;
ssize_t n; 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"); snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000");
fd = open(path, O_RDONLY | O_CLOEXEC); fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) if (fd < 0)
@@ -1275,8 +1356,6 @@ writefocusedwin(Client *c)
} }
} }
static int lidfd = -1;
void void
focus(Client *c) 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 void
keypress(XEvent *e) keypress(XEvent *e)
{ {
@@ -1972,26 +2138,43 @@ keypress(XEvent *e)
ev = &e->xkey; ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
if ((keysym == XF86XK_PowerOff || keysym == XF86XK_PickupPhone || if (is_phone_locked()) {
keysym == XF86XK_Phone || keysym == XK_Menu || keysym == XF86XK_Back || wake_phone();
keysym == XK_Return || return;
keysym == XF86XK_KbdLcdMenu1 || keysym == XF86XK_KbdLcdMenu2) && }
is_phone_locked()) { if ((dwm_now_ms() - last_wake_ms) < 350) {
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);
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy); XFlush(dpy);
set_hw_backlight(1);
spawn(&unlockcmd);
return; 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 && if (CLEANMASK(ev->state) == 0 &&
(is_left_softkey(keysym, ev->keycode) || is_right_softkey(keysym, ev->keycode))) { (is_left_softkey(keysym, ev->keycode) || is_right_softkey(keysym, ev->keycode))) {
long long now = dwm_now_ms(); long long now = dwm_now_ms();
@@ -2079,6 +2262,9 @@ keyrelease(XEvent *e)
markreleased(keysym); 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)) { if (is_left_softkey(keysym, ev->keycode) || is_right_softkey(keysym, ev->keycode)) {
return; return;
} }
@@ -2503,9 +2689,9 @@ void
run(void) run(void)
{ {
XEvent ev; XEvent ev;
struct pollfd fds[2]; struct pollfd fds[1 + MAX_INPUT_FDS];
struct input_event ie; struct input_event ie;
int nfds, xfd; int nfds, xfd, i;
/* main event loop */ /* main event loop */
XSync(dpy, False); XSync(dpy, False);
@@ -2523,11 +2709,11 @@ run(void)
fds[0].events = POLLIN; fds[0].events = POLLIN;
fds[0].revents = 0; fds[0].revents = 0;
nfds = 1; nfds = 1;
if (lidfd >= 0) { for (i = 0; i < num_input_fds; i++) {
fds[1].fd = lidfd; fds[nfds].fd = input_fds[i];
fds[1].events = POLLIN; fds[nfds].events = POLLIN;
fds[1].revents = 0; fds[nfds].revents = 0;
nfds = 2; nfds++;
} }
int timeout_ms = -1; int timeout_ms = -1;
if (softkey_pending && softkey_deadline_ms > 0) { if (softkey_pending && softkey_deadline_ms > 0) {
@@ -2546,22 +2732,51 @@ run(void)
timeout_ms = (int)rem; 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 (poll(fds, nfds, timeout_ms) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
break; break;
} }
if (nfds == 2 && (fds[1].revents & POLLIN)) { for (i = 0; i < num_input_fds; i++) {
while (read(lidfd, &ie, sizeof(ie)) == (ssize_t)sizeof(ie)) { 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.type == EV_SW && ie.code == SW_LID) {
if (ie.value == 1) { if (ie.value == 1) {
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff"); lock_phone_screenoff();
set_hw_backlight(0);
spawn(&offcmd);
} else if (ie.value == 0) { } else if (ie.value == 0) {
const Arg oncmd = SHCMD("xset s off s noblank -dpms; sxmo_state.sh set unlock"); wake_phone();
set_hw_backlight(1); }
spawn(&oncmd); } 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; |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask|KeyReleaseMask;
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask); XSelectInput(dpy, root, wa.event_mask);
lidfd = open("/dev/input/by-path/platform-gpio-keys-event", O_RDONLY | O_NONBLOCK | O_CLOEXEC); num_input_fds = 0;
if (lidfd < 0) for (i = 0; i < MAX_INPUT_FDS; i++) {
lidfd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK | O_CLOEXEC); 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_suppress");
unlink("/tmp/sxmo_softkey_state"); unlink("/tmp/sxmo_softkey_state");
load_plugins(); load_plugins();
+23 -2
View File
@@ -357,13 +357,27 @@ class PhoneController {
"Microphone", false, 0, 1, 1, (dec1 > 0) ? 1 : 0}); "Microphone", false, 0, 1, 1, (dec1 > 0) ? 1 : 0});
// 8. Screen brightness (slider 1..screenMax_) // 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); int scrStep = std::max(1, screenMax_ / 14);
items_.push_back({ControlId::ScreenBright, kIconBrightness, kIconBrightness, items_.push_back({ControlId::ScreenBright, kIconBrightness, kIconBrightness,
"Screen", true, 1, screenMax_, scrStep, scrCur}); "Screen", true, 1, screenMax_, scrStep, scrCur});
// 9. Keyboard brightness (slider if max_brightness > 1, toggle otherwise) // 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_) { if (kbdSupportsSlider_) {
int kbdStep = std::max(1, kbdMax_ / 10); int kbdStep = std::max(1, kbdMax_ / 10);
items_.push_back({ControlId::KbdBright, kIconKeyboard, kIconKeyboard, items_.push_back({ControlId::KbdBright, kIconKeyboard, kIconKeyboard,
@@ -593,13 +607,20 @@ class PhoneController {
break; break;
} }
case ControlId::ScreenBright: { case ControlId::ScreenBright: {
std::string cfg = getSxmoCfgDir();
::mkdir(cfg.c_str(), 0755);
writeIntFile(backlightDir_ + "/bl_power", 0); writeIntFile(backlightDir_ + "/bl_power", 0);
writeIntFile(backlightDir_ + "/brightness", it.value); writeIntFile(backlightDir_ + "/brightness", it.value);
writeIntFile("/tmp/sxmo_saved_brightness", it.value); writeIntFile("/tmp/sxmo_saved_brightness", it.value);
writeIntFile(cfg + "/brightness", it.value);
break; break;
} }
case ControlId::KbdBright: { case ControlId::KbdBright: {
int v = kbdSupportsSlider_ ? it.value : (it.value ? kbdMax_ : 0); 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)) { if (!writeIntFile(kbdDir_ + "/brightness", v)) {
char cmd[128]; char cmd[128];
std::snprintf(cmd, sizeof(cmd), std::snprintf(cmd, sizeof(cmd),