foo-wm

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

commit c15aa46cd4562cf132a2188b078c6792ec413f22
parent 8d850e245a39a7ad39e991434a3b43acb6a5627a
Author: = <miles.sandlar@gmail.com>
Date:   Tue, 21 Aug 2012 12:45:20 -0400

More organization

Diffstat:
Msrc/commands.c | 224+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/commands.h | 14+++++++-------
2 files changed, 124 insertions(+), 114 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -6,18 +6,9 @@ #include "tree.h" #include "util.h" -/* Extracts the next token from the tokenString */ -char * nextToken(char ** tokenString) { - char *command; - command = strsep(tokenString, " "); - if (!command) return NULL; - - char *newLine = strchr(command, '\n'); - if (newLine) *newLine = '\0'; - - return command; -} - +/* ----------------------------------------------------------------------------- + * Handeling Commands + * ---------------------------------------------------------------------------*/ char * handleCommand(char * request) { fprintf(stderr, "Recv from Socket: %s", request); @@ -51,93 +42,44 @@ char * handleCommand(char * request) { return response; } -void layout(char * l) { - fprintf(stderr, "Setting layout to: %s", l); - - Node *setNode = isClient(focusedNode) ? focusedNode -> parent : focusedNode; - int newLayout = 0; - - if (!strcmp(l, "vertical")) newLayout = VERTICAL; - else if (!strcmp(l, "horizontal")) newLayout = HORIZONTAL; - else if (!strcmp(l, "grid")) newLayout = GRID; - else if (!strcmp(l, "max")) newLayout = MAX; - else if (!strcmp(l, "float")) newLayout = FLOAT; - - setNode -> layout = newLayout; - placeNode(setNode, - setNode -> x, setNode -> y, setNode -> width, setNode -> height); -} +/* Extracts the next token from the tokenString */ +char * nextToken(char ** tokenString) { + char *command; + command = strsep(tokenString, " "); + if (!command) return NULL; -//Moves the current selection given amount -void move(int amount) { - Node *swapNode = getBrother(focusedNode, amount); + char *newLine = strchr(command, '\n'); + if (newLine) *newLine = '\0'; - swapNodes(focusedNode, swapNode); - focusNode(focusedNode, NULL, True, True); + return command; } -/* Adds the current viewNode as a mark */ -void mark(char * markName) { - - Mark *m = malloc(sizeof(Mark)); - m -> name = malloc(sizeof(markName)); - strcpy(m -> name, markName); - m -> node = viewNode; - m -> previous = markTail; - markTail = m; - - fprintf(stderr, "\nAdded the mark:: %s // %s\n", markName, markTail -> name); -} - -void jump(char * markName) { - fprintf(stderr, "Finding a node"); - - Mark *n = NULL; - for(n = markTail; n; n = n -> previous) { - if (!strcmp(n -> name, markName)) { - fprintf(stderr, "Going to focus mark %p", n -> node); - unmapNode(viewNode); - viewNode = n -> node; - placeNode(n -> node, rootX, rootY, rootWidth, rootHeight); - focusNode(n -> node, NULL, True, True); - while (!isClient(focusedNode)) focus("pc", "1"); - } - } -} +/* ----------------------------------------------------------------------------- + * IPC Commands + * ---------------------------------------------------------------------------*/ +void containerize(void) { + if (!focusedNode) return; + if (focusedNode -> child && !isClient(focusedNode -> child)) + if (isOnlyChild(focusedNode -> child)) return; + Node *insertNode, *newContainer = allocateNode(); int insertPosition; + if (focusedNode -> parent && focusedNode -> parent -> focus == focusedNode) + focusedNode -> parent -> focus = newContainer; -/* Updates the viewNode approximating the current focusNode */ -void zoom(int level) { - while (level < 0) { - if (viewNode -> parent) { - unmapNode(viewNode); - viewNode = viewNode -> parent; - } else { return; } - placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); - focusNode(focusedNode, NULL, True, True); - level++; + if (focusedNode -> previous) { + insertNode = focusedNode -> previous; insertPosition = NEXT; + } else { + insertNode = focusedNode -> next; insertPosition = PREVIOUS; } - while (level > 0) { - if (focusedNode == viewNode) return; - Node *n = focusedNode; - while (n && n -> parent != viewNode) n = n -> parent; - if (!n) return; - unmapNode(viewNode); - viewNode = n; - //TODO:: Need placeNode to be aware of focusnnode (in)active colors.... - - fprintf(stderr, "placeing yo"); - placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); - if (focusedNode == viewNode && !isClient(focusedNode)) { - focusNode(focusOrChildOf(focusedNode), NULL, True, True); - } - level--; - } + parentNode(focusedNode, newContainer); + brotherNode(newContainer, insertNode, insertPosition); + placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); } + void focus(char * argA, char * argB) { int delta = atoi(argB); @@ -165,26 +107,6 @@ void focus(char * argA, char * argB) { } -void containerize(void) { - if (!focusedNode) return; - if (focusedNode -> child && !isClient(focusedNode -> child)) - if (isOnlyChild(focusedNode -> child)) return; - - Node *insertNode, *newContainer = allocateNode(); int insertPosition; - if (focusedNode -> parent && focusedNode -> parent -> focus == focusedNode) - focusedNode -> parent -> focus = newContainer; - - if (focusedNode -> previous) { - insertNode = focusedNode -> previous; insertPosition = NEXT; - } else { - insertNode = focusedNode -> next; insertPosition = PREVIOUS; - } - - parentNode(focusedNode, newContainer); - brotherNode(newContainer, insertNode, insertPosition); - placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); -} - void kill(void) { dumpTree(); fprintf(stderr, "Destroying Client %p\n", focusedNode); @@ -211,3 +133,91 @@ void kill(void) { } } +void jump(char * markName) { + fprintf(stderr, "Finding a node"); + + Mark *n = NULL; + for(n = markTail; n; n = n -> previous) { + if (!strcmp(n -> name, markName)) { + fprintf(stderr, "Going to focus mark %p", n -> node); + unmapNode(viewNode); + viewNode = n -> node; + placeNode(n -> node, rootX, rootY, rootWidth, rootHeight); + focusNode(n -> node, NULL, True, True); + while (!isClient(focusedNode)) focus("pc", "1"); + } + } +} + + +void layout(char * l) { + fprintf(stderr, "Setting layout to: %s", l); + + Node *setNode = isClient(focusedNode) ? focusedNode -> parent : focusedNode; + int newLayout = 0; + + if (!strcmp(l, "vertical")) newLayout = VERTICAL; + else if (!strcmp(l, "horizontal")) newLayout = HORIZONTAL; + else if (!strcmp(l, "grid")) newLayout = GRID; + else if (!strcmp(l, "max")) newLayout = MAX; + else if (!strcmp(l, "float")) newLayout = FLOAT; + + + setNode -> layout = newLayout; + placeNode(setNode, + setNode -> x, setNode -> y, setNode -> width, setNode -> height); +} + + +/* Adds the current viewNode as a mark */ +void mark(char * markName) { + + Mark *m = malloc(sizeof(Mark)); + m -> name = malloc(sizeof(markName)); + strcpy(m -> name, markName); + m -> node = viewNode; + m -> previous = markTail; + markTail = m; + + fprintf(stderr, "\nAdded the mark:: %s // %s\n", markName, markTail -> name); +} + + +//Moves the current selection given amount +void move(int amount) { + Node *swapNode = getBrother(focusedNode, amount); + + swapNodes(focusedNode, swapNode); + focusNode(focusedNode, NULL, True, True); +} + + +/* Updates the viewNode approximating the current focusNode */ +void zoom(int level) { + while (level < 0) { + if (viewNode -> parent) { + unmapNode(viewNode); + viewNode = viewNode -> parent; + } else { return; } + placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); + focusNode(focusedNode, NULL, True, True); + level++; + } + while (level > 0) { + if (focusedNode == viewNode) return; + Node *n = focusedNode; + while (n && n -> parent != viewNode) n = n -> parent; + if (!n) return; + + unmapNode(viewNode); + viewNode = n; + //TODO:: Need placeNode to be aware of focusnnode (in)active colors.... + + fprintf(stderr, "placeing yo"); + placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); + if (focusedNode == viewNode && !isClient(focusedNode)) { + focusNode(focusOrChildOf(focusedNode), NULL, True, True); + } + level--; + } +} diff --git a/src/commands.h b/src/commands.h @@ -1,11 +1,11 @@ -char * nextToken(char ** tokenString); char * handleCommand(char * request); -void move(int amount); -void shift(char * directionString); -void mark(char * markName); +char * nextToken(char ** tokenString); + +void containerize(void); +void focus(char * argA, char * argB); +void kill(void); void jump(char * markName); void layout(char * l); +void mark(char * markName); +void move(int amount); void zoom(int level); -void focus(char * argA, char * argB); -void containerize(void); -void kill(void);