aboutsummaryrefslogtreecommitdiffstats
path: root/swaymsg
diff options
context:
space:
mode:
authorLibravatar nyorain <nyorain@gmail.com>2017-07-07 15:38:45 +0200
committerLibravatar nyorain <nyorain@gmail.com>2017-07-07 15:38:45 +0200
commit02c75ebe37d50ff97c4fd8b6be169ac4e1074b07 (patch)
treedc5f4295e0b988b2f8746507a2fadfbda7b8d881 /swaymsg
parentMake asciidoc (and man pages) optional (diff)
downloadsway-02c75ebe37d50ff97c4fd8b6be169ac4e1074b07.tar.gz
sway-02c75ebe37d50ff97c4fd8b6be169ac4e1074b07.tar.zst
sway-02c75ebe37d50ff97c4fd8b6be169ac4e1074b07.zip
Implement ipc get_clipboard
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c22
1 files changed, 21 insertions, 1 deletions
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) {
144 printf("sway version %s\n", json_object_get_string(ver)); 144 printf("sway version %s\n", json_object_get_string(ver));
145} 145}
146 146
147static void pretty_print_clipboard(json_object *v) {
148 bool _success;
149 json_object *success;
150 json_object_object_get_ex(v, "success", &success);
151 _success = json_object_get_boolean(success);
152
153 if (_success) {
154 json_object *ver;
155 json_object_object_get_ex(v, "content", &ver);
156 printf("%s\n", json_object_get_string(ver));
157 }
158}
159
147static void pretty_print(int type, json_object *resp) { 160static void pretty_print(int type, json_object *resp) {
148 if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && 161 if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
149 type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && 162 type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
150 type != IPC_GET_VERSION) { 163 type != IPC_GET_VERSION && type != IPC_GET_CLIPBOARD) {
151 printf("%s\n", json_object_to_json_string_ext(resp, 164 printf("%s\n", json_object_to_json_string_ext(resp,
152 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); 165 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
153 return; 166 return;
@@ -158,6 +171,11 @@ static void pretty_print(int type, json_object *resp) {
158 return; 171 return;
159 } 172 }
160 173
174 if (type == IPC_GET_CLIPBOARD) {
175 pretty_print_clipboard(resp);
176 return;
177 }
178
161 json_object *obj; 179 json_object *obj;
162 size_t len = json_object_array_length(resp); 180 size_t len = json_object_array_length(resp);
163 for (size_t i = 0; i < len; ++i) { 181 for (size_t i = 0; i < len; ++i) {
@@ -267,6 +285,8 @@ int main(int argc, char **argv) {
267 type = IPC_GET_BAR_CONFIG; 285 type = IPC_GET_BAR_CONFIG;
268 } else if (strcasecmp(cmdtype, "get_version") == 0) { 286 } else if (strcasecmp(cmdtype, "get_version") == 0) {
269 type = IPC_GET_VERSION; 287 type = IPC_GET_VERSION;
288 } else if (strcasecmp(cmdtype, "get_clipboard") == 0) {
289 type = IPC_GET_CLIPBOARD;
270 } else { 290 } else {
271 sway_abort("Unknown message type %s", cmdtype); 291 sway_abort("Unknown message type %s", cmdtype);
272 } 292 }