remove sw/sh, calculate each time

This commit is contained in:
Julien Danjou 2007-09-07 17:19:03 +02:00
parent c3d2e56ef1
commit 8db67dca7c
4 changed files with 25 additions and 27 deletions

View File

@ -13,7 +13,7 @@
#include "layouts/floating.h" #include "layouts/floating.h"
/* extern */ /* extern */
extern int sx, sy, sw, sh; /* screen geometry */ extern int sx, sy; /* screen geometry */
extern int wax, way, wah, waw; /* windowarea geometry */ extern int wax, way, wah, waw; /* windowarea geometry */
extern Client *clients, *sel, *stack; /* global client list and stack */ extern Client *clients, *sel, *stack; /* global client list and stack */
extern Atom wmatom[WMLast], netatom[NetLast]; extern Atom wmatom[WMLast], netatom[NetLast];
@ -346,7 +346,8 @@ manage(Display * disp, DC *drawcontext, Window w, XWindowAttributes * wa, jdwm_c
c->h = c->rh = wa->height; c->h = c->rh = wa->height;
c->oldborder = wa->border_width; c->oldborder = wa->border_width;
c->display = disp; c->display = disp;
if(c->w == sw && c->h == sh) if(c->w == DisplayWidth(disp, DefaultScreen(disp))
&& c->h == DisplayHeight(disp, DefaultScreen(disp)))
{ {
c->x = sx; c->x = sx;
c->y = sy; c->y = sy;
@ -438,10 +439,10 @@ resize(Client * c, int x, int y, int w, int h, Bool sizehints)
if(w <= 0 || h <= 0) if(w <= 0 || h <= 0)
return; return;
/* offscreen appearance fixes */ /* offscreen appearance fixes */
if(x > sw) if(x > DisplayWidth(c->display, DefaultScreen(c->display)))
x = sw - w - 2 * c->border; x = DisplayWidth(c->display, DefaultScreen(c->display)) - w - 2 * c->border;
if(y > sh) if(y > DisplayHeight(c->display, DefaultScreen(c->display)))
y = sh - h - 2 * c->border; y = DisplayHeight(c->display, DefaultScreen(c->display)) - h - 2 * c->border;
if(x + w + 2 * c->border < sx) if(x + w + 2 * c->border < sx)
x = sx; x = sx;
if(y + h + 2 * c->border < sy) if(y + h + 2 * c->border < sy)

7
draw.c
View File

@ -2,7 +2,6 @@
#include "layout.h" #include "layout.h"
extern int sw; /* screen geometry */
extern Window barwin; extern Window barwin;
extern DC dc; /* global draw context */ extern DC dc; /* global draw context */
extern Client *clients, *sel, *stack; /* global client list and stack */ extern Client *clients, *sel, *stack; /* global client list and stack */
@ -130,11 +129,11 @@ drawstatus(Display *disp, jdwm_config * jdwmconf)
drawtext(disp, jdwmconf->current_layout->symbol, dc.norm); drawtext(disp, jdwmconf->current_layout->symbol, dc.norm);
x = dc.x + dc.w; x = dc.x + dc.w;
dc.w = textw(jdwmconf->statustext); dc.w = textw(jdwmconf->statustext);
dc.x = sw - dc.w; dc.x = DisplayWidth(disp, DefaultScreen(disp)) - dc.w;
if(dc.x < x) if(dc.x < x)
{ {
dc.x = x; dc.x = x;
dc.w = sw - x; dc.w = DisplayWidth(disp, DefaultScreen(disp)) - x;
} }
drawtext(disp, jdwmconf->statustext, dc.norm); drawtext(disp, jdwmconf->statustext, dc.norm);
if((dc.w = dc.x - x) > jdwmconf->statusbar.height) if((dc.w = dc.x - x) > jdwmconf->statusbar.height)
@ -148,6 +147,6 @@ drawstatus(Display *disp, jdwm_config * jdwmconf)
else else
drawtext(disp, NULL, dc.norm); drawtext(disp, NULL, dc.norm);
} }
XCopyArea(disp, dc.drawable, barwin, dc.gc, 0, 0, sw, jdwmconf->statusbar.height, 0, 0); XCopyArea(disp, dc.drawable, barwin, dc.gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), jdwmconf->statusbar.height, 0, 0);
XSync(disp, False); XSync(disp, False);
} }

20
event.c
View File

@ -13,7 +13,7 @@
#include "layouts/floating.h" #include "layouts/floating.h"
/* extern */ /* extern */
extern int screen, sw, sh; /* screen geometry */ extern int screen; /* screen geometry */
extern int wax, way, wah, waw; /* windowarea geometry */ extern int wax, way, wah, waw; /* windowarea geometry */
extern Window barwin; extern Window barwin;
extern DC dc; /* global draw context */ extern DC dc; /* global draw context */
@ -203,10 +203,10 @@ handle_event_configurerequest(XEvent * e, jdwm_config *jdwmconf __attribute__ ((
c->w = ev->width; c->w = ev->width;
if(ev->value_mask & CWHeight) if(ev->value_mask & CWHeight)
c->h = ev->height; c->h = ev->height;
if((c->x + c->w) > sw && c->isfloating) if((c->x + c->w) > DisplayWidth(c->display, DefaultScreen(c->display)) && c->isfloating)
c->x = sw / 2 - c->w / 2; /* center in x direction */ c->x = DisplayWidth(c->display, DefaultScreen(c->display)) / 2 - c->w / 2; /* center in x direction */
if((c->y + c->h) > sh && c->isfloating) if((c->y + c->h) > DisplayHeight(c->display, DefaultScreen(c->display)) && c->isfloating)
c->y = sh / 2 - c->h / 2; /* center in y direction */ c->y = DisplayHeight(c->display, DefaultScreen(c->display)) / 2 - c->h / 2; /* center in y direction */
if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight))) if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight)))
configure(c); configure(c);
if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags)) if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags))
@ -234,13 +234,13 @@ handle_event_configurenotify(XEvent * e, jdwm_config *jdwmconf)
{ {
XConfigureEvent *ev = &e->xconfigure; XConfigureEvent *ev = &e->xconfigure;
if(ev->window == DefaultRootWindow(e->xany.display) && (ev->width != sw || ev->height != sh)) if(ev->window == DefaultRootWindow(e->xany.display) && (ev->width != DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)) || ev->height != DisplayHeight(e->xany.display, DefaultScreen(e->xany.display))))
{ {
sw = ev->width; DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)) = ev->width;
sh = ev->height; DisplayHeight(e->xany.display, DefaultScreen(e->xany.display)) = ev->height;
XFreePixmap(e->xany.display, dc.drawable); XFreePixmap(e->xany.display, dc.drawable);
dc.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), sw, jdwmconf->statusbar.height, DefaultDepth(e->xany.display, screen)); dc.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)), jdwmconf->statusbar.height, DefaultDepth(e->xany.display, screen));
XResizeWindow(e->xany.display, barwin, sw, jdwmconf->statusbar.height); XResizeWindow(e->xany.display, barwin, DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)), jdwmconf->statusbar.height);
updatebarpos(e->xany.display, jdwmconf->statusbar); updatebarpos(e->xany.display, jdwmconf->statusbar);
arrange(e->xany.display, jdwmconf); arrange(e->xany.display, jdwmconf);
} }

12
jdwm.c
View File

@ -18,7 +18,7 @@
#include "layout.h" #include "layout.h"
#include "tag.h" #include "tag.h"
int screen, sx, sy, sw, sh, wax, way, waw, wah; int screen, sx, sy, wax, way, waw, wah;
Atom wmatom[WMLast], netatom[NetLast]; Atom wmatom[WMLast], netatom[NetLast];
Client *clients = NULL; Client *clients = NULL;
Client *sel = NULL; Client *sel = NULL;
@ -170,14 +170,12 @@ setup(Display *disp, jdwm_config *jdwmconf)
compileregs(jdwmconf); compileregs(jdwmconf);
/* geometry */ /* geometry */
sx = sy = 0; sx = sy = 0;
sw = DisplayWidth(disp, screen);
sh = DisplayHeight(disp, screen);
/* bar */ /* bar */
dc.h = jdwmconf->statusbar.height = dc.font.height + 2; dc.h = jdwmconf->statusbar.height = dc.font.height + 2;
wa.override_redirect = 1; wa.override_redirect = 1;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | ExposureMask; wa.event_mask = ButtonPressMask | ExposureMask;
barwin = XCreateWindow(disp, DefaultRootWindow(disp), sx, sy, sw, jdwmconf->statusbar.height, 0, barwin = XCreateWindow(disp, DefaultRootWindow(disp), sx, sy, DisplayWidth(disp, DefaultScreen(disp)), jdwmconf->statusbar.height, 0,
DefaultDepth(disp, screen), CopyFromParent, DefaultDepth(disp, screen), CopyFromParent,
DefaultVisual(disp, screen), DefaultVisual(disp, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
@ -185,7 +183,7 @@ setup(Display *disp, jdwm_config *jdwmconf)
updatebarpos(disp, jdwmconf->statusbar); updatebarpos(disp, jdwmconf->statusbar);
XMapRaised(disp, barwin); XMapRaised(disp, barwin);
/* pixmap for everything */ /* pixmap for everything */
dc.drawable = XCreatePixmap(disp, DefaultRootWindow(disp), sw, jdwmconf->statusbar.height, DefaultDepth(disp, screen)); dc.drawable = XCreatePixmap(disp, DefaultRootWindow(disp), DisplayWidth(disp, DefaultScreen(disp)), jdwmconf->statusbar.height, DefaultDepth(disp, screen));
dc.gc = XCreateGC(disp, DefaultRootWindow(disp), 0, 0); dc.gc = XCreateGC(disp, DefaultRootWindow(disp), 0, 0);
XSetLineAttributes(disp, dc.gc, 1, LineSolid, CapButt, JoinMiter); XSetLineAttributes(disp, dc.gc, 1, LineSolid, CapButt, JoinMiter);
if(!dc.font.set) if(!dc.font.set)
@ -221,8 +219,8 @@ updatebarpos(Display *disp, Statusbar statusbar)
wax = sx; wax = sx;
way = sy; way = sy;
wah = sh; wah = DisplayHeight(disp, DefaultScreen(disp));
waw = sw; waw = DisplayWidth(disp, DefaultScreen(disp));
switch (statusbar.position) switch (statusbar.position)
{ {
default: default: