From af2e36860b32ee64e8293300aa71ba5aa97f2360 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Fri, 23 Jul 2021 01:50:31 +0530 Subject: [PATCH 1/8] [berrywm] static rounded corners --- config.h.in | 1 + configure | 4 ++-- wm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/config.h.in b/config.h.in index e2934b2..7b2eb3a 100644 --- a/config.h.in +++ b/config.h.in @@ -67,5 +67,6 @@ #define POINTER_INTERVAL 0 #define FOLLOW_POINTER false #define WARP_POINTER false +#define ROUND_CORNERS 20 #endif diff --git a/configure b/configure index 8c818f3..19c0411 100755 --- a/configure +++ b/configure @@ -26,10 +26,10 @@ seds=[s/ -std=c/ -march=native -std=c/] progs="CC=gcc CC=clang CC=cc INSTALL=install" # Required dependencies -pkgs="x11 xinerama fontconfig xft" +pkgs="x11 xinerama fontconfig xft xext" # Default pkg flags to substitute when pkg-config is not found -pkg_libs="-lX11 -lXinerama -lfontconfig -lfreetype -lXft" +pkg_libs="-lX11 -lXinerama -lfontconfig -lfreetype -lXft -lXext" pkg_cflags="-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include" pkg_ldflags="" diff --git a/wm.c b/wm.c index 8678899..ba2048a 100644 --- a/wm.c +++ b/wm.c @@ -135,6 +135,7 @@ static void draw_text(struct client *c, bool focused); static struct client* get_client_from_window(Window w); static void load_color(XftColor *dest_color, unsigned long raw_color); static void load_config(char *conf_path); +static void round_window_corners(struct client *c, int rad); static void manage_new_window(Window w, XWindowAttributes *wa); static int manage_xsend_icccm(struct client *c, Atom atom); static void grab_buttons(void); @@ -526,6 +527,7 @@ client_fullscreen(struct client *c, bool toggle, bool fullscreen, bool max) client_refresh(c); } + round_window_corners(c, c->fullscreen ? 0 : ROUND_CORNERS); client_set_status(c); } @@ -1303,6 +1305,43 @@ client_manage_focus(struct client *c) } } +static void +round_window_corners(struct client *c, int rad) +{ + unsigned int ww, wh, dia = 2 * rad; + + ww = get_actual_width(c); + wh = get_actual_height(c); + + if (ww < dia || wh < dia) return; + + Pixmap mask = XCreatePixmap(display, c->window, ww, wh, 1); + + if (!mask) return; + + XGCValues xgcv; + GC shape_gc = XCreateGC(display, mask, 0, &xgcv); + + if (!shape_gc) { + XFreePixmap(display, mask); + return; + } + + XSetForeground(display, shape_gc, 0); + XFillRectangle(display, mask, shape_gc, 0, 0, ww, wh); + XSetForeground(display, shape_gc, 1); + XFillArc(display, mask, shape_gc, 0, 0, dia, dia, 0, 23040); + XFillArc(display, mask, shape_gc, ww-dia-1, 0, dia, dia, 0, 23040); + XFillArc(display, mask, shape_gc, 0, wh-dia-1, dia, dia, 0, 23040); + XFillArc(display, mask, shape_gc, ww-dia-1, wh-dia-1, dia, dia, 0, 23040); + XFillRectangle(display, mask, shape_gc, rad, 0, ww-dia, wh); + XFillRectangle(display, mask, shape_gc, 0, rad, ww, wh-dia); + XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, mask, ShapeSet); + XShapeCombineMask(display, c->dec, ShapeBounding, 0, 0, mask, ShapeSet); + XFreePixmap(display, mask); + XFreeGC(display, shape_gc); +} + static void manage_new_window(Window w, XWindowAttributes *wa) { @@ -1381,6 +1420,8 @@ manage_new_window(Window w, XWindowAttributes *wa) ewmh_set_desktop(c, c->ws); ewmh_set_client_list(); + round_window_corners(c, ROUND_CORNERS); + if (conf.decorate) XMapWindow(display, c->dec); @@ -1780,6 +1821,13 @@ client_resize_absolute(struct client *c, int w, int h) dec_h = h - (2 * conf.b_width); } + c->geom.width = MAX(w, MINIMUM_DIM); + c->geom.height = MAX(h, MINIMUM_DIM); + if (c->mono) + c->mono = false; + + round_window_corners(c, ROUND_CORNERS); + /*LOGN("Resizing client main window");*/ XResizeWindow(display, c->window, MAX(dw, MINIMUM_DIM), MAX(dh, MINIMUM_DIM)); if (c->decorated) { @@ -1787,10 +1835,6 @@ client_resize_absolute(struct client *c, int w, int h) XResizeWindow(display, c->dec, MAX(dec_w, MINIMUM_DIM), MAX(dec_h, MINIMUM_DIM)); } - c->geom.width = MAX(w, MINIMUM_DIM); - c->geom.height = MAX(h, MINIMUM_DIM); - if (c->mono) - c->mono = false; client_set_status(c); } From 9a8d3b72c033ca07fd9358959dfdd367d4b565a8 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Fri, 23 Jul 2021 12:52:04 +0530 Subject: [PATCH 2/8] [berrywm] dynamic rounded corners --- client.c | 1 + config.h.in | 2 +- ipc.h | 1 + types.h | 2 +- wm.c | 77 ++++++++++++++++++++++++++++------------------------- 5 files changed, 45 insertions(+), 38 deletions(-) diff --git a/client.c b/client.c index cadadda..d97e705 100644 --- a/client.c +++ b/client.c @@ -53,6 +53,7 @@ static const struct command command_table[] = { { "text_unfocus_color", IPCTitleUnfocusColor, true, 1, fn_hex }, { "border_width", IPCBorderWidth, true, 1, fn_int }, { "inner_border_width", IPCInnerBorderWidth, true, 1, fn_int }, + { "border_radius", IPCBorderRadius, true, 1, fn_int }, { "title_height", IPCTitleHeight, true, 1, fn_int }, { "switch_workspace", IPCSwitchWorkspace, false, 1, fn_int }, { "send_to_workspace", IPCSendWorkspace, false, 1, fn_int }, diff --git a/config.h.in b/config.h.in index 7b2eb3a..e05c801 100644 --- a/config.h.in +++ b/config.h.in @@ -27,6 +27,7 @@ #define BORDER_WIDTH 3 #define INTERNAL_BORDER_WIDTH 3 #define TITLE_HEIGHT 30 +#define BORDER_RADIUS 20 #define MOVE_STEP 40 #define RESIZE_STEP 40 @@ -67,6 +68,5 @@ #define POINTER_INTERVAL 0 #define FOLLOW_POINTER false #define WARP_POINTER false -#define ROUND_CORNERS 20 #endif diff --git a/ipc.h b/ipc.h index 488b1f3..236df48 100644 --- a/ipc.h +++ b/ipc.h @@ -56,6 +56,7 @@ enum IPCCommand IPCPointerInterval, IPCFocusFollowsPointer, IPCWarpPointer, + IPCBorderRadius, IPCLast }; diff --git a/types.h b/types.h index 0c61810..9abcf29 100644 --- a/types.h +++ b/types.h @@ -24,7 +24,7 @@ struct client { }; struct config { - int b_width, i_width, t_height, top_gap, bot_gap, left_gap, right_gap, r_step, m_step, move_mask, resize_mask, pointer_interval; + int b_width, i_width, t_height, top_gap, bot_gap, left_gap, right_gap, r_step, m_step, move_mask, resize_mask, pointer_interval, border_radius; unsigned long bf_color, bu_color, if_color, iu_color; bool focus_new, focus_motion, edge_lock, t_center, smart_place, draw_text, json_status, decorate, fs_remove_dec, fs_max; bool follow_pointer, warp_pointer; diff --git a/wm.c b/wm.c index ba2048a..c29084c 100644 --- a/wm.c +++ b/wm.c @@ -135,7 +135,7 @@ static void draw_text(struct client *c, bool focused); static struct client* get_client_from_window(Window w); static void load_color(XftColor *dest_color, unsigned long raw_color); static void load_config(char *conf_path); -static void round_window_corners(struct client *c, int rad); +static void round_window_corners(struct client *c); static void manage_new_window(Window w, XWindowAttributes *wa); static int manage_xsend_icccm(struct client *c, Atom atom); static void grab_buttons(void); @@ -380,8 +380,8 @@ static void client_decorations_create(struct client *c) { LOGN("Decorating new client"); - int w = c->geom.width + 2 * conf.i_width; - int h = c->geom.height + 2 * conf.i_width + conf.t_height; + int w = c->geom.width + 2 * (conf.i_width + conf.b_width); + int h = c->geom.height + 2 * (conf.i_width + conf.b_width) + conf.t_height; int x = c->geom.x - conf.i_width - conf.b_width; int y = c->geom.y - conf.i_width - conf.b_width - conf.t_height; @@ -527,7 +527,7 @@ client_fullscreen(struct client *c, bool toggle, bool fullscreen, bool max) client_refresh(c); } - round_window_corners(c, c->fullscreen ? 0 : ROUND_CORNERS); + round_window_corners(c); client_set_status(c); } @@ -1179,6 +1179,9 @@ ipc_config(long *d) case IPCWarpPointer: conf.warp_pointer = d[2]; break; + case IPCBorderRadius: + conf.border_radius = d[2]; + break; default: break; } @@ -1306,40 +1309,40 @@ client_manage_focus(struct client *c) } static void -round_window_corners(struct client *c, int rad) -{ - unsigned int ww, wh, dia = 2 * rad; - - ww = get_actual_width(c); - wh = get_actual_height(c); +round_window_corners(struct client *c) +{ + unsigned int dia = 2 * conf.border_radius, + ww = c->geom.width, + wh = c->geom.height; - if (ww < dia || wh < dia) return; + XGCValues w_xgcv; - Pixmap mask = XCreatePixmap(display, c->window, ww, wh, 1); - - if (!mask) return; - - XGCValues xgcv; - GC shape_gc = XCreateGC(display, mask, 0, &xgcv); + if (ww < dia || wh < dia) + return; + + Pixmap w_mask = XCreatePixmap(display, c->window, ww, wh, 1); + if (!w_mask) return; - if (!shape_gc) { - XFreePixmap(display, mask); + GC w_shape_gc = XCreateGC(display, w_mask, 0, &w_xgcv); + if (!w_shape_gc) { + XFreePixmap(display, w_mask); return; } - XSetForeground(display, shape_gc, 0); - XFillRectangle(display, mask, shape_gc, 0, 0, ww, wh); - XSetForeground(display, shape_gc, 1); - XFillArc(display, mask, shape_gc, 0, 0, dia, dia, 0, 23040); - XFillArc(display, mask, shape_gc, ww-dia-1, 0, dia, dia, 0, 23040); - XFillArc(display, mask, shape_gc, 0, wh-dia-1, dia, dia, 0, 23040); - XFillArc(display, mask, shape_gc, ww-dia-1, wh-dia-1, dia, dia, 0, 23040); - XFillRectangle(display, mask, shape_gc, rad, 0, ww-dia, wh); - XFillRectangle(display, mask, shape_gc, 0, rad, ww, wh-dia); - XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, mask, ShapeSet); - XShapeCombineMask(display, c->dec, ShapeBounding, 0, 0, mask, ShapeSet); - XFreePixmap(display, mask); - XFreeGC(display, shape_gc); + XSetForeground(display, w_shape_gc, 0); + XFillRectangle(display, w_mask, w_shape_gc, 0, 0, ww, wh); + XSetForeground(display, w_shape_gc, 1); + + XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, ww-dia, 0, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, 0, wh-dia, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, ww-dia, wh-dia, dia, dia, 0, 360 << 6); + + XFillRectangle(display, w_mask, w_shape_gc, conf.border_radius, 0, ww-dia, wh); + XFillRectangle(display, w_mask, w_shape_gc, 0, conf.border_radius, ww, wh-dia); + XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, w_mask, ShapeSet); + XFreePixmap(display, w_mask); + XFreeGC(display, w_shape_gc); } static void @@ -1420,8 +1423,6 @@ manage_new_window(Window w, XWindowAttributes *wa) ewmh_set_desktop(c, c->ws); ewmh_set_client_list(); - round_window_corners(c, ROUND_CORNERS); - if (conf.decorate) XMapWindow(display, c->dec); @@ -1430,6 +1431,8 @@ manage_new_window(Window w, XWindowAttributes *wa) XGrabButton(display, 1, conf.move_mask, c->window, True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None); XGrabButton(display, 1, conf.resize_mask, c->window, True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None); client_manage_focus(c); + + round_window_corners(c); } static int @@ -1826,8 +1829,6 @@ client_resize_absolute(struct client *c, int w, int h) if (c->mono) c->mono = false; - round_window_corners(c, ROUND_CORNERS); - /*LOGN("Resizing client main window");*/ XResizeWindow(display, c->window, MAX(dw, MINIMUM_DIM), MAX(dh, MINIMUM_DIM)); if (c->decorated) { @@ -1835,6 +1836,8 @@ client_resize_absolute(struct client *c, int w, int h) XResizeWindow(display, c->dec, MAX(dec_w, MINIMUM_DIM), MAX(dec_h, MINIMUM_DIM)); } + round_window_corners(c); + client_set_status(c); } @@ -1996,6 +1999,7 @@ setup(void) conf.b_width = BORDER_WIDTH; conf.t_height = TITLE_HEIGHT; conf.i_width = INTERNAL_BORDER_WIDTH; + conf.border_radius = BORDER_RADIUS; conf.bf_color = BORDER_FOCUS_COLOR; conf.bu_color = BORDER_UNFOCUS_COLOR; conf.if_color = INNER_FOCUS_COLOR; @@ -2204,6 +2208,7 @@ client_toggle_decorations(struct client *c) client_raise(c); client_manage_focus(c); ewmh_set_frame_extents(c); + round_window_corners(c); } /* From 9c95e7d882d5806739e779efda92c01e2aea7360 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Fri, 23 Jul 2021 13:45:22 +0530 Subject: [PATCH 3/8] gnrl: cleanup --- wm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wm.c b/wm.c index c29084c..a63908a 100644 --- a/wm.c +++ b/wm.c @@ -1310,7 +1310,7 @@ client_manage_focus(struct client *c) static void round_window_corners(struct client *c) -{ +{ unsigned int dia = 2 * conf.border_radius, ww = c->geom.width, wh = c->geom.height; @@ -1319,7 +1319,7 @@ round_window_corners(struct client *c) if (ww < dia || wh < dia) return; - + Pixmap w_mask = XCreatePixmap(display, c->window, ww, wh, 1); if (!w_mask) return; @@ -1332,7 +1332,7 @@ round_window_corners(struct client *c) XSetForeground(display, w_shape_gc, 0); XFillRectangle(display, w_mask, w_shape_gc, 0, 0, ww, wh); XSetForeground(display, w_shape_gc, 1); - + XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, ww-dia, 0, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, 0, wh-dia, dia, dia, 0, 360 << 6); From aeb932e8bcb516b2e412fbfe73ba818a3b5ec4bd Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Sat, 24 Jul 2021 01:37:40 +0530 Subject: [PATCH 4/8] [berrywm] rounded corner for decorations --- wm.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/wm.c b/wm.c index a63908a..12ea7b0 100644 --- a/wm.c +++ b/wm.c @@ -1310,16 +1310,44 @@ client_manage_focus(struct client *c) static void round_window_corners(struct client *c) -{ +{ unsigned int dia = 2 * conf.border_radius, ww = c->geom.width, - wh = c->geom.height; + wh = c->geom.height, + dw = get_actual_width(c), + dh = get_actual_height(c); - XGCValues w_xgcv; + XGCValues w_xgcv, d_xgcv; if (ww < dia || wh < dia) return; + + /* Add rounnded corners to the dec window */ + Pixmap d_mask = XCreatePixmap(display, c->dec, dw, dh, 1); + if (!d_mask) return; + + GC d_shape_gc = XCreateGC(display, d_mask, 0, &d_xgcv); + if (!d_shape_gc) { + XFreePixmap(display, d_mask); + return; + } + + XSetForeground(display, d_shape_gc, 0); + XFillRectangle(display, d_mask, d_shape_gc, 0, 0, dw, dh); + XSetForeground(display, d_shape_gc, 1); + XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, 0, dh-dia, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia, dh-dia, dia, dia, 0, 360 << 6); + XFillRectangle(display, d_mask, d_shape_gc, conf.border_radius, 0, dw-dia, dh); + XFillRectangle(display, d_mask, d_shape_gc, 0, conf.border_radius, dw, dh-dia); + XShapeCombineMask(display, c->dec, ShapeBounding, 0, 0, d_mask, ShapeSet); + XFreePixmap(display, d_mask); + XFreeGC(display, d_shape_gc); + + + /* Add corners to the dec window */ Pixmap w_mask = XCreatePixmap(display, c->window, ww, wh, 1); if (!w_mask) return; @@ -1332,12 +1360,10 @@ round_window_corners(struct client *c) XSetForeground(display, w_shape_gc, 0); XFillRectangle(display, w_mask, w_shape_gc, 0, 0, ww, wh); XSetForeground(display, w_shape_gc, 1); - XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, ww-dia, 0, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, 0, wh-dia, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, ww-dia, wh-dia, dia, dia, 0, 360 << 6); - XFillRectangle(display, w_mask, w_shape_gc, conf.border_radius, 0, ww-dia, wh); XFillRectangle(display, w_mask, w_shape_gc, 0, conf.border_radius, ww, wh-dia); XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, w_mask, ShapeSet); From 4b619fe23bab31e04328c944e94a5bed52095f72 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Sat, 24 Jul 2021 13:33:40 +0530 Subject: [PATCH 5/8] [berrywm] fullscreen and border fixes Due to multiple misconceptions of the workings of windows and decorations bugs were made. They have been promptly smashed. Using border(outer_border) causes: -> Removal of inner_border's rounded cornerss -> When used without inner_border visual artifacts appear --- wm.c | 85 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/wm.c b/wm.c index 12ea7b0..45dfe11 100644 --- a/wm.c +++ b/wm.c @@ -380,8 +380,8 @@ static void client_decorations_create(struct client *c) { LOGN("Decorating new client"); - int w = c->geom.width + 2 * (conf.i_width + conf.b_width); - int h = c->geom.height + 2 * (conf.i_width + conf.b_width) + conf.t_height; + int w = c->geom.width + 2 * conf.i_width; + int h = c->geom.height + 2 * conf.i_width + conf.t_height; int x = c->geom.x - conf.i_width - conf.b_width; int y = c->geom.y - conf.i_width - conf.b_width - conf.t_height; @@ -507,6 +507,7 @@ client_fullscreen(struct client *c, bool toggle, bool fullscreen, bool max) client_resize_absolute(c, m_list[mon].width, m_list[mon].height); } c->fullscreen = true; + client_refresh(c); } else { ewmh_set_fullscreen(c, false); if (max) { @@ -526,8 +527,6 @@ client_fullscreen(struct client *c, bool toggle, bool fullscreen, bool max) c->was_fs = false; client_refresh(c); } - - round_window_corners(c); client_set_status(c); } @@ -1310,43 +1309,49 @@ client_manage_focus(struct client *c) static void round_window_corners(struct client *c) -{ - unsigned int dia = 2 * conf.border_radius, - ww = c->geom.width, - wh = c->geom.height, - dw = get_actual_width(c), - dh = get_actual_height(c); +{ + unsigned int rad = conf.border_radius; + + if (c->fullscreen) + rad = 0; + + unsigned int ww, wh, dw, dh, dia = 2 * rad; + + ww = c->geom.width - (c->decorated ? get_dec_width(c) : 0) ; + wh = c->geom.height - (c->decorated ? get_dec_width(c) : 0) ; + dw = c->geom.width; + dh = c->geom.height; XGCValues w_xgcv, d_xgcv; if (ww < dia || wh < dia) return; + if (c->decorated == true) { + /* Add rounnded corners to the dec window */ + Pixmap d_mask = XCreatePixmap(display, c->dec, dw, dh, 1); + if (!d_mask) return; + + GC d_shape_gc = XCreateGC(display, d_mask, 0, &d_xgcv); + if (!d_shape_gc) { + XFreePixmap(display, d_mask); + return; + } - /* Add rounnded corners to the dec window */ - Pixmap d_mask = XCreatePixmap(display, c->dec, dw, dh, 1); - if (!d_mask) return; - - GC d_shape_gc = XCreateGC(display, d_mask, 0, &d_xgcv); - if (!d_shape_gc) { + XSetForeground(display, d_shape_gc, 0); + XFillRectangle(display, d_mask, d_shape_gc, 0, 0, dw, dh); + XSetForeground(display, d_shape_gc, 1); + XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, 0, dh-dia, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia, dh-dia, dia, dia, 0, 360 << 6); + XFillRectangle(display, d_mask, d_shape_gc, rad, 0, dw-dia, dh); + XFillRectangle(display, d_mask, d_shape_gc, 0, rad, dw, dh-dia); + XShapeCombineMask(display, c->dec, ShapeBounding, -conf.b_width, -conf.b_width, d_mask, ShapeSet); XFreePixmap(display, d_mask); - return; + XFreeGC(display, d_shape_gc); } - XSetForeground(display, d_shape_gc, 0); - XFillRectangle(display, d_mask, d_shape_gc, 0, 0, dw, dh); - XSetForeground(display, d_shape_gc, 1); - XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, 0, dh-dia, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia, dh-dia, dia, dia, 0, 360 << 6); - XFillRectangle(display, d_mask, d_shape_gc, conf.border_radius, 0, dw-dia, dh); - XFillRectangle(display, d_mask, d_shape_gc, 0, conf.border_radius, dw, dh-dia); - XShapeCombineMask(display, c->dec, ShapeBounding, 0, 0, d_mask, ShapeSet); - XFreePixmap(display, d_mask); - XFreeGC(display, d_shape_gc); - - /* Add corners to the dec window */ Pixmap w_mask = XCreatePixmap(display, c->window, ww, wh, 1); if (!w_mask) return; @@ -1364,8 +1369,8 @@ round_window_corners(struct client *c) XFillArc(display, w_mask, w_shape_gc, ww-dia, 0, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, 0, wh-dia, dia, dia, 0, 360 << 6); XFillArc(display, w_mask, w_shape_gc, ww-dia, wh-dia, dia, dia, 0, 360 << 6); - XFillRectangle(display, w_mask, w_shape_gc, conf.border_radius, 0, ww-dia, wh); - XFillRectangle(display, w_mask, w_shape_gc, 0, conf.border_radius, ww, wh-dia); + XFillRectangle(display, w_mask, w_shape_gc, rad, 0, ww-dia, wh); + XFillRectangle(display, w_mask, w_shape_gc, 0, rad, ww, wh-dia); XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, w_mask, ShapeSet); XFreePixmap(display, w_mask); XFreeGC(display, w_shape_gc); @@ -1535,6 +1540,7 @@ client_move_absolute(struct client *c, int x, int y) c->mono = false; client_set_status(c); + round_window_corners(c); } static void @@ -1850,11 +1856,6 @@ client_resize_absolute(struct client *c, int w, int h) dec_h = h - (2 * conf.b_width); } - c->geom.width = MAX(w, MINIMUM_DIM); - c->geom.height = MAX(h, MINIMUM_DIM); - if (c->mono) - c->mono = false; - /*LOGN("Resizing client main window");*/ XResizeWindow(display, c->window, MAX(dw, MINIMUM_DIM), MAX(dh, MINIMUM_DIM)); if (c->decorated) { @@ -1862,9 +1863,12 @@ client_resize_absolute(struct client *c, int w, int h) XResizeWindow(display, c->dec, MAX(dec_w, MINIMUM_DIM), MAX(dec_h, MINIMUM_DIM)); } - round_window_corners(c); - + c->geom.width = MAX(w, MINIMUM_DIM); + c->geom.height = MAX(h, MINIMUM_DIM); + if (c->mono) + c->mono = false; client_set_status(c); + round_window_corners(c); } static void @@ -2234,7 +2238,6 @@ client_toggle_decorations(struct client *c) client_raise(c); client_manage_focus(c); ewmh_set_frame_extents(c); - round_window_corners(c); } /* From a14a7daa9bdb431925c537da68b0b0ae633304e9 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Sat, 24 Jul 2021 14:43:41 +0530 Subject: [PATCH 6/8] [berrywm] title patch I made a mistake with the calculation of the mask size --- wm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wm.c b/wm.c index 45dfe11..a5db957 100644 --- a/wm.c +++ b/wm.c @@ -1318,7 +1318,7 @@ round_window_corners(struct client *c) unsigned int ww, wh, dw, dh, dia = 2 * rad; ww = c->geom.width - (c->decorated ? get_dec_width(c) : 0) ; - wh = c->geom.height - (c->decorated ? get_dec_width(c) : 0) ; + wh = c->geom.height - (c->decorated ? get_dec_height(c) : 0) ; dw = c->geom.width; dh = c->geom.height; From cde2f67d62fd02c8a270259d3e88826bd16eeaa6 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Sat, 24 Jul 2021 15:11:09 +0530 Subject: [PATCH 7/8] [berrywm] minor visual modifications --- wm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wm.c b/wm.c index a5db957..a836b42 100644 --- a/wm.c +++ b/wm.c @@ -1341,10 +1341,10 @@ round_window_corners(struct client *c) XSetForeground(display, d_shape_gc, 0); XFillRectangle(display, d_mask, d_shape_gc, 0, 0, dw, dh); XSetForeground(display, d_shape_gc, 1); - XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, 0, dh-dia, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia, dh-dia, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia-1, 0, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, 0, dh-dia-1, dia, dia, 0, 360 << 6); + XFillArc(display, d_mask, d_shape_gc, dw-dia-1, dh-dia-1, dia, dia, 0, 360 << 6); XFillRectangle(display, d_mask, d_shape_gc, rad, 0, dw-dia, dh); XFillRectangle(display, d_mask, d_shape_gc, 0, rad, dw, dh-dia); XShapeCombineMask(display, c->dec, ShapeBounding, -conf.b_width, -conf.b_width, d_mask, ShapeSet); @@ -1365,10 +1365,10 @@ round_window_corners(struct client *c) XSetForeground(display, w_shape_gc, 0); XFillRectangle(display, w_mask, w_shape_gc, 0, 0, ww, wh); XSetForeground(display, w_shape_gc, 1); - XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, ww-dia, 0, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, 0, wh-dia, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, ww-dia, wh-dia, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, ww-dia-1, 0, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, 0, wh-dia-1, dia, dia, 0, 360 << 6); + XFillArc(display, w_mask, w_shape_gc, ww-dia-1, wh-dia-1, dia, dia, 0, 360 << 6); XFillRectangle(display, w_mask, w_shape_gc, rad, 0, ww-dia, wh); XFillRectangle(display, w_mask, w_shape_gc, 0, rad, ww, wh-dia); XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, w_mask, ShapeSet); From 67ae346484e1f9d7df778876bf6dcf1c38c95d00 Mon Sep 17 00:00:00 2001 From: sidd-dino Date: Mon, 26 Jul 2021 06:09:25 +0530 Subject: [PATCH 8/8] [berrywm] code refactored --- config.h.in | 2 +- wm.c | 86 ++++++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 52 deletions(-) diff --git a/config.h.in b/config.h.in index e05c801..bb58d01 100644 --- a/config.h.in +++ b/config.h.in @@ -27,7 +27,7 @@ #define BORDER_WIDTH 3 #define INTERNAL_BORDER_WIDTH 3 #define TITLE_HEIGHT 30 -#define BORDER_RADIUS 20 +#define BORDER_RADIUS 0 #define MOVE_STEP 40 #define RESIZE_STEP 40 diff --git a/wm.c b/wm.c index a836b42..7a1bb2a 100644 --- a/wm.c +++ b/wm.c @@ -135,6 +135,7 @@ static void draw_text(struct client *c, bool focused); static struct client* get_client_from_window(Window w); static void load_color(XftColor *dest_color, unsigned long raw_color); static void load_config(char *conf_path); +static void construct_mask(Window W, int x, int y, int w, int h, int dia); static void round_window_corners(struct client *c); static void manage_new_window(Window w, XWindowAttributes *wa); static int manage_xsend_icccm(struct client *c, Atom atom); @@ -1307,73 +1308,56 @@ client_manage_focus(struct client *c) } } +static void +construct_mask(Window W, int x, int y, int w, int h, int dia) +{ + XGCValues xgcv; + + Pixmap mask = XCreatePixmap(display, W, w, h, 1); + if (!mask) return; + + GC shape_gc = XCreateGC(display, mask, 0, &xgcv); + if (!shape_gc) { + XFreePixmap(display, mask); + return; + } + + XSetForeground(display, shape_gc, 0); + XFillRectangle(display, mask, shape_gc, 0, 0, w, h); + XSetForeground(display, shape_gc, 1); + XFillArc(display, mask, shape_gc, 0, 0, dia, dia, 0, 360 << 6); + XFillArc(display, mask, shape_gc, w-dia-1, 0, dia, dia, 0, 360 << 6); + XFillArc(display, mask, shape_gc, 0, h-dia-1, dia, dia, 0, 360 << 6); + XFillArc(display, mask, shape_gc, w-dia-1, h-dia-1, dia, dia, 0, 360 << 6); + XFillRectangle(display, mask, shape_gc, dia>>1, 0, w-dia, h); + XFillRectangle(display, mask, shape_gc, 0, dia>>1, w, h-dia); + XShapeCombineMask(display, W, ShapeBounding, x, y, mask, ShapeSet); + XFreePixmap(display, mask); + XFreeGC(display, shape_gc); +} + static void round_window_corners(struct client *c) { - unsigned int rad = conf.border_radius; + unsigned int dia = conf.border_radius << 1; if (c->fullscreen) - rad = 0; + dia = 0; - unsigned int ww, wh, dw, dh, dia = 2 * rad; + unsigned int ww, wh, dw, dh; ww = c->geom.width - (c->decorated ? get_dec_width(c) : 0) ; wh = c->geom.height - (c->decorated ? get_dec_height(c) : 0) ; dw = c->geom.width; dh = c->geom.height; - XGCValues w_xgcv, d_xgcv; - if (ww < dia || wh < dia) return; - if (c->decorated == true) { - /* Add rounnded corners to the dec window */ - Pixmap d_mask = XCreatePixmap(display, c->dec, dw, dh, 1); - if (!d_mask) return; - - GC d_shape_gc = XCreateGC(display, d_mask, 0, &d_xgcv); - if (!d_shape_gc) { - XFreePixmap(display, d_mask); - return; - } - - XSetForeground(display, d_shape_gc, 0); - XFillRectangle(display, d_mask, d_shape_gc, 0, 0, dw, dh); - XSetForeground(display, d_shape_gc, 1); - XFillArc(display, d_mask, d_shape_gc, 0, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia-1, 0, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, 0, dh-dia-1, dia, dia, 0, 360 << 6); - XFillArc(display, d_mask, d_shape_gc, dw-dia-1, dh-dia-1, dia, dia, 0, 360 << 6); - XFillRectangle(display, d_mask, d_shape_gc, rad, 0, dw-dia, dh); - XFillRectangle(display, d_mask, d_shape_gc, 0, rad, dw, dh-dia); - XShapeCombineMask(display, c->dec, ShapeBounding, -conf.b_width, -conf.b_width, d_mask, ShapeSet); - XFreePixmap(display, d_mask); - XFreeGC(display, d_shape_gc); - } - - /* Add corners to the dec window */ - Pixmap w_mask = XCreatePixmap(display, c->window, ww, wh, 1); - if (!w_mask) return; - - GC w_shape_gc = XCreateGC(display, w_mask, 0, &w_xgcv); - if (!w_shape_gc) { - XFreePixmap(display, w_mask); - return; - } + if (c->decorated == true) + construct_mask(c->dec, -conf.b_width, -conf.b_width, dw, dh, dia); - XSetForeground(display, w_shape_gc, 0); - XFillRectangle(display, w_mask, w_shape_gc, 0, 0, ww, wh); - XSetForeground(display, w_shape_gc, 1); - XFillArc(display, w_mask, w_shape_gc, 0, 0, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, ww-dia-1, 0, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, 0, wh-dia-1, dia, dia, 0, 360 << 6); - XFillArc(display, w_mask, w_shape_gc, ww-dia-1, wh-dia-1, dia, dia, 0, 360 << 6); - XFillRectangle(display, w_mask, w_shape_gc, rad, 0, ww-dia, wh); - XFillRectangle(display, w_mask, w_shape_gc, 0, rad, ww, wh-dia); - XShapeCombineMask(display, c->window, ShapeBounding, 0, 0, w_mask, ShapeSet); - XFreePixmap(display, w_mask); - XFreeGC(display, w_shape_gc); + construct_mask(c->window, 0, 0, ww, wh, dia); } static void