1
dot-files/bin/gnome-toggle-touchpad-lock

50 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
################################################################################
#
# gnome-toggle-touchpad-lock
# Toggles GNOME's touchpad typing lock feature
#
# Requires notify-send to be installed
#
################################################################################
################################################################################
# User configuration
################################################################################
title="Touchpad Lock"
body_enabled="Touchpad will be locked while typing."
body_disabled="Touchpad will be unlocked while typing."
icon_enabled="touchpad-disabled"
icon_disabled="input-touchpad"
key="org.gnome.desktop.peripherals.touchpad disable-while-typing"
################################################################################
# GSettings toggle code
################################################################################
# Get original value of key
value=$(gsettings get $key)
# Determine a temp file to store the notification ID in
notif_id_file_name=/tmp/tmp.$(echo $key | tr -d ' ').nid
{ prev_notif_id=$(<$notif_id_file_name); } 2> /dev/null
# If we have an ID from a previous notification,
# set the replace flag so that we override it
replace_flag=""
case $prev_notif_id in
''|*[!0-9]*) ;;
*) replace_flag="--replace-id=$prev_notif_id" ;;
esac
# Toggle the key and send the notification
if [[ $value == "true" ]]; then
gsettings set $key false
notify-send "$title Disabled" "$body_disabled" --app-name "$title" --icon "$icon_disabled" $replace_flag --transient --expire-time=0 --print-id > "$notif_id_file_name"
else
gsettings set $key true
notify-send "$title Enabled" "$body_enabled" --app-name "$title" --icon "$icon_enabled" $replace_flag --transient --expire-time=0 --print-id > "$notif_id_file_name"
fi