Browse Source

Added padding support

Dmitry Yu Okunev 5 years ago
parent
commit
f130a46401
2 changed files with 42 additions and 9 deletions
  1. 6 1
      config.h
  2. 36 8
      dwm.c

+ 6 - 1
config.h

@@ -13,6 +13,7 @@ static const char selbgcolor[]      = "#440000";
 static const char selfgcolor[]      = "#ffff00";
 static const unsigned int borderpx  = 1;        /* border pixel of windows */
 static const unsigned int snap      = 8;        /* snap pixel */
+static unsigned int padding         = 0;
 static const Bool showbar           = True;     /* False means no bar */
 static const Bool topbar            = True;     /* False means bottom bar */
 static unsigned char systray_spacing= 16;
@@ -59,7 +60,7 @@ static const Layout layouts[] = {
 static const char *dmenucmd[] = { "_dwm_menu.sh", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
 static const char *termcmd[]  = { "xterm", NULL };
 static const char *xwwwbrowserselcmd[] = { "x-www-browser-xsel", NULL };
-static const char *itscmd[]  			= { "redmine.sh", NULL };
+//static const char *itscmd[]  			= { "redmine.sh", NULL };
 static const char *itsissueselcmd[] 		= { "redmine-issue-sel.sh", NULL };
 static const char *itsissuedelselcmd[]  	= { "redmine-issue-del-sel.sh", NULL };
 static const char *itsissuedelselconfirmcmd[] 	= { "redmine-issue-del-sel.sh", "confirm", NULL };
@@ -71,6 +72,7 @@ static const char *mpvForwardCmd[] 		= { "_dwm_mpv_forward.sh", NULL };
 static const char *mpvBackwardCmd[] 		= { "_dwm_mpv_backward.sh", NULL };
 static const char *layoutEn[] 			= { "xkblayout-state", "set", "0", NULL };
 static const char *layoutRu[] 			= { "xkblayout-state", "set", "1", NULL };
+static const char *keyboardChangeColor[] 	= { "/usr/local/bin/_keyboard_randomFromCycle_color.sh", NULL };
 //static const char *xk_XF86WebCam_cmd[] 		= { "XF86WebCam.sh", NULL };
 
 static Key keys[] = {
@@ -124,6 +126,9 @@ static Key keys[] = {
 	{ 0,				XKB_KEY_XF86AudioPlay, spawn,   {.v = mpvPlayPauseCmd} },
 	{ 0,				XKB_KEY_XF86AudioRaiseVolume, spawn, {.v = mpvForwardCmd} },
 	{ 0,				XKB_KEY_XF86AudioLowerVolume, spawn, {.v = mpvBackwardCmd} },
+	{ 0,				XKB_KEY_XF86Launch0, spawn, {.v = keyboardChangeColor} },
+	{ MODKEY|ControlMask,		XK_bracketright, paddingAdd, {.i = +1 } },
+	{ MODKEY|ControlMask,		XK_bracketleft,  paddingAdd, {.i = -1 } },
 };
 
 /* button definitions */

+ 36 - 8
dwm.c

@@ -200,6 +200,7 @@ static void focus(Client *c);
 static void focusin(XEvent *e);
 static void focusmon(const Arg *arg);
 static void focusstack(const Arg *arg);
+static void paddingAdd(const Arg *arg);
 static unsigned long getcolor(const char *colstr);
 static Bool getrootptr(int *x, int *y);
 static long getstate(Window w);
@@ -581,6 +582,14 @@ configure(Client *c) {
 	ce.border_width = c->bw;
 	ce.above = None;
 	ce.override_redirect = False;
+
+	if (c->w > padding*4 && c->h > padding*4) {
+		ce.x = c->x + padding;
+		ce.y = c->y + padding;
+		ce.width = c->w - padding*2;
+		ce.height = c->h - padding*2;
+	}
+
 	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
 }
 
@@ -631,7 +640,7 @@ configurerequest(XEvent *e) {
 			if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
 				configure(c);
 			if(ISVISIBLE(c))
-				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+				XMoveResizeWindow(dpy, c->win, c->x + padding, c->y + padding, c->w - padding*2, c->h - padding*2);
 		}
 		else
 			configure(c);
@@ -943,6 +952,13 @@ focusstack(const Arg *arg) {
 	}
 }
 
+void paddingAdd(const Arg *arg) {
+	padding += arg->i;
+	if (padding < 0) padding = 0;
+	printf("New padding is: %i\n", padding);
+	arrange(NULL);
+}
+
 unsigned long
 getcolor(const char *colstr) {
 	Colormap cmap = DefaultColormap(dpy, screen);
@@ -1218,7 +1234,7 @@ manage(Window w, XWindowAttributes *wa) {
 		XLowerWindow(dpy, c->win);
 	attach(c);
 	attachstack(c);
-	XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
+	XMoveResizeWindow(dpy, c->win, c->x + 2 * sw + padding, c->y + padding, c->w - padding*2, c->h - padding*2); /* some windows require this */
 	XMapWindow(dpy, c->win);
 	setclientstate(c, NormalState);
 	arrange(c->mon);
@@ -1422,10 +1438,22 @@ void
 resizeclient(Client *c, int x, int y, int w, int h) {
 	XWindowChanges wc;
 
-	c->oldx = c->x; c->x = wc.x = x;
-	c->oldy = c->y; c->y = wc.y = y;
-	c->oldw = c->w; c->w = wc.width = w;
-	c->oldh = c->h; c->h = wc.height = h;
+	c->oldx = c->x; c->x = x;
+	c->oldy = c->y; c->y = y;
+	c->oldw = c->w; c->w = w;
+	c->oldh = c->h; c->h = h;
+
+	if (w > padding*4 && h > padding*4) {
+		x += padding;
+		y += padding;
+		w -= padding*2;
+		h -= padding*2;
+	}
+
+	wc.x = x;
+	wc.y = y;
+	wc.width = w;
+	wc.height = h;
 	wc.border_width = c->bw;
 	XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
 	configure(c);
@@ -1662,14 +1690,14 @@ showhide(Client *c) {
 		return;
 	}
 	if(ISVISIBLE(c)) { /* show clients top down */
-		XMoveWindow(dpy, c->win, c->x, c->y);
+		XMoveWindow(dpy, c->win, c->x + padding, c->y + padding);
 		if(!c->mon->lt[c->mon->sellt]->arrange || c->isfloating)
 			resize(c, c->x, c->y, c->w, c->h, False);
 		showhide(c->snext);
 	}
 	else { /* hide clients bottom up */
 		showhide(c->snext);
-		XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+		XMoveWindow(dpy, c->win, c->x + 2 * sw + padding, c->y + padding);
 	}
 }