foo-wm

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

commit d86dff55c3f3220a85495eef5f0db6aa23c9e7b1
parent 6f760eb40e0f090484147a090841dc3cdf7477a9
Author: = <miles.sandlar@gmail.com>
Date:   Thu, 11 Oct 2012 11:46:23 -0400

Moved JSON responses to seperate responses.c
Removed dumpTree for dumping to STDERR

Diffstat:
MMakefile | 2+-
Msrc/commands.c | 35++++++-----------------------------
Msrc/structs.h | 1-
Msrc/tree.c | 74--------------------------------------------------------------------------
4 files changed, 7 insertions(+), 105 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ CC=gcc CFLAGS=-Wall -lX11 -g -lm VPATH=./src -WM_OBJS= events.o tree.o commands.o util.o window.o lookup.o foo-wm.o +WM_OBJS= events.o tree.o commands.o responses.o util.o window.o lookup.o foo-wm.o CLI_OBJS= client.o all: foo-wm foo-wm-c diff --git a/src/commands.c b/src/commands.c @@ -3,6 +3,7 @@ #include <string.h> #include "foo-wm.h" #include "commands.h" +#include "responses.h" #include "tree.h" #include "util.h" @@ -122,40 +123,16 @@ void focus(char * argA, char * argB) { char * get(char * property) { if (!strcmp(property, "tree")) - return crawlNode(rootNode, 0); + return jsonTree(rootNode, 0); else if (!strcmp(property, "view")) - return crawlNode(viewNode, 0); + return jsonTree(viewNode, 0); else if (!strcmp(property, "focus")) - return crawlNode(focusedNode, 0); - - - char * marksResponse = malloc(1024); - if (!strcmp(property, "marks")) { - sprintf(marksResponse, "{\"marks\":["); - Mark *n = NULL; - for(n = markTail; n; n = n -> previous) { - fprintf(stderr, "%s%s%s\n", marksResponse, n == markTail ? "," : "", n -> name); - sprintf(marksResponse, - "%s%s\"%s\"", - marksResponse, - n != markTail ? "," : "", - n -> name - ); - fprintf(stderr, "After the Sprintf"); - } - fprintf(stderr, "The Marks Response is %s\n", marksResponse); - - sprintf(marksResponse, "%s]}", marksResponse); - realloc(marksResponse, bytesUntilNull(marksResponse)); - return marksResponse; - } - - - + return jsonTree(focusedNode, 0); + else if (!strcmp(property, "marks")) + return jsonMarks(); } void kill(void) { - dumpTree(); fprintf(stderr, "Destroying Client %p\n", focusedNode); if (isClient(focusedNode)) { diff --git a/src/structs.h b/src/structs.h @@ -1,6 +1,5 @@ #include <X11/Xlib.h> -enum { LEFT, UP, RIGHT, DOWN }; enum { VERTICAL, HORIZONTAL, GRID, MAX, TABBED, FLOAT, FREEFLOAT }; enum { PREVIOUS, NEXT }; diff --git a/src/tree.c b/src/tree.c @@ -82,72 +82,6 @@ Bool unfocusNode(Node * n, Bool focusPath) { } /* -------------------------------------------------------------------------- - * Char * Returns - * -------------------------------------------------------------------------- */ -char * crawlNode(Node * node, int level) { - char - *buffer = malloc(5120), - *label = "", - *nestString = ""; - - /* Recursivly Crawl Children */ - if (!isClient(node)) { - nestString = malloc(5120); - Node *n = NULL; int c = 0; - - int last = -1; - for (n = node -> child; n; n = n -> next, last++) { } - n = NULL; - - for (n = node -> child; n; n = n -> next, c++) { - char *crawlResult = malloc(5120); - crawlResult = crawlNode(n, level + 1); - sprintf(nestString, "%s%s%s", - c == 0 ? "" : nestString, - crawlResult, - c != last ? "," : "" - ); - free(crawlResult); - } - } - - - /* Determine Label for sprintf */ - if (!isClient(node)) { - switch (node -> layout) { - case VERTICAL : label = ",\"layout\":\"vertical\""; break; - case HORIZONTAL : label = ",\"layout\":\"horizontal\""; break; - case GRID : label = ",\"layout\":\"grid\""; break; - case MAX : label = ",\"layout\":\"max\""; break; - case FLOAT : label = ",\"layout\":\"float\""; break; - } - } - - /* Print to the buffer */ - sprintf(buffer, - /* Type (Pointer) (?Layout) (?R/V/F) (?ChildFocus) */ - "{\"node\":\"(%p)\",\"type\":\"%s\"%s%s%s%s%s,\"children\":[%s]}\0", - node, - isClient(node) ? "client" : "container", - label, - node == rootNode ? ",\"root\":\"true\"" : "", - node == focusedNode ? ",\"focus\":\"true\"" : "", - node == viewNode ? ",\"view\":\"true\"" : "", - node -> focus ? node -> focus : "", - nestString - ); - - /* If it was a container, we malloc'd room for nestString */ - if (sizeof(nestString) > sizeof(char*)) - free(nestString); - - realloc(buffer, bytesUntilNull(buffer)); - return buffer; -} - - - -/* -------------------------------------------------------------------------- * Long Returns * -------------------------------------------------------------------------- */ long getBorderColor(Node * node, Bool focusPath) { @@ -303,14 +237,6 @@ void destroyNode(Node * n) { } -void dumpTree() { - fprintf(stderr, "Printing the tree\n"); - fprintf(stderr, "----------------------------------\n"); - crawlNode(rootNode, 0); - fprintf(stderr, "----------------------------------\n"); -} - - //This should focus OR select void focusNode(Node * n, XEvent * event, Bool setFocused, Bool focusPath) { if (!n || n == focusedNode) return;