aboutsummaryrefslogtreecommitdiffstats
path: root/swaymsg
diff options
context:
space:
mode:
authorLibravatar nyorain <nyorain@gmail.com>2017-07-07 21:51:34 +0200
committerLibravatar nyorain <nyorain@gmail.com>2017-07-07 21:51:34 +0200
commitc0f2acce4e08eecdcf29058335aece113467daee (patch)
tree7f871abe8b5d1cdf4a74512810d68e9e66f0d57f /swaymsg
parentFix/Simplify get_clipboard ipc-server impl (diff)
downloadsway-c0f2acce4e08eecdcf29058335aece113467daee.tar.gz
sway-c0f2acce4e08eecdcf29058335aece113467daee.tar.zst
sway-c0f2acce4e08eecdcf29058335aece113467daee.zip
Rework get_clipboard implementation
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c41
-rw-r--r--swaymsg/swaymsg.1.txt6
2 files changed, 33 insertions, 14 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index fa28553b..450df673 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -19,15 +19,17 @@ void sway_terminate(int exit_code) {
19 exit(exit_code); 19 exit(exit_code);
20} 20}
21 21
22static void pretty_print_cmd(json_object *r) { 22static bool success(json_object *r, bool fallback) {
23 bool _success;
24 json_object *success; 23 json_object *success;
25 if (!json_object_object_get_ex(r, "success", &success)) { 24 if (!json_object_object_get_ex(r, "success", &success)) {
26 _success = true; 25 return fallback;
27 } else { 26 } else {
28 _success = json_object_get_boolean(success); 27 return json_object_get_boolean(success);
29 } 28 }
30 if (!_success) { 29}
30
31static void pretty_print_cmd(json_object *r) {
32 if (!success(r, true)) {
31 json_object *error; 33 json_object *error;
32 if (!json_object_object_get_ex(r, "error", &error)) { 34 if (!json_object_object_get_ex(r, "error", &error)) {
33 printf("An unknkown error occured"); 35 printf("An unknkown error occured");
@@ -145,15 +147,23 @@ static void pretty_print_version(json_object *v) {
145} 147}
146 148
147static void pretty_print_clipboard(json_object *v) { 149static void pretty_print_clipboard(json_object *v) {
148 bool _success; 150 if (success(v, true)) {
149 json_object *success; 151 if (json_object_is_type(v, json_type_array)) {
150 json_object_object_get_ex(v, "success", &success); 152 for (int i = 0; i < json_object_array_length(v); ++i) {
151 _success = json_object_get_boolean(success); 153 json_object *o = json_object_array_get_idx(v, i);
152 154 printf("%s\n", json_object_get_string(o));
153 if (_success) { 155 }
154 json_object *ver; 156 } else {
155 json_object_object_get_ex(v, "content", &ver); 157 // NOTE: could be extended to print all received types
156 printf("%s\n", json_object_get_string(ver)); 158 // instead just the first one when sways ipc server
159 // supports it
160 struct json_object_iterator iter = json_object_iter_begin(v);
161 struct json_object_iterator end = json_object_iter_end(v);
162 if (!json_object_iter_equal(&iter, &end)) {
163 printf("%s\n", json_object_get_string(
164 json_object_iter_peek_value(&iter)));
165 }
166 }
157 } 167 }
158} 168}
159 169
@@ -310,6 +320,9 @@ int main(int argc, char **argv) {
310 printf("%s\n", resp); 320 printf("%s\n", resp);
311 ret = 1; 321 ret = 1;
312 } else { 322 } else {
323 if (!success(obj, true)) {
324 ret = 1;
325 }
313 if (raw) { 326 if (raw) {
314 printf("%s\n", json_object_to_json_string_ext(obj, 327 printf("%s\n", json_object_to_json_string_ext(obj,
315 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); 328 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
diff --git a/swaymsg/swaymsg.1.txt b/swaymsg/swaymsg.1.txt
index 1f03bee3..6fd08e81 100644
--- a/swaymsg/swaymsg.1.txt
+++ b/swaymsg/swaymsg.1.txt
@@ -65,6 +65,12 @@ IPC Message Types
65*get_version*:: 65*get_version*::
66 Get JSON-encoded version information for the running instance of sway. 66 Get JSON-encoded version information for the running instance of sway.
67 67
68*get_clipboard*::
69 Get JSON-encoded information about the clipboard.
70 Returns the current clipboard mime-types if called without
71 arguments, otherwise returns the clipboard data in the requested
72 formats. Encodes the data using base64 for non-text mime types.
73
68Authors 74Authors
69------- 75-------
70 76