From eda4ab0e8e2f97225e4c0470318e9427e09bbfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 29 Dec 2016 17:58:00 +0100 Subject: vis: cleanup key action lifetime management --- vis.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'vis.h') diff --git a/vis.h b/vis.h index ef8897d..312da4b 100644 --- a/vis.h +++ b/vis.h @@ -53,15 +53,17 @@ typedef union { /* various types of arguments passed to key action functions */ void (*f)(Vis*); } Arg; +/* action handling function, keys refers to the next characters found in the input queue + * (an empty string "" indicates an empty queue). The return value of func has to point to + * the first non consumed key. Returning NULL indicates that not enough keys were available + * to complete the action. In this case the function will be called again when more input + * becomes available */ +typedef const char *KeyActionFunction(Vis*, const char *keys, const Arg*); + typedef struct { /* a KeyAction can be bound to a key binding */ const char *name; /* aliases can refer to this action by means of a pseudo key */ const char *help; /* short (one line) human readable description, displayed by :help */ - /* action handling function, keys refers to the next characters found in the input queue - * (an empty string "" indicates an empty queue). The return value of func has to point to - * the first non consumed key. Returning NULL indicates that not enough keys were available - * to complete the action. In this case the function will be called again when more input - * becomes available */ - const char* (*func)(Vis*, const char *keys, const Arg*); + KeyActionFunction *func; /* action implementation */ Arg arg; /* additional arguments which will be passed as to func */ } KeyAction; @@ -175,6 +177,9 @@ bool vis_window_mode_map(Win*, enum VisMode, bool force, const char *key, const /* in the specified mode: unmap a given key, fails if the key is not currently mapped */ bool vis_mode_unmap(Vis*, enum VisMode, const char *key); bool vis_window_mode_unmap(Win*, enum VisMode, const char *key); + +KeyAction *vis_action_new(Vis*, const char *name, const char *help, KeyActionFunction*, Arg); +void vis_action_free(Vis*, KeyAction*); /* associates the special pseudo key name> with the given key action. * after successfull registration the pseudo key can be used key binding aliases */ bool vis_action_register(Vis*, const KeyAction*); -- cgit v1.2.3