aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-json.c
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2022-09-22 17:38:14 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2022-10-03 13:35:52 +0200
commitf70d1e1b959d218378cb786bcaeb44ea9ed05aa2 (patch)
treee36c41233b20861e920387bed0b019340c0ff05b /sway/ipc-json.c
parentman: Add XWayland information (diff)
downloadsway-f70d1e1b959d218378cb786bcaeb44ea9ed05aa2.tar.gz
sway-f70d1e1b959d218378cb786bcaeb44ea9ed05aa2.tar.zst
sway-f70d1e1b959d218378cb786bcaeb44ea9ed05aa2.zip
ipc: expose mode picture aspect ratio
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r--sway/ipc-json.c62
1 files changed, 48 insertions, 14 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 763fb3fe..61613f53 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -116,6 +116,39 @@ static const char *ipc_json_output_adaptive_sync_status_description(
116 return NULL; 116 return NULL;
117} 117}
118 118
119static const char *ipc_json_output_mode_aspect_ratio_description(
120 enum wlr_output_mode_aspect_ratio aspect_ratio) {
121 switch (aspect_ratio) {
122 case WLR_OUTPUT_MODE_ASPECT_RATIO_NONE:
123 return "none";
124 case WLR_OUTPUT_MODE_ASPECT_RATIO_4_3:
125 return "4:3";
126 case WLR_OUTPUT_MODE_ASPECT_RATIO_16_9:
127 return "16:9";
128 case WLR_OUTPUT_MODE_ASPECT_RATIO_64_27:
129 return "64:27";
130 case WLR_OUTPUT_MODE_ASPECT_RATIO_256_135:
131 return "256:135";
132 }
133 return NULL;
134}
135
136static json_object *ipc_json_output_mode_description(
137 const struct wlr_output_mode *mode) {
138 const char *pic_ar =
139 ipc_json_output_mode_aspect_ratio_description(mode->picture_aspect_ratio);
140 json_object *mode_object = json_object_new_object();
141 json_object_object_add(mode_object, "width",
142 json_object_new_int(mode->width));
143 json_object_object_add(mode_object, "height",
144 json_object_new_int(mode->height));
145 json_object_object_add(mode_object, "refresh",
146 json_object_new_int(mode->refresh));
147 json_object_object_add(mode_object, "picture_aspect_ratio",
148 json_object_new_string(pic_ar));
149 return mode_object;
150}
151
119#if HAVE_XWAYLAND 152#if HAVE_XWAYLAND
120static const char *ipc_json_xwindow_type_description(struct sway_view *view) { 153static const char *ipc_json_xwindow_type_description(struct sway_view *view) {
121 struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; 154 struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface;
@@ -308,25 +341,26 @@ static void ipc_json_describe_enabled_output(struct sway_output *output,
308 json_object *modes_array = json_object_new_array(); 341 json_object *modes_array = json_object_new_array();
309 struct wlr_output_mode *mode; 342 struct wlr_output_mode *mode;
310 wl_list_for_each(mode, &wlr_output->modes, link) { 343 wl_list_for_each(mode, &wlr_output->modes, link) {
311 json_object *mode_object = json_object_new_object(); 344 json_object *mode_object =
312 json_object_object_add(mode_object, "width", 345 ipc_json_output_mode_description(mode);
313 json_object_new_int(mode->width));
314 json_object_object_add(mode_object, "height",
315 json_object_new_int(mode->height));
316 json_object_object_add(mode_object, "refresh",
317 json_object_new_int(mode->refresh));
318 json_object_array_add(modes_array, mode_object); 346 json_object_array_add(modes_array, mode_object);
319 } 347 }
320 348
321 json_object_object_add(object, "modes", modes_array); 349 json_object_object_add(object, "modes", modes_array);
322 350
323 json_object *current_mode_object = json_object_new_object(); 351 json_object *current_mode_object;
324 json_object_object_add(current_mode_object, "width", 352 if (wlr_output->current_mode != NULL) {
325 json_object_new_int(wlr_output->width)); 353 current_mode_object =
326 json_object_object_add(current_mode_object, "height", 354 ipc_json_output_mode_description(wlr_output->current_mode);
327 json_object_new_int(wlr_output->height)); 355 } else {
328 json_object_object_add(current_mode_object, "refresh", 356 current_mode_object = json_object_new_object();
329 json_object_new_int(wlr_output->refresh)); 357 json_object_object_add(current_mode_object, "width",
358 json_object_new_int(wlr_output->width));
359 json_object_object_add(current_mode_object, "height",
360 json_object_new_int(wlr_output->height));
361 json_object_object_add(current_mode_object, "refresh",
362 json_object_new_int(wlr_output->refresh));
363 }
330 json_object_object_add(object, "current_mode", current_mode_object); 364 json_object_object_add(object, "current_mode", current_mode_object);
331 365
332 struct sway_node *parent = node_get_parent(&output->node); 366 struct sway_node *parent = node_get_parent(&output->node);