aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-13 09:17:09 -0400
committerGitHub <noreply@github.com>2018-03-13 09:17:09 -0400
commit1dca041513105e966c40197da8518c6abea9a79c (patch)
tree837339ed8929c7c21630b3f4b49d53a0482b5a97
parent3035db74df147aa5fe7252a626c8c767e5e30631 (diff)
parent4ab55060644a9c7f01e8f257b7dd34067adfaaf8 (diff)
Merge pull request #1623 from emersion/ipc-output-modes
ipc: add output modes
-rw-r--r--sway/ipc-json.c14
-rw-r--r--swaymsg/main.c26
2 files changed, 38 insertions, 2 deletions
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) {