From de1d16cea916c7c7f408684f60fa02d7f5ae1924 Mon Sep 17 00:00:00 2001 From: locture Date: Tue, 25 Apr 2023 03:21:28 +0000 Subject: [PATCH] customized csd buttons, based on gnome-like style Changed the csd drawings for the maxmize, return to window, minimize, close buttons. The new drawing style allows the csd to be more aligned with gnome. --- image.png | Bin 0 -> 284 bytes render.c | 203 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 119 insertions(+), 84 deletions(-) create mode 100644 image.png diff --git a/image.png b/image.png new file mode 100644 index 0000000000000000000000000000000000000000..97ccddf24dfece1063558c89c4fad58be3d5e6e6 GIT binary patch literal 284 zcmeAS@N?(olHy`uVBq!ia0y~yV8~-&V36iuV_;yIyJc4=0|NtNage(c!@6@aFBupZ zSkfJR9T^xl_H+M9WMyDr;4JWnEM{QfI}E~%$MaXDFfcG|^mK6y$#8yq;~`g*fr!Jy ztHGxC<*U~?-B8dgzo{g}evW<7kK_gE!C!*%zXrAx=T;w-;5$_i(AI1uGv(m|9`;lV zjl+&VpQj}3fB#lv`_;9wwa+E&rISnSijM9rymKJu_f!kZb84rx59?l1cj&+ReZC*h zVO^2OXV;`1c9hIpxZ_gIamFJVn?G)t&zvr9@p<2gKgoY`dM^Gv@!mp1ekz(hl6)(t asBeq1?B1<(MT&uefx*+&&t;ucLK6Uvqi?MM literal 0 HcmV?d00001 diff --git a/render.c b/render.c index 521c8b7f..8e622725 100644 --- a/render.c +++ b/render.c @@ -2095,38 +2095,21 @@ render_csd_button_minimize(struct terminal *term, struct buffer *buf) const int max_height = buf->height / 2; const int max_width = buf->width / 2; - int width = max_width; - int height = max_width / 2; + int width = min(max_height, max_width); + int thick = min(width / 2, 1 * term->scale); - if (height > max_height) { - height = max_height; - width = height * 2; - } + const int x_margin = (buf->width - width) / 2; + const int y_margin = (buf->height - width) / 2; - xassert(width <= max_width); - xassert(height <= max_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} + }); - int x_margin = (buf->width - width) / 2.; - int y_margin = (buf->height - height) / 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), - }, - }; - - pixman_composite_triangles( - PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1, - 0, 0, 0, 0, 1, &tri); pixman_image_unref(src); } @@ -2143,6 +2126,38 @@ render_csd_button_maximize_maximized( 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; + const int shrink = 1; + 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, 4, + (pixman_rectangle16_t[]){ + {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); + +} + +static void +render_csd_button_maximize_window( + 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 / 3; + 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; @@ -2152,58 +2167,12 @@ render_csd_button_maximize_maximized( pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix[0], &color, 4, - (pixman_rectangle16_t[]){ + (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); - -} - -static void -render_csd_button_maximize_window( - 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; - } - - xassert(width <= max_width); - xassert(height <= max_height); - - int x_margin = (buf->width - width) / 2.; - int y_margin = (buf->height - height) / 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), - }, - }; - - pixman_composite_triangles( - PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1, - 0, 0, 0, 0, 1, &tri); + { 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); } @@ -2227,13 +2196,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); }