From 59f2556ff16f14b9221201229e2da442a87bf651 Mon Sep 17 00:00:00 2001 From: seanpringle Date: Fri, 31 Aug 2012 14:20:58 +1000 Subject: [PATCH] smart placement --- cerberus.c | 23 ++++++++++++++++++++--- cerberus.h | 1 + config.h | 14 +++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/cerberus.c b/cerberus.c index 2ff979b..1e26af1 100644 --- a/cerberus.c +++ b/cerberus.c @@ -296,8 +296,8 @@ void spot_xywh(int spot, int *x, int *y, int *w, int *h) { spot = MAX(SPOT1, MIN(SPOT3, spot)); - int width_spot1 = (double)screen_w / 100 * SPOT1_WIDTH_PCT; - int height_spot2 = (double)screen_h / 100 * SPOT2_HEIGHT_PCT; + int width_spot1 = (double)screen_w / 100 * MIN(90, MAX(10, SPOT1_WIDTH_PCT)); + int height_spot2 = (double)screen_h / 100 * MIN(90, MAX(10, SPOT2_HEIGHT_PCT)); // default, left 2/3 of screen *x = screen_x, *y = screen_y, *w = width_spot1, *h = screen_h; @@ -536,7 +536,24 @@ void map_request(XMapEvent *e) { client_review(c); - int spot = SPOT_START == SPOT_CURRENT ? current_spot: SPOT_START; + int spot = SPOT_START; + + if (SPOT_START == SPOT_CURRENT) + spot = current_spot; + + if (SPOT_START == SPOT_SMART) + { + int x, y, w, h; + spot = SPOT1; + + spot_xywh(SPOT2, &x, &y, &w, &h); + if (c->attr.width <= w && c->attr.height <= h) + spot = SPOT2; + + spot_xywh(SPOT3, &x, &y, &w, &h); + if (c->attr.width <= w && c->attr.height <= h) + spot = SPOT3; + } client_spot(c, spot, 0); } client_free(c); diff --git a/cerberus.h b/cerberus.h index 023b293..99b4ac9 100644 --- a/cerberus.h +++ b/cerberus.h @@ -130,6 +130,7 @@ typedef struct { enum { SPOT_CURRENT, + SPOT_SMART, SPOT1, // large left pane SPOT2, // medium top right pane SPOT3 // small bottom right pane diff --git a/config.h b/config.h index a02e24e..420297d 100644 --- a/config.h +++ b/config.h @@ -2,7 +2,19 @@ #define BORDER 2 #define BORDER_BLUR "Dark Gray" #define BORDER_FOCUS "Royal Blue" -#define SPOT_START SPOT1 + +// new windows go to the same tile as the active window. +// this implies auto-raise and focus stealing. +//#define SPOT_START SPOT_CURRENT + +// new windows go to the tile of best fit. +// works best when apps remember their size. +// if tile is not current, window won't steal focus. +#define SPOT_START SPOT_SMART + +// all new windows go to a specific tile. +// if tile is not current, window won't steal focus. +//#define SPOT_START SPOT1 #define SPOT1_WIDTH_PCT 67 #define SPOT2_HEIGHT_PCT 67