refactor: move corner_radius to container struct

This commit is contained in:
Will McKinnon 2022-10-21 00:44:03 -04:00
parent f27ee32bd8
commit ab5e65e050
3 changed files with 38 additions and 31 deletions

View file

@ -115,6 +115,8 @@ struct sway_container {
float alpha; float alpha;
int corner_radius;
struct wlr_texture *title_focused; struct wlr_texture *title_focused;
struct wlr_texture *title_focused_inactive; struct wlr_texture *title_focused_inactive;
struct wlr_texture *title_focused_tab_title; struct wlr_texture *title_focused_tab_title;

View file

@ -257,8 +257,8 @@ damage_finish:
// _box.x and .y are expected to be layout-local // _box.x and .y are expected to be layout-local
// _box.width and .height are expected to be output-buffer-local // _box.width and .height are expected to be output-buffer-local
void render_border_corner(struct sway_output *output, pixman_region32_t *output_damage, void render_border_corner(struct sway_output *output, pixman_region32_t *output_damage,
const struct wlr_box *_box, float color[static 4], int border_thickness, const struct wlr_box *_box, float color[static 4], int corner_radius,
enum corner_location corner_location) { int border_thickness, enum corner_location corner_location) {
struct wlr_output *wlr_output = output->wlr_output; struct wlr_output *wlr_output = output->wlr_output;
struct fx_renderer *renderer = output->server->renderer; struct fx_renderer *renderer = output->server->renderer;
@ -282,7 +282,7 @@ void render_border_corner(struct sway_output *output, pixman_region32_t *output_
for (int i = 0; i < nrects; ++i) { for (int i = 0; i < nrects; ++i) {
scissor_output(wlr_output, &rects[i]); scissor_output(wlr_output, &rects[i]);
fx_render_border_corner(renderer, &box, color, wlr_output->transform_matrix, fx_render_border_corner(renderer, &box, color, wlr_output->transform_matrix,
corner_location, config->corner_radius * wlr_output->scale, border_thickness); corner_location, corner_radius * wlr_output->scale, border_thickness);
} }
damage_finish: damage_finish:
@ -320,12 +320,12 @@ static void render_view_toplevels(struct sway_view *view,
render_surface_iterator, &data); render_surface_iterator, &data);
} }
static void render_view_popups(struct sway_view *view, static void render_view_popups(struct sway_view *view, struct sway_output *output,
struct sway_output *output, pixman_region32_t *damage, float alpha) { pixman_region32_t *damage, float alpha, int corner_radius) {
struct render_data data = { struct render_data data = {
.damage = damage, .damage = damage,
.alpha = alpha, .alpha = alpha,
.corner_radius = config->corner_radius, .corner_radius = corner_radius,
}; };
output_view_for_each_popup_surface(output, view, output_view_for_each_popup_surface(output, view,
render_surface_iterator, &data); render_surface_iterator, &data);
@ -399,9 +399,9 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors, bool has_titlebar) { struct sway_container *con, struct border_colors *colors, bool has_titlebar) {
struct sway_view *view = con->view; struct sway_view *view = con->view;
if (!wl_list_empty(&view->saved_buffers)) { if (!wl_list_empty(&view->saved_buffers)) {
render_saved_view(view, output, damage, view->container->alpha, config->corner_radius); render_saved_view(view, output, damage, con->alpha, con->corner_radius);
} else if (view->surface) { } else if (view->surface) {
render_view_toplevels(view, output, damage, view->container->alpha, config->corner_radius); render_view_toplevels(view, output, damage, con->alpha, con->corner_radius);
} }
if (con->current.border == B_NONE || con->current.border == B_CSD) { if (con->current.border == B_NONE || con->current.border == B_CSD) {
@ -421,12 +421,12 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->content_height; box.height = state->content_height;
// adjust sizing for rounded border corners // adjust sizing for rounded border corners
if (config->corner_radius) { if (con->corner_radius) {
if (!has_titlebar) { if (!has_titlebar) {
box.y += config->corner_radius; box.y += con->corner_radius;
box.height -= 2 * config->corner_radius; box.height -= 2 * con->corner_radius;
} else { } else {
box.height -= config->corner_radius; box.height -= con->corner_radius;
} }
} }
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -449,12 +449,12 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->content_height; box.height = state->content_height;
// adjust sizing for rounded border corners // adjust sizing for rounded border corners
if (config->corner_radius) { if (con->corner_radius) {
if (!has_titlebar) { if (!has_titlebar) {
box.y += config->corner_radius; box.y += con->corner_radius;
box.height -= 2 * config->corner_radius; box.height -= 2 * con->corner_radius;
} else { } else {
box.height -= config->corner_radius; box.height -= con->corner_radius;
} }
} }
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -473,16 +473,16 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
box.width = state->width; box.width = state->width;
box.height = state->border_thickness; box.height = state->border_thickness;
// adjust sizing for rounded border corners // adjust sizing for rounded border corners
if (config->corner_radius) { if (con->corner_radius) {
box.x += config->corner_radius; box.x += con->corner_radius;
box.width -= 2 * config->corner_radius; box.width -= 2 * con->corner_radius;
} }
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output, damage, &box, color); render_rect(output, damage, &box, color);
// rounded bottom left & bottom right border corners // rounded bottom left & bottom right border corners
if (config->corner_radius) { if (con->corner_radius) {
int size = 2 * (config->corner_radius + state->border_thickness); int size = 2 * (con->corner_radius + state->border_thickness);
int scaled_thickness = state->border_thickness * output_scale; int scaled_thickness = state->border_thickness * output_scale;
if (state->border_left) { if (state->border_left) {
box.width = size; box.width = size;
@ -490,7 +490,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
box.x = floor(state->x); box.x = floor(state->x);
box.y = floor(state->y + state->height - size); box.y = floor(state->y + state->height - size);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_border_corner(output, damage, &box, color, scaled_thickness, BOTTOM_LEFT); render_border_corner(output, damage, &box, color,
con->corner_radius, scaled_thickness, BOTTOM_LEFT);
} }
if (state->border_right) { if (state->border_right) {
box.width = size; box.width = size;
@ -498,7 +499,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
box.x = floor(state->x + state->width - size); box.x = floor(state->x + state->width - size);
box.y = floor(state->y + state->height - size); box.y = floor(state->y + state->height - size);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_border_corner(output, damage, &box, color, scaled_thickness, BOTTOM_RIGHT); render_border_corner(output, damage, &box, color,
con->corner_radius, scaled_thickness, BOTTOM_RIGHT);
} }
} }
} }
@ -787,16 +789,16 @@ static void render_top_border(struct sway_output *output,
box.width = state->width; box.width = state->width;
box.height = state->border_thickness; box.height = state->border_thickness;
// adjust sizing for rounded border corners // adjust sizing for rounded border corners
if (config->corner_radius) { if (con->corner_radius) {
box.x += config->corner_radius; box.x += con->corner_radius;
box.width -= 2 * config->corner_radius; box.width -= 2 * con->corner_radius;
} }
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output, output_damage, &box, color); render_rect(output, output_damage, &box, color);
// render rounded top corner borders if corner_radius is set > 0 // render rounded top corner borders if corner_radius is set > 0
if (config->corner_radius) { if (con->corner_radius) {
int size = 2 * (config->corner_radius + state->border_thickness); int size = 2 * (con->corner_radius + state->border_thickness);
int scaled_thickness = state->border_thickness * output_scale; int scaled_thickness = state->border_thickness * output_scale;
// top left // top left
@ -806,7 +808,8 @@ static void render_top_border(struct sway_output *output,
box.x = floor(state->x); box.x = floor(state->x);
box.y = floor(state->y); box.y = floor(state->y);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_border_corner(output, output_damage, &box, color, scaled_thickness, TOP_LEFT); render_border_corner(output, output_damage, &box, color,
con->corner_radius, scaled_thickness, TOP_LEFT);
} }
// top right // top right
if (state->border_right) { if (state->border_right) {
@ -815,7 +818,8 @@ static void render_top_border(struct sway_output *output,
box.x = floor(state->x + state->width - size); box.x = floor(state->x + state->width - size);
box.y = floor(state->y); box.y = floor(state->y);
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_border_corner(output, output_damage, &box, color, scaled_thickness, TOP_RIGHT); render_border_corner(output, output_damage, &box, color,
con->corner_radius, scaled_thickness, TOP_RIGHT);
} }
} }
} }
@ -1251,7 +1255,7 @@ void output_render(struct sway_output *output, struct timespec *when,
struct sway_seat *seat = input_manager_current_seat(); struct sway_seat *seat = input_manager_current_seat();
struct sway_container *focus = seat_get_focused_container(seat); struct sway_container *focus = seat_get_focused_container(seat);
if (focus && focus->view) { if (focus && focus->view) {
render_view_popups(focus->view, output, damage, focus->alpha); render_view_popups(focus->view, output, damage, focus->alpha, focus->corner_radius);
} }
render_overlay: render_overlay:

View file

@ -40,6 +40,7 @@ struct sway_container *container_create(struct sway_view *view) {
c->pending.layout = L_NONE; c->pending.layout = L_NONE;
c->view = view; c->view = view;
c->alpha = 1.0f; c->alpha = 1.0f;
c->corner_radius = config->corner_radius;
if (!view) { if (!view) {
c->pending.children = create_list(); c->pending.children = create_list();