home · contact · privacy
43a5edde23ff72cd53137287800765209e62dcd7
[plomrogue] / src / keybindings.h
1 /* keybindings.h
2  *
3  * Retrieval and storage of keybindings.
4  */
5
6 #ifndef KEYBINDINGS_H
7 #define KEYBINDINGS_H
8
9 #include <stdint.h> /* for uint8_t, uint16_t */
10
11
12
13 /* Individual keybinding in keybinding chain. */
14 struct KeyBinding
15 {
16   struct KeyBinding * next;
17   uint16_t key; /* keycode */
18   char * name;  /* name of functionality bound to keycode */
19 };
20
21 /* Wrapper to keybinding chain, contains some keybinding editing metadata. */
22 struct KeyBiData
23 {
24     struct KeyBinding * kbs;
25     uint8_t edit;    /* 1 if currently editing a keybinding, else 0 */
26     uint16_t select; /* linear list index of keybinding selected for editing */
27 };
28
29
30
31 /* Return name of action / functionality coupled to keycode; NULL on failure. */
32 extern char * get_func_to_keycode(struct KeyBinding * kb_p, uint16_t key);
33
34 /* Return keycode matched by keybinding to command of "name". */
35 extern uint16_t get_keycode_to_action(struct KeyBinding * keybindings,
36                                       char * name);
37
38 /* Return human-readable name (of maximum 9 chars) for "keycode" as matched by
39  * ncurses.h; if none is found, return "UNKNOWN".
40  */
41 extern char * get_name_to_keycode(uint16_t keycode);
42
43 /* Return number of keybindings in keybindings chain from "kb_p" on. */
44 extern uint16_t get_n_of_keybs(struct KeyBinding * kb_p);
45
46 /* Return "n"-th keybinding in keybindings chain from "kb_p" on. */
47 extern struct KeyBinding * get_keyb_of_n(struct KeyBinding * kb_p, uint16_t n);
48
49 /* Initialize/save keybindings data from/to file at "path" to/from keybindings
50  * data pointer "kbd".
51  */
52 extern void init_keybindings(char * path, struct KeyBiData * kbd);
53 extern void save_keybindings(char * path, struct KeyBiData * kbd);
54
55 /* Free keybinding chain starting at "kb_start". */
56 extern void free_keybindings(struct KeyBinding * kb_start);
57
58 /* Mark keybinding selected for modification as being edited, get user input to
59  * modify it, then unmark it again. Ensure there are max. three digits in the
60  * keycode ASCII representation.
61  */
62 extern void mod_selected_keyb(struct KeyBiData * kbd);
63
64 /* Move keybinding modification selection upwards ("dir"=="u") or downwards
65  * ("dir"=="d") within the limits of the keybindings chain length.
66  */
67 extern void move_keyb_mod_selection(struct KeyBiData * kbd, char dir);
68
69
70
71 #endif