summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bar.c17
-rw-r--r--client.c64
-rw-r--r--cmd.c12
-rw-r--r--config.h8
-rw-r--r--draw.c45
-rw-r--r--draw.h8
-rw-r--r--event.c17
-rw-r--r--font.c81
-rw-r--r--menu.c97
-rw-r--r--mouse.c20
-rw-r--r--wm.c23
-rw-r--r--wm.h7
12 files changed, 164 insertions, 235 deletions
diff --git a/bar.c b/bar.c
index 1f12512..f70a246 100644
--- a/bar.c
+++ b/bar.c
@@ -8,23 +8,22 @@
8void 8void
9draw_bar() 9draw_bar()
10{ 10{
11 brush.rect = barrect; 11 brush.x = brush.y = 0;
12 brush.rect.x = brush.rect.y = 0; 12 brush.w = bw;
13 brush.h = bh;
13 draw(dpy, &brush, False, NULL); 14 draw(dpy, &brush, False, NULL);
14 15
15 if(stack) { 16 if(stack) {
16 brush.rect.width = textwidth(&brush.font, stack->name) + labelheight(&brush.font); 17 brush.w = textw(&brush.font, stack->name) + bh;
17 swap((void **)&brush.fg, (void **)&brush.bg); 18 swap((void **)&brush.fg, (void **)&brush.bg);
18 draw(dpy, &brush, True, stack->name); 19 draw(dpy, &brush, True, stack->name);
19 swap((void **)&brush.fg, (void **)&brush.bg); 20 swap((void **)&brush.fg, (void **)&brush.bg);
20 brush.rect.x += brush.rect.width; 21 brush.x += brush.w;
21 } 22 }
22 23
23 brush.rect.width = textwidth(&brush.font, statustext) + labelheight(&brush.font); 24 brush.w = textw(&brush.font, statustext) + bh;
24 brush.rect.x = barrect.x + barrect.width - brush.rect.width; 25 brush.x = bx + bw - brush.w;
25 draw(dpy, &brush, False, statustext); 26 draw(dpy, &brush, False, statustext);
26 27 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0);
27 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
28 barrect.height, 0, 0);
29 XFlush(dpy); 28 XFlush(dpy);
30} 29}
diff --git a/client.c b/client.c
index ee659c4..84fbce5 100644
--- a/client.c
+++ b/client.c
@@ -10,7 +10,16 @@
10#include "util.h" 10#include "util.h"
11#include "wm.h" 11#include "wm.h"
12 12
13#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask) 13static void
14resize_title(Client *c)
15{
16 c->tw = textw(&brush.font, c->name) + bh;
17 if(c->tw > c->w)
18 c->tw = c->w + 2;
19 c->tx = c->x + c->w - c->tw + 2;
20 c->ty = c->y;
21 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
22}
14 23
15void 24void
16update_name(Client *c) 25update_name(Client *c)
@@ -37,6 +46,7 @@ update_name(Client *c)
37 } 46 }
38 } 47 }
39 XFree(name.value); 48 XFree(name.value);
49 resize_title(c);
40} 50}
41 51
42void 52void
@@ -74,26 +84,37 @@ update_size(Client *c)
74} 84}
75 85
76void 86void
87raise(Client *c)
88{
89 XRaiseWindow(dpy, c->win);
90 XRaiseWindow(dpy, c->title);
91}
92
93void
94lower(Client *c)
95{
96 XLowerWindow(dpy, c->title);
97 XLowerWindow(dpy, c->win);
98}
99
100void
77focus(Client *c) 101focus(Client *c)
78{ 102{
79 Client **l, *old; 103 Client **l, *old;
80 104
81 old = stack; 105 old = stack;
82 for(l=&stack; *l && *l != c; l=&(*l)->snext); 106 for(l = &stack; *l && *l != c; l = &(*l)->snext);
83 eassert(*l == c); 107 eassert(*l == c);
84 *l = c->snext; 108 *l = c->snext;
85 c->snext = stack; 109 c->snext = stack;
86 stack = c; 110 stack = c;
87 XRaiseWindow(dpy, c->win);
88 XRaiseWindow(dpy, c->title);
89 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
90 if(old && old != c) { 111 if(old && old != c) {
91 XMapWindow(dpy, old->title); 112 XMapWindow(dpy, old->title);
92 draw_client(old); 113 draw_client(old);
93 } 114 }
94 XUnmapWindow(dpy, c->title); 115 XUnmapWindow(dpy, c->title);
95 draw_bar(); 116 draw_client(old);
96 discard_events(EnterWindowMask); 117 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
97 XFlush(dpy); 118 XFlush(dpy);
98} 119}
99 120
@@ -107,13 +128,16 @@ manage(Window w, XWindowAttributes *wa)
107 c->win = w; 128 c->win = w;
108 c->tx = c->x = wa->x; 129 c->tx = c->x = wa->x;
109 c->ty = c->y = wa->y; 130 c->ty = c->y = wa->y;
131 if(c->y < bh)
132 c->ty = c->y += bh;
110 c->tw = c->w = wa->width; 133 c->tw = c->w = wa->width;
111 c->h = wa->height; 134 c->h = wa->height;
112 c->th = barrect.height; 135 c->th = bh;
113 update_size(c); 136 update_size(c);
114 XSetWindowBorderWidth(dpy, c->win, 1); 137 XSetWindowBorderWidth(dpy, c->win, 1);
115 XSetWindowBorder(dpy, c->win, brush.border); 138 XSetWindowBorder(dpy, c->win, brush.border);
116 XSelectInput(dpy, c->win, CLIENT_MASK); 139 XSelectInput(dpy, c->win,
140 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
117 XGetTransientForHint(dpy, c->win, &c->trans); 141 XGetTransientForHint(dpy, c->win, &c->trans);
118 twa.override_redirect = 1; 142 twa.override_redirect = 1;
119 twa.background_pixmap = ParentRelative; 143 twa.background_pixmap = ParentRelative;
@@ -130,8 +154,8 @@ manage(Window w, XWindowAttributes *wa)
130 *l = c; 154 *l = c;
131 c->snext = stack; 155 c->snext = stack;
132 stack = c; 156 stack = c;
133 XMapWindow(dpy, c->win); 157 XMapRaised(dpy, c->win);
134 XMapWindow(dpy, c->title); 158 XMapRaised(dpy, c->title);
135 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, 159 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
136 GrabModeAsync, GrabModeSync, None, None); 160 GrabModeAsync, GrabModeSync, None, None);
137 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask, 161 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
@@ -147,6 +171,7 @@ resize(Client *c)
147{ 171{
148 XConfigureEvent e; 172 XConfigureEvent e;
149 173
174 resize_title(c);
150 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 175 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
151 e.type = ConfigureNotify; 176 e.type = ConfigureNotify;
152 e.event = c->win; 177 e.event = c->win;
@@ -158,9 +183,7 @@ resize(Client *c)
158 e.border_width = 0; 183 e.border_width = 0;
159 e.above = None; 184 e.above = None;
160 e.override_redirect = False; 185 e.override_redirect = False;
161 XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
162 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e); 186 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
163 XSelectInput(dpy, c->win, CLIENT_MASK);
164 XFlush(dpy); 187 XFlush(dpy);
165} 188}
166 189
@@ -219,17 +242,14 @@ getclient(Window w)
219void 242void
220draw_client(Client *c) 243draw_client(Client *c)
221{ 244{
222 if(c == stack) 245 if(c == stack) {
223 draw_bar(); 246 draw_bar();
247 return;
248 }
224 249
225 c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font); 250 brush.x = brush.y = 0;
226 c->tx = c->x + c->w - c->tw + 2; 251 brush.w = c->tw;
227 c->ty = c->y; 252 brush.h = c->th;
228 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
229
230 brush.rect.x = brush.rect.y = 0;
231 brush.rect.width = c->tw;
232 brush.rect.height = c->th;
233 253
234 draw(dpy, &brush, True, c->name); 254 draw(dpy, &brush, True, c->name);
235 XCopyArea(dpy, brush.drawable, c->title, brush.gc, 255 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
23sel(void *aux) 23sel(void *aux)
24{ 24{
25 const char *arg = aux; 25 const char *arg = aux;
26 Client *c; 26 Client *c = NULL;
27 27
28 if(!arg || !stack) 28 if(!arg || !stack)
29 return; 29 return;
30 if(!strncmp(arg, "next", 5)) 30 if(!strncmp(arg, "next", 5))
31 focus(stack->snext ? stack->snext : stack); 31 c = stack->snext ? stack->snext : stack;
32 else if(!strncmp(arg, "prev", 5)) { 32 else if(!strncmp(arg, "prev", 5))
33 for(c = stack; c && c->snext; c = c->snext); 33 for(c = stack; c && c->snext; c = c->snext);
34 focus(c ? c : stack); 34 if(!c)
35 } 35 c = stack;
36 raise(c);
37 focus(c);
36} 38}
37 39
38void 40void
diff --git a/config.h b/config.h
index ec633c3..9d28e75 100644
--- a/config.h
+++ b/config.h
@@ -4,7 +4,7 @@
4 */ 4 */
5 5
6#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" 6#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
7#define BGCOLOR "#0c0c33" 7#define BGCOLOR "#666699"
8#define FGCOLOR "#b2c8cd" 8#define FGCOLOR "#ffffff"
9#define BORDERCOLOR "#3030c0" 9#define BORDERCOLOR "#9999CC"
10#define STATUSDELAY 10 /* milliseconds */ 10#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)
15 XPoint points[5]; 15 XPoint points[5];
16 XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter); 16 XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
17 XSetForeground(dpy, b->gc, b->border); 17 XSetForeground(dpy, b->gc, b->border);
18 points[0].x = b->rect.x; 18 points[0].x = b->x;
19 points[0].y = b->rect.y; 19 points[0].y = b->y;
20 points[1].x = b->rect.width - 1; 20 points[1].x = b->w - 1;
21 points[1].y = 0; 21 points[1].y = 0;
22 points[2].x = 0; 22 points[2].x = 0;
23 points[2].y = b->rect.height - 1; 23 points[2].y = b->h - 1;
24 points[3].x = -(b->rect.width - 1); 24 points[3].x = -(b->w - 1);
25 points[3].y = 0; 25 points[3].y = 0;
26 points[4].x = 0; 26 points[4].x = 0;
27 points[4].y = -(b->rect.height - 1); 27 points[4].y = -(b->h - 1);
28 XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious); 28 XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
29} 29}
30 30
@@ -34,9 +34,10 @@ draw(Display *dpy, Brush *b, Bool border, const char *text)
34 unsigned int x, y, w, h, len; 34 unsigned int x, y, w, h, len;
35 static char buf[256]; 35 static char buf[256];
36 XGCValues gcv; 36 XGCValues gcv;
37 XRectangle r = { b->x, b->y, b->w, b->h };
37 38
38 XSetForeground(dpy, b->gc, b->bg); 39 XSetForeground(dpy, b->gc, b->bg);
39 XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1); 40 XFillRectangles(dpy, b->drawable, b->gc, &r, 1);
40 41
41 if(border) 42 if(border)
42 drawborder(dpy, b); 43 drawborder(dpy, b);
@@ -51,14 +52,14 @@ draw(Display *dpy, Brush *b, Bool border, const char *text)
51 buf[len] = 0; 52 buf[len] = 0;
52 53
53 h = b->font.ascent + b->font.descent; 54 h = b->font.ascent + b->font.descent;
54 y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent; 55 y = b->y + (b->h / 2) - (h / 2) + b->font.ascent;
55 x = b->rect.x + (h / 2); 56 x = b->x + (h / 2);
56 57
57 /* shorten text if necessary */ 58 /* shorten text if necessary */
58 while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h) 59 while(len && (w = textnw(&b->font, buf, len)) > b->w - h)
59 buf[--len] = 0; 60 buf[--len] = 0;
60 61
61 if(w > b->rect.width) 62 if(w > b->w)
62 return; /* too long */ 63 return; /* too long */
63 64
64 gcv.foreground = b->fg; 65 gcv.foreground = b->fg;
@@ -94,20 +95,26 @@ loadcolors(Display *dpy, int screen, Brush *b,
94} 95}
95 96
96unsigned int 97unsigned int
97textwidth_l(Fnt *font, char *text, unsigned int len) 98textnw(Fnt *font, char *text, unsigned int len)
98{ 99{
100 XRectangle r;
99 if(font->set) { 101 if(font->set) {
100 XRectangle r; 102 XmbTextExtents(font->set, text, len, NULL, &r);
101 XmbTextExtents(font->set, text, len, 0, &r);
102 return r.width; 103 return r.width;
103 } 104 }
104 return XTextWidth(font->xfont, text, len); 105 return XTextWidth(font->xfont, text, len);
105} 106}
106 107
107unsigned int 108unsigned int
108textwidth(Fnt *font, char *text) 109textw(Fnt *font, char *text)
109{ 110{
110 return textwidth_l(font, text, strlen(text)); 111 return textnw(font, text, strlen(text));
112}
113
114unsigned int
115texth(Fnt *font)
116{
117 return font->height + 4;
111} 118}
112 119
113void 120void
@@ -162,9 +169,3 @@ loadfont(Display *dpy, Fnt *font, const char *fontstr)
162 } 169 }
163 font->height = font->ascent + font->descent; 170 font->height = font->ascent + font->descent;
164} 171}
165
166unsigned int
167labelheight(Fnt *font)
168{
169 return font->height + 4;
170}
diff --git a/draw.h b/draw.h
index 6c3d886..4cd6fb1 100644
--- a/draw.h
+++ b/draw.h
@@ -20,7 +20,7 @@ struct Fnt {
20struct Brush { 20struct Brush {
21 GC gc; 21 GC gc;
22 Drawable drawable; 22 Drawable drawable;
23 XRectangle rect; 23 int x, y, w, h;
24 Fnt font; 24 Fnt font;
25 unsigned long bg; 25 unsigned long bg;
26 unsigned long fg; 26 unsigned long fg;
@@ -31,6 +31,6 @@ extern void draw(Display *dpy, Brush *b, Bool border, const char *text);
31extern void loadcolors(Display *dpy, int screen, Brush *b, 31extern void loadcolors(Display *dpy, int screen, Brush *b,
32 const char *bg, const char *fg, const char *bo); 32 const char *bg, const char *fg, const char *bo);
33extern void loadfont(Display *dpy, Fnt *font, const char *fontstr); 33extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
34extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len); 34extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
35extern unsigned int textwidth(Fnt *font, char *text); 35extern unsigned int textw(Fnt *font, char *text);
36extern unsigned int labelheight(Fnt *font); 36extern 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 *) = {
37 [UnmapNotify] = unmapnotify 37 [UnmapNotify] = unmapnotify
38}; 38};
39 39
40unsigned int 40void
41discard_events(long even_mask) 41discard_events(long even_mask)
42{ 42{
43 XEvent ev; 43 XEvent ev;
44 unsigned int n = 0; 44 while(XCheckMaskEvent(dpy, even_mask, &ev));
45 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
46 return n;
47} 45}
48 46
49static void 47static void
@@ -53,6 +51,7 @@ buttonpress(XEvent *e)
53 Client *c; 51 Client *c;
54 52
55 if((c = getclient(ev->window))) { 53 if((c = getclient(ev->window))) {
54 raise(c);
56 switch(ev->button) { 55 switch(ev->button) {
57 default: 56 default:
58 break; 57 break;
@@ -60,7 +59,7 @@ buttonpress(XEvent *e)
60 mmove(c); 59 mmove(c);
61 break; 60 break;
62 case Button2: 61 case Button2:
63 XLowerWindow(dpy, c->win); 62 lower(c);
64 break; 63 break;
65 case Button3: 64 case Button3:
66 mresize(c); 65 mresize(c);
@@ -122,10 +121,8 @@ enternotify(XEvent *e)
122 121
123 if((c = getclient(ev->window))) 122 if((c = getclient(ev->window)))
124 focus(c); 123 focus(c);
125 else if(ev->window == root) { 124 else if(ev->window == root)
126 sel_screen = True; 125 sel_screen = True;
127 /*draw_frames();*/
128 }
129} 126}
130 127
131static void 128static void
@@ -133,10 +130,8 @@ leavenotify(XEvent *e)
133{ 130{
134 XCrossingEvent *ev = &e->xcrossing; 131 XCrossingEvent *ev = &e->xcrossing;
135 132
136 if((ev->window == root) && !ev->same_screen) { 133 if((ev->window == root) && !ev->same_screen)
137 sel_screen = True; 134 sel_screen = True;
138 /*draw_frames();*/
139 }
140} 135}
141 136
142static void 137static 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 @@
1/*
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <locale.h>
10
11unsigned int
12textwidth_l(BlitzFont *font, char *text, unsigned int len)
13{
14 if(font->set) {
15 XRectangle r;
16 XmbTextExtents(font->set, text, len, nil, &r);
17 return r.width;
18 }
19 return XTextWidth(font->xfont, text, len);
20}
21
22unsigned int
23textwidth(BlitzFont *font, char *text)
24{
25 return blitz_textwidth_l(font, text, strlen(text));
26}
27
28void
29loadfont(Blitz *blitz, BlitzFont *font)
30{
31 char *fontname = font->fontstr;
32 char **missing = nil, *def = "?";
33 int n;
34
35 setlocale(LC_ALL, "");
36 if(font->set)
37 XFreeFontSet(blitz->dpy, font->set);
38 font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
39 if(missing) {
40 while(n--)
41 fprintf(stderr, "missing fontset: %s\n", missing[n]);
42 XFreeStringList(missing);
43 if(font->set) {
44 XFreeFontSet(blitz->dpy, font->set);
45 font->set = nil;
46 }
47 }
48 if(font->set) {
49 XFontSetExtents *font_extents;
50 XFontStruct **xfonts;
51 char **font_names;
52 unsigned int i;
53
54 font->ascent = font->descent = 0;
55 font_extents = XExtentsOfFontSet(font->set);
56 n = XFontsOfFontSet(font->set, &xfonts, &font_names);
57 for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
58 if(font->ascent < (*xfonts)->ascent)
59 font->ascent = (*xfonts)->ascent;
60 if(font->descent < (*xfonts)->descent)
61 font->descent = (*xfonts)->descent;
62 xfonts++;
63 }
64 }
65 else {
66 if(font->xfont)
67 XFreeFont(blitz->dpy, font->xfont);
68 font->xfont = nil;
69 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
70 if (!font->xfont) {
71 fontname = "fixed";
72 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
73 }
74 if (!font->xfont) {
75 fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
76 exit(1);
77 }
78 font->ascent = font->xfont->ascent;
79 font->descent = font->xfont->descent;
80 }
81}
diff --git a/menu.c b/menu.c
index e09d3b7..2392ed5 100644
--- a/menu.c
+++ b/menu.c
@@ -31,7 +31,6 @@ struct Item {
31static Display *dpy; 31static Display *dpy;
32static Window root; 32static Window root;
33static Window win; 33static Window win;
34static XRectangle rect;
35static Bool done = False; 34static Bool done = False;
36 35
37static Item *allitem = NULL; /* first of all items */ 36static Item *allitem = NULL; /* first of all items */
@@ -41,14 +40,14 @@ static Item *nextoff = NULL;
41static Item *prevoff = NULL; 40static Item *prevoff = NULL;
42static Item *curroff = NULL; 41static Item *curroff = NULL;
43 42
44static int screen; 43static int screen, mx, my, mw, mh;
45static char *title = NULL; 44static char *title = NULL;
46static char text[4096]; 45static char text[4096];
47static int ret = 0; 46static int ret = 0;
48static int nitem = 0; 47static int nitem = 0;
49static unsigned int cmdw = 0; 48static unsigned int cmdw = 0;
50static unsigned int twidth = 0; 49static unsigned int tw = 0;
51static unsigned int cwidth = 0; 50static unsigned int cw = 0;
52static const int seek = 30; /* 30px */ 51static const int seek = 30; /* 30px */
53 52
54static Brush brush = {0}; 53static Brush brush = {0};
@@ -74,21 +73,21 @@ update_offsets()
74 return; 73 return;
75 74
76 for(nextoff = curroff; nextoff; nextoff=nextoff->right) { 75 for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
77 tw = textwidth(&brush.font, nextoff->text); 76 tw = textw(&brush.font, nextoff->text);
78 if(tw > rect.width / 3) 77 if(tw > mw / 3)
79 tw = rect.width / 3; 78 tw = mw / 3;
80 w += tw + brush.font.height; 79 w += tw + brush.font.height;
81 if(w > rect.width) 80 if(w > mw)
82 break; 81 break;
83 } 82 }
84 83
85 w = cmdw + 2 * seek; 84 w = cmdw + 2 * seek;
86 for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) { 85 for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
87 tw = textwidth(&brush.font, prevoff->left->text); 86 tw = textw(&brush.font, prevoff->left->text);
88 if(tw > rect.width / 3) 87 if(tw > mw / 3)
89 tw = rect.width / 3; 88 tw = mw / 3;
90 w += tw + brush.font.height; 89 w += tw + brush.font.height;
91 if(w > rect.width) 90 if(w > mw)
92 break; 91 break;
93 } 92 }
94} 93}
@@ -103,9 +102,9 @@ update_items(char *pattern)
103 return; 102 return;
104 103
105 if(!title || *pattern) 104 if(!title || *pattern)
106 cmdw = cwidth; 105 cmdw = cw;
107 else 106 else
108 cmdw = twidth; 107 cmdw = tw;
109 108
110 item = j = NULL; 109 item = j = NULL;
111 nitem = 0; 110 nitem = 0;
@@ -143,42 +142,40 @@ update_items(char *pattern)
143static void 142static void
144draw_menu() 143draw_menu()
145{ 144{
146 unsigned int offx = 0;
147 Item *i; 145 Item *i;
148 146
149 brush.rect = rect; 147 brush.x = 0;
150 brush.rect.x = 0; 148 brush.y = 0;
151 brush.rect.y = 0; 149 brush.w = mw;
150 brush.h = mh;
152 draw(dpy, &brush, False, 0); 151 draw(dpy, &brush, False, 0);
153 152
154 /* print command */ 153 /* print command */
155 if(!title || text[0]) { 154 if(!title || text[0]) {
156 cmdw = cwidth; 155 cmdw = cw;
157 if(cmdw && item) 156 if(cmdw && item)
158 brush.rect.width = cmdw; 157 brush.w = cmdw;
159 draw(dpy, &brush, False, text); 158 draw(dpy, &brush, False, text);
160 } 159 }
161 else { 160 else {
162 cmdw = twidth; 161 cmdw = tw;
163 brush.rect.width = cmdw; 162 brush.w = cmdw;
164 draw(dpy, &brush, False, title); 163 draw(dpy, &brush, False, title);
165 } 164 }
166 offx += brush.rect.width; 165 brush.x += brush.w;
167 166
168 if(curroff) { 167 if(curroff) {
169 brush.rect.x = offx; 168 brush.w = seek;
170 brush.rect.width = seek;
171 offx += brush.rect.width;
172 draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0); 169 draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
170 brush.x += brush.w;
173 171
174 /* determine maximum items */ 172 /* determine maximum items */
175 for(i = curroff; i != nextoff; i=i->right) { 173 for(i = curroff; i != nextoff; i=i->right) {
176 brush.border = False; 174 brush.border = False;
177 brush.rect.x = offx; 175 brush.w = textw(&brush.font, i->text);
178 brush.rect.width = textwidth(&brush.font, i->text); 176 if(brush.w > mw / 3)
179 if(brush.rect.width > rect.width / 3) 177 brush.w = mw / 3;
180 brush.rect.width = rect.width / 3; 178 brush.w += brush.font.height;
181 brush.rect.width += brush.font.height;
182 if(sel == i) { 179 if(sel == i) {
183 swap((void **)&brush.fg, (void **)&brush.bg); 180 swap((void **)&brush.fg, (void **)&brush.bg);
184 draw(dpy, &brush, True, i->text); 181 draw(dpy, &brush, True, i->text);
@@ -186,15 +183,14 @@ draw_menu()
186 } 183 }
187 else 184 else
188 draw(dpy, &brush, False, i->text); 185 draw(dpy, &brush, False, i->text);
189 offx += brush.rect.width; 186 brush.x += brush.w;
190 } 187 }
191 188
192 brush.rect.x = rect.width - seek; 189 brush.x = mw - seek;
193 brush.rect.width = seek; 190 brush.w = seek;
194 draw(dpy, &brush, False, nextoff ? ">" : 0); 191 draw(dpy, &brush, False, nextoff ? ">" : 0);
195 } 192 }
196 XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width, 193 XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0);
197 rect.height, 0, 0);
198 XFlush(dpy); 194 XFlush(dpy);
199} 195}
200 196
@@ -399,36 +395,35 @@ main(int argc, char *argv[])
399 wa.background_pixmap = ParentRelative; 395 wa.background_pixmap = ParentRelative;
400 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; 396 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
401 397
402 rect.width = DisplayWidth(dpy, screen); 398 mx = my = 0;
403 rect.height = labelheight(&brush.font); 399 mw = DisplayWidth(dpy, screen);
404 rect.y = DisplayHeight(dpy, screen) - rect.height; 400 mh = texth(&brush.font);
405 rect.x = 0;
406 401
407 win = XCreateWindow(dpy, root, rect.x, rect.y, 402 win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
408 rect.width, rect.height, 0, DefaultDepth(dpy, screen), 403 DefaultDepth(dpy, screen), CopyFromParent,
409 CopyFromParent, DefaultVisual(dpy, screen), 404 DefaultVisual(dpy, screen),
410 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 405 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
411 XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); 406 XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
412 XFlush(dpy); 407 XFlush(dpy);
413 408
414 /* pixmap */ 409 /* pixmap */
415 brush.gc = XCreateGC(dpy, root, 0, 0); 410 brush.gc = XCreateGC(dpy, root, 0, 0);
416 brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height, 411 brush.drawable = XCreatePixmap(dpy, win, mw, mh,
417 DefaultDepth(dpy, screen)); 412 DefaultDepth(dpy, screen));
418 XFlush(dpy); 413 XFlush(dpy);
419 414
420 if(maxname) 415 if(maxname)
421 cwidth = textwidth(&brush.font, maxname) + brush.font.height; 416 cw = textw(&brush.font, maxname) + brush.font.height;
422 if(cwidth > rect.width / 3) 417 if(cw > mw / 3)
423 cwidth = rect.width / 3; 418 cw = mw / 3;
424 419
425 if(title) { 420 if(title) {
426 twidth = textwidth(&brush.font, title) + brush.font.height; 421 tw = textw(&brush.font, title) + brush.font.height;
427 if(twidth > rect.width / 3) 422 if(tw > mw / 3)
428 twidth = rect.width / 3; 423 tw = mw / 3;
429 } 424 }
430 425
431 cmdw = title ? twidth : cwidth; 426 cmdw = title ? tw : cw;
432 427
433 text[0] = 0; 428 text[0] = 0;
434 update_items(text); 429 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)
45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
46 None, cursor[CurResize], CurrentTime) != GrabSuccess) 46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
47 return; 47 return;
48 XGrabServer(dpy);
49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 48 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
50 for(;;) { 49 for(;;) {
51 XMaskEvent(dpy, MouseMask, &ev); 50 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
52 switch(ev.type) { 51 switch(ev.type) {
53 default: break; 52 default: break;
53 case Expose:
54 handler[Expose](&ev);
55 break;
54 case MotionNotify: 56 case MotionNotify:
55 XUngrabServer(dpy); 57 XFlush(dpy);
56 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); 58 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
57 XResizeWindow(dpy, c->win, c->w, c->h); 59 XResizeWindow(dpy, c->win, c->w, c->h);
58 XGrabServer(dpy);
59 break; 60 break;
60 case ButtonRelease: 61 case ButtonRelease:
61 resize(c); 62 resize(c);
62 XUngrabServer(dpy);
63 XUngrabPointer(dpy, CurrentTime); 63 XUngrabPointer(dpy, CurrentTime);
64 return; 64 return;
65 } 65 }
@@ -80,21 +80,21 @@ mmove(Client *c)
80 None, cursor[CurMove], CurrentTime) != GrabSuccess) 80 None, cursor[CurMove], CurrentTime) != GrabSuccess)
81 return; 81 return;
82 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 82 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
83 XGrabServer(dpy);
84 for(;;) { 83 for(;;) {
85 XMaskEvent(dpy, MouseMask, &ev); 84 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
86 switch (ev.type) { 85 switch (ev.type) {
87 default: break; 86 default: break;
87 case Expose:
88 handler[Expose](&ev);
89 break;
88 case MotionNotify: 90 case MotionNotify:
89 XUngrabServer(dpy); 91 XFlush(dpy);
90 c->x = old_cx + (ev.xmotion.x - x1); 92 c->x = old_cx + (ev.xmotion.x - x1);
91 c->y = old_cy + (ev.xmotion.y - y1); 93 c->y = old_cy + (ev.xmotion.y - y1);
92 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 94 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
93 XGrabServer(dpy);
94 break; 95 break;
95 case ButtonRelease: 96 case ButtonRelease:
96 resize(c); 97 resize(c);
97 XUngrabServer(dpy);
98 XUngrabPointer(dpy, CurrentTime); 98 XUngrabPointer(dpy, CurrentTime);
99 return; 99 return;
100 } 100 }
diff --git a/wm.c b/wm.c
index 82b2dee..f0069d2 100644
--- a/wm.c
+++ b/wm.c
@@ -23,12 +23,11 @@ Display *dpy;
23Window root, barwin; 23Window root, barwin;
24Atom wm_atom[WMLast], net_atom[NetLast]; 24Atom wm_atom[WMLast], net_atom[NetLast];
25Cursor cursor[CurLast]; 25Cursor cursor[CurLast];
26XRectangle rect, barrect;
27Bool running = True; 26Bool running = True;
28Bool sel_screen; 27Bool sel_screen;
29 28
30char statustext[1024], tag[256]; 29char statustext[1024], tag[256];
31int screen; 30int screen, sx, sy, sw, sh, bx, by, bw, bh;
32 31
33Brush brush = {0}; 32Brush brush = {0};
34Client *clients = NULL; 33Client *clients = NULL;
@@ -39,7 +38,7 @@ static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R.
39static int (*x_error_handler) (Display *, XErrorEvent *); 38static int (*x_error_handler) (Display *, XErrorEvent *);
40 39
41static const char *status[] = { 40static const char *status[] = {
42 "sh", "-c", "echo -n `date '+%Y/%m/%d %H:%M'`" 41 "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`"
43 " `uptime | sed 's/.*://; s/,//g'`" 42 " `uptime | sed 's/.*://; s/,//g'`"
44 " `acpi | awk '{print $4}' | sed 's/,//'`", 0 43 " `acpi | awk '{print $4}' | sed 's/,//'`", 0
45}; 44};
@@ -220,9 +219,9 @@ main(int argc, char *argv[])
220 if(other_wm_running) 219 if(other_wm_running)
221 error("gridwm: another window manager is already running\n"); 220 error("gridwm: another window manager is already running\n");
222 221
223 rect.x = rect.y = 0; 222 sx = sy = 0;
224 rect.width = DisplayWidth(dpy, screen); 223 sw = DisplayWidth(dpy, screen);
225 rect.height = DisplayHeight(dpy, screen); 224 sh = DisplayHeight(dpy, screen);
226 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 225 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
227 226
228 XSetErrorHandler(0); 227 XSetErrorHandler(0);
@@ -253,18 +252,16 @@ main(int argc, char *argv[])
253 wa.background_pixmap = ParentRelative; 252 wa.background_pixmap = ParentRelative;
254 wa.event_mask = ExposureMask; 253 wa.event_mask = ExposureMask;
255 254
256 barrect = rect; 255 bx = by = 0;
257 barrect.height = labelheight(&brush.font); 256 bw = sw;
258 barrect.y = rect.height - barrect.height; 257 bh = texth(&brush.font);
259 barwin = XCreateWindow(dpy, root, barrect.x, barrect.y, 258 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
260 barrect.width, barrect.height, 0, DefaultDepth(dpy, screen),
261 CopyFromParent, DefaultVisual(dpy, screen), 259 CopyFromParent, DefaultVisual(dpy, screen),
262 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 260 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
263 XDefineCursor(dpy, barwin, cursor[CurNormal]); 261 XDefineCursor(dpy, barwin, cursor[CurNormal]);
264 XMapRaised(dpy, barwin); 262 XMapRaised(dpy, barwin);
265 263
266 brush.drawable = XCreatePixmap(dpy, root, rect.width, barrect.height, 264 brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
267 DefaultDepth(dpy, screen));
268 brush.gc = XCreateGC(dpy, root, 0, 0); 265 brush.gc = XCreateGC(dpy, root, 0, 0);
269 266
270 pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); 267 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;
46extern Window root, barwin; 46extern Window root, barwin;
47extern Atom wm_atom[WMLast], net_atom[NetLast]; 47extern Atom wm_atom[WMLast], net_atom[NetLast];
48extern Cursor cursor[CurLast]; 48extern Cursor cursor[CurLast];
49extern XRectangle rect, barrect;
50extern Bool running, sel_screen, grid; 49extern Bool running, sel_screen, grid;
51extern void (*handler[LASTEvent]) (XEvent *); 50extern void (*handler[LASTEvent]) (XEvent *);
52 51
53extern int screen; 52extern int screen, sx, sy, sw, sh, bx, by, bw, bh;
54extern char statustext[1024], tag[256]; 53extern char statustext[1024], tag[256];
55 54
56extern Brush brush; 55extern Brush brush;
@@ -75,9 +74,11 @@ extern void draw_client(Client *c);
75extern void resize(Client *c); 74extern void resize(Client *c);
76extern void update_size(Client *c); 75extern void update_size(Client *c);
77extern Client *gettitle(Window w); 76extern Client *gettitle(Window w);
77extern void raise(Client *c);
78extern void lower(Client *c);
78 79
79/* event.c */ 80/* event.c */
80extern unsigned int discard_events(long even_mask); 81extern void discard_events(long even_mask);
81 82
82/* key.c */ 83/* key.c */
83extern void update_keys(); 84extern void update_keys();