Skip to content

Commit

Permalink
support xkb_key_offset option
Browse files Browse the repository at this point in the history
Per #4, xwayland gets angry if the minimum key drops below 8, so allow
setting an offset to apply when processing keycodes.
  • Loading branch information
r-c-f committed May 24, 2021
1 parent 443242f commit 7fe49bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/config-example/xkb_key_offset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions include/wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct wlContext {
struct org_kde_kwin_idle *idle_manager;
struct org_kde_kwin_idle_timeout *idle_timeout;
// keyboard layout handling
int xkb_key_offset;
struct xkb_context *xkb_ctx;
struct xkb_keymap *xkb_map;
struct xkb_state *xkb_state;
Expand Down
5 changes: 3 additions & 2 deletions src/wl_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ int wlKeySetConfigLayout(struct wlContext *ctx)
strcpy(ptr, keymap_str);
zwp_virtual_keyboard_v1_keymap(ctx->keyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd, keymap_size);
local_mod_init(ctx, keymap_str);
ctx->xkb_key_offset = configTryLong("xkb_key_offset", 0);
done:
free(keymap_str);
return ret;
Expand All @@ -90,13 +91,13 @@ void wlKey(struct wlContext *ctx, int key, int state)
return;
}
key_press_counts[key] += state ? 1 : -1;
xkb_state_update_key(ctx->xkb_state, key, state);
xkb_state_update_key(ctx->xkb_state, key + ctx->xkb_key_offset, state);
xkb_mod_mask_t depressed = xkb_state_serialize_mods(ctx->xkb_state, XKB_STATE_MODS_DEPRESSED);
xkb_mod_mask_t latched = xkb_state_serialize_mods(ctx->xkb_state, XKB_STATE_MODS_LATCHED);
xkb_mod_mask_t locked = xkb_state_serialize_mods(ctx->xkb_state, XKB_STATE_MODS_LOCKED);
xkb_layout_index_t group = xkb_state_serialize_layout(ctx->xkb_state, XKB_STATE_LAYOUT_EFFECTIVE);
logDbg("depressed: %x latched: %x locked: %x group: %x", depressed, latched, locked, group);
zwp_virtual_keyboard_v1_key(ctx->keyboard, wlTS(ctx), key - 8, state);
zwp_virtual_keyboard_v1_key(ctx->keyboard, wlTS(ctx), key - 8 + ctx->xkb_key_offset, state);
zwp_virtual_keyboard_v1_modifiers(ctx->keyboard, depressed, latched, locked, group);
wl_display_flush(ctx->display);
}
Expand Down

0 comments on commit 7fe49bd

Please sign in to comment.