/
toggle
executable file
·66 lines (53 loc) · 3.1 KB
/
toggle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# The MIT License (MIT)
# Copyright (c) 2020 Siddharth S Singh
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
touch_state="$(< "$HOME/.multitouch_toggle")" # File to store the toggle state in.
# check 'xinput list' for what these should be on your machine.
touch_device_name='Wacom ISDv4 E6 Finger touch' # You can safely delete this line if you do not have a touch screen. Do not forget to omit this device from remappable_devices.
wacom_stylus='Wacom ISDv4 E6 Pen stylus' # rename to whatever your stylus is called.
wacom_eraser='Wacom ISDv4 E6 Pen eraser' # rename to whatever your eraser is called. If your stylus does not have an eraser, just omit this from remappable_devices.
# Array of remappable devices.
remappable_devices=("$touch_device_name" "$wacom_stylus" "$wacom_eraser")
# The app-name notify-send will use to send notifications. I use the ThinkVantage button on my X220t, hence this name.
notification_sender='ThinkVantage Button Listener'
touch_state="$(xrandr | awk ' / connected / { print $1; } END { print "Disable Touch" }' | dmenu -p "Which display do you want to remap to?")"
if [[ $touch_state == "Disable Touch" ]]; then
touch_state="OFF"
fi
if [[ -z $touch_state ]]; then
notify-send -a $notification_sender "Touch not remapped."
exit 1
fi
if [[ $touch_state != "OFF" ]]; then # touch state is set to a device name.
xinput set-prop "$touch_device_name" 'Device Enabled' 1 # make sure finger touch is enabled.
# remap to selected display.
for device in "${remappable_devices[@]}"; do
xinput --map-to-output "$device" "$touch_state"
done
# Notify user.
notify-send -a "$notification_sender" "Touch remapped" "Touchscreen and Wacom digitizer remapped to $touch_state"
else # Touch state is OFF.
if [[ -n "$touch_device_name" ]]; then # If the touchscreen is configured.
# disable touch screen.
xinput set-prop "$touch_device_name" 'Device Enabled' 0
# Notify.
notify-send -a "$notification_sender" "Touch disabled" "Finger touch has been disabled"
fi
fi
# Save the state for next invocation.
echo "$touch_state" > "$HOME/.multitouch_toggle