client.c
changeset 775 920b51271fc8
parent 772 a1dd3d977e25
child 776 be103ae46dbc
--- a/client.c	Mon Feb 19 14:52:19 2007 +0100
+++ b/client.c	Mon Feb 19 14:57:32 2007 +0100
@@ -46,6 +46,21 @@
 				GrabModeAsync, GrabModeSync, None, None);
 }
 
+static Bool
+isprotodel(Client *c) {
+	int i, n;
+	Atom *protocols;
+	Bool ret = False;
+
+	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
+		for(i = 0; !ret && i < n; i++)
+			if(protocols[i] == wmatom[WMDelete])
+				ret = True;
+		XFree(protocols);
+	}
+	return ret;
+}
+
 static void
 setclientstate(Client *c, long state) {
 	long data[] = {state, None};
@@ -61,6 +76,20 @@
 /* extern */
 
 void
+attach(Client *c) {
+	if(clients)
+		clients->prev = c;
+	c->next = clients;
+	clients = c;
+}
+
+void
+attachstack(Client *c) {
+	c->snext = stack;
+	stack = c;
+}
+
+void
 configure(Client *c) {
 	XConfigureEvent ce;
 
@@ -79,6 +108,24 @@
 }
 
 void
+detach(Client *c) {
+	if(c->prev)
+		c->prev->next = c->next;
+	if(c->next)
+		c->next->prev = c->prev;
+	if(c == clients)
+		clients = c->next;
+	c->next = c->prev = NULL;
+}
+
+void
+detachstack(Client *c) {
+	Client **tc;
+	for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
+	*tc = c->snext;
+}
+
+void
 focus(Client *c) {
 	if(c && !isvisible(c))
 		return;
@@ -103,19 +150,46 @@
 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
 }
 
-Bool
-isprotodel(Client *c) {
-	int i, n;
-	Atom *protocols;
-	Bool ret = False;
+void
+focusnext(Arg *arg) {
+	Client *c;
+   
+	if(!sel)
+		return;
+	for(c = sel->next; c && !isvisible(c); c = c->next);
+	if(!c)
+		for(c = clients; c && !isvisible(c); c = c->next);
+	if(c) {
+		focus(c);
+		restack();
+	}
+}
+
+void
+focusprev(Arg *arg) {
+	Client *c;
 
-	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
-		for(i = 0; !ret && i < n; i++)
-			if(protocols[i] == wmatom[WMDelete])
-				ret = True;
-		XFree(protocols);
+	if(!sel)
+		return;
+	for(c = sel->prev; c && !isvisible(c); c = c->prev);
+	if(!c) {
+		for(c = clients; c && c->next; c = c->next);
+		for(; c && !isvisible(c); c = c->prev);
+	}
+	if(c) {
+		focus(c);
+		restack();
 	}
-	return ret;
+}
+
+Client *
+getclient(Window w) {
+	Client *c;
+
+	for(c = clients; c; c = c->next)
+		if(c->win == w)
+			return c;
+	return NULL;
 }
 
 void