foo-wm

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

commit fe40164cf0bf8df7a9207018d54e217222afa57d
parent 5a1ef3c1f4b0a7ac4ea50c70a44d506241334482
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Mon, 16 Jul 2012 12:35:00 -0400

Rework of cycleFocus handle containers
cycleFocus previous works on Selected Containers as well

Diffstat:
Msrc/commands.c | 66+++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Msrc/events.c | 2+-
Msrc/tree.c | 12+++++-------
3 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -27,7 +27,7 @@ void handleCommand(char* request) { char *tokens[5]; char *token; int i = 0; - while ((token = nextToken(&request)) != NULL) { + while ((token = nextToken(&request))) { tokens[i] = token; i++; } @@ -64,14 +64,12 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "select")) { if (!strcmp(tokens[1], "parent")) { fprintf(stderr, "Selecting parent node\n"); - if (selectedNode == NULL) { + if (!selectedNode) { fprintf(stderr, "Selected Node is NULL\n"); selectNode(focusedNode -> parent, True); - } else { - if (selectedNode -> parent != NULL) { + } else if (selectedNode -> parent) { fprintf(stderr, "Selecting from Parent\n"); selectNode(selectedNode -> parent, True); - } } } else if (!strcmp(tokens[1], "next")) { @@ -86,7 +84,7 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "view")) { if (!strcmp(tokens[1], "parent")) { - if (viewNode -> parent != NULL) { + if (viewNode -> parent) { unmapNode(viewNode); viewNode = viewNode -> parent; placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); @@ -94,10 +92,10 @@ void handleCommand(char* request) { } } else if (!strcmp(tokens[1], "child")) { - if (focusedNode != viewNode) { Node *n = focusedNode; - while (n -> parent != viewNode && n != NULL) { n = n -> parent; } + while (n && n -> parent != viewNode) n = n -> parent; + if (!n) return; unmapNode(viewNode); viewNode = n; @@ -128,28 +126,63 @@ Node * getClient (Node *start, int direction) { return n; } +/* void cycleFocus(int direction) { Node *next = NULL; Node *loopback = NULL; + if (direction == 0) { next = getClient(focusedNode, 0); if (!isClient(next)) { loopback = focusedNode; while (loopback -> next != NULL) loopback = loopback-> next; - if (isClient(loopback)) next = loopback; - else next = getClient(loopback, 0); + next = isClient(loopback) ? loopback : getClient(loopback, 0); } } else if (direction == 1) { next = getClient(focusedNode, 1); if (!isClient(next)) { loopback = focusedNode -> parent -> child; - if (isClient(loopback)) next = loopback; - else next = getClient(loopback, 1); + next = (isClient(loopback)) ? loopback : getClient(loopback, 1); + } + } + if (next) focusNode(next, NULL); +} +*/ + +/* If there is a selectedNode, updates focus + * depending, there may be a new selectedNode & focusNode OR + * just a new focusNode and no selectedNode */ +void cycleFocus(int direction) { + Node * newSelect = NULL; + Node * newFocus = NULL; + Node * focusOrigin = selectedNode ? selectedNode : focusedNode; + + + if (direction == 0) { + //Alright we have a prvious, now figure out focus & select + //First time around and were selecting a container! + //Loop to find client to focus to + if ((newFocus = focusOrigin -> previous)) { + if (!isClient(newFocus)) newSelect = newFocus; + while (!isClient(newFocus)) + newFocus = (newFocus -> focus) ? + newFocus -> focus : newFocus -> child; + + //End of the linked list, will need a loopback + } else { + } + + + fprintf(stderr, "The New Select is %p\nThe new focus is %p\n", newSelect, newFocus); + + focusNode(newFocus, NULL); + selectNode(newSelect, True); } - focusNode(next, NULL); + } + void directionFocus(int direction) { } @@ -174,12 +207,12 @@ void containerize() { } else if (focusedNode != NULL) { /* Working iwth a focused Client */ /* Containerizing a client that is one of many in an existing container */ - if (focusedNode -> previous != NULL || focusedNode -> next != NULL) { + if (focusedNode -> previous || focusedNode -> next) { Node *insertNode; int insertPosition; fprintf(stderr, "Containerizing, using some ref brother\n"); - if (focusedNode -> previous != NULL) { + if (focusedNode -> previous) { insertNode = focusedNode -> previous; insertPosition = 1; - } else if (focusedNode -> next != NULL) { + } else if (focusedNode -> next) { insertNode = focusedNode -> next; insertPosition = 0; } else { fprintf(stderr, "NO INSERT NODE\n"); @@ -187,7 +220,6 @@ void containerize() { parentNode(focusedNode, newContainer); brotherNode(newContainer, insertNode, insertPosition); - placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); } else { /* Containerizing client that is alone in container */ diff --git a/src/events.c b/src/events.c @@ -89,7 +89,7 @@ void eConfigureRequest(XEvent *e) { XConfigureRequestEvent *ev = &e->xconfigurerequest; Node *configuredNode = getNodeByWindow(&ev->window); - if (configuredNode == NULL) return; + if (!configuredNode) return; XWindowChanges wc; wc.x = configuredNode -> x; diff --git a/src/tree.c b/src/tree.c @@ -49,7 +49,7 @@ void dumpTree() { //Will only work on nodes with windows for now void focusNode(Node * n, XEvent * event) { - if (focusedNode == n) return; + if (!n || focusedNode == n) return; if (!isClient(n)) { fprintf(stderr, "Trying to focus a node thats not a client !\n"); return; @@ -93,17 +93,15 @@ void focusNode(Node * n, XEvent * event) { } void selectNode(Node * n, Bool setSelected) { + if (!n || selectedNode == n) return; if (setSelected == True) selectedNode = n; Node *i; - for (i = n -> child; i != NULL; i = i -> next) { - if (isClient(i) == True) { - fprintf(stderr, "Node %p", n); + for (i = n -> child; i != NULL; i = i -> next) + if (isClient(i) == True) XSetWindowBorder(display, i->window, focusedColor); - } else { + else selectNode(i, False); - } - } }