get_deco_rect: fix floaters on tabbed/stacked ws

This fixes the decoration rects for floating containers on a workspace
that is either tabbed or stacked. Without this, the floater would
incorrectly try to calculate where it's tab or stack decorations were
on the workspace. This would cause a SIGFPE (due to a divide-by-zero)
when the floater was on a tabbed workspace without any tiling children.
Furthermore, the floater does not care what the workspace's layout is
and should just use the location relative to the workspace. This should
have no effect on children of a floating container.
This commit is contained in:
Brian Ashworth 2019-03-11 22:21:38 -04:00 committed by Drew DeVault
parent 79369681ab
commit 1bab5a9553

View file

@ -352,8 +352,9 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace,
static void get_deco_rect(struct sway_container *c, struct wlr_box *deco_rect) { static void get_deco_rect(struct sway_container *c, struct wlr_box *deco_rect) {
enum sway_container_layout parent_layout = container_parent_layout(c); enum sway_container_layout parent_layout = container_parent_layout(c);
if ((parent_layout != L_TABBED && parent_layout != L_STACKED && bool tab_or_stack = parent_layout == L_TABBED || parent_layout == L_STACKED;
c->current.border != B_NORMAL) || if (((!tab_or_stack || container_is_floating(c)) &&
c->current.border != B_NORMAL) ||
c->fullscreen_mode != FULLSCREEN_NONE || c->fullscreen_mode != FULLSCREEN_NONE ||
c->workspace == NULL) { c->workspace == NULL) {
deco_rect->x = deco_rect->y = deco_rect->width = deco_rect->height = 0; deco_rect->x = deco_rect->y = deco_rect->width = deco_rect->height = 0;
@ -370,17 +371,19 @@ static void get_deco_rect(struct sway_container *c, struct wlr_box *deco_rect) {
deco_rect->width = c->width; deco_rect->width = c->width;
deco_rect->height = container_titlebar_height(); deco_rect->height = container_titlebar_height();
if (parent_layout == L_TABBED) { if (!container_is_floating(c)) {
deco_rect->width = c->parent if (parent_layout == L_TABBED) {
? c->parent->width / c->parent->children->length deco_rect->width = c->parent
: c->workspace->width / c->workspace->tiling->length; ? c->parent->width / c->parent->children->length
deco_rect->x += deco_rect->width * container_sibling_index(c); : c->workspace->width / c->workspace->tiling->length;
} else if (container_parent_layout(c) == L_STACKED) { deco_rect->x += deco_rect->width * container_sibling_index(c);
if (!c->view) { } else if (parent_layout == L_STACKED) {
size_t siblings = container_get_siblings(c)->length; if (!c->view) {
deco_rect->y -= deco_rect->height * siblings; size_t siblings = container_get_siblings(c)->length;
deco_rect->y -= deco_rect->height * siblings;
}
deco_rect->y += deco_rect->height * container_sibling_index(c);
} }
deco_rect->y += deco_rect->height * container_sibling_index(c);
} }
} }