device-nokia-n900: rework screen locking
Provide a unified screen locking mechanism, supporting x11 and sway. Auto locking is also improved to correctly disable inputs in all screen locking scenarios, and re-enabling them on unlock. Unlock on keypad slide now also works on sway (from sway v1.12). Any x11 UI can use the existing script by setting up appropriate keybinds to the script and autostarting xautolock. It may be necessary to disable any built-in autolock method integrated within a specific x11 WM. NB: This is NOT locking in the sense of secure locking. It is purely for turning the screen off and disabling some inputs (currently only the touchscreen) to prevent unintended wakeups. Signed-off-By: Sicelo A. Mhlongo <absicsz@gmail.com> Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/8472>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Reference: <https://postmarketos.org/devicepkg>
|
||||
maintainer="Danct12 <danct12@disroot.org>"
|
||||
pkgname=device-nokia-n900
|
||||
pkgver=52
|
||||
pkgver=53
|
||||
pkgrel=0
|
||||
pkgdesc="Nokia N900"
|
||||
url="https://postmarketos.org"
|
||||
@@ -9,7 +9,6 @@ arch="armv7"
|
||||
license="MIT"
|
||||
depends="
|
||||
alsa-utils
|
||||
evtest
|
||||
kbd
|
||||
kbd-bkeymaps
|
||||
linux-firmware-ti-connectivity
|
||||
@@ -68,7 +67,7 @@ source="
|
||||
keymaps/rx51_it.map
|
||||
keymaps/rx51_ptes.map
|
||||
keymaps/rx51_us.map
|
||||
lock.sh
|
||||
screenlock.sh
|
||||
modem-load.conf
|
||||
modem-opts.conf
|
||||
modules.blocklist
|
||||
@@ -76,7 +75,6 @@ source="
|
||||
sway/etc-sway-config.d-n900-status.conf
|
||||
sway/etc-sway-config.d-nokia-n900.conf
|
||||
sway/etc-xdg-foot-foot.ini
|
||||
sway/usr-bin-sway-saver.sh
|
||||
uboot-script.cmd
|
||||
udev/10-nokia-modem.rules
|
||||
udev/15-bq27k.rules
|
||||
@@ -122,6 +120,8 @@ package() {
|
||||
"$pkgdir"/etc/local.d/$pkgname.start
|
||||
install -Dm755 "$srcdir"/bq27k-monitor.sh \
|
||||
"$pkgdir"/usr/bin/bq27k-monitor
|
||||
install -Dm755 "$srcdir"/screenlock.sh \
|
||||
"$pkgdir"/usr/bin/screenlock.sh
|
||||
|
||||
# Udev rules
|
||||
install -D -m644 "$srcdir"/90-touchscreen-dev.rules \
|
||||
@@ -175,7 +175,7 @@ package() {
|
||||
|
||||
x11() {
|
||||
install_if="$pkgname=$pkgver-r$pkgrel xorg-server"
|
||||
depends="unclutter-xfixes scrot xdotool xinput xrdb xset"
|
||||
depends="unclutter-xfixes scrot xautolock xdotool xinput xrdb xset"
|
||||
mkdir "$pkgdir"/etc/acpi
|
||||
install -D -m755 "$srcdir"/acpi_handler.sh \
|
||||
"$pkgdir"/etc/acpi/handler.sh
|
||||
@@ -185,8 +185,6 @@ x11() {
|
||||
"$subpkgdir"/usr/share/X11/xorg.conf.d/40-xkb.conf
|
||||
install -D -m644 "$srcdir"/xorg.conf \
|
||||
"$subpkgdir"/usr/share/X11/xorg.conf.d/11-n900.conf
|
||||
install -Dm755 "$srcdir"/lock.sh \
|
||||
"$subpkgdir"/usr/bin/lock.sh
|
||||
install -Dm644 "$srcdir"/xresources \
|
||||
"$subpkgdir"/usr/share/X11/Xresources-mobile
|
||||
}
|
||||
@@ -231,8 +229,6 @@ sway() {
|
||||
"$subpkgdir"/etc/sway/config.d/nokia-n900.conf
|
||||
install -D -m644 "$srcdir"/etc-sway-config.d-n900-status.conf \
|
||||
"$subpkgdir"/etc/sway/config.d/01-status-bar.conf
|
||||
install -D -m755 "$srcdir"/usr-bin-sway-saver.sh \
|
||||
"$subpkgdir"/usr/bin/sway-saver.sh
|
||||
}
|
||||
|
||||
foot() {
|
||||
@@ -268,7 +264,7 @@ sha512sums="
|
||||
4887bc1f9a3559614bf3092511114be4a824a4e94bec6dfda31f52b877f92b38164568c8223cab22234a1edf818f9e3b4af0d7f7244c9880bc3399fa4cb0ce37 10-initfs-input.files
|
||||
4656d3b3ced0a86e2d6315c89322899f646a689e9cb64609aa8ad5a676b23d93706d8a37f3be6f6b12c6b1e8501b7d26ecafecf27322333850513a6805c61910 10-initfs-keymap.sh
|
||||
2e6c324c2a0627fb37ee2feff249d6c828116a9c1a32d572481dddc12648c98b726eb3a475838398742f76a60e3f2249d7707502360473b8bf2e794bf22f57ce acpi.map
|
||||
b2c2033f8a77a18dc0c5192e0304f60e3c2a2a7d132c2072ab0dd6ee1a5b2a8c7e6396165411534468311a254663ae887cbaf23816f8b17893dd28e99e549790 acpi_handler.sh
|
||||
eef1f3d5fab1148af498607d3bc7c6a866b61d808d2b90a4ea3e360d5fef779070380670431b67bd3d87111bc7d0e877ef9ab656f4de17c3071cfc360a2746e3 acpi_handler.sh
|
||||
5b87071834313a389f83d29f86f6e3ea108d0921f17dc918be7a46de7e74c73a4418044ef600a0fbf72c8fad22b7730dcd5bfe3d6d01d76bf01556f8540f0b32 asound.state.headset
|
||||
67acc17a33bc75113300393b4a5bba15319014032407e774d079abf310368e75f4f697dbb4856ba2d2d8ea184b056bb33561f42918de3ee91ab6a77df89a133c asound.state.speakers
|
||||
3d55e34b95791636e44a5f41754f3d0de039dbba41f7a556d43a95c9e64afcfa930046b4b96b40020b6f196096ffba93514682927e32fa4488686fdd19c6da5a backlight-enable.sh
|
||||
@@ -284,7 +280,7 @@ d9ef88c714e9fce8822f63b7a9d7fc3e1ed472c8c876b44ba524d44efea322839f13ddd2fa652420
|
||||
82038d38f94cb975a8d38914afca49b64957446bef7490ab684efa1df47ede2ea1c769045789bb9fded673345eea01911fbbf85fdb54c28685cad8022bfaafac ofono
|
||||
d7f79fa0887110b85dfb676bd426fa76764fbbb8093df89184552838ddb703b62500f61d7cfa8decdb75a542e3ef577cc71ee4c12ed14d6a76827a3f5aa13073 wifi
|
||||
d7d1599a9952fd02d3cfbeaa6b3307251e765f98a9eb723237c94f585831cc8f11d9d30dbc0352e3b008224dec12b820cf86fa28a5e5ac303cfd03d80b8872f5 config-checker
|
||||
c95afd02124e53f0de1ef33e7bbee12a15ae2d4d629a201157ed9d428288365241dfc3358fc7055154845f9df986fd975a2ebd4de384b8e175cb45f26b2fa38d i3wm.conf
|
||||
2f00222e3502cc7ca245ceab24e370fd9d653d7bcad2c4039848fbba5a16d7f467c107fcf80ea253d42cc632048d6cef890b39446cac31a9a6f2c42cb48d9d30 i3wm.conf
|
||||
63ec5a88f4385fd944477d0b7ca7061745b061337cba8d3c779826aa96a94dda79bfca4fb3456234f6adbdb483e660d3cf6ccefd8576d23a70f52e3f44f0edb4 pwr-key-handler.sh
|
||||
181187db6d88b872233f594759373f32fd08065ee340b60f0c3ff06396d99f4b1250192d70a054fcc9e51e067f6cc063c62b7d8dfff3427b292f1d0c766db206 40-xkb.conf
|
||||
dc585e11bf4e06e36c5c62bcc024eaacecc30437d9da5257df14be05e247a2f2bc208874be3058edc6f87cc2877da2ecafd2f627d9b465d4fd24475fc21fdc71 rx51_ch.map
|
||||
@@ -292,15 +288,14 @@ dc585e11bf4e06e36c5c62bcc024eaacecc30437d9da5257df14be05e247a2f2bc208874be3058ed
|
||||
082a5166e38296b097e873b0b4aeaf007e594d3bf4470c74e91ee3efedcf28ad25cd55c23dd63e460339898ae08e77e111b0e1092fa5e661db90bb40732103a1 rx51_it.map
|
||||
6e4e8b10a41d0957968736f5d780f14c7070b03913d80859cb07180e9cec9a36bbc9c639748765e48962772640974f5491627520cc36bd3d6c9d01748f9ddaff rx51_ptes.map
|
||||
e440ed7a3070c17e003b86b72dbe6d8194d01b577ca8dd56dd066f216b6dda32bb965c780950f1789a66f7c948290016b048da9f1cf63aba9e11d7e7fd6873ba rx51_us.map
|
||||
83374ba470dc6c34e11c62e91e90a96614d76ae7ce240dd830cb1b2f07f9a72c83e5b50e07e49885a72b9caf25fd586c4ea26452a73baf8bab1d2b4490a107ab lock.sh
|
||||
580753dfe302024cac6260be6aa0472f6fcca2899e31b41fae23e48a34e49ed482a7170a4ec38978618c0b222b28988d6f7e77e38f4bf7bcd72da98b9b5d7070 screenlock.sh
|
||||
157b27feebcfddf800a1ffd8c6e369d2b58e5db25b1a44b4443dada8d9fe74abb91d036b9f0e97769bbafbdc72020b5637313682c6932fe7b0bddb9ebebbad42 modem-load.conf
|
||||
695feac7f69a0ec8c5e007cdb651adcc3492f1c6236e7fd183edec2a5e25cb957d3ace630ea5fdb87fd703e35ac368f1d097c2f881ecb52c9cfd433564db2a6c modem-opts.conf
|
||||
862ebc7cd2d7a1b3d41b10701b8418308c89eb0732eb99c42ec1091d48e08db9421727f67a3272b7309549798d59afb1b8d7d2fa48d1447b208fcb2329472d4d modules.blocklist
|
||||
143c21f0b18a016d37cb44178e9daea09f128a90769b48353c03c3f245cb9b1f7e773b9ccee084973fc78ddd7a18c2642e54888a85bda7c7daecddc9a8c62eff pointercal
|
||||
3ec2e28a59298ad87ece5205be37b6e07c5f0f3bd0a98022f9f6824500444792cb06425bfbb62c9503c3072183f2d571c8504b6f23054062bb082c7a5b125a2b etc-sway-config.d-n900-status.conf
|
||||
f108939785958bb991c5849c3ccd1b45a70d89e07c535c91f881d46b96642e16a868dad1b7043876e30ab169bf92da7b5b585b9d9b67c2e13a77a52720b3d5b8 etc-sway-config.d-nokia-n900.conf
|
||||
1e6939c583372dd4d493e1e2cfb6a4758a17606edd262d322bc01b2d3d76de4370581954f22f6ac976d86e87aab0979b2233e1c75780aeaff0670ea25dba62ca etc-sway-config.d-nokia-n900.conf
|
||||
45da074b597a47825146ae1f3712538210e2ebe1c459f98a8189ccfc7c16ed54d221999b5890785c92aa750c6295dee7e920ef7f97d415d4212f8c0fea29169f etc-xdg-foot-foot.ini
|
||||
8ca33e8e8bb5da1c4de562db3a96ff3481d42344d9cabe532730665231cce491c777526ed35a4872bee768f48e5573f35bc034757740f8b57a570d409004b241 usr-bin-sway-saver.sh
|
||||
42f916d87dd305111028992a1107bf6fe108bebbd782ae8edd065e76505db2b3a75e57515970c3e40cb0d1b7e83097a1bba92785be13df7c3fd80959a8d9c5c1 uboot-script.cmd
|
||||
465b9a0d2b46d0981c64b47cb1f656c2456a90b91b1751a2efad10af38a96030dd99108b1fd76ce31bf1ea0f236d55bed38b114d6bd712f09f8968de034c946c 10-nokia-modem.rules
|
||||
1acc441b9f83dc91fd65fa3f89b8205bfd72a465286bc181b4e7e92dd4b8c0bc5c20a18dab46ff3ee8ae70940efd7d767b3dfb920edb4c74377bd418b838693d 15-bq27k.rules
|
||||
|
||||
@@ -3,20 +3,13 @@
|
||||
user=$( getent passwd 10000 | cut -d: -f1 )
|
||||
cmd=$( echo $0 | awk '{i=split($0,a,"/"); print a[i]}' )
|
||||
|
||||
function adjust_keypad_bl {
|
||||
for i in $(seq 1 6); do
|
||||
echo $1 > /sys/class/leds/lp5523\:kb$i/brightness
|
||||
done
|
||||
}
|
||||
|
||||
case $cmd in
|
||||
KP_SLIDE_OPEN)
|
||||
adjust_keypad_bl 63
|
||||
su $user -c 'DISPLAY=:0.0 /usr/bin/xset dpms force on'
|
||||
su $user -c 'DISPLAY=:0.0 /usr/bin/xinput enable "TSC2005 touchscreen"'
|
||||
su $user -c '/usr/bin/screenlock.sh unlock'
|
||||
/usr/bin/screenlock.sh kbd_backlight 31
|
||||
;;
|
||||
KP_SLIDE_CLOSE)
|
||||
adjust_keypad_bl 0
|
||||
/usr/bin/screenlock.sh kbd_backlight 0
|
||||
;;
|
||||
CAM_BTN_DWN)
|
||||
echo "Not implemented yet"
|
||||
|
||||
@@ -67,7 +67,7 @@ bindsym --release Shift+Up exec --no-startup-id xdotool click 4
|
||||
bindsym --release Shift+Down exec --no-startup-id xdotool click 5
|
||||
|
||||
# Handle screenlock key
|
||||
bindsym --release XF86ScreenSaver exec --no-startup-id lock.sh
|
||||
bindsym --release XF86ScreenSaver exec --no-startup-id screenlock.sh
|
||||
|
||||
# Pressing the power button offers reboot, shutdown, or suspend choice
|
||||
bindsym XF86PowerOff exec --no-startup-id pwr-key-handler
|
||||
@@ -101,4 +101,6 @@ exec --no-startup-id xrdb -merge /usr/share/X11/Xresources-mobile
|
||||
# Hide mouse cursor
|
||||
exec --no-startup-id unclutter-xfixes --fork
|
||||
# Turn display off after 2 minutes of idle
|
||||
exec --no-startup-id xset dpms 0 0 120
|
||||
exec --no-startup-id xset dpms 0 0 0
|
||||
exec --no-startup-id xset s off
|
||||
exec --no-startup-id xautolock -time 2 -detectsleep -locker 'screenlock.sh lock'
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
touch_state=$(xinput list-props "TSC2005 touchscreen" | grep "Device Enabled" | tr -d "\t" | cut -d ":" -f 2)
|
||||
|
||||
case "$touch_state" in
|
||||
0)
|
||||
xinput enable "TSC2005 touchscreen"
|
||||
xset dpms force on
|
||||
;;
|
||||
1)
|
||||
xinput disable "TSC2005 touchscreen"
|
||||
xset dpms force off
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,99 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
kbd_backlight() {
|
||||
for i in $(seq 1 6); do
|
||||
brightnessctl --quiet --device="*kb$i" s "$1"
|
||||
done
|
||||
}
|
||||
|
||||
x11_unlock() {
|
||||
export DISPLAY=:0
|
||||
xautolock -enable
|
||||
xset dpms force on
|
||||
xset dpms 0 0 0
|
||||
xinput enable "TSC2005 touchscreen"
|
||||
}
|
||||
|
||||
x11_lock() {
|
||||
export DISPLAY=:0
|
||||
xinput disable "TSC2005 touchscreen"
|
||||
xset dpms 0 0 3
|
||||
xset dpms force off
|
||||
xautolock -disable
|
||||
kbd_backlight 0
|
||||
}
|
||||
|
||||
sway_unlock() {
|
||||
SWAYSOCK="$(find /run/user/ -name "*sway-ipc*")"
|
||||
export SWAYSOCK
|
||||
swaymsg output DPI-1 power on
|
||||
swaymsg exec "swayidle timeout 120 'swaymsg exec screenlock.sh lock'"
|
||||
swaymsg input "0:2005:TSC2005_touchscreen" events enabled
|
||||
}
|
||||
|
||||
sway_lock() {
|
||||
SWAYSOCK="$(find /run/user/ -name "*sway-ipc*")"
|
||||
export SWAYSOCK
|
||||
swaymsg input "0:2005:TSC2005_touchscreen" events disabled
|
||||
swaymsg output DPI-1 power off
|
||||
pkill -f swayidle
|
||||
kbd_backlight 0
|
||||
}
|
||||
|
||||
get_environment() {
|
||||
environment="unknown"
|
||||
if pgrep -nf Xorg > /dev/null; then
|
||||
environment="x11"
|
||||
elif pgrep -nf sway$ > /dev/null; then
|
||||
environment="sway"
|
||||
else
|
||||
# add other environments here
|
||||
exit 0
|
||||
fi
|
||||
echo "$environment"
|
||||
}
|
||||
|
||||
toggle() {
|
||||
case "$(get_environment)" in
|
||||
x11)
|
||||
export DISPLAY=:0
|
||||
touch_state=$(xinput list-props "TSC2005 touchscreen" | grep "Device Enabled" | tr -d "\t" | cut -d ":" -f 2)
|
||||
;;
|
||||
sway)
|
||||
SWAYSOCK="$(find /run/user/ -name "*sway-ipc*")"
|
||||
export SWAYSOCK
|
||||
touch_state=$(swaymsg -t get_inputs | jq -r '.[] | select (.identifier == "0:2005:TSC2005_touchscreen") | .libinput.send_events')
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$touch_state" in
|
||||
disabled)
|
||||
sway_unlock
|
||||
;;
|
||||
enabled)
|
||||
sway_lock
|
||||
;;
|
||||
0)
|
||||
x11_unlock
|
||||
;;
|
||||
1)
|
||||
x11_lock
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ "$#" -ge 1 ]; then
|
||||
case "$1" in
|
||||
*lock)
|
||||
env="$(get_environment)"
|
||||
eval "$env"_"$1"
|
||||
;;
|
||||
kbd_backlight)
|
||||
shift 1
|
||||
kbd_backlight "$1"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
toggle
|
||||
fi
|
||||
@@ -31,12 +31,16 @@ bindsym --release Shift+Down exec -- seat * cursor press button5
|
||||
|
||||
# Handle screenlock key (XF86ScreenSaver)
|
||||
# Bind using code due to sway bug: https://github.com/swaywm/sway/issues/8438
|
||||
bindcode --no-repeat 160 exec sway-saver.sh
|
||||
bindcode --no-repeat 160 exec screenlock.sh
|
||||
|
||||
# Handle keypad slide
|
||||
bindswitch keypad_slide:on exec screenlock.sh kbd_backlight 31 && screenlock.sh unlock
|
||||
bindswitch keypad_slide:off exec screenlock.sh kbd_backlight 0
|
||||
|
||||
# TODO: Pressing the power button should offer choices including rebooting,
|
||||
# shutdown, and suspend.
|
||||
# At present, it will only lock and unlock the screen, same as XF86ScreenSaver
|
||||
bindsym XF86PowerOff exec sway-saver.sh
|
||||
bindsym XF86PowerOff exec screenlock.sh
|
||||
|
||||
# Use PA once UCM2 config is available
|
||||
bindsym XF86AudioRaiseVolume exec amixer set PCM 5%+
|
||||
@@ -47,4 +51,4 @@ bindsym Shift+XF86AudioRaiseVolume exec brightnessctl --quiet --class=backlight
|
||||
bindsym Shift+XF86AudioLowerVolume exec brightnessctl --quiet --class=backlight set 10%-
|
||||
|
||||
# Idle configuration
|
||||
exec swayidle timeout 120 'swaymsg exec sway-saver.sh disable'
|
||||
exec swayidle timeout 120 'swaymsg exec screenlock.sh lock'
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Silence shellcheck's errorneous "(warning): In POSIX sh, 'enable' is undefined."
|
||||
# shellcheck disable=3044
|
||||
set -e
|
||||
|
||||
set_kbd_backlight() {
|
||||
for i in $(seq 1 6); do
|
||||
brightnessctl --quiet --device="*kb$i" s "$1"
|
||||
done
|
||||
}
|
||||
|
||||
enable() {
|
||||
swaymsg input "0:2005:TSC2005_touchscreen" events enabled
|
||||
swaymsg output DPI-1 power on
|
||||
set_kbd_backlight 25
|
||||
swaymsg exec "swayidle timeout 120 'swaymsg exec sway-saver.sh disable'"
|
||||
}
|
||||
|
||||
disable() {
|
||||
swaymsg input "0:2005:TSC2005_touchscreen" events disabled
|
||||
swaymsg output DPI-1 power off
|
||||
set_kbd_backlight 0
|
||||
pkill -f swayidle
|
||||
}
|
||||
|
||||
# Enable/disable based on cmdline parameter
|
||||
if [ "$#" -eq 1 ]; then
|
||||
case "$1" in
|
||||
enable|disable)
|
||||
eval "$1"
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
fi
|
||||
|
||||
state_touch=$(swaymsg -t get_inputs | jq -r '.[] | select (.identifier == "0:2005:TSC2005_touchscreen") | .libinput.send_events')
|
||||
|
||||
# Toggle enabled/disabled state
|
||||
case "$state_touch" in
|
||||
disabled)
|
||||
enable
|
||||
;;
|
||||
enabled)
|
||||
disable
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user