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