Skip to content

Commit

Permalink
ipc: handle unnamed xkb_active_layout_name
Browse files Browse the repository at this point in the history
If the active xkb_layout does not have a name, use `NULL` instead of
`json_object_new_string(NULL)`. This also makes it so swaymsg will pretty
print this as `(unnamed)`.
  • Loading branch information
RedSoxFan authored and emersion committed Feb 11, 2019
1 parent 418c19f commit a64a3ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sway/ipc-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
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));
layout ? json_object_new_string(layout) : NULL);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions swaymsg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ static void pretty_print_input(json_object *i) {
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));
const char *layout = json_object_get_string(kbdlayout);
printf(" Active Keyboard Layout: %s\n", layout ? layout : "(unnamed)");
}

if (json_object_object_get_ex(i, "libinput_send_events", &events)) {
Expand Down

0 comments on commit a64a3ee

Please sign in to comment.