diff --git a/overlay/rootfs/etc/doas.d/50-sxmo.conf b/overlay/rootfs/etc/doas.d/50-sxmo.conf index a0fdd93..71967ed 100644 --- a/overlay/rootfs/etc/doas.d/50-sxmo.conf +++ b/overlay/rootfs/etc/doas.d/50-sxmo.conf @@ -37,6 +37,8 @@ permit nopass :wheel as root cmd /usr/bin/sxmo_power.sh permit nopass :wheel as root cmd sxmo_power.sh permit nopass :wheel as root cmd /usr/bin/sxmo_sdcard.sh permit nopass :wheel as root cmd sxmo_sdcard.sh +permit nopass :wheel as root cmd /usr/bin/bananarchy-verify-passcode +permit nopass :wheel as root cmd bananarchy-verify-passcode permit nopass :wheel as root cmd /usr/bin/plymouth args quit permit nopass :wheel as root cmd plymouth args quit permit nopass :wheel as root cmd rc-service args hexagonrpcd-adsp-sensorspd stop diff --git a/overlay/rootfs/usr/bin/bananarchy-verify-passcode b/overlay/rootfs/usr/bin/bananarchy-verify-passcode new file mode 100755 index 0000000..a70711e Binary files /dev/null and b/overlay/rootfs/usr/bin/bananarchy-verify-passcode differ diff --git a/overlay/rootfs/usr/bin/dwm b/overlay/rootfs/usr/bin/dwm index 300e7a7..74c9c45 100755 Binary files a/overlay/rootfs/usr/bin/dwm and b/overlay/rootfs/usr/bin/dwm differ diff --git a/overlay/rootfs/usr/bin/dwm-plugin b/overlay/rootfs/usr/bin/dwm-plugin index 9127587..8fea48a 100755 Binary files a/overlay/rootfs/usr/bin/dwm-plugin and b/overlay/rootfs/usr/bin/dwm-plugin differ diff --git a/overlay/rootfs/usr/bin/sxmo_state.sh b/overlay/rootfs/usr/bin/sxmo_state.sh index 1098188..6187b00 100755 --- a/overlay/rootfs/usr/bin/sxmo_state.sh +++ b/overlay/rootfs/usr/bin/sxmo_state.sh @@ -22,6 +22,21 @@ transition_can_suspend() { transition() { state="$1" + if [ "$state" = "unlock" ] && [ -f /tmp/bananarchy_screen_locked ]; then + state="lock" + printf '%s\n' "$state" > "$SXMO_STATE" + sxmo_wm.sh display on >/dev/null 2>&1 & + xlocker wake >/dev/null 2>&1 & + return 0 + fi + if [ "$state" = "lock" ]; then + printf '1\n' > /tmp/bananarchy_screen_locked + xlocker >/dev/null 2>&1 & + elif [ "$state" = "screenoff" ]; then + printf '1\n' > /tmp/bananarchy_screen_locked + xlocker screenoff >/dev/null 2>&1 & + fi + sxmo_log "transitioning to stage $state" printf '%s\n' "$state" > "$SXMO_STATE" @@ -106,10 +121,16 @@ shift case "$action" in get) read_state + if [ -f /tmp/bananarchy_screen_locked ] && [ "$state" = "unlock" ]; then + state="lock" + fi printf %s "$state" exit 0 ;; is_locked) + if [ -f /tmp/bananarchy_screen_locked ]; then + exit 0 + fi if [ -n "$SXMO_HAS_PEANUTBUTTER" ]; then pidof peanutbutter swaylock waylock i3lock > /dev/null && exit 0 fi diff --git a/overlay/rootfs/usr/bin/xlocker b/overlay/rootfs/usr/bin/xlocker new file mode 120000 index 0000000..e492465 --- /dev/null +++ b/overlay/rootfs/usr/bin/xlocker @@ -0,0 +1 @@ +dwm-plugin \ No newline at end of file diff --git a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so index c9b1d65..01d91dc 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so and b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so index b98a761..bdc7633 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so and b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/camera.so b/overlay/rootfs/usr/lib/dwm/plugins/camera.so index 913e7b4..8ade6f1 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/camera.so and b/overlay/rootfs/usr/lib/dwm/plugins/camera.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so index 6161887..6656268 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so and b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so index 685dd04..28f1fb0 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so and b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so b/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so index 844655f..245001a 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so and b/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/files.so b/overlay/rootfs/usr/lib/dwm/plugins/files.so index 723331b..433bc5b 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/files.so and b/overlay/rootfs/usr/lib/dwm/plugins/files.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/locker.so b/overlay/rootfs/usr/lib/dwm/plugins/locker.so new file mode 100755 index 0000000..bcc2985 Binary files /dev/null and b/overlay/rootfs/usr/lib/dwm/plugins/locker.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/modem.so b/overlay/rootfs/usr/lib/dwm/plugins/modem.so index c7ba3fe..b02f966 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/modem.so and b/overlay/rootfs/usr/lib/dwm/plugins/modem.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/music.so b/overlay/rootfs/usr/lib/dwm/plugins/music.so index 0fbaab2..862c7ad 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/music.so and b/overlay/rootfs/usr/lib/dwm/plugins/music.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/networks.so b/overlay/rootfs/usr/lib/dwm/plugins/networks.so index e91f447..0bf9f06 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/networks.so and b/overlay/rootfs/usr/lib/dwm/plugins/networks.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so b/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so index 358c62f..efdfb9c 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so and b/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/sms.so b/overlay/rootfs/usr/lib/dwm/plugins/sms.so index 163a4d8..f40a8f1 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/sms.so and b/overlay/rootfs/usr/lib/dwm/plugins/sms.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/themes.so b/overlay/rootfs/usr/lib/dwm/plugins/themes.so index e3d9305..1418815 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/themes.so and b/overlay/rootfs/usr/lib/dwm/plugins/themes.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so b/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so index be6a2e4..9ed9e7a 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so and b/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/xdrawer.so b/overlay/rootfs/usr/lib/dwm/plugins/xdrawer.so index e4e0c2a..bd9023b 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/xdrawer.so and b/overlay/rootfs/usr/lib/dwm/plugins/xdrawer.so differ diff --git a/overlay/rootfs/usr/lib/libneoui.so b/overlay/rootfs/usr/lib/libneoui.so index da4872a..7285744 100755 Binary files a/overlay/rootfs/usr/lib/libneoui.so and b/overlay/rootfs/usr/lib/libneoui.so differ diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh index e7954ee..2fa6646 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh @@ -25,15 +25,15 @@ else CURRENT_STATE="$(sxmo_state.sh get)" fi -if [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; then +if [ -f /tmp/bananarchy_screen_locked ] || { [ "$CURRENT_STATE" != "unlock" ] && sxmo_state.sh is_locked; }; then case "$ACTION" in "powerbutton_one"|"powerbutton_two"|"powerbutton_three"|"menuleft_one"|"menuright_one"|"enter_one"|"enter_two"|"enter_three") - if [ -n "$WAYLAND_DISPLAY" ]; then - wlopm --on "*" >/dev/null 2>&1 || sxmo_wm.sh display on + sxmo_wm.sh display on + if [ -f /tmp/bananarchy_screen_locked ]; then + xlocker wake >/dev/null 2>&1 & else - sxmo_wm.sh display on + sxmo_state.sh set unlock & fi - sxmo_state.sh set unlock & exit 0 ;; "voldown_one"|"volup_one") diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh index 0603de4..6aca6c6 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh @@ -2,14 +2,6 @@ # configversion: 70028f54f5d7428d4e3178de5c98978b # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2022 Sxmo Contributors -# -# See man 7 sxmo.states. -# -# This will: -# - blink blue led once -# - turn screen on -# - disable input -# - set up a daemon to automatically transition to screenoff state after 8s. # include common definitions # shellcheck source=scripts/core/sxmo_common.sh @@ -22,30 +14,23 @@ 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 +printf '1\n' > /tmp/bananarchy_screen_locked -[ "$SXMO_WM" = "sway" ] && swaymsg mode default -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 +if [ -z "$SXMO_DISABLE_LEDS" ]; then + sxmo_led.sh blink blue & fi case "$SXMO_WM" in - dwm) - if ! sxmo_jobs.sh running proximity_lock -q; then - sxmo_dmenu.sh close - fi - ;; + dwm) + if ! sxmo_jobs.sh running proximity_lock -q; then + sxmo_dmenu.sh close + fi + xlocker >/dev/null 2>&1 & + ;; esac if [ -z "$SXMO_DISABLE_LEDS" ]; then - sxmo_jobs.sh stop periodic_blink + sxmo_jobs.sh stop periodic_blink fi sxmo_jobs.sh stop periodic_wakelock_check sxmo_jobs.sh stop idle_locker diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_screenoff.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_screenoff.sh index 6b5a380..75b1ba1 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_screenoff.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_screenoff.sh @@ -2,63 +2,40 @@ # configversion: 66b67db06146e3b2dd3ae9a6f1411c5e # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2022 Sxmo Contributors -# -# See man 7 sxmo.states. -# -# This will: -# - turn screen off -# - turn input off -# - launch a demon to blink purple led every 2s -# - check wakelocks and if none suspend after 3s hold # include common definitions # shellcheck source=scripts/core/sxmo_common.sh . sxmo_common.sh -# This hook is called when the system reaches a off state (screen off) +# This hook is called when the system reaches a screenoff 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 +printf '1\n' > /tmp/bananarchy_screen_locked + if [ -z "$SXMO_DISABLE_LEDS" ]; then - sxmo_led.sh blink red blue & -fi - -[ "$SXMO_WM" = "sway" ] && swaymsg mode default -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 - -if [ -z "$SXMO_DISABLE_LEDS" ] && [ ! -e "$XDG_CACHE_HOME"/sxmo/sxmo.nosuspend ]; then - sxmo_jobs.sh start periodic_blink \ - sxmo_run_periodically.sh -w 2 -- sxmo_led.sh blink red blue + sxmo_led.sh blink red blue & fi case "$SXMO_WM" in - dwm) - # dmenu will grab input focus (i.e. power button) so kill it before going to - # screenoff unless proximity lock is running (i.e. there's a phone call). - if ! sxmo_jobs.sh running proximity_lock -q; then - sxmo_dmenu.sh close - fi - ;; + dwm) + if ! sxmo_jobs.sh running proximity_lock -q; then + sxmo_dmenu.sh close + fi + xlocker screenoff >/dev/null 2>&1 & + ;; esac +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 + sxmo_jobs.sh stop idle_locker wait - -case "$SXMO_WM" in - sway) - if [ -n "$SXMO_HAS_PEANUTBUTTER" ] && command -v peanutbutter > /dev/null; then - peanutbutter --font Sxmo --statuscommand sxmo_hook_lockstatusbar.sh && sxmo_hook_statusbar.sh state_change & - fi - ;; -esac diff --git a/prebuilt/sxmo-x11/usr/bin/bananarchy-verify-passcode b/prebuilt/sxmo-x11/usr/bin/bananarchy-verify-passcode new file mode 100755 index 0000000..a70711e Binary files /dev/null and b/prebuilt/sxmo-x11/usr/bin/bananarchy-verify-passcode differ diff --git a/prebuilt/sxmo-x11/usr/bin/dwm b/prebuilt/sxmo-x11/usr/bin/dwm index 300e7a7..74c9c45 100755 Binary files a/prebuilt/sxmo-x11/usr/bin/dwm and b/prebuilt/sxmo-x11/usr/bin/dwm differ diff --git a/prebuilt/sxmo-x11/usr/bin/dwm-plugin b/prebuilt/sxmo-x11/usr/bin/dwm-plugin index 9127587..8fea48a 100755 Binary files a/prebuilt/sxmo-x11/usr/bin/dwm-plugin and b/prebuilt/sxmo-x11/usr/bin/dwm-plugin differ diff --git a/prebuilt/sxmo-x11/usr/bin/xlocker b/prebuilt/sxmo-x11/usr/bin/xlocker new file mode 120000 index 0000000..e492465 --- /dev/null +++ b/prebuilt/sxmo-x11/usr/bin/xlocker @@ -0,0 +1 @@ +dwm-plugin \ No newline at end of file diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so index c9b1d65..01d91dc 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so index b98a761..bdc7633 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so index 913e7b4..8ade6f1 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so index 6161887..6656268 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so index 685dd04..28f1fb0 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so index 844655f..245001a 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so index 723331b..433bc5b 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so new file mode 100755 index 0000000..bcc2985 Binary files /dev/null and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so index c7ba3fe..b02f966 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so index 0fbaab2..862c7ad 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so index e91f447..0bf9f06 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so index 358c62f..efdfb9c 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so index 163a4d8..f40a8f1 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so index e3d9305..1418815 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so index be6a2e4..9ed9e7a 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so index e4e0c2a..bd9023b 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/libneoui.so b/prebuilt/sxmo-x11/usr/lib/libneoui.so index da4872a..7285744 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/libneoui.so and b/prebuilt/sxmo-x11/usr/lib/libneoui.so differ diff --git a/scripts/build-sxmo-x11.sh b/scripts/build-sxmo-x11.sh index 0ff7831..6b06b84 100755 --- a/scripts/build-sxmo-x11.sh +++ b/scripts/build-sxmo-x11.sh @@ -105,8 +105,9 @@ EOF PLUG_INCS="$(pkgconf --cflags x11 xft fontconfig freetype2 pango pangoxft alsa libjpeg libpng) -I/bananarchy/src/neoui" PLUG_LIBS="$(pkgconf --libs x11 xft fontconfig freetype2 pango pangoxft alsa)" MEDIA_LIBS="$(pkgconf --libs libjpeg libpng)" + CXX_PLUG_FLAGS="$OPT_CFLAGS -fPIC -shared -std=c++20 -Wall -Wextra -Wno-psabi" - $CXX $OPT_CFLAGS -fPIC -shared -Wl,-soname,libneoui.so -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS -Wl,-soname,libneoui.so $PLUG_INCS \ /bananarchy/src/neoui/neoui.cpp $PLUG_LIBS $MEDIA_LIBS \ -o /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so cp -f /bananarchy/src/neoui/neoui.h /bananarchy/prebuilt/sxmo-x11/usr/include/neoui.h @@ -116,62 +117,86 @@ EOF echo "[7/7] Compiling DWM Plugins (linked against libneoui.so) and dwm-plugin runner..." mkdir -p /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins + pids="" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/xdrawer/xdrawer.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/xdrawer.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/dialer_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/calllog_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/callscreen_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/contacts_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/sms_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/files_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/files.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/camera_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS -lpthread \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/camera.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/themes_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/themes.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/modem_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/modem.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/networks_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/ringtones_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/wallpapers_plugin.cpp $NEOUI_LIBS $PLUG_LIBS $MEDIA_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so & + pids="$pids $!" - $CXX $OPT_CFLAGS -fPIC -shared -std=c++17 -Wall -Wextra $PLUG_INCS \ + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ /bananarchy/src/dwm-plugins/music_plugin.cpp $NEOUI_LIBS $PLUG_LIBS \ - -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so & + pids="$pids $!" + + $CXX $CXX_PLUG_FLAGS $PLUG_INCS \ + /bananarchy/src/dwm-plugins/locker_plugin.cpp $NEOUI_LIBS $PLUG_LIBS -lcrypt \ + -o /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so & + pids="$pids $!" + + for pid in $pids; do + wait "$pid" + done $STRIP --strip-unneeded \ /bananarchy/prebuilt/sxmo-x11/usr/lib/libneoui.so \ @@ -188,7 +213,8 @@ EOF /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/networks.so \ /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/ringtones.so \ /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/wallpapers.so \ - /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so + /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/music.so \ + /bananarchy/prebuilt/sxmo-x11/usr/lib/dwm/plugins/locker.so $CC $OPT_CFLAGS -std=c99 -D_DEFAULT_SOURCE -Wall -Wextra \ /bananarchy/src/dwm-plugins/dwm_plugin_runner.c -ldl \ @@ -200,8 +226,14 @@ EOF -o /bananarchy/prebuilt/sxmo-x11/usr/bin/sxmo_vibrate $STRIP --strip-unneeded /bananarchy/prebuilt/sxmo-x11/usr/bin/sxmo_vibrate + $CC $OPT_CFLAGS -std=c99 -D_DEFAULT_SOURCE -Wall -Wextra \ + /bananarchy/src/dwm-plugins/verify_passcode.c -lcrypt \ + -o /bananarchy/prebuilt/sxmo-x11/usr/bin/bananarchy-verify-passcode + $STRIP --strip-unneeded /bananarchy/prebuilt/sxmo-x11/usr/bin/bananarchy-verify-passcode + ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/dmenu ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xdmenu + ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xlocker ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xdrawer ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/XDrawer ln -sf dwm-plugin /bananarchy/prebuilt/sxmo-x11/usr/bin/xdialer diff --git a/src/dwm-plugins/dwm_plugin_runner.c b/src/dwm-plugins/dwm_plugin_runner.c index e02b83b..9cf2271 100644 --- a/src/dwm-plugins/dwm_plugin_runner.c +++ b/src/dwm-plugins/dwm_plugin_runner.c @@ -160,7 +160,18 @@ static int try_send_plugin_fifo(const char *plugin_name, int sub_argc, char **su char cmd[256]; int len = 0; - if (strcmp(plugin_name, "xdrawer") == 0) { + if (strcmp(plugin_name, "locker") == 0) { + if (sub_argc >= 2 && sub_argv[1] && + (strcasecmp(sub_argv[1], "screenoff") == 0 || + strcasecmp(sub_argv[1], "blank") == 0)) { + len = snprintf(cmd, sizeof(cmd), "LOCK_BLANK\n"); + } else if (sub_argc >= 2 && sub_argv[1] && + strcasecmp(sub_argv[1], "wake") == 0) { + len = snprintf(cmd, sizeof(cmd), "WAKE\n"); + } else { + len = snprintf(cmd, sizeof(cmd), "LOCK\n"); + } + } else if (strcmp(plugin_name, "xdrawer") == 0) { len = snprintf(cmd, sizeof(cmd), "TOGGLE\n"); } else if (strcmp(plugin_name, "dmenu") == 0 && sub_argc >= 2 && sub_argv[1] && strcmp(sub_argv[1], "close") == 0) { @@ -240,6 +251,9 @@ static const char *resolve_plugin_name_from_argv0(const char *argv0) { if (strcasecmp(base, "dmenu") == 0 || strcasecmp(base, "xdmenu") == 0) { return "dmenu"; } + if (strcasecmp(base, "xlocker") == 0 || strcasecmp(base, "locker") == 0) { + return "locker"; + } if (strcasecmp(base, "xdrawer") == 0) { return "xdrawer"; } @@ -285,6 +299,27 @@ static const char *resolve_plugin_name_from_argv0(const char *argv0) { strcasecmp(base, "xplayer") == 0) { return "music"; } + if (strcasecmp(base, "xsip") == 0 || strcasecmp(base, "sip") == 0) { + return "sip"; + } + if (strcasecmp(base, "xemail") == 0 || strcasecmp(base, "xmail") == 0 || + strcasecmp(base, "email") == 0) { + return "email"; + } + if (strcasecmp(base, "xirc") == 0 || strcasecmp(base, "irc") == 0) { + return "irc"; + } + if (strcasecmp(base, "xtox") == 0 || strcasecmp(base, "tox") == 0) { + return "tox"; + } + if (strcasecmp(base, "xkopher") == 0 || strcasecmp(base, "xsmallweb") == 0 || + strcasecmp(base, "smallweb") == 0) { + return "smallweb"; + } + if (strcasecmp(base, "xgps") == 0 || strcasecmp(base, "xmaps") == 0 || + strcasecmp(base, "gps") == 0) { + return "gps"; + } return NULL; } @@ -377,6 +412,20 @@ int main(int argc, char **argv) { sub_argv = argv + 1; } + if (access("/tmp/bananarchy_screen_locked", F_OK) == 0 && + strcmp(plugin_name, "locker") != 0 && + strcmp(plugin_name, "callscreen") != 0) { + const char *a1 = (sub_argc >= 2 && sub_argv[1]) ? sub_argv[1] : ""; + if (strcmp(a1, "--preload") != 0 && + strcmp(a1, "close") != 0 && + strcmp(a1, "-v") != 0 && + strcmp(a1, "isopen") != 0 && + strcmp(a1, "--apply") != 0 && + strcmp(a1, "--export-default") != 0) { + return 1; + } + } + if (strcmp(plugin_name, "dmenu") == 0) { if (sub_argc >= 2 && sub_argv[1]) { if (strcmp(sub_argv[1], "-v") == 0) { diff --git a/src/dwm-plugins/locker_plugin.cpp b/src/dwm-plugins/locker_plugin.cpp new file mode 100644 index 0000000..fce1364 --- /dev/null +++ b/src/dwm-plugins/locker_plugin.cpp @@ -0,0 +1,865 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Fullscreen Passcode Phone Locker DWM Plugin (240x320) +// Verifies numeric passcode against the current user's shadow password hash +// and blocks all keypad, softkey, and power-button bypasses while locked. + +#include +#include +#include +#include +#include +#include +#ifndef _EVDEVK +#define _EVDEVK(_v) (0x10081000 + (_v)) +#endif +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../sxmo-dwm/dwm_plugin.h" +#include "phone_data.h" + +namespace { + +using namespace bananarchy; + +constexpr const char* kLockFlagPath = "/tmp/bananarchy_screen_locked"; + +volatile sig_atomic_t gRunning = 1; + +void handleSignal(int) { + // Ignore termination signals while the phone is locked so the locker cannot be killed + if (::access(kLockFlagPath, F_OK) == 0) { + return; + } + gRunning = 0; +} + +std::string readSmallFileTrimmed(const char* path) { + int fd = ::open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) { + return ""; + } + char buf[256]; + ssize_t n = ::read(fd, buf, sizeof(buf) - 1); + ::close(fd); + if (n <= 0) { + return ""; + } + while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r' || buf[n - 1] == ' ')) { + --n; + } + buf[n] = '\0'; + return std::string(buf); +} + +void writeSmallFileStr(const char* path, const char* val) { + int fd = ::open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd >= 0) { + (void)::write(fd, val, std::strlen(val)); + ::close(fd); + } +} + +void writeSysfsStr(const char* path, const char* val) { + int fd = ::open(path, O_WRONLY | O_CLOEXEC); + if (fd >= 0) { + (void)::write(fd, val, std::strlen(val)); + ::close(fd); + } +} + +bool isScreenBlanked() { + std::string br = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness"); + return (!br.empty() && std::atoi(br.c_str()) <= 0); +} + +void blankScreenBacklight() { + std::string cur = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness"); + if (!cur.empty() && std::atoi(cur.c_str()) >= 1) { + std::string line = std::to_string(std::atoi(cur.c_str())) + "\n"; + writeSmallFileStr("/tmp/sxmo_saved_brightness", line.c_str()); + } + writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", "0"); + writeSysfsStr("/sys/class/backlight/backlight/brightness", "0"); +} + +void wakeScreenBacklight() { + std::string cur = readSmallFileTrimmed("/tmp/sxmo_saved_brightness"); + int val = std::atoi(cur.c_str()); + if (val < 1) { + std::string cfgPath = getHomeDir() + "/.config/sxmo/brightness"; + cur = readSmallFileTrimmed(cfgPath.c_str()); + val = std::atoi(cur.c_str()); + } + if (val < 1) { + val = 14; + } + std::string valStr = std::to_string(val); + writeSysfsStr("/sys/class/backlight/backlight/bl_power", "0"); + writeSysfsStr("/sys/class/backlight/backlight/brightness", valStr.c_str()); + + std::string kbd = readSmallFileTrimmed("/tmp/sxmo_saved_kbd_brightness"); + if (kbd.empty()) { + std::string kbdCfg = getHomeDir() + "/.config/sxmo/kbd_brightness"; + kbd = readSmallFileTrimmed(kbdCfg.c_str()); + } + writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", + kbd.empty() ? "255" : kbd.c_str()); +} + +void setSxmoStateFile(const char* st) { + std::string path = getRuntimeFile("sxmo.state"); + std::string content = std::string(st) + "\n"; + writeSmallFileStr(path.c_str(), content.c_str()); +} + +bool constantTimeEq(const std::string& a, const std::string& b) { + if (a.empty() || a.size() != b.size()) { + return false; + } + unsigned char diff = 0; + for (size_t i = 0; i < a.size(); ++i) { + diff |= static_cast(a[i] ^ b[i]); + } + return diff == 0; +} + +class PasscodeVerifier { + public: + void refreshIfNeeded() { + struct stat st {}; + if (::stat("/etc/shadow", &st) == 0) { + if (!cachedHash_.empty() && st.st_mtim.tv_sec == shadowMtime_ && + st.st_size == shadowSize_) { + return; + } + shadowMtime_ = st.st_mtim.tv_sec; + shadowSize_ = st.st_size; + } + int pipefd[2]; + if (::pipe(pipefd) != 0) { + return; + } + pid_t pid = ::fork(); + if (pid == 0) { + ::close(pipefd[0]); + ::dup2(pipefd[1], STDOUT_FILENO); + int nullfd = ::open("/dev/null", O_RDWR); + if (nullfd >= 0) { + ::dup2(nullfd, STDIN_FILENO); + ::dup2(nullfd, STDERR_FILENO); + if (nullfd > 2) { + ::close(nullfd); + } + } + if (pipefd[1] > 2) { + ::close(pipefd[1]); + } + ::execl("/usr/bin/doas", "doas", "-n", + "/usr/bin/bananarchy-verify-passcode", "--print-hash", "user", + static_cast(nullptr)); + ::_exit(1); + } + ::close(pipefd[1]); + char buf[256]; + ssize_t n = ::read(pipefd[0], buf, sizeof(buf) - 1); + ::close(pipefd[0]); + int status = 0; + if (pid > 0) { + ::waitpid(pid, &status, 0); + } + if (n > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) { + while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) { + --n; + } + buf[n] = '\0'; + if (buf[0] == '$') { + cachedHash_ = buf; + } + } + } + + bool verify(const std::string& candidate) { + if (candidate.empty()) { + return false; + } + refreshIfNeeded(); + if (!cachedHash_.empty()) { + char* res = ::crypt(candidate.c_str(), cachedHash_.c_str()); + if (res && constantTimeEq(res, cachedHash_)) { + return true; + } + return false; + } + // Fallback to helper binary via stdin + int pipefd[2]; + if (::pipe(pipefd) != 0) { + return false; + } + pid_t pid = ::fork(); + if (pid == 0) { + ::close(pipefd[1]); + ::dup2(pipefd[0], STDIN_FILENO); + int nullfd = ::open("/dev/null", O_WRONLY); + if (nullfd >= 0) { + ::dup2(nullfd, STDOUT_FILENO); + ::dup2(nullfd, STDERR_FILENO); + if (nullfd > 2) { + ::close(nullfd); + } + } + if (pipefd[0] > 2) { + ::close(pipefd[0]); + } + ::execl("/usr/bin/doas", "doas", "-n", + "/usr/bin/bananarchy-verify-passcode", "user", + static_cast(nullptr)); + ::_exit(1); + } + ::close(pipefd[0]); + std::string line = candidate + "\n"; + (void)::write(pipefd[1], line.data(), line.size()); + ::close(pipefd[1]); + int status = 0; + if (pid > 0 && ::waitpid(pid, &status, 0) > 0) { + return WIFEXITED(status) && WEXITSTATUS(status) == 0; + } + return false; + } + + private: + std::string cachedHash_; + time_t shadowMtime_ = 0; + off_t shadowSize_ = 0; +}; + +int countNotifFiles() { + std::string notifDir = getRuntimeFile("sxmo_notifications"); + DIR* d = ::opendir(notifDir.c_str()); + if (!d) { + return 0; + } + int count = 0; + struct dirent* ent; + while ((ent = ::readdir(d)) != nullptr) { + if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') { + ++count; + } + } + ::closedir(d); + return count; +} + +int locker_run_main(int argc, char** argv) { + gRunning = 1; + bool isPreload = false; + std::string initCmd = "LOCK"; + + for (int i = 1; i < argc; ++i) { + if (!argv[i]) { + continue; + } + if (std::strcmp(argv[i], "--preload") == 0) { + isPreload = true; + } else if (strcasecmp(argv[i], "lock") == 0 || + strcasecmp(argv[i], "open") == 0) { + initCmd = "LOCK"; + } else if (strcasecmp(argv[i], "screenoff") == 0 || + strcasecmp(argv[i], "blank") == 0) { + initCmd = "LOCK_BLANK"; + } else if (strcasecmp(argv[i], "wake") == 0) { + initCmd = "WAKE"; + } else if (strcasecmp(argv[i], "status") == 0 || + strcasecmp(argv[i], "islocked") == 0) { + return (::access(kLockFlagPath, F_OK) == 0) ? 0 : 1; + } + } + + if (sendPluginCommand("locker", isPreload ? "NOP" : initCmd)) { + return 0; + } + + std::string daemonPidPath = getPluginDaemonPidPath("locker"); + std::string activePidPath = getRuntimeFile("xlocker.pid"); + writeIntFile(daemonPidPath, static_cast(::getpid())); + int fifoFd = setupPluginDaemonFifo("locker"); + + struct sigaction sa {}; + sa.sa_handler = handleSignal; + sigemptyset(&sa.sa_mask); + sigaction(SIGTERM, &sa, nullptr); + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGHUP, &sa, nullptr); + + NeoWindow neo; + if (!neo.create("xlocker", "XLocker", "Phone Lock", + 0, 0, kScreenWidth, kScreenHeight, true, + ExposureMask | KeyPressMask | KeyReleaseMask | + VisibilityChangeMask | FocusChangeMask | StructureNotifyMask)) { + if (fifoFd >= 0) { + ::close(fifoFd); + } + ::unlink(daemonPidPath.c_str()); + return 1; + } + + Display* dpy = neo.dpy; + Window win = neo.win; + Pixmap pix = neo.pix; + GC gc = neo.gc; + PangoLayout* layoutNum = neo.layoutNum; + PangoLayout* layoutMain = neo.layoutMain; + PangoLayout* layoutSmall = neo.layoutSmall; + PangoLayout* layoutIcon = neo.layoutIcon; + PluginTheme& theme = neo.theme; + + // Create an extra-large clock layout + PangoLayout* layoutClock = pango_layout_new(neo.pangoCtx); + auto updateClockFont = [&]() { + int clockPx = std::max(28, theme.spec.baseFontSize * 2 + 6); + std::string fontDescStr = + theme.spec.fontFace + " Bold " + std::to_string(clockPx) + "px"; + PangoFontDescription* fd = + pango_font_description_from_string(fontDescStr.c_str()); + pango_layout_set_font_description(layoutClock, fd); + pango_font_description_free(fd); + }; + updateClockFont(); + + PasscodeVerifier verifier; + verifier.refreshIfNeeded(); + + bool visible = false; + bool grabHeld = false; + std::string passcode; + std::string statusMsg; + bool statusIsError = false; + int failedAttempts = 0; + int64_t cooldownUntilMs = 0; + int64_t statusClearAtMs = 0; + int64_t lockActivatedMs = 0; + + auto grabLockerInput = [&]() { + if (!visible || isCallActiveOrRingingFast()) { + return; + } + XRaiseWindow(dpy, win); + XSetInputFocus(dpy, win, RevertToParent, CurrentTime); + for (int attempt = 0; attempt < 5; ++attempt) { + if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync, + CurrentTime) == GrabSuccess) { + grabHeld = true; + break; + } + ::usleep(10000); + } + XGrabPointer(dpy, win, True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + XFlush(dpy); + }; + + auto releaseLockerGrab = [&]() { + if (grabHeld) { + XUngrabKeyboard(dpy, CurrentTime); + XUngrabPointer(dpy, CurrentTime); + grabHeld = false; + XFlush(dpy); + } + }; + + auto closeOtherOverlays = [&]() { + sendPluginCommand("dmenu", "CLOSE"); + sendPluginCommand("xdrawer", "CLOSE"); + ::unlink("/tmp/dwm_plugin_dmenu.active"); + }; + + auto render = [&]() { + if (!visible || isScreenBlanked()) { + return; + } + + int64_t now = nowMs(); + if (statusClearAtMs > 0 && now >= statusClearAtMs && cooldownUntilMs <= now) { + statusMsg.clear(); + statusIsError = false; + statusClearAtMs = 0; + } + + // Background fill + XSetForeground(dpy, gc, theme.spec.bgMain); + XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, kScreenHeight); + + // Top bar strip (24px) + XSetForeground(dpy, gc, theme.spec.bgHeader); + XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, 24); + XSetForeground(dpy, gc, theme.spec.border); + XDrawLine(dpy, pix, gc, 0, 23, kScreenWidth, 23); + + neo.drawPango(layoutIcon, &theme.colYellow, 8, 0, 24, kIconLock); + neo.drawPango(layoutSmall, &theme.colLight, 26, 0, 24, "Locked"); + + std::string cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity"); + std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status"); + std::string batText = cap.empty() ? "" : (cap + "%"); + if (batStatus == "Charging") { + batText = std::string(kIconFlash) + " " + batText; + } + if (!batText.empty()) { + int bw = neo.pangoWidth(layoutSmall, batText); + XftColor* batCol = (std::atoi(cap.c_str()) <= 15 && batStatus != "Charging") + ? &theme.colRed + : &theme.colMuted; + neo.drawPango(layoutSmall, batCol, kScreenWidth - bw - 8, 0, 24, batText); + } + + // Current time and date + std::time_t t = std::time(nullptr); + struct tm tmNow {}; + localtime_r(&t, &tmNow); + char timeBuf[32]; + char dateBuf[64]; + std::strftime(timeBuf, sizeof(timeBuf), "%H:%M", &tmNow); + std::strftime(dateBuf, sizeof(dateBuf), "%a, %b %d", &tmNow); + + neo.drawPango(layoutClock, &theme.colWhite, 0, 34, 42, timeBuf, + kScreenWidth, 1); + neo.drawPango(layoutMain, &theme.colMuted, 0, 78, 22, dateBuf, + kScreenWidth, 1); + + // Notification badge (count only, no private content exposed on lockscreen) + int notifCount = countNotifFiles(); + if (notifCount > 0) { + std::string nstr = std::string(kIconBell) + " " + + std::to_string(notifCount) + + (notifCount == 1 ? " notification" : " notifications"); + int pillW = std::min(200, neo.pangoWidth(layoutSmall, nstr) + 20); + int pillX = (kScreenWidth - pillW) / 2; + XSetForeground(dpy, gc, theme.spec.bgAltOdd); + XFillRectangle(dpy, pix, gc, pillX, 105, pillW, 22); + XSetForeground(dpy, gc, theme.spec.border); + XDrawRectangle(dpy, pix, gc, pillX, 105, pillW - 1, 21); + neo.drawPango(layoutSmall, &theme.colYellow, pillX, 105, 22, nstr, + pillW, 1); + } + + // Passcode entry card + int cardX = 18; + int cardY = 136; + int cardW = kScreenWidth - 36; + int cardH = 54; + bool inCooldown = (cooldownUntilMs > now); + + uint32_t boxBg = theme.spec.bgInput; + uint32_t boxBorder = statusIsError ? theme.spec.danger + : (passcode.empty() ? theme.spec.border + : theme.spec.selBg); + XSetForeground(dpy, gc, boxBg); + XFillRectangle(dpy, pix, gc, cardX, cardY, cardW, cardH); + XSetForeground(dpy, gc, boxBorder); + XDrawRectangle(dpy, pix, gc, cardX, cardY, cardW - 1, cardH - 1); + if (!passcode.empty() || statusIsError) { + XDrawRectangle(dpy, pix, gc, cardX + 1, cardY + 1, cardW - 3, cardH - 3); + } + + std::string labelStr = std::string(kIconKey) + " Enter Passcode"; + neo.drawPango(layoutSmall, &theme.colMuted, cardX, cardY + 4, 18, + labelStr, cardW, 1); + + if (inCooldown) { + int remSec = static_cast((cooldownUntilMs - now + 999) / 1000); + std::string waitStr = "Locked out (" + std::to_string(remSec) + "s)"; + neo.drawPango(layoutMain, &theme.colRed, cardX + 6, cardY + 24, 24, + waitStr, cardW - 12, 1); + } else if (!passcode.empty()) { + std::string masked; + for (size_t i = 0; i < passcode.size(); ++i) { + if (i > 0) { + masked += ' '; + } + masked += '*'; + } + neo.drawPango(layoutNum, &theme.colYellow, cardX + 6, cardY + 22, 26, + masked, cardW - 12, 1); + } else if (!statusMsg.empty()) { + XftColor* stCol = statusIsError ? &theme.colRed : &theme.colLight; + neo.drawPango(layoutMain, stCol, cardX + 6, cardY + 24, 24, + statusMsg, cardW - 12, 1); + } else { + neo.drawPango(layoutSmall, &theme.colMuted, cardX + 6, cardY + 25, 22, + "Type 0-9 on keypad", cardW - 12, 1); + } + + // Visual keypad grid hint / status panel + int infoX = 18; + int infoY = 202; + int infoW = kScreenWidth - 36; + int infoH = 74; + XSetForeground(dpy, gc, theme.spec.bgAltEven); + XFillRectangle(dpy, pix, gc, infoX, infoY, infoW, infoH); + XSetForeground(dpy, gc, theme.spec.border); + XDrawRectangle(dpy, pix, gc, infoX, infoY, infoW - 1, infoH - 1); + + neo.drawPango(layoutSmall, &theme.colLight, infoX + 8, infoY + 8, 18, + std::string(kIconShield) + " Device Protected", + infoW - 16, 1); + neo.drawPango(layoutSmall, &theme.colMuted, infoX + 8, infoY + 30, 18, + "Enter user numeric password", infoW - 16, 1); + neo.drawPango(layoutSmall, &theme.colMuted, infoX + 8, infoY + 48, 18, + "End/Power: turn screen off", infoW - 16, 1); + + // Bottom softkey bar (Y=294..320) + neo.drawSoftbar("Unlock", "OK", + passcode.empty() ? "Sleep" : "Clear", + &theme.colYellow); + + neo.present(); + }; + + auto unlockPhone = [&]() { + passcode.clear(); + statusMsg.clear(); + statusIsError = false; + failedAttempts = 0; + cooldownUntilMs = 0; + ::unlink(kLockFlagPath); + ::unlink(activePidPath.c_str()); + releaseLockerGrab(); + if (visible) { + XUnmapWindow(dpy, win); + XFlush(dpy); + visible = false; + } + writeSoftkeySuppress(nowMs() + 350); + setSxmoStateFile("unlock"); + wakeScreenBacklight(); + runAsyncCmd("sxmo_hook_unlock.sh >/dev/null 2>&1"); + }; + + auto lockPhone = [&](bool blankDisplay) { + writeSmallFileStr(kLockFlagPath, "1\n"); + writeIntFile(activePidPath, static_cast(::getpid())); + closeOtherOverlays(); + verifier.refreshIfNeeded(); + passcode.clear(); + statusMsg.clear(); + statusIsError = false; + lockActivatedMs = nowMs(); + writeSoftkeySuppress(lockActivatedMs + 400); + if (!visible) { + XMapRaised(dpy, win); + XMoveResizeWindow(dpy, win, 0, 0, kScreenWidth, kScreenHeight); + visible = true; + } + grabLockerInput(); + if (blankDisplay) { + setSxmoStateFile("screenoff"); + blankScreenBacklight(); + } else { + setSxmoStateFile("lock"); + wakeScreenBacklight(); + render(); + } + }; + + auto submitPasscode = [&](bool explicitSubmit) { + int64_t now = nowMs(); + if (cooldownUntilMs > now) { + render(); + return; + } + if (passcode.empty()) { + if (explicitSubmit) { + statusMsg = "Enter passcode"; + statusIsError = false; + statusClearAtMs = now + 1500; + render(); + } + return; + } + if (verifier.verify(passcode)) { + unlockPhone(); + return; + } + if (explicitSubmit || passcode.size() >= 12) { + passcode.clear(); + ++failedAttempts; + statusIsError = true; + runAsyncCmd("sxmo_vibrate 80 >/dev/null 2>&1"); + if (failedAttempts >= 5) { + cooldownUntilMs = now + 10000; + statusMsg = "Locked out (10s)"; + statusClearAtMs = cooldownUntilMs; + } else { + statusMsg = "Wrong passcode"; + statusClearAtMs = now + 1800; + } + render(); + } + }; + + if (!isPreload) { + lockPhone(initCmd == "LOCK_BLANK"); + } else if (::access(kLockFlagPath, F_OK) == 0) { + lockPhone(isScreenBlanked()); + } + + int xfd = ConnectionNumber(dpy); + bool callWasActive = false; + + while (gRunning) { + if (fifoFd >= 0) { + for (const std::string& cmd : readFifoLines(fifoFd)) { + if (cmd == "NOP") { + continue; + } + if (cmd == "RELOAD_THEME") { + neo.reloadTheme(); + updateClockFont(); + if (visible) { + render(); + } + continue; + } + if (cmd == "LOCK" || cmd == "OPEN" || cmd.rfind("OPEN ", 0) == 0) { + if (cmd == "OPEN screenoff" || cmd == "OPEN blank") { + lockPhone(true); + } else { + lockPhone(false); + } + continue; + } + if (cmd == "LOCK_BLANK" || cmd == "SCREENOFF" || cmd == "BLANK") { + lockPhone(true); + continue; + } + if (cmd == "WAKE") { + if (::access(kLockFlagPath, F_OK) == 0 || visible) { + if (!visible) { + lockPhone(false); + } else { + closeOtherOverlays(); + wakeScreenBacklight(); + grabLockerInput(); + render(); + } + } + continue; + } + if (cmd.rfind("VERIFY ", 0) == 0) { + std::string code = trimStr(cmd.substr(7)); + if (cooldownUntilMs <= nowMs() && verifier.verify(code)) { + unlockPhone(); + } else { + passcode.clear(); + ++failedAttempts; + statusIsError = true; + if (failedAttempts >= 5) { + cooldownUntilMs = nowMs() + 10000; + statusMsg = "Locked out (10s)"; + statusClearAtMs = cooldownUntilMs; + } else { + statusMsg = "Wrong passcode"; + statusClearAtMs = nowMs() + 1800; + } + if (visible) { + render(); + } + } + continue; + } + // Ignore CLOSE while locked so external scripts cannot dismiss the lockscreen + } + } + + if (visible) { + if (neo.checkReloadTheme()) { + updateClockFont(); + render(); + } + bool callNow = isCallActiveOrRingingFast(); + if (callNow && !callWasActive) { + releaseLockerGrab(); + } else if (!callNow && callWasActive) { + grabLockerInput(); + render(); + } else if (!callNow && !grabHeld) { + grabLockerInput(); + } + callWasActive = callNow; + } + + while (XPending(dpy) > 0) { + XEvent ev; + XNextEvent(dpy, &ev); + if (ev.type == Expose) { + if (visible && ev.xexpose.count == 0) { + render(); + } + } else if (ev.type == VisibilityNotify || ev.type == FocusOut || + ev.type == UnmapNotify) { + if (visible && ::access(kLockFlagPath, F_OK) == 0 && + !isCallActiveOrRingingFast()) { + if (ev.type == UnmapNotify) { + XMapRaised(dpy, win); + } + grabLockerInput(); + render(); + } + } else if (ev.type == KeyPress) { + if (!visible) { + continue; + } + int64_t now = nowMs(); + if (isScreenBlanked()) { + wakeScreenBacklight(); + lockActivatedMs = now; + render(); + continue; + } + if (now - lockActivatedMs < 180) { + continue; + } + + unsigned int kc = ev.xkey.keycode; + KeySym sym = XLookupKeysym(&ev.xkey, 0); + + // Power / End Call / Sleep button blanks the screen while remaining locked + if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep || + sym == XF86XK_Standby || sym == XF86XK_Suspend || + sym == XF86XK_HangupPhone || sym == XK_Cancel || + sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) || + sym == XK_Escape) { + passcode.clear(); + statusMsg.clear(); + statusIsError = false; + setSxmoStateFile("screenoff"); + blankScreenBacklight(); + continue; + } + + // Left softkey: explicit Unlock attempt + if (isLeftSoftkey(sym, kc)) { + submitPasscode(true); + continue; + } + + // Right softkey: Clear last digit, or blank screen if empty + if (isRightSoftkey(sym, kc)) { + if (!passcode.empty()) { + passcode.pop_back(); + render(); + } else { + setSxmoStateFile("screenoff"); + blankScreenBacklight(); + } + continue; + } + + // Backspace / Left arrow: delete last digit + if (sym == XK_BackSpace || sym == XK_Delete || + sym == XK_Left || sym == XK_KP_Left) { + if (!passcode.empty()) { + passcode.pop_back(); + render(); + } + continue; + } + + // Enter / Center OK / Call / Pound (#): explicit Unlock attempt + if (sym == XK_Return || sym == XK_KP_Enter || + sym == XF86XK_Phone || sym == XF86XK_PickupPhone || + sym == XF86XK_Send || isPoundKey(sym, kc)) { + submitPasscode(true); + continue; + } + + // Numeric digits 0-9 + char ch = mapDialKey(sym, kc, ev.xkey.state); + if (ch >= '0' && ch <= '9') { + if (cooldownUntilMs > now) { + render(); + continue; + } + if (passcode.size() < 32) { + passcode.push_back(ch); + statusMsg.clear(); + statusIsError = false; + render(); + if (passcode.size() >= 4) { + submitPasscode(false); + } + } + continue; + } + } + } + + if (visible && !isScreenBlanked()) { + render(); + } + + int timeoutMs = -1; + if (visible) { + if (isScreenBlanked()) { + timeoutMs = 2000; + } else if (cooldownUntilMs > nowMs()) { + timeoutMs = 250; + } else { + timeoutMs = 1000; + } + } + + struct pollfd pfds[2] {}; + pfds[0].fd = xfd; + pfds[0].events = POLLIN; + pfds[1].fd = fifoFd; + pfds[1].events = POLLIN; + ::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs); + } + + g_object_unref(layoutClock); + releaseLockerGrab(); + if (fifoFd >= 0) { + ::close(fifoFd); + } + ::unlink(getPluginFifoPath("locker").c_str()); + ::unlink(daemonPidPath.c_str()); + return 0; +} + +int locker_plugin_init(const DwmHostApi* host) { + if (host && host->spawn_plugin) { + host->spawn_plugin("locker", "--preload"); + } + return 0; +} + +} // namespace + +extern "C" __attribute__((visibility("default"))) const DwmPlugin dwm_plugin_entry = { + DWM_PLUGIN_API_VERSION, + "locker", + "Fullscreen numeric passcode phone locker verified against shadow password", + locker_plugin_init, + nullptr, + nullptr, + nullptr, + nullptr, + locker_run_main +}; diff --git a/src/dwm-plugins/phone_data.h b/src/dwm-plugins/phone_data.h index bde53be..6926493 100644 --- a/src/dwm-plugins/phone_data.h +++ b/src/dwm-plugins/phone_data.h @@ -480,6 +480,32 @@ inline char mapDialKey(KeySym sym, unsigned int keycode, unsigned int state) { return '\0'; } +inline bool isLeftSoftkey(KeySym sym, unsigned int keycode) { + return sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 || keycode == 135; +} + +inline bool isRightSoftkey(KeySym sym, unsigned int keycode) { + return sym == XF86XK_Back || sym == XF86XK_KbdLcdMenu2 || keycode == 166; +} + +inline bool isStarKey(KeySym sym, unsigned int keycode) { + return keycode == 63 || keycode == 530 || sym == XK_asterisk || + sym == XK_KP_Multiply || static_cast(sym) == 0x1008ffaa; +} + +inline bool isPoundKey(KeySym sym, unsigned int keycode) { + return keycode == 106 || keycode == 531 || sym == XK_numbersign || + sym == XK_KP_Divide || static_cast(sym) == 0x1008ffab; +} + +inline std::string getHomeDir() { + return getHomeDirPath(); +} + +inline bool isPhonePasscodeLocked() { + return ::access("/tmp/bananarchy_screen_locked", F_OK) == 0; +} + inline std::string trimStr(const std::string& s) { size_t b = 0; while (b < s.size() && std::isspace(static_cast(s[b]))) { @@ -1794,6 +1820,12 @@ inline void closeOtherPlugins(const char* selfPluginName) { {"xringtones.pid", "ringtones"}, {"xwallpapers.pid", "wallpapers"}, {"xmusic.pid", "music"}, + {"xsip.pid", "sip"}, + {"xemail.pid", "email"}, + {"xirc.pid", "irc"}, + {"xtox.pid", "tox"}, + {"xsmallweb.pid", "smallweb"}, + {"xgps.pid", "gps"}, }; for (const auto& p : kAllPlugins) { if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) { @@ -1815,6 +1847,7 @@ inline bool isAnotherPluginActive(const char* selfPluginName) { const char* name; }; static const PluginRef kAllPlugins[] = { + {"xlocker.pid", "locker"}, {"xdrawer.pid", "xdrawer"}, {"xdialer.pid", "dialer"}, {"xcalllog.pid", "calllog"}, @@ -1829,6 +1862,12 @@ inline bool isAnotherPluginActive(const char* selfPluginName) { {"xringtones.pid", "ringtones"}, {"xwallpapers.pid", "wallpapers"}, {"xmusic.pid", "music"}, + {"xsip.pid", "sip"}, + {"xemail.pid", "email"}, + {"xirc.pid", "irc"}, + {"xtox.pid", "tox"}, + {"xsmallweb.pid", "smallweb"}, + {"xgps.pid", "gps"}, }; for (const auto& p : kAllPlugins) { if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) { @@ -1859,6 +1898,7 @@ inline void grabPluginKeyboard(Display* dpy, Window win) { inline void broadcastThemeReload(const char* selfPluginName = nullptr) { static const char* kPlugins[] = { "dmenu", + "locker", "xdrawer", "dialer", "calllog", @@ -1873,6 +1913,12 @@ inline void broadcastThemeReload(const char* selfPluginName = nullptr) { "ringtones", "wallpapers", "music", + "sip", + "email", + "irc", + "tox", + "smallweb", + "gps", }; for (const char* name : kPlugins) { if (selfPluginName && std::strcmp(name, selfPluginName) == 0) { diff --git a/src/dwm-plugins/verify_passcode.c b/src/dwm-plugins/verify_passcode.c new file mode 100644 index 0000000..967a2cd --- /dev/null +++ b/src/dwm-plugins/verify_passcode.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Bananarchy shadow passcode verifier for the fullscreen phone locker. + +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#endif +#include +#include +#include +#include +#include +#include +#include + +static int constant_time_eq(const char *a, const char *b) { + if (!a || !b) { + return 0; + } + size_t la = strlen(a); + size_t lb = strlen(b); + if (la == 0 || la != lb) { + return 0; + } + unsigned char diff = 0; + for (size_t i = 0; i < la; ++i) { + diff |= (unsigned char)(a[i] ^ b[i]); + } + return diff == 0; +} + +int main(int argc, char **argv) { + int print_hash = 0; + const char *username = "user"; + + for (int i = 1; i < argc; ++i) { + if (strcmp(argv[i], "--print-hash") == 0) { + print_hash = 1; + } else if (argv[i][0] != '-') { + username = argv[i]; + } + } + + if (strcmp(username, "user") != 0 && strcmp(username, "root") != 0) { + return 2; + } + + struct spwd *sp = getspnam(username); + const char *hash = (sp && sp->sp_pwdp) ? sp->sp_pwdp : NULL; + if (!hash || !hash[0]) { + struct passwd *pw = getpwnam(username); + hash = (pw && pw->pw_passwd) ? pw->pw_passwd : NULL; + } + if (!hash || !hash[0] || hash[0] == '!' || hash[0] == '*') { + return 1; + } + + if (print_hash) { + puts(hash); + return 0; + } + + char pass[128]; + if (!fgets(pass, sizeof(pass), stdin)) { + return 1; + } + size_t len = strlen(pass); + while (len > 0 && (pass[len - 1] == '\n' || pass[len - 1] == '\r')) { + pass[--len] = '\0'; + } + if (len == 0) { + return 1; + } + + char *calc = crypt(pass, hash); + memset(pass, 0, sizeof(pass)); + if (!calc) { + return 1; + } + return constant_time_eq(calc, hash) ? 0 : 1; +} diff --git a/src/neoui/neoui.cpp b/src/neoui/neoui.cpp index 6c8b416..647b5a2 100644 --- a/src/neoui/neoui.cpp +++ b/src/neoui/neoui.cpp @@ -1772,9 +1772,9 @@ int neoui_apply_theme_file(const char* xth_path) { int neoui_broadcast_theme_reload(const char* skip_plugin) { const char* kPlugins[] = { - "dmenu", "xdrawer", "dialer", "calllog", "callscreen", "contacts", + "dmenu", "locker", "xdrawer", "dialer", "calllog", "callscreen", "contacts", "sms", "files", "camera", "themes", "modem", "networks", "ringtones", - "wallpapers", "music" + "wallpapers", "music", "sip", "email", "irc", "tox", "smallweb", "gps" }; std::string skip = (skip_plugin && skip_plugin[0]) ? skip_plugin : ""; for (const char* p : kPlugins) { diff --git a/src/sxmo-dmenu/dmenu.c b/src/sxmo-dmenu/dmenu.c index 30c3edf..bafe18d 100644 --- a/src/sxmo-dmenu/dmenu.c +++ b/src/sxmo-dmenu/dmenu.c @@ -2694,9 +2694,9 @@ open_builtin_menu(const char *menu_name, int keep_idx) reset_session_defaults(1, "Power"); append_active_call_entries(); snprintf(label, sizeof(label), "%s Lock", ICON_LCK); - add_menu_item(label, "sxmo_state.sh set lock", 0); + add_menu_item(label, "@plugin:locker", 0); snprintf(label, sizeof(label), "%s Lock (Screen off)", ICON_LCK); - add_menu_item(label, "sxmo_state.sh set screenoff", 0); + add_menu_item(label, "@plugin:locker:screenoff", 0); snprintf(label, sizeof(label), "%s Logout", ICON_OUT); add_menu_item(label, "@menu:confirm_logout", 1); snprintf(label, sizeof(label), "%s Reboot", ICON_RLD); @@ -2820,7 +2820,10 @@ open_builtin_menu(const char *menu_name, int keep_idx) static int any_other_plugin_active(void) { + if (access("/tmp/bananarchy_screen_locked", F_OK) == 0) + return 1; static const char *pid_files[] = { + "xlocker.pid", "xdrawer.pid", "xdialer.pid", "xcalllog.pid", @@ -2835,6 +2838,12 @@ any_other_plugin_active(void) "xringtones.pid", "xwallpapers.pid", "xmusic.pid", + "xsip.pid", + "xemail.pid", + "xirc.pid", + "xtox.pid", + "xsmallweb.pid", + "xgps.pid", }; const char *rdir = getenv("XDG_RUNTIME_DIR"); const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000"; @@ -2879,6 +2888,12 @@ close_other_active_plugins(void) { "xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo" }, { "xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo" }, { "xmusic.pid", "/tmp/dwm_plugin_music.fifo" }, + { "xsip.pid", "/tmp/dwm_plugin_sip.fifo" }, + { "xemail.pid", "/tmp/dwm_plugin_email.fifo" }, + { "xirc.pid", "/tmp/dwm_plugin_irc.fifo" }, + { "xtox.pid", "/tmp/dwm_plugin_tox.fifo" }, + { "xsmallweb.pid", "/tmp/dwm_plugin_smallweb.fifo" }, + { "xgps.pid", "/tmp/dwm_plugin_gps.fifo" }, }; const char *rdir = getenv("XDG_RUNTIME_DIR"); const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000"; @@ -3074,6 +3089,11 @@ show_menu(void) const int bar_h = 24; int target_y; + if (access("/tmp/bananarchy_screen_locked", F_OK) == 0) { + menu_mode = MODE_NONE; + return; + } + check_dmenu_xres_changed(); promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; diff --git a/src/sxmo-dwm/dwm.c b/src/sxmo-dwm/dwm.c index 5a4c033..feefeb5 100644 --- a/src/sxmo-dwm/dwm.c +++ b/src/sxmo-dwm/dwm.c @@ -1301,6 +1301,21 @@ set_sxmo_state_str(const char *st) } } +static int +is_screen_off(void) +{ + char buf[32]; + + read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf)); + return (buf[0] != '\0' && atoi(buf) <= 0) ? 1 : 0; +} + +static int +is_passcode_locked(void) +{ + return access("/tmp/bananarchy_screen_locked", F_OK) == 0 ? 1 : 0; +} + static int is_phone_locked(void) { @@ -1309,8 +1324,7 @@ is_phone_locked(void) int fd; ssize_t n; - read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf)); - if (buf[0] != '\0' && atoi(buf) <= 0) + if (is_screen_off() || is_passcode_locked()) return 1; snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000"); @@ -1728,7 +1742,7 @@ is_right_softkey(KeySym ks, unsigned int keycode) #include #include "dwm_plugin.h" -#define MAX_DWM_PLUGINS 24 +#define MAX_DWM_PLUGINS 48 typedef struct { void *handle; @@ -1796,7 +1810,13 @@ host_spawn_plugin(const char *plugin_name, const char *arg) if (arg && strcmp(arg, "--preload") == 0) { if (is_plugin_daemon_alive(plugin_name)) return; - int stagger_ms = (strcmp(plugin_name, "dmenu") == 0) ? 150 : (600 + (preload_stagger_idx++ * 220)); + int stagger_ms = 600; + if (strcmp(plugin_name, "locker") == 0) + stagger_ms = 80; + else if (strcmp(plugin_name, "dmenu") == 0) + stagger_ms = 150; + else + stagger_ms = 600 + (preload_stagger_idx++ * 220); if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); @@ -1807,15 +1827,24 @@ host_spawn_plugin(const char *plugin_name, const char *arg) } return; } - XUngrabKeyboard(dpy, CurrentTime); - XFlush(dpy); + if (strcmp(plugin_name, "locker") != 0) { + XUngrabKeyboard(dpy, CurrentTime); + XFlush(dpy); + } if (is_plugin_daemon_alive(plugin_name)) { char fifopath[128], msg[128]; snprintf(fifopath, sizeof(fifopath), "/tmp/dwm_plugin_%s.fifo", plugin_name); int fd = open(fifopath, O_WRONLY | O_NONBLOCK | O_CLOEXEC); if (fd >= 0) { int len; - if (strcmp(plugin_name, "xdrawer") == 0) + if (strcmp(plugin_name, "locker") == 0) { + if (arg && (strcmp(arg, "screenoff") == 0 || strcmp(arg, "blank") == 0)) + len = snprintf(msg, sizeof(msg), "LOCK_BLANK\n"); + else if (arg && strcmp(arg, "wake") == 0) + len = snprintf(msg, sizeof(msg), "WAKE\n"); + else + len = snprintf(msg, sizeof(msg), "LOCK\n"); + } else if (strcmp(plugin_name, "xdrawer") == 0) len = snprintf(msg, sizeof(msg), "TOGGLE\n"); else if (strcmp(plugin_name, "dmenu") == 0 && arg && strcmp(arg, "close") == 0) len = snprintf(msg, sizeof(msg), "CLOSE\n"); @@ -2086,6 +2115,7 @@ static void lock_phone_screenoff(void) { const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff"); + int lfd; softkey_pending = 0; softkey_first_ms = 0; softkey_deadline_ms = 0; @@ -2096,8 +2126,14 @@ lock_phone_screenoff(void) star_down = 0; pound_down = 0; write_softkey_state(0, 0); + lfd = open("/tmp/bananarchy_screen_locked", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (lfd >= 0) { + (void)write(lfd, "1\n", 2); + close(lfd); + } if (is_plugin_loaded("dmenu")) host_spawn_plugin("dmenu", "close"); + host_spawn_plugin("locker", "screenoff"); set_sxmo_state_str("screenoff"); set_hw_backlight(0); spawn(&offcmd); @@ -2121,10 +2157,15 @@ wake_phone(void) pound_down = 0; write_softkey_state(0, 0); write_softkey_suppress(now + SOFTKEY_SUPPRESS_MS); + set_hw_backlight(1); + if (is_passcode_locked()) { + set_sxmo_state_str("lock"); + host_spawn_plugin("locker", "wake"); + return; + } XUngrabKeyboard(dpy, CurrentTime); XFlush(dpy); set_sxmo_state_str("unlock"); - set_hw_backlight(1); spawn(&oncmd); } @@ -2138,6 +2179,14 @@ keypress(XEvent *e) ev = &e->xkey; keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); + if (is_screen_off()) { + wake_phone(); + return; + } + if (is_passcode_locked()) { + host_spawn_plugin("locker", "wake"); + return; + } if (is_phone_locked()) { wake_phone(); return; @@ -2767,9 +2816,12 @@ run(void) pound_down = (ie.value != 0); if (ie.value == 1) { - if (is_phone_locked()) { + if (is_screen_off()) { wake_phone(); - } else if ((ie.code == 522 || ie.code == 55 || + } else if (!is_passcode_locked() && is_phone_locked()) { + wake_phone(); + } else if (!is_passcode_locked() && + (ie.code == 522 || ie.code == 55 || ie.code == 523 || ie.code == 98) && star_down && pound_down) { trigger_screenshot_chord(dwm_now_ms()); diff --git a/src/xdrawer/xdrawer.cpp b/src/xdrawer/xdrawer.cpp index 7383391..e3bdce0 100644 --- a/src/xdrawer/xdrawer.cpp +++ b/src/xdrawer/xdrawer.cpp @@ -1021,11 +1021,15 @@ static int xdrawer_run_main(int argc, char** argv) { }; auto isOtherPluginActive = [&]() { + if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0) { + return true; + } static const char* kPids[] = { - "xdialer.pid", "xcalllog.pid", "xcallscreen.pid", "xcontacts.pid", - "xsms.pid", "xfiles.pid", "xcamera.pid", "xthemes.pid", - "xmodem.pid", "xnetworks.pid", "xringtones.pid", "xwallpapers.pid", - "xmusic.pid", + "xlocker.pid", "xdialer.pid", "xcalllog.pid", "xcallscreen.pid", + "xcontacts.pid", "xsms.pid", "xfiles.pid", "xcamera.pid", + "xthemes.pid", "xmodem.pid", "xnetworks.pid", "xringtones.pid", + "xwallpapers.pid", "xmusic.pid", "xsip.pid", "xemail.pid", + "xirc.pid", "xtox.pid", "xsmallweb.pid", "xgps.pid", }; for (const char* pf : kPids) { int p = readIntFile(getRuntimeFile(pf), -1); @@ -1040,7 +1044,7 @@ static int xdrawer_run_main(int argc, char** argv) { }; auto showWindow = [&]() { - if (visible) { + if (visible || ::access("/tmp/bananarchy_screen_locked", F_OK) == 0) { return; } writeIntFile(pidPath, static_cast(::getpid())); @@ -1057,6 +1061,12 @@ static int xdrawer_run_main(int argc, char** argv) { closeOtherPlugin("xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo"); closeOtherPlugin("xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo"); closeOtherPlugin("xmusic.pid", "/tmp/dwm_plugin_music.fifo"); + closeOtherPlugin("xsip.pid", "/tmp/dwm_plugin_sip.fifo"); + closeOtherPlugin("xemail.pid", "/tmp/dwm_plugin_email.fifo"); + closeOtherPlugin("xirc.pid", "/tmp/dwm_plugin_irc.fifo"); + closeOtherPlugin("xtox.pid", "/tmp/dwm_plugin_tox.fifo"); + closeOtherPlugin("xsmallweb.pid", "/tmp/dwm_plugin_smallweb.fifo"); + closeOtherPlugin("xgps.pid", "/tmp/dwm_plugin_gps.fifo"); if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) { int dfd = ::open("/tmp/dwm_plugin_dmenu.fifo", O_WRONLY | O_NONBLOCK | O_CLOEXEC); if (dfd >= 0) {