Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New package: auto lock the attached keyboard when flipped behind tablet #565

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions PKGBUILDS/pine64/acpi-kbd-autolock-pinetab2/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Maintainer: ScottFreeCode <scottfreecode@gmail.com>
pkgname=acpi-kbd-autolock-pinetab2
pkgver=0.1.0
pkgrel=1
pkgdesc="Automatically turn off the hardware/case keyboard when it is flipped shut (or behind the tablet), for the PineTab 2"
arch=(any)
url="https://github.com/dreemurrs-embedded/Pine64-Arch"
license=('BSD')
depends=('acpid')
source=(lid toggle-keyboard.sh)

package() {
install -D -m644 "$srcdir"/lid \
"$pkgdir"/etc/acpi/events/lid
install -D -m755 "$srcdir"/toggle-keyboard.sh \
"$pkgdir"/etc/acpi/toggle-keyboard.sh
}

install=acpi-kbd-autolock-pinetab2.install

md5sums=('fdac6076a6c9cf9e3fad89302fc06cf9'
'c8862783b76c9addf604ba095c9814b4')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
post_install() {
systemctl enable --now acpid
}
2 changes: 2 additions & 0 deletions PKGBUILDS/pine64/acpi-kbd-autolock-pinetab2/lid
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
event=button/lid
action=/etc/acpi/toggle-keyboard.sh %e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use logind for this? iirc it has an option to handle lid switch events, and that way you don't need to add an extra dependency.

Copy link
Author

@ScottFreeCode ScottFreeCode Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to dig up my research, but from what I read the systemd login interface only lets you choose from a predefined list of behaviors – screen off, suspend, shutdown, etc. – and there's theoretically a way to redefine those behaviors (suspend.target, etc.) but I didn't really think that was appropriate (anything more than screen off, e.g. suspend, should prevent keyboard usage anyway; and more importantly people's screens might be configured to turn off via other conditions as well), plus I didn't see an event that can turn the keyboard back on. As far as I was able to find out, ACPI is intended to be the lower level interface for more control of customization like this.

20 changes: 20 additions & 0 deletions PKGBUILDS/pine64/acpi-kbd-autolock-pinetab2/toggle-keyboard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

ACTION=bind
MESSAGE=on
if [[ "$3" = "close" ]]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we had a command (let's just call it lid-closed for example) that detected whether the keyboard's current state is flipped shut, then we could call this script on boot with the following modification:

Suggested change
if [[ "$3" = "close" ]]
if [[ "$3" = "close" ]] || lid-closed

then
ACTION=unbind
MESSAGE=off
fi

KEYBOARD=4-1
#KEYBOARD=`grep -r --include=uevent Touchpad /sys/devices/ | cut -d/ -f7 | grep -v : | sort | uniq`

echo "$KEYBOARD" > /sys/bus/usb/drivers/usb/"$ACTION"

for user in `who | cut -f1 -d\ | sort | uniq`
do
sudo -u "$user" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/"`id -u $user`"/bus \
notify-send -a 'PineTab2 case' "Keyboard turned $MESSAGE."
done