foo-wm

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

commit 698000037ff1898b62bd6a6b502f4732889a8064
parent a810137e08f5b1a603a17d6cbd0927a4b448e60e
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Sat, 14 Jul 2012 01:56:57 -0400

cycleFocus for cycle clients within containers

Diffstat:
Msrc/commands.c | 91++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/tree.c | 26++++++++++++++++----------
2 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -50,10 +50,16 @@ void handleCommand(char* request) { (focusedNode -> parent) -> width, (focusedNode -> parent) -> height); } else if (!strcmp(tokens[0], "focus")) { - if (!strcmp(tokens[1], "left")) focus(0); - else if (!strcmp(tokens[1], "up")) focus(1); - else if (!strcmp(tokens[1], "right")) focus(2); - else if (!strcmp(tokens[1], "down")) focus(3); + if (!strcmp(tokens[1], "cycle")) { + if (!strcmp(tokens[2], "previous")) cycleFocus(0); + else if (!strcmp(tokens[2], "next")) cycleFocus(1); + + } else if (!strcmp(tokens[1], "direction")) { + if (!strcmp(tokens[2], "left")) directionFocus(0); + else if (!strcmp(tokens[2], "up")) directionFocus(1); + else if (!strcmp(tokens[2], "right")) directionFocus(2); + else if (!strcmp(tokens[2], "down")) directionFocus(3); + } } else if (!strcmp(tokens[0], "select")) { if (!strcmp(tokens[1], "parent")) { @@ -110,49 +116,48 @@ void handleCommand(char* request) { } } +/* Gets the brother client in given direction + * Does not loop */ +Node * getClient (Node *start, int direction) { + Node *n = (direction == 0) ? start -> previous : start -> next; + while (n != NULL) { + if (isClient(n)) return n; -void focus(int direction) { - /* - //Direction: 0 - Left, 1 - Up, 2 - Right, 3 - Down - switch (focusedNode -> parent -> layout) { - - //Vertical Container - case 0: - switch (direction) { - case 0: //Get client from parent to the left - - break; - case 1: //Get the client upward - break; + if (direction == 0) { + if (n -> previous == NULL) return NULL; + else n = n -> previous; - case 2: //Get client from parent to the right - break; - - case 3: //Get client downward - break; + } else if (direction == 1) { + if (n -> next == NULL) return NULL; + else n = n -> next; + } } + return n; +} - break; - - //Horizontal Container - case 1: - switch (direction) { - case 0: //Get client to the left - break; - - case 1: //Get client from container upwards - break; - - case 2: //Get client to the right - break; +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); + } + } 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); + } + } - case 3: //Get client from container dowwards + focusNode(next); +} - break; - } - break; - } - */ +void directionFocus(int direction) { } void containerize() { @@ -234,7 +239,3 @@ void kill() { viewNode -> width, viewNode -> height); } } - - - - diff --git a/src/tree.c b/src/tree.c @@ -67,7 +67,14 @@ void focusNode(Node * n) { //Set the Focused Node and selectedNode = NULL; focusedNode = n; - if (focusedNode -> parent != NULL) focusedNode -> parent -> focus = focusedNode; + if (focusedNode -> parent != NULL) { + focusedNode -> parent -> focus = focusedNode; + if (focusedNode -> parent -> layout == MAX) + placeNode(focusedNode -> parent, + focusedNode -> parent -> x, focusedNode -> parent -> y, + focusedNode -> parent -> width, focusedNode -> parent -> height); + } + // Set the Input focus, and ungrab the window (no longer point to click XSetInputFocus(display, n -> window, RevertToParent, CurrentTime); @@ -155,7 +162,7 @@ void brotherNode(Node *node, Node * brother, int position) { if (position == 0) { node -> next = brother; - if (brother -> previous == NULL) { //Pop in the front + if (!brother -> previous) { //Pop in the front node -> parent -> child = node; } else { //Shift previous pointer @@ -173,20 +180,19 @@ void brotherNode(Node *node, Node * brother, int position) { void parentNode(Node *node, Node *parent) { fprintf(stderr, "Pareting node %p into parent %p\n", node, parent); - if (parent == NULL) { return; } //Cant add to NULL - fprintf(stderr, "Made it here\n"); + if (!parent) return; //Cant add to NULL unparentNode(node); //Unparent then set the parent to new parent node -> parent = parent; //Find last in children of parent, add to end - if (parent -> child == NULL) { - parent -> child = node; - } else { + if (parent -> child) { Node *n = parent -> child; - while (n -> next != NULL) { n = n -> next; } + while (n -> next != NULL) n = n -> next; node -> previous = n; n -> next = node; + } else { + parent -> child = node; } } @@ -232,7 +238,7 @@ void placeNode(Node * node, int x, int y, int width, int height) { case VERTICAL : cols = children; rows = 1; break; case HORIZONTAL: cols = 1; rows = children; break; case GRID : gridDimensions(children, &rows, &cols); break; - case MAX: cols = 1; rows = 1; break; + case MAX : cols = 1; rows = 1; break; } Bool callPlace; @@ -247,7 +253,7 @@ void placeNode(Node * node, int x, int y, int width, int height) { else callPlace = False; } - if (callPlace != False) { + if (callPlace) { a -> x = x + (i % cols) * (width/cols) + pad; a -> y = y + ((int)(i / cols)) * (height/rows) + pad; a -> width = width / cols - (pad * 2);