foo-wm

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

commit dcd4a04f2cb134aee7c358301fcb7d589b42cc49
parent 3fa654de760ad4cddfa03398308f805d476bc5a5
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Sat, 30 Jun 2012 15:11:31 -0400

Improving on unparentContainer & destroyContainer

Diffstat:
Mconfig/.xbindkeysrc | 4++++
Msrc/commands.c | 16++++++++++++++++
Msrc/tree.c | 55++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/tree.h | 1+
4 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/config/.xbindkeysrc b/config/.xbindkeysrc @@ -37,6 +37,10 @@ m:0x40 + c:28 Mod4 + t +"echo 'kill client set' > /home/mil/fifos/wm-fifo" + m:0x40 + c:24 + Mod4 + q + "dmenu-suggestions.rb | dmenu -h 60 -x 100 -y 400 -w 1200 -fn 'Envy Code R-20' -sb '#ffffff' -nf '#00ffd5' -nb '#1f1f1f' -sf '#000000' -b -p 'Command:' | xargs -0 -I INPUT handler INPUT" m:0x40 + c:40 diff --git a/src/commands.c b/src/commands.c @@ -86,16 +86,32 @@ void handleCommand(char* request) { parentClient((currentContainer -> focus) , newContainer); parentContainer(newContainer, currentContainer); currentContainer = newContainer; + placeContainer(currentContainer, + currentContainer -> x, currentContainer -> y, + currentContainer -> width, currentContainer -> height); + } else { fprintf(stderr, "Containerize called but already alone in a container..."); } } else if (!strcmp(tokens[0], "kill")) { if (!strcmp(tokens[1], "client")) { + + + dumpTree(); + fprintf(stderr, "Destroy Client %p\n", currentContainer -> focus); + destroyClient(currentContainer -> focus); + + dumpTree(); + placeContainer(currentContainer, currentContainer -> x, currentContainer -> y, currentContainer -> width, currentContainer -> height); } else if (!strcmp(tokens[1], "container")) { + dumpTree(); + fprintf(stderr, "Destroy Container %p\n", currentContainer); + destroyContainer(currentContainer); + dumpTree(); } } } diff --git a/src/tree.c b/src/tree.c @@ -43,7 +43,7 @@ void unparentClient(Client *c) { if (c -> parent != NULL) { if (c -> next != NULL) { - (c -> next) -> previous = c -> previous; + (c -> next) -> previous = c -> previous; (c -> parent) -> focus = c -> next; } @@ -51,22 +51,62 @@ void unparentClient(Client *c) { (c -> previous) -> next = c -> next; (c -> parent) -> focus = c -> previous; } - + XUnmapWindow(display, c -> window); c -> parent = NULL; } } -void destroyContainer(Container *c) { +void unparentContainer(Container *c) { + if (c -> parent == NULL) { return; } + + //Pop the container out of its linked list + if (c -> next == NULL && c -> previous == NULL) { + (c -> parent) -> child = NULL; + } else { + if (c -> next != NULL) { (c -> next) -> previous = c -> previous; } + if (c -> previous != NULL) { (c -> previous) -> next = c -> next; } + } + + //Destroy Children Clients + if (c -> client != NULL) { + Client *client; + for (client = c -> client; client != NULL; client = client -> next) { + unparentClient(client); + } + } + + //Destroy Children Containers + if (c -> child != NULL) { + Container *container; + for (container = c -> child; container != NULL; container = container -> next) { + unparentContainer(container); + } + } + + c -> parent = NULL; +} + +void destroyContainer(Container *c) { + if (c != NULL) { + fprintf(stderr, "Destorying Container %p\n", c); + unparentContainer(c); + } } void destroyClient(Client *c) { + //Check if client alone, if so destroy the container if (c == NULL) { return; } - fprintf(stderr, "Destroying %p\n", c); - XUnmapWindow(display, c -> window); - unparentClient(c); - free(c); + fprintf(stderr, "c->next = %p\nc->previous = %p\n", c->next, c->previous); + if (c -> next == NULL && (c -> parent) -> client == c) { + destroyContainer(c -> parent); + } else { + fprintf(stderr, "Destroying Client %p\n", c); + unparentClient(c); + XUnmapWindow(display, c -> window); + free(c); + } } @@ -87,6 +127,7 @@ int parentClient(Client * child, Container * parent) { Client *c = parent -> client; while (c -> next != NULL) { c = c -> next; } c -> next = child; + fprintf(stderr, "c->next set to %p\n", c->next); child -> previous = c; child -> parent = parent; } diff --git a/src/tree.h b/src/tree.h @@ -2,6 +2,7 @@ void crawlContainer(Container * container, int level); void dumpTree(); int parentClient(Client * child, Container * parent); void destroyClient(Client * c); +void destroyContainer(Container * c); int parentContainer(Container * child, Container * parent); int placeContainer(Container * container, int x, int y, int width, int height); Client * getClientByWindow(Window * window);