baskerville / sxhkd

Simple X hotkey daemon
BSD 2-Clause "Simplified" License
2.79k stars 138 forks source link

[Feature Request] No daemon option (for temporary binding) #94

Open rieje opened 7 years ago

rieje commented 7 years ago

xbindkeys has the -n option for no-daemon mode. This is incredibly useful for scripts where bindings can be temporarily assigned for the duration of the running script. For example, I can run a script that has xbindkeys re-map the space bar to execute another script which runs xdotools so that I can mouse-over any webpage, hit space bar, and it will copy that webpage's URL into clipboard and append it to a text file. If I were to bind the script to a hotkey via sxhkdrc, then it would have to be an unused hotkey (which is limited and inconvenient).

I realize it goes against the spirit of the name of sxhkd but I wonder how difficult it is to implement such a feature. Or perhaps I can already do something similar with sxhkd. This is the only thing holding me back from switching to sxhkd fully.

baskerville commented 7 years ago

You could specify an extra config and add/remove temporary bindings there (and call pkill -USR1 -x sxhkd to make sxhkd reload its config files).

rieje commented 7 years ago

@baskerville I would need to kill all instances of sxhkd beforehand though, right? Since specifying the config files (sxhkd -c <system config> <temp config>) starts a new instance. I think the only way to not require sxhkd to restart an instance is to move the system config somewhere else and symlink the temp config to ~/.config/sxhkd/sxhkd that the system instance of sxhkd already reads by default then reload the config. This has all sorts of limitations--e.g. temp configs need to be combined with system config manually and updated over time and the need to move files back and forth when the script is executed).

Am I correct?

baskerville commented 7 years ago

Please note that the default configuration file is ~/.config/sxhkd/sxhkdrc, so specifying that as the argument to -c is a waste of keystrokes.

If you want to launch an extra instance to handle the temporary bindings, you need to start it with sxhkd -c EXTRA_CONFIG.

And then send the reload signal to the newest instance: pkill -USR1 -nx sxhkd.

rieje commented 7 years ago

To handle temporary bindings for the duration of the script, I have the following the script:

sxhkd -c temp_sxhkdrc &      # start separate instance for this script only
...
pkill -USR1 -nx sxhkd &         # reload config
...
pkill -nx sxhkd &                    # kill the newest instance of sxhkd, which should always be the one created by this script

When I execute this script, maybe a little under 50% of the time it works as expected--I get the temporary bindings until I cancel the script. However, when I don't get the bindings (no errors reported--the temporary bindings just don't work), then restarting this script will never work unless I execute the script to kill all instances of sxhkd and then start the system-wide permanent bindings:

killall -q sxhkd
while pgrep -x sxhkd >/dev/null; do sleep 1; done
sxhkd &

Any idea what may be the issue?

To be clear, I already have an instance of sxhkd & running via ~/.xinitrc for the system. I've been told that sxhkd doesn't work with multiple instances, but you seem to imply it can so I'm not sure.

tecfu commented 6 years ago

@baskerville , @rieje Killing the sxhkd process isn't a good solution for this problem, because the kill command isn't exactly synchronous. That's why this is working for @rieje only half of the time.

See: https://stackoverflow.com/questions/20132671/how-to-kill-process-synchronously-on-linux

I see two solutions:

[1] Expose a sxhkd command that allows you to disable/enable key bindings on-the-fly. [2] Create a debounce option for commands

BlueDrink9 commented 5 years ago

Making this smooth would be a good way to work around having i3-like modes stored in a separate file. Would be great to see progress here

Konfekt commented 5 years ago

Perhaps https://github.com/hbekel/xchainkeys is in the meanwhile of interest.

BlueDrink9 commented 5 years ago

Xchainkeys is still pretty janky sadly. Almost more effort than it's worth to re-write config for it. I wonder if koekeishiya/skhd could be adapted to linux…