summaryrefslogtreecommitdiff
path: root/dwm-centerwindow.diff
blob: 06f8f3b7494522fb5d440dbae2edaab313d460bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
diff --git a/config.def.h b/config.def.h
index 1c0b587..fe14e10 100644
--- a/config.def.h
+++ b/config.def.h
@@ -71,6 +71,7 @@ static Key keys[] = {
 	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
 	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
 	{ MODKEY,                       XK_Return, zoom,           {0} },
+	{ MODKEY,                       XK_g,      center,         {0} },
 	{ MODKEY,                       XK_Tab,    view,           {0} },
 	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
 	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
diff --git a/dwm.c b/dwm.c
index 4465af1..15eadc2 100644
--- a/dwm.c
+++ b/dwm.c
@@ -149,6 +149,7 @@ static void arrangemon(Monitor *m);
 static void attach(Client *c);
 static void attachstack(Client *c);
 static void buttonpress(XEvent *e);
+static void center(const Arg *unused);
 static void checkotherwm(void);
 static void cleanup(void);
 static void cleanupmon(Monitor *mon);
@@ -455,6 +456,23 @@ buttonpress(XEvent *e)
 			buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
 }
 
+void
+center(const Arg *unused)
+{
+	Client *c;
+
+	if (selmon->lt[selmon->sellt]->arrange && !(selmon->sel && selmon->sel->isfloating))
+		return;
+
+	c = selmon->sel;
+
+	resizeclient(c,
+	             selmon->wx + (selmon->ww / 2 - WIDTH(c) / 2),
+	             selmon->wy + (selmon->wh / 2 - HEIGHT(c) / 2),
+	             c->w,
+	             c->h);
+}
+
 void
 checkotherwm(void)
 {