aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorlocture <locture@noreply.codeberg.org>2023-04-25 03:43:36 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-05-18 15:49:44 +0000
commitd2f81443f167408318eeaf4e1c1eae6cb74e672e (patch)
tree5840585ca04a72572746e0dc51835454fd58830d /render.c
parentsearch: regression: refresh current view when canceling a scrollback search (diff)
customized gnome-like csd buttons
Diffstat (limited to 'render.c')
-rw-r--r--render.c179
1 files changed, 107 insertions, 72 deletions
diff --git a/render.c b/render.c
index f1e80392..340e0378 100644
--- a/render.c
+++ b/render.c
@@ -2096,41 +2096,24 @@ render_csd_button_minimize(struct terminal *term, struct buffer *buf)
pixman_color_t color = get_csd_button_fg_color(term->conf);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
- const int max_height = buf->height / 2;
- const int max_width = buf->width / 2;
-
- int width = max_width;
- int height = max_width / 2;
-
- if (height > max_height) {
- height = max_height;
- width = height * 2;
- }
+ const int max_height = buf->height / 3;
+ const int max_width = buf->width / 3;
- xassert(width <= max_width);
- xassert(height <= max_height);
+ int width = min(max_height, max_width);
+ int thick = min(width / 2, 1 * term->scale);
- int x_margin = (buf->width - width) / 2.;
- int y_margin = (buf->height - height) / 2.;
+ const int x_margin = (buf->width - width) / 2;
+ const int y_margin = (buf->height - width) / 2;
- pixman_triangle_t tri = {
- .p1 = {
- .x = pixman_int_to_fixed(x_margin),
- .y = pixman_int_to_fixed(y_margin),
- },
- .p2 = {
- .x = pixman_int_to_fixed(x_margin + width),
- .y = pixman_int_to_fixed(y_margin),
- },
- .p3 = {
- .x = pixman_int_to_fixed(buf->width / 2),
- .y = pixman_int_to_fixed(y_margin + height),
- },
- };
+ xassert(x_margin + width - thick >= 0);
+ xassert(width - 2 * thick >= 0);
+ xassert(y_margin + width - thick >= 0);
+ pixman_image_fill_rectangles(
+ PIXMAN_OP_SRC, buf->pix[0], &color, 1,
+ (pixman_rectangle16_t[]) {
+ {x_margin, y_margin + width - thick, width, thick}
+ });
- pixman_composite_triangles(
- PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1,
- 0, 0, 0, 0, 1, &tri);
pixman_image_unref(src);
}
@@ -2149,7 +2132,7 @@ render_csd_button_maximize_maximized(
const int x_margin = (buf->width - width) / 2;
const int y_margin = (buf->height - width) / 2;
-
+ const int shrink = 1;
xassert(x_margin + width - thick >= 0);
xassert(width - 2 * thick >= 0);
xassert(y_margin + width - thick >= 0);
@@ -2157,11 +2140,11 @@ render_csd_button_maximize_maximized(
pixman_image_fill_rectangles(
PIXMAN_OP_SRC, buf->pix[0], &color, 4,
(pixman_rectangle16_t[]){
- {x_margin, y_margin, width, thick},
- {x_margin, y_margin + thick, thick, width - 2 * thick},
- {x_margin + width - thick, y_margin + thick, thick, width - 2 * thick},
- {x_margin, y_margin + width - thick, width, thick}});
-
+ {x_margin + shrink, y_margin + shrink, width - 2 * shrink, thick},
+ { x_margin + shrink, y_margin + thick, thick, width - 2 * thick - shrink },
+ { x_margin + width - thick - shrink, y_margin + thick, thick, width - 2 * thick - shrink },
+ { x_margin + shrink, y_margin + width - thick - shrink, width - 2 * shrink, thick }});
+
pixman_image_unref(src);
}
@@ -2173,41 +2156,27 @@ render_csd_button_maximize_window(
pixman_color_t color = get_csd_button_fg_color(term->conf);
pixman_image_t *src = pixman_image_create_solid_fill(&color);
- const int max_height = buf->height / 2;
- const int max_width = buf->width / 2;
-
- int width = max_width;
- int height = max_width / 2;
-
- if (height > max_height) {
- height = max_height;
- width = height * 2;
- }
+ const int max_height = buf->height / 3;
+ const int max_width = buf->width / 3;
- xassert(width <= max_width);
- xassert(height <= max_height);
+ int width = min(max_height, max_width);
+ int thick = min(width / 2, 1 * term->scale);
- int x_margin = (buf->width - width) / 2.;
- int y_margin = (buf->height - height) / 2.;
+ const int x_margin = (buf->width - width) / 2;
+ const int y_margin = (buf->height - width) / 2;
- pixman_triangle_t tri = {
- .p1 = {
- .x = pixman_int_to_fixed(buf->width / 2),
- .y = pixman_int_to_fixed(y_margin),
- },
- .p2 = {
- .x = pixman_int_to_fixed(x_margin),
- .y = pixman_int_to_fixed(y_margin + height),
- },
- .p3 = {
- .x = pixman_int_to_fixed(x_margin + width),
- .y = pixman_int_to_fixed(y_margin + height),
- },
- };
+ xassert(x_margin + width - thick >= 0);
+ xassert(width - 2 * thick >= 0);
+ xassert(y_margin + width - thick >= 0);
- pixman_composite_triangles(
- PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1,
- 0, 0, 0, 0, 1, &tri);
+ pixman_image_fill_rectangles(
+ PIXMAN_OP_SRC, buf->pix[0], &color, 4,
+ (pixman_rectangle16_t[]) {
+ {x_margin, y_margin, width, thick},
+ { x_margin, y_margin + thick, thick, width - 2 * thick },
+ { x_margin + width - thick, y_margin + thick, thick, width - 2 * thick },
+ { x_margin, y_margin + width - thick, width, thick }
+ });
pixman_image_unref(src);
}
@@ -2231,13 +2200,79 @@ render_csd_button_close(struct terminal *term, struct buffer *buf)
const int max_width = buf->width / 3;
int width = min(max_height, max_width);
-
+ int thick = min(width / 2, 1 * term->scale);
const int x_margin = (buf->width - width) / 2;
const int y_margin = (buf->height - width) / 2;
- pixman_image_fill_rectangles(
- PIXMAN_OP_SRC, buf->pix[0], &color, 1,
- &(pixman_rectangle16_t){x_margin, y_margin, width, width});
+ xassert(x_margin + width - thick >= 0);
+ xassert(width - 2 * thick >= 0);
+ xassert(y_margin + width - thick >= 0);
+
+ pixman_triangle_t tri[4] = {
+ {
+ .p1 = {
+ .x = pixman_int_to_fixed(x_margin),
+ .y = pixman_int_to_fixed(y_margin + thick),
+ },
+ .p2 = {
+ .x = pixman_int_to_fixed(x_margin + width - thick),
+ .y = pixman_int_to_fixed(y_margin + width),
+ },
+ .p3 = {
+ .x = pixman_int_to_fixed(x_margin + thick),
+ .y = pixman_int_to_fixed(y_margin),
+ },
+ },
+
+ {
+ .p1 = {
+ .x = pixman_int_to_fixed(x_margin + width),
+ .y = pixman_int_to_fixed(y_margin + width - thick),
+ },
+ .p2 = {
+ .x = pixman_int_to_fixed(x_margin + thick),
+ .y = pixman_int_to_fixed(y_margin),
+ },
+ .p3 = {
+ .x = pixman_int_to_fixed(x_margin + width - thick),
+ .y = pixman_int_to_fixed(y_margin + width),
+ },
+ },
+
+ {
+ .p1 = {
+ .x = pixman_int_to_fixed(x_margin),
+ .y = pixman_int_to_fixed(y_margin + width - thick),
+ },
+ .p2 = {
+ .x = pixman_int_to_fixed(x_margin + width),
+ .y = pixman_int_to_fixed(y_margin + thick),
+ },
+ .p3 = {
+ .x = pixman_int_to_fixed(x_margin + thick),
+ .y = pixman_int_to_fixed(y_margin + width),
+ },
+ },
+
+ {
+ .p1 = {
+ .x = pixman_int_to_fixed(x_margin + width),
+ .y = pixman_int_to_fixed(y_margin + thick),
+ },
+ .p2 = {
+ .x = pixman_int_to_fixed(x_margin),
+ .y = pixman_int_to_fixed(y_margin + width - thick),
+ },
+ .p3 = {
+ .x = pixman_int_to_fixed(x_margin + width - thick),
+ .y = pixman_int_to_fixed(y_margin),
+ },
+ },
+ };
+
+ pixman_composite_triangles(
+ PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1,
+ 0, 0, 0, 0, 4, tri);
pixman_image_unref(src);
}