Skip to content

Commit

Permalink
IPC: Send keyboard layout info in IPC_GET_INPUTS
Browse files Browse the repository at this point in the history
Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
  • Loading branch information
harishkrupo committed Nov 12, 2018
1 parent ee6b0ce commit d8ad429
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
22 changes: 22 additions & 0 deletions sway/ipc-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "sway/input/seat.h"
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
#include <xkbcommon/xkbcommon.h>
#include "wlr-layer-shell-unstable-v1-protocol.h"

static const char *ipc_json_layout_description(enum sway_container_layout l) {
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions swaymsg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static const char *pretty_type_name(const char *name) {
}

static void pretty_print_input(json_object *i) {
json_object *id, *name, *type, *product, *vendor;
json_object *id, *name, *type, *product, *vendor, *kbdlayout;
json_object_object_get_ex(i, "identifier", &id);
json_object_object_get_ex(i, "name", &name);
json_object_object_get_ex(i, "type", &type);
Expand All @@ -123,14 +123,21 @@ static void pretty_print_input(json_object *i) {
" Type: %s\n"
" Identifier: %s\n"
" Product ID: %d\n"
" Vendor ID: %d\n\n";
" Vendor ID: %d\n";


printf(fmt, json_object_get_string(name),
pretty_type_name(json_object_get_string(type)),
json_object_get_string(id),
json_object_get_int(product),
json_object_get_int(vendor));

if (json_object_object_get_ex(i, "xkb_active_layout_name", &kbdlayout)) {
printf(" Active Keyboard Layout: %s\n",
json_object_get_string(kbdlayout));
}

printf("\n");
}

static void pretty_print_seat(json_object *i) {
Expand Down

0 comments on commit d8ad429

Please sign in to comment.