Skip to content

Instantly share code, notes, and snippets.

@andreycizov
Last active July 30, 2023 03:18
Show Gist options
  • Save andreycizov/493fa9553f4f59949fcb849b4e5cba94 to your computer and use it in GitHub Desktop.
Save andreycizov/493fa9553f4f59949fcb849b4e5cba94 to your computer and use it in GitHub Desktop.
mousemon.sh - Disable mouse when locking the screen Ubuntu
#!/bin/bash
# mousemon.sh - Andrey Cizov (acizov@gmail.com) 2018 (no license applied, free to use on any terms)
#
# Sometimes you'd like to have more control on what toggles the screensaver on your Ubuntu.
# In my scenario the mouse is too sensitive, so whenever I lock the screen subsequently turning
# off the monitors - it's too easy to turn them back on by accidentally touching the mouse.
# Even mildly loud bass is enough to do so.
# This script disables a selected device whenever the lock screen is activated.
# To run this script on login - I suggest using startup-settings utility located here:
# https://github.com/hant0508-zz/startup-settings
# use `xinput list` to find the required device
# prepend the name with `pointer:` to be more specific (my mouse also receives a keyboard ID, but we do not want this)
mouse="pointer:Laview Technology Mionix Avior 7000"
function switch {
xinput --set-prop "$mouse" "Device Enabled" "$1"
}
function cleanup {
switch "1"
}
trap cleanup EXIT
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | ( while read line; do
if echo $line | grep "boolean true" &> /dev/null; then
switch "0"
else
switch "1"
fi
done )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment