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.
This commit is contained in:
locture 2023-04-25 03:21:28 +00:00
parent a2db3cdd5b
commit de1d16cea9
2 changed files with 119 additions and 84 deletions

BIN
image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

203
render.c
View file

@ -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);
}