Created
June 2, 2019 14:31
-
-
Save galatolofederico/04b3bf673658ce8b12d318aa495e2cd5 to your computer and use it in GitHub Desktop.
HP Pavilion x2 tablet mode switch script
This file contains hidden or 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
| #! /usr/bin/bash | |
| KEYBOARD="HID 04f3:074d" | |
| MODE="pc" | |
| pc_mode() { | |
| killall florence | |
| set_layout "it" | |
| } | |
| tablet_mode() { | |
| florence & | |
| } | |
| set_layout () { | |
| kb_list=$(xinput -list | grep "$KEYBOARD" | awk -F'=' '{print $2}' | cut -c 1-2) | |
| for ID in $kb_list | |
| do | |
| setxkbmap -device "${ID}" -layout "$1" > /dev/null 2>&1 || true | |
| done | |
| } | |
| stdbuf -oL -eL libinput debug-events | \ | |
| while read line | |
| do | |
| if [[ $line == *"$KEYBOARD"* ]]; then | |
| if [[ $line == *"DEVICE_ADDED"* && $MODE != "pc" ]]; then | |
| echo "[!] PC MODE" | |
| pc_mode | |
| MODE="pc" | |
| fi | |
| if [[ $line == *"DEVICE_REMOVED"* && $MODE != "tablet" ]]; then | |
| echo "[!] TABLET MODE" | |
| tablet_mode | |
| MODE="tablet" | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment