ipc: add xkb_layout_names and xkb_active_layout_index
These can be useful to implement per-window layouts as a script. See https://github.com/swaywm/sway/issues/2361
This commit is contained in:
parent
5b1a8d62b9
commit
84e4061bf4
|
@ -824,19 +824,24 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
|
||||||
struct wlr_keyboard *keyboard = device->wlr_device->keyboard;
|
struct wlr_keyboard *keyboard = device->wlr_device->keyboard;
|
||||||
struct xkb_keymap *keymap = keyboard->keymap;
|
struct xkb_keymap *keymap = keyboard->keymap;
|
||||||
struct xkb_state *state = keyboard->xkb_state;
|
struct xkb_state *state = keyboard->xkb_state;
|
||||||
|
|
||||||
|
json_object *layouts_arr = json_object_new_array();
|
||||||
|
json_object_object_add(object, "xkb_layout_names", layouts_arr);
|
||||||
|
|
||||||
xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
|
xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
|
||||||
xkb_layout_index_t layout_idx;
|
xkb_layout_index_t layout_idx;
|
||||||
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
|
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
|
||||||
bool is_active =
|
const char *layout = xkb_keymap_layout_get_name(keymap, layout_idx);
|
||||||
xkb_state_layout_index_is_active(state,
|
json_object_array_add(layouts_arr,
|
||||||
layout_idx,
|
layout ? json_object_new_string(layout) : NULL);
|
||||||
XKB_STATE_LAYOUT_EFFECTIVE);
|
|
||||||
|
bool is_active = xkb_state_layout_index_is_active(state,
|
||||||
|
layout_idx, XKB_STATE_LAYOUT_EFFECTIVE);
|
||||||
if (is_active) {
|
if (is_active) {
|
||||||
const char *layout =
|
json_object_object_add(object, "xkb_active_layout_index",
|
||||||
xkb_keymap_layout_get_name(keymap, layout_idx);
|
json_object_new_int(layout_idx));
|
||||||
json_object_object_add(object, "xkb_active_layout_name",
|
json_object_object_add(object, "xkb_active_layout_name",
|
||||||
layout ? json_object_new_string(layout) : NULL);
|
layout ? json_object_new_string(layout) : NULL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue