foo-wm

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

commit 2ecd5bc1bf29419178427364efde1d2e2b5789b0
parent 751f75c12245c05fffcf51438774fcdffc9302a2
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Fri,  6 Jul 2012 22:41:39 -0400

Added select to commands. Fixed reversed V/H
Vertical and horizontal layouts were inverse.

Diffstat:
Mconfig/.xbindkeysrc | 4++++
Msrc/commands.c | 37+++++++++++++++++++++++++++----------
Msrc/config.h | 2+-
Msrc/fifo-wm.c | 1+
Msrc/fifo-wm.h | 22+++++++++++-----------
Msrc/tree.c | 83++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/tree.h | 2+-
7 files changed, 89 insertions(+), 62 deletions(-)

diff --git a/config/.xbindkeysrc b/config/.xbindkeysrc @@ -38,6 +38,10 @@ m:0x40 + c:45 Mod4 + k +"echo 'select parent set' > /home/mil/fifos/wm-fifo" + m:0x40 + c:32 + Mod4 + o + "echo 'dump tree' > /home/mil/fifos/wm-fifo" m:0x40 + c:28 Mod4 + t diff --git a/src/commands.c b/src/commands.c @@ -93,11 +93,14 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "select")) { if (!strcmp(tokens[1], "parent")) { + fprintf(stderr, "Selecting parent node\n"); if (selectedNode == NULL) { - selectNode(focusedNode -> parent); + fprintf(stderr, "Selected Node is NULL\n"); + selectNode(focusedNode -> parent, True); } else { if (selectedNode -> parent != NULL) { - selectNode(selectedNode); + fprintf(stderr, "Selecting from Parent\n"); + selectNode(selectedNode -> parent, True); } } } else if (!strcmp(tokens[1], "next")) { @@ -108,28 +111,42 @@ void handleCommand(char* request) { } else if (!strcmp(tokens[0], "containerize")) { if (!strcmp(tokens[1], "client")) { - if (!(focusedNode -> previous == NULL && focusedNode -> next == NULL)) { + if (focusedNode -> previous != NULL || focusedNode -> next != NULL) { fprintf(stderr,"Containerizing"); Node * newContainer = allocateNode(); newContainer -> layout = layout; + Node *child; + if (selectedNode != NULL) { + child = selectedNode; + } else { + child = focusedNode; + } + fprintf(stderr, "Child is %p\n", child); + /* Save a node and position to insert for when we reparent */ Node *insertNode; int insertPosition; - if (focusedNode -> previous != NULL) { - insertNode = focusedNode -> previous; insertPosition = 1; - } else if (focusedNode -> next != NULL) { - insertNode = focusedNode -> next; insertPosition = 0; + if (child -> previous != NULL) { + insertNode = child -> previous; insertPosition = 1; + } else if (child -> next != NULL) { + insertNode = child -> next; insertPosition = 0; } //Unparents focusedNode and reparents into newContainer - parentNode(focusedNode, newContainer); + parentNode(child, newContainer); brotherNode(newContainer, insertNode, insertPosition); - focusedNode = newContainer -> child; + if (selectedNode == NULL) { + focusedNode = newContainer -> child; + } //Rerender the viewnode placeNode(viewNode, rootX, rootY, rootWidth, rootHeight); - focusNode(newContainer -> child); + + + if (selectedNode == NULL) { + focusNode(newContainer -> child); + } } else { fprintf(stderr, "Containerize called but alone in contianer"); diff --git a/src/config.h b/src/config.h @@ -8,7 +8,7 @@ // Containers #define CONTAINER_DEFAULT_LAYOUT (2) #define CONTAINER_PADDING (1) -#define BORDER_WIDTH (1) +#define BORDER_WIDTH (10) #define SCREEN_PADDING_TOP (20) #define SCREEN_PADDING_LEFT (2) diff --git a/src/fifo-wm.c b/src/fifo-wm.c @@ -24,6 +24,7 @@ void handleEvents() { int result = 0; + struct timeval tv; tv.tv_sec = 200; fifoFd = open(FIFO, O_RDONLY | O_NONBLOCK); diff --git a/src/fifo-wm.h b/src/fifo-wm.h @@ -3,24 +3,24 @@ #include "structs.h" -Lookup * lookup; - -int screen, activeScreen; -int padding; -int layout; -int border; +//X Server Display *display; -Window root; -struct timeval tv; -long unfocusedColor; -long focusedColor; - +int screen, activeScreen; int rootX, rootY, rootWidth, rootHeight; +Window root; /* focusedNode :: Currently focused client node (recieves input) * selectedNode :: Currently selected node (for containerize, move, etc....) * viewNode :: Currently viewed node (screenspace) */ Node *focusedNode, *selectedNode, *viewNode; +/* X Window -> Node Lookup Table */ +Lookup * lookup; + +//Customizations +int padding, layout, border; +long unfocusedColor, focusedColor; + + void handleCommand(char* request); void handleEvents(); diff --git a/src/tree.c b/src/tree.c @@ -12,7 +12,7 @@ void crawlNode(Node * node, int level) { if (isClient(node)) { fprintf(stderr, "Client (%p)", node); - if (node == focusedNode) { fprintf(stderr, " [FOCUS]"); } + if (node == focusedNode) { fprintf(stderr, " [Focused]"); } fprintf(stderr, "\n"); } else { @@ -22,7 +22,11 @@ void crawlNode(Node * node, int level) { case 1: label = "Horizontal"; break; case 2: label = "Grid"; break; } - fprintf(stderr, "Container (%p) %s\n", node, label); + fprintf(stderr, "Container (%p) %s", node, label); + if (node == selectedNode) { fprintf(stderr, " [Selected]"); } + fprintf(stderr, "\n"); + + Node *n; for (n = node -> child; n != NULL; n = n -> next) { @@ -49,6 +53,8 @@ void focusNode(Node * n) { XSetWindowBorder(display, focusedNode -> window, unfocusedColor); } + selectedNode = NULL; + focusedNode = n; XRaiseWindow(display, n -> window); XSetInputFocus(display, n -> window, RevertToPointerRoot, CurrentTime); @@ -56,21 +62,28 @@ void focusNode(Node * n) { centerPointer(&n -> window); } -void selectNode(Node * n) { +void selectNode(Node * n, Bool setSelected) { + 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); + XSetWindowBorder(display, i->window, focusedColor); + } else { + selectNode(i, False); + } + } } void destroyNode(Node * n) { - fprintf(stderr, "PRE DESTROY\n"); dumpTree(); if (n == NULL) { return; } - if ( (n -> next == NULL && - (n -> parent -> child == n && n -> previous == NULL)) && - n -> parent -> parent != NULL - ) { + if ( n -> next == NULL && n -> parent -> child == n && + n -> previous == NULL && n -> parent -> parent != NULL) { fprintf(stderr, "Calling destroy node on parent\n"); destroyNode(n -> parent); return; @@ -108,13 +121,12 @@ void unparentNode(Node *node) { focusNode(getClosestClient(node)); //Move parent's child pointer if were it.... - if ((node -> parent) -> child == node) { - (node -> parent) -> child = node -> next; - } + if (node -> parent -> child == node) + node -> parent -> child = node -> next; //Move the next and previous pointers to cut out the node - if (node -> next != NULL) { (node -> next) -> previous = node -> previous; } - if (node -> previous != NULL) { (node -> previous) -> next = node -> next; } + if (node -> next != NULL) node -> next -> previous = node -> previous; + if (node -> previous != NULL) node -> previous -> next = node -> next; //Set our parent to NULL node -> parent = NULL; node -> next = NULL; node -> previous = NULL; @@ -161,13 +173,9 @@ void parentNode(Node *node, Node *parent) { void unmapNode(Node * node) { Node *n; - for (n = node -> child; n != NULL; n = n -> next) { - if (n -> window != (Window) NULL) { - XUnmapWindow(display, n -> window); - } else if (n -> child != NULL) { - unmapNode(n -> child); - } - } + for (n = node -> child; n != NULL; n = n -> next) + if (n -> window != (Window) NULL) XUnmapWindow(display, n -> window); + else if (n -> child != NULL) unmapNode(n -> child); } void placeNode(Node * node, int x, int y, int width, int height) { @@ -201,8 +209,8 @@ void placeNode(Node * node, int x, int y, int width, int height) { /* Determine the number of rows and cols */ int rows; int cols; switch (node -> layout) { - case 0: cols = 1; rows = children; break; - case 1: cols = children; rows = 1; break; + case 0: cols = children; rows = 1; break; + case 1: cols = 1; rows = children; break; case 2: gridDimensions(children, &rows, &cols); break; } @@ -215,9 +223,9 @@ void placeNode(Node * node, int x, int y, int width, int height) { if (node -> layout == 2) { //Two nodes, edge case for formula - if (children == 2) { a -> height = height - (padding * 2); } - //Scretch the last child - if (i + 1 == children) { a -> width = x + width - a -> x - (padding * 2); } + if (children == 2) a -> height = height - (padding * 2); + //Strecth the last child + if (i + 1 == children) a -> width = x + width - a -> x - (padding * 2); } placeNode(a, a -> x, a -> y, a -> width, a -> height); } @@ -226,9 +234,9 @@ void placeNode(Node * node, int x, int y, int width, int height) { Bool isClient(Node * node) { - if (node == NULL) { return False; } - if (node -> window != (Window) NULL) { return True; - } else { return False; } + if (node == NULL) return False; + if (node -> window != (Window) NULL) return True; + return False; } /* Gets the next brother client to node, in given direction @@ -240,16 +248,16 @@ Node * getBrotherClient(Node * node, int direction) { Node *nNode = node; while (pNode -> previous != NULL || nNode -> next != NULL) { - if (pNode -> previous != NULL) { pNode = pNode -> previous; } - if (nNode -> next != NULL ) { nNode = nNode -> next; } + if (pNode -> previous != NULL) pNode = pNode -> previous; + if (nNode -> next != NULL ) nNode = nNode -> next; switch (direction) { case 0: - if (isClient(pNode) && pNode != node) { return pNode; } - if (isClient(nNode) && nNode != node) { return nNode; } + if (isClient(pNode) && pNode != node) return pNode; + if (isClient(nNode) && nNode != node) return nNode; break; case 1: - if (isClient(nNode) && nNode != node) { return nNode; } - if (isClient(pNode) && pNode != node) { return pNode; } + if (isClient(nNode) && nNode != node) return nNode; + if (isClient(pNode) && pNode != node) return pNode; break; } } @@ -264,11 +272,8 @@ Node * getClosestClient(Node * node) { while (returnNode == NULL) { returnNode = getBrotherClient(currentNode, 1); if (returnNode == NULL) { - if (currentNode -> parent != NULL) { //Try one level up - currentNode = currentNode -> parent; - } else { //We didn't find a brother and we have no parent, end game - return NULL; - } + if (currentNode -> parent != NULL) currentNode = currentNode -> parent; + else return NULL; } else { //We found a client return returnNode; } diff --git a/src/tree.h b/src/tree.h @@ -5,7 +5,7 @@ void unparentNode(Node * node); void brotherNode(Node *node, Node * brother, int position); void parentNode(Node * node, Node * parent); void focusNode(Node * node); -void selectNode(Node * n); +void selectNode(Node * n, Bool setSelected); void unmapNode(Node * node); void placeNode(Node * node, int x, int y, int width, int height); Node * getBrotherClient(Node * node, int direction);