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