~anjan/public-inbox

sxmo-userscripts: Add hooks directory and android_buttons hook v2 SUPERSEDED

~flimflam
~flimflam: 2
 Add hooks directory and android_buttons hook
 Fix android_buttons hook for sxmo-utils-1.5.2.1

 4 files changed, 123 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~anjan/public-inbox/patches/25687/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH sxmo-userscripts v2 1/2] Add hooks directory and android_buttons hook Export this patch

~flimflam
From: David Kennedy <qpg7x5@masqt.com>

---
 hooks/README.md                    | 35 ++++++++++++++++++++++
 hooks/inputhandler/README.md       | 17 +++++++++++
 hooks/inputhandler/android_buttons | 48 ++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 hooks/README.md
 create mode 100644 hooks/inputhandler/README.md
 create mode 100755 hooks/inputhandler/android_buttons

diff --git a/hooks/README.md b/hooks/README.md
new file mode 100644
index 0000000..3b933b0
--- /dev/null
+++ b/hooks/README.md
@@ -0,0 +1,35 @@
# User hooks

This directory contains example hooks contributed by the community.

# Usage

To use one of these hooks, copy it to `$XDG_CONFIG_HOME/sxmo/hooks/[name]`,
where `[name]` is the name of the directory containing the file, and make it
executable.

For example:

```
$ cp inputhandler/android_buttons $XDG_CONFIG_HOME/sxmo/hooks/inputhandler
$ chmod u+x $XDG_CONFIG_HOME/sxmo/hooks/inputhandler
```

# Contributing

Add your own hooks under a directory corresponding to the hook name and rename
the file itself something descriptive. This way, we can have multiple examples
of each type of hook organized like so:

```
hooks/
    inputhandler/
        README.md
        android_buttons
        inverted_volume
	...
```

Please also add a brief description of your hook to the README in its parent
directory.

diff --git a/hooks/inputhandler/README.md b/hooks/inputhandler/README.md
new file mode 100644
index 0000000..ebda088
--- /dev/null
+++ b/hooks/inputhandler/README.md
@@ -0,0 +1,17 @@
# inputhandler hooks

This directory contains example inputhandler hooks.

# Caveats

As of version 1.5.1, this hook is only executed when the screen is unlocked.
It's not possible to modify the behavior of the power button when locked.

# Contents

## android_buttons
- Author: David Kennedy
- License: WTFPL
- Description: Modifies the hardware button behavior to mimic a typical Android
  device.

diff --git a/hooks/inputhandler/android_buttons b/hooks/inputhandler/android_buttons
new file mode 100755
index 0000000..99310a8
--- /dev/null
+++ b/hooks/inputhandler/android_buttons
@@ -0,0 +1,48 @@
#!/bin/sh

# This hook modifies the hardware button behavior to mimic a typical Android
# device, i.e.:
#
# - The power button locks the screen and turns it off
# - The volume up button turns the volume up
# - The volume down button turns the volume down
#
# It also adds a couple features that don't normally exist on Android:
#
# - Holding the power button enters CRUST suspend
# - Holding the volume down button mutes the volume
#
# You still have to hold down the power button to unlock the screen.

WMCLASS="$1"
WMNAME="$2"
ACTION="$3"

# You must exit 0 if you handled the input to not trigger default behaviors

case "$ACTION" in
	powerbutton_three)
		sxmo_screenlock.sh crust
		exit 0
		;;
	powerbutton_*)
		sxmo_screenlock.sh off
		exit 0
		;;
	volup_*)
		sxmo_vol.sh unmute
		sxmo_vol.sh up
		exit 0
		;;
	voldown_three)
		sxmo_vol.sh mute
		exit 0
		;;
	voldown_*)
		sxmo_vol.sh down
		exit 0
		;;
esac

exit 1

-- 
2.32.0

[PATCH sxmo-userscripts v2 2/2] Fix android_buttons hook for sxmo-utils-1.5.2.1 Export this patch

~flimflam
From: David Kennedy <qpg7x5@masqt.com>

---
 hooks/inputhandler/android_buttons | 33 +++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/hooks/inputhandler/android_buttons b/hooks/inputhandler/android_buttons
index 99310a8..2db27c0 100755
--- a/hooks/inputhandler/android_buttons
+++ b/hooks/inputhandler/android_buttons
@@ -3,16 +3,13 @@
# This hook modifies the hardware button behavior to mimic a typical Android
# device, i.e.:
#
# - The power button locks the screen and turns it off
# - The power button toggles the display on or off
# - The volume up button turns the volume up
# - The volume down button turns the volume down
#
# It also adds a couple features that don't normally exist on Android:
# In addition:
#
# - Holding the power button enters CRUST suspend
# - Holding the volume down button mutes the volume
#
# You still have to hold down the power button to unlock the screen.

WMCLASS="$1"
WMNAME="$2"
@@ -20,13 +17,29 @@ ACTION="$3"

# You must exit 0 if you handled the input to not trigger default behaviors

DEBUG=0

debug_log() {
	[ $DEBUG -eq 0 ] && return
	echo "$@" >> inputhandler-hook.log
}

toggle_screenlock() {
	local action="$1"
	local state="$(sxmo_screenlock.sh getCurState)"

	if [ "$state" = off ]; then
		debug_log "action=$action, old state=$state, new state=unlock"
		sxmo_screenlock.sh unlock
	else
		debug_log "action=$action, old state=$state, new state=off"
		sxmo_screenlock.sh off
	fi
}

case "$ACTION" in
	powerbutton_three)
		sxmo_screenlock.sh crust
		exit 0
		;;
	powerbutton_*)
		sxmo_screenlock.sh off
		toggle_screenlock "$ACTION"
		exit 0
		;;
	volup_*)
-- 
2.32.0