diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-03-06 00:33:10 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-03-06 10:05:00 +0100 |
commit | 19df2e590602abe0b5e1b53bc11debdb37be3fbe (patch) | |
tree | 3dc7057488cec9bbdfc9a54e619a0ccc396d6973 /sway/ipc-json.c | |
parent | Set DISPLAY after initializing Xwayland (diff) | |
download | sway-19df2e590602abe0b5e1b53bc11debdb37be3fbe.tar.gz sway-19df2e590602abe0b5e1b53bc11debdb37be3fbe.tar.zst sway-19df2e590602abe0b5e1b53bc11debdb37be3fbe.zip |
ipc: change {,deco_}rect to match i3
This fixes the `deco_rect` and `rect` properties in the IPC responses
to match i3's behavior.
`deco_rect` should be relative to the parent node, not the current
node. This also takes tabbed and stacked decorations into account and
will calculate `deco_rect` for all containers since tabbed and stacked
child containers will have decorations.
`rect` should exclude the window decorations.
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r-- | sway/ipc-json.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 125df387..c008f241 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -350,6 +350,38 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace, | |||
350 | json_object_object_add(object, "floating_nodes", floating_array); | 350 | json_object_object_add(object, "floating_nodes", floating_array); |
351 | } | 351 | } |
352 | 352 | ||
353 | static void get_deco_rect(struct sway_container *c, struct wlr_box *deco_rect) { | ||
354 | enum sway_container_layout parent_layout = container_parent_layout(c); | ||
355 | if (parent_layout != L_TABBED && parent_layout != L_STACKED && | ||
356 | c->current.border != B_NORMAL) { | ||
357 | deco_rect->x = deco_rect->y = deco_rect->width = deco_rect->height = 0; | ||
358 | return; | ||
359 | } | ||
360 | |||
361 | if (c->parent) { | ||
362 | deco_rect->x = c->x - c->parent->x; | ||
363 | deco_rect->y = c->y - c->parent->y; | ||
364 | } else { | ||
365 | deco_rect->x = c->x - c->workspace->x; | ||
366 | deco_rect->y = c->y - c->workspace->y; | ||
367 | } | ||
368 | deco_rect->width = c->width; | ||
369 | deco_rect->height = container_titlebar_height(); | ||
370 | |||
371 | if (parent_layout == L_TABBED) { | ||
372 | deco_rect->width = c->parent | ||
373 | ? c->parent->width / c->parent->children->length | ||
374 | : c->workspace->width / c->workspace->tiling->length; | ||
375 | deco_rect->x += deco_rect->width * container_sibling_index(c); | ||
376 | } else if (container_parent_layout(c) == L_STACKED) { | ||
377 | if (!c->view) { | ||
378 | size_t siblings = container_get_siblings(c)->length; | ||
379 | deco_rect->y -= deco_rect->height * siblings; | ||
380 | } | ||
381 | deco_rect->y += deco_rect->height * container_sibling_index(c); | ||
382 | } | ||
383 | } | ||
384 | |||
353 | static void ipc_json_describe_view(struct sway_container *c, json_object *object) { | 385 | static void ipc_json_describe_view(struct sway_container *c, json_object *object) { |
354 | json_object_object_add(object, "pid", json_object_new_int(c->view->pid)); | 386 | json_object_object_add(object, "pid", json_object_new_int(c->view->pid)); |
355 | 387 | ||
@@ -377,15 +409,6 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object | |||
377 | 409 | ||
378 | json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box)); | 410 | json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box)); |
379 | 411 | ||
380 | struct wlr_box deco_box = {0, 0, 0, 0}; | ||
381 | |||
382 | if (c->current.border == B_NORMAL) { | ||
383 | deco_box.width = c->width; | ||
384 | deco_box.height = c->content_y - c->y; | ||
385 | } | ||
386 | |||
387 | json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); | ||
388 | |||
389 | struct wlr_box geometry = {0, 0, c->view->natural_width, c->view->natural_height}; | 412 | struct wlr_box geometry = {0, 0, c->view->natural_width, c->view->natural_height}; |
390 | json_object_object_add(object, "geometry", ipc_json_create_rect(&geometry)); | 413 | json_object_object_add(object, "geometry", ipc_json_create_rect(&geometry)); |
391 | 414 | ||
@@ -465,6 +488,10 @@ static void ipc_json_describe_container(struct sway_container *c, json_object *o | |||
465 | json_object_new_int(c->current.border_thickness)); | 488 | json_object_new_int(c->current.border_thickness)); |
466 | json_object_object_add(object, "floating_nodes", json_object_new_array()); | 489 | json_object_object_add(object, "floating_nodes", json_object_new_array()); |
467 | 490 | ||
491 | struct wlr_box deco_box = {0, 0, 0, 0}; | ||
492 | get_deco_rect(c, &deco_box); | ||
493 | json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); | ||
494 | |||
468 | if (c->view) { | 495 | if (c->view) { |
469 | ipc_json_describe_view(c, object); | 496 | ipc_json_describe_view(c, object); |
470 | } | 497 | } |
@@ -505,6 +532,12 @@ json_object *ipc_json_describe_node(struct sway_node *node) { | |||
505 | 532 | ||
506 | struct wlr_box box; | 533 | struct wlr_box box; |
507 | node_get_box(node, &box); | 534 | node_get_box(node, &box); |
535 | if (node->type == N_CONTAINER) { | ||
536 | struct wlr_box deco_rect = {0, 0, 0, 0}; | ||
537 | get_deco_rect(node->sway_container, &deco_rect); | ||
538 | box.y += deco_rect.height; | ||
539 | box.height -= deco_rect.height; | ||
540 | } | ||
508 | 541 | ||
509 | json_object *focus = json_object_new_array(); | 542 | json_object *focus = json_object_new_array(); |
510 | struct focus_inactive_data data = { | 543 | struct focus_inactive_data data = { |