From d8ad429e3974690ed7b48e5ad1d5af6dc7f2aebe Mon Sep 17 00:00:00 2001 From: Harish Krupo Date: Mon, 12 Nov 2018 14:33:16 +0530 Subject: IPC: Send keyboard layout info in IPC_GET_INPUTS Signed-off-by: Harish Krupo --- sway/ipc-json.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sway') diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 4583558c..4d9a87d8 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -12,6 +12,7 @@ #include "sway/input/seat.h" #include #include +#include #include "wlr-layer-shell-unstable-v1-protocol.h" static const char *ipc_json_layout_description(enum sway_container_layout l) { @@ -503,6 +504,27 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { json_object_object_add(object, "type", json_object_new_string(describe_device_type(device))); + if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) { + struct wlr_keyboard *keyboard = device->wlr_device->keyboard; + struct xkb_keymap *keymap = keyboard->keymap; + struct xkb_state *state = keyboard->xkb_state; + xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap); + xkb_layout_index_t layout_idx; + for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) { + bool is_active = + xkb_state_layout_index_is_active(state, + layout_idx, + XKB_STATE_LAYOUT_EFFECTIVE); + if (is_active) { + const char *layout = + xkb_keymap_layout_get_name(keymap, layout_idx); + json_object_object_add(object, "xkb_active_layout_name", + json_object_new_string(layout)); + break; + } + } + } + return object; } -- cgit v1.2.3