Skip to content

Commit

Permalink
probably the best approach here
Browse files Browse the repository at this point in the history
No early return from the raw keymap function at all. Definitely
fixes #28, and prevents any weirdness with malformed configs elsewhere.
  • Loading branch information
r-c-f committed Jan 29, 2022
1 parent 6f9bbba commit caa126e
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/wl_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ static void load_raw_keymap(struct wlContext *ctx)
}
/* start with the xkb maximum */
ctx->input.key_count = xkb_keymap_max_keycode(ctx->input.xkb_map);
if ((count = configReadFullSection("raw-keymap", &key, &val)) == -1) {
return;
}
/* slightly inefficient approach, but it will actually work
* First pass -- just find the *real* maximum raw keycode */
for (i = 0; i < count; ++i) {
errno = 0;
lkey = strtol(key[i], &endstr, 0);
if (errno || endstr == key[i])
continue;
if (lkey >= ctx->input.key_count) {
ctx->input.key_count = lkey + 1;
if ((count = configReadFullSection("raw-keymap", &key, &val)) != -1) {
/* slightly inefficient approach, but it will actually work
* First pass -- just find the *real* maximum raw keycode */
for (i = 0; i < count; ++i) {
errno = 0;
lkey = strtol(key[i], &endstr, 0);
if (errno || endstr == key[i])
continue;
if (lkey >= ctx->input.key_count) {
ctx->input.key_count = lkey + 1;
}
}
}
/* initialize everything */
ctx->input.raw_keymap = xcalloc(ctx->input.key_count, sizeof(*ctx->input.raw_keymap));
for (i = 0; i < ctx->input.key_count; ++i) {
ctx->input.raw_keymap[i] = i;
}
/* initialize key state tracking now that the size is known */
ctx->input.key_press_state = xcalloc(ctx->input.key_count, sizeof(*ctx->input.key_press_state));
/* and second pass -- store any actually mappings, apply offset */
offset = configTryLong("raw-keymap/offset", 0);
for (i = 0; i < count; ++i) {
Expand Down Expand Up @@ -99,8 +100,6 @@ int wlKeySetConfigLayout(struct wlContext *ctx)
ctx->input.xkb_key_offset = configTryLong("xkb_key_offset", 0);
ret = !ctx->input.key_map(&ctx->input, keymap_str);
load_raw_keymap(ctx);
/* initialize key state tracking now that the size is known */
ctx->input.key_press_state = xcalloc(ctx->input.key_count, sizeof(*ctx->input.key_press_state));
free(keymap_str);
return ret;
}
Expand Down

0 comments on commit caa126e

Please sign in to comment.