Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

berrywm: rounded corners #145

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 },
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define BORDER_WIDTH 3
#define INTERNAL_BORDER_WIDTH 3
#define TITLE_HEIGHT 30
#define BORDER_RADIUS 0

#define MOVE_STEP 40
#define RESIZE_STEP 40
Expand Down
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's likely we will need to coordinate with package maintainers for this new dependency (unless its already included elsewhere, I will double check this).

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=""

Expand Down
1 change: 1 addition & 0 deletions ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum IPCCommand
IPCPointerInterval,
IPCFocusFollowsPointer,
IPCWarpPointer,
IPCBorderRadius,
IPCLast
};

Expand Down
2 changes: 1 addition & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 63 additions & 1 deletion wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ 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);
static void grab_buttons(void);
Expand Down Expand Up @@ -506,6 +508,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) {
Expand All @@ -525,7 +528,6 @@ client_fullscreen(struct client *c, bool toggle, bool fullscreen, bool max)
c->was_fs = false;
client_refresh(c);
}

client_set_status(c);
}

Expand Down Expand Up @@ -1177,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;
}
Expand Down Expand Up @@ -1303,6 +1308,58 @@ 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 dia = conf.border_radius << 1;

if (c->fullscreen)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this behavior, we might want to consider doing this for monocled windows as well? I'm open to either behavior for monocled windows actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should monocole view have it's corners rounded?

dia = 0;

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;

if (ww < dia || wh < dia)
return;

if (c->decorated == true)
construct_mask(c->dec, -conf.b_width, -conf.b_width, dw, dh, dia);

construct_mask(c->window, 0, 0, ww, wh, dia);
}

static void
manage_new_window(Window w, XWindowAttributes *wa)
{
Expand Down Expand Up @@ -1389,6 +1446,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
Expand Down Expand Up @@ -1465,6 +1524,7 @@ client_move_absolute(struct client *c, int x, int y)
c->mono = false;

client_set_status(c);
round_window_corners(c);
}

static void
Expand Down Expand Up @@ -1792,6 +1852,7 @@ client_resize_absolute(struct client *c, int w, int h)
if (c->mono)
c->mono = false;
client_set_status(c);
round_window_corners(c);
}

static void
Expand Down Expand Up @@ -1952,6 +2013,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;
Expand Down