xiwm

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

commit
f8a051b2ea2d9150dd34ad50bf81d21729cf852e
parent
60f496a915eec951a06992a676944a194035ed5a
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-10-13 10:15
convert sel to array

Diffstat

M xiwm.c 64 ++++++++++++++++++++++++++++++++++++-------------------------

1 files changed, 38 insertions, 26 deletions


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

@@ -110,7 +110,8 @@ static Bool running = True;
  110   110 static unsigned int desktop;
  111   111 static float mfact = 0.5;
  112   112 static Display *dpy;
  113    -1 static Client *clients, *sel;
   -1   113 static Client *clients;
   -1   114 static Client *sel[DESKTOPS];
  114   115 static Window root, wmcheckwin;
  115   116 
  116   117 void
@@ -337,13 +338,13 @@ restack(void)
  337   338 	Client *c;
  338   339 	XEvent ev;
  339   340 
  340    -1 	if (!sel)
   -1   341 	if (!sel[desktop])
  341   342 		return;
  342    -1 	if (sel->position == PLeft || sel->position == PRight)
   -1   343 	if (sel[desktop]->position == PLeft || sel[desktop]->position == PRight)
  343   344 		for (c = clients; c; c = c->next)
  344   345 			if (ISVISIBLE(c) && (c->position == PLeft || c->position == PRight))
  345   346 				XRaiseWindow(dpy, c->win);
  346    -1 	XRaiseWindow(dpy, sel->win);
   -1   347 	XRaiseWindow(dpy, sel[desktop]->win);
  347   348 	XSync(dpy, False);
  348   349 	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  349   350 }
@@ -455,10 +456,15 @@ attach(Client *c)
  455   456 void
  456   457 detach(Client *c)
  457   458 {
   -1   459 	int i;
  458   460 	Client **tc;
  459   461 
  460   462 	for (tc = &clients; *tc && *tc != c; tc = &(*tc)->next);
  461   463 	*tc = c->next;
   -1   464 
   -1   465 	for (i = 0; i < DESKTOPS; i++)
   -1   466 		if (c == sel[i])
   -1   467 			sel[i] = NULL;
  462   468 }
  463   469 
  464   470 void
@@ -466,9 +472,9 @@ focus(Client *c)
  466   472 {
  467   473 	if (!c || !ISVISIBLE(c))
  468   474 		for (c = clients; c && !ISVISIBLE(c); c = c->next);
  469    -1 	if (sel && sel != c) {
  470    -1 		grabbuttons(sel, False);
  471    -1 		XSetWindowBorder(dpy, sel->win, COL_NORM);
   -1   475 	if (sel[desktop] && sel[desktop] != c) {
   -1   476 		grabbuttons(sel[desktop], False);
   -1   477 		XSetWindowBorder(dpy, sel[desktop]->win, COL_NORM);
  472   478 	}
  473   479 	if (c) {
  474   480 		XSetWindowBorder(dpy, c->win, COL_HIGH);
@@ -480,7 +486,7 @@ focus(Client *c)
  480   486 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  481   487 		XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
  482   488 	}
  483    -1 	sel = c;
   -1   489 	sel[desktop] = c;
  484   490 	restack();
  485   491 }
  486   492 
@@ -567,7 +573,7 @@ movemouse(void)
  567   573 	Time lasttime = 0;
  568   574 	Window dummy;
  569   575 
  570    -1 	if (!(c = sel))
   -1   576 	if (!(c = sel[desktop]))
  571   577 		return;
  572   578 	if (c->isfullscreen || c->position != PFloat)
  573   579 		return;
@@ -608,7 +614,7 @@ resizemouse(void)
  608   614 	XEvent ev;
  609   615 	Time lasttime = 0;
  610   616 
  611    -1 	if (!(c = sel))
   -1   617 	if (!(c = sel[desktop]))
  612   618 		return;
  613   619 	if (c->isfullscreen || c->position != PFloat)
  614   620 		return;
@@ -675,7 +681,7 @@ clientmessage(XEvent *e)
  675   681 		|| cme->data.l[2] == netatom[NetWMFullscreen])
  676   682 			setfullscreen(c, (cme->data.l[0] == 1 || (cme->data.l[0] == 2 && !c->isfullscreen)));
  677   683 	} else if (cme->message_type == netatom[NetActiveWindow]) {
  678    -1 		if (c != sel) {
   -1   684 		if (c != sel[desktop]) {
  679   685 			setdesktop(c->desktop);
  680   686 			focus(c);
  681   687 		}
@@ -728,16 +734,19 @@ maprequest(XEvent *e)
  728   734 void
  729   735 tag(const Arg *arg)
  730   736 {
  731    -1 	if (!sel)
   -1   737 	Client *c;
   -1   738 
   -1   739 	if (!(c = sel[desktop]))
  732   740 		return;
  733    -1 	if (arg->ui >= desktops)
   -1   741 	if (arg->ui >= DESKTOPS)
  734   742 		return;
  735    -1 	if (sel->desktop == arg->ui)
   -1   743 	if (c->desktop == arg->ui)
  736   744 		return;
  737    -1 	sel->desktop = arg->ui;
  738    -1 	xsetclientdesktop(sel);
   -1   745 	sel[desktop] = NULL;
   -1   746 	c->desktop = arg->ui;
   -1   747 	xsetclientdesktop(c);
  739   748 	setdesktop(arg->ui);
  740    -1 	restack();
   -1   749 	focus(c);
  741   750 }
  742   751 
  743   752 void
@@ -766,14 +775,14 @@ focusstack(const Arg *arg)
  766   775 {
  767   776 	Client *c = NULL, *i;
  768   777 
  769    -1 	if (!sel)
   -1   778 	if (!sel[desktop])
  770   779 		return;
  771   780 	if (arg->i > 0) {
  772    -1 		for (c = sel->next; c && !ISVISIBLE(c); c = c->next);
   -1   781 		for (c = sel[desktop]->next; c && !ISVISIBLE(c); c = c->next);
  773   782 		if (!c)
  774   783 			for (c = clients; c && !ISVISIBLE(c); c = c->next);
  775   784 	} else {
  776    -1 		for (i = clients; i != sel; i = i->next)
   -1   785 		for (i = clients; i != sel[desktop]; i = i->next)
  777   786 			if (ISVISIBLE(i))
  778   787 				c = i;
  779   788 		if (!c)
@@ -788,9 +797,9 @@ focusstack(const Arg *arg)
  788   797 void
  789   798 setposition(const Arg *arg)
  790   799 {
  791    -1 	if (!sel)
   -1   800 	if (!sel[desktop])
  792   801 		return;
  793    -1 	sel->position = arg->i;
   -1   802 	sel[desktop]->position = arg->i;
  794   803 	layout();
  795   804 }
  796   805 
@@ -804,13 +813,13 @@ setmfact(const Arg *arg)
  804   813 void
  805   814 killclient(const Arg *arg)
  806   815 {
  807    -1 	if (!sel)
   -1   816 	if (!sel[desktop])
  808   817 		return;
  809    -1 	if (!sendevent(sel, wmatom[WMDelete])) {
   -1   818 	if (!sendevent(sel[desktop], wmatom[WMDelete])) {
  810   819 		XGrabServer(dpy);
  811   820 		XSetErrorHandler(xerrordummy);
  812   821 		XSetCloseDownMode(dpy, DestroyAll);
  813    -1 		XKillClient(dpy, sel->win);
   -1   822 		XKillClient(dpy, sel[desktop]->win);
  814   823 		XSync(dpy, False);
  815   824 		XSetErrorHandler(xerror);
  816   825 		XUngrabServer(dpy);
@@ -841,7 +850,7 @@ spawn(const Arg *arg)
  841   850 void
  842   851 setup(void)
  843   852 {
  844    -1 	int screen;
   -1   853 	int i, screen;
  845   854 	Atom utf8string;
  846   855 	const unsigned int desktops = DESKTOPS;
  847   856 
@@ -851,6 +860,9 @@ setup(void)
  851   860 	/* clean up any zombies immediately */
  852   861 	sigchld(0);
  853   862 
   -1   863 	for (i = 0; i < DESKTOPS; i++)
   -1   864 		sel[i] = NULL;
   -1   865 
  854   866 	/* init screen */
  855   867 	screen = DefaultScreen(dpy);
  856   868 	sw = DisplayWidth(dpy, screen);