foo-wm

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

commit debc8f473c44fa7c0f8890874eea369c03d57284
parent ddef8084e3510c69b7281811ef9f11d82dbc6380
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Wed, 27 Jun 2012 00:37:28 -0400

Improved Handeling of FIFO - More Reliable
FIFO is now only closed once -->resulting commands reliability
Addition of client.c & client.h. Moved code from window.c to client.c
Other minor bug fixes and improvements

Diffstat:
MMakefile | 2+-
Asrc/client.c | 24++++++++++++++++++++++++
Asrc/client.h | 1+
Msrc/commands.c | 19++++++++++++++-----
Msrc/config.h | 2+-
Msrc/events.c | 10+++++-----
Msrc/fifo-wm.c | 36+++++++++++++++---------------------
Msrc/structs.h | 1+
Msrc/tree.c | 23++++++++++++++---------
Msrc/window.c | 23-----------------------
Msrc/window.h | 1-
11 files changed, 76 insertions(+), 66 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ CFLAGS=-Wall -lX11 -g VPATH=./src all:fifo-wm -fifo-wm: events.o tree.o commands.o util.o window.o +fifo-wm: events.o tree.o commands.o util.o window.o client.o clean: rm -rf fifo-wm *.o diff --git a/src/client.c b/src/client.c @@ -0,0 +1,24 @@ +#include <X11/Xlib.h> + +#include "fifo-wm.h" +#include "client.h" + + +void focusClient(Client *client) { + XSetWindowBorder(display, currentClient -> window, unfocusedColor); + XSetWindowBorderWidth(display, currentClient -> window, 0); + + XSetWindowBorderWidth(display, client -> window, 2); + XSetWindowBorder(display, client -> window, focusedColor); + + //Focuses window + XSelectInput( + display, client -> window, + FocusChangeMask | KeyPressMask | + ButtonPressMask | LeaveWindowMask | OwnerGrabButtonMask + ); + XGrabButton( + display, AnyButton, AnyModifier, client -> window, False, + OwnerGrabButtonMask | ButtonPressMask, + GrabModeSync, GrabModeSync, None, None); +} diff --git a/src/client.h b/src/client.h @@ -0,0 +1 @@ +void focusClient(Client *client); diff --git a/src/commands.c b/src/commands.c @@ -28,14 +28,23 @@ void handleCommand(char* request) { fprintf(stderr, "Setting layout to: %s", tokens[1]); if (!strcmp(tokens[1], "vertical")) { currentContainer -> layout = 0; + } else if (!strcmp(tokens[1], "horizontal")) { currentContainer -> layout = 1; } + placeContainer(currentContainer, + currentContainer -> x, currentContainer -> y, + currentContainer -> width, currentContainer -> height); + } else if (!strcmp(tokens[0], "containerize")) { - fprintf(stderr, "Containerizing!"); - Container * newContainer = malloc(sizeof(Container)); - parentClient(currentClient, newContainer); - parentContainer(newContainer, currentContainer); - currentContainer = newContainer; + if (currentClient -> previous != NULL) { + fprintf(stderr, "Containerizing!"); + Container * newContainer = malloc(sizeof(Container)); + parentClient(currentClient, newContainer); + parentContainer(newContainer, currentContainer); + currentContainer = newContainer; + } else { + fprintf(stderr, "Containerize called but already alone in a container..."); + } } } diff --git a/src/config.h b/src/config.h @@ -7,4 +7,4 @@ // Containers #define CONTAINER_DEFAULT_LAYOUT (0) -#define CONTAINER_PADDING 1 +#define CONTAINER_PADDING 0 diff --git a/src/events.c b/src/events.c @@ -7,6 +7,7 @@ #include "events.h" #include "tree.h" #include "window.h" +#include "client.h" void handleXEvent(XEvent *event) { switch (event -> type) { @@ -43,7 +44,7 @@ void eMapRequest(XEvent *event) { DisplayHeight (display, activeScreen) ); - focusWindow(&(newClient -> window)); + //focusClient(newClient); //Add Client and window to lookup list @@ -57,12 +58,11 @@ void eMapRequest(XEvent *event) { void eButtonPress(XEvent *event) { - fprintf(stderr, "\n\nButton Event Window is %p\n\n", &(event -> xbutton.subwindow)); + fprintf(stderr, "Button Event Window is %p\n", &(event -> xbutton.subwindow)); //Root Window if (event -> xbutton.subwindow == None) { return; } - /* Client *c = getClientByWindow(&(event -> xbutton.subwindow)); - fprintf(stderr, "Got the client matching to the window %d", c); - focusWindow( & (event -> xbutton.subwindow)); */ + Client *c = getClientByWindow(&(event -> xbutton.subwindow)); + focusClient(c); } diff --git a/src/fifo-wm.c b/src/fifo-wm.c @@ -15,45 +15,39 @@ #include "window.h" void handleEvents() { + XEvent event; int fifoFd = 0; - int xFd = 0; + int xFd = XConnectionNumber(display); fd_set descriptors; //Descriptors FD Set - XEvent event; char commands[256]; int result = 0; - tv.tv_sec = 0; - tv.tv_usec = 50000; + tv.tv_sec = 20; + tv.tv_usec = 5; + fifoFd = open(FIFO, O_RDONLY | O_NONBLOCK); for (;;) { - /* Reset the File Descriptor */ FD_ZERO(&descriptors); - - /* Open the FIFO FD, Add the X FD and the FIFO FD to the Set */ - fifoFd = open(FIFO, O_RDWR | O_NONBLOCK); - FD_SET(fifoFd, &descriptors); FD_SET(xFd, &descriptors); + FD_SET(fifoFd, &descriptors); - /* Run Select on File Descriptors */ - select(xFd + 1, &descriptors, 0, 0, &tv); - - //Recieved event from X - while (XPending(display)) { - XNextEvent(display, &event); - handleXEvent(&event); - } + select(fifoFd + 1, &descriptors, 0, 0, &tv); - //Commands from FIFO can be up to 300 character long - if ((result = read(fifoFd, commands, 300)) > 0) { + if ((result = read(fifoFd, commands, 200)) > 0) { commands[result] = '\0'; handleCommand(commands); } - close(fifoFd); + + while (XPending(display) > 0) { + XNextEvent(display, &event); + handleXEvent(&event); + } } + close(fifoFd); } - + int main() { layout = CONTAINER_DEFAULT_LAYOUT; diff --git a/src/structs.h b/src/structs.h @@ -14,6 +14,7 @@ struct Client { struct Container { char *label; int layout; + int x, y, width, height; Container *parent; Container *next; diff --git a/src/tree.c b/src/tree.c @@ -88,6 +88,10 @@ int parentContainer(Container * child, Container * parent) { } int placeContainer(Container * container, int x, int y, int width, int height) { + container -> x = x; + container -> y = y; + container -> width = width; + container -> height = height; //Count up children int children = 0; @@ -103,8 +107,8 @@ int placeContainer(Container * container, int x, int y, int width, int height) { switch (container -> layout) { case 0: placeContainer(b, - x + (i * (width/children)), y, - (width / children), height); + x + (i * (width/children)) + padding, y + padding, + (width / children) - (padding * 2), height - (padding * 2)); break; case 1: @@ -127,17 +131,17 @@ int placeContainer(Container * container, int x, int y, int width, int height) { switch (container -> layout) { case 0: XMoveResizeWindow(display, a -> window, - (x + (i * (width / children))) + padding, + (x + (i * (width / children))), y + padding, - (width / children) + padding, - height + padding); + (width / children), + height); break; case 1: XMoveResizeWindow(display, a -> window, - x + padding, - (y + (i * (height / children))) + padding, - width + padding, - (height / children) + padding); + x , + (y + (i * (height / children))), + width, + (height / children)); break; default: break; @@ -149,6 +153,7 @@ int placeContainer(Container * container, int x, int y, int width, int height) { return 0; } + //Returns the client associated with given window Client * getClientByWindow(Window * window) { Lookup *node; diff --git a/src/window.c b/src/window.c @@ -14,26 +14,3 @@ void centerPointer(Window *window) { //Warp to Center XWarpPointer(display, None, *window, 0, 0, 0, 0, centerX,centerY); } - - -void focusWindow(Window * window) { -XSetWindowBorderWidth(display, *window, 2); - XSetWindowBorder(display, *window, focusedColor); - - //Focuses window - XSelectInput( - display, *window, - FocusChangeMask | KeyPressMask | ButtonPressMask | LeaveWindowMask | OwnerGrabButtonMask - ); - XGrabButton( - display, - AnyButton, - AnyModifier, - *window, - False, - OwnerGrabButtonMask | ButtonPressMask, - GrabModeSync, - GrabModeSync, - None, - None); -} diff --git a/src/window.h b/src/window.h @@ -1,2 +1 @@ void centerPointer(Window *window); -void focusWindow(Window * window);