Screen locker:Disable inputs
Some screen lockers do not disable inputs like touchscreen or buttons. This page collects possibilites how to hande this.
Xfce4
Here is an example draft script that disables inputs when the screen is locked in Xfce4.
The approach of this script is parasitical usage of dbus signals or method calls of other programs.
Note: The script might not work reliable. The approach of using other programs signals or method calls implies a certain instability. |
Preparation:
- Package
xinput
needs to be installed. - The power button is used for locking. Go to Settings -> Keyboard -> Application Shortcuts, select command xflock4, double-click the current shortcut and hit the power button. Additionally, edit the file
/etc/elogind/logind.conf
, disable the line "HandlePowerKey=ignore", log out or reboot to apply the change. (You can also use another button but might need to adapt the script.) - You need to set up a virtual keyboard for the unlocking screen.
onboard
works well but availability is limited, alternatively you can usematchbox-keyboard
. See Input_methods#Conventional_on-screen_keyboards for installation and Screen_locker#xfce4-screensaver for implementation. - The script is waiting for a locking signal. To have it work properly, go to Settings -> Power Manager -> System and check "Lock screen when system is going to sleep.
The script needs to be adapted to your specific situation:
- Check the id numbers of the inputs you want to disable with
xinput list
(or e.g.DISPLAY=:0 xinput list
via ssh) and adapt the input function blocks of the script. - The script refers to
xfce4-screensaver
. If you use another screen locker, you need to adapt the commands and probably also the dbus signals and method calls. - If you also want to handle the LEDs, make sure you have permission to do so (see LEDs#Access_via_sysfs), adapt the sysfs path in the script and uncomment the lines related to LEDs (the functions "disable_leds" and "enable_leds" at the top, their calls further down and one "else" line at the end).
- Before using the script, check if the dbus-monitor commands of the script work for your setup by executing them via ssh and then lock/unlock your device. For the session bus, DISPLAY variable needs to be exported. The command via ssh looks like
DISPLAY=:0 dbus-monitor --session ...
If the dbus-commands seem to work, you can test the script via ssh. Create the script by e.g. vi ~/xfce4-screensaver-disable-inputs.sh
, paste your code, make it executable by chmod +x ~/xfce4-screensaver-disable-inputs.sh
. To test it via ssh, you need to uncomment the export DISPLAY at the beginning of the script and for better debugging also the echo commands spread over the script. Start the script by ~/xfce4-screensaver-disable-inputs.sh
.
In case the dbus-monitor commands do not work for your setup, you can try to find others that might work for you:
DISPLAY=:0 dbus-monitor --session type=signal
shows signals on the session bus.DISPLAY=:0 dbus-monitor --session
shows signals and method calls on the session bus.dbus-monitor --system
shows only signals on the system bus.sudo dbus-monitor --system
shows signals and method calls on the system bus.
Usage of LEDs is recommended if possible. They are a good indication on the state of the inputs.
When the script looks good, it can be added to autostart in Settings -> Session and Startup -> Application Autostart -> +
.
Known issues if the script are:
- When hitting the cancel button at the unlock screen fast and repeatedly, a situation can be produced where the screen is on but the inputs off. In this case, you have to wait until the screen blanks again, thereafter you can unlock the device.
#!/bin/sh
# For debugging via ssh, DISPLAY variable needs to be exported. The value might differ.
# export DISPLAY=:0
### functions ###
# Make sure to adapt the list of inputs to your use case. Install xinput and check with xinput list.
# function for disabling inputs
disable_inputs () {
xinput disable 6
xinput disable 7
xinput disable 9
xinput disable 11
}
# function for enabling inputs
enable_inputs () {
xinput enable 6
xinput enable 7
xinput enable 9
xinput enable 11
}
# If you have some auxillary leds, e.g. at the touch buttons, you can use them here.
# You need permission to change them, though. See wiki article on LEDs.
# optionally: function for disabling leds
# disable_leds () {
# echo 0 > /sys/class/leds/tm2-touchkey/brightness
# }
# optionally: function for enabling leds
# enable_leds () {
# echo 1 > /sys/class/leds/tm2-touchkey/brightness
# }
### main ###
# wait until the sesseion gets locked
dbus-monitor --session "interface='org.xfce.ScreenSaver',member='ActiveChanged'" | \
while read signal_lock; do
if [ "$(echo $signal_lock | grep -o true)" ]; then
# optionally for debugging:
# echo "locked"
disable_inputs
# disable_leds
# optionally for debugging:
# echo "touchscreen off 1"
# optionally for debugging:
# echo "leds off 1"
# go into a loop as long as the session is locked
locked="true"
while $locked; do
# watch for the screen waking up
dbus-monitor --session "interface='org.xfce.Xfconf',member='GetAllProperties'" | grep -m 0 xfce4-screensaver
enable_inputs
# enable_leds
# optionally for debugging:
# echo "touchscreen on 1"
# optionally for debugging:
# echo "leds on 1"
# when leaving the unlock dialogue, go on
dbus-monitor --session member='NameLost' | grep -m 0 NameLost
disable_inputs
# optionally for debugging:
# echo "touchscreen off 2"
# check whether the session is unlocked
# add a bit of delay to make sure the check returns the correct result
sleep 0.5
if [ "$(xfce4-screensaver-command --query | grep -o inactive)" = "inactive" ]; then
# optionally for debugging:
# echo "unlocked"
enable_inputs
# optionally for debugging:
# echo "touchscreen on 2"
locked="false"
# else # uncomment this when using leds
# disable_leds
# optionally for debugging:
# echo "leds off 2"
fi
done
fi
done
MATE
The almost same script can be used for MATE. It needs some minor changes.
--- xfce
+++ mate
@@ -41,3 +41,3 @@
# wait until the sesseion gets locked
-dbus-monitor --session "interface='org.xfce.ScreenSaver',member='ActiveChanged'" | \
+dbus-monitor --session "interface='org.mate.ScreenSaver',member='ActiveChanged'" | \
while read signal_lock; do
@@ -61,3 +61,3 @@
# watch for the screen waking up
- dbus-monitor --session "interface='org.xfce.Xfconf',member='GetAllProperties'" | grep -m 0 xfce4-screensaver
+ dbus-monitor --session member=StartServiceByName | grep -m 0 "org.gtk.vfs.Daemon"
@@ -72,3 +72,3 @@
# when leaving the unlock dialogue, go on
- dbus-monitor --session member='NameLost' | grep -m 0 NameLost
+ dbus-monitor --session member='NameLost' | grep -m 1 NameLost
@@ -82,3 +82,3 @@
sleep 0.5
- if [ "$(xfce4-screensaver-command --query | grep -o inactive)" = "inactive" ]; then
+ if [ "$(mate-screensaver-command --query | grep -o inactive)" = "inactive" ]; then
Following steps to set up the script:
- Install package
xinput
. - Assign the power key to screen lock by System -> Preferences -> Hardware -> Keyboard Shortcuts -> af the end of the "Desktop" section look for "Lock screen" and double-click the shortcut at the lefthand side -> hit the power key -> close.
- Edit the file
/etc/elogind/logind.conf
, disable the line "HandlePowerKey=ignore", log out or reboot to apply the change. - Create a new file
~/mate-screensaver-disable-inputs.sh
- Copy-paste the script for Xfce4 in there.
- Apply changes for MATE (see diff above).
- Check
xinput list
and adapt the input numbers you want to lock in script (all buttons and touchscreen except the power key). - If you have user permissions to change LEDs, uncomment the according parts of the script.
- Make the script executable by
chmod +x ~/mate-screensaver-disable-inputs.sh
. - Test by entering
~/mate-screensaver-disable-inputs.sh
in the terminal directly on the device, lock the screen, check if the touchscreen is disabled, wake up by hitting the power button, unlock the screen. Abort the terminal command by Ctrl+C. - If it works ok, create an autostart entry by System -> Preferences -> Personal -> Startup Applications -> Add. Log out or reboot to autostart the script.
Note: The script might not work reliable and possibly needs improvement. |