foo-wm

(Archived) Experimental Zooming IPC-based WM
git clone http://milesalan.com/git/foo-wm
Log | Files | Refs | Mirror | README | LICENSE

commit f8509cdfd456e7e2a3c3d097b10f17d66a603a30
parent 3f5caafe7ddf7e0813f16eab375a262e0095dd41
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Mon, 16 Jul 2012 13:29:28 -0400

{PREVIOUS NEXT} enumuration

Diffstat:
Msrc/commands.c | 27+++++++++++++--------------
Msrc/structs.h | 2++
Msrc/tree.c | 12++++++------
3 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -51,8 +51,8 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "focus")) { if (!strcmp(tokens[1], "cycle")) { - if (!strcmp(tokens[2], "previous")) cycleFocus(0); - else if (!strcmp(tokens[2], "next")) cycleFocus(1); + if (!strcmp(tokens[2], "previous")) cycleFocus(PREVIOUS); + else if (!strcmp(tokens[2], "next")) cycleFocus(NEXT); } else if (!strcmp(tokens[1], "direction")) { if (!strcmp(tokens[2], "left")) directionFocus(0); @@ -118,14 +118,14 @@ void handleCommand(char* request) { * depending, there may be a new selectedNode & focusNode OR * just a new focusNode and no selectedNode */ void cycleFocus(int direction) { - if (direction != 0 && direction != 1) return; + if (direction != PREVIOUS && direction != NEXT) return; Node * newSelect = NULL; Node * focusOrigin = selectedNode ? selectedNode : focusedNode; Node * newFocus = NULL; //Loopback incase, //TODO: Could use focused node starting to make faster instead of focusOrigin? - if (direction == 0) { + if (direction == PREVIOUS) { if (!(newFocus = focusOrigin -> previous)) { newFocus = focusOrigin; while (newFocus -> next != NULL) @@ -161,12 +161,12 @@ void containerize() { Node * newContainer = allocateNode(); if (selectedNode != NULL) { - if (selectedNode -> previous != NULL || selectedNode -> next != NULL) { + if (selectedNode -> previous || selectedNode -> next) { Node *insertNode; int insertPosition; - if (selectedNode -> previous != NULL) { - insertNode = selectedNode -> previous; insertPosition = 1; - } else if (focusedNode -> next != NULL) { - insertNode = selectedNode -> next; insertPosition = 0; + if (selectedNode -> previous) { + insertNode = selectedNode -> previous; insertPosition = NEXT; + } else if (focusedNode -> next) { + insertNode = selectedNode -> next; insertPosition = PREVIOUS; } parentNode(selectedNode, newContainer); @@ -181,9 +181,9 @@ void containerize() { Node *insertNode; int insertPosition; fprintf(stderr, "Containerizing, using some ref brother\n"); if (focusedNode -> previous) { - insertNode = focusedNode -> previous; insertPosition = 1; + insertNode = focusedNode -> previous; insertPosition = NEXT; } else if (focusedNode -> next) { - insertNode = focusedNode -> next; insertPosition = 0; + insertNode = focusedNode -> next; insertPosition = PREVIOUS; } else { fprintf(stderr, "NO INSERT NODE\n"); } @@ -209,10 +209,9 @@ void kill() { /* Save closest client and destroy node */ Node *newFocus = getClosestClient(focusedNode); - if (focusedNode == viewNode) { viewNode = viewNode -> parent; } + if (focusedNode == viewNode) viewNode = viewNode -> parent; - if ( - focusedNode -> next == NULL && focusedNode -> previous == NULL + if ( !focusedNode -> next && !focusedNode -> previous && viewNode == focusedNode -> parent) { if (focusedNode -> parent -> parent != NULL) { fprintf(stderr, "Parent's parent exists\n"); diff --git a/src/structs.h b/src/structs.h @@ -1,6 +1,8 @@ #include <X11/Xlib.h> enum { VERTICAL, HORIZONTAL, GRID, MAX }; +enum { PREVIOUS, NEXT }; + typedef struct Node Node; struct Node { diff --git a/src/tree.c b/src/tree.c @@ -291,9 +291,9 @@ Node * getBrotherClient(Node * node, int direction) { Node *pNode = node; Node *nNode = node; - while (pNode -> previous != NULL || nNode -> next != NULL) { - if (pNode -> previous != NULL) pNode = pNode -> previous; - if (nNode -> next != NULL ) nNode = nNode -> next; + while (pNode -> previous || nNode -> next) { + if (pNode -> previous ) pNode = pNode -> previous; + if (nNode -> next ) nNode = nNode -> next; switch (direction) { case 0: if (isClient(pNode) && pNode != node) return pNode; @@ -314,10 +314,10 @@ Node * getClosestClient(Node * node) { Node * currentNode = node; /* Calls getBrotherClient going up the tree until a client is found */ - while (returnNode == NULL) { + while (!returnNode) { returnNode = getBrotherClient(currentNode, 1); - if (returnNode == NULL) { - if (currentNode -> parent != NULL) currentNode = currentNode -> parent; + if (!returnNode) { + if (currentNode -> parent) currentNode = currentNode -> parent; else return NULL; } else { //We found a client return returnNode;