This updated script provides an additional systemd
service to manage and restore the screenpad
state when locking the device and the original service for resuming from sleep on Asus laptops with a Screenpad installed.
This has been tested with the Asus UX482EG but it should… work with other models.
Table of Contents
Note that this requires that the package Asus WMI Screenpad is installed.
Screen Management Script
The script ran by both the screenpad-sleeper.service & screenpad-lock.service:
#!/bin/sh
# Get the current brightness 0 indicates that it is offline
BRIGHTNESS_FILE="/var/tmp/screenpad_brightness"
BRIGHTNESS_SYS_FILE="/sys/class/leds/asus::screenpad/brightness"
store_brightness() {
cat "$BRIGHTNESS_SYS_FILE" > "$BRIGHTNESS_FILE"
}
restore_brightness() {
if [ -f "$BRIGHTNESS_FILE" ]; then
STORED_BRIGHTNESS=$(cat "$BRIGHTNESS_FILE")
if [ "$STORED_BRIGHTNESS" -gt 0 ]; then
# screenpad 1
echo "$STORED_BRIGHTNESS" > "$BRIGHTNESS_SYS_FILE"
else
screenpad off
fi
rm "$BRIGHTNESS_FILE"
else
screenpad off
fi
}
on_lock() {
gdbus monitor -y -d org.freedesktop.login1 |
while read -r line; do
if [[ $line =~ \'LockedHint\':\ \<([^>]+)\> ]]; then
locked_hint="${BASH_REMATCH[1],,}" # Convert to lowercase
if [ "$locked_hint" = "true" ]; then
store_brightness
screenpad off
echo "LockedHint: true"
else
restore_brightness
echo "LockedHint: false"
fi
fi
done
}
if [ "$1" = "pre" ]; then
store_brightness
screenpad off
elif [ "$1" = "post" ]; then
restore_brightness
elif [ "$1" = "onlock" ]; then
on_lock
fi
The screenpad-lock.service:
[Unit]
Description=Monitor GNOME screen lock status
After=graphical.target
[Service]
ExecStart=/usr/local/bin/screenpad_wake_helper.sh onlock
Restart=always
[Install]
WantedBy=graphical.target
The screenpad-sleeper
.service:
[Unit]
Description=Run helper on wake from sleep; restores screenpad state prior to sleep.
Before=systemd-suspend.service
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/screenpad_wake_helper.sh pre
ExecStop=/usr/local/bin/screenpad_wake_helper.sh post