Created
January 12, 2017 22:16
-
-
Save fornellas/249e216abbfc486545d987dcaba52e4d to your computer and use it in GitHub Desktop.
Lenovo Yoga X1 tablet mode toggle
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
event=ibm/hotkey LEN0068:00 00000080 000060c0 | |
action=/etc/acpi/toggle-tablet-mode.sh |
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 | |
TABLET_MODE_DISABLED_INPUTS=( | |
'SynPS/2 Synaptics TouchPad' | |
'TPPS/2 IBM TrackPoint' | |
) | |
TABLET_MODE_ROTATE_INPUTS=( | |
'Wacom Co.,Ltd. Pen and multitouch sensor Finger touch' | |
'Wacom Co.,Ltd. Pen and multitouch sensor Pen stylus' | |
'Wacom Co.,Ltd. Pen and multitouch sensor Pen eraser' | |
) | |
TABLET_MODE_ROTATE_DISPLAY='eDP1' | |
function current_mode() { | |
MODE="$(/usr/bin/xrandr --prop | /bin/grep -e '^eDP1 connected ')" | |
case "$MODE" in | |
'eDP1 connected (normal left inverted right x axis y axis)'|'eDP1 connected 2560x1440+0+0 (normal left inverted right x axis y axis) 310mm x 170mm') | |
echo -n regular | |
;; | |
'eDP1 connected left (normal left inverted right x axis y axis)'|'eDP1 connected 1440x2560+0+0 left (normal left inverted right x axis y axis) 310mm x 170mm') | |
echo -n tablet | |
;; | |
esac | |
} | |
function for_each_display() { | |
for DISPLAY in $(/bin/ls /tmp/.X11-unix/ | /usr/bin/cut -c2-) | |
do | |
export DISPLAY=":$DISPLAY" | |
for XAUTHORITY in $(/bin/ls /home/*/.Xauthority) | |
do | |
export XAUTHORITY="$XAUTHORITY" | |
eval "${@}" | |
done | |
done | |
} | |
function to_tablet_mode() { | |
for INPUT in "${TABLET_MODE_DISABLED_INPUTS[@]}" | |
do | |
/usr/bin/xinput disable "$INPUT" | |
done | |
/usr/bin/xrandr --output "$TABLET_MODE_ROTATE_DISPLAY" --rotation left | |
for INPUT in "${TABLET_MODE_ROTATE_INPUTS[@]}" | |
do | |
/usr/bin/xinput set-prop "$INPUT" "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1 | |
done | |
onboard & | |
} | |
function to_regular_mode() { | |
for INPUT in "${TABLET_MODE_DISABLED_INPUTS[@]}" | |
do | |
/usr/bin/xinput enable "$INPUT" | |
done | |
/usr/bin/xrandr --output "$TABLET_MODE_ROTATE_DISPLAY" --rotation normal | |
for INPUT in "${TABLET_MODE_ROTATE_INPUTS[@]}" | |
do | |
/usr/bin/xinput set-prop "$INPUT" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1 | |
done | |
killall onboard | |
} | |
function toggle() { | |
case "$(current_mode)" in | |
regular) | |
to_tablet_mode | |
;; | |
tablet) | |
to_regular_mode | |
;; | |
esac | |
} | |
for_each_display toggle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment