aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-22 08:27:42 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-22 08:27:42 +1000
commitf6c3682c05bce05f00b13b8f469b52923ecd8ddb (patch)
tree57a109a0bef2b14ecd24a39469d52c70f6933987 /sway
parentImplement stacked layout (diff)
downloadsway-f6c3682c05bce05f00b13b8f469b52923ecd8ddb.tar.gz
sway-f6c3682c05bce05f00b13b8f469b52923ecd8ddb.tar.zst
sway-f6c3682c05bce05f00b13b8f469b52923ecd8ddb.zip
Use constants for titlebar dimensions
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/output.c64
-rw-r--r--sway/tree/arrange.c12
-rw-r--r--sway/tree/container.c6
-rw-r--r--sway/tree/view.c8
4 files changed, 48 insertions, 42 deletions
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,
404 box.x = x; 404 box.x = x;
405 box.y = y; 405 box.y = y;
406 box.width = width; 406 box.width = width;
407 box.height = 1; 407 box.height = TITLEBAR_BORDER_THICKNESS;
408 scale_box(&box, output_scale); 408 scale_box(&box, output_scale);
409 render_rect(output->wlr_output, output_damage, &box, color); 409 render_rect(output->wlr_output, output_damage, &box, color);
410 410
@@ -420,27 +420,28 @@ static void render_titlebar(struct sway_output *output,
420 } 420 }
421 } 421 }
422 box.x = x + left_offset; 422 box.x = x + left_offset;
423 box.y = y + config->font_height + 7; 423 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
424 box.width = width - left_offset - right_offset; 424 box.width = width - left_offset - right_offset;
425 box.height = 1; 425 box.height = TITLEBAR_BORDER_THICKNESS;
426 scale_box(&box, output_scale); 426 scale_box(&box, output_scale);
427 render_rect(output->wlr_output, output_damage, &box, color); 427 render_rect(output->wlr_output, output_damage, &box, color);
428 428
429 if (layout == L_TABBED) { 429 if (layout == L_TABBED) {
430 // Single pixel left edge 430 // Single pixel left edge
431 box.x = x; 431 box.x = x;
432 box.y = y + 1; 432 box.y = y + TITLEBAR_BORDER_THICKNESS;
433 box.width = 1; 433 box.width = TITLEBAR_BORDER_THICKNESS;
434 box.height = config->font_height + 6; 434 box.height =
435 container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2;
435 scale_box(&box, output_scale); 436 scale_box(&box, output_scale);
436 render_rect(output->wlr_output, output_damage, &box, color); 437 render_rect(output->wlr_output, output_damage, &box, color);
437 438
438 // Single pixel right edge 439 // Single pixel right edge
439 box.x = (x + width - 1) * output_scale; 440 box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale;
440 render_rect(output->wlr_output, output_damage, &box, color); 441 render_rect(output->wlr_output, output_damage, &box, color);
441 } 442 }
442 443
443 size_t inner_width = width - 6; 444 size_t inner_width = width - TITLEBAR_H_PADDING * 2;
444 445
445 // Marks 446 // Marks
446 size_t marks_width = 0; 447 size_t marks_width = 0;
@@ -448,8 +449,9 @@ static void render_titlebar(struct sway_output *output,
448 struct wlr_box texture_box; 449 struct wlr_box texture_box;
449 wlr_texture_get_size(marks_texture, 450 wlr_texture_get_size(marks_texture,
450 &texture_box.width, &texture_box.height); 451 &texture_box.width, &texture_box.height);
451 texture_box.x = (x + width - 3) * output_scale - texture_box.width; 452 texture_box.x =
452 texture_box.y = (y + 4) * output_scale; 453 (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width;
454 texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale;
453 455
454 float matrix[9]; 456 float matrix[9];
455 wlr_matrix_project_box(matrix, &texture_box, 457 wlr_matrix_project_box(matrix, &texture_box,
@@ -470,8 +472,8 @@ static void render_titlebar(struct sway_output *output,
470 struct wlr_box texture_box; 472 struct wlr_box texture_box;
471 wlr_texture_get_size(title_texture, 473 wlr_texture_get_size(title_texture,
472 &texture_box.width, &texture_box.height); 474 &texture_box.width, &texture_box.height);
473 texture_box.x = (x + 3) * output_scale; 475 texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale;
474 texture_box.y = (y + 4) * output_scale; 476 texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale;
475 477
476 float matrix[9]; 478 float matrix[9];
477 wlr_matrix_project_box(matrix, &texture_box, 479 wlr_matrix_project_box(matrix, &texture_box,
@@ -489,40 +491,40 @@ static void render_titlebar(struct sway_output *output,
489 // Padding above title 491 // Padding above title
490 memcpy(&color, colors->background, sizeof(float) * 4); 492 memcpy(&color, colors->background, sizeof(float) * 4);
491 premultiply_alpha(color, con->alpha); 493 premultiply_alpha(color, con->alpha);
492 box.x = x + (layout == L_TABBED); 494 box.x = x + (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
493 box.y = y + 1; 495 box.y = y + TITLEBAR_BORDER_THICKNESS;
494 box.width = width - (layout == L_TABBED) * 2; 496 box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2;
495 box.height = 3; 497 box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS;
496 scale_box(&box, output_scale); 498 scale_box(&box, output_scale);
497 render_rect(output->wlr_output, output_damage, &box, color); 499 render_rect(output->wlr_output, output_damage, &box, color);
498 500
499 // Padding below title 501 // Padding below title
500 box.y = (y + 4 + config->font_height) * output_scale; 502 box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale;
501 render_rect(output->wlr_output, output_damage, &box, color); 503 render_rect(output->wlr_output, output_damage, &box, color);
502 504
503 // Filler between title and marks 505 // Filler between title and marks
504 box.width = inner_width * output_scale - title_width - marks_width; 506 box.width = inner_width * output_scale - title_width - marks_width;
505 if (box.width > 0) { 507 if (box.width > 0) {
506 box.x = (x + 3) * output_scale + title_width; 508 box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width;
507 box.y = (y + 4) * output_scale; 509 box.y = (y + TITLEBAR_V_PADDING) * output_scale;
508 box.height = config->font_height * output_scale; 510 box.height = config->font_height * output_scale;
509 render_rect(output->wlr_output, output_damage, &box, color); 511 render_rect(output->wlr_output, output_damage, &box, color);
510 } 512 }
511 513
512 // Padding left of title 514 // Padding left of title
513 left_offset = layout == L_TABBED ? 1 : 0; 515 left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
514 box.x = x + left_offset; 516 box.x = x + left_offset;
515 box.y = y + 4; 517 box.y = y + TITLEBAR_V_PADDING;
516 box.width = 3 - left_offset; 518 box.width = TITLEBAR_H_PADDING - left_offset;
517 box.height = config->font_height; 519 box.height = config->font_height;
518 scale_box(&box, output_scale); 520 scale_box(&box, output_scale);
519 render_rect(output->wlr_output, output_damage, &box, color); 521 render_rect(output->wlr_output, output_damage, &box, color);
520 522
521 // Padding right of marks 523 // Padding right of marks
522 right_offset = layout == L_TABBED ? 1 : 0; 524 right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS;
523 box.x = x + width - 3; 525 box.x = x + width - TITLEBAR_H_PADDING;
524 box.y = y + 4; 526 box.y = y + TITLEBAR_V_PADDING;
525 box.width = 3 - right_offset; 527 box.width = TITLEBAR_H_PADDING - right_offset;
526 box.height = config->font_height; 528 box.height = config->font_height;
527 scale_box(&box, output_scale); 529 scale_box(&box, output_scale);
528 render_rect(output->wlr_output, output_damage, &box, color); 530 render_rect(output->wlr_output, output_damage, &box, color);
@@ -530,17 +532,17 @@ static void render_titlebar(struct sway_output *output,
530 if (connects_sides) { 532 if (connects_sides) {
531 // Left pixel in line with bottom bar 533 // Left pixel in line with bottom bar
532 box.x = x; 534 box.x = x;
533 box.y = y + config->font_height + 7; 535 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
534 box.width = view->border_thickness * view->border_left; 536 box.width = view->border_thickness * view->border_left;
535 box.height = 1; 537 box.height = TITLEBAR_BORDER_THICKNESS;
536 scale_box(&box, output_scale); 538 scale_box(&box, output_scale);
537 render_rect(output->wlr_output, output_damage, &box, color); 539 render_rect(output->wlr_output, output_damage, &box, color);
538 540
539 // Right pixel in line with bottom bar 541 // Right pixel in line with bottom bar
540 box.x = x + width - view->border_thickness * view->border_right; 542 box.x = x + width - view->border_thickness * view->border_right;
541 box.y = y + config->font_height + 7; 543 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
542 box.width = view->border_thickness * view->border_right; 544 box.width = view->border_thickness * view->border_right;
543 box.height = 1; 545 box.height = TITLEBAR_BORDER_THICKNESS;
544 scale_box(&box, output_scale); 546 scale_box(&box, output_scale);
545 render_rect(output->wlr_output, output_damage, &box, color); 547 render_rect(output->wlr_output, output_damage, &box, color);
546 } 548 }
@@ -719,7 +721,7 @@ static void render_container_stacked(struct sway_output *output,
719 marks_texture = view ? view->marks_unfocused : NULL; 721 marks_texture = view ? view->marks_unfocused : NULL;
720 } 722 }
721 723
722 int y = con->y + (config->font_height + 8) * i; 724 int y = con->y + container_titlebar_height() * i;
723 render_titlebar(output, damage, child, child->x, y, child->width, 725 render_titlebar(output, damage, child, child->x, y, child->width,
724 colors, title_texture, marks_texture); 726 colors, title_texture, marks_texture);
725 727
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) {
88 } 88 }
89 size_t parent_offset = 0; 89 size_t parent_offset = 0;
90 if (parent->parent->layout == L_TABBED) { 90 if (parent->parent->layout == L_TABBED) {
91 parent_offset = config->font_height + 8; 91 parent_offset = container_titlebar_height();
92 } else if (parent->parent->layout == L_STACKED) { 92 } else if (parent->parent->layout == L_STACKED) {
93 parent_offset = (config->font_height + 8) 93 parent_offset =
94 * parent->parent->children->length; 94 container_titlebar_height() * parent->parent->children->length;
95 } 95 }
96 size_t parent_height = parent->height - parent_offset; 96 size_t parent_height = parent->height - parent_offset;
97 97
@@ -136,10 +136,10 @@ static void apply_vert_layout(struct sway_container *parent) {
136 } 136 }
137 size_t parent_offset = 0; 137 size_t parent_offset = 0;
138 if (parent->parent->layout == L_TABBED) { 138 if (parent->parent->layout == L_TABBED) {
139 parent_offset = config->font_height + 8; 139 parent_offset = container_titlebar_height();
140 } else if (parent->parent->layout == L_STACKED) { 140 } else if (parent->parent->layout == L_STACKED) {
141 parent_offset = (config->font_height + 8) 141 parent_offset =
142 * parent->parent->children->length; 142 container_titlebar_height() * parent->parent->children->length;
143 } 143 }
144 size_t parent_height = parent->height - parent_offset; 144 size_t parent_height = parent->height - parent_offset;
145 145
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,
510 struct sway_seat *seat = input_manager_current_seat(input_manager); 510 struct sway_seat *seat = input_manager_current_seat(input_manager);
511 511
512 // Tab titles 512 // Tab titles
513 int title_height = config->border_thickness * 2 + config->font_height; 513 int title_height = container_titlebar_height();
514 if (oy < parent->y + title_height) { 514 if (oy < parent->y + title_height) {
515 int tab_width = parent->width / parent->children->length; 515 int tab_width = parent->width / parent->children->length;
516 int child_index = (ox - parent->x) / tab_width; 516 int child_index = (ox - parent->x) / tab_width;
@@ -847,3 +847,7 @@ void container_notify_child_title_changed(struct sway_container *container) {
847 container_update_title_textures(container); 847 container_update_title_textures(container);
848 container_notify_child_title_changed(container->parent); 848 container_notify_child_title_changed(container->parent);
849} 849}
850
851size_t container_titlebar_height() {
852 return config->font_height + TITLEBAR_V_PADDING * 2;
853}
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) {
182 // area. We have to offset the surface y by the height of the title bar, and 182 // area. We have to offset the surface y by the height of the title bar, and
183 // disable any top border because we'll always have the title bar. 183 // disable any top border because we'll always have the title bar.
184 if (view->swayc->parent->layout == L_TABBED) { 184 if (view->swayc->parent->layout == L_TABBED) {
185 y_offset = config->font_height + 8; 185 y_offset = container_titlebar_height();
186 view->border_top = 0; 186 view->border_top = 0;
187 } else if (view->swayc->parent->layout == L_STACKED) { 187 } else if (view->swayc->parent->layout == L_STACKED) {
188 y_offset = (config->font_height + 8) 188 y_offset = container_titlebar_height()
189 * view->swayc->parent->children->length; 189 * view->swayc->parent->children->length;
190 view->border_top = 0; 190 view->border_top = 0;
191 } 191 }
@@ -218,8 +218,8 @@ void view_autoconfigure(struct sway_view *view) {
218 height = view->swayc->height - y_offset 218 height = view->swayc->height - y_offset
219 - view->border_thickness * view->border_bottom; 219 - view->border_thickness * view->border_bottom;
220 } else { 220 } else {
221 y = view->swayc->y + config->font_height + 8; 221 y = view->swayc->y + container_titlebar_height();
222 height = view->swayc->height - config->font_height - 8 222 height = view->swayc->height - container_titlebar_height()
223 - view->border_thickness * view->border_bottom; 223 - view->border_thickness * view->border_bottom;
224 } 224 }
225 break; 225 break;