Created
December 3, 2023 04:21
-
-
Save meepak/2a7e5b8b7ab479e389419e23fa7091ea to your computer and use it in GitHub Desktop.
Cinnamon panel launcher - add quick touchscreen toggle button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the device name, find it using xinput list | |
# deviceName="G2Touch Multi-Touch by G2TSP" | |
# Get touchscreen device id, if it's too slow, hardcode it | |
# deviceId=$(xinput list | grep "$deviceName" | awk '{print $7}' | awk -F '=' '{print $2}') | |
# Hardcoding this because it seems a bit slow and the cursor disappears | |
deviceId=11 | |
touchPadId=13 | |
launcherDesktopFile="/home/usr/.local/share/applications/cinnamon-custom-launcher-1.desktop" | |
# Function to toggle device state | |
toggle_device() { | |
device=$1 | |
state=$(xinput list-props $device | grep "Device Enabled" | awk '{print $4}') | |
if [ "$state" == "0" ]; then | |
xinput enable $device | |
notify-send "Device $device, Touchscreen Enabled" | |
update_launcher "Disable TouchScreen" "devices/input-touchpad-symbolic.symbolic.png" | |
else | |
xinput disable $device | |
notify-send "Device $device, Touchscreen Disabled" | |
update_launcher "Enable TouchScreen" "status/touchpad-disabled-symbolic.symbolic.png" | |
fi | |
} | |
# Function to update launcher file | |
update_launcher() { | |
name=$1 | |
icon=$2 | |
# Update Name and Icon in the launcher file | |
sed -i "s/^Name=.*/Name=$name/" $launcherDesktopFile | |
# /usr/share/icons/Adwaita/24x24/status/touchpad-disabled-symbolic.symbolic.png | |
sed -i "s|^Icon=.*|Icon=/usr/share/icons/Adwaita/24x24/$icon|" $launcherDesktopFile | |
# allow delay to save file | |
sleep 0.2 | |
# Execute command to reload Cinnamon panel launchers, wish there was way to refresh one launcher only | |
dbus-send --session --dest=org.Cinnamon.LookingGlass --type=method_call /org/Cinnamon/LookingGlass org.Cinnamon.LookingGlass.ReloadExtension string:'[email protected]' string:'APPLET' | |
} | |
# Toggle touchscreen | |
toggle_device $deviceId | |
# Toggle touchpad to force cursor reappearing, wish there was better workaround | |
xinput disable $touchPadId | |
xinput enable $touchPadId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to https://gist.github.com/hyOzd/35e913db620b3ba086fb for the command to reload applets