From 0b00ebaa33d0cbc62da7407a91e69ff648e39fdb Mon Sep 17 00:00:00 2001 From: wassname Date: Thu, 14 Mar 2019 09:30:09 +0800 Subject: [PATCH] use acpi listen to trigger tablet mode --- .gitignore | 159 +++++++++++++++++++++++++ README.md | 7 +- systemd/yoga-tablet.service | 7 +- tablet/acpi_tablet_monitor.sh | 28 +++++ tablet/events/thinkpad-tablet-disabled | 5 - tablet/events/thinkpad-tablet-enabled | 6 - tablet/mouse-toggle.sh | 37 ------ 7 files changed, 194 insertions(+), 55 deletions(-) create mode 100644 .gitignore create mode 100755 tablet/acpi_tablet_monitor.sh delete mode 100644 tablet/events/thinkpad-tablet-disabled delete mode 100644 tablet/events/thinkpad-tablet-enabled delete mode 100755 tablet/mouse-toggle.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01e45da --- /dev/null +++ b/.gitignore @@ -0,0 +1,159 @@ + +# Created by https://www.gitignore.io/api/vim,linux,python +# Edit at https://www.gitignore.io/?templates=vim,linux,python + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### Python Patch ### +.venv/ + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# End of https://www.gitignore.io/api/vim,linux,python diff --git a/README.md b/README.md index 7d85483..059f4c8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Status: - [x] turn off touchscreen when using pen - [ ] turn off touchpad and trackpoint in tablet mode - [x] Changed to use acpi hook since it lacks hotkey - - [ ] BUG: doesn't always fire + - [ ] BUG: doesn't always fire + - [x] I'm adding this to startup `/usr/bin/acpi_listen | /opt/thinkpad-x380-yoga-scripts/tablet/acpi_tablet_monitor.sh` - [x] BUG: touchpad wont enable again, this seems to be a driver bug forked from :https://github.com/ffejery/thinkpad-l380-yoga-scripts @@ -48,10 +49,6 @@ sudo systemctl status yoga-rotate@${USER}.service sudo systemctl enable yoga-tablet.service sudo systemctl start yoga-tablet.service sudo systemctl status yoga-tablet.service - - -# install acpi hooks (since the tablet mode acpi doesn't seem to register as a hotkey on the x380) -sudo cp -r ./tablet/* /etc/acpi/ ``` # Scripts should fix: diff --git a/systemd/yoga-tablet.service b/systemd/yoga-tablet.service index 41e4204..5291193 100644 --- a/systemd/yoga-tablet.service +++ b/systemd/yoga-tablet.service @@ -4,12 +4,15 @@ Requires=display-manager.service After=display-manager.service [Service] -ExecStart=/bin/bash /opt/thinkpad-x380-yoga-scripts/tablet/mouse-toggle.sh +ExecStart=/bin/bash -c '/usr/bin/acpi_listen | /opt/thinkpad-x380-yoga-scripts/tablet/acpi_tablet_monitor.sh' KillMode=process Environment="DISPLAY=:0" -Type=forking +Type=simple Restart=always RestartSec=5 [Install] WantedBy=multi-user.target + + + \ No newline at end of file diff --git a/tablet/acpi_tablet_monitor.sh b/tablet/acpi_tablet_monitor.sh new file mode 100755 index 0000000..57cdd1b --- /dev/null +++ b/tablet/acpi_tablet_monitor.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +while true ; do +read ACPI_EVENT +case "$ACPI_EVENT" in +"ibm/hotkey IBM0068:00 00000080 0000500c") +echo "Stylus removed" +;; +"ibm/hotkey IBM0068:00 00000080 0000500b") +echo "Stylus replaced" +;; +"video/tabletmode TBLT 0000008A 00000001") +xinput disable "ETPS/2 Elantech TrackPoint" +synclient TouchpadOff=1 +nohup onboard >/dev/null 2>&1 & +echo "Tablet mode" +;; +"video/tabletmode TBLT 0000008A 00000000") +xinput enable "ETPS/2 Elantech TrackPoint" +synclient TouchpadOff=0 +killall onboard +echo "Normal mode" +;; +*) +echo "Unknown event: '$ACPI_EVENT'" +;; +esac +done diff --git a/tablet/events/thinkpad-tablet-disabled b/tablet/events/thinkpad-tablet-disabled deleted file mode 100644 index c456fd4..0000000 --- a/tablet/events/thinkpad-tablet-disabled +++ /dev/null @@ -1,5 +0,0 @@ -# /etc/acpi/events/thinkpad-tablet-disabled -# This is called when the lid is placed in normal position on -# Lenovo ThinkPad X380 Tablet -event=video/tabletmode TBLT 0000008A 00000000 -action=/etc/acpi/mouse-toggle.sh on diff --git a/tablet/events/thinkpad-tablet-enabled b/tablet/events/thinkpad-tablet-enabled deleted file mode 100644 index 51d22a5..0000000 --- a/tablet/events/thinkpad-tablet-enabled +++ /dev/null @@ -1,6 +0,0 @@ -# /etc/acpi/events/thinkpad-tablet-enabled -# This is called when the lid is placed in tablet position on -# Lenovo ThinkPad X380 Tablet -event=video/tabletmode TBLT 0000008A 00000001 -action=/etc/acpi/mouse-toggle.sh off - diff --git a/tablet/mouse-toggle.sh b/tablet/mouse-toggle.sh deleted file mode 100755 index 99a9b0d..0000000 --- a/tablet/mouse-toggle.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# Simple script to toggle on/off the ThinkPad Yoga's Trackpoint and Clickpad -# and kill/launch. To be binded with switches when switching between tablet/laptop -# modes. -# -# Must be run as user running X11. -# -# https://github.com/ffejery/thinkpad-x380-yoga-scripts -# -# Originally from AdmiralAkber: -# https://github.com/admiralakber/thinkpad-yoga-scripts -# Author: AdmiralAkber -case "$1" in - off) - logger "Tablet mode on, mouse $1" - # TODO do touchpad buttons - # Trackpoint includes the red joystick and also the mouse buttons - xinput disable "ETPS/2 Elantech TrackPoint" - # BUG workaround: using xinput to turn the touchpad off works, but I can't turn it back on without restarting. synclient works however. - #xinput disable "ETPS/2 Elantech Touchpad" - synclient TouchpadOff=1 - nohup onboard >/dev/null 2>&1 & - ;; - on) - logger "Tablet mode off, mouse $1" - # for some reason this isn't working, we can't enable the touchpad again! - - #xinput enable "ETPS/2 Elantech Touchpad" - xinput enable "ETPS/2 Elantech TrackPoint" - synclient TouchpadOff=0 - killall onboard - ;; - *) - logger "ACPI action undefined: $1" - ;; -esac -