From dfd84f9bf3b9d949412a73bc62a43109b340d395 Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Wed, 12 Jul 2006 15:17:22 +0200 Subject: [PATCH] simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable) --- bar.c | 17 +++++----- client.c | 64 ++++++++++++++++++++++++------------- cmd.c | 12 ++++--- config.h | 8 ++--- draw.c | 45 +++++++++++++------------- draw.h | 8 ++--- event.c | 17 ++++------ font.c | 81 ---------------------------------------------- menu.c | 97 +++++++++++++++++++++++++++----------------------------- mouse.c | 20 ++++++------ wm.c | 23 ++++++-------- wm.h | 7 ++-- 12 files changed, 164 insertions(+), 235 deletions(-) delete mode 100644 font.c diff --git a/bar.c b/bar.c index 1f12512..f70a246 100644 --- a/bar.c +++ b/bar.c @@ -8,23 +8,22 @@ void draw_bar() { - brush.rect = barrect; - brush.rect.x = brush.rect.y = 0; + brush.x = brush.y = 0; + brush.w = bw; + brush.h = bh; draw(dpy, &brush, False, NULL); if(stack) { - brush.rect.width = textwidth(&brush.font, stack->name) + labelheight(&brush.font); + brush.w = textw(&brush.font, stack->name) + bh; swap((void **)&brush.fg, (void **)&brush.bg); draw(dpy, &brush, True, stack->name); swap((void **)&brush.fg, (void **)&brush.bg); - brush.rect.x += brush.rect.width; + brush.x += brush.w; } - brush.rect.width = textwidth(&brush.font, statustext) + labelheight(&brush.font); - brush.rect.x = barrect.x + barrect.width - brush.rect.width; + brush.w = textw(&brush.font, statustext) + bh; + brush.x = bx + bw - brush.w; draw(dpy, &brush, False, statustext); - - XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, - barrect.height, 0, 0); + XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0); XFlush(dpy); } diff --git a/client.c b/client.c index ee659c4..84fbce5 100644 --- a/client.c +++ b/client.c @@ -10,7 +10,16 @@ #include "util.h" #include "wm.h" -#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask) +static void +resize_title(Client *c) +{ + c->tw = textw(&brush.font, c->name) + bh; + if(c->tw > c->w) + c->tw = c->w + 2; + c->tx = c->x + c->w - c->tw + 2; + c->ty = c->y; + XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th); +} void update_name(Client *c) @@ -37,6 +46,7 @@ update_name(Client *c) } } XFree(name.value); + resize_title(c); } void @@ -73,27 +83,38 @@ update_size(Client *c) c->minw = c->minh = 0; } +void +raise(Client *c) +{ + XRaiseWindow(dpy, c->win); + XRaiseWindow(dpy, c->title); +} + +void +lower(Client *c) +{ + XLowerWindow(dpy, c->title); + XLowerWindow(dpy, c->win); +} + void focus(Client *c) { Client **l, *old; old = stack; - for(l=&stack; *l && *l != c; l=&(*l)->snext); + for(l = &stack; *l && *l != c; l = &(*l)->snext); eassert(*l == c); *l = c->snext; c->snext = stack; stack = c; - XRaiseWindow(dpy, c->win); - XRaiseWindow(dpy, c->title); - XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); if(old && old != c) { XMapWindow(dpy, old->title); draw_client(old); } XUnmapWindow(dpy, c->title); - draw_bar(); - discard_events(EnterWindowMask); + draw_client(old); + XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XFlush(dpy); } @@ -107,13 +128,16 @@ manage(Window w, XWindowAttributes *wa) c->win = w; c->tx = c->x = wa->x; c->ty = c->y = wa->y; + if(c->y < bh) + c->ty = c->y += bh; c->tw = c->w = wa->width; c->h = wa->height; - c->th = barrect.height; + c->th = bh; update_size(c); XSetWindowBorderWidth(dpy, c->win, 1); XSetWindowBorder(dpy, c->win, brush.border); - XSelectInput(dpy, c->win, CLIENT_MASK); + XSelectInput(dpy, c->win, + StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XGetTransientForHint(dpy, c->win, &c->trans); twa.override_redirect = 1; twa.background_pixmap = ParentRelative; @@ -130,8 +154,8 @@ manage(Window w, XWindowAttributes *wa) *l = c; c->snext = stack; stack = c; - XMapWindow(dpy, c->win); - XMapWindow(dpy, c->title); + XMapRaised(dpy, c->win); + XMapRaised(dpy, c->title); XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask, @@ -147,6 +171,7 @@ resize(Client *c) { XConfigureEvent e; + resize_title(c); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); e.type = ConfigureNotify; e.event = c->win; @@ -158,9 +183,7 @@ resize(Client *c) e.border_width = 0; e.above = None; e.override_redirect = False; - XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e); - XSelectInput(dpy, c->win, CLIENT_MASK); XFlush(dpy); } @@ -219,17 +242,14 @@ getclient(Window w) void draw_client(Client *c) { - if(c == stack) + if(c == stack) { draw_bar(); + return; + } - c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font); - c->tx = c->x + c->w - c->tw + 2; - c->ty = c->y; - XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th); - - brush.rect.x = brush.rect.y = 0; - brush.rect.width = c->tw; - brush.rect.height = c->th; + brush.x = brush.y = 0; + brush.w = c->tw; + brush.h = c->th; draw(dpy, &brush, True, c->name); XCopyArea(dpy, brush.drawable, c->title, brush.gc, diff --git a/cmd.c b/cmd.c index c14c3e6..baa3ae9 100644 --- a/cmd.c +++ b/cmd.c @@ -23,16 +23,18 @@ void sel(void *aux) { const char *arg = aux; - Client *c; + Client *c = NULL; if(!arg || !stack) return; if(!strncmp(arg, "next", 5)) - focus(stack->snext ? stack->snext : stack); - else if(!strncmp(arg, "prev", 5)) { + c = stack->snext ? stack->snext : stack; + else if(!strncmp(arg, "prev", 5)) for(c = stack; c && c->snext; c = c->snext); - focus(c ? c : stack); - } + if(!c) + c = stack; + raise(c); + focus(c); } void diff --git a/config.h b/config.h index ec633c3..9d28e75 100644 --- a/config.h +++ b/config.h @@ -4,7 +4,7 @@ */ #define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" -#define BGCOLOR "#0c0c33" -#define FGCOLOR "#b2c8cd" -#define BORDERCOLOR "#3030c0" -#define STATUSDELAY 10 /* milliseconds */ +#define BGCOLOR "#666699" +#define FGCOLOR "#ffffff" +#define BORDERCOLOR "#9999CC" +#define STATUSDELAY 10 /* seconds */ diff --git a/draw.c b/draw.c index a3c526e..c148362 100644 --- a/draw.c +++ b/draw.c @@ -15,16 +15,16 @@ drawborder(Display *dpy, Brush *b) XPoint points[5]; XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter); XSetForeground(dpy, b->gc, b->border); - points[0].x = b->rect.x; - points[0].y = b->rect.y; - points[1].x = b->rect.width - 1; + points[0].x = b->x; + points[0].y = b->y; + points[1].x = b->w - 1; points[1].y = 0; points[2].x = 0; - points[2].y = b->rect.height - 1; - points[3].x = -(b->rect.width - 1); + points[2].y = b->h - 1; + points[3].x = -(b->w - 1); points[3].y = 0; points[4].x = 0; - points[4].y = -(b->rect.height - 1); + points[4].y = -(b->h - 1); XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious); } @@ -34,9 +34,10 @@ draw(Display *dpy, Brush *b, Bool border, const char *text) unsigned int x, y, w, h, len; static char buf[256]; XGCValues gcv; + XRectangle r = { b->x, b->y, b->w, b->h }; XSetForeground(dpy, b->gc, b->bg); - XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1); + XFillRectangles(dpy, b->drawable, b->gc, &r, 1); if(border) drawborder(dpy, b); @@ -51,14 +52,14 @@ draw(Display *dpy, Brush *b, Bool border, const char *text) buf[len] = 0; h = b->font.ascent + b->font.descent; - y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent; - x = b->rect.x + (h / 2); + y = b->y + (b->h / 2) - (h / 2) + b->font.ascent; + x = b->x + (h / 2); /* shorten text if necessary */ - while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h) + while(len && (w = textnw(&b->font, buf, len)) > b->w - h) buf[--len] = 0; - if(w > b->rect.width) + if(w > b->w) return; /* too long */ gcv.foreground = b->fg; @@ -94,20 +95,26 @@ loadcolors(Display *dpy, int screen, Brush *b, } unsigned int -textwidth_l(Fnt *font, char *text, unsigned int len) +textnw(Fnt *font, char *text, unsigned int len) { + XRectangle r; if(font->set) { - XRectangle r; - XmbTextExtents(font->set, text, len, 0, &r); + XmbTextExtents(font->set, text, len, NULL, &r); return r.width; } return XTextWidth(font->xfont, text, len); } unsigned int -textwidth(Fnt *font, char *text) +textw(Fnt *font, char *text) { - return textwidth_l(font, text, strlen(text)); + return textnw(font, text, strlen(text)); +} + +unsigned int +texth(Fnt *font) +{ + return font->height + 4; } void @@ -162,9 +169,3 @@ loadfont(Display *dpy, Fnt *font, const char *fontstr) } font->height = font->ascent + font->descent; } - -unsigned int -labelheight(Fnt *font) -{ - return font->height + 4; -} diff --git a/draw.h b/draw.h index 6c3d886..4cd6fb1 100644 --- a/draw.h +++ b/draw.h @@ -20,7 +20,7 @@ struct Fnt { struct Brush { GC gc; Drawable drawable; - XRectangle rect; + int x, y, w, h; Fnt font; unsigned long bg; unsigned long fg; @@ -31,6 +31,6 @@ extern void draw(Display *dpy, Brush *b, Bool border, const char *text); extern void loadcolors(Display *dpy, int screen, Brush *b, const char *bg, const char *fg, const char *bo); extern void loadfont(Display *dpy, Fnt *font, const char *fontstr); -extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len); -extern unsigned int textwidth(Fnt *font, char *text); -extern unsigned int labelheight(Fnt *font); +extern unsigned int textnw(Fnt *font, char *text, unsigned int len); +extern unsigned int textw(Fnt *font, char *text); +extern unsigned int texth(Fnt *font); diff --git a/event.c b/event.c index 604420d..1db3d96 100644 --- a/event.c +++ b/event.c @@ -37,13 +37,11 @@ void (*handler[LASTEvent]) (XEvent *) = { [UnmapNotify] = unmapnotify }; -unsigned int +void discard_events(long even_mask) { XEvent ev; - unsigned int n = 0; - while(XCheckMaskEvent(dpy, even_mask, &ev)) n++; - return n; + while(XCheckMaskEvent(dpy, even_mask, &ev)); } static void @@ -53,6 +51,7 @@ buttonpress(XEvent *e) Client *c; if((c = getclient(ev->window))) { + raise(c); switch(ev->button) { default: break; @@ -60,7 +59,7 @@ buttonpress(XEvent *e) mmove(c); break; case Button2: - XLowerWindow(dpy, c->win); + lower(c); break; case Button3: mresize(c); @@ -122,10 +121,8 @@ enternotify(XEvent *e) if((c = getclient(ev->window))) focus(c); - else if(ev->window == root) { + else if(ev->window == root) sel_screen = True; - /*draw_frames();*/ - } } static void @@ -133,10 +130,8 @@ leavenotify(XEvent *e) { XCrossingEvent *ev = &e->xcrossing; - if((ev->window == root) && !ev->same_screen) { + if((ev->window == root) && !ev->same_screen) sel_screen = True; - /*draw_frames();*/ - } } static void diff --git a/font.c b/font.c deleted file mode 100644 index a6b8225..0000000 --- a/font.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ - -#include -#include -#include -#include - -unsigned int -textwidth_l(BlitzFont *font, char *text, unsigned int len) -{ - if(font->set) { - XRectangle r; - XmbTextExtents(font->set, text, len, nil, &r); - return r.width; - } - return XTextWidth(font->xfont, text, len); -} - -unsigned int -textwidth(BlitzFont *font, char *text) -{ - return blitz_textwidth_l(font, text, strlen(text)); -} - -void -loadfont(Blitz *blitz, BlitzFont *font) -{ - char *fontname = font->fontstr; - char **missing = nil, *def = "?"; - int n; - - setlocale(LC_ALL, ""); - if(font->set) - XFreeFontSet(blitz->dpy, font->set); - font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); - if(missing) { - while(n--) - fprintf(stderr, "missing fontset: %s\n", missing[n]); - XFreeStringList(missing); - if(font->set) { - XFreeFontSet(blitz->dpy, font->set); - font->set = nil; - } - } - if(font->set) { - XFontSetExtents *font_extents; - XFontStruct **xfonts; - char **font_names; - unsigned int i; - - font->ascent = font->descent = 0; - font_extents = XExtentsOfFontSet(font->set); - n = XFontsOfFontSet(font->set, &xfonts, &font_names); - for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) { - if(font->ascent < (*xfonts)->ascent) - font->ascent = (*xfonts)->ascent; - if(font->descent < (*xfonts)->descent) - font->descent = (*xfonts)->descent; - xfonts++; - } - } - else { - if(font->xfont) - XFreeFont(blitz->dpy, font->xfont); - font->xfont = nil; - font->xfont = XLoadQueryFont(blitz->dpy, fontname); - if (!font->xfont) { - fontname = "fixed"; - font->xfont = XLoadQueryFont(blitz->dpy, fontname); - } - if (!font->xfont) { - fprintf(stderr, "%s", "error, cannot load 'fixed' font\n"); - exit(1); - } - font->ascent = font->xfont->ascent; - font->descent = font->xfont->descent; - } -} diff --git a/menu.c b/menu.c index e09d3b7..2392ed5 100644 --- a/menu.c +++ b/menu.c @@ -31,7 +31,6 @@ struct Item { static Display *dpy; static Window root; static Window win; -static XRectangle rect; static Bool done = False; static Item *allitem = NULL; /* first of all items */ @@ -41,14 +40,14 @@ static Item *nextoff = NULL; static Item *prevoff = NULL; static Item *curroff = NULL; -static int screen; +static int screen, mx, my, mw, mh; static char *title = NULL; static char text[4096]; static int ret = 0; static int nitem = 0; static unsigned int cmdw = 0; -static unsigned int twidth = 0; -static unsigned int cwidth = 0; +static unsigned int tw = 0; +static unsigned int cw = 0; static const int seek = 30; /* 30px */ static Brush brush = {0}; @@ -74,21 +73,21 @@ update_offsets() return; for(nextoff = curroff; nextoff; nextoff=nextoff->right) { - tw = textwidth(&brush.font, nextoff->text); - if(tw > rect.width / 3) - tw = rect.width / 3; + tw = textw(&brush.font, nextoff->text); + if(tw > mw / 3) + tw = mw / 3; w += tw + brush.font.height; - if(w > rect.width) + if(w > mw) break; } w = cmdw + 2 * seek; for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) { - tw = textwidth(&brush.font, prevoff->left->text); - if(tw > rect.width / 3) - tw = rect.width / 3; + tw = textw(&brush.font, prevoff->left->text); + if(tw > mw / 3) + tw = mw / 3; w += tw + brush.font.height; - if(w > rect.width) + if(w > mw) break; } } @@ -103,9 +102,9 @@ update_items(char *pattern) return; if(!title || *pattern) - cmdw = cwidth; + cmdw = cw; else - cmdw = twidth; + cmdw = tw; item = j = NULL; nitem = 0; @@ -143,42 +142,40 @@ update_items(char *pattern) static void draw_menu() { - unsigned int offx = 0; Item *i; - brush.rect = rect; - brush.rect.x = 0; - brush.rect.y = 0; + brush.x = 0; + brush.y = 0; + brush.w = mw; + brush.h = mh; draw(dpy, &brush, False, 0); /* print command */ if(!title || text[0]) { - cmdw = cwidth; + cmdw = cw; if(cmdw && item) - brush.rect.width = cmdw; + brush.w = cmdw; draw(dpy, &brush, False, text); } else { - cmdw = twidth; - brush.rect.width = cmdw; + cmdw = tw; + brush.w = cmdw; draw(dpy, &brush, False, title); } - offx += brush.rect.width; + brush.x += brush.w; if(curroff) { - brush.rect.x = offx; - brush.rect.width = seek; - offx += brush.rect.width; + brush.w = seek; draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0); + brush.x += brush.w; /* determine maximum items */ for(i = curroff; i != nextoff; i=i->right) { brush.border = False; - brush.rect.x = offx; - brush.rect.width = textwidth(&brush.font, i->text); - if(brush.rect.width > rect.width / 3) - brush.rect.width = rect.width / 3; - brush.rect.width += brush.font.height; + brush.w = textw(&brush.font, i->text); + if(brush.w > mw / 3) + brush.w = mw / 3; + brush.w += brush.font.height; if(sel == i) { swap((void **)&brush.fg, (void **)&brush.bg); draw(dpy, &brush, True, i->text); @@ -186,15 +183,14 @@ draw_menu() } else draw(dpy, &brush, False, i->text); - offx += brush.rect.width; + brush.x += brush.w; } - brush.rect.x = rect.width - seek; - brush.rect.width = seek; + brush.x = mw - seek; + brush.w = seek; draw(dpy, &brush, False, nextoff ? ">" : 0); } - XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width, - rect.height, 0, 0); + XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0); XFlush(dpy); } @@ -399,36 +395,35 @@ main(int argc, char *argv[]) wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - rect.width = DisplayWidth(dpy, screen); - rect.height = labelheight(&brush.font); - rect.y = DisplayHeight(dpy, screen) - rect.height; - rect.x = 0; + mx = my = 0; + mw = DisplayWidth(dpy, screen); + mh = texth(&brush.font); - win = XCreateWindow(dpy, root, rect.x, rect.y, - rect.width, rect.height, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), + win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, + DefaultDepth(dpy, screen), CopyFromParent, + DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); XFlush(dpy); /* pixmap */ brush.gc = XCreateGC(dpy, root, 0, 0); - brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height, + brush.drawable = XCreatePixmap(dpy, win, mw, mh, DefaultDepth(dpy, screen)); XFlush(dpy); if(maxname) - cwidth = textwidth(&brush.font, maxname) + brush.font.height; - if(cwidth > rect.width / 3) - cwidth = rect.width / 3; + cw = textw(&brush.font, maxname) + brush.font.height; + if(cw > mw / 3) + cw = mw / 3; if(title) { - twidth = textwidth(&brush.font, title) + brush.font.height; - if(twidth > rect.width / 3) - twidth = rect.width / 3; + tw = textw(&brush.font, title) + brush.font.height; + if(tw > mw / 3) + tw = mw / 3; } - cmdw = title ? twidth : cwidth; + cmdw = title ? tw : cw; text[0] = 0; update_items(text); diff --git a/mouse.c b/mouse.c index 577f23c..896d6b0 100644 --- a/mouse.c +++ b/mouse.c @@ -45,21 +45,21 @@ mresize(Client *c) if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, None, cursor[CurResize], CurrentTime) != GrabSuccess) return; - XGrabServer(dpy); XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); for(;;) { - XMaskEvent(dpy, MouseMask, &ev); + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); switch(ev.type) { default: break; + case Expose: + handler[Expose](&ev); + break; case MotionNotify: - XUngrabServer(dpy); + XFlush(dpy); mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); XResizeWindow(dpy, c->win, c->w, c->h); - XGrabServer(dpy); break; case ButtonRelease: resize(c); - XUngrabServer(dpy); XUngrabPointer(dpy, CurrentTime); return; } @@ -80,21 +80,21 @@ mmove(Client *c) None, cursor[CurMove], CurrentTime) != GrabSuccess) return; XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); - XGrabServer(dpy); for(;;) { - XMaskEvent(dpy, MouseMask, &ev); + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); switch (ev.type) { default: break; + case Expose: + handler[Expose](&ev); + break; case MotionNotify: - XUngrabServer(dpy); + XFlush(dpy); c->x = old_cx + (ev.xmotion.x - x1); c->y = old_cy + (ev.xmotion.y - y1); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); - XGrabServer(dpy); break; case ButtonRelease: resize(c); - XUngrabServer(dpy); XUngrabPointer(dpy, CurrentTime); return; } diff --git a/wm.c b/wm.c index 82b2dee..f0069d2 100644 --- a/wm.c +++ b/wm.c @@ -23,12 +23,11 @@ Display *dpy; Window root, barwin; Atom wm_atom[WMLast], net_atom[NetLast]; Cursor cursor[CurLast]; -XRectangle rect, barrect; Bool running = True; Bool sel_screen; char statustext[1024], tag[256]; -int screen; +int screen, sx, sy, sw, sh, bx, by, bw, bh; Brush brush = {0}; Client *clients = NULL; @@ -39,7 +38,7 @@ static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. static int (*x_error_handler) (Display *, XErrorEvent *); static const char *status[] = { - "sh", "-c", "echo -n `date '+%Y/%m/%d %H:%M'`" + "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" " `uptime | sed 's/.*://; s/,//g'`" " `acpi | awk '{print $4}' | sed 's/,//'`", 0 }; @@ -220,9 +219,9 @@ main(int argc, char *argv[]) if(other_wm_running) error("gridwm: another window manager is already running\n"); - rect.x = rect.y = 0; - rect.width = DisplayWidth(dpy, screen); - rect.height = DisplayHeight(dpy, screen); + sx = sy = 0; + sw = DisplayWidth(dpy, screen); + sh = DisplayHeight(dpy, screen); sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); XSetErrorHandler(0); @@ -253,18 +252,16 @@ main(int argc, char *argv[]) wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask; - barrect = rect; - barrect.height = labelheight(&brush.font); - barrect.y = rect.height - barrect.height; - barwin = XCreateWindow(dpy, root, barrect.x, barrect.y, - barrect.width, barrect.height, 0, DefaultDepth(dpy, screen), + bx = by = 0; + bw = sw; + bh = texth(&brush.font); + barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, barwin, cursor[CurNormal]); XMapRaised(dpy, barwin); - brush.drawable = XCreatePixmap(dpy, root, rect.width, barrect.height, - DefaultDepth(dpy, screen)); + brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); brush.gc = XCreateGC(dpy, root, 0, 0); pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); diff --git a/wm.h b/wm.h index 8f31f60..b5b07b5 100644 --- a/wm.h +++ b/wm.h @@ -46,11 +46,10 @@ extern Display *dpy; extern Window root, barwin; extern Atom wm_atom[WMLast], net_atom[NetLast]; extern Cursor cursor[CurLast]; -extern XRectangle rect, barrect; extern Bool running, sel_screen, grid; extern void (*handler[LASTEvent]) (XEvent *); -extern int screen; +extern int screen, sx, sy, sw, sh, bx, by, bw, bh; extern char statustext[1024], tag[256]; extern Brush brush; @@ -75,9 +74,11 @@ extern void draw_client(Client *c); extern void resize(Client *c); extern void update_size(Client *c); extern Client *gettitle(Window w); +extern void raise(Client *c); +extern void lower(Client *c); /* event.c */ -extern unsigned int discard_events(long even_mask); +extern void discard_events(long even_mask); /* key.c */ extern void update_keys();