aboutsummaryrefslogtreecommitdiffstats
path: root/nsxiv.h
diff options
context:
space:
mode:
authorArthur Williams <taaparthur@gmail.com>2021-09-18 21:27:12 +0200
committerN-R-K <79544946+N-R-K@users.noreply.github.com>2021-10-13 02:05:00 +0200
commit12efa0e3b429675047cb2900d49e1f38afeb650b (patch)
tree31a5e934aeac55b14f26a89b3333921bb985e318 /nsxiv.h
parent5c6947c1c6df76ab8438ac27377559da79ab1eab (diff)
downloadnsxiv-12efa0e3b429675047cb2900d49e1f38afeb650b.tar.zst
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
Diffstat (limited to 'nsxiv.h')
-rw-r--r--nsxiv.h18
1 files changed, 4 insertions, 14 deletions
diff --git a/nsxiv.h b/nsxiv.h
index d65875b..45d1772 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -60,6 +60,7 @@ typedef enum {
} byteorder_t;
typedef enum {
+ MODE_ALL,
MODE_IMAGE,
MODE_THUMB
} appmode_t;
@@ -162,36 +163,25 @@ bool arl_handle(arl_t*);
typedef int arg_t;
typedef bool (*cmd_f)(arg_t);
-#define G_CMD(c) g_##c,
-#define I_CMD(c) i_##c,
-#define T_CMD(c) t_##c,
-
-typedef enum {
-#include "commands.lst"
- CMD_COUNT
-} cmd_id_t;
-
typedef struct {
- int mode;
cmd_f func;
+ appmode_t mode;
} cmd_t;
typedef struct {
unsigned int mask;
KeySym ksym;
- cmd_id_t cmd;
+ cmd_t cmd;
arg_t arg;
} keymap_t;
typedef struct {
unsigned int mask;
unsigned int button;
- cmd_id_t cmd;
+ cmd_t cmd;
arg_t arg;
} button_t;
-extern const cmd_t cmds[CMD_COUNT];
-
/* image.c */