Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passthrough unknown key codes #898

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) { \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = &section->entries[i];
const char *name = ent->val;

Expand Down Expand Up @@ -1025,4 +1027,3 @@ int config_add_entry(struct config *config, const char *exp)

return set_layer_entry(config, layer, keyname, &d);
}

6 changes: 3 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum op {
};

union descriptor_arg {
uint8_t code;
uint16_t code;
uint8_t mods;
int16_t idx;
uint16_t sz;
Expand All @@ -70,7 +70,7 @@ struct descriptor {
};

struct chord {
uint8_t keys[8];
uint16_t keys[8];
size_t sz;

struct descriptor d;
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/evloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 21 additions & 21 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading