From 82cd55a67006a2817daa466fd2a56e3e5aa11e17 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Sun, 20 May 2018 23:12:33 -0400 Subject: Fix border commands from changing focus --- sway/commands/border.c | 2 +- sway/commands/seat/cursor.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/border.c b/sway/commands/border.c index 1eb06a21..4ba361da 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -41,7 +41,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) { - cursor_send_pointer_motion(seat->cursor, 0); + cursor_send_pointer_motion(seat->cursor, 0, false); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 929384b0..4d0a22c7 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, 0); + cursor_send_pointer_motion(cursor, 0, true); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root_container.width; float y = strtof(argv[2], NULL) / root_container.height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, 0); + cursor_send_pointer_motion(cursor, 0, true); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); -- cgit v1.2.3 From c08f9bf257c38c92a75988d89fba2d4de6bb2aea Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 19 May 2018 22:54:50 +1000 Subject: Implement tabbed layout --- include/sway/tree/container.h | 2 +- sway/commands/layout.c | 2 + sway/desktop/output.c | 192 +++++++++++++++++++++++++++++- sway/input/cursor.c | 2 +- sway/tree/arrange.c | 44 +++++-- sway/tree/container.c | 267 ++++++++++++++++++++++++++++++------------ sway/tree/layout.c | 11 +- sway/tree/view.c | 1 + 8 files changed, 436 insertions(+), 85 deletions(-) (limited to 'sway/commands') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index e7e9d944..598a4f3d 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -162,7 +162,7 @@ struct sway_container *container_parent(struct sway_container *container, * is a view and the view contains a surface at those coordinates. */ struct sway_container *container_at(struct sway_container *container, - double lx, double ly, struct wlr_surface **surface, + double ox, double oy, struct wlr_surface **surface, double *sx, double *sy); /** diff --git a/sway/commands/layout.c b/sway/commands/layout.c index bb36bb18..8aa321ae 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -39,6 +39,8 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "splitv") == 0) { parent->layout = L_VERT; + } else if (strcasecmp(argv[0], "tabbed") == 0) { + parent->layout = L_TABBED; } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { if (parent->layout == L_HORIZ) { parent->layout = L_VERT; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 51c1ffbe..e39ef8db 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -599,12 +599,198 @@ static void render_container_simple(struct sway_output *output, } } +static void render_tab(struct sway_output *output, pixman_region32_t *damage, + struct sway_container *parent, int child_index, + struct border_colors *colors, struct wlr_texture *title_texture) { + float output_scale = output->wlr_output->scale; + float color[4]; + struct wlr_box box; + bool is_first = (child_index == 0); + bool is_last = (child_index == parent->children->length - 1); + + int tab_width = parent->width / parent->children->length; + int x = parent->x + tab_width * child_index; + // Make last tab use the remaining width of the parent + if (is_last) { + tab_width = parent->width - tab_width * child_index; + } + + // Single pixel bar above title + memcpy(&color, colors->border, sizeof(float) * 4); + box.x = x; + box.y = parent->y; + box.width = tab_width; + box.height = 1; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + + // Single pixel bar below title + memcpy(&color, colors->border, sizeof(float) * 4); + box.x = x + config->border_thickness * is_first; + box.y = parent->y + config->border_thickness * 2 + config->font_height - 1; + box.width = tab_width - config->border_thickness * is_first + - config->border_thickness * is_last; + box.height = 1; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + + // Title text + size_t title_width = 0; + if (title_texture) { + struct wlr_box texture_box; + wlr_texture_get_size(title_texture, + &texture_box.width, &texture_box.height); + texture_box.x = (x + config->border_thickness) * output_scale; + texture_box.y = (parent->y + config->border_thickness) * output_scale; + + float matrix[9]; + wlr_matrix_project_box(matrix, &texture_box, + WL_OUTPUT_TRANSFORM_NORMAL, + 0.0, output->wlr_output->transform_matrix); + + int available = (tab_width - config->border_thickness * 2) + * output_scale; + if (texture_box.width > available) { + texture_box.width = available; + } + render_texture(output->wlr_output, damage, title_texture, + &texture_box, matrix, 1.0); + title_width = texture_box.width; + } + + // Title background - above the text + memcpy(&color, colors->background, sizeof(float) * 4); + box.x = x + config->border_thickness; + box.y = parent->y + 1; + box.width = tab_width - config->border_thickness * 2; + box.height = config->border_thickness - 1; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + + // Title background - below the text + box.y = (parent->y + config->border_thickness + config->font_height) + * output_scale; + render_rect(output->wlr_output, damage, &box, color); + + // Title background - left border + box.x = x; + box.y = parent->y + 1; + box.width = config->border_thickness; + box.height = config->border_thickness * 2 + + config->font_height - 1 - !is_first; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + + // Title background - right border + box.x = x + tab_width - config->border_thickness; + box.y = parent->y + 1; + box.width = config->border_thickness; + box.height = config->border_thickness * 2 + + config->font_height - 1 - !is_last; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + + // Title background - right of text + box.x = (x + config->border_thickness) * output_scale + title_width; + box.y = (parent->y + config->border_thickness) * output_scale; + box.width = (tab_width - config->border_thickness * 2) * output_scale + - title_width; + box.height = config->font_height * output_scale; + render_rect(output->wlr_output, damage, &box, color); +} + +static void render_tab_content(struct sway_output *output, + pixman_region32_t *damage, struct sway_container *con, + struct border_colors *colors) { + struct sway_view *view = con->sway_view; + render_view(view, output, damage); + + struct wlr_box box; + float output_scale = output->wlr_output->scale; + float color[4]; + + if (view->border_left) { + memcpy(&color, colors->child_border, sizeof(float) * 4); + color[3] *= con->alpha; + box.x = con->x; + box.y = con->y + config->border_thickness * 2 + config->font_height; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + } + + if (view->border_right) { + memcpy(&color, colors->child_border, sizeof(float) * 4); + color[3] *= con->alpha; + box.x = view->x + view->width; + box.y = con->y + config->border_thickness * 2 + config->font_height; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + } + + if (view->border_bottom) { + memcpy(&color, colors->child_border, sizeof(float) * 4); + color[3] *= con->alpha; + box.x = con->x; + box.y = view->y + view->height; + box.width = con->width; + box.height = view->border_thickness; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + } +} + /** * Render a container's children using the L_TABBED layout. */ static void render_container_tabbed(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con) { - // TODO + pixman_region32_t *damage, struct sway_container *con, + bool parent_focused) { + if (!con->children->length) { + return; + } + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + struct sway_container *current = seat_get_focus_inactive(seat, con); + while (current->parent != con) { + current = current->parent; + } + struct border_colors *current_colors = NULL; + + // Render tabs + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + struct border_colors *colors; + struct wlr_texture *title_texture; + + if (focus == child || parent_focused) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + } else if (child == current) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + } + + render_tab(output, damage, con, i, colors, title_texture); + + if (child == current) { + current_colors = colors; + } + } + + // Render surface and left/right/bottom borders + if (current->type == C_VIEW) { + render_tab_content(output, damage, current, current_colors); + } else { + render_container(output, damage, current, + parent_focused || current == focus); + } } /** @@ -628,7 +814,7 @@ static void render_container(struct sway_output *output, render_container_stacked(output, damage, con); break; case L_TABBED: - render_container_tabbed(output, damage, con); + render_container_tabbed(output, damage, con, parent_focused); break; case L_FLOATING: // TODO diff --git a/sway/input/cursor.c b/sway/input/cursor.c index b0ce8002..e0b987d2 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -108,7 +108,7 @@ static struct sway_container *container_at_coords( } struct sway_container *c; - if ((c = container_at(ws, x, y, surface, sx, sy))) { + if ((c = container_at(ws, ox, oy, surface, sx, sy))) { return c; } diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 83bb20fb..8aebc0cc 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -86,6 +86,13 @@ static void apply_horiz_layout(struct sway_container *parent) { if (!num_children) { return; } + size_t parent_height = parent->height; + size_t parent_offset = 0; + if (parent->parent->layout == L_TABBED) { + parent_offset = config->border_thickness * 2 + config->font_height; + parent_height -= parent_offset; + } + // Calculate total width of children double total_width = 0; for (size_t i = 0; i < num_children; ++i) { @@ -111,9 +118,9 @@ static void apply_horiz_layout(struct sway_container *parent) { "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, child->width, scale); child->x = child_x; - child->y = parent->y; + child->y = parent->y + parent_offset; child->width = floor(child->width * scale); - child->height = parent->height; + child->height = parent_height; child_x += child->width; } // Make last child use remaining width of parent @@ -125,24 +132,31 @@ static void apply_vert_layout(struct sway_container *parent) { if (!num_children) { return; } + size_t parent_height = parent->height; + size_t parent_offset = 0; + if (parent->parent->layout == L_TABBED) { + parent_offset = config->border_thickness * 2 + config->font_height; + parent_height -= parent_offset; + } + // Calculate total height of children double total_height = 0; for (size_t i = 0; i < num_children; ++i) { struct sway_container *child = parent->children->items[i]; if (child->height <= 0) { if (num_children > 1) { - child->height = parent->height / (num_children - 1); + child->height = parent_height / (num_children - 1); } else { - child->height = parent->height; + child->height = parent_height; } } total_height += child->height; } - double scale = parent->height / total_height; + double scale = parent_height / total_height; // Resize wlr_log(L_DEBUG, "Arranging %p vertically", parent); - double child_y = parent->y; + double child_y = parent->y + parent_offset; struct sway_container *child; for (size_t i = 0; i < num_children; ++i) { child = parent->children->items[i]; @@ -156,7 +170,20 @@ static void apply_vert_layout(struct sway_container *parent) { child_y += child->height; } // Make last child use remaining height of parent - child->height = parent->y + parent->height - child->y; + child->height = parent->y + parent_offset + parent_height - child->y; +} + +static void apply_tabbed_layout(struct sway_container *parent) { + if (!parent->children->length) { + return; + } + for (int i = 0; i < parent->children->length; ++i) { + struct sway_container *child = parent->children->items[i]; + child->x = parent->x; + child->y = parent->y; + child->width = parent->width; + child->height = parent->height; + } } void arrange_children_of(struct sway_container *parent) { @@ -189,6 +216,9 @@ void arrange_children_of(struct sway_container *parent) { case L_VERT: apply_vert_layout(parent); break; + case L_TABBED: + apply_tabbed_layout(parent); + break; default: wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); diff --git a/sway/tree/container.c b/sway/tree/container.c index feaf7647..76a21c19 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -452,80 +452,139 @@ struct sway_container *container_parent(struct sway_container *container, return container; } -struct sway_container *container_at(struct sway_container *parent, - double lx, double ly, +static struct sway_container *container_at_view(struct sway_container *swayc, + double ox, double oy, struct wlr_surface **surface, double *sx, double *sy) { - list_t *queue = get_bfs_queue(); - if (!queue) { + struct sway_view *sview = swayc->sway_view; + double view_sx = ox - sview->x; + double view_sy = oy - sview->y; + + double _sx, _sy; + struct wlr_surface *_surface = NULL; + switch (sview->type) { + case SWAY_VIEW_XWAYLAND: + _surface = wlr_surface_surface_at(sview->surface, + view_sx, view_sy, &_sx, &_sy); + break; + case SWAY_VIEW_XDG_SHELL_V6: + // the top left corner of the sway container is the + // coordinate of the top left corner of the window geometry + view_sx += sview->wlr_xdg_surface_v6->geometry.x; + view_sy += sview->wlr_xdg_surface_v6->geometry.y; + + _surface = wlr_xdg_surface_v6_surface_at( + sview->wlr_xdg_surface_v6, + view_sx, view_sy, &_sx, &_sy); + break; + case SWAY_VIEW_XDG_SHELL: + // the top left corner of the sway container is the + // coordinate of the top left corner of the window geometry + view_sx += sview->wlr_xdg_surface->geometry.x; + view_sy += sview->wlr_xdg_surface->geometry.y; + + _surface = wlr_xdg_surface_surface_at( + sview->wlr_xdg_surface, + view_sx, view_sy, &_sx, &_sy); + break; + } + if (_surface) { + *sx = _sx; + *sy = _sy; + *surface = _surface; + } + return swayc; +} + +/** + * container_at for a container with layout L_TABBED. + */ +static struct sway_container *container_at_tabbed(struct sway_container *parent, + double ox, double oy, + struct wlr_surface **surface, double *sx, double *sy) { + if (oy < parent->y || oy > parent->y + parent->height) { return NULL; } + struct sway_seat *seat = input_manager_current_seat(input_manager); - list_add(queue, parent); + // Tab titles + int title_height = config->border_thickness * 2 + config->font_height; + if (oy < parent->y + title_height) { + int tab_width = parent->width / parent->children->length; + int child_index = (ox - parent->x) / tab_width; + if (child_index >= parent->children->length) { + child_index = parent->children->length - 1; + } + struct sway_container *child = parent->children->items[child_index]; + return seat_get_focus_inactive(seat, child); + } - struct sway_container *swayc = NULL; - while (queue->length) { - swayc = queue->items[0]; - list_del(queue, 0); - if (swayc->type == C_VIEW) { - struct sway_view *sview = swayc->sway_view; - struct sway_container *soutput = container_parent(swayc, C_OUTPUT); - struct wlr_box *output_box = - wlr_output_layout_get_box( - root_container.sway_root->output_layout, - soutput->sway_output->wlr_output); - double ox = lx - output_box->x; - double oy = ly - output_box->y; - double view_sx = ox - sview->x; - double view_sy = oy - sview->y; - - double _sx, _sy; - struct wlr_surface *_surface; - switch (sview->type) { - case SWAY_VIEW_XWAYLAND: - _surface = wlr_surface_surface_at(sview->surface, - view_sx, view_sy, &_sx, &_sy); - break; - case SWAY_VIEW_XDG_SHELL_V6: - // the top left corner of the sway container is the - // coordinate of the top left corner of the window geometry - view_sx += sview->wlr_xdg_surface_v6->geometry.x; - view_sy += sview->wlr_xdg_surface_v6->geometry.y; - - _surface = wlr_xdg_surface_v6_surface_at( - sview->wlr_xdg_surface_v6, - view_sx, view_sy, &_sx, &_sy); - break; - case SWAY_VIEW_XDG_SHELL: - // the top left corner of the sway container is the - // coordinate of the top left corner of the window geometry - view_sx += sview->wlr_xdg_surface->geometry.x; - view_sy += sview->wlr_xdg_surface->geometry.y; - - _surface = wlr_xdg_surface_surface_at( - sview->wlr_xdg_surface, - view_sx, view_sy, &_sx, &_sy); - break; - } - if (_surface) { - *sx = _sx; - *sy = _sy; - *surface = _surface; - return swayc; - } - // Check the view's decorations - struct wlr_box swayc_box = { - .x = swayc->x, - .y = swayc->y, - .width = swayc->width, - .height = swayc->height, - }; - if (wlr_box_contains_point(&swayc_box, ox, oy)) { - return swayc; - } - } else { - list_cat(queue, swayc->children); + // Surfaces + struct sway_container *current = seat_get_focus_inactive(seat, parent); + while (current->parent != parent) { + current = current->parent; + } + + return container_at(current, ox, oy, surface, sx, sy); +} + +/** + * container_at for a container with layout L_STACKED. + */ +static struct sway_container *container_at_stacked( + struct sway_container *parent, double ox, double oy, + struct wlr_surface **surface, double *sx, double *sy) { + // TODO + return NULL; +} + +/** + * container_at for a container with layout L_HORIZ or L_VERT. + */ +static struct sway_container *container_at_linear(struct sway_container *parent, + double ox, double oy, + struct wlr_surface **surface, double *sx, double *sy) { + for (int i = 0; i < parent->children->length; ++i) { + struct sway_container *child = parent->children->items[i]; + struct wlr_box box = { + .x = child->x, + .y = child->y, + .width = child->width, + .height = child->height, + }; + if (wlr_box_contains_point(&box, ox, oy)) { + return container_at(child, ox, oy, surface, sx, sy); } } + return NULL; +} + +struct sway_container *container_at(struct sway_container *parent, + double ox, double oy, + struct wlr_surface **surface, double *sx, double *sy) { + if (!sway_assert(parent->type >= C_WORKSPACE, + "Expected workspace or deeper")) { + return NULL; + } + if (parent->type == C_VIEW) { + return container_at_view(parent, ox, oy, surface, sx, sy); + } + if (!parent->children->length) { + return NULL; + } + + switch (parent->layout) { + case L_HORIZ: + case L_VERT: + return container_at_linear(parent, ox, oy, surface, sx, sy); + case L_TABBED: + return container_at_tabbed(parent, ox, oy, surface, sx, sy); + case L_STACKED: + return container_at_stacked(parent, ox, oy, surface, sx, sy); + case L_FLOATING: + return NULL; // TODO + case L_NONE: + return NULL; + } return NULL; } @@ -699,18 +758,82 @@ void container_calculate_title_height(struct sway_container *container) { container->title_height = height; } +/** + * Calculate and return the length of the concatenated child titles. + * An example concatenated title is: V[Terminal, Firefox] + * If buffer is not NULL, also populate the buffer with the concatenated title. + */ +static size_t concatenate_child_titles(struct sway_container *parent, + char *buffer) { + size_t len = 2; // V[ + if (buffer) { + switch (parent->layout) { + case L_VERT: + strcpy(buffer, "V["); + break; + case L_HORIZ: + strcpy(buffer, "H["); + break; + case L_TABBED: + strcpy(buffer, "T["); + break; + case L_STACKED: + strcpy(buffer, "S["); + break; + case L_FLOATING: + strcpy(buffer, "F["); + break; + case L_NONE: + strcpy(buffer, "?["); + break; + } + } + + for (int i = 0; i < parent->children->length; ++i) { + if (i != 0) { + len += 2; + if (buffer) { + strcat(buffer, ", "); + } + } + struct sway_container *child = parent->children->items[i]; + if (child->name) { + len += strlen(child->name); + if (buffer) { + strcat(buffer, child->name); + } + } else { + len += 6; + if (buffer) { + strcat(buffer, "(null)"); + } + } + } + + len += 1; + if (buffer) { + strcat(buffer, "]"); + } + return len; +} + void container_notify_child_title_changed(struct sway_container *container) { if (!container || container->type != C_CONTAINER) { return; } - if (container->layout != L_TABBED && container->layout != L_STACKED) { - return; - } if (container->formatted_title) { free(container->formatted_title); } - // TODO: iterate children and concatenate their titles - container->formatted_title = strdup(""); + + size_t len = concatenate_child_titles(container, NULL); + char *buffer = calloc(len + 1, sizeof(char)); + if (!sway_assert(buffer, "Unable to allocate title string")) { + return; + } + concatenate_child_titles(container, buffer); + + container->name = buffer; + container->formatted_title = buffer; container_calculate_title_height(container); container_update_title_textures(container); container_notify_child_title_changed(container->parent); diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ec1c6fe5..f8acdf6c 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -149,6 +149,8 @@ struct sway_container *container_remove_child(struct sway_container *child) { } } child->parent = NULL; + container_notify_child_title_changed(parent); + return parent; } @@ -182,6 +184,8 @@ void container_move_to(struct sway_container *container, container_sort_workspaces(new_parent); seat_set_focus(seat, new_parent); } + container_notify_child_title_changed(old_parent); + container_notify_child_title_changed(new_parent); if (old_parent) { arrange_children_of(old_parent); } @@ -234,9 +238,9 @@ static bool is_parallel(enum sway_container_layout layout, enum movement_direction dir) { switch (layout) { case L_TABBED: - case L_STACKED: case L_HORIZ: return dir == MOVE_LEFT || dir == MOVE_RIGHT; + case L_STACKED: case L_VERT: return dir == MOVE_UP || dir == MOVE_DOWN; default: @@ -485,6 +489,9 @@ void container_move(struct sway_container *container, } } + container_notify_child_title_changed(old_parent); + container_notify_child_title_changed(container->parent); + if (old_parent) { seat_set_focus(config->handler_context.seat, old_parent); seat_set_focus(config->handler_context.seat, container); @@ -832,6 +839,8 @@ struct sway_container *container_split(struct sway_container *child, container_add_child(cont, child); } + container_notify_child_title_changed(cont); + return cont; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 192a73c5..636abb25 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -441,6 +441,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { input_manager_set_focus(input_manager, cont); view_update_title(view, false); + container_notify_child_title_changed(view->swayc->parent); view_execute_criteria(view); container_damage_whole(cont); -- cgit v1.2.3 From 664169fbf1c4e07f17a48b2b801dad9cea31ea4c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 21 May 2018 22:58:46 +1000 Subject: Implement stacked layout --- sway/commands/layout.c | 2 + sway/desktop/output.c | 596 ++++++++++++++++++++++--------------------------- sway/tree/arrange.c | 32 ++- sway/tree/view.c | 15 +- 4 files changed, 303 insertions(+), 342 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 8aa321ae..58728f16 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -41,6 +41,8 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent->layout = L_VERT; } else if (strcasecmp(argv[0], "tabbed") == 0) { parent->layout = L_TABBED; + } else if (strcasecmp(argv[0], "stacking") == 0) { + parent->layout = L_STACKED; } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { if (parent->layout == L_HORIZ) { parent->layout = L_VERT; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 551e96fc..3b501a63 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -269,17 +269,6 @@ static void render_unmanaged(struct sway_output *output, render_surface_iterator, &data); } -static void render_view(struct sway_view *view, struct sway_output *output, - pixman_region32_t *damage) { - struct render_data data = { - .output = output, - .damage = damage, - .alpha = view->swayc->alpha, - }; - output_view_for_each_surface( - view, &data.root_geo, render_surface_iterator, &data); -} - static void render_rect(struct wlr_output *wlr_output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]) { @@ -317,108 +306,159 @@ static void premultiply_alpha(float color[4], float opacity) { color[2] *= color[3]; } +static void render_view_surfaces(struct sway_view *view, + struct sway_output *output, pixman_region32_t *damage) { + struct render_data data = { + .output = output, + .damage = damage, + .alpha = view->swayc->alpha, + }; + output_view_for_each_surface( + view, &data.root_geo, render_surface_iterator, &data); +} + /** - * Render decorations for a view with "border normal". - * - * Care must be taken not to render over the same pixel multiple times, - * otherwise the colors will be incorrect when using opacity. + * Render a view's surface and left/bottom/right borders. */ -static void render_container_simple_border_normal(struct sway_output *output, - pixman_region32_t *output_damage, - struct sway_container *con, struct border_colors *colors, - struct wlr_texture *title_texture, struct wlr_texture *marks_texture) { - struct wlr_box box; - float color[4]; +static void render_view(struct sway_output *output, pixman_region32_t *damage, + struct sway_container *con, struct border_colors *colors) { struct sway_view *view = con->sway_view; - float output_scale = output->wlr_output->scale; + render_view_surfaces(view, output, damage); - if (view->border_left) { - // Child border - left edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y + 1; - box.width = view->border_thickness; - box.height = con->height - 1 - - view->border_thickness * view->border_bottom; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } + struct wlr_box box; + float output_scale = output->wlr_output->scale; + float color[4]; - if (view->border_right) { - // Child border - right edge - if (con->parent->children->length == 1 - && con->parent->layout == L_HORIZ) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { + if (view->border != B_NONE) { + if (view->border_left) { memcpy(&color, colors->child_border, sizeof(float) * 4); + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = view->y; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); } - premultiply_alpha(color, con->alpha); - box.x = con->x + con->width - view->border_thickness; - box.y = con->y + 1; - box.width = view->border_thickness; - box.height = con->height - 1 - - view->border_thickness * view->border_bottom; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } - if (view->border_bottom) { - // Child border - bottom edge - if (con->parent->children->length == 1 - && con->parent->layout == L_VERT) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); + if (view->border_right) { + if (con->parent->children->length == 1 + && con->parent->layout == L_HORIZ) { + memcpy(&color, colors->indicator, sizeof(float) * 4); + } else { + memcpy(&color, colors->child_border, sizeof(float) * 4); + } + premultiply_alpha(color, con->alpha); + box.x = view->x + view->width; + box.y = view->y; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + } + + if (view->border_bottom) { + if (con->parent->children->length == 1 + && con->parent->layout == L_VERT) { + memcpy(&color, colors->indicator, sizeof(float) * 4); + } else { + memcpy(&color, colors->child_border, sizeof(float) * 4); + } + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = view->y + view->height; + box.width = con->width; + box.height = view->border_thickness; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); } - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y + con->height - view->border_thickness; - box.width = con->width; - box.height = view->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); } +} + +/** + * Render a titlebar. + * + * Care must be taken not to render over the same pixel multiple times, + * otherwise the colors will be incorrect when using opacity. + * + * The height is: 1px border, 3px padding, font height, 3px padding, 1px border + * The left side for L_TABBED is: 1px border, 2px padding, title + * The left side for other layouts is: 3px padding, title + */ +static void render_titlebar(struct sway_output *output, + pixman_region32_t *output_damage, struct sway_container *con, + int x, int y, int width, + struct border_colors *colors, struct wlr_texture *title_texture, + struct wlr_texture *marks_texture) { + struct wlr_box box; + float color[4]; + struct sway_view *view = con->type == C_VIEW ? con->sway_view : NULL; + float output_scale = output->wlr_output->scale; + enum sway_container_layout layout = con->parent->layout; + bool is_last_child = + con->parent->children->items[con->parent->children->length - 1] == con; // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y; - box.width = con->width; + box.x = x; + box.y = y; + box.width = width; box.height = 1; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - // Setting these makes marks and title easier - size_t inner_x = con->x + view->border_thickness * view->border_left; - size_t inner_width = con->width - view->border_thickness * view->border_left - - view->border_thickness * view->border_right; - // Single pixel bar below title - memcpy(&color, colors->border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = inner_x; - box.y = view->y - 1; - box.width = inner_width; + size_t left_offset = 0, right_offset = 0; + bool connects_sides = false; + if (layout == L_HORIZ || layout == L_VERT || + (layout == L_STACKED && is_last_child)) { + if (view) { + left_offset = view->border_left * view->border_thickness; + right_offset = view->border_right * view->border_thickness; + connects_sides = true; + } + } + box.x = x + left_offset; + box.y = y + config->font_height + 7; + box.width = width - left_offset - right_offset; box.height = 1; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); + if (layout == L_TABBED) { + // Single pixel left edge + box.x = x; + box.y = y + 1; + box.width = 1; + box.height = config->font_height + 6; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); + + // Single pixel right edge + box.x = (x + width - 1) * output_scale; + render_rect(output->wlr_output, output_damage, &box, color); + } + + size_t inner_width = width - 6; + // Marks size_t marks_width = 0; if (config->show_marks && marks_texture) { struct wlr_box texture_box; wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); - texture_box.x = (inner_x + inner_width) * output_scale - texture_box.width; - texture_box.y = (con->y + view->border_thickness) * output_scale; + texture_box.x = (x + width - 3) * output_scale - texture_box.width; + texture_box.y = (y + 4) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 0.0, output->wlr_output->transform_matrix); + if (inner_width * output_scale < texture_box.width) { + texture_box.width = inner_width * output_scale; + } render_texture(output->wlr_output, output_damage, marks_texture, &texture_box, matrix, con->alpha); marks_width = texture_box.width; @@ -430,8 +470,8 @@ static void render_container_simple_border_normal(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = inner_x * output_scale; - texture_box.y = (con->y + view->border_thickness) * output_scale; + texture_box.x = (x + 3) * output_scale; + texture_box.y = (y + 4) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -446,104 +486,89 @@ static void render_container_simple_border_normal(struct sway_output *output, title_width = texture_box.width; } - // Title background - above the text + // Padding above title memcpy(&color, colors->background, sizeof(float) * 4); premultiply_alpha(color, con->alpha); - box.x = inner_x; - box.y = con->y + 1; - box.width = inner_width; - box.height = view->border_thickness - 1; + box.x = x + (layout == L_TABBED); + box.y = y + 1; + box.width = width - (layout == L_TABBED) * 2; + box.height = 3; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - // Title background - below the text - box.y = (con->y + view->border_thickness + config->font_height) - * output_scale; + // Padding below title + box.y = (y + 4 + config->font_height) * output_scale; render_rect(output->wlr_output, output_damage, &box, color); - // Title background - filler between title and marks + // Filler between title and marks box.width = inner_width * output_scale - title_width - marks_width; if (box.width > 0) { - box.x = inner_x * output_scale + title_width; - box.y = (con->y + view->border_thickness) * output_scale; + box.x = (x + 3) * output_scale + title_width; + box.y = (y + 4) * output_scale; box.height = config->font_height * output_scale; render_rect(output->wlr_output, output_damage, &box, color); } -} -/** - * Render decorations for a view with "border pixel". - * - * Care must be taken not to render over the same pixel multiple times, - * otherwise the colors will be incorrect when using opacity. - */ -static void render_container_simple_border_pixel(struct sway_output *output, - pixman_region32_t *output_damage, struct sway_container *con, - struct border_colors *colors) { - struct wlr_box box; - float color[4]; - struct sway_view *view = con->sway_view; - float output_scale = output->wlr_output->scale; + // Padding left of title + left_offset = layout == L_TABBED ? 1 : 0; + box.x = x + left_offset; + box.y = y + 4; + box.width = 3 - left_offset; + box.height = config->font_height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); - if (view->border_left) { - // Child border - left edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y + view->border_thickness * view->border_top; - box.width = view->border_thickness; - box.height = con->height - view->border_thickness - * (view->border_top + view->border_bottom); - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } + // Padding right of marks + right_offset = layout == L_TABBED ? 1 : 0; + box.x = x + width - 3; + box.y = y + 4; + box.width = 3 - right_offset; + box.height = config->font_height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); - if (view->border_right) { - // Child border - right edge - if (con->parent->children->length == 1 - && con->parent->layout == L_HORIZ) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); - } - premultiply_alpha(color, con->alpha); - box.x = con->x + con->width - view->border_thickness; - box.y = con->y + view->border_thickness * view->border_top; - box.width = view->border_thickness; - box.height = con->height - view->border_thickness - * (view->border_top + view->border_bottom); + if (connects_sides) { + // Left pixel in line with bottom bar + box.x = x; + box.y = y + config->font_height + 7; + box.width = view->border_thickness * view->border_left; + box.height = 1; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - } - if (view->border_top) { - // Child border - top edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y; - box.width = con->width; - box.height = view->border_thickness; + // Right pixel in line with bottom bar + box.x = x + width - view->border_thickness * view->border_right; + box.y = y + config->font_height + 7; + box.width = view->border_thickness * view->border_right; + box.height = 1; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } +} - if (view->border_bottom) { - // Child border - bottom edge - if (con->parent->children->length == 1 - && con->parent->layout == L_VERT) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); - } - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y + con->height - view->border_thickness; - box.width = con->width; - box.height = view->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); +/** + * Render the top border line for a view using "border pixel". + */ +static void render_top_border(struct sway_output *output, + pixman_region32_t *output_damage, struct sway_container *con, + struct border_colors *colors) { + struct sway_view *view = con->sway_view; + if (!view->border_top) { + return; } + struct wlr_box box; + float color[4]; + float output_scale = output->wlr_output->scale; + + // Child border - top edge + memcpy(&color, colors->child_border, sizeof(float) * 4); + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = con->y; + box.width = con->width; + box.height = view->border_thickness; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); } static void render_container(struct sway_output *output, @@ -565,33 +590,30 @@ static void render_container_simple(struct sway_output *output, struct sway_container *child = con->children->items[i]; if (child->type == C_VIEW) { - if (child->sway_view->border != B_NONE) { - struct border_colors *colors; - struct wlr_texture *title_texture; - struct wlr_texture *marks_texture; - if (focus == child || parent_focused) { - colors = &config->border_colors.focused; - title_texture = child->title_focused; - marks_texture = child->sway_view->marks_focused; - } else if (seat_get_focus_inactive(seat, con) == child) { - colors = &config->border_colors.focused_inactive; - title_texture = child->title_focused_inactive; - marks_texture = child->sway_view->marks_focused_inactive; - } else { - colors = &config->border_colors.unfocused; - title_texture = child->title_unfocused; - marks_texture = child->sway_view->marks_unfocused; - } - - if (child->sway_view->border == B_NORMAL) { - render_container_simple_border_normal(output, damage, - child, colors, title_texture, marks_texture); - } else { - render_container_simple_border_pixel(output, damage, child, - colors); - } + struct border_colors *colors; + struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + if (focus == child || parent_focused) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + marks_texture = child->sway_view->marks_focused; + } else if (seat_get_focus_inactive(seat, con) == child) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + marks_texture = child->sway_view->marks_focused_inactive; + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + marks_texture = child->sway_view->marks_unfocused; + } + + if (child->sway_view->border == B_NORMAL) { + render_titlebar(output, damage, child, child->x, child->y, + child->width, colors, title_texture, marks_texture); + } else { + render_top_border(output, damage, child, colors); } - render_view(child->sway_view, output, damage); + render_view(output, damage, child, colors); } else { render_container(output, damage, child, parent_focused || focus == child); @@ -599,154 +621,71 @@ static void render_container_simple(struct sway_output *output, } } -static void render_tab(struct sway_output *output, pixman_region32_t *damage, - struct sway_container *parent, int child_index, - struct border_colors *colors, struct wlr_texture *title_texture) { - struct sway_container *con = parent->children->items[child_index]; - float output_scale = output->wlr_output->scale; - float color[4]; - struct wlr_box box; - - int tab_width = parent->width / parent->children->length; - int x = parent->x + tab_width * child_index; - // Make last tab use the remaining width of the parent - if (child_index == parent->children->length - 1) { - tab_width = parent->width - tab_width * child_index; +/** + * Render a container's children using the L_TABBED layout. + */ +static void render_container_tabbed(struct sway_output *output, + pixman_region32_t *damage, struct sway_container *con, + bool parent_focused) { + if (!con->children->length) { + return; } + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + struct sway_container *current = seat_get_active_child(seat, con); + struct border_colors *current_colors = NULL; - // Single pixel bar above title - memcpy(&color, colors->border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = x; - box.y = parent->y; - box.width = tab_width; - box.height = 1; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); - - // Single pixel bar below title - box.y = (parent->y + config->border_thickness * 2 + config->font_height - 1) - * output_scale; - render_rect(output->wlr_output, damage, &box, color); - - // Single pixel bar on left - box.x = x; - box.y = parent->y + 1; - box.width = 1; - box.height = config->border_thickness * 2 + config->font_height - 2; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); - - // Single pixel bar on right - box.x = (x + tab_width - 1) * output_scale; - render_rect(output->wlr_output, damage, &box, color); - - // Title text - size_t title_width = 0; - if (title_texture) { - struct wlr_box texture_box; - wlr_texture_get_size(title_texture, - &texture_box.width, &texture_box.height); - texture_box.x = (x + 1 + config->border_thickness) * output_scale; - texture_box.y = (parent->y + config->border_thickness) * output_scale; - - float matrix[9]; - wlr_matrix_project_box(matrix, &texture_box, - WL_OUTPUT_TRANSFORM_NORMAL, - 0.0, output->wlr_output->transform_matrix); + // Render tabs + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + struct border_colors *colors; + struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + struct sway_view *view = + child->type == C_VIEW ? child->sway_view : NULL; - int available = (tab_width - config->border_thickness * 2 - 2) - * output_scale; - if (texture_box.width > available) { - texture_box.width = available; + if (focus == child || parent_focused) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + marks_texture = view ? view->marks_focused : NULL; + } else if (child == current) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + marks_texture = view ? view->marks_focused : NULL; + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + marks_texture = view ? view->marks_unfocused : NULL; } - render_texture(output->wlr_output, damage, title_texture, - &texture_box, matrix, 1.0); - title_width = texture_box.width; - } - // Title background - above the text - memcpy(&color, colors->background, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = x + 1; - box.y = parent->y + 1; - box.width = tab_width - 2; - box.height = config->border_thickness - 1; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); - - // Title background - below the text - box.y = (parent->y + config->border_thickness + config->font_height) - * output_scale; - render_rect(output->wlr_output, damage, &box, color); - - // Title background - left of text - box.x = x + 1; - box.y = parent->y + config->border_thickness; - box.width = config->border_thickness; - box.height = config->font_height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); - - // Title background - right of text - box.x = (x + 1 + config->border_thickness) * output_scale + title_width; - box.y = (parent->y + config->border_thickness) * output_scale; - box.width = (tab_width - config->border_thickness - 2) * output_scale - - title_width; - box.height = config->font_height * output_scale; - render_rect(output->wlr_output, damage, &box, color); -} - -static void render_tab_content(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con, - struct border_colors *colors) { - struct sway_view *view = con->sway_view; - render_view(view, output, damage); - - struct wlr_box box; - float output_scale = output->wlr_output->scale; - float color[4]; - - if (view->border != B_NONE) { - if (view->border_left) { - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = con->y + config->border_thickness * 2 + config->font_height; - box.width = view->border_thickness; - box.height = view->height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); + int tab_width = con->width / con->children->length; + int x = con->x + tab_width * i; + // Make last tab use the remaining width of the parent + if (i == con->children->length - 1) { + tab_width = con->width - tab_width * i; } - if (view->border_right) { - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = view->x + view->width; - box.y = con->y + config->border_thickness * 2 + config->font_height; - box.width = view->border_thickness; - box.height = view->height; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); - } + render_titlebar(output, damage, child, x, child->y, tab_width, colors, + title_texture, marks_texture); - if (view->border_bottom) { - memcpy(&color, colors->child_border, sizeof(float) * 4); - premultiply_alpha(color, con->alpha); - box.x = con->x; - box.y = view->y + view->height; - box.width = con->width; - box.height = view->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, damage, &box, color); + if (child == current) { + current_colors = colors; } } + + // Render surface and left/right/bottom borders + if (current->type == C_VIEW) { + render_view(output, damage, current, current_colors); + } else { + render_container(output, damage, current, + parent_focused || current == focus); + } } /** - * Render a container's children using the L_TABBED layout. + * Render a container's children using the L_STACKED layout. */ -static void render_container_tabbed(struct sway_output *output, +static void render_container_stacked(struct sway_output *output, pixman_region32_t *damage, struct sway_container *con, bool parent_focused) { if (!con->children->length) { @@ -757,24 +696,32 @@ static void render_container_tabbed(struct sway_output *output, struct sway_container *current = seat_get_active_child(seat, con); struct border_colors *current_colors = NULL; - // Render tabs + // Render titles for (int i = 0; i < con->children->length; ++i) { struct sway_container *child = con->children->items[i]; struct border_colors *colors; struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + struct sway_view *view = + child->type == C_VIEW ? child->sway_view : NULL; if (focus == child || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; + marks_texture = view ? view->marks_focused : NULL; } else if (child == current) { colors = &config->border_colors.focused_inactive; title_texture = child->title_focused_inactive; + marks_texture = view ? view->marks_focused_inactive : NULL; } else { colors = &config->border_colors.unfocused; title_texture = child->title_unfocused; + marks_texture = view ? view->marks_unfocused : NULL; } - render_tab(output, damage, con, i, colors, title_texture); + int y = con->y + (config->font_height + 8) * i; + render_titlebar(output, damage, child, child->x, y, child->width, + colors, title_texture, marks_texture); if (child == current) { current_colors = colors; @@ -783,21 +730,13 @@ static void render_container_tabbed(struct sway_output *output, // Render surface and left/right/bottom borders if (current->type == C_VIEW) { - render_tab_content(output, damage, current, current_colors); + render_view(output, damage, current, current_colors); } else { render_container(output, damage, current, parent_focused || current == focus); } } -/** - * Render a container's children using the L_STACKED layout. - */ -static void render_container_stacked(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con) { - // TODO -} - static void render_container(struct sway_output *output, pixman_region32_t *damage, struct sway_container *con, bool parent_focused) { @@ -808,7 +747,7 @@ static void render_container(struct sway_output *output, render_container_simple(output, damage, con, parent_focused); break; case L_STACKED: - render_container_stacked(output, damage, con); + render_container_stacked(output, damage, con, parent_focused); break; case L_TABBED: render_container_tabbed(output, damage, con, parent_focused); @@ -868,7 +807,8 @@ static void render_output(struct sway_output *output, struct timespec *when, } // TODO: handle views smaller than the output - render_view(workspace->sway_workspace->fullscreen, output, damage); + render_view_surfaces( + workspace->sway_workspace->fullscreen, output, damage); if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) { render_unmanaged(output, damage, diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 8aebc0cc..b8e07bca 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -86,12 +86,14 @@ static void apply_horiz_layout(struct sway_container *parent) { if (!num_children) { return; } - size_t parent_height = parent->height; size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->border_thickness * 2 + config->font_height; - parent_height -= parent_offset; + parent_offset = config->font_height + 8; + } else if (parent->parent->layout == L_STACKED) { + parent_offset = (config->font_height + 8) + * parent->parent->children->length; } + size_t parent_height = parent->height - parent_offset; // Calculate total width of children double total_width = 0; @@ -132,12 +134,14 @@ static void apply_vert_layout(struct sway_container *parent) { if (!num_children) { return; } - size_t parent_height = parent->height; size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->border_thickness * 2 + config->font_height; - parent_height -= parent_offset; + parent_offset = config->font_height + 8; + } else if (parent->parent->layout == L_STACKED) { + parent_offset = (config->font_height + 8) + * parent->parent->children->length; } + size_t parent_height = parent->height - parent_offset; // Calculate total height of children double total_height = 0; @@ -186,6 +190,19 @@ static void apply_tabbed_layout(struct sway_container *parent) { } } +static void apply_stacked_layout(struct sway_container *parent) { + if (!parent->children->length) { + return; + } + for (int i = 0; i < parent->children->length; ++i) { + struct sway_container *child = parent->children->items[i]; + child->x = parent->x; + child->y = parent->y; + child->width = parent->width; + child->height = parent->height; + } +} + void arrange_children_of(struct sway_container *parent) { if (config->reloading) { return; @@ -219,6 +236,9 @@ void arrange_children_of(struct sway_container *parent) { case L_TABBED: apply_tabbed_layout(parent); break; + case L_STACKED: + apply_stacked_layout(parent); + break; default: wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); diff --git a/sway/tree/view.c b/sway/tree/view.c index c013e635..1280dc8d 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -182,11 +182,11 @@ void view_autoconfigure(struct sway_view *view) { // area. We have to offset the surface y by the height of the title bar, and // disable any top border because we'll always have the title bar. if (view->swayc->parent->layout == L_TABBED) { - y_offset = config->border_thickness * 2 + config->font_height; + y_offset = config->font_height + 8; view->border_top = 0; } else if (view->swayc->parent->layout == L_STACKED) { - y_offset = config->border_thickness * 2 + config->font_height; - y_offset *= view->swayc->parent->children->length; + y_offset = (config->font_height + 8) + * view->swayc->parent->children->length; view->border_top = 0; } @@ -208,7 +208,7 @@ void view_autoconfigure(struct sway_view *view) { - view->border_thickness * view->border_bottom; break; case B_NORMAL: - // Height is: border + title height + border + view height + border + // Height is: 1px border + 3px pad + title height + 3px pad + 1px border x = view->swayc->x + view->border_thickness * view->border_left; width = view->swayc->width - view->border_thickness * view->border_left @@ -218,10 +218,9 @@ void view_autoconfigure(struct sway_view *view) { height = view->swayc->height - y_offset - view->border_thickness * view->border_bottom; } else { - y = view->swayc->y + config->font_height + view->border_thickness * 2 - + y_offset; - height = view->swayc->height - config->font_height - - view->border_thickness * (2 + view->border_bottom); + y = view->swayc->y + config->font_height + 8; + height = view->swayc->height - config->font_height - 8 + - view->border_thickness * view->border_bottom; } break; } -- cgit v1.2.3