foo-wm

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

commit 1125f75222ed9afe2d1c7985b13915acc5536418
parent 811b4845c82f78286b6cac8e09433d68c8aa3868
Author: Miles Sandlar <miles.sandlar@gmail.com>
Date:   Fri,  6 Jul 2012 15:24:38 -0400

Added a grid layout. Restructured placeNode.
placeNode uses same grid code by spec col/rows
Added Mod+g to xbindkeys for grid

Diffstat:
MMakefile | 2+-
Mconfig/.xbindkeysrc | 4++++
Msrc/commands.c | 10++++++++--
Msrc/config.h | 2+-
Msrc/tree.c | 41++++++++++++++++++++++++++---------------
Msrc/util.c | 15+++++++++++++++
Msrc/util.h | 1+
7 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-Wall -lX11 -g +CFLAGS=-Wall -lX11 -g -lm VPATH=./src all:fifo-wm diff --git a/config/.xbindkeysrc b/config/.xbindkeysrc @@ -20,6 +20,10 @@ m:0x40 + c:56 Mod4 + b +"echo 'layout grid set' > /home/mil/fifos/wm-fifo" + m:0x40 + c:42 + Mod4 + g + "echo 'containerize client set' > /home/mil/fifos/wm-fifo" m:0x40 + c:33 diff --git a/src/commands.c b/src/commands.c @@ -69,8 +69,14 @@ void handleCommand(char* request) { dumpTree(); } else if (!strcmp(tokens[0], "layout")) { fprintf(stderr, "Setting layout to: %s", tokens[1]); - if (!strcmp(tokens[1], "vertical")) { (activeNode -> parent) -> layout = 0; - } else if (!strcmp(tokens[1], "horizontal")) { (activeNode -> parent) -> layout = 1; } + if (!strcmp(tokens[1], "vertical")) { + activeNode -> parent -> layout = 0; + } else if (!strcmp(tokens[1], "horizontal")) { + activeNode -> parent -> layout = 1; + } else if (!strcmp(tokens[1], "grid")) { + activeNode -> parent -> layout = 2; + } + placeNode(activeNode -> parent, (activeNode -> parent) -> x, (activeNode -> parent) -> y, (activeNode -> parent) -> width, (activeNode -> parent) -> height); diff --git a/src/config.h b/src/config.h @@ -8,7 +8,7 @@ // Containers #define CONTAINER_DEFAULT_LAYOUT (0) #define CONTAINER_PADDING (1) -#define BORDER_WIDTH (1) +#define BORDER_WIDTH (3) #define SCREEN_PADDING_TOP (18) #define SCREEN_PADDING_LEFT (2) diff --git a/src/tree.c b/src/tree.c @@ -1,6 +1,7 @@ #include <X11/Xlib.h> #include <stdio.h> #include <stdlib.h> +#include <math.h> #include "fifo-wm.h" #include "tree.h" @@ -164,22 +165,32 @@ void placeNode(Node * node, int x, int y, int width, int height) { //Count up children prior to loop int children = 0; int i = 0; Node *a; for (a = node -> child; a != NULL; a = a -> next) { children++; } + + /* Determine the number of rows and cols */ + int rows; int cols; + switch (node -> layout) { + case 0: + cols = 1; + rows = children; + break; + case 1: + cols = children; + rows = 1; + break; + case 2: + gridDimensions(children, &rows, &cols); + break; + } + //fprintf(stderr, "Rows = %d\nCols = %d\n", rows, cols); + + for (a = node -> child; a != NULL; a = a -> next, i++) { - switch (node -> layout) { - case 0: - a -> x = x + (i * (width / children)) + padding; - a -> y = y + padding; - a -> width = (width / children) - (padding*2); - a -> height = height - (padding*2); - break; - - case 1: - a -> x = x + padding; - a -> y = y + (i * (height / children)) + padding; - a -> width = width - (padding * 2); - a -> height = (height / children) - (padding * 2); - break; - } + a -> x = x + (i % cols) * (width/cols); + a -> y = y + ((int)(i / cols)) * (height/rows); + a -> width = width / cols; + a -> height = height / rows; + + fprintf(stderr, "Calling place node with X[%d] and Y[%d]\n", a -> x, a -> y); placeNode(a, a -> x, a -> y, a -> width, a -> height); } } diff --git a/src/util.c b/src/util.c @@ -26,3 +26,18 @@ Node * allocateNode() { n -> parent = NULL; n -> child = NULL; return n; } + +void gridDimensions(int children, int * rows, int * cols) { + int square = (int) sqrt(children); + int r = square; + + while (((children % r) != 0)) { r++; } + int c = children / r; + + if ((r == 1 && c != 1) || (c == 1 && r != 1)) { + gridDimensions(children + 1, rows, cols); + } else { + *rows = r; + *cols = c; + } +} diff --git a/src/util.h b/src/util.h @@ -1,3 +1,4 @@ unsigned long getColor(const char *colstr); int xError(XErrorEvent *e); Node * allocateNode(); +void gridDimensions(int children, int * rows, int * cols);