sxhkd icon indicating copy to clipboard operation
sxhkd copied to clipboard

REQUEST: Simple plugin system

Open progandy opened this issue 11 years ago • 4 comments

I'd like to be able to create simple plugins for ipc mechanisms like i3-msg or herbstclient. It feels wasteful to run an executable each time I want to send a keystroke to my window manager. I envision something like this: Allow the user to list the names of plugins in the configuration file and use dlopen/dlclose. The API would be very simple with 3 functions:

bool load(void); // during configuration load, after dlopen
int call(char *unparsed_args, char **argv, int argc); // plugin is called as a command
void unload(void); // during configuration reset and program end, before dlclose

Extend the configuration format. If a command starts with $ followed by the pluginname, run the plugin instead of a shell. You'll have to add a small state machine to parse the arguments into an array, but that should not be too difficult.

As a minor addition that can reuse the argument parser, I'd also suggest another command prefix. Use & in order to run the command directly without invoking a shell. In that case you might also consider adding a variable replacement for $HOME (e.g. %home)

progandy avatar Oct 06 '14 02:10 progandy

I can almost guarantee this won't happen. For one, compared to the time it takes you to press a hotkey, starting an executable takes infinitely little time.

Stebalien avatar Oct 06 '14 04:10 Stebalien

No problem. I just hate wasting cpu cycles, maybe I'll try it on my own some time.

progandy avatar Oct 06 '14 14:10 progandy

Quick test:

$ time (repeat 10000 echo "hi" > /dev/null)
( repeat 10000; do; echo "hi" > /dev/null; done; )  0.02s user 0.02s system 96% cpu 0.034 total

That's 3.4µs per echo.

Loading and rendering this text will have cost you millions of times the processor cycles that you would save in a the next few thousand years by optimising this.

There's always a relevant xkcd. :)

anko avatar Mar 19 '15 19:03 anko

I'd like to second this request.

It would be awesome to be able to integrate it with various window managers and what not. For example, in MATE, macro (the window manager) doesn't have commands for switching between windows and so on, but the DE's keyboard shortcut settings tool allows you to assign keyboard shortcuts to the window manager actions. I am guessing they communicate via IPC.

sxhkd is perfectly usable on its own, but it would be awesome if it can also be integrated with other stuff. Hence, why I think an IPC mechanism or integration with specific apps shouldn't be implemented directly, and why I think a plugin system is the perfect solution.

When sxhkd reaches a command, it can first check if it's a plugin function, and if it is, execute it. If it's not, look into the regular channels.

ifohancroft avatar Sep 29 '21 20:09 ifohancroft