foo-wm

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

commit 81c5b19b7af94f73d9b9367ae0975e569ba3f559
parent 9c59f43afc1740a519b92bedeb9c232fa32161d1
Author: = <miles.sandlar@gmail.com>
Date:   Tue, 21 Aug 2012 12:12:28 -0400

Remove focusing by direction - should be scripted

Diffstat:
Mconfig/.xbindkeysrc | 18+++++++++---------
Msrc/commands.c | 73+++++++++++++++++++++----------------------------------------------------
Msrc/tree.c | 100-------------------------------------------------------------------------------
3 files changed, 30 insertions(+), 161 deletions(-)

diff --git a/config/.xbindkeysrc b/config/.xbindkeysrc @@ -40,19 +40,19 @@ m:0x40 + c:23 Mod4 + Tab -"foo-wm-c /tmp/foo-wm.socket 'focus direction left'" +"foo-wm-c /tmp/foo-wm.socket 'focus brother -2'" m:0x40 + c:43 Mod4 + h -"foo-wm-c /tmp/foo-wm.socket 'focus direction down'" +"foo-wm-c /tmp/foo-wm.socket 'focus brother 1'" m:0x40 + c:44 Mod4 + j -"foo-wm-c /tmp/foo-wm.socket 'focus direction up'" +"foo-wm-c /tmp/foo-wm.socket 'focus brother -1'" m:0x40 + c:45 Mod4 + k -"foo-wm-c /tmp/foo-wm.socket 'focus direction right'" +"foo-wm-c /tmp/foo-wm.socket 'focus brother -2'" m:0x40 + c:46 Mod4 + l @@ -72,20 +72,20 @@ Shift+Mod4 + Tab # Shift VIM-Esque Movement -"foo-wm-c /tmp/foo-wm.socket 'shift left'" +"foo-wm-c /tmp/foo-wm.socket 'move 2'" m:0x41 + c:43 Shift+Mod4 + h -"foo-wm-c /tmp/foo-wm.socket 'shift down'" +"foo-wm-c /tmp/foo-wm.socket 'move 1'" m:0x41 + c:44 - Shift+Mod4 + k + Shift+Mod4 + j -"foo-wm-c /tmp/foo-wm.socket 'shift up'" +"foo-wm-c /tmp/foo-wm.socket 'move -1'" m:0x41 + c:45 Shift+Mod4 + k -"foo-wm-c /tmp/foo-wm.socket 'shift right'" +"foo-wm-c /tmp/foo-wm.socket 'move -2'" m:0x41 + c:46 Shift+Mod4 + l diff --git a/src/commands.c b/src/commands.c @@ -35,8 +35,6 @@ char * handleCommand(char * request) { focus(tokens[1], tokens[2]); else if (!strcmp(tokens[0], "move")) move(atoi(tokens[1])); - else if (!strcmp(tokens[0], "shift")) - shift(tokens[1]); else if (!strcmp(tokens[0], "mark")) addMark(tokens[1]); else if(!strcmp(tokens[0], "jump")) @@ -80,28 +78,6 @@ void move(int amount) { } -void shift(char * directionString) { - int direction = directionStringToInt(directionString); - Node * insertNode = getBrotherByDirection(focusedNode, direction); - if (!insertNode) { insertNode = getClientByDirection(focusedNode, direction); } - - Node * oldParent = focusedNode -> parent; - unparentNode(focusedNode); - placeNode(oldParent, oldParent -> x, oldParent -> y, oldParent -> width, oldParent -> height); - - /* Shifting within our current container */ - if (insertNode) { - while (!isClient(insertNode)) { - insertNode = insertNode -> focus ? insertNode -> focus : insertNode -> child; - } - brotherNode(focusedNode, insertNode, direction == LEFT || direction == UP ? 0 : 1); - placeNode(focusedNode -> parent, focusedNode -> parent -> x, focusedNode -> parent -> y, - focusedNode -> parent -> width, focusedNode -> parent -> height); - - focusNode(focusedNode, NULL, True, True); - } -} - /* Adds the current viewNode as a mark */ void addMark(char * markName) { @@ -163,37 +139,30 @@ void zoom(int level) { } void focus(char * argA, char * argB) { - if (!strcmp(argA, "direction")) { - int direction = directionStringToInt(argB); - Node *newFocus = getClientByDirection(focusedNode, direction); - fprintf(stderr, "Directional focusing %p\n", newFocus); - focusNode(newFocus, NULL, True, True); - - } else { - int delta = atoi(argB); - - fprintf(stderr, "Cycling focus"); - int brotherSwitch = -1; - if (!strcmp(argA, "brother")) brotherSwitch = 1; - else if (!strcmp(argA, "pc")) brotherSwitch = 0; - else return; - - while (delta != 0) { - Node * newFocus; - - if (brotherSwitch) { - newFocus = getBrother(focusedNode, (delta < 0) ? -1 : 1); - } else { - newFocus = (delta < 0) ? - focusedNode -> parent : focusOrChildOf(focusedNode); - } + int delta = atoi(argB); + + fprintf(stderr, "Cycling focus"); + int brotherSwitch = -1; + if (!strcmp(argA, "brother")) brotherSwitch = 1; + else if (!strcmp(argA, "pc")) brotherSwitch = 0; + else return; + + while (delta != 0) { + Node * newFocus; + + if (brotherSwitch) { + newFocus = getBrother(focusedNode, (delta < 0) ? -1 : 1); + } else { + newFocus = (delta < 0) ? + focusedNode -> parent : focusOrChildOf(focusedNode); + } - fprintf(stderr, "Going to focus node: %p", newFocus); + fprintf(stderr, "Going to focus node: %p", newFocus); - focusNode(newFocus, NULL, True, True); - delta = delta + ( delta > 0 ? -1 : 1); - } + focusNode(newFocus, NULL, True, True); + delta = delta + ( delta > 0 ? -1 : 1); } + } void containerize(void) { diff --git a/src/tree.c b/src/tree.c @@ -377,30 +377,6 @@ Node * getBrother(Node * node, int delta) { return node; } - -Node * getClientByDirection(Node * originNode, int direction) { - int c = 0; - Node *returnNode = NULL; - - - while (!returnNode) { - returnNode = getBrotherByDirection(originNode, direction); - if (!returnNode) { - /* Search up until we have a brother in the direction */ - if (originNode -> parent) originNode = originNode -> parent; - else break; - } else { - /* Search down until we have a client */ - while (!isClient(returnNode)) { - returnNode = returnNode -> focus ? - returnNode -> focus : returnNode -> child; - } - } - c++; - } - return nodeIsParentOf(viewNode, returnNode) ? returnNode : NULL; -} - /* Searches nodeA for an occurance of nodeB * if successful, return true */ Bool nodeIsParentOf(Node * nodeA, Node * nodeB) { @@ -415,82 +391,6 @@ Bool nodeIsParentOf(Node * nodeA, Node * nodeB) { return False; } - -/* Gets brother in specific direction - * If can't get brother in direction, returns NULL - * */ -Node * getBrotherByDirection(Node * node, int direction) { - if (!node || !node -> parent) return NULL; - if (node -> parent && node -> parent -> layout == MAX) return NULL; - - // Count up children and find us in our parent - int parentChildren = 0, nodePosition = -1; - Node *n = NULL; - for (n = node -> parent -> child; n; n = n -> next) { - parentChildren++; - if (n == node) nodePosition = parentChildren; - } - - - fprintf(stderr, "Getting grid dems for %d, Layout = %d\n", parentChildren, node -> parent -> layout); - // Get the dimensions of the current grid - int rows = 0, cols = 0; - switch (node -> parent -> layout) { - case VERTICAL: - cols = parentChildren; rows = 1; - break; - case HORIZONTAL: - cols = 1; rows = parentChildren; - break; - case GRID: - gridDimensions(parentChildren, &rows, &cols); - break; - } - - - - int dest; - //Determine the brother - switch (direction) { - case LEFT: - if (((nodePosition - 1) % cols != 0) && node -> previous) - return node -> previous; - break; - case RIGHT: - if ((nodePosition % cols != 0) && node -> next) - return node -> next; - break; - case UP: - dest = nodePosition - cols; - if (dest > 0) { - n = node; - if (!node -> next && cols != 1 && isPrime(parentChildren)) dest++; - while (dest != nodePosition) { - n = n -> previous; dest++; - } - return n; - } - break; - case DOWN: - dest = nodePosition + cols; - if (rows == 1) { break; - } else if (dest <= parentChildren) { - n = node; - while (dest != nodePosition) { - n = n -> next; dest--; - } - return n; - } else if (dest <= parentChildren + 1 && isPrime(parentChildren)) { - n = node; // Prime odd case - while (n -> next) { n = n -> next; } - if (n != node) return n; - } - break; - } - - return NULL; -} - /* Swaps nodes within the same container of the tree * [ NULL <- A <-> B <-> C <-> D -> NULL ] */ void swapNodes(Node * a, Node * b) {