Initial commit.

This commit is contained in:
2018-10-02 20:14:20 +02:00
commit ab49ee4cee
8 changed files with 269 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
event=ibm/hotkey LEN0268:00 00000080 00001315
action=/etc/acpi/thinkpad-favbutton.sh
+2
View File
@@ -0,0 +1,2 @@
event=ibm/hotkey LEN0268:00 00000080 00001315
action=/etc/acpi/thinkpad-kdb-backlight.sh
+2
View File
@@ -0,0 +1,2 @@
event=video/tabletmode
action=/etc/acpi/thinkpad-tabletmode.sh %e
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env python2
"""
thinkpad-rotate.py
Rotates any detected screen, wacom digitizers, touchscreens,
touchpad/trackpoint based on orientation gathered from accelerometer.
Tested with Lenovo Thinkpad Yoga S1
https://github.com/admiralakber/thinkpad-yoga-scripts
Acknowledgements:
Modified from source:
https://gist.githubusercontent.com/ei-grad/4d9d23b1463a99d24a8d/raw/rotate.py
"""
### BEGIN Configurables
rotate_pens = True # Set false if your DE rotates pen for you
disable_touchpads = False # Don't use in conjunction with tablet-mode
ignore_touchpads = True
grace_time = 3
### END Configurables
from time import sleep, time
from os import path as op
import sys
from subprocess import check_call, check_output
from glob import glob
from os import environ
def bdopen(fname):
return open(op.join(basedir, fname))
def read(fname):
return bdopen(fname).read()
for basedir in glob('/sys/bus/iio/devices/iio:device*'):
if 'accel' in read('name'):
break
else:
sys.stderr.write("Can't find an accellerator device!\n")
sys.exit(1)
env = environ.copy()
scale = float(read('in_accel_scale'))
g = 7.0 # (m^2 / s) sensibility, gravity trigger
STATES = [
{'rot': 'normal', 'pen': 'none', 'coord': '1 0 0 0 1 0 0 0 1', 'touchpad': 'enable',
'check': lambda x, y: y <= -g},
{'rot': 'inverted', 'pen': 'half', 'coord': '-1 0 1 0 -1 1 0 0 1', 'touchpad': 'disable',
'check': lambda x, y: y >= g},
{'rot': 'left', 'pen': 'ccw', 'coord': '0 -1 1 1 0 0 0 0 1', 'touchpad': 'disable',
'check': lambda x, y: x >= g},
{'rot': 'right', 'pen': 'cw', 'coord': '0 1 0 -1 0 1 0 0 1', 'touchpad': 'disable',
'check': lambda x, y: x <= -g},
]
def rotate(state):
s = STATES[state]
check_call(['/usr/local/bin/thinkpad-rotate.rb', s['rot']], env=env)
def read_accel(fp):
fp.seek(0)
return float(fp.read()) * scale
if __name__ == '__main__':
accel_x = bdopen('in_accel_x_raw')
accel_y = bdopen('in_accel_y_raw')
current_state = None
next_state=None
next_ts=0.0
while True:
x = read_accel(accel_x)
y = read_accel(accel_y)
for i in range(4):
if i == current_state:
continue
if STATES[i]['check'](x, y):
ts = time()
if not next_state == i:
next_state = i
next_ts = ts
elif ts - next_ts >= grace_time:
current_state = i
rotate(i)
break
sleep(1)
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
# ToDo
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
DEVICE=/sys/devices/platform/thinkpad_acpi/leds/tpacpi\:\:kbd_backlight/brightness
CUR_VAL=$(cat $DEVICE)
case $CUR_VAL in
0)
echo "1" > $DEVICE
;;
1)
echo "2" > $DEVICE
;;
2)
echo "0" > $DEVICE
;;
esac
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
MODE=$4
USER=$(ps aux | grep startkde | grep -v sddm | grep -v grep | awk '{print $1}')
export DISPLAY=:0
case $MODE in
00000001)
# Tabletmode ON
sudo -u $USER xinput set-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 0
sudo -u $USER xinput set-prop "TPPS/2 Elan TrackPoint" "Device Enabled" 0
sudo -u $USER /etc/acpi/thinkpad-autorotate.py &
sudo -u $USER /usr/bin/onboard &
;;
00000000)
# Tabletmode OFF
sudo -u $USER xinput set-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 1
sudo -u $USER xinput set-prop "TPPS/2 Elan TrackPoint" "Device Enabled" 1
pkill -f thinkpad-autorotate.py
pkill -f /usr/bin/onboard
sudo -u $USER /usr/local/bin/thinkpad-rotate.rb normal
;;
esac