foo-wm

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

commit 9fc7a7ddcfdf1d2bfc9e43461a863428002e56f8
parent 953898272ac7e58da3c8bd192dec3319964d0271
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Fri,  6 Jul 2012 18:21:51 -0400

Added brotherNode() to tree, containerize uses it
brotherNode adds a node as a brother so that position is not lost

Diffstat:
Msrc/commands.c | 17++++++++++++++---
Msrc/tree.c | 30++++++++++++++++++++++++++++--
Msrc/tree.h | 1+
3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -93,15 +93,26 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "containerize")) { if (!strcmp(tokens[1], "client")) { - if (activeNode -> previous != NULL) { + if (!(activeNode -> previous == NULL && activeNode -> next == NULL)) { fprintf(stderr,"Containerizing"); Node * newContainer = allocateNode(); Node * nodeParent = activeNode -> parent; + /* Save a node and position to insert for when we reparent */ + Node *insertNode; int insertPosition; + if (activeNode -> previous != NULL) { + insertNode = activeNode -> previous; insertPosition = 1; + } else if (activeNode -> next != NULL) { + insertNode = activeNode -> next; insertPosition = 0; + } + + //Unparents activeNode and reparents into newContainer parentNode(activeNode, newContainer); - parentNode(newContainer, nodeParent); + brotherNode(newContainer, insertNode, insertPosition); + activeNode = newContainer -> child; - + + //Rerender the viewnode placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); focusNode(newContainer -> child); diff --git a/src/tree.c b/src/tree.c @@ -16,8 +16,13 @@ void crawlNode(Node * node, int level) { fprintf(stderr, "\n"); } else { - char *or = node -> layout == 0 ? "Vertical" : "Horizontal"; - fprintf(stderr, "Container (%p) %s\n", node, or); + char *label; + switch (node -> layout) { + case 0: label = "Vertical"; break; + case 1: label = "Horizontal"; break; + case 2: label = "Grid"; break; + } + fprintf(stderr, "Container (%p) %s\n", node, label); Node *n; for (n = node -> child; n != NULL; n = n -> next) { @@ -110,6 +115,26 @@ void unparentNode(Node *node) { node -> parent = NULL; node -> next = NULL; node -> previous = NULL; } + +void brotherNode(Node *node, Node * brother, int position) { + if (position == 0) { + node -> next = brother; + if (brother -> previous == NULL) { //Pop in the front + node -> parent = brother -> parent; + node -> parent -> child = node; + } else { + //Shift previous pointer + node -> previous = brother -> previous; + brother -> previous = node; + } + } else if (position == 1) { + node -> previous = brother; + node -> next = brother -> next; + brother -> next = node; + } +} + + void parentNode(Node *node, Node *parent) { if (parent == NULL) { return; } //Cant add to NULL @@ -127,6 +152,7 @@ void parentNode(Node *node, Node *parent) { } } + void unmapNode(Node * node) { Node *n; for (n = node -> child; n != NULL; n = n -> next) { diff --git a/src/tree.h b/src/tree.h @@ -2,6 +2,7 @@ void crawlNode(Node * node, int level); void dumpTree(); void destroyNode(Node * n); void unparentNode(Node * node); +void brotherNode(Node *node, Node * brother, int position); void parentNode(Node * node, Node * parent); void focusNode(Node * node); void unmapNode(Node * node);