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