mirror of
https://github.com/swaywm/sway.git
synced 2026-04-23 06:46:27 -04:00
Fix segfault when connecting keyboard/mouse
Sometimes `device->wlr_device->keyboard->keymap` is NULL. When that happens, the call to `xkb_keymap_num_layouts` segfaults. This adds a guard around the handling of `keymap` to prevent that. This should resolve issues #6502 #6484
This commit is contained in:
parent
ffc603d451
commit
6f0b5b9cb3
1 changed files with 15 additions and 13 deletions
|
|
@ -989,20 +989,22 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
|
||||||
json_object *layouts_arr = json_object_new_array();
|
json_object *layouts_arr = json_object_new_array();
|
||||||
json_object_object_add(object, "xkb_layout_names", layouts_arr);
|
json_object_object_add(object, "xkb_layout_names", layouts_arr);
|
||||||
|
|
||||||
xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
|
if (keymap) {
|
||||||
xkb_layout_index_t layout_idx;
|
xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
|
||||||
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
|
xkb_layout_index_t layout_idx;
|
||||||
const char *layout = xkb_keymap_layout_get_name(keymap, layout_idx);
|
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
|
||||||
json_object_array_add(layouts_arr,
|
const char *layout = xkb_keymap_layout_get_name(keymap, layout_idx);
|
||||||
layout ? json_object_new_string(layout) : NULL);
|
json_object_array_add(layouts_arr,
|
||||||
|
|
||||||
bool is_active = xkb_state_layout_index_is_active(state,
|
|
||||||
layout_idx, XKB_STATE_LAYOUT_EFFECTIVE);
|
|
||||||
if (is_active) {
|
|
||||||
json_object_object_add(object, "xkb_active_layout_index",
|
|
||||||
json_object_new_int(layout_idx));
|
|
||||||
json_object_object_add(object, "xkb_active_layout_name",
|
|
||||||
layout ? json_object_new_string(layout) : NULL);
|
layout ? json_object_new_string(layout) : NULL);
|
||||||
|
|
||||||
|
bool is_active = xkb_state_layout_index_is_active(state,
|
||||||
|
layout_idx, XKB_STATE_LAYOUT_EFFECTIVE);
|
||||||
|
if (is_active) {
|
||||||
|
json_object_object_add(object, "xkb_active_layout_index",
|
||||||
|
json_object_new_int(layout_idx));
|
||||||
|
json_object_object_add(object, "xkb_active_layout_name",
|
||||||
|
layout ? json_object_new_string(layout) : NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue