aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Harish Krupo <harishkrupo@gmail.com>2018-11-12 14:33:16 +0530
committerLibravatar Harish Krupo <harishkrupo@gmail.com>2018-11-12 22:00:22 +0530
commitd8ad429e3974690ed7b48e5ad1d5af6dc7f2aebe (patch)
treebf43028f14e68cd1dcd1b3c4fcec6506674d4376
parentMerge pull request #3113 from RedSoxFan/fix-ws-auto-back-and-forth (diff)
downloadsway-d8ad429e3974690ed7b48e5ad1d5af6dc7f2aebe.tar.gz
sway-d8ad429e3974690ed7b48e5ad1d5af6dc7f2aebe.tar.zst
sway-d8ad429e3974690ed7b48e5ad1d5af6dc7f2aebe.zip
IPC: Send keyboard layout info in IPC_GET_INPUTS
Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
-rw-r--r--sway/ipc-json.c22
-rw-r--r--swaymsg/main.c11
2 files changed, 31 insertions, 2 deletions
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 @@
12#include "sway/input/seat.h" 12#include "sway/input/seat.h"
13#include <wlr/types/wlr_box.h> 13#include <wlr/types/wlr_box.h>
14#include <wlr/types/wlr_output.h> 14#include <wlr/types/wlr_output.h>
15#include <xkbcommon/xkbcommon.h>
15#include "wlr-layer-shell-unstable-v1-protocol.h" 16#include "wlr-layer-shell-unstable-v1-protocol.h"
16 17
17static const char *ipc_json_layout_description(enum sway_container_layout l) { 18static 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) {
503 json_object_object_add(object, "type", 504 json_object_object_add(object, "type",
504 json_object_new_string(describe_device_type(device))); 505 json_object_new_string(describe_device_type(device)));
505 506
507 if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
508 struct wlr_keyboard *keyboard = device->wlr_device->keyboard;
509 struct xkb_keymap *keymap = keyboard->keymap;
510 struct xkb_state *state = keyboard->xkb_state;
511 xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
512 xkb_layout_index_t layout_idx;
513 for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
514 bool is_active =
515 xkb_state_layout_index_is_active(state,
516 layout_idx,
517 XKB_STATE_LAYOUT_EFFECTIVE);
518 if (is_active) {
519 const char *layout =
520 xkb_keymap_layout_get_name(keymap, layout_idx);
521 json_object_object_add(object, "xkb_active_layout_name",
522 json_object_new_string(layout));
523 break;
524 }
525 }
526 }
527
506 return object; 528 return object;
507} 529}
508 530
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 663518f6..243b5fdc 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -111,7 +111,7 @@ static const char *pretty_type_name(const char *name) {
111} 111}
112 112
113static void pretty_print_input(json_object *i) { 113static void pretty_print_input(json_object *i) {
114 json_object *id, *name, *type, *product, *vendor; 114 json_object *id, *name, *type, *product, *vendor, *kbdlayout;
115 json_object_object_get_ex(i, "identifier", &id); 115 json_object_object_get_ex(i, "identifier", &id);
116 json_object_object_get_ex(i, "name", &name); 116 json_object_object_get_ex(i, "name", &name);
117 json_object_object_get_ex(i, "type", &type); 117 json_object_object_get_ex(i, "type", &type);
@@ -123,7 +123,7 @@ static void pretty_print_input(json_object *i) {
123 " Type: %s\n" 123 " Type: %s\n"
124 " Identifier: %s\n" 124 " Identifier: %s\n"
125 " Product ID: %d\n" 125 " Product ID: %d\n"
126 " Vendor ID: %d\n\n"; 126 " Vendor ID: %d\n";
127 127
128 128
129 printf(fmt, json_object_get_string(name), 129 printf(fmt, json_object_get_string(name),
@@ -131,6 +131,13 @@ static void pretty_print_input(json_object *i) {
131 json_object_get_string(id), 131 json_object_get_string(id),
132 json_object_get_int(product), 132 json_object_get_int(product),
133 json_object_get_int(vendor)); 133 json_object_get_int(vendor));
134
135 if (json_object_object_get_ex(i, "xkb_active_layout_name", &kbdlayout)) {
136 printf(" Active Keyboard Layout: %s\n",
137 json_object_get_string(kbdlayout));
138 }
139
140 printf("\n");
134} 141}
135 142
136static void pretty_print_seat(json_object *i) { 143static void pretty_print_seat(json_object *i) {