From 02c75ebe37d50ff97c4fd8b6be169ac4e1074b07 Mon Sep 17 00:00:00 2001 From: nyorain Date: Fri, 7 Jul 2017 15:38:45 +0200 Subject: Implement ipc get_clipboard --- swaymsg/main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'swaymsg') diff --git a/swaymsg/main.c b/swaymsg/main.c index efd0ec25..fa28553b 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -144,10 +144,23 @@ static void pretty_print_version(json_object *v) { printf("sway version %s\n", json_object_get_string(ver)); } +static void pretty_print_clipboard(json_object *v) { + bool _success; + json_object *success; + json_object_object_get_ex(v, "success", &success); + _success = json_object_get_boolean(success); + + if (_success) { + json_object *ver; + json_object_object_get_ex(v, "content", &ver); + printf("%s\n", json_object_get_string(ver)); + } +} + static void pretty_print(int type, json_object *resp) { if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && - type != IPC_GET_VERSION) { + type != IPC_GET_VERSION && type != IPC_GET_CLIPBOARD) { printf("%s\n", json_object_to_json_string_ext(resp, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); return; @@ -158,6 +171,11 @@ static void pretty_print(int type, json_object *resp) { return; } + if (type == IPC_GET_CLIPBOARD) { + pretty_print_clipboard(resp); + return; + } + json_object *obj; size_t len = json_object_array_length(resp); for (size_t i = 0; i < len; ++i) { @@ -267,6 +285,8 @@ int main(int argc, char **argv) { type = IPC_GET_BAR_CONFIG; } else if (strcasecmp(cmdtype, "get_version") == 0) { type = IPC_GET_VERSION; + } else if (strcasecmp(cmdtype, "get_clipboard") == 0) { + type = IPC_GET_CLIPBOARD; } else { sway_abort("Unknown message type %s", cmdtype); } -- cgit v1.2.3-54-g00ecf