Merge pull request #2015 from RyanDwyer/stacked-layout

Implement stacked layout
master
Drew DeVault 7 years ago committed by GitHub
commit 9731d080be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,12 @@ extern struct sway_container root_container;
struct sway_view; struct sway_view;
struct sway_seat; struct sway_seat;
#define TITLEBAR_BORDER_THICKNESS 1
// Padding includes titlebar border
#define TITLEBAR_H_PADDING 3
#define TITLEBAR_V_PADDING 4
/** /**
* Different kinds of containers. * Different kinds of containers.
* *
@ -212,4 +218,9 @@ void container_calculate_title_height(struct sway_container *container);
void container_notify_child_title_changed(struct sway_container *container); void container_notify_child_title_changed(struct sway_container *container);
/**
* Return the height of a regular title bar.
*/
size_t container_titlebar_height(void);
#endif #endif

@ -41,6 +41,8 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
parent->layout = L_VERT; parent->layout = L_VERT;
} else if (strcasecmp(argv[0], "tabbed") == 0) { } else if (strcasecmp(argv[0], "tabbed") == 0) {
parent->layout = L_TABBED; 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) { } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) {
if (parent->layout == L_HORIZ) { if (parent->layout == L_HORIZ) {
parent->layout = L_VERT; parent->layout = L_VERT;

@ -269,17 +269,6 @@ static void render_unmanaged(struct sway_output *output,
render_surface_iterator, &data); 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, static void render_rect(struct wlr_output *wlr_output,
pixman_region32_t *output_damage, const struct wlr_box *_box, pixman_region32_t *output_damage, const struct wlr_box *_box,
float color[static 4]) { float color[static 4]) {
@ -317,36 +306,42 @@ static void premultiply_alpha(float color[4], float opacity) {
color[2] *= color[3]; 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". * Render a view's surface and left/bottom/right borders.
*
* 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_normal(struct sway_output *output, static void render_view(struct sway_output *output, pixman_region32_t *damage,
pixman_region32_t *output_damage, struct sway_container *con, struct border_colors *colors) {
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];
struct sway_view *view = con->sway_view; struct sway_view *view = con->sway_view;
render_view_surfaces(view, output, damage);
struct wlr_box box;
float output_scale = output->wlr_output->scale; float output_scale = output->wlr_output->scale;
float color[4];
if (view->border != B_NONE) {
if (view->border_left) { if (view->border_left) {
// Child border - left edge
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = con->x;
box.y = con->y + 1; box.y = view->y;
box.width = view->border_thickness; box.width = view->border_thickness;
box.height = con->height - 1 box.height = view->height;
- view->border_thickness * view->border_bottom;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, damage, &box, color);
} }
if (view->border_right) { if (view->border_right) {
// Child border - right edge
if (con->parent->children->length == 1 if (con->parent->children->length == 1
&& con->parent->layout == L_HORIZ) { && con->parent->layout == L_HORIZ) {
memcpy(&color, colors->indicator, sizeof(float) * 4); memcpy(&color, colors->indicator, sizeof(float) * 4);
@ -354,17 +349,15 @@ static void render_container_simple_border_normal(struct sway_output *output,
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x + con->width - view->border_thickness; box.x = view->x + view->width;
box.y = con->y + 1; box.y = view->y;
box.width = view->border_thickness; box.width = view->border_thickness;
box.height = con->height - 1 box.height = view->height;
- view->border_thickness * view->border_bottom;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, damage, &box, color);
} }
if (view->border_bottom) { if (view->border_bottom) {
// Child border - bottom edge
if (con->parent->children->length == 1 if (con->parent->children->length == 1
&& con->parent->layout == L_VERT) { && con->parent->layout == L_VERT) {
memcpy(&color, colors->indicator, sizeof(float) * 4); memcpy(&color, colors->indicator, sizeof(float) * 4);
@ -373,52 +366,101 @@ static void render_container_simple_border_normal(struct sway_output *output,
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = con->x;
box.y = con->y + con->height - view->border_thickness; box.y = view->y + view->height;
box.width = con->width; box.width = con->width;
box.height = view->border_thickness; box.height = view->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_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 // Single pixel bar above title
memcpy(&color, colors->border, sizeof(float) * 4); memcpy(&color, colors->border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = x;
box.y = con->y; box.y = y;
box.width = con->width; box.width = width;
box.height = 1; box.height = TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); 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 // Single pixel bar below title
memcpy(&color, colors->border, sizeof(float) * 4); size_t left_offset = 0, right_offset = 0;
premultiply_alpha(color, con->alpha); bool connects_sides = false;
box.x = inner_x; if (layout == L_HORIZ || layout == L_VERT ||
box.y = view->y - 1; (layout == L_STACKED && is_last_child)) {
box.width = inner_width; if (view) {
box.height = 1; 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 + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
box.width = width - left_offset - right_offset;
box.height = TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
if (layout == L_TABBED) {
// Single pixel left edge
box.x = x;
box.y = y + TITLEBAR_BORDER_THICKNESS;
box.width = TITLEBAR_BORDER_THICKNESS;
box.height =
container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2;
scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color);
// Single pixel right edge
box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale;
render_rect(output->wlr_output, output_damage, &box, color);
}
size_t inner_width = width - TITLEBAR_H_PADDING * 2;
// Marks // Marks
size_t marks_width = 0; size_t marks_width = 0;
if (config->show_marks && marks_texture) { if (config->show_marks && marks_texture) {
struct wlr_box texture_box; struct wlr_box texture_box;
wlr_texture_get_size(marks_texture, wlr_texture_get_size(marks_texture,
&texture_box.width, &texture_box.height); &texture_box.width, &texture_box.height);
texture_box.x = (inner_x + inner_width) * output_scale - texture_box.width; texture_box.x =
texture_box.y = (con->y + view->border_thickness) * output_scale; (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width;
texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale;
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &texture_box, wlr_matrix_project_box(matrix, &texture_box,
WL_OUTPUT_TRANSFORM_NORMAL, WL_OUTPUT_TRANSFORM_NORMAL,
0.0, output->wlr_output->transform_matrix); 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, render_texture(output->wlr_output, output_damage, marks_texture,
&texture_box, matrix, con->alpha); &texture_box, matrix, con->alpha);
marks_width = texture_box.width; marks_width = texture_box.width;
@ -430,8 +472,8 @@ static void render_container_simple_border_normal(struct sway_output *output,
struct wlr_box texture_box; struct wlr_box texture_box;
wlr_texture_get_size(title_texture, wlr_texture_get_size(title_texture,
&texture_box.width, &texture_box.height); &texture_box.width, &texture_box.height);
texture_box.x = inner_x * output_scale; texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale;
texture_box.y = (con->y + view->border_thickness) * output_scale; texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale;
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &texture_box, wlr_matrix_project_box(matrix, &texture_box,
@ -446,104 +488,89 @@ static void render_container_simple_border_normal(struct sway_output *output,
title_width = texture_box.width; title_width = texture_box.width;
} }
// Title background - above the text // Padding above title
memcpy(&color, colors->background, sizeof(float) * 4); memcpy(&color, colors->background, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = inner_x; box.x = x + (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
box.y = con->y + 1; box.y = y + TITLEBAR_BORDER_THICKNESS;
box.width = inner_width; box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2;
box.height = view->border_thickness - 1; box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
// Title background - below the text // Padding below title
box.y = (con->y + view->border_thickness + config->font_height) box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale;
* output_scale;
render_rect(output->wlr_output, output_damage, &box, color); 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; box.width = inner_width * output_scale - title_width - marks_width;
if (box.width > 0) { if (box.width > 0) {
box.x = inner_x * output_scale + title_width; box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width;
box.y = (con->y + view->border_thickness) * output_scale; box.y = (y + TITLEBAR_V_PADDING) * output_scale;
box.height = config->font_height * output_scale; box.height = config->font_height * output_scale;
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
} }
}
/** // Padding left of title
* Render decorations for a view with "border pixel". left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
* box.x = x + left_offset;
* Care must be taken not to render over the same pixel multiple times, box.y = y + TITLEBAR_V_PADDING;
* otherwise the colors will be incorrect when using opacity. box.width = TITLEBAR_H_PADDING - left_offset;
*/ box.height = config->font_height;
static void render_container_simple_border_pixel(struct sway_output *output, scale_box(&box, output_scale);
pixman_region32_t *output_damage, struct sway_container *con, render_rect(output->wlr_output, output_damage, &box, color);
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;
if (view->border_left) { // Padding right of marks
// Child border - left edge right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
memcpy(&color, colors->child_border, sizeof(float) * 4); box.x = x + width - TITLEBAR_H_PADDING;
premultiply_alpha(color, con->alpha); box.y = y + TITLEBAR_V_PADDING;
box.x = con->x; box.width = TITLEBAR_H_PADDING - right_offset;
box.y = con->y + view->border_thickness * view->border_top; box.height = config->font_height;
box.width = view->border_thickness;
box.height = con->height - view->border_thickness
* (view->border_top + view->border_bottom);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
}
if (view->border_right) { if (connects_sides) {
// Child border - right edge // Left pixel in line with bottom bar
if (con->parent->children->length == 1 box.x = x;
&& con->parent->layout == L_HORIZ) { box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
memcpy(&color, colors->indicator, sizeof(float) * 4); box.width = view->border_thickness * view->border_left;
} else { box.height = TITLEBAR_BORDER_THICKNESS;
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);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
}
if (view->border_top) { // Right pixel in line with bottom bar
// Child border - top edge box.x = x + width - view->border_thickness * view->border_right;
memcpy(&color, colors->child_border, sizeof(float) * 4); box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
premultiply_alpha(color, con->alpha); box.width = view->border_thickness * view->border_right;
box.x = con->x; box.height = TITLEBAR_BORDER_THICKNESS;
box.y = con->y;
box.width = con->width;
box.height = view->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
} }
}
if (view->border_bottom) { /**
// Child border - bottom edge * Render the top border line for a view using "border pixel".
if (con->parent->children->length == 1 */
&& con->parent->layout == L_VERT) { static void render_top_border(struct sway_output *output,
memcpy(&color, colors->indicator, sizeof(float) * 4); pixman_region32_t *output_damage, struct sway_container *con,
} else { struct border_colors *colors) {
memcpy(&color, colors->child_border, sizeof(float) * 4); 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); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = con->x;
box.y = con->y + con->height - view->border_thickness; box.y = con->y;
box.width = con->width; box.width = con->width;
box.height = view->border_thickness; box.height = view->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
}
} }
static void render_container(struct sway_output *output, static void render_container(struct sway_output *output,
@ -565,7 +592,6 @@ static void render_container_simple(struct sway_output *output,
struct sway_container *child = con->children->items[i]; struct sway_container *child = con->children->items[i];
if (child->type == C_VIEW) { if (child->type == C_VIEW) {
if (child->sway_view->border != B_NONE) {
struct border_colors *colors; struct border_colors *colors;
struct wlr_texture *title_texture; struct wlr_texture *title_texture;
struct wlr_texture *marks_texture; struct wlr_texture *marks_texture;
@ -584,14 +610,12 @@ static void render_container_simple(struct sway_output *output,
} }
if (child->sway_view->border == B_NORMAL) { if (child->sway_view->border == B_NORMAL) {
render_container_simple_border_normal(output, damage, render_titlebar(output, damage, child, child->x, child->y,
child, colors, title_texture, marks_texture); child->width, colors, title_texture, marks_texture);
} else { } else {
render_container_simple_border_pixel(output, damage, child, render_top_border(output, damage, child, colors);
colors);
}
} }
render_view(child->sway_view, output, damage); render_view(output, damage, child, colors);
} else { } else {
render_container(output, damage, child, render_container(output, damage, child,
parent_focused || focus == child); parent_focused || focus == child);
@ -599,154 +623,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, * Render a container's children using the L_TABBED layout.
struct border_colors *colors, struct wlr_texture *title_texture) { */
struct sway_container *con = parent->children->items[child_index]; static void render_container_tabbed(struct sway_output *output,
float output_scale = output->wlr_output->scale; pixman_region32_t *damage, struct sway_container *con,
float color[4]; bool parent_focused) {
struct wlr_box box; if (!con->children->length) {
return;
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;
} }
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 // Render tabs
memcpy(&color, colors->border, sizeof(float) * 4); for (int i = 0; i < con->children->length; ++i) {
premultiply_alpha(color, con->alpha); struct sway_container *child = con->children->items[i];
box.x = x; struct border_colors *colors;
box.y = parent->y; struct wlr_texture *title_texture;
box.width = tab_width; struct wlr_texture *marks_texture;
box.height = 1; struct sway_view *view =
scale_box(&box, output_scale); child->type == C_VIEW ? child->sway_view : NULL;
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);
int available = (tab_width - config->border_thickness * 2 - 2) if (focus == child || parent_focused) {
* output_scale; colors = &config->border_colors.focused;
if (texture_box.width > available) { title_texture = child->title_focused;
texture_box.width = available; marks_texture = view ? view->marks_focused : NULL;
} } else if (child == current) {
render_texture(output->wlr_output, damage, title_texture, colors = &config->border_colors.focused_inactive;
&texture_box, matrix, 1.0); title_texture = child->title_focused_inactive;
title_width = texture_box.width; 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;
} }
// Title background - above the text int tab_width = con->width / con->children->length;
memcpy(&color, colors->background, sizeof(float) * 4); int x = con->x + tab_width * i;
premultiply_alpha(color, con->alpha); // Make last tab use the remaining width of the parent
box.x = x + 1; if (i == con->children->length - 1) {
box.y = parent->y + 1; tab_width = con->width - tab_width * i;
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; render_titlebar(output, damage, child, x, child->y, tab_width, colors,
float output_scale = output->wlr_output->scale; title_texture, marks_texture);
float color[4];
if (view->border != B_NONE) { if (child == current) {
if (view->border_left) { current_colors = colors;
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);
} }
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);
} }
if (view->border_bottom) { // Render surface and left/right/bottom borders
memcpy(&color, colors->child_border, sizeof(float) * 4); if (current->type == C_VIEW) {
premultiply_alpha(color, con->alpha); render_view(output, damage, current, current_colors);
box.x = con->x; } else {
box.y = view->y + view->height; render_container(output, damage, current,
box.width = con->width; parent_focused || current == focus);
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. * 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, pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) { bool parent_focused) {
if (!con->children->length) { if (!con->children->length) {
@ -757,24 +698,32 @@ static void render_container_tabbed(struct sway_output *output,
struct sway_container *current = seat_get_active_child(seat, con); struct sway_container *current = seat_get_active_child(seat, con);
struct border_colors *current_colors = NULL; struct border_colors *current_colors = NULL;
// Render tabs // Render titles
for (int i = 0; i < con->children->length; ++i) { for (int i = 0; i < con->children->length; ++i) {
struct sway_container *child = con->children->items[i]; struct sway_container *child = con->children->items[i];
struct border_colors *colors; struct border_colors *colors;
struct wlr_texture *title_texture; 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) { if (focus == child || parent_focused) {
colors = &config->border_colors.focused; colors = &config->border_colors.focused;
title_texture = child->title_focused; title_texture = child->title_focused;
marks_texture = view ? view->marks_focused : NULL;
} else if (child == current) { } else if (child == current) {
colors = &config->border_colors.focused_inactive; colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive; title_texture = child->title_focused_inactive;
marks_texture = view ? view->marks_focused_inactive : NULL;
} else { } else {
colors = &config->border_colors.unfocused; colors = &config->border_colors.unfocused;
title_texture = child->title_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 + container_titlebar_height() * i;
render_titlebar(output, damage, child, child->x, y, child->width,
colors, title_texture, marks_texture);
if (child == current) { if (child == current) {
current_colors = colors; current_colors = colors;
@ -783,21 +732,13 @@ static void render_container_tabbed(struct sway_output *output,
// Render surface and left/right/bottom borders // Render surface and left/right/bottom borders
if (current->type == C_VIEW) { if (current->type == C_VIEW) {
render_tab_content(output, damage, current, current_colors); render_view(output, damage, current, current_colors);
} else { } else {
render_container(output, damage, current, render_container(output, damage, current,
parent_focused || current == focus); 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, static void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) { bool parent_focused) {
@ -808,7 +749,7 @@ static void render_container(struct sway_output *output,
render_container_simple(output, damage, con, parent_focused); render_container_simple(output, damage, con, parent_focused);
break; break;
case L_STACKED: case L_STACKED:
render_container_stacked(output, damage, con); render_container_stacked(output, damage, con, parent_focused);
break; break;
case L_TABBED: case L_TABBED:
render_container_tabbed(output, damage, con, parent_focused); render_container_tabbed(output, damage, con, parent_focused);
@ -868,7 +809,8 @@ static void render_output(struct sway_output *output, struct timespec *when,
} }
// TODO: handle views smaller than the output // 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) { if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) {
render_unmanaged(output, damage, render_unmanaged(output, damage,

@ -86,12 +86,14 @@ static void apply_horiz_layout(struct sway_container *parent) {
if (!num_children) { if (!num_children) {
return; return;
} }
size_t parent_height = parent->height;
size_t parent_offset = 0; size_t parent_offset = 0;
if (parent->parent->layout == L_TABBED) { if (parent->parent->layout == L_TABBED) {
parent_offset = config->border_thickness * 2 + config->font_height; parent_offset = container_titlebar_height();
parent_height -= parent_offset; } else if (parent->parent->layout == L_STACKED) {
parent_offset =
container_titlebar_height() * parent->parent->children->length;
} }
size_t parent_height = parent->height - parent_offset;
// Calculate total width of children // Calculate total width of children
double total_width = 0; double total_width = 0;
@ -132,12 +134,14 @@ static void apply_vert_layout(struct sway_container *parent) {
if (!num_children) { if (!num_children) {
return; return;
} }
size_t parent_height = parent->height;
size_t parent_offset = 0; size_t parent_offset = 0;
if (parent->parent->layout == L_TABBED) { if (parent->parent->layout == L_TABBED) {
parent_offset = config->border_thickness * 2 + config->font_height; parent_offset = container_titlebar_height();
parent_height -= parent_offset; } else if (parent->parent->layout == L_STACKED) {
parent_offset =
container_titlebar_height() * parent->parent->children->length;
} }
size_t parent_height = parent->height - parent_offset;
// Calculate total height of children // Calculate total height of children
double total_height = 0; 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) { void arrange_children_of(struct sway_container *parent) {
if (config->reloading) { if (config->reloading) {
return; return;
@ -219,6 +236,9 @@ void arrange_children_of(struct sway_container *parent) {
case L_TABBED: case L_TABBED:
apply_tabbed_layout(parent); apply_tabbed_layout(parent);
break; break;
case L_STACKED:
apply_stacked_layout(parent);
break;
default: default:
wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
apply_horiz_layout(parent); apply_horiz_layout(parent);

@ -510,7 +510,7 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
// Tab titles // Tab titles
int title_height = config->border_thickness * 2 + config->font_height; int title_height = container_titlebar_height();
if (oy < parent->y + title_height) { if (oy < parent->y + title_height) {
int tab_width = parent->width / parent->children->length; int tab_width = parent->width / parent->children->length;
int child_index = (ox - parent->x) / tab_width; int child_index = (ox - parent->x) / tab_width;
@ -533,8 +533,23 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
static struct sway_container *container_at_stacked( static struct sway_container *container_at_stacked(
struct sway_container *parent, double ox, double oy, struct sway_container *parent, double ox, double oy,
struct wlr_surface **surface, double *sx, double *sy) { struct wlr_surface **surface, double *sx, double *sy) {
// TODO if (oy < parent->y || oy > parent->y + parent->height) {
return NULL; return NULL;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
// Title bars
int title_height = container_titlebar_height();
int child_index = (oy - parent->y) / title_height;
if (child_index < parent->children->length) {
struct sway_container *child = parent->children->items[child_index];
return seat_get_focus_inactive(seat, child);
}
// Surfaces
struct sway_container *current = seat_get_active_child(seat, parent);
return container_at(current, ox, oy, surface, sx, sy);
} }
/** /**
@ -847,3 +862,7 @@ void container_notify_child_title_changed(struct sway_container *container) {
container_update_title_textures(container); container_update_title_textures(container);
container_notify_child_title_changed(container->parent); container_notify_child_title_changed(container->parent);
} }
size_t container_titlebar_height() {
return config->font_height + TITLEBAR_V_PADDING * 2;
}

@ -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 // 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. // disable any top border because we'll always have the title bar.
if (view->swayc->parent->layout == L_TABBED) { if (view->swayc->parent->layout == L_TABBED) {
y_offset = config->border_thickness * 2 + config->font_height; y_offset = container_titlebar_height();
view->border_top = 0; view->border_top = 0;
} else if (view->swayc->parent->layout == L_STACKED) { } else if (view->swayc->parent->layout == L_STACKED) {
y_offset = config->border_thickness * 2 + config->font_height; y_offset = container_titlebar_height()
y_offset *= view->swayc->parent->children->length; * view->swayc->parent->children->length;
view->border_top = 0; view->border_top = 0;
} }
@ -208,7 +208,7 @@ void view_autoconfigure(struct sway_view *view) {
- view->border_thickness * view->border_bottom; - view->border_thickness * view->border_bottom;
break; break;
case B_NORMAL: 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; x = view->swayc->x + view->border_thickness * view->border_left;
width = view->swayc->width width = view->swayc->width
- view->border_thickness * view->border_left - view->border_thickness * view->border_left
@ -218,10 +218,9 @@ void view_autoconfigure(struct sway_view *view) {
height = view->swayc->height - y_offset height = view->swayc->height - y_offset
- view->border_thickness * view->border_bottom; - view->border_thickness * view->border_bottom;
} else { } else {
y = view->swayc->y + config->font_height + view->border_thickness * 2 y = view->swayc->y + container_titlebar_height();
+ y_offset; height = view->swayc->height - container_titlebar_height()
height = view->swayc->height - config->font_height - view->border_thickness * view->border_bottom;
- view->border_thickness * (2 + view->border_bottom);
} }
break; break;
} }

Loading…
Cancel
Save