remove global bh/blw and add a Statusbar type

This commit is contained in:
Julien Danjou 2007-09-07 16:13:59 +02:00
parent 2eaadb39e7
commit a6a705dd85
9 changed files with 33 additions and 29 deletions

View File

@ -17,8 +17,6 @@
#include "layouts/spiral.h"
#include "layouts/floating.h"
int blw = 0;
/* static */
static void initfont(const char *, Display *, DC *);
static unsigned long initcolor(const char *colstr, Display *, int);
@ -165,6 +163,8 @@ static void
set_default_config(jdwm_config *jdwmconf)
{
strcpy(jdwmconf->statustext, "jdwm-" VERSION);
jdwmconf->statusbar.width = 0;
jdwmconf->statusbar.height = 0;
}
/** Parse configuration file and initialize some stuff
@ -217,8 +217,8 @@ parse_config(Display * disp, int scr, DC * drawcontext, jdwm_config *jdwmconf)
eprint("unknown layout in configuration file\n");
j = textw(jdwmconf->layouts[i].symbol);
if(j > blw)
blw = j;
if(j > jdwmconf->statusbar.width)
jdwmconf->statusbar.width = j;
}
jdwmconf->layouts[i].symbol = NULL;

View File

@ -54,6 +54,13 @@ typedef struct
const char *arg;
} Key;
/** Status bar */
typedef struct
{
int width;
int height;
} Statusbar;
/** Main configuration structure */
struct jdwm_config
{
@ -101,6 +108,8 @@ struct jdwm_config
char statustext[256];
/** Current layout */
Layout * current_layout;
/** Status bar */
Statusbar statusbar;
};
void parse_config(Display *, int, DC *, jdwm_config *); /* parse configuration file */

7
draw.c
View File

@ -3,7 +3,6 @@
#include "layout.h"
extern int sw; /* screen geometry */
extern int bh, blw; /* bar height, bar layout label width */
extern Window barwin;
extern DC dc; /* global draw context */
extern Client *clients, *sel, *stack; /* global client list and stack */
@ -127,7 +126,7 @@ drawstatus(Display *disp, jdwm_config * jdwmconf)
}
dc.x += dc.w;
}
dc.w = blw;
dc.w = jdwmconf->statusbar.width;
drawtext(disp, jdwmconf->current_layout->symbol, dc.norm);
x = dc.x + dc.w;
dc.w = textw(jdwmconf->statustext);
@ -138,7 +137,7 @@ drawstatus(Display *disp, jdwm_config * jdwmconf)
dc.w = sw - x;
}
drawtext(disp, jdwmconf->statustext, dc.norm);
if((dc.w = dc.x - x) > bh)
if((dc.w = dc.x - x) > jdwmconf->statusbar.height)
{
dc.x = x;
if(sel)
@ -149,6 +148,6 @@ drawstatus(Display *disp, jdwm_config * jdwmconf)
else
drawtext(disp, NULL, dc.norm);
}
XCopyArea(disp, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
XCopyArea(disp, dc.drawable, barwin, dc.gc, 0, 0, sw, jdwmconf->statusbar.height, 0, 0);
XSync(disp, False);
}

View File

@ -15,7 +15,6 @@
/* extern */
extern int screen, sw, sh; /* screen geometry */
extern int wax, way, wah, waw; /* windowarea geometry */
extern int bh, blw; /* bar height, bar layout label width */
extern Window barwin;
extern DC dc; /* global draw context */
extern Cursor cursor[CurLast];
@ -152,7 +151,7 @@ handle_event_buttonpress(XEvent * e, jdwm_config *jdwmconf)
return;
}
}
if((ev->x < x + blw) && ev->button == Button1)
if((ev->x < x + jdwmconf->statusbar.width) && ev->button == Button1)
uicb_setlayout(e->xany.display, jdwmconf, NULL);
}
else if((c = getclient(ev->window)))
@ -240,9 +239,9 @@ handle_event_configurenotify(XEvent * e, jdwm_config *jdwmconf)
sw = ev->width;
sh = ev->height;
XFreePixmap(e->xany.display, dc.drawable);
dc.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), sw, bh, DefaultDepth(e->xany.display, screen));
XResizeWindow(e->xany.display, barwin, sw, bh);
updatebarpos(e->xany.display, jdwmconf->current_bpos);
dc.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), sw, jdwmconf->statusbar.height, DefaultDepth(e->xany.display, screen));
XResizeWindow(e->xany.display, barwin, sw, jdwmconf->statusbar.height);
updatebarpos(e->xany.display, jdwmconf->statusbar, jdwmconf->current_bpos);
arrange(e->xany.display, jdwmconf);
}
}

19
jdwm.c
View File

