Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef KEYMAP_H
18 #define KEYMAP_H
20 #include <stdint.h>
22 struct buffer;
24 struct kmap {
25 TAILQ_HEAD(map, keymap) m;
26 void (*unhandled_input)(void);
27 };
28 extern struct kmap global_map, minibuffer_map;
30 typedef void(interactivefn)(struct buffer *);
32 struct keymap {
33 int meta;
34 int key;
35 struct kmap map;
36 interactivefn *fn;
38 TAILQ_ENTRY(keymap) keymaps;
39 };
41 struct thiskey {
42 short meta;
43 int key;
44 uint32_t cp;
45 };
47 enum {
48 LK_ADVANCED_MAP,
49 LK_MATCHED,
50 LK_UNBOUND,
51 };
53 int kbd(const char *);
54 const char *unkbd(int);
55 int kmap_define_key(struct kmap *, const char *, interactivefn *);
56 int lookup_key(struct kmap **, struct thiskey *, struct buffer *);
58 #endif