Skip to content

Instantly share code, notes, and snippets.

@galatolofederico
Created June 2, 2019 14:31
Show Gist options
  • Select an option

  • Save galatolofederico/04b3bf673658ce8b12d318aa495e2cd5 to your computer and use it in GitHub Desktop.

Select an option

Save galatolofederico/04b3bf673658ce8b12d318aa495e2cd5 to your computer and use it in GitHub Desktop.
HP Pavilion x2 tablet mode switch script
#! /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