@ -19,7 +19,6 @@
#include "tag.h"
int screen, sx, sy, sw, sh, wax, way, waw, wah;
int bh;
Atom jdwmprops, wmatom[WMLast], netatom[NetLast];
Client *clients = NULL;
Client *sel = NULL;
@ -175,19 +174,19 @@ setup(Display *disp, jdwm_config *jdwmconf)
sw = DisplayWidth(disp, screen);
sh = DisplayHeight(disp, screen);
/* bar */
dc.h = bh = dc.font.height + 2;
dc.h = jdwmconf->statusbar.height = dc.font.height + 2;
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | ExposureMask;
barwin = XCreateWindow(disp, DefaultRootWindow(disp), sx, sy, sw, bh, 0,
barwin = XCreateWindow(disp, DefaultRootWindow(disp), sx, sy, sw, jdwmconf->statusbar.height, 0,
DefaultDepth(disp, screen), CopyFromParent,
DefaultVisual(disp, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
XDefineCursor(disp, barwin, cursor[CurNormal]);
updatebarpos(disp, jdwmconf->current_bpos);
updatebarpos(disp, jdwmconf->statusbar, jdwmconf->current_bpos);
XMapRaised(disp, barwin);
/* pixmap for everything */
dc.drawable = XCreatePixmap(disp, DefaultRootWindow(disp), sw, bh, DefaultDepth(disp, screen));
dc.drawable = XCreatePixmap(disp, DefaultRootWindow(disp), sw, jdwmconf->statusbar.height, DefaultDepth(disp, screen));
dc.gc = XCreateGC(disp, DefaultRootWindow(disp), 0, 0);
XSetLineAttributes(disp, dc.gc, 1, LineSolid, CapButt, JoinMiter);
if(!dc.font.set)
@ -217,7 +216,7 @@ uicb_quit(Display *disp __attribute__ ((unused)),
}
void
updatebarpos(Display *disp, int bpos)
updatebarpos(Display *disp, Statusbar statusbar, int bpos)
{
XEvent ev;
@ -228,16 +227,16 @@ updatebarpos(Display *disp, int bpos)
switch (bpos)
{
default:
wah -= bh;
way += bh;
wah -= statusbar.height;
way += statusbar.height;
XMoveWindow(disp, barwin, sx, sy);
break;
case BarBot:
wah -= bh;
wah -= statusbar.height;
XMoveWindow(disp, barwin, sx, sy + wah);
break;
case BarOff:
XMoveWindow(disp, barwin, sx, sy - bh);
XMoveWindow(disp, barwin, sx, sy - statusbar.height);
break;
}
XSync(disp, False);

2
jdwm.h
View File

@ -42,7 +42,7 @@ enum
{ WMProtocols, WMDelete, WMName, WMState, WMLast }; /* default atoms */
Bool gettextprop(Display *, Window, Atom, char *, unsigned int); /* return text property, UTF-8 compliant */
void updatebarpos(Display *, int); /* updates the bar position */
void updatebarpos(Display *, Statusbar, int); /* updates the bar position */
void uicb_quit(Display *, jdwm_config *, const char *); /* quit jdwm nicely */
int xerror(Display *, XErrorEvent *); /* jdwm's X error handler */

View File

@ -178,7 +178,7 @@ uicb_togglebar(Display *disp,
jdwmconf->current_bpos = (jdwmconf->bpos == BarOff) ? BarTop : jdwmconf->bpos;
else
jdwmconf->current_bpos = BarOff;
updatebarpos(disp, jdwmconf->current_bpos);
updatebarpos(disp, jdwmconf->statusbar, jdwmconf->current_bpos);
arrange(disp, jdwmconf);
}

View File

@ -5,7 +5,6 @@
#include "tag.h"
extern int wah, waw; /* windowarea geometry */
extern int bh, bpos; /* bar height, bar position */
extern Client *clients; /* global client list and stack */
extern DC dc;
@ -37,7 +36,7 @@ grid(Display *disp, jdwm_config *jdwmconf)
continue;
c->ismax = False;
cx = (i / rows) * cw;
cy = (i % rows) * ch + (jdwmconf->current_bpos == BarTop ? bh : 0); // bh? adjust
cy = (i % rows) * ch + (jdwmconf->current_bpos == BarTop ? jdwmconf->statusbar.height : 0); // bh? adjust
/* adjust height/width of last row/column's windows */
ah = ((i + 1) % rows == 0) ? wah - ch * rows : 0;
aw = (i >= rows * (cols - 1)) ? waw - cw * cols : 0;

View File

@ -9,7 +9,6 @@
/* extern */
extern int wax, way, wah, waw; /* windowarea geometry */
extern int bh; /* bar height */
extern Client *sel, *clients;
/* static */
@ -85,7 +84,7 @@ _tile(jdwm_config *jdwmconf, const Bool right)
mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;
mw = (n <= nmaster) ? waw : mwfact * waw;
th = (n > nmaster) ? wah / (n - nmaster) : 0;
if(n > nmaster && th < bh)
if(n > nmaster && th < jdwmconf->statusbar.height)
th = wah;
nx = wax;