AutoRotate.sh — небольшой скрипт-твик, без которого фактически бесполезны возможности ноутбука-трансформера при работе на большинстве Debian Linux. Немного покопав различную документацию, и посмотрев примеры, мне удалось написать простенький скрипт, который отслеживает положение гироскопа ноутбука через monitor-sensor (из пакета iio-sensor-proxy), и обнаружив изменение его состояния через inotifywait (из пакета inotify-tools), применяет серию команд к графическому серверу xorg (xrandr) и матрице тачскрина (xinput). В результате вы имеете корректно реагирующий на изменение положения ноутбук или планшет под управлением Linux.
Данный скрипт протестирован и используется на Dell Inspiron 13 (5378), под управлением Linux kUbuntu 18.04. Именно с этого устройства взято название тачскрина, передаваемое первым параметром команде xinput в теле скрипта. Если у вас нет тачскрина, то вы можете спокойно удалить эту команду (с параметрами), а так же предваряющий ее оператор «&&»
Дата выпуска: | 2018 |
Совместимость с ОС: | Ubuntu Linux 16+ |
Язык интерфейса: | Английский |
Язык и среда программирования (IDE): | — Bash — Kate |
Особенности программы: |
|
#!/bin/sh # Auto rotate screen based on device orientation # Receives input from monitor-sensor (part of iio-sensor-proxy package) # Screen orientation and launcher location is set based upon accelerometer position # Launcher will be on the left in a landscape orientation and on the bottom in a portrait orientation # This script should be added to startup applications for the user # Clear sensor.log so it doesn't get too long over time > sensor.log # Launch monitor-sensor and store the output in a variable that can be parsed by the rest of the script monitor-sensor >> sensor.log 2>&1 & # Parse output or monitor sensor to get the new orientation whenever the log file is updated # Possibles are: normal, bottom-up, right-up, left-up # Light data will be ignored while inotifywait -e modify sensor.log; do # Read the last line that was added to the file and get the orientation ORIENTATION=$(tail -n 1 sensor.log | grep 'orientation' | grep -oE '[^ ]+$') # Set the actions to be taken for each possible orientation case "$ORIENTATION" in normal) xrandr -o normal && xinput set-prop "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" 0 0 0 0 0 0 0 0 0 ;; bottom-up) xrandr -o inverted && xinput set-prop "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1 ;; right-up) xrandr -o right && xinput set-prop "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1 ;; left-up) xrandr -o left && xinput set-prop "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1 ;; esac done