Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script rotates the screen and touchscreen input, disables or enbles the touchpad, and dis- or enables the virtual keyboard on a Lenovo Yoga 13 or Yoga 2 Pro (source: http://askubuntu.com/q/405628/34298)
#!/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='ELAN Touchscreen'
TouchpadDevice='SynPS/2 Synaptics TouchPad'
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 disable "$TouchpadDevice"
# Remove hashtag below if you want pop-up the virtual keyboard
#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 disable "$TouchpadDevice"
#killall onboard
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 disable "$TouchpadDevice"
#killall onboard
else
echo "Back to normal"
xrandr -o normal
xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $normal
xinput enable "$TouchpadDevice"
#killall onboard
fi
@rubo77

This comment has been minimized.

Show comment
Hide comment
Owner

rubo77 commented Jun 20, 2014

This script is referred to in my guide how to install Ubuntu on a Yoga 2 Pro

@kablamo

This comment has been minimized.

Show comment
Hide comment
@kablamo

kablamo Sep 1, 2014

Awesome. Thank you. Unfortunately onboard is really wonky for me. Also I had to put 'synclient TapButton2=2' etc at the end of this script because it seems like the settings get overwritten each time the touchpad is renabled.

kablamo commented Sep 1, 2014

Awesome. Thank you. Unfortunately onboard is really wonky for me. Also I had to put 'synclient TapButton2=2' etc at the end of this script because it seems like the settings get overwritten each time the touchpad is renabled.

@fv42wid

This comment has been minimized.

Show comment
Hide comment
@fv42wid

fv42wid Oct 31, 2014

I tried installing this script via the yoga 2 link mentioned above by linking it to the keyboard shortcut alt + f5 but it won't work for me. I have ubuntu 14.04 installed. Do either of you guys have any tips for troubleshooting? Thanks for putting this together.

fv42wid commented Oct 31, 2014

I tried installing this script via the yoga 2 link mentioned above by linking it to the keyboard shortcut alt + f5 but it won't work for me. I have ubuntu 14.04 installed. Do either of you guys have any tips for troubleshooting? Thanks for putting this together.

@muaddib1971

This comment has been minimized.

Show comment
Hide comment
@muaddib1971

muaddib1971 Nov 22, 2014

Hi There

I just downloaded this script and made modifications for my hardware - I just purchased a Thinkpad Helix Series 1.

This script worked straight out of the box once I replaced the reference to the devices with their ids. I find the names you are supposed to use even with the output from xinput is ambiguous but that's a linux problem - certainly no problem with this script from my perspective.

And it is the first thing that has actually worked after about a day of searching and experimenting.

I really appreciate your effort here, rubo77.

regards

Hi There

I just downloaded this script and made modifications for my hardware - I just purchased a Thinkpad Helix Series 1.

This script worked straight out of the box once I replaced the reference to the devices with their ids. I find the names you are supposed to use even with the output from xinput is ambiguous but that's a linux problem - certainly no problem with this script from my perspective.

And it is the first thing that has actually worked after about a day of searching and experimenting.

I really appreciate your effort here, rubo77.

regards

@ryanvade

This comment has been minimized.

Show comment
Hide comment
@ryanvade

ryanvade Jan 17, 2015

Is there no way to tie this into the accelerometer?

Is there no way to tie this into the accelerometer?

@Aubreymcfato

This comment has been minimized.

Show comment
Hide comment
@Aubreymcfato

Aubreymcfato Apr 8, 2015

Hi, thanks! It worked well for me, as soon as I chanced the name of the hardware.
A minor issue, though, is that the cursor is now doubled: it remains a shodow cursor that is in the same position as the last rotated screen.

Hi, thanks! It worked well for me, as soon as I chanced the name of the hardware.
A minor issue, though, is that the cursor is now doubled: it remains a shodow cursor that is in the same position as the last rotated screen.

@Mingling94

This comment has been minimized.

Show comment
Hide comment
@Mingling94

Mingling94 Jun 23, 2015

Thank you so much, this takes a lot of skill to set up!

Thank you so much, this takes a lot of skill to set up!

@Mingling94

This comment has been minimized.

Show comment
Hide comment
@Mingling94

Mingling94 Jul 15, 2015

It seems after executing this script, my hi-dpi scaling setting goes away. Not sure how to deal with this :/

It seems after executing this script, my hi-dpi scaling setting goes away. Not sure how to deal with this :/

@dcrystalj

This comment has been minimized.

Show comment
Hide comment
@dcrystalj

dcrystalj Dec 30, 2015

it doesnt disable my keyboard

it doesnt disable my keyboard

@uladkasach

This comment has been minimized.

Show comment
Hide comment
@uladkasach

uladkasach Apr 28, 2016

xinput --list | grep -m3 'Touchscreen' | tail -n1 | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+' will return the id of the touchscreen, without the user having to explicitly specify it.

xinput --list | grep -m3 'Touchscreen' | tail -n1 | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+' will return the id of the touchscreen, without the user having to explicitly specify it.

@elmtreecomputers

This comment has been minimized.

Show comment
Hide comment
@elmtreecomputers

elmtreecomputers Jun 17, 2016

awesome! works very well on HP Spectre X2 Fedora 23
Just need to change the Touchpad to:
SYNAPTICS Synaptics HIDUSB TouchPad V07 Touchpad
I wonder how you can auto detect screen orientation via the gyrometer / accelerometer.

awesome! works very well on HP Spectre X2 Fedora 23
Just need to change the Touchpad to:
SYNAPTICS Synaptics HIDUSB TouchPad V07 Touchpad
I wonder how you can auto detect screen orientation via the gyrometer / accelerometer.

@neatville

This comment has been minimized.

Show comment
Hide comment
@neatville

neatville Sep 18, 2016

I have a lenovo yoga 2 11 and it says the Elan touchscreen isn't found or something. Does anyone know what I could use instead of that.

I have a lenovo yoga 2 11 and it says the Elan touchscreen isn't found or something. Does anyone know what I could use instead of that.

@mvaled

This comment has been minimized.

Show comment
Hide comment
@mvaled

mvaled Nov 10, 2016

xinput --list on my Yoga 900 13ISK2 does not print any Touchpads. There are 3 pointers, though:

$ xinput --list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ SYNA2B29:00 06CB:77C6                   	id=10	[slave  pointer  (2)]
⎜   ↳ ELAN21EF:00 04F3:227C                   	id=11	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Power Button                            	id=8	[slave  keyboard (3)]
    ↳ Lenovo EasyCamera                       	id=9	[slave  keyboard (3)]
    ↳ Ideapad extra buttons                   	id=12	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=13	[slave  keyboard (3)]

How can I go on?

mvaled commented Nov 10, 2016

xinput --list on my Yoga 900 13ISK2 does not print any Touchpads. There are 3 pointers, though:

$ xinput --list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ SYNA2B29:00 06CB:77C6                   	id=10	[slave  pointer  (2)]
⎜   ↳ ELAN21EF:00 04F3:227C                   	id=11	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Power Button                            	id=8	[slave  keyboard (3)]
    ↳ Lenovo EasyCamera                       	id=9	[slave  keyboard (3)]
    ↳ Ideapad extra buttons                   	id=12	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=13	[slave  keyboard (3)]

How can I go on?

@daN4cat

This comment has been minimized.

Show comment
Hide comment
@daN4cat

daN4cat Dec 25, 2016

For Lenovo Yoga 300 (and I assume 900 too @mvaled) use Virtual core XTEST pointer in the script instead of ELAN Touchscreen.

daN4cat commented Dec 25, 2016

For Lenovo Yoga 300 (and I assume 900 too @mvaled) use Virtual core XTEST pointer in the script instead of ELAN Touchscreen.

@HusseinElMotayam

This comment has been minimized.

Show comment
Hide comment
@HusseinElMotayam

HusseinElMotayam Feb 25, 2017

Works perfectly fine. Thank you.

For Lenovo Yoga 3 pro:

TouchscreenDevice='Virtual core XTEST pointer'
TouchpadDevice='SYNA2B22:00 06CB:2714'

Works perfectly fine. Thank you.

For Lenovo Yoga 3 pro:

TouchscreenDevice='Virtual core XTEST pointer'
TouchpadDevice='SYNA2B22:00 06CB:2714'
@mrquincle

This comment has been minimized.

Show comment
Hide comment

https://github.com/mrquincle/yoga-900-auto-rotate/ is directly tied to the accelerometer.

@mrncrt

This comment has been minimized.

Show comment
Hide comment
@mrncrt

mrncrt Jun 3, 2018

Many thanks, works very well with a thinkpad x230T.

mrncrt commented Jun 3, 2018

Many thanks, works very well with a thinkpad x230T.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment