diff --git a/src/config.c b/src/config.c index d3b301c..aaec7fe 100644 --- a/src/config.c +++ b/src/config.c @@ -187,7 +187,7 @@ static uint8_t lookup_keycode(const char *name) { size_t i; - for (i = 0; i < 256; i++) { + for (i = 0; i < KEY_MAX; i++) { const struct keycode_table_ent *ent = &keycode_table[i]; if (ent->name && @@ -200,7 +200,7 @@ static uint8_t lookup_keycode(const char *name) return 0; } -static struct descriptor *layer_lookup_chord(struct layer *layer, uint8_t *keys, size_t n) +static struct descriptor *layer_lookup_chord(struct layer *layer, uint16_t *keys, size_t n) { size_t i; @@ -241,11 +241,11 @@ static int set_layer_entry(const struct config *config, //TODO: Handle aliases char *tok; struct descriptor *ld; - uint8_t keys[ARRAY_SIZE(layer->chords[0].keys)]; + uint16_t keys[ARRAY_SIZE(layer->chords[0].keys)]; size_t n = 0; for (tok = strtok(key, "+"); tok; tok = strtok(NULL, "+")) { - uint8_t code = lookup_keycode(tok); + uint16_t code = lookup_keycode(tok); if (!code) { err("%s is not a valid key", tok); return -1; @@ -285,7 +285,7 @@ static int set_layer_entry(const struct config *config, } if (!found) { - uint8_t code; + uint16_t code; if (!(code = lookup_keycode(key))) { err("%s is not a valid key or alias", key); @@ -481,7 +481,8 @@ static int parse_fn(char *s, int parse_macro_expression(const char *s, struct macro *macro) { - uint8_t code, mods; + uint16_t code; + uint8_t mods; #define ADD_ENTRY(t, d) do { \ if (macro->sz >= ARRAY_SIZE(macro->entries)) { \ @@ -543,7 +544,8 @@ static int parse_descriptor(char *s, char *fn = NULL; char *args[5]; size_t nargs = 0; - uint8_t code, mods; + uint16_t code; + uint8_t mods; int ret; struct macro macro; struct command cmd; @@ -804,7 +806,7 @@ static void parse_alias_section(struct config *config, struct ini_section *secti size_t i; for (i = 0; i < section->nr_entries; i++) { - uint8_t code; + uint16_t code; struct ini_entry *ent = §ion->entries[i]; const char *name = ent->val; @@ -1025,4 +1027,3 @@ int config_add_entry(struct config *config, const char *exp) return set_layer_entry(config, layer, keyname, &d); } - diff --git a/src/config.h b/src/config.h index 0d77832..1c7257b 100644 --- a/src/config.h +++ b/src/config.h @@ -54,7 +54,7 @@ enum op { }; union descriptor_arg { - uint8_t code; + uint16_t code; uint8_t mods; int16_t idx; uint16_t sz; @@ -70,7 +70,7 @@ struct descriptor { }; struct chord { - uint8_t keys[8]; + uint16_t keys[8]; size_t sz; struct descriptor d; @@ -94,7 +94,7 @@ struct layer { } type; uint8_t mods; - struct descriptor keymap[256]; + struct descriptor keymap[KEY_MAX]; struct chord chords[64]; size_t nr_chords; diff --git a/src/daemon.c b/src/daemon.c index 9033372..add8a31 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -10,7 +10,7 @@ static int ipcfd = -1; static struct vkbd *vkbd = NULL; static struct config_ent *configs; -static uint8_t keystate[256]; +static uint8_t keystate[KEY_MAX]; static int listeners[32]; static size_t nr_listeners = 0; @@ -39,14 +39,14 @@ static void clear_vkbd() { size_t i; - for (i = 0; i < 256; i++) + for (i = 0; i < KEY_MAX; i++) if (keystate[i]) { vkbd_send_key(vkbd, i, 0); keystate[i] = 0; } } -static void send_key(uint8_t code, uint8_t state) +static void send_key(uint16_t code, uint8_t state) { keystate[code] = state; vkbd_send_key(vkbd, code, state); @@ -290,7 +290,8 @@ static int input(char *buf, size_t sz, uint32_t timeout) char s[2]; if (csz == 1) { - uint8_t code, mods; + uint16_t code; + uint8_t mods; s[0] = (char)codepoint; s[1] = 0; diff --git a/src/device.c b/src/device.c index c7bc5fb..6d4baba 100644 --- a/src/device.c +++ b/src/device.c @@ -491,7 +491,8 @@ struct device_event *device_read_event(struct device *dev) && ev.code <= BTN_TOOL_QUADTAP); else { keyd_log("r{ERROR:} unsupported evdev code: 0x%x\n", ev.code); - return NULL; + /* passthrough the code unchanged; we won't be able to remap it + but we can still send the input. */ } } diff --git a/src/device.h b/src/device.h index bf306c6..b2738df 100644 --- a/src/device.h +++ b/src/device.h @@ -52,7 +52,7 @@ struct device_event { DEV_REMOVED, } type; - uint8_t code; + uint16_t code; uint8_t pressed; uint32_t x; uint32_t y; diff --git a/src/evloop.c b/src/evloop.c index 58e631a..d7befa5 100644 --- a/src/evloop.c +++ b/src/evloop.c @@ -8,7 +8,7 @@ static size_t nr_aux_fds = 0; struct device device_table[MAX_DEVICES]; size_t device_table_sz; -static void panic_check(uint8_t code, uint8_t pressed) +static void panic_check(uint16_t code, uint8_t pressed) { static uint8_t enter, backspace, escape; switch (code) { diff --git a/src/keyboard.c b/src/keyboard.c index e41b93c..54274d6 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -6,7 +6,7 @@ #include "keyd.h" -static long process_event(struct keyboard *kbd, uint8_t code, int pressed, long time); +static long process_event(struct keyboard *kbd, uint16_t code, int pressed, long time); /* * Here be tiny dragons. @@ -19,7 +19,7 @@ static long get_time() return time++; } -static int cache_set(struct keyboard *kbd, uint8_t code, struct cache_entry *ent) +static int cache_set(struct keyboard *kbd, uint16_t code, struct cache_entry *ent) { size_t i; int slot = -1; @@ -45,7 +45,7 @@ static int cache_set(struct keyboard *kbd, uint8_t code, struct cache_entry *ent return 0; } -static struct cache_entry *cache_get(struct keyboard *kbd, uint8_t code) +static struct cache_entry *cache_get(struct keyboard *kbd, uint16_t code) { size_t i; @@ -60,7 +60,7 @@ static void reset_keystate(struct keyboard *kbd) { size_t i; - for (i = 0; i < 256; i++) { + for (i = 0; i < KEY_MAX; i++) { if (kbd->keystate[i]) { kbd->output.send_key(i, 0); kbd->keystate[i] = 0; @@ -69,7 +69,7 @@ static void reset_keystate(struct keyboard *kbd) } -static void send_key(struct keyboard *kbd, uint8_t code, uint8_t pressed) +static void send_key(struct keyboard *kbd, uint16_t code, uint8_t pressed) { if (code == KEYD_NOOP || code == KEYD_EXTERNAL_MOUSE_BUTTON) return; @@ -83,7 +83,7 @@ static void send_key(struct keyboard *kbd, uint8_t code, uint8_t pressed) } } -static void clear_mod(struct keyboard *kbd, uint8_t code) +static void clear_mod(struct keyboard *kbd, uint16_t code) { /* * Some modifiers have a special meaning when used in @@ -114,7 +114,7 @@ static void set_mods(struct keyboard *kbd, uint8_t mods) for (i = 0; i < ARRAY_SIZE(modifiers); i++) { uint8_t mask = modifiers[i].mask; - uint8_t code = modifiers[i].key; + uint16_t code = modifiers[i].key; if (mask & mods) { if (!kbd->keystate[code]) @@ -161,7 +161,7 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr { /* Minimize redundant modifier strokes for simple key sequences. */ if (macro->sz == 1 && macro->entries[0].type == MACRO_KEYSEQUENCE) { - uint8_t code = macro->entries[0].data; + uint16_t code = macro->entries[0].data; uint8_t mods = macro->entries[0].data >> 8; update_mods(kbd, dl, mods); @@ -173,7 +173,7 @@ static void execute_macro(struct keyboard *kbd, int dl, const struct macro *macr } } -static void lookup_descriptor(struct keyboard *kbd, uint8_t code, +static void lookup_descriptor(struct keyboard *kbd, uint16_t code, struct descriptor *d, int *dl) { size_t max; @@ -255,7 +255,7 @@ static void deactivate_layer(struct keyboard *kbd, int idx) * corresponding deactivation call. */ -static void activate_layer(struct keyboard *kbd, uint8_t code, int idx) +static void activate_layer(struct keyboard *kbd, uint16_t code, int idx) { dbg("Activating layer %s", kbd->config.layers[idx].name); struct cache_entry *ce; @@ -304,7 +304,7 @@ static int chord_event_match(struct chord *chord, struct key_event *events, size return n == chord->sz ? 2 : 1; } -static void enqueue_chord_event(struct keyboard *kbd, uint8_t code, uint8_t pressed, long time) +static void enqueue_chord_event(struct keyboard *kbd, uint16_t code, uint8_t pressed, long time) { if (!code) return; @@ -475,7 +475,7 @@ static long calculate_main_loop_timeout(struct keyboard *kbd, long time) return timeout ? timeout - time : 0; } -static long process_descriptor(struct keyboard *kbd, uint8_t code, +static long process_descriptor(struct keyboard *kbd, uint16_t code, const struct descriptor *d, int dl, int pressed, long time) { @@ -502,7 +502,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, struct macro *macro; struct descriptor *action; uint8_t mods; - uint8_t new_code; + uint16_t new_code; case OP_KEYSEQUENCE: new_code = d->args[0].code; @@ -759,7 +759,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, update_mods(kbd, -1, 0); } else { for (i = 0; i < CACHE_SIZE; i++) { - uint8_t code = kbd->cache[i].code; + uint16_t code = kbd->cache[i].code; int layer = kbd->cache[i].layer; int type = kbd->config.layers[layer].type; @@ -786,7 +786,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, if (macro && macro->sz == 1 && macro->entries[0].type == MACRO_KEYSEQUENCE) { - uint8_t code = macro->entries[0].data; + uint16_t code = macro->entries[0].data; send_key(kbd, code, 0); update_mods(kbd, -1, 0); @@ -851,7 +851,7 @@ static int resolve_chord(struct keyboard *kbd) if (chord) { size_t i; - uint8_t code = 0; + uint16_t code = 0; for (i = 0; i < ARRAY_SIZE(kbd->active_chords); i++) { struct active_chord *ac = &kbd->active_chords[i]; @@ -886,7 +886,7 @@ static int abort_chord(struct keyboard *kbd) } static int handle_chord(struct keyboard *kbd, - uint8_t code, int pressed, long time) + uint16_t code, int pressed, long time) { size_t i; const long interkey_timeout = kbd->config.chord_interkey_timeout; @@ -895,7 +895,7 @@ static int handle_chord(struct keyboard *kbd, if (code && !pressed) { for (i = 0; i < ARRAY_SIZE(kbd->active_chords); i++) { struct active_chord *ac = &kbd->active_chords[i]; - uint8_t chord_code = KEYD_CHORD_1 + i; + uint16_t chord_code = KEYD_CHORD_1 + i; if (ac->active) { size_t i; @@ -1026,7 +1026,7 @@ static int handle_chord(struct keyboard *kbd, return 0; } -int handle_pending_key(struct keyboard *kbd, uint8_t code, int pressed, long time) +int handle_pending_key(struct keyboard *kbd, uint16_t code, int pressed, long time) { if (!kbd->pending_key.code) return 0; @@ -1089,7 +1089,7 @@ int handle_pending_key(struct keyboard *kbd, uint8_t code, int pressed, long tim struct key_event queue[ARRAY_SIZE(kbd->pending_key.queue)]; size_t queue_sz = kbd->pending_key.queue_sz; - uint8_t code = kbd->pending_key.code; + uint16_t code = kbd->pending_key.code; int dl = kbd->pending_key.dl; memcpy(queue, kbd->pending_key.queue, sizeof kbd->pending_key.queue); @@ -1119,7 +1119,7 @@ int handle_pending_key(struct keyboard *kbd, uint8_t code, int pressed, long tim * of process_event must take place. A return value of 0 permits the * main loop to call at liberty. */ -static long process_event(struct keyboard *kbd, uint8_t code, int pressed, long time) +static long process_event(struct keyboard *kbd, uint16_t code, int pressed, long time) { int dl = -1; struct descriptor d; diff --git a/src/keyboard.h b/src/keyboard.h index dc94075..1cc0a27 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -18,20 +18,20 @@ struct keyboard; struct cache_entry { - uint8_t code; + uint16_t code; struct descriptor d; int dl; int layer; }; struct key_event { - uint8_t code; + uint16_t code; uint8_t pressed; int timestamp; }; struct output { - void (*send_key) (uint8_t code, uint8_t state); + void (*send_key) (uint16_t code, uint8_t state); void (*on_layer_change) (const struct keyboard *kbd, const struct layer *layer, uint8_t active); }; @@ -47,8 +47,8 @@ struct keyboard { */ struct cache_entry cache[CACHE_SIZE]; - uint8_t last_pressed_output_code; - uint8_t last_pressed_code; + uint16_t last_pressed_output_code; + uint16_t last_pressed_code; uint8_t oneshot_latch; @@ -56,7 +56,6 @@ struct keyboard { struct macro *active_macro; int active_macro_layer; - int overload_last_layer_code; long macro_timeout; long oneshot_timeout; @@ -83,7 +82,7 @@ struct keyboard { const struct chord *match; int match_layer; - uint8_t start_code; + uint16_t start_code; long last_code_time; enum { @@ -95,7 +94,7 @@ struct keyboard { } chord; struct { - uint8_t code; + uint16_t code; uint8_t dl; long expire; long tap_expiry; @@ -122,7 +121,7 @@ struct keyboard { uint8_t oneshot_depth; } layer_state[MAX_LAYERS]; - uint8_t keystate[256]; + uint8_t keystate[KEY_MAX]; struct { int x; diff --git a/src/keyd.c b/src/keyd.c index d08ac48..b61721b 100644 --- a/src/keyd.c +++ b/src/keyd.c @@ -64,7 +64,7 @@ static int list_keys(int argc, char *argv[]) { size_t i; - for (i = 0; i < 256; i++) { + for (i = 0; i < KEY_MAX; i++) { const char *altname = keycode_table[i].alt_name; const char *shiftedname = keycode_table[i].shifted_name; const char *name = keycode_table[i].name; diff --git a/src/keys.c b/src/keys.c index 52f22ee..6ee8bcb 100644 --- a/src/keys.c +++ b/src/keys.c @@ -15,7 +15,7 @@ const struct modifier modifiers[MAX_MOD] = { {MOD_CTRL, KEYD_LEFTCTRL}, }; -const struct keycode_table_ent keycode_table[256] = { +const struct keycode_table_ent keycode_table[KEY_MAX] = { [KEYD_ESC] = { "esc", "escape", NULL }, [KEYD_1] = { "1", NULL, "!" }, [KEYD_2] = { "2", NULL, "@" }, @@ -343,7 +343,7 @@ int parse_modset(const char *s, uint8_t *mods) return 0; } -int parse_key_sequence(const char *s, uint8_t *codep, uint8_t *modsp) +int parse_key_sequence(const char *s, uint16_t *codep, uint8_t *modsp) { const char *c = s; size_t i; @@ -378,7 +378,7 @@ int parse_key_sequence(const char *s, uint8_t *codep, uint8_t *modsp) c += 2; } - for (i = 0; i < 256; i++) { + for (i = 0; i < KEY_MAX; i++) { const struct keycode_table_ent *ent = &keycode_table[i]; if (ent->name) { diff --git a/src/keys.h b/src/keys.h index d7a09e7..787dbb8 100644 --- a/src/keys.h +++ b/src/keys.h @@ -288,12 +288,14 @@ struct modifier { #define KEYD_FN 254 #define KEYD_MOUSE_FORWARD 255 +/* input-event-codes.h; this is the same on both Linux and FreeBSD. */ +#define KEY_MAX 0x2ff #define KEY_NAME(code) (keycode_table[code].name ? keycode_table[code].name : "UNKNOWN") int parse_modset(const char *s, uint8_t *mods); -int parse_key_sequence(const char *s, uint8_t *code, uint8_t *mods); +int parse_key_sequence(const char *s, uint16_t *code, uint8_t *mods); extern const struct modifier modifiers[MAX_MOD]; -extern const struct keycode_table_ent keycode_table[256]; +extern const struct keycode_table_ent keycode_table[KEY_MAX]; #endif diff --git a/src/macro.c b/src/macro.c index 13f743e..07f0901 100644 --- a/src/macro.c +++ b/src/macro.c @@ -21,7 +21,8 @@ int macro_parse(char *s, struct macro *macro) macro->sz = 0; for (tok = strtok(s, " "); tok; tok = strtok(NULL, " ")) { - uint8_t code, mods; + uint16_t code; + uint8_t mods; size_t len = strlen(tok); if (!parse_key_sequence(tok, &code, &mods)) { @@ -55,7 +56,7 @@ int macro_parse(char *s, struct macro *macro) int xcode; if (chrsz == 1 && codepoint < 128) { - for (i = 0; i < 256; i++) { + for (i = 0; i < KEY_MAX; i++) { const char *name = keycode_table[i].name; const char *shiftname = keycode_table[i].shifted_name; @@ -82,7 +83,7 @@ int macro_parse(char *s, struct macro *macro) #undef ADD_ENTRY } -void macro_execute(void (*output)(uint8_t, uint8_t), +void macro_execute(void (*output)(uint16_t, uint8_t), const struct macro *macro, size_t timeout) { size_t i; @@ -95,7 +96,7 @@ void macro_execute(void (*output)(uint8_t, uint8_t), size_t j; uint16_t idx; uint8_t codes[4]; - uint8_t code, mods; + uint16_t code, mods; case MACRO_HOLD: if (hold_start == -1) @@ -132,7 +133,7 @@ void macro_execute(void (*output)(uint8_t, uint8_t), mods = ent->data >> 8; for (j = 0; j < ARRAY_SIZE(modifiers); j++) { - uint8_t code = modifiers[j].key; + uint16_t code = modifiers[j].key; uint8_t mask = modifiers[j].mask; if (mods & mask) @@ -146,7 +147,7 @@ void macro_execute(void (*output)(uint8_t, uint8_t), output(code, 0); for (j = 0; j < ARRAY_SIZE(modifiers); j++) { - uint8_t code = modifiers[j].key; + uint16_t code = modifiers[j].key; uint8_t mask = modifiers[j].mask; if (mods & mask) diff --git a/src/macro.h b/src/macro.h index 14c6f8d..4fdb0e4 100644 --- a/src/macro.h +++ b/src/macro.h @@ -27,7 +27,7 @@ struct macro { }; -void macro_execute(void (*output)(uint8_t, uint8_t), +void macro_execute(void (*output)(uint16_t, uint8_t), const struct macro *macro, size_t timeout); diff --git a/src/monitor.c b/src/monitor.c index 8e461bb..047be76 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -48,7 +48,7 @@ int event_handler(struct event *ev) case EV_DEV_EVENT: switch (ev->devev->type) { case DEV_KEY: - name = keycode_table[ev->devev->code].name; + name = KEY_NAME(ev->devev->code); if (time_flag && last_time) keyd_log("r{+%ld} ms\t", ev->timestamp - last_time); diff --git a/src/vkbd.h b/src/vkbd.h index e512306..1309772 100644 --- a/src/vkbd.h +++ b/src/vkbd.h @@ -16,7 +16,7 @@ void vkbd_mouse_move(const struct vkbd *vkbd, int x, int y); void vkbd_mouse_move_abs(const struct vkbd *vkbd, int x, int y); void vkbd_mouse_scroll(const struct vkbd *vkbd, int x, int y); -void vkbd_send_key(const struct vkbd *vkbd, uint8_t code, int state); +void vkbd_send_key(const struct vkbd *vkbd, uint16_t code, int state); void free_vkbd(struct vkbd *vkbd); #endif diff --git a/src/vkbd/stdout.c b/src/vkbd/stdout.c index 4440af9..d543095 100644 --- a/src/vkbd/stdout.c +++ b/src/vkbd/stdout.c @@ -37,9 +37,9 @@ void vkbd_mouse_move_abs(const struct vkbd *vkbd, int x, int y) printf("absolute mouse movement: x: %d, y: %d\n", x, y); } -void vkbd_send_key(const struct vkbd *vkbd, uint8_t code, int state) +void vkbd_send_key(const struct vkbd *vkbd, uint16_t code, int state) { - printf("key: %s, state: %d\n", keycode_table[code].name, state); + printf("key: %s, state: %d\n", KEY_NAME(code), state); } void free_vkbd(struct vkbd *vkbd) diff --git a/src/vkbd/uinput.c b/src/vkbd/uinput.c index 6c5f974..2d5e26e 100644 --- a/src/vkbd/uinput.c +++ b/src/vkbd/uinput.c @@ -64,7 +64,7 @@ static int create_virtual_keyboard(const char *name) exit(-1); } - for (code = 0; code < 256; code++) { + for (code = 0; code < KEY_MAX; code++) { if (keycode_table[code].name) { if (ioctl(fd, UI_SET_KEYBIT, code)) { perror("ioctl set_keybit"); @@ -157,7 +157,7 @@ static int create_virtual_pointer(const char *name) return fd; } -static void write_key_event(const struct vkbd *vkbd, uint8_t code, int state) +static void write_key_event(const struct vkbd *vkbd, uint16_t code, int state) { static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; struct input_event ev; @@ -331,7 +331,7 @@ void vkbd_mouse_move_abs(const struct vkbd *vkbd, int x, int y) xwrite(vkbd->pfd, &ev, sizeof(ev)); } -void vkbd_send_key(const struct vkbd *vkbd, uint8_t code, int state) +void vkbd_send_key(const struct vkbd *vkbd, uint16_t code, int state) { dbg("output %s %s", KEY_NAME(code), state == 1 ? "down" : "up"); diff --git a/src/vkbd/usb-gadget.c b/src/vkbd/usb-gadget.c index 6b9853b..7f03eea 100644 --- a/src/vkbd/usb-gadget.c +++ b/src/vkbd/usb-gadget.c @@ -149,7 +149,7 @@ void vkbd_mouse_scroll(const struct vkbd *vkbd, int x, int y) fprintf(stderr, "usb-gadget: mouse support is not implemented\n"); } -void vkbd_send_key(const struct vkbd *vkbd, uint8_t code, int state) +void vkbd_send_key(const struct vkbd *vkbd, uint16_t code, int state) { if (update_modifier_state(code, state) < 0) update_key_state(code, state); diff --git a/src/vkbd/usb-gadget.h b/src/vkbd/usb-gadget.h index 553fff8..852dd1d 100644 --- a/src/vkbd/usb-gadget.h +++ b/src/vkbd/usb-gadget.h @@ -19,7 +19,7 @@ #define HID_RIGHTSUPER 0x80 #define HID_SUPER 0x8 -static const uint8_t hid_table[256] = { +static const uint8_t hid_table[KEY_MAX] = { [KEYD_ESC] = 0x29, [KEYD_1] = 0x1e, [KEYD_2] = 0x1f, diff --git a/t/test-io.c b/t/test-io.c index 0f74cb7..8bc2ba6 100644 --- a/t/test-io.c +++ b/t/test-io.c @@ -35,7 +35,7 @@ static uint8_t lookup_code(const char *name) return 0; } -static void send_key(uint8_t code, uint8_t pressed) +static void send_key(uint16_t code, uint8_t pressed) { output[noutput].code = code; output[noutput].pressed = pressed; @@ -170,7 +170,7 @@ static int parse_events(char *s, struct key_event in[MAX_EVENTS], size_t *nin, if (len >= 2 && line[len - 1] == 's' && line[len - 2] == 'm') { time += atoi(line); } else { - uint8_t code; + uint16_t code; char *k = strtok(line, " "); char *v = strtok(NULL, " \n");