From 1d702b6376b49c2e115c5b985ca241aedc40a48b Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 30 Nov 2017 11:40:49 -0500 Subject: meson build swaymsg --- swaymsg/meson.build | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 swaymsg/meson.build (limited to 'swaymsg') diff --git a/swaymsg/meson.build b/swaymsg/meson.build new file mode 100644 index 00000000..2d678878 --- /dev/null +++ b/swaymsg/meson.build @@ -0,0 +1,8 @@ +executable( + 'swaymsg', + 'main.c', + include_directories: [sway_inc], + dependencies: [jsonc], + link_with: [lib_sway_common], + install: true +) -- cgit v1.2.3 From 517af37cc9a9f7b5efa3e22d7021aab691c80244 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 30 Nov 2017 11:54:01 -0500 Subject: remove relevant CMakeLists.txt --- CMakeLists.txt | 165 ----------------------------------------- common/CMakeLists.txt | 15 ---- completions/zsh/CMakeLists.txt | 4 - sway/CMakeLists.txt | 96 ------------------------ swaymsg/CMakeLists.txt | 23 ------ 5 files changed, 303 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 common/CMakeLists.txt delete mode 100644 completions/zsh/CMakeLists.txt delete mode 100644 sway/CMakeLists.txt delete mode 100644 swaymsg/CMakeLists.txt (limited to 'swaymsg') diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9580e15d..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,165 +0,0 @@ -cmake_minimum_required(VERSION 3.1.0) - -project(sway C) - -add_compile_options(-g) -set(CMAKE_C_STANDARD 99) -set(CMAKE_C_EXTENSIONS OFF) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) -add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror) - -# Add Address Sanitiezed build type -set(CMAKE_C_FLAGS_ASAN - "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" - CACHE STRING "Flags used by the C compiler during address sanitizer builds." - FORCE ) -mark_as_advanced( - CMAKE_C_FLAGS_ASAN - CMAKE_EXE_LINKER_FLAGS_DEBUG - CMAKE_SHARED_LINKER_FLAGS_DEBUG - ) - -list(INSERT CMAKE_MODULE_PATH 0 - ${CMAKE_CURRENT_SOURCE_DIR}/CMake - ) - -if (VERSION) - add_definitions(-DSWAY_VERSION=\"${VERSION}\") -else() - execute_process( - COMMAND git describe --always --tags - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - - string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC) - add_definitions("-DSWAY_VERSION=\"${GIT_COMMIT_HASH} (${CURRENT_DATE}, branch \\\"${GIT_BRANCH}\\\")\"") -endif() - -option(enable-swaylock "Enables the swaylock utility" YES) -option(enable-swaybg "Enables the wallpaper utility" YES) -option(enable-swaybar "Enables the swaybar utility" YES) -option(enable-swaygrab "Enables the swaygrab utility" YES) -option(enable-swaymsg "Enables the swaymsg utility" YES) -option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES) -option(enable-tray "Enables the swaybar tray" YES) -option(zsh-completions "Zsh shell completions" NO) -option(default-wallpaper "Installs the default wallpaper" YES) -option(LD_LIBRARY_PATH "Configure sway's default LD_LIBRARY_PATH") - -if (LD_LIBRARY_PATH) - add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") -endif() - -find_package(JsonC 0.12.1 REQUIRED) -find_package(PCRE REQUIRED) -find_package(Wlroots REQUIRED) -find_package(Wayland REQUIRED) -find_package(XKBCommon REQUIRED) -find_package(Cairo REQUIRED) -find_package(Pango REQUIRED) -find_package(GdkPixbuf) -find_package(PAM) -find_package(DBus 1.10) - -find_package(LibInput REQUIRED) - -if (CMAKE_SYSTEM_NAME STREQUAL Linux) - find_package(Libcap REQUIRED) -endif (CMAKE_SYSTEM_NAME STREQUAL Linux) - -if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - find_package(EpollShim REQUIRED) -endif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - -include(FeatureSummary) -include(Manpage) -include(GNUInstallDirs) - -if (enable-gdk-pixbuf) - if (GDK_PIXBUF_FOUND) - set(WITH_GDK_PIXBUF YES) - add_definitions(-DWITH_GDK_PIXBUF) - else() - message(WARNING "gdk-pixbuf required but not found, only png images supported.") - endif() -else() - message(STATUS "Building without gdk-pixbuf, only png images supported.") -endif() - -if (enable-tray) - if (DBUS_FOUND) - set(ENABLE_TRAY TRUE) - add_definitions(-DENABLE_TRAY) - else() - message(WARNING "Tray required but DBus was not found. Tray will not be included") - endif() -else() - message(STATUS "Building without the tray.") -endif() - -include_directories(include) - -add_subdirectory(protocols) -add_subdirectory(common) -add_subdirectory(wayland) - -add_subdirectory(sway) -if(enable-swaybg) - if(CAIRO_FOUND AND PANGO_FOUND) - # TODO WLR - #add_subdirectory(swaybg) - else() - message(WARNING "Not building swaybg - cairo, and pango are required.") - endif() -endif() -if(enable-swaymsg) - add_subdirectory(swaymsg) -endif() -if(enable-swaygrab) - # TODO WLR - #add_subdirectory(swaygrab) -endif() -if(enable-swaybar) - if(CAIRO_FOUND AND PANGO_FOUND) - # TODO WLR - #add_subdirectory(swaybar) - else() - message(WARNING "Not building swaybar - cairo, and pango are required.") - endif() -endif() -if(enable-swaylock) - if(CAIRO_FOUND AND PANGO_FOUND AND PAM_FOUND) - # TODO WLR - #add_subdirectory(swaylock) - else() - message(WARNING "Not building swaylock - cairo, pango, and PAM are required.") - endif() -endif() -if(zsh-completions) - add_subdirectory(completions/zsh) -endif() -install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop - DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/wayland-sessions - COMPONENT data - ) - -if(default-wallpaper) - install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets/ - DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/backgrounds/sway - COMPONENT data - FILES_MATCHING PATTERN "*Wallpaper*" - ) -endif() - -feature_summary(WHAT ALL) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt deleted file mode 100644 index 4fa71f3a..00000000 --- a/common/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories( - ${WLC_INCLUDE_DIRS} - ${XKBCOMMON_INCLUDE_DIRS} -) - -add_library(sway-common STATIC - ipc-client.c - list.c - log.c - util.c - readline.c - stringop.c -) - -target_link_libraries(sway-common m) diff --git a/completions/zsh/CMakeLists.txt b/completions/zsh/CMakeLists.txt deleted file mode 100644 index 62c85090..00000000 --- a/completions/zsh/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -install( - FILES _sway _swaymsg _swaygrab _swaylock - DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/zsh/site-functions/ -) diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt deleted file mode 100644 index 274fcc4a..00000000 --- a/sway/CMakeLists.txt +++ /dev/null @@ -1,96 +0,0 @@ -include_directories( - ${PROTOCOLS_INCLUDE_DIRS} - ${WLR_INCLUDE_DIRS} - ${PCRE_INCLUDE_DIRS} - ${JSONC_INCLUDE_DIRS} - ${XKBCOMMON_INCLUDE_DIRS} - ${LIBINPUT_INCLUDE_DIRS} - ${CAIRO_INCLUDE_DIRS} - ${PANGO_INCLUDE_DIRS} - ${WAYLAND_INCLUDE_DIR} -) - -add_executable(sway - desktop/output.c - desktop/xdg_shell_v6.c - - commands.c - commands/exit.c - - tree/container.c - tree/layout.c - tree/workspace.c - - base64.c - main.c - server.c - ipc-json.c - ipc-server.c -) - -add_definitions( - -DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -) - -target_link_libraries(sway - sway-common - sway-protocols - sway-wayland - ${WLR_LIBRARIES} - ${XKBCOMMON_LIBRARIES} - ${PCRE_LIBRARIES} - ${JSONC_LIBRARIES} - ${WAYLAND_SERVER_LIBRARIES} - ${LIBINPUT_LIBRARIES} - ${PANGO_LIBRARIES} - ${JSONC_LIBRARIES} - m -) - -if (CMAKE_SYSTEM_NAME STREQUAL Linux) - target_link_libraries(sway cap) -endif (CMAKE_SYSTEM_NAME STREQUAL Linux) - -install( - TARGETS sway - RUNTIME - DESTINATION bin - COMPONENT runtime -) - -add_custom_target(configs ALL) - -function(add_config name source destination) - add_custom_command( - OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name} - COMMAND sed -r - 's?__PREFIX__?${CMAKE_INSTALL_PREFIX}?g\; s?__SYSCONFDIR__?${CMAKE_INSTALL_FULL_SYSCONFDIR}?g\; s?__DATADIR__?${CMAKE_INSTALL_FULL_DATADIR}?g' - ${PROJECT_SOURCE_DIR}/${source}.in > ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name} - DEPENDS ${PROJECT_SOURCE_DIR}/${source}.in - COMMENT "Generating config file ${source}" - ) - - install( - FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name} - DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${destination} - COMPONENT configuration - ) - - add_custom_target(config-${name} DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) - add_dependencies(configs config-${name}) -endfunction() - -add_config(config config sway) -add_config(00-defaults security.d/00-defaults sway/security.d) - -if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - add_config(10-freebsd security.d/10-freebsd sway/security.d) -endif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - -if (A2X_FOUND) - add_manpage(sway 1) - add_manpage(sway 5) - add_manpage(sway-input 5) - add_manpage(sway-bar 5) - add_manpage(sway-security 7) -endif() diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt deleted file mode 100644 index b428a409..00000000 --- a/swaymsg/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -add_executable(swaymsg - main.c -) - -include_directories( - ${JSONC_INCLUDE_DIRS} -) - -target_link_libraries(swaymsg - sway-common - ${JSONC_LIBRARIES} -) - -install( - TARGETS swaymsg - RUNTIME - DESTINATION bin - COMPONENT runtime -) - -if (A2X_FOUND) - add_manpage(swaymsg 1) -endif() -- cgit v1.2.3 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 --- include/sway/ipc-json.h | 2 ++ sway/ipc-json.c | 37 +++++++++++++++++++++++++ sway/ipc-server.c | 14 ++++++++++ swaymsg/main.c | 72 +++++++++++++++++++++++-------------------------- 4 files changed, 86 insertions(+), 39 deletions(-) (limited to 'swaymsg') diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 9435b664..eef5a018 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h @@ -2,10 +2,12 @@ #define _SWAY_IPC_JSON_H #include #include "sway/container.h" +#include "sway/input/input-manager.h" json_object *ipc_json_get_version(); json_object *ipc_json_describe_container(swayc_t *c); json_object *ipc_json_describe_container_recursive(swayc_t *c); +json_object *ipc_json_describe_input(struct sway_input_device *device); #endif diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 09a32c1b..bab9a201 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -141,3 +141,40 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) { return object; } + +static const char *describe_device_type(struct sway_input_device *device) { + switch (device->wlr_device->type) { + case WLR_INPUT_DEVICE_POINTER: + return "pointer"; + case WLR_INPUT_DEVICE_KEYBOARD: + return "keyboard"; + case WLR_INPUT_DEVICE_TOUCH: + return "touch"; + case WLR_INPUT_DEVICE_TABLET_TOOL: + return "tablet_tool"; + case WLR_INPUT_DEVICE_TABLET_PAD: + return "tablet_pad"; + } + return "unknown"; +} + +json_object *ipc_json_describe_input(struct sway_input_device *device) { + if (!(sway_assert(device, "Device must not be null"))) { + return NULL; + } + + json_object *object = json_object_new_object(); + + json_object_object_add(object, "identifier", + json_object_new_string(device->identifier)); + json_object_object_add(object, "name", + json_object_new_string(device->wlr_device->name)); + json_object_object_add(object, "vendor", + json_object_new_int(device->wlr_device->vendor)); + json_object_object_add(object, "product", + json_object_new_int(device->wlr_device->product)); + json_object_object_add(object, "type", + json_object_new_string(describe_device_type(device))); + + return object; +} diff --git a/sway/ipc-server.c b/sway/ipc-server.c index b7cd2d76..046e40a8 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -20,6 +20,7 @@ #include "sway/ipc-json.h" #include "sway/ipc-server.h" #include "sway/server.h" +#include "sway/input/input-manager.h" #include "list.h" #include "log.h" @@ -359,6 +360,19 @@ void ipc_client_handle_command(struct ipc_client *client) { goto exit_cleanup; } + case IPC_GET_INPUTS: + { + json_object *inputs = json_object_new_array(); + struct sway_input_device *device = NULL; + wl_list_for_each(device, &input_manager->devices, link) { + json_object_array_add(inputs, ipc_json_describe_input(device)); + } + const char *json_string = json_object_to_json_string(inputs); + ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); + json_object_put(inputs); // free + goto exit_cleanup; + } + case IPC_GET_TREE: { json_object *tree = 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') 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') 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') 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') 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') 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') 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