xiwm

simple window manager
git clone https://git.ce9e.org/xiwm.git

commit
a77ffa14d656dec561dc10429bc8559d2b43cd34
parent
129d79fc8e988e10bc23ce88d17cdc4ea45f84e3
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-10-13 07:01
use enum for position

Diffstat

M config.def.h 10 +++++-----
M xiwm.c 36 +++++++++++++++++++-----------------

2 files changed, 24 insertions, 22 deletions


diff --git a/config.def.h b/config.def.h

@@ -11,7 +11,7 @@ static const Rule rules[] = {
   11    11 	 *	WM_CLASS(STRING) = instance, class
   12    12 	 */
   13    13 	/* class         instance    desktop   position */
   14    -1 	{ "Thunderbird", NULL,       0,        0 },
   -1    14 	{ "Thunderbird", NULL,       0,        PMax },
   15    15 };
   16    16 
   17    17 /* commands */
@@ -35,10 +35,10 @@ static Key keys[] = {
   35    35 	{ Mod1Mask|ControlMask,  XK_Left,   viewrel,      {.i = -1 } },
   36    36 	{ Mod1Mask|ShiftMask,    XK_Right,  tagrel,       {.i = +1 } },
   37    37 	{ Mod1Mask|ShiftMask,    XK_Left,   tagrel,       {.i = -1 } },
   38    -1 	{ Mod1Mask,              XK_Down,   setposition,  {.i = -1 } },
   39    -1 	{ Mod1Mask,              XK_Up,     setposition,  {.i = 0 } },
   40    -1 	{ Mod1Mask,              XK_Left,   setposition,  {.i = 1 } },
   41    -1 	{ Mod1Mask,              XK_Right,  setposition,  {.i = 2 } },
   -1    38 	{ Mod1Mask,              XK_Down,   setposition,  {.i = PFloat } },
   -1    39 	{ Mod1Mask,              XK_Up,     setposition,  {.i = PMax } },
   -1    40 	{ Mod1Mask,              XK_Left,   setposition,  {.i = PLeft } },
   -1    41 	{ Mod1Mask,              XK_Right,  setposition,  {.i = PRight } },
   42    42 };
   43    43 
   44    44 /* button definitions */

diff --git a/xiwm.c b/xiwm.c

@@ -28,6 +28,7 @@ enum { NetSupported, NetWMName, NetWMDesktop, NetWMState, NetWMCheck,
   28    28        NetWMWindowTypeDialog, NetWMWindowTypeDock,
   29    29        NetClientList, NetCurrentDesktop, NetLast }; /* EWMH atoms */
   30    30 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
   -1    31 typedef enum { PFloat, PMax, PLeft, PRight } Position;
   31    32 
   32    33 typedef union {
   33    34 	int i;
@@ -48,7 +49,7 @@ struct Client {
   48    49 	int x, y, w, h;
   49    50 	int fx, fy, fw, fh;
   50    51 	unsigned int desktop;
   51    -1 	int position;
   -1    52 	Position position;
   52    53 	Bool isfixed, isfullscreen, isdock;
   53    54 	Client *next;
   54    55 	Window win;
@@ -65,7 +66,7 @@ typedef struct {
   65    66 	const char *class;
   66    67 	const char *instance;
   67    68 	unsigned int desktop;
   68    -1 	int position;
   -1    69 	Position position;
   69    70 } Rule;
   70    71 
   71    72 /* actions */
@@ -312,7 +313,7 @@ resize(Client *c, int x, int y, int w, int h, int bw)
  312   313 	c->y = wc.y = y;
  313   314 	c->w = wc.width = w;
  314   315 	c->h = wc.height = h;
  315    -1 	if (c->position < 0 && !c->isfullscreen) {
   -1   316 	if (c->position == PFloat && !c->isfullscreen) {
  316   317 		c->fx = c->x;
  317   318 		c->fy = c->y;
  318   319 		c->fw = c->w;
@@ -325,7 +326,7 @@ resize(Client *c, int x, int y, int w, int h, int bw)
  325   326 }
  326   327 
  327   328 void
  328    -1 layoutcolumn(int pos, int x, int w)
   -1   329 layoutcolumn(Position pos, int x, int w)
  329   330 {
  330   331 	Client *c;
  331   332 	unsigned int n = 0;
@@ -355,14 +356,14 @@ layout(void)
  355   356 			XMoveWindow(dpy, c->win, sw * -2, c->y);
  356   357 		else if (c->isfullscreen)
  357   358 			resize(c, 0, 0, sw, sh, 0);
  358    -1 		else if (c->position < 0)
   -1   359 		else if (c->position == PFloat)
  359   360 			resize(c, c->fx, c->fy, c->fw, c->fh, 1);
  360    -1 		else if (c->position == 0)
   -1   361 		else if (c->position == PMax)
  361   362 			resize(c, 0, bh, sw, sh - bh, 0);
  362   363 	}
  363   364 
  364    -1 	layoutcolumn(1, 0, sw * mfact);
  365    -1 	layoutcolumn(2, sw * mfact, sw - sw * mfact);
   -1   365 	layoutcolumn(PLeft, 0, sw * mfact);
   -1   366 	layoutcolumn(PRight, sw * mfact, sw - sw * mfact);
  366   367 }
  367   368 
  368   369 void
@@ -373,9 +374,9 @@ restack(void)
  373   374 
  374   375 	if (!sel)
  375   376 		return;
  376    -1 	if (sel->position > 0)
   -1   377 	if (sel->position == PLeft || sel->position == PRight)
  377   378 		for (c = clients; c; c = c->next)
  378    -1 			if (ISVISIBLE(c) && c->position > 0)
   -1   379 			if (ISVISIBLE(c) && (c->position == PLeft || c->position == PRight))
  379   380 				XRaiseWindow(dpy, c->win);
  380   381 	XRaiseWindow(dpy, sel->win);
  381   382 	XSync(dpy, False);
@@ -442,7 +443,7 @@ updatewindowtype(Client *c)
  442   443 	if (state == netatom[NetWMFullscreen])
  443   444 		setfullscreen(c, True);
  444   445 	if (wtype == netatom[NetWMWindowTypeDialog])
  445    -1 		c->position = -1;
   -1   446 		c->position = PFloat;
  446   447 	if (wtype == netatom[NetWMWindowTypeDock])
  447   448 		c->isdock = True;
  448   449 }
@@ -530,6 +531,7 @@ manage(Window w, XWindowAttributes *wa)
  530   531 
  531   532 	c = calloc(1, sizeof(Client));
  532   533 	c->win = w;
   -1   534 	c->position = PMax;
  533   535 	/* geometry */
  534   536 	c->fx = c->x = wa->x == 0 ? (sw - wa->width) / 2 : wa->x;
  535   537 	c->fy = c->y = wa->y == 0 ? (sh - wa->height) / 2 : wa->y;
@@ -550,8 +552,8 @@ manage(Window w, XWindowAttributes *wa)
  550   552 	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
  551   553 	grabbuttons(c, False);
  552   554 	if (trans != None || c->isfixed)
  553    -1 		c->position = -1;
  554    -1 	if (c->position < 0)
   -1   555 		c->position = PFloat;
   -1   556 	if (c->position == PFloat)
  555   557 		XRaiseWindow(dpy, c->win);
  556   558 	attach(c);
  557   559 	XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32,
@@ -863,7 +865,7 @@ movemouse(const Arg *arg)
  863   865 
  864   866 	if (!(c = sel))
  865   867 		return;
  866    -1 	if (c->isfullscreen || c->position >= 0)
   -1   868 	if (c->isfullscreen || c->position != PFloat)
  867   869 		return;
  868   870 	restack();
  869   871 	ocx = c->x;
@@ -887,7 +889,7 @@ movemouse(const Arg *arg)
  887   889 
  888   890 			nx = ocx + (ev.xmotion.x - x);
  889   891 			ny = ocy + (ev.xmotion.y - y);
  890    -1 			if (c->position < 0)
   -1   892 			if (c->position == PFloat)
  891   893 				resize(c, nx, ny, c->w, c->h, 1);
  892   894 			break;
  893   895 		}
@@ -905,7 +907,7 @@ resizemouse(const Arg *arg)
  905   907 
  906   908 	if (!(c = sel))
  907   909 		return;
  908    -1 	if (c->isfullscreen || c->position >= 0)
   -1   910 	if (c->isfullscreen || c->position != PFloat)
  909   911 		return;
  910   912 	restack();
  911   913 	ocx = c->x;
@@ -928,7 +930,7 @@ resizemouse(const Arg *arg)
  928   930 
  929   931 			nw = MAX(ev.xmotion.x - ocx - 1, 1);
  930   932 			nh = MAX(ev.xmotion.y - ocy - 1, 1);
  931    -1 			if (c->position < 0)
   -1   933 			if (c->position == PFloat)
  932   934 				resize(c, c->x, c->y, nw, nh, 1);
  933   935 			break;
  934   936 		}