-
-
Save kalinchernev/35cbccdffbf0f827ae38 to your computer and use it in GitHub Desktop.
Bind to a key to rotate the screen of a convertible laptop
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 | |
# This script rotates the screen and touchscreen input 90 degrees each time it is called, | |
# also disables the touchpad, and enables the virtual keyboard accordingly | |
# by Ruben Barkow: https://gist.github.com/rubo77/daa262e0229f6e398766 | |
#### configuration | |
# find your Touchscreen and Touchpad device with `xinput` | |
TouchscreenDevice='Wacom ISDv4 E6 Finger touch' | |
TouchpadDevice='SynPS/2 Synaptics TouchPad' | |
Stylus='Wacom ISDv4 E6 Pen stylus' | |
if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then | |
echo 'Usage: rotate-screen.sh [OPTION]' | |
echo | |
echo 'This script rotates the screen and touchscreen input 90 degrees each time it is called,' | |
echo 'also disables the touchpad, and enables the virtual keyboard accordingly' | |
echo | |
echo Usage: | |
echo ' -h --help display this help' | |
echo ' -j (just horizontal) rotates the screen and touchscreen input only 180 degrees' | |
echo ' -n always rotates the screen back to normal' | |
exit 0 | |
fi | |
touchpadEnabled=$(xinput --list-props "$TouchpadDevice" | awk '/Device Enabled/{print $NF}') | |
screenMatrix=$(xinput --list-props "$TouchscreenDevice" | awk '/Coordinate Transformation Matrix/{print $5$6$7$8$9$10$11$12$NF}') | |
# Matrix for rotation | |
# ⎡ 1 0 0 ⎤ | |
# ⎜ 0 1 0 ⎥ | |
# ⎣ 0 0 1 ⎦ | |
normal='1 0 0 0 1 0 0 0 1' | |
normal_float='1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000' | |
#⎡ -1 0 1 ⎤ | |
#⎜ 0 -1 1 ⎥ | |
#⎣ 0 0 1 ⎦ | |
inverted='-1 0 1 0 -1 1 0 0 1' | |
inverted_float='-1.000000,0.000000,1.000000,0.000000,-1.000000,1.000000,0.000000,0.000000,1.000000' | |
# 90° to the left | |
# ⎡ 0 -1 1 ⎤ | |
# ⎜ 1 0 0 ⎥ | |
# ⎣ 0 0 1 ⎦ | |
left='0 -1 1 1 0 0 0 0 1' | |
left_float='0.000000,-1.000000,1.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000' | |
# 90° to the right | |
#⎡ 0 1 0 ⎤ | |
#⎜ -1 0 1 ⎥ | |
#⎣ 0 0 1 ⎦ | |
right='0 1 0 -1 0 1 0 0 1' | |
if [ $screenMatrix == $normal_float ] && [ "$1" != "-n" ] | |
then | |
echo "Upside down" | |
xrandr -o inverted | |
xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $inverted | |
xinput set-prop "$Stylus" 'Coordinate Transformation Matrix' $inverted | |
xinput disable "$TouchpadDevice" | |
# Remove hashtag below if you want pop-up the virtual keyboard | |
gsettings set org.onboard.keyboard input-event-source XInput | |
gsettings set org.onboard.keyboard touch-input none | |
xsetwacom --set "Wacom ISDv4 E6 Finger touch" Gesture on | |
killall onboard; ./onboard | |
onboard & | |
elif [ $screenMatrix == $inverted_float ] && [ "$1" != "-j" ] && [ "$1" != "-n" ] | |
then | |
echo "90° to the left" | |
xrandr -o left | |
xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $left | |
xinput set-prop "$Stylus" 'Coordinate Transformation Matrix' $left | |
xinput disable "$TouchpadDevice" | |
elif [ $screenMatrix == $left_float ] && [ "$1" != "-j" ] && [ "$1" != "-n" ] | |
then | |
echo "90° to the right" | |
xrandr -o right | |
xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $right | |
xinput set-prop "$Stylus" 'Coordinate Transformation Matrix' $right | |
xinput disable "$TouchpadDevice" | |
else | |
echo "Back to normal" | |
xrandr -o normal | |
xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $normal | |
xinput set-prop "$Stylus" 'Coordinate Transformation Matrix' $normal | |
xinput enable "$TouchpadDevice" | |
fi |
Author
kalinchernev
commented
Feb 1, 2021
via email
Just restart your computer and the state of the system will be as if you
never executed the script
…On Mon, 1 Feb 2021, 20:47 RogerThorp, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
How do i put everything back to normal as if i never did the script?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/35cbccdffbf0f827ae38#gistcomment-3615875>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOVTFEENZVRPFQJVR2LTHTS43ZK7ANCNFSM4W5HU47Q>
.
it for some reason stays like that even after reboot or shut down
I was able to go in to system settings display and change the screen to normal now its correct, but im worried about the other changes?
Well, the script is open source and you see all the contents - nothing is
hidden. Follow the logic, break it down or understand it, if necessary,
change it, run it, etc.
…On Mon, Feb 1, 2021 at 8:37 PM RogerThorp ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
it for some reason stays like that even after reboot or shut down
I was able to go in to system settings display and change the screen to
normal now its correct, but im worried about the other changes?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/35cbccdffbf0f827ae38#gistcomment-3615923>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOVTFCVXPHCWOTGDE7LZY3S437G5ANCNFSM4W5HU47Q>
.
--
Kalin Chernev
tel: +359878536542
I had no luck, but I was able to get to system settings and go to display
and change settings now screen is no longer upside down, are there any
other changes from the script I need to change?
Thanks
Ray
…On Mon, Feb 1, 2021, 1:25 PM Kalin Chernev ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
To remove the script, remove the rotate-screen.sh file you executed.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/35cbccdffbf0f827ae38#gistcomment-3615856>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASV7AQUIDAYAAPSLOARSEATS43WZVANCNFSM4W5HU47Q>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment