home · contact · privacy
763ca56ca7bc27ee4f783dfa0f9461ab76abd4b5
[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 #include <stdio.h> /* FILE */
11 struct Command;
12
13
14
15 struct KeyBinding
16 {
17   uint16_t keycode;
18   struct Command * command; /* command in command DB to which key is bound */
19 };
20
21 struct KeyBindingDB
22 {
23     struct KeyBinding * kbs;
24     uint16_t n_of_kbs; /* how many KeyBinding structs are stored below .kbs? */
25     uint16_t select; /* linear list index of keybinding selected for editing */
26     uint8_t edit;    /* 1 if currently editing a keybinding, else 0 */
27 };
28
29
30
31 /* Return command bound to "keycode" in "kbdb"; NULL if none found. */
32 extern struct Command * get_command_to_keycode(struct KeyBindingDB * kbdb,
33                                                uint16_t keycode);
34
35 /* Return human-readable name (of maximum 9 chars) for "keycode" as matched by
36  * ncurses.h; if none is found, return "UNKNOWN".
37  */
38 extern char * get_keyname_to_keycode(uint16_t keycode);
39
40 /* Read/write from/to "file" "kbd", delimited by world.delim. */
41 extern void write_keybindings_to_file(FILE * file, struct KeyBindingDB * kbd);
42 extern void read_keybindings_from_file(char * line, uint32_t linemax,
43                                        FILE * file, struct KeyBindingDB * kbd);
44
45 /* Mark keybinding in KeybindingDB (char_selected_kb_db()-) selected by "kb_c"
46  * as being edited, get user input to modify it, then unmark it again. Ensure
47  * there are max. three digits in the ASCII string of the kecode read from user.
48  */
49 extern void mod_selected_keyb(char kb_c);
50
51 /* Move .select in KeybindingDB (char-selected_kb_db()-) selected by "kb_c"
52  * upwards ("dir"=="u") or downwards ("dir"=="d") within KeyBindingDB limits.
53  */
54 extern void move_keyb_selection(char kb_c, char dir);
55
56
57
58 #endif