Add null-safety check for virtual keyboard keymaps

Note that in the `sway_keyboard_configure` function of sway/input/keyboard.c,
we have skipped the `sway_keyboard_set_layout` function for virtual
keyboards, which then have null keymaps.
Hence, a null-safety check is needed at runtime.
This commit is contained in:
JingMatrix 2024-08-09 00:26:03 +02:00 committed by Simon Ser
parent 951a22c244
commit f344e9d5a5
2 changed files with 12 additions and 2 deletions

View file

@ -1133,7 +1133,9 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
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 =
keymap ? xkb_keymap_num_layouts(keymap) : 0;
// Virtual keyboards might have null keymap
xkb_layout_index_t layout_idx;
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
const char *layout = xkb_keymap_layout_get_name(keymap, layout_idx);