foo-wm

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

commit 0f5c66c1a5dfba2b56751d19ff3a2b80fe9cda73
parent 156c065b98ddf45829822635d87525d977d6c20e
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Tue,  3 Jul 2012 16:14:32 -0400

Safer allocation by NULLing pointer values
New function called allocateNode()

Diffstat:
Msrc/commands.c | 3+++
Msrc/events.c | 4++--
Msrc/fifo-wm.c | 2++
Msrc/tree.c | 15---------------
Msrc/util.c | 12++++++++----
Msrc/util.h | 1+
6 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -5,6 +5,7 @@ #include "fifo-wm.h" #include "commands.h" #include "tree.h" +#include "util.h" void focus(int direction) { @@ -75,6 +76,8 @@ void handleCommand(char* request) { if (activeNode -> previous != NULL) { fprintf(stderr,"Containerizing"); Node * newContainer = malloc(sizeof(Node)); + newContainer -> next = NULL; newContainer -> previous = NULL; + newContainer -> parent = NULL; newContainer -> child = NULL; Node * nodeParent = activeNode -> parent; parentNode(activeNode, newContainer); diff --git a/src/events.c b/src/events.c @@ -8,12 +8,12 @@ #include "events.h" #include "tree.h" #include "window.h" +#include "util.h" void eMapRequest(XEvent *event) { fprintf(stderr, "Got a map request\n"); - Node *newNode; - newNode = malloc(sizeof(Node)); + Node *newNode = allocateNode(); newNode -> window = event -> xmaprequest.window; if (activeNode == NULL) { diff --git a/src/fifo-wm.c b/src/fifo-wm.c @@ -88,6 +88,8 @@ int main() { viewNode -> x = rootX; viewNode -> y = rootY; viewNode -> width = rootWidth; viewNode -> height = rootHeight; + viewNode -> previous = NULL; viewNode -> next = NULL; + viewNode -> parent = NULL; viewNode -> child = NULL; XSetErrorHandler((XErrorHandler)(xError)); XFlush(display); diff --git a/src/tree.c b/src/tree.c @@ -70,14 +70,6 @@ void destroyNode(Node * n) { dumpTree(); //Recursivly destroy all children of the node if (n -> window != (Window)NULL) { - /* - Lookup * entry; - for (entry = lookup; entry != NULL; entry = entry -> previous) { - if (n == (entry -> previous) -> node) { - entry -> previous = (entry -> previous) -> previous; - } - } - */ XUnmapWindow(display, n -> window); } else { fprintf(stderr, "The child is %p\n", n -> child); @@ -192,7 +184,6 @@ void placeNode(Node * node, int x, int y, int width, int height) { } Bool isClient(Node * node) { - fprintf(stderr,"Checking if %p is a client", node); if (node == NULL) { return False; } if (node -> window != (Window) NULL) { return True; } else { return False; } @@ -212,19 +203,13 @@ Node * getNodeByWindow(Window * window) { } Node * getClosestNode(Node * node) { - fprintf(stderr, "\nWITHIN !! GetClosest node called on %p\n", node); Node * pNode = node; 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 (isClient(nNode) && nNode != node) { return nNode; } - - fprintf(stderr,"pNode is %p", pNode); if (isClient(pNode) && pNode != node) { return pNode; } - - } //If not returned by here must look for more nodes in the parent, recur if (node -> parent == NULL) { return NULL; } else { diff --git a/src/util.c b/src/util.c @@ -1,5 +1,6 @@ #include <X11/Xlib.h> #include <stdio.h> +#include <stdlib.h> #include "fifo-wm.h" #include "util.h" @@ -15,10 +16,13 @@ unsigned long getColor(const char *colstr) { int xError(XErrorEvent *e) { - char err[500]; - - XGetErrorText(display, e -> request_code, err, 500); fprintf(stderr, "XErrorEvent of Request Code: %d and Error Code of %d\n", e -> request_code, e -> error_code); - fprintf(stderr, "%s\n", err); return 0; } + +Node * allocateNode() { + Node *n = malloc(sizeof(Node)); + n -> previous = NULL; n -> next = NULL; + n -> parent = NULL; n -> child = NULL; + return n; +} diff --git a/src/util.h b/src/util.h @@ -1,2 +1,3 @@ unsigned long getColor(const char *colstr); int xError(XErrorEvent *e); +Node * allocateNode();