-
-
Save emiller/6488449 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # | |
| # yoga-auto-rotate -- ghetto-style tablet mode, with keyboard and all. | |
| # | |
| # Simple little script that will detect an orientation change for a | |
| # Lenovo Yoga 13 (very hackily) and adjust the active display's | |
| # orientation and disable/enable the touchpad as necessary. | |
| # | |
| # The Yoga 13 will emit keycode `e03e` at one second intervals | |
| # when the screen is flipped into tablet mode. Since this keycode | |
| # isn't actually mapped to anything by default, this script will | |
| # use those events to determine if it should rotate the display or | |
| # not. | |
| # | |
| # To make this work, the keycode that the system emits needs to be | |
| # mapped first. You can pick a keycode to map it to via the `xmodmap -pk` | |
| # command. The keycode mapping I used personally was `231`, for example: | |
| # | |
| # setkeycodes e03e 231 | |
| # | |
| # I run the above `setkeycodes` mapping command on start-up, and | |
| # set an additional hotkey binding in my window manager to execute the | |
| # `yoga-auto-rotate` script whenever the hotkey is pressed. | |
| # | |
| # It may be necessary to add the following commands to `/etc/sudoers` | |
| # for your user or group, as `setkeycodes` and `input-events` may not | |
| # allow it by default: | |
| # | |
| # %users ALL=NOPASSWD: /usr/bin/setkeycodes, /usr/bin/input-events | |
| # | |
| # @author emiller | |
| # @date 2013-09-08 | |
| input="Virtual core keyboard" | |
| output="LVDS1" | |
| touchpad="SynPS/2 Synaptics TouchPad" | |
| stub="/tmp/.yoga-tablet-watcher" | |
| interval=2 | |
| function timestamp() { | |
| seconds=-1 | |
| if [ -f $stub ]; then | |
| filemtime=`stat -c %Y $stub` | |
| currtime=`date +%s` | |
| seconds=$(( ($currtime - $filemtime) )) | |
| fi | |
| echo $seconds | |
| } | |
| function toggle_tablet() { | |
| orientation=`xrandr --properties | grep $output | cut -d ' ' -f4 | sed 's/(//g'` | |
| case $1 in | |
| enable) | |
| xrandr --output $output --rotate right | |
| xinput disable "$touchpad" | |
| which onboard && nohup onboard >/dev/null 2>&1 & | |
| which easystroke && nohup easystroke >/dev/null 2>&1 & | |
| ;; | |
| disable) | |
| xrandr --output $output --rotate normal | |
| which onboard && pkill -9 -f onboard | |
| which easystroke && pkill -9 -f easystroke | |
| xinput enable "$touchpad" | |
| ;; | |
| esac | |
| } | |
| function update_timer() { | |
| echo $(timestamp) > $stub | |
| } | |
| function clear_timer() { | |
| rm -f $stub | |
| } | |
| function watcher() { | |
| toggle_tablet "enable" | |
| update_timer | |
| sudo input-events -t $interval `xinput --list "$input" | head -n 1 | cut -d= -f2 | sed 's/\S*\[.*//g'` | |
| toggle_tablet "disable" | |
| clear_timer | |
| } | |
| test -f $stub || { watcher & } |
Hello,
I own an hp spectre x360 (late 2017) laptop. This is the only script I find promising so far. But I get "output LVDS1 not found". Note that both the input and the touchpad names are the same with yours (xinput list). So I wonder, what is this output variable correspond to? And, if this script is not suitable for me are you aware of another one for my model. I am using Ubuntu 16.04
@johnnemo LVDS1 is your display's identifier. It may be a different one on your HP laptop. You can get a listing of all displays using the xrandr command. In my case, it is called eDP-1.
You might also want to check out this program: https://github.com/mrquincle/yoga-900-auto-rotate/
I just got a Lenovo IdeaPad Flex 14API 81ss
How would i determine the input/ouput or find device names like "touchpad"
I just wanted to bring this tool to your attention: https://github.com/wolfgang-noichl/magick-rotation
I more or less blindly forked it from an orphaned launchpad project, to keep my Fujitsu T901 running. But I would be very happy for contributors who want to support their convertible as well :)
the device ID fed to the input-events via $(xinput --list ...) is not matching at least for Ubuntu 16.04.
@chuugar, btw, this mismatch seems to be the reason why it all returns to original position -- because now events are being catched from the wrong /dev/input/event* and input-events just exits