From d6c63bd086609049da82dd22074597ff9316fefc Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 12 Sep 2007 16:03:42 +0200 Subject: [PATCH] remove wa(x,y,h,w) from global vars, add functions to compute them --- awesome.c | 41 ++++++++++++++++++++++++++++++++--------- awesome.h | 4 ++++ client.c | 6 +++++- event.c | 5 ++++- layout.c | 24 +++++++++++++++++------- layouts/grid.c | 4 +++- layouts/spiral.c | 10 +++++----- layouts/tile.c | 39 ++++++++++++++++++++++----------------- 8 files changed, 92 insertions(+), 41 deletions(-) diff --git a/awesome.c b/awesome.c index 7297593e..8aa7f0fc 100644 --- a/awesome.c +++ b/awesome.c @@ -35,7 +35,6 @@ #include "layout.h" #include "tag.h" -int wax, way, waw, wah; Client *clients = NULL; Client *sel = NULL; Client *stack = NULL; @@ -191,25 +190,49 @@ uicb_quit(Display *disp __attribute__ ((unused)), readin = running = False; } +int +get_windows_area_x(Statusbar statusbar __attribute__ ((unused))) +{ + return 0; +} + +int +get_windows_area_y(Statusbar statusbar) +{ + if(statusbar.position == BarTop) + return statusbar.height; + + return 0; +} + +int +get_windows_area_height(Display *disp, Statusbar statusbar) +{ + if(statusbar.position == BarTop || statusbar.position == BarBot) + return DisplayHeight(disp, DefaultScreen(disp)) - statusbar.height; + + return DisplayHeight(disp, DefaultScreen(disp)); +} + +int +get_windows_area_width(Display *disp, + Statusbar statusbar __attribute__ ((unused))) +{ + return DisplayWidth(disp, DefaultScreen(disp)); +} + void updatebarpos(Display *disp, Statusbar statusbar) { XEvent ev; - wax = 0; - way = 0; - wah = DisplayHeight(disp, DefaultScreen(disp)); - waw = DisplayWidth(disp, DefaultScreen(disp)); switch (statusbar.position) { default: - wah -= statusbar.height; - way += statusbar.height; XMoveWindow(disp, statusbar.window, 0, 0); break; case BarBot: - wah -= statusbar.height; - XMoveWindow(disp, statusbar.window, 0, wah); + XMoveWindow(disp, statusbar.window, 0, get_windows_area_width(disp, statusbar) - statusbar.height); break; case BarOff: XMoveWindow(disp, statusbar.window, 0, 0 - statusbar.height); diff --git a/awesome.h b/awesome.h index b7e3b0ec..a6162686 100644 --- a/awesome.h +++ b/awesome.h @@ -31,5 +31,9 @@ Bool gettextprop(Display *, Window, Atom, char *, unsigned int); /* return tex void updatebarpos(Display *, Statusbar); /* updates the bar position */ void uicb_quit(Display *, awesome_config *, const char *); /* quit awesome nicely */ int xerror(Display *, XErrorEvent *); /* awesome's X error handler */ +int get_windows_area_x(Statusbar); +int get_windows_area_y(Statusbar); +int get_windows_area_height(Display *, Statusbar); +int get_windows_area_width(Display *, Statusbar); #endif diff --git a/client.c b/client.c index ba83f870..10c068d7 100644 --- a/client.c +++ b/client.c @@ -30,7 +30,6 @@ #include "layouts/floating.h" /* extern */ -extern int wax, way, wah, waw; /* windowarea geometry */ extern Client *clients, *sel, *stack; /* global client list and stack */ /** Attach client stack to clients stacks @@ -370,6 +369,11 @@ manage(Display * disp, DC *drawcontext, Window w, XWindowAttributes * wa, awesom } else { + int wax = get_windows_area_x(awesomeconf->statusbar); + int way = get_windows_area_y(awesomeconf->statusbar); + int waw = get_windows_area_width(disp, awesomeconf->statusbar); + int wah = get_windows_area_height(disp, awesomeconf->statusbar); + if(c->x + c->w + 2 * c->border > wax + waw) c->x = c->rx = wax + waw - c->w - 2 * c->border; if(c->y + c->h + 2 * c->border > way + wah) diff --git a/event.c b/event.c index 07e2b266..62b7014d 100644 --- a/event.c +++ b/event.c @@ -31,7 +31,6 @@ #include "layouts/floating.h" /* extern */ -extern int wax, way, wah, waw; /* windowarea geometry */ extern DC dc; /* global draw context */ extern Cursor cursor[CurLast]; extern Client *clients, *sel; /* global client list */ @@ -55,6 +54,10 @@ movemouse(Client * c, awesome_config *awesomeconf) unsigned int dui; Window dummy; XEvent ev; + int wax = get_windows_area_x(awesomeconf->statusbar); + int way = get_windows_area_y(awesomeconf->statusbar); + int waw = get_windows_area_width(c->display, awesomeconf->statusbar); + int wah = get_windows_area_height(c->display, awesomeconf->statusbar); ocx = nx = c->x; ocy = ny = c->y; diff --git a/layout.c b/layout.c index bb8e7f40..ffe96ed1 100644 --- a/layout.c +++ b/layout.c @@ -28,7 +28,6 @@ #include "layouts/floating.h" /* extern */ -extern int wax, way, wah, waw; /* windowarea geometry */ extern Client *clients, *sel; /* global client list */ extern DC dc; @@ -228,30 +227,41 @@ maximize(int x, int y, int w, int h, awesome_config *awesomeconf) } void -uicb_togglemax(Display *disp __attribute__ ((unused)), +uicb_togglemax(Display *disp, awesome_config *awesomeconf, const char *arg __attribute__ ((unused))) { - maximize(wax, way, waw - 2 * awesomeconf->borderpx, wah - 2 * awesomeconf->borderpx, awesomeconf); + maximize(get_windows_area_x(awesomeconf->statusbar), + get_windows_area_y(awesomeconf->statusbar), + get_windows_area_width(disp, awesomeconf->statusbar) - 2 * awesomeconf->borderpx, + get_windows_area_height(disp, awesomeconf->statusbar) - 2 * awesomeconf->borderpx, awesomeconf); } void -uicb_toggleverticalmax(Display *disp __attribute__ ((unused)), +uicb_toggleverticalmax(Display *disp, awesome_config *awesomeconf, const char *arg __attribute__ ((unused))) { if(sel) - maximize(sel->x, way, sel->w, wah - 2 * awesomeconf->borderpx, awesomeconf); + maximize(sel->x, + get_windows_area_y(awesomeconf->statusbar), + sel->w, + get_windows_area_height(disp, awesomeconf->statusbar) - 2 * awesomeconf->borderpx, + awesomeconf); } void -uicb_togglehorizontalmax(Display *disp __attribute__ ((unused)), +uicb_togglehorizontalmax(Display *disp, awesome_config *awesomeconf, const char *arg __attribute__ ((unused))) { if(sel) - maximize(wax, sel->y, waw - 2 * awesomeconf->borderpx, sel->h, awesomeconf); + maximize(get_windows_area_x(awesomeconf->statusbar), + sel->y, + get_windows_area_height(disp, awesomeconf->statusbar) - 2 * awesomeconf->borderpx, + sel->h, + awesomeconf); } void diff --git a/layouts/grid.c b/layouts/grid.c index 22bcf5c4..1af32baf 100644 --- a/layouts/grid.c +++ b/layouts/grid.c @@ -20,11 +20,11 @@ * */ +#include "awesome.h" #include "grid.h" #include "layout.h" #include "tag.h" -extern int wah, waw; /* windowarea geometry */ extern Client *clients; /* global client list and stack */ extern DC dc; @@ -32,6 +32,8 @@ void grid(Display *disp, awesome_config *awesomeconf) { unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows; + int waw = get_windows_area_width(disp, awesomeconf->statusbar); + int wah = get_windows_area_height(disp, awesomeconf->statusbar); Client *c; for(n = 0, c = clients; c; c = c->next) diff --git a/layouts/spiral.c b/layouts/spiral.c index 8a2c15ad..710d8675 100644 --- a/layouts/spiral.c +++ b/layouts/spiral.c @@ -20,11 +20,11 @@ * */ +#include "awesome.h" #include "layout.h" #include "tag.h" #include "spiral.h" -extern int wax, way, wah, waw; /* windowarea geometry */ extern Client *clients; /* global client list */ extern DC dc; @@ -34,10 +34,10 @@ fibonacci(Display *disp, awesome_config *awesomeconf, int shape) int n, nx, ny, nh, nw, i; Client *c; - nx = wax; + nx = get_windows_area_x(awesomeconf->statusbar); ny = 0; - nw = waw; - nh = wah; + nw = get_windows_area_width(disp, awesomeconf->statusbar); + nh = get_windows_area_height(disp, awesomeconf->statusbar); for(n = 0, c = clients; c; c = c->next) if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags)) n++; @@ -75,7 +75,7 @@ fibonacci(Display *disp, awesome_config *awesomeconf, int shape) nx -= nw; } if(i == 0) - ny = way; + ny = get_windows_area_y(awesomeconf->statusbar); i++; } resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, False); diff --git a/layouts/tile.c b/layouts/tile.c index 76620898..1afa89b7 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -22,18 +22,16 @@ #include -#include "layouts/tile.h" -#include "layout.h" +#include "awesome.h" #include "tag.h" +#include "layout.h" +#include "layouts/tile.h" /* extern */ -extern int wax, way, wah, waw; /* windowarea geometry */ extern Client *sel, *clients; /* static */ -static void _tile(awesome_config *, const Bool); /* arranges all windows tiled */ - static double mwfact = 0.6; static int nmaster = 2; @@ -43,6 +41,7 @@ uicb_setnmaster(Display *disp, const char * arg) { int delta; + int wah = get_windows_area_height(disp, awesomeconf->statusbar); if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait)) return; @@ -92,8 +91,12 @@ uicb_setmwfact(Display *disp, } static void -_tile(awesome_config *awesomeconf, const Bool right) +_tile(Display *disp, awesome_config *awesomeconf, const Bool right) { + int wah = get_windows_area_height(disp, awesomeconf->statusbar); + int waw = get_windows_area_width(disp, awesomeconf->statusbar); + int wax = get_windows_area_x(awesomeconf->statusbar); + int way = get_windows_area_y(awesomeconf->statusbar); unsigned int nx, ny, nw, nh, mw; int n, th, i, mh; Client *c; @@ -152,22 +155,24 @@ _tile(awesome_config *awesomeconf, const Bool right) } void -tile(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf) +tile(Display *disp, awesome_config *awesomeconf) { - _tile(awesomeconf, True); + _tile(disp, awesomeconf, True); } void -tileleft(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf) +tileleft(Display *disp, awesome_config *awesomeconf) { - _tile(awesomeconf, False); + _tile(disp, awesomeconf, False); } static void -_bstack(awesome_config *awesomeconf, Bool portrait) +_bstack(Display *disp, awesome_config *awesomeconf, Bool portrait) { int i, n, nx, ny, nw, nh, mw, mh, tw, th; + int wah = get_windows_area_height(disp, awesomeconf->statusbar); + int waw = get_windows_area_width(disp, awesomeconf->statusbar); Client *c; for(n = 0, c = clients; c; c = c->next) @@ -186,8 +191,8 @@ _bstack(awesome_config *awesomeconf, Bool portrait) continue; c->ismax = False; - nx = wax; - ny = way; + nx = get_windows_area_x(awesomeconf->statusbar); + ny = get_windows_area_y(awesomeconf->statusbar); if(i < nmaster) { ny += i * mh; @@ -221,13 +226,13 @@ _bstack(awesome_config *awesomeconf, Bool portrait) } void -bstack(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf) +bstack(Display *disp, awesome_config *awesomeconf) { - _bstack(awesomeconf, False); + _bstack(disp, awesomeconf, False); } void -bstackportrait(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf) +bstackportrait(Display *disp, awesome_config *awesomeconf) { - _bstack(awesomeconf, True); + _bstack(disp, awesomeconf, True); }