alesya-h / linux_detect_tablet_mode

Detect if your laptop is in normal or tablet mode. Useful for Yoga laptops to disable keyboard/trackpoint/touchpad in a tablet mode
MIT License
138 stars 28 forks source link

Added support for devices that use KEYBOARD_KEY events #25

Closed RhinoRapscallion closed 2 years ago

RhinoRapscallion commented 2 years ago

Good Morning,

I was i the process of setting up your script for my ASUS Laptop when i noticed that instead of my laptop using the switch events that your script looks for, it uses keyboard events.

Feel free to review my code and edit it to fit the script better and improve in my conventions as i am not too familiar with Ruby, that way the script can support more devices

alesya-h commented 2 years ago

Ideally this should be fixed in the kernel, but I think your addition is useful nevertheless.

mohdforever commented 3 months ago

I set a new command to enable/disable laptop mode manually since there is no switch is detected for my ASUS ROG FLOX X16

feel free to review my simple code that could help

!/bin/bash

fconfig="/home/$USER/convertible-mode-indicator"

if [ ! -f "$fconfig" ]; then echo "Creating config file" echo "enabled" > $fconfig var="enabled"

else read -r var< $fconfig echo "laptop mode is : $var"

fi

if [ "$var" = "disabled" ]; then notify-send "Enabling laptop mode ..." echo "enabling laptop mode ..." for id in $(xinput list | grep "Keyboard" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput enable $id; done #to enable keyboard for laptop mode for id in $(xinput list | grep "Touchpad" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput enable $id; done #to enable touchpad for laptop mode for id in $(xinput list | grep "Mouse" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput enable $id; done #to enable mouse for laptop mode for id in $(xinput list | grep "ELAN" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput disable $id; done #to disable touch screen for laptop mode notify-send "laptop mode is enabled" echo "enabled" > $fconfig

elif [ "$var" = "enabled" ]; then notify-send "Disabling laptop mode ... " echo "disabling laptop mode ... " for id in $(xinput list | grep "Keyboard" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput disable $id; done #to disable keyboard for taplet mode for id in $(xinput list | grep "Touchpad" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput disable $id; done #to disable touchpad for taplet mode for id in $(xinput list | grep "Mouse" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput disable $id; done #to disable mouse for taplet mode for id in $(xinput list | grep "ELAN" | grep -oP 'id=\d+' | cut -d= -f2 | paste -s -d' '); do xinput enable $id; done #to enable touch screen for taplet mode notify-send "laptop mode is disabled" echo 'disabled' > $fconfig fi