From f2985000f364693fbeb832df1c4fd468c608e40f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 18 Dec 2017 14:27:38 -0500 Subject: ipc get_inputs --- swaymsg/main.c | 72 +++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) (limited to 'swaymsg/main.c') diff --git a/swaymsg/main.c b/swaymsg/main.c index 2f9cfb14..18f17a59 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -61,55 +61,49 @@ static void pretty_print_workspace(json_object *w) { ); } -static void pretty_print_input(json_object *i) { - json_object *id, *name, *size, *caps; - json_object_object_get_ex(i, "identifier", &id); - json_object_object_get_ex(i, "name", &name); - json_object_object_get_ex(i, "size", &size); - json_object_object_get_ex(i, "capabilities", &caps); - - printf( "Input device %s\n Type: ", json_object_get_string(name)); - +static const char *pretty_type_name(const char *name) { + // TODO these constants probably belong in the common lib struct { const char *a; const char *b; - } cap_names[] = { + } type_names[] = { { "keyboard", "Keyboard" }, { "pointer", "Mouse" }, - { "touch", "Touch" }, - { "tablet_tool", "Tablet tool" }, { "tablet_pad", "Tablet pad" }, - { "gesture", "Gesture" }, - { "switch", "Switch" }, + { "tablet_tool", "Tablet tool" }, + { "touch", "Touch" }, }; - size_t len = json_object_array_length(caps); - if (len == 0) { - printf("Unknown"); - } - - json_object *cap; - for (size_t i = 0; i < len; ++i) { - cap = json_object_array_get_idx(caps, i); - const char *cap_s = json_object_get_string(cap); - const char *_name = NULL; - for (size_t j = 0; j < sizeof(cap_names) / sizeof(cap_names[0]); ++i) { - if (strcmp(cap_names[i].a, cap_s) == 0) { - _name = cap_names[i].b; - break; - } + for (size_t i = 0; i < sizeof(type_names) / sizeof(type_names[0]); ++i) { + if (strcmp(type_names[i].a, name) == 0) { + return type_names[i].b; } - printf("%s%s", _name ? _name : cap_s, len > 1 && i != len - 1 ? ", " : ""); - } - printf("\n Sway ID: %s\n", json_object_get_string(id)); - if (size) { - json_object *width, *height; - json_object_object_get_ex(size, "width", &width); - json_object_object_get_ex(size, "height", &height); - printf(" Size: %lfmm x %lfmm\n", - json_object_get_double(width), json_object_get_double(height)); } - printf("\n"); + + return name; +} + +static void pretty_print_input(json_object *i) { + json_object *id, *name, *type, *product, *vendor; + json_object_object_get_ex(i, "identifier", &id); + json_object_object_get_ex(i, "name", &name); + json_object_object_get_ex(i, "type", &type); + json_object_object_get_ex(i, "product", &product); + json_object_object_get_ex(i, "vendor", &vendor); + + const char *fmt = + "Input device: %s\n" + " Type: %s\n" + " Identifier: %s\n" + " Product ID: %d\n" + " Vendor ID: %d\n\n"; + + + printf(fmt, json_object_get_string(name), + pretty_type_name(json_object_get_string(type)), + json_object_get_string(id), + json_object_get_int(product), + json_object_get_int(vendor)); } static void pretty_print_output(json_object *o) { -- cgit v1.2.3 From 8b4d81114a6e25be9f8f7c7bca17e55dbebd675d Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 18 Dec 2017 17:52:50 -0500 Subject: fix memory leak in swaymsg --- swaymsg/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'swaymsg/main.c') diff --git a/swaymsg/main.c b/swaymsg/main.c index 18f17a59..dfc175a8 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -335,7 +335,7 @@ int main(int argc, char **argv) { } else { pretty_print(type, obj); } - free(obj); + json_object_put(obj); } } close(socketfd); -- cgit v1.2.3 From a4c1270ef0a3c5bd610b13867be7616a55e59dc5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 05:38:41 -0500 Subject: fix memory leak in swaymsg --- swaymsg/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'swaymsg/main.c') diff --git a/swaymsg/main.c b/swaymsg/main.c index dfc175a8..b431872a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -308,9 +308,11 @@ int main(int argc, char **argv) { } free(cmdtype); - char *command = strdup(""); + char *command = NULL; if (optind < argc) { command = join_args(argv + optind, argc - optind); + } else { + command = strdup(""); } int ret = 0; -- cgit v1.2.3 From fff67906e189e3d64860557db99b5af49d848315 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Dec 2017 11:16:57 +0100 Subject: Pretty-print all output info in swaymsg -t get_outputs --- swaymsg/main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'swaymsg/main.c') diff --git a/swaymsg/main.c b/swaymsg/main.c index b431872a..8a720fca 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -107,29 +107,42 @@ static void pretty_print_input(json_object *i) { } static void pretty_print_output(json_object *o) { - json_object *name, *rect, *focused, *active, *ws, *scale; + json_object *name, *rect, *focused, *active, *ws; json_object_object_get_ex(o, "name", &name); json_object_object_get_ex(o, "rect", &rect); json_object_object_get_ex(o, "focused", &focused); json_object_object_get_ex(o, "active", &active); json_object_object_get_ex(o, "current_workspace", &ws); + json_object *make, *model, *serial, *scale, *refresh, *transform; + json_object_object_get_ex(o, "make", &make); + json_object_object_get_ex(o, "model", &model); + json_object_object_get_ex(o, "serial", &serial); json_object_object_get_ex(o, "scale", &scale); + json_object_object_get_ex(o, "refresh", &refresh); + json_object_object_get_ex(o, "transform", &transform); json_object *x, *y, *width, *height; json_object_object_get_ex(rect, "x", &x); json_object_object_get_ex(rect, "y", &y); json_object_object_get_ex(rect, "width", &width); json_object_object_get_ex(rect, "height", &height); printf( - "Output %s%s%s\n" - " Geometry: %dx%d @ %d,%d\n" + "Output %s '%s %s %s'%s%s\n" + " Mode: %dx%d @ %f Hz\n" + " Position: %d,%d\n" " Scale factor: %dx\n" + " Transform: %s\n" " Workspace: %s\n\n", json_object_get_string(name), + json_object_get_string(make), + json_object_get_string(model), + json_object_get_string(serial), json_object_get_boolean(focused) ? " (focused)" : "", !json_object_get_boolean(active) ? " (inactive)" : "", json_object_get_int(width), json_object_get_int(height), + (float)json_object_get_int(refresh) / 1000, json_object_get_int(x), json_object_get_int(y), json_object_get_int(scale), + json_object_get_string(transform), json_object_get_string(ws) ); } -- cgit v1.2.3 From dc0e6d46fb63aad09b8767d94976c6e56db5ffdb Mon Sep 17 00:00:00 2001 From: Rachel K Date: Thu, 4 Jan 2018 15:43:40 +0000 Subject: update json-c dep to 0.13 --- meson.build | 2 +- swaymsg/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'swaymsg/main.c') diff --git a/meson.build b/meson.build index 029aea46..49392126 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ datadir = get_option('datadir') sysconfdir = get_option('sysconfdir') prefix = get_option('prefix') -jsonc = dependency('json-c', version: '>=0.12.1') +jsonc = dependency('json-c', version: '>=0.13') pcre = dependency('libpcre') wlroots = dependency('wlroots') wayland_server = dependency('wayland-server') diff --git a/swaymsg/main.c b/swaymsg/main.c index 8a720fca..a34eced4 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -156,7 +156,7 @@ static void pretty_print_version(json_object *v) { static void pretty_print_clipboard(json_object *v) { if (success(v, true)) { if (json_object_is_type(v, json_type_array)) { - for (int i = 0; i < json_object_array_length(v); ++i) { + for (size_t i = 0; i < json_object_array_length(v); ++i) { json_object *o = json_object_array_get_idx(v, i); printf("%s\n", json_object_get_string(o)); } -- cgit v1.2.3 From 51f6718581ab7e21fd7a8d50450586f3969781ab Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 5 Jan 2018 23:09:26 +0100 Subject: swaymsg: convert to wlr_log --- swaymsg/main.c | 2 +- swaymsg/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'swaymsg/main.c') diff --git a/swaymsg/main.c b/swaymsg/main.c index a34eced4..88b14813 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -232,7 +232,7 @@ int main(int argc, char **argv) { char *socket_path = NULL; char *cmdtype = NULL; - init_log(L_INFO); + wlr_log_init(L_INFO, NULL); static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, diff --git a/swaymsg/meson.build b/swaymsg/meson.build index 2d678878..8638b838 100644 --- a/swaymsg/meson.build +++ b/swaymsg/meson.build @@ -2,7 +2,7 @@ executable( 'swaymsg', 'main.c', include_directories: [sway_inc], - dependencies: [jsonc], + dependencies: [jsonc, wlroots], link_with: [lib_sway_common], install: true ) -- cgit v1.2.3 From 4ab55060644a9c7f01e8f257b7dd34067adfaaf8 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 12 Mar 2018 13:48:42 +0100 Subject: ipc: add output modes --- sway/ipc-json.c | 14 ++++++++++++++ swaymsg/main.c | 26 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'swaymsg/main.c') diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 213c8fb6..977f1ecb 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -78,6 +78,20 @@ static void ipc_json_describe_output(swayc_t *container, json_object *object) { json_object_new_string(ipc_json_get_output_transform(wlr_output->transform))); // TODO WLR need to set "current_workspace" to the currently focused // workspace in a way that makes sense with multiseat + + json_object *modes_array = json_object_new_array(); + struct wlr_output_mode *mode; + wl_list_for_each(mode, &wlr_output->modes, link) { + json_object *mode_object = json_object_new_object(); + json_object_object_add(mode_object, "width", + json_object_new_int(mode->width)); + json_object_object_add(mode_object, "height", + json_object_new_int(mode->height)); + json_object_object_add(mode_object, "refresh", + json_object_new_int(mode->refresh)); + json_object_array_add(modes_array, mode_object); + } + json_object_object_add(object, "modes", modes_array); } static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { diff --git a/swaymsg/main.c b/swaymsg/main.c index 88b14813..c9be3a86 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -125,13 +125,16 @@ static void pretty_print_output(json_object *o) { json_object_object_get_ex(rect, "y", &y); json_object_object_get_ex(rect, "width", &width); json_object_object_get_ex(rect, "height", &height); + json_object *modes; + json_object_object_get_ex(o, "modes", &modes); + printf( "Output %s '%s %s %s'%s%s\n" - " Mode: %dx%d @ %f Hz\n" + " Current mode: %dx%d @ %f Hz\n" " Position: %d,%d\n" " Scale factor: %dx\n" " Transform: %s\n" - " Workspace: %s\n\n", + " Workspace: %s\n", json_object_get_string(name), json_object_get_string(make), json_object_get_string(model), @@ -145,6 +148,25 @@ static void pretty_print_output(json_object *o) { json_object_get_string(transform), json_object_get_string(ws) ); + + size_t modes_len = json_object_array_length(modes); + if (modes_len > 0) { + printf(" Available modes:\n"); + for (size_t i = 0; i < modes_len; ++i) { + json_object *mode = json_object_array_get_idx(modes, i); + + json_object *mode_width, *mode_height, *mode_refresh; + json_object_object_get_ex(mode, "width", &mode_width); + json_object_object_get_ex(mode, "height", &mode_height); + json_object_object_get_ex(mode, "refresh", &mode_refresh); + + printf(" %dx%d @ %f Hz\n", json_object_get_int(mode_width), + json_object_get_int(mode_height), + (float)json_object_get_int(mode_refresh) / 1000); + } + } + + printf("\n"); } static void pretty_print_version(json_object *v) { -- cgit v1.2.3