![]() |
[Announce] [SFOS] Volume/Camera Button Monitor
so many years later, finally implemented a hardware button monitor for sailfish!
functionality is similar to n9-button-monitor. you can use sf-button-monitor to run arbitrary commands while the phone is locked, or unlocked. tested and working on Xperia X and Xperia X Compact, YMMV NOTE: core functionality provided by simply reading from: Code:
/dev/input/by-path/platform-gpio_keys.105-event perl dbus-send (for all CONDITIONS, and for all ACTIONS except cmd(SHELL_CMD)) the following unrelated hacks make this script more useful: -dont unlock the screen when pressing volume/camera -dont control media volume when screen is locked -write window title to a file so window() condition can tell which program is running https://github.com/teleshoes/sf-button-monitor |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
ALSO: this script is only useful if you turn off display-unlock-with-volume/camera with mcetool:
Code:
mcetool --set-exception-length-volume=0 /usr/share/lipstick-jolla-home-qt5/volumecontrol/VolumeControl.qml Code:
*** 473,478 **** |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
I'll be trying that soon on the Proš, it should be very useful, thanks!
Can this be used for events like the following (keyboard open/closed state)? Code:
/dev/input/event2: 1579511420.010 - 0x05/EV_SW - 0x00a/SW_KEYPAD_SLIDE - 0 Code:
/dev/input/event2: 1579511420.010 - 0x05/EV_SW - 0x00a/SW_KEYPAD_SLIDE - 1 |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Very Cool!
On Proš there are different files. Code:
cat /dev/input/by-path/platform-c17a000.i2c-event-kbd Code:
�&^S For kbd open/close, volume and powerbutton i get same formated values from Code:
cat /dev/input/by-path/platform-soc\:gpio_keys-event Code:
platform-1711a000.sound-tavil-event |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
on x compact, SFOS 3.2.1.20, the key is in the 10th byte and the value (press/release) is in the 12th. (each key press/release produces 16 bytes)
just cat it to a file, press a single key, ctrl+c, and then read the bytes (with hexdump or something). do it 3x with the same key, and 3x with a different key and compare/contrast |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Will try. Thanks for the explanation!
But i have to correct, your script with adapted path to that of the Proš gives output on exactly one key of the hardware keyboard. It is the w key on QWERTZ / q key on QWERTY that does that if pressed multiple times in a row: Code:
EVENT: CAM_HALF => press 1239ms (ch-press) https://mosushi.de/misc/keyboard-single1.txt Above link is cat > keyboard-single1.txt with only the "1" pressed once. https://mosushi.de/misc/keyboard-3x1.txt This is the cat > keyboard-3x1.txt if i press the "1" key three times followed by "2" key three times. Trying to makes sense of the output, figure to still post it quick since you all are faster. lol. |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
in that case: modify my script, adding this line after line 195:
print "$buttonId ($value)\n"; then run it, press those buttons you want to do, and then add lines around 112 like this: Code:
[qw(16 KEY_W kw)], |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Perfect, thank you.
Now i understand some more of the script. I can print the assigned value to every key if i add them all in the block around line 115. Specific to Proš: "sym" is code 249. "FX" is code 125. "Yellow Mod" is code 100. I guess the 100 is due to TheKits kernel mod to make it usable in sfos xkbd, right @kabouik? |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
btw, if you get something cool working for you, please pull request your changes. i might not add them to master since i cannot test it in any way (i ONLY have xperias), but others might benefit from it, and i might buy an fxtec soon myself ;)
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
EDIT: Now i have the script altered for gpio read out and found code 10 is the state of the Keyboard. 10 - release is opened 10 - pressed is closed EDIT 2: Now i am able to switch on the keyboard backlight when it opens with this action in sf-button-monitor.conf Code:
action=cmd(echo 1 > /sys/class/leds/keyboard-backlight/brightness),kb,always Code:
[qw(10 KBD_STATE kb)], EDIT 3: I just created a .desktop file in /user/share/applications/ to start the script from app-grid. Works for now :P |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
Quote:
nice! are you running this as root btw, or does nemo have write perms on that brightness device? if the latter, ill happily add this as an action, and kb as a button, if it works at the same time as mine and you can test it on yours |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
I was thinking how to have the script always running conveniently.
Monitoring it i found no obvious cpu usage, thats nice. As a patch it would be started after boot but patches are ment to alter existing files, not to start up scripts, right? They way i am doing currently is okish, only after boot i need to manually hit the Kbdlight starter and the script runs until killed. But how to do this correct, is my noob question ;) The script runs without superuser privs, as regular nemo user. |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
no idea the 'correct' way to do this, but patchmanager is probably not a good way to do it, if you even can make it start a long-lived script.
i personally do all my auto-start crap like this: 1) make service file to run /usr/local/bin/autostart Code:
nemo@sx:~$ cat /usr/lib/systemd/user/auto-start.service Code:
nemo@sx:~$ ls -al /home/nemo/.config/systemd/user/auto-start.service /home/nemo/.config/systemd/user/user-session.target.wants/auto-start.service Code:
nemo@sx:~$ cat /usr/local/bin/autostart |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Thanks to both of you for progressing this fast! I didn't actually had the time to try myself and you already got something working. :D I guess I'll wait until your changes are merged Mosen. :>
Quote:
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Thanks for the explanation @wolke. That is some cool stuff. Will do for sure but i realize i derail your thread into things not related to your original topic.
In that regard it would be most interesting and useful to not only listen from one source $INPUT_DEV but multiple ones. On Proš we have /dev/input/by-path/platform-soc\:gpio_keys-event For volume up, cam-button and Kbd-state /dev/input/by-path/platform-c17a000.i2c-event-kbd For the keys on the hwkbd /dev/input/event0 For volume down and the power button. How to combine those sources in one script to have all keys available to assign actions too? |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
It also provides an example of a simple "one-shot" systemd system unit being deployed. Note that you have to deploy a user unit at the slightly different path /etc/systemd/user/ (= %{_sysconfdir}/systemd/user/, but do not use the OS' path /usr/lib/systemd/user/ as shown in section 1). You also have to let RPM create the [Install] section links (result shown by @wolke in section 2) by a systemctl --user enable <unit> in a %post section and delete them per systemctl --user disable <unit> in a %preun section. Do not create them manually (either literally or in an RPM). @mosen, you may even clone ("fork" in Github / Gitlab parlance) the mount-sdcard git repository as a starting point, as the git directory structure seems to fit well. RPMs can be easily built on the device per: * Preparation (once)
The only RPM documentation which comes somewhat close to a reference is still (though old and unmaintained): http://ftp.rpm.org/max-rpm/index.html Plus many, many guides for noobs, absolute beginners, fresh starters, DAUs etc. exist (but none for advanced packagers) with lots of examples but no real explanations. The least worse of those are probably https://rpm-guide.readthedocs.io/en/latest/ and https://docs.fedoraproject.org/en-US...ide/index.html P.S.: Better substitute every occurrence of /home/nemo/ in section 3 with ~/ to make it work for every user (as Jolla slowly prepares SailfishOS for multiple users). HTH |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
open $fh, "-|", "cat", "file1", "file2"; see if that works. im not sure its a good idea to do the kb events one tho, that device probably gets a LOT of output as you type, and my script assumes relatively infrequent events EDIT: of course the above doesnt work, wasnt thinking. use IO::Select and do can_read |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
try something like this:
(untested on my side, and i wont be trying to support keyboard keys, i think) Code:
diff --git a/src/sf-button-monitor b/src/sf-button-monitor |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Not directly related to wolke's script, but related to the current discussion: we now have keyboard backlight support on the Proš with mce thanks to Elros34: https://github.com/sailfish-on-fxtec...ment-577118740
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
added a bunch of features:
conditions: always, screenLocked, screenUnlocked, home, app(REGEX), noapp, anyapp, android actions: cmd(SHELL_CMD), torch, screenshot, reboot, shutdown, openCamera, selfie, newAlarm, newNote, writeEmail patterns: e.g: VU(VD VD) => hold V+, press V- twice, release V- |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
MISSING FEATURES:
1) DONE get pid or command name of topmost window when that window is an aliendalvik app the pid returned by the below cmd is for `system_server`: Code:
dbus-send --print-reply --system NOTE: this is done, but requires a hack in lipstick QML https://talk.maemo.org/showpost.php?...8&postcount=30 2) ]keep-alive while locked without draining battery horribly (vol buttons dont wake phone up, and so sometimes the actions dont work) JUST GONNA USE keepalive-tool FOREVER :( 3) DONE-ISH long-press keys just needs some clever event handling that i havent had time to implement 4) torch on/off (NOT toggle, which is already done) probably easy to query torch state with DBUS, but if not, i could just write directly to the LED devices. (i used to long press vol for torch, and release to turn it off, and liked that a lot) 5) multiple input devices, configuration options for input devices 6) support for optional EXACT pattern matching (have to not push any other keys before, in the middle, or after) maybe: "^vu vu$" or something 7) configuration options for timeouts/delays/etc 8) SOLVED-EXTERNALLY OPTIONALLY disable volume button default actions, e.g. in certain apps (this would probably be completely separate from sf-button-monitor, if i can implement it) solution: add a dconf config item to volume control QML to optionally ignore /usr/share/lipstick-jolla-home-qt5/volumecontrol/VolumeControl.qml see: patch 9) new conditions: landscape, portrait 10) new action: forceClose (kill -9 pid of topmost window) 11) new action: lockOrientation 12) (optionally) support power button with journalctl mce |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
if anyone knows how to do #1, #2, #4 or #8, it would be much appreciated
also, anyone have any feature requests (in addition to #5) while im still actively working on this? |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
If it's possible, can you add : - condition : screen orientation - action : screen orientation lock, force to close (kill -9) current app Screen orientation lock could be nice with the Pro1, when the keyboard is opened. However I don't know how to do the screen stuff :( EDIT : a word missing : screen lock -> screen orientation lock |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
would it be possible to add a feature to run something when a button is double-clicked?
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
Quote:
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
AARGHHH
i just tried for like half an hour straight to find a way to get the app name of the topmost window for android apps (lipstick dbus tells me its "system_server"). is this REALLY that hard? is there some obvious method im just not thinking of? maybe some dbus api i dont know about? or some wayland thing to get the last kb-focused window or something.... |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
yo, i hate wayland. couldnt there be some standard way of doing this for root users? i can list, kill, send keyboard input to, and otherwise manipulate every process on the system...but i cant know which one has active keyboard focus?
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
fukket, im just gonna modify goddamn lipstick QML to write window title to a file in /tmp
bastards |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
sigh, here it is. if you do this, then window() condition will match window title of the most recently opened app....
the file in question is: /usr/share/lipstick-jolla-home-qt5/switcher/Switcher.qml Code:
commit 4564109ada4d5e5f971bb3d173252ecc5a70ecff (HEAD -> master) |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
still working in (2). i cant figure out a way cause read() to actually wake up when theres input from the device.
anyone know a way to magically bless a process, or file on the filesystem, or something, that will prevent or interrupt deep sleep? |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
so i decided to just run `keepalive-tool sf-button-monitor` to never let the phone deep sleep, ever.
my battery usage for a full day used to be 100%=>72%, and now its 100%=>61%. this is easily worth it, to have the button actions always work without unlocking the phone first. i had not realized how LITTLE deep sleep was actually doing for me. |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
3 months of keepalive-tool running constantly, and my battery hasnt died once.
(the volume buttons just always work, locked or unlocked, like on the N9) |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
added repeated-commands
e.g.: action=repeat(500, brightness +1),ch-press vu-press,always => hold camera-half and volume-up to have brightness incrementally increase (where `brightness` is a script you write) |
Re: [Announce] [SFOS] Volume/Camera Button Monitor
i get error loop on line 264 and 268, read on closed filehandle, use of uninitialized value $buttonId...
|
Re: [Announce] [SFOS] Volume/Camera Button Monitor
updated for Xperia 10 III
added support for power button and "google assist" (camera) button. power button also works now on Xperia XZ2 Compact, and maybe others (but not Xperia X or Xperia X Compact) (power button still of course also always locks/unlocks the phone, so this is maybe not that useful) |
All times are GMT. The time now is 19:05. |
vBulletin® Version 3.8.8