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

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

Open
rieje opened this issue May 21, 2017 · 8 comments
Open

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

rieje opened this issue May 21, 2017 · 8 comments

Comments

@rieje
Copy link

rieje commented May 21, 2017

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.

@rieje rieje changed the title [feature request] No daemon option [Feature Request] No daemon option (for temporary binding) May 21, 2017
@baskerville
Copy link
Owner

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 rieje closed this as completed May 23, 2017
@rieje
Copy link
Author

rieje commented May 23, 2017

@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?

@rieje rieje reopened this May 23, 2017
@baskerville
Copy link
Owner

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
Copy link
Author

rieje commented May 24, 2017

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
Copy link

tecfu commented Sep 4, 2018

@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
Copy link

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
Copy link

Konfekt commented Apr 30, 2019

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

@BlueDrink9
Copy link

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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants