kmap.h (4733B)
1 /* see LICENSE file for copyright and license details */ 2 #ifndef KMAP_H 3 #define KMAP_H 4 5 #include <stddef.h> 6 #include <stdio.h> 7 8 /* 9 * kmap: a keyboard layout as portable text, one file a layout or variant. 10 * lines are a key and words, rc quoted ('...' one word, '' a quote inside it), 11 * # starts a comment: 12 * 13 * kmap 1 14 * id de-nodeadkeys 15 * layout de 16 * variant nodeadkeys 17 * name German (no dead keys) 18 * level3 ralt 19 * key AD01 q Q @ Ω caps 20 * key SPCE space 21 * 22 * a key is named by its xkb position (AE01 the key under 1, AD01 under q on a 23 * us board, TLDE, BKSL, LSGT, SPCE, KP7), which no system owns. its symbols 24 * are its levels: base, shift, level 3 (altgr), level 3 with shift, and to 25 * eight for the layouts that reach level 5. type=NAME, on the keys that 26 * need it, is the xkb type that says which modifiers reach which level (a 27 * keypad's second level is num lock's: type=KEYPAD); without it the levels 28 * are xkb's own choice for them. a symbol 29 * is the one character it types, or a keysym name for what is not one 30 * (space, dead_acute, KP_Delete), none for nothing. caps marks a key caps 31 * lock shifts. level3 ralt says right alt reaches level 3. 32 * 33 * pc.kmap is the whole pc keyboard under every layout, with the keysyms 34 * that drive each modifier ("modmap Mod1 Alt_L Alt_R"); options/<group>/ 35 * <name>.kmap are the xkb options that change keys, laid over a layout; and 36 * xkb/ holds the key codes, types and compatibility every xkb keymap has, so 37 * kmap -x needs no xkb data of the system's. 38 * 39 * compose.kmap, beside the layouts, says what a dead key makes: 40 * 41 * compose dead_acute e é 42 * 43 * the layouts live in KMAP_DIR/<layout>/<variant>.kmap, the base layout in 44 * KMAP_DIR/<layout>/<layout>.kmap 45 */ 46 47 #define KMAP_DIR "/share/kmap" 48 #define KMAP_LEVELS 8 49 #define KMAP_SYM 32 50 51 struct kmap_key { 52 char name[8]; 53 char sym[KMAP_LEVELS][KMAP_SYM]; 54 int nsym; 55 int caps; 56 char type[48]; // the xkb type, "" when xkb's own choice is the layout's 57 }; 58 59 struct kmap_compose { 60 char dead[KMAP_SYM]; 61 char base[KMAP_SYM]; 62 char result[KMAP_SYM]; 63 }; 64 65 /* a modifier and the keysyms whose keys drive it: pc.kmap's own maps */ 66 struct kmap_modmap { 67 char mod[16]; 68 char sym[16][KMAP_SYM]; 69 int n; 70 }; 71 72 struct kmap { 73 char id[64], layout[32], variant[64], name[256]; 74 int level3_ralt; 75 struct kmap_modmap modmaps[8]; 76 int nmodmaps; 77 struct kmap_key *keys; 78 size_t nkeys; 79 struct kmap_compose *compose; 80 size_t ncompose; 81 }; 82 83 /* path of layout's variant (NULL or "" for the base layout) under dir */ 84 void kmap_path(char *buf, size_t sz, const char *dir, const char *layout, const char *variant); 85 86 /* reads path into k, adding to what k has: a layout, then compose.kmap, whose 87 own id and name do not replace the layout's. k starts zeroed. 0, or -1 88 with the reason said */ 89 int kmap_read(const char *path, struct kmap *k); 90 void kmap_free(struct kmap *k); 91 92 /* the unicode character sym is, -1 when it is a name */ 93 long kmap_char(const char *sym); 94 95 /* the words of line, rc unquoted in place, into w (max of them). their number */ 96 int kmap_words(char *line, char **w, int max); 97 98 /* the ways systems number keys: evdev codes (linux), pc scancodes of set 1 99 (wscons for pc keyboards, syscons and vt), and usb hid usages (wscons for 100 usb keyboards) */ 101 enum kmap_codes { 102 KMAP_EVDEV, 103 KMAP_PC, 104 KMAP_HID, 105 }; 106 107 /* where a key is in one of those numberings, -1 for a key kmap does not 108 place there */ 109 int kmap_code(const char *name, enum kmap_codes scheme); 110 111 /* the unicode character a symbol types: a character, a named one (space, 112 nobreakspace, combining_acute), or Uxxxx. -1 for anything else */ 113 long kmap_unicode(const char *sym); 114 115 /* the combining character a dead key puts on the next one (U+0301 for 116 dead_acute), -1 when sym is no dead key */ 117 long kmap_dead(const char *sym); 118 119 /* the console's keyboard set to k, through the system's own interface: the 120 linux console (kmap_linux.c), wscons on netbsd and openbsd 121 (kmap_wscons.c), syscons and vt on freebsd (kmap_fbsd.c). 0, or -1 with 122 the reason said, as on a system kmap has no backend for (kmap_posix.c) */ 123 int kmap_load_console(const struct kmap *k); 124 125 /* a whole xkb keymap, needing no xkb data: the key codes, types and 126 compatibility in dir/xkb, the pc keyboard pc, the n layouts of maps as a 127 group each over it, then the nopts options over every group. 0, or -1 128 said */ 129 int kmap_write_xkb( 130 FILE *fp, 131 const char *dir, 132 const struct kmap *pc, 133 const struct kmap *maps, 134 int n, 135 const struct kmap *opts, 136 int nopts 137 ); 138 139 #endif