Add ability to bind arbitrary functions.

Before all the predated commands where kept in an array and their
indexes were used in bindings. This meant that users couldn't add their
own functions from the config file. Now key/mouse bindings have been
changed to to store the function ptr (wrapped in a cmd_t struct to also
store the mode) directly instead.

General cleanup done in this commit:
Defined `MODE_ALL` instead of using magic number.

For example, suppose one had bindings like:
{ 0,                   XK_q,             g_quit,                     None },
{ ShitMask,            XK_q,             {quit_err},                 None }
{ ControlMask,         XK_q,             {quit_err, .mode=MODE_IMAGE}, None }

The existing binding `q` has been left unchanged and is defined the same
way. However, the new hypothetical binding `Shift-q` can be used to call
the custom function quit_err in any mode (default). `Ctrl-q` on the
other hand will be called only on image mode.

Closes #50
This commit is contained in:
Arthur Williams
2021-09-18 12:27:12 -07:00
committed by N-R-K
parent 5c6947c1c6
commit 12efa0e3b4
6 changed files with 96 additions and 70 deletions

View File

@ -64,7 +64,7 @@ nsxiv: $(OBJS)
@echo "CC $@"
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(OBJS): Makefile nsxiv.h commands.lst config.h
$(OBJS): Makefile nsxiv.h config.h
options.o: version.h
window.o: icon/data.h