From f6c3682c05bce05f00b13b8f469b52923ecd8ddb Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 22 May 2018 08:27:42 +1000 Subject: Use constants for titlebar dimensions --- include/sway/tree/container.h | 11 ++++++++ sway/desktop/output.c | 64 ++++++++++++++++++++++--------------------- sway/tree/arrange.c | 12 ++++---- sway/tree/container.c | 6 +++- sway/tree/view.c | 8 +++--- 5 files changed, 59 insertions(+), 42 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 598a4f3d..64e8634a 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -11,6 +11,12 @@ extern struct sway_container root_container; struct sway_view; 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. * @@ -212,4 +218,9 @@ void container_calculate_title_height(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(); + #endif diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 3b501a63..765647fd 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -404,7 +404,7 @@ static void render_titlebar(struct sway_output *output, box.x = x; box.y = y; box.width = width; - box.height = 1; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); @@ -420,27 +420,28 @@ static void render_titlebar(struct sway_output *output, } } box.x = x + left_offset; - box.y = y + config->font_height + 7; + box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = width - left_offset - right_offset; - box.height = 1; + box.height = TITLEBAR_BORDER_THICKNESS; 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; + 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 - 1) * output_scale; + box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale; render_rect(output->wlr_output, output_damage, &box, color); } - size_t inner_width = width - 6; + size_t inner_width = width - TITLEBAR_H_PADDING * 2; // Marks size_t marks_width = 0; @@ -448,8 +449,9 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x + width - 3) * output_scale - texture_box.width; - texture_box.y = (y + 4) * output_scale; + texture_box.x = + (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; + texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -470,8 +472,8 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x + 3) * output_scale; - texture_box.y = (y + 4) * output_scale; + texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale; + texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -489,40 +491,40 @@ static void render_titlebar(struct sway_output *output, // Padding above title memcpy(&color, colors->background, sizeof(float) * 4); premultiply_alpha(color, con->alpha); - box.x = x + (layout == L_TABBED); - box.y = y + 1; - box.width = width - (layout == L_TABBED) * 2; - box.height = 3; + box.x = x + (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; + box.y = y + TITLEBAR_BORDER_THICKNESS; + box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2; + box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); // Padding below title - box.y = (y + 4 + config->font_height) * output_scale; + box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale; render_rect(output->wlr_output, output_damage, &box, color); // Filler between title and marks box.width = inner_width * output_scale - title_width - marks_width; if (box.width > 0) { - box.x = (x + 3) * output_scale + title_width; - box.y = (y + 4) * output_scale; + box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width; + box.y = (y + TITLEBAR_V_PADDING) * output_scale; box.height = config->font_height * output_scale; render_rect(output->wlr_output, output_damage, &box, color); } // Padding left of title - left_offset = layout == L_TABBED ? 1 : 0; + left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; box.x = x + left_offset; - box.y = y + 4; - box.width = 3 - left_offset; + box.y = y + TITLEBAR_V_PADDING; + box.width = TITLEBAR_H_PADDING - left_offset; box.height = config->font_height; 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; + right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; + box.x = x + width - TITLEBAR_H_PADDING; + box.y = y + TITLEBAR_V_PADDING; + box.width = TITLEBAR_H_PADDING - right_offset; box.height = config->font_height; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); @@ -530,17 +532,17 @@ static void render_titlebar(struct sway_output *output, if (connects_sides) { // Left pixel in line with bottom bar box.x = x; - box.y = y + config->font_height + 7; + box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = view->border_thickness * view->border_left; - box.height = 1; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); // 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.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.width = view->border_thickness * view->border_right; - box.height = 1; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } @@ -719,7 +721,7 @@ static void render_container_stacked(struct sway_output *output, marks_texture = view ? view->marks_unfocused : NULL; } - int y = con->y + (config->font_height + 8) * i; + int y = con->y + container_titlebar_height() * i; render_titlebar(output, damage, child, child->x, y, child->width, colors, title_texture, marks_texture); diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index b8e07bca..37f4a066 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -88,10 +88,10 @@ static void apply_horiz_layout(struct sway_container *parent) { } size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->font_height + 8; + parent_offset = container_titlebar_height(); } else if (parent->parent->layout == L_STACKED) { - parent_offset = (config->font_height + 8) - * parent->parent->children->length; + parent_offset = + container_titlebar_height() * parent->parent->children->length; } size_t parent_height = parent->height - parent_offset; @@ -136,10 +136,10 @@ static void apply_vert_layout(struct sway_container *parent) { } size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->font_height + 8; + parent_offset = container_titlebar_height(); } else if (parent->parent->layout == L_STACKED) { - parent_offset = (config->font_height + 8) - * parent->parent->children->length; + parent_offset = + container_titlebar_height() * parent->parent->children->length; } size_t parent_height = parent->height - parent_offset; diff --git a/sway/tree/container.c b/sway/tree/container.c index 5d88325f..3f30a079 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -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); // Tab titles - int title_height = config->border_thickness * 2 + config->font_height; + int title_height = container_titlebar_height(); if (oy < parent->y + title_height) { int tab_width = parent->width / parent->children->length; int child_index = (ox - parent->x) / tab_width; @@ -847,3 +847,7 @@ void container_notify_child_title_changed(struct sway_container *container) { container_update_title_textures(container); container_notify_child_title_changed(container->parent); } + +size_t container_titlebar_height() { + return config->font_height + TITLEBAR_V_PADDING * 2; +} diff --git a/sway/tree/view.c b/sway/tree/view.c index 1280dc8d..07157818 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -182,10 +182,10 @@ 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->font_height + 8; + y_offset = container_titlebar_height(); view->border_top = 0; } else if (view->swayc->parent->layout == L_STACKED) { - y_offset = (config->font_height + 8) + y_offset = container_titlebar_height() * view->swayc->parent->children->length; view->border_top = 0; } @@ -218,8 +218,8 @@ 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 + 8; - height = view->swayc->height - config->font_height - 8 + y = view->swayc->y + container_titlebar_height(); + height = view->swayc->height - container_titlebar_height() - view->border_thickness * view->border_bottom; } break; -- cgit v1.2.3-54-g00ecf