diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-15 17:00:56 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-15 17:00:56 +0200 |
| commit | adaa28a6e600f636f5e86244ccef69e98419ba1a (patch) | |
| tree | a7373162dabedbc0edf809559781489eca5a3fbb /draw.c | |
| parent | rearranged several stuff (diff) | |
| download | dwm-adaa28a6e600f636f5e86244ccef69e98419ba1a.tar.gz dwm-adaa28a6e600f636f5e86244ccef69e98419ba1a.zip | |
proceeded with cleaning up, sorting functions, etc
Diffstat (limited to 'draw.c')
| -rw-r--r-- | draw.c | 146 |
1 files changed, 74 insertions, 72 deletions
| @@ -2,13 +2,34 @@ | |||
| 2 | * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> | 2 | * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> |
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | #include "dwm.h" | ||
| 5 | 6 | ||
| 6 | #include <stdio.h> | 7 | #include <stdio.h> |
| 7 | #include <string.h> | 8 | #include <string.h> |
| 8 | |||
| 9 | #include <X11/Xlocale.h> | 9 | #include <X11/Xlocale.h> |
| 10 | 10 | ||
| 11 | #include "dwm.h" | 11 | /* static functions */ |
| 12 | |||
| 13 | static void | ||
| 14 | drawborder(void) | ||
| 15 | { | ||
| 16 | XPoint points[5]; | ||
| 17 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | ||
| 18 | XSetForeground(dpy, dc.gc, dc.border); | ||
| 19 | points[0].x = dc.x; | ||
| 20 | points[0].y = dc.y; | ||
| 21 | points[1].x = dc.w - 1; | ||
| 22 | points[1].y = 0; | ||
| 23 | points[2].x = 0; | ||
| 24 | points[2].y = dc.h - 1; | ||
| 25 | points[3].x = -(dc.w - 1); | ||
| 26 | points[3].y = 0; | ||
| 27 | points[4].x = 0; | ||
| 28 | points[4].y = -(dc.h - 1); | ||
| 29 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); | ||
| 30 | } | ||
| 31 | |||
| 32 | /* extern functions */ | ||
| 12 | 33 | ||
| 13 | void | 34 | void |
| 14 | drawall() | 35 | drawall() |
| @@ -53,59 +74,6 @@ drawstatus() | |||
| 53 | } | 74 | } |
| 54 | 75 | ||
| 55 | void | 76 | void |
| 56 | drawtitle(Client *c) | ||
| 57 | { | ||
| 58 | int i; | ||
| 59 | Bool istile = arrange == dotile; | ||
| 60 | |||
| 61 | if(c == sel) { | ||
| 62 | drawstatus(); | ||
| 63 | XUnmapWindow(dpy, c->title); | ||
| 64 | XSetWindowBorder(dpy, c->win, dc.fg); | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | XSetWindowBorder(dpy, c->win, dc.bg); | ||
| 69 | XMapWindow(dpy, c->title); | ||
| 70 | |||
| 71 | dc.x = dc.y = 0; | ||
| 72 | |||
| 73 | dc.w = 0; | ||
| 74 | for(i = 0; i < TLast; i++) { | ||
| 75 | if(c->tags[i]) { | ||
| 76 | dc.x += dc.w; | ||
| 77 | dc.w = textw(c->tags[i]); | ||
| 78 | drawtext(c->tags[i], !istile, True); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | dc.x += dc.w; | ||
| 82 | dc.w = textw(c->name); | ||
| 83 | drawtext(c->name, !istile, True); | ||
| 84 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, | ||
| 85 | 0, 0, c->tw, c->th, 0, 0); | ||
| 86 | XFlush(dpy); | ||
| 87 | } | ||
| 88 | |||
| 89 | static void | ||
| 90 | drawborder(void) | ||
| 91 | { | ||
| 92 | XPoint points[5]; | ||
| 93 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | ||
| 94 | XSetForeground(dpy, dc.gc, dc.border); | ||
| 95 | points[0].x = dc.x; | ||
| 96 | points[0].y = dc.y; | ||
| 97 | points[1].x = dc.w - 1; | ||
| 98 | points[1].y = 0; | ||
| 99 | points[2].x = 0; | ||
| 100 | points[2].y = dc.h - 1; | ||
| 101 | points[3].x = -(dc.w - 1); | ||
| 102 | points[3].y = 0; | ||
| 103 | points[4].x = 0; | ||
| 104 | points[4].y = -(dc.h - 1); | ||
| 105 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); | ||
| 106 | } | ||
| 107 | |||
| 108 | void | ||
| 109 | drawtext(const char *text, Bool invert, Bool border) | 77 | drawtext(const char *text, Bool invert, Bool border) |
| 110 | { | 78 | { |
| 111 | int x, y, w, h; | 79 | int x, y, w, h; |
| @@ -155,6 +123,40 @@ drawtext(const char *text, Bool invert, Bool border) | |||
| 155 | } | 123 | } |
| 156 | } | 124 | } |
| 157 | 125 | ||
| 126 | void | ||
| 127 | drawtitle(Client *c) | ||
| 128 | { | ||
| 129 | int i; | ||
| 130 | Bool istile = arrange == dotile; | ||
| 131 | |||
| 132 | if(c == sel) { | ||
| 133 | drawstatus(); | ||
| 134 | XUnmapWindow(dpy, c->title); | ||
| 135 | XSetWindowBorder(dpy, c->win, dc.fg); | ||
| 136 | return; | ||
| 137 | } | ||
| 138 | |||
| 139 | XSetWindowBorder(dpy, c->win, dc.bg); | ||
| 140 | XMapWindow(dpy, c->title); | ||
| 141 | |||
| 142 | dc.x = dc.y = 0; | ||
| 143 | |||
| 144 | dc.w = 0; | ||
| 145 | for(i = 0; i < TLast; i++) { | ||
| 146 | if(c->tags[i]) { | ||
| 147 | dc.x += dc.w; | ||
| 148 | dc.w = textw(c->tags[i]); | ||
| 149 | drawtext(c->tags[i], !istile, True); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | dc.x += dc.w; | ||
| 153 | dc.w = textw(c->name); | ||
| 154 | drawtext(c->name, !istile, True); | ||
| 155 | XCopyArea(dpy, dc.drawable, c->title, dc.gc, | ||
| 156 | 0, 0, c->tw, c->th, 0, 0); | ||
| 157 | XFlush(dpy); | ||
| 158 | } | ||
| 159 | |||
| 158 | unsigned long | 160 | unsigned long |
| 159 | getcolor(const char *colstr) | 161 | getcolor(const char *colstr) |
| 160 | { | 162 | { |
| @@ -165,23 +167,6 @@ getcolor(const char *colstr) | |||
| 165 | return color.pixel; | 167 | return color.pixel; |
| 166 | } | 168 | } |
| 167 | 169 | ||
| 168 | unsigned int | ||
| 169 | textnw(char *text, unsigned int len) | ||
| 170 | { | ||
| 171 | XRectangle r; | ||
| 172 | if(dc.font.set) { | ||
| 173 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 174 | return r.width; | ||
| 175 | } | ||
| 176 | return XTextWidth(dc.font.xfont, text, len); | ||
| 177 | } | ||
| 178 | |||
| 179 | unsigned int | ||
| 180 | textw(char *text) | ||
| 181 | { | ||
| 182 | return textnw(text, strlen(text)) + dc.font.height; | ||
| 183 | } | ||
| 184 | |||
| 185 | void | 170 | void |
| 186 | setfont(const char *fontstr) | 171 | setfont(const char *fontstr) |
| 187 | { | 172 | { |
| @@ -232,3 +217,20 @@ setfont(const char *fontstr) | |||
| 232 | } | 217 | } |
| 233 | dc.font.height = dc.font.ascent + dc.font.descent; | 218 | dc.font.height = dc.font.ascent + dc.font.descent; |
| 234 | } | 219 | } |
| 220 | |||
| 221 | unsigned int | ||
| 222 | textnw(char *text, unsigned int len) | ||
| 223 | { | ||
| 224 | XRectangle r; | ||
| 225 | if(dc.font.set) { | ||
| 226 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 227 | return r.width; | ||
| 228 | } | ||
| 229 | return XTextWidth(dc.font.xfont, text, len); | ||
| 230 | } | ||
| 231 | |||
| 232 | unsigned int | ||
| 233 | textw(char *text) | ||
| 234 | { | ||
| 235 | return textnw(text, strlen(text)) + dc.font.height; | ||
| 236 | } | ||
