diff options
Diffstat (limited to '')
| -rw-r--r-- | dwm.c | 253 |
1 files changed, 70 insertions, 183 deletions
| @@ -54,7 +54,7 @@ | |||
| 54 | #define WIDTH(X) ((X)->w + 2 * (X)->bw) | 54 | #define WIDTH(X) ((X)->w + 2 * (X)->bw) |
| 55 | #define HEIGHT(X) ((X)->h + 2 * (X)->bw) | 55 | #define HEIGHT(X) ((X)->h + 2 * (X)->bw) |
| 56 | #define TAGMASK ((1 << LENGTH(tags)) - 1) | 56 | #define TAGMASK ((1 << LENGTH(tags)) - 1) |
| 57 | #define TEXTW(X) (textnw(X, strlen(X)) + dc.font.height) | 57 | #define TEXTW(X) (drw_font_getexts_width(drw->font, X, strlen(X)) + drw->font->h) |
| 58 | 58 | ||
| 59 | /* enums */ | 59 | /* enums */ |
| 60 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | 60 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
| @@ -99,21 +99,6 @@ struct Client { | |||
| 99 | }; | 99 | }; |
| 100 | 100 | ||
| 101 | typedef struct { | 101 | typedef struct { |
| 102 | int x, y, w, h; | ||
| 103 | unsigned long norm[ColLast]; | ||
| 104 | unsigned long sel[ColLast]; | ||
| 105 | Drawable drawable; | ||
| 106 | GC gc; | ||
| 107 | struct { | ||
| 108 | int ascent; | ||
| 109 | int descent; | ||
| 110 | int height; | ||
| 111 | XFontSet set; | ||
| 112 | XFontStruct *xfont; | ||
| 113 | } font; | ||
| 114 | } DC; /* draw context */ | ||
| 115 | |||
| 116 | typedef struct { | ||
| 117 | unsigned int mod; | 102 | unsigned int mod; |
| 118 | KeySym keysym; | 103 | KeySym keysym; |
| 119 | void (*func)(const Arg *); | 104 | void (*func)(const Arg *); |
| @@ -178,22 +163,18 @@ static void detachstack(Client *c); | |||
| 178 | static Monitor *dirtomon(int dir); | 163 | static Monitor *dirtomon(int dir); |
| 179 | static void drawbar(Monitor *m); | 164 | static void drawbar(Monitor *m); |
| 180 | static void drawbars(void); | 165 | static void drawbars(void); |
| 181 | static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); | ||
| 182 | static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); | ||
| 183 | static void enternotify(XEvent *e); | 166 | static void enternotify(XEvent *e); |
| 184 | static void expose(XEvent *e); | 167 | static void expose(XEvent *e); |
| 185 | static void focus(Client *c); | 168 | static void focus(Client *c); |
| 186 | static void focusin(XEvent *e); | 169 | static void focusin(XEvent *e); |
| 187 | static void focusmon(const Arg *arg); | 170 | static void focusmon(const Arg *arg); |
| 188 | static void focusstack(const Arg *arg); | 171 | static void focusstack(const Arg *arg); |
| 189 | static unsigned long getcolor(const char *colstr); | ||
| 190 | static Bool getrootptr(int *x, int *y); | 172 | static Bool getrootptr(int *x, int *y); |
| 191 | static long getstate(Window w); | 173 | static long getstate(Window w); |
| 192 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); | 174 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
| 193 | static void grabbuttons(Client *c, Bool focused); | 175 | static void grabbuttons(Client *c, Bool focused); |
| 194 | static void grabkeys(void); | 176 | static void grabkeys(void); |
| 195 | static void incnmaster(const Arg *arg); | 177 | static void incnmaster(const Arg *arg); |
| 196 | static void initfont(const char *fontstr); | ||
| 197 | static void keypress(XEvent *e); | 178 | static void keypress(XEvent *e); |
| 198 | static void killclient(const Arg *arg); | 179 | static void killclient(const Arg *arg); |
| 199 | static void manage(Window w, XWindowAttributes *wa); | 180 | static void manage(Window w, XWindowAttributes *wa); |
| @@ -226,7 +207,6 @@ static void sigchld(int unused); | |||
| 226 | static void spawn(const Arg *arg); | 207 | static void spawn(const Arg *arg); |
| 227 | static void tag(const Arg *arg); | 208 | static void tag(const Arg *arg); |
| 228 | static void tagmon(const Arg *arg); | 209 | static void tagmon(const Arg *arg); |
| 229 | static int textnw(const char *text, unsigned int len); | ||
| 230 | static void tile(Monitor *); | 210 | static void tile(Monitor *); |
| 231 | static void togglebar(const Arg *arg); | 211 | static void togglebar(const Arg *arg); |
| 232 | static void togglefloating(const Arg *arg); | 212 | static void togglefloating(const Arg *arg); |
| @@ -279,10 +259,13 @@ static void (*handler[LASTEvent]) (XEvent *) = { | |||
| 279 | }; | 259 | }; |
| 280 | static Atom wmatom[WMLast], netatom[NetLast]; | 260 | static Atom wmatom[WMLast], netatom[NetLast]; |
| 281 | static Bool running = True; | 261 | static Bool running = True; |
| 282 | static Cursor cursor[CurLast]; | 262 | static Cur *cursor[CurLast]; |
| 263 | static Theme thmnorm[ColLast]; | ||
| 264 | static Theme thmsel[ColLast]; | ||
| 283 | static Display *dpy; | 265 | static Display *dpy; |
| 284 | static DC dc; | 266 | static Drw *drw; |
| 285 | static Monitor *mons = NULL, *selmon = NULL; | 267 | static Fnt *fnt; |
| 268 | static Monitor *mons, *selmon; | ||
| 286 | static Window root; | 269 | static Window root; |
| 287 | 270 | ||
| 288 | /* configuration, allows nested code to access above variables */ | 271 | /* configuration, allows nested code to access above variables */ |
| @@ -486,18 +469,20 @@ cleanup(void) { | |||
| 486 | for(m = mons; m; m = m->next) | 469 | for(m = mons; m; m = m->next) |
| 487 | while(m->stack) | 470 | while(m->stack) |
| 488 | unmanage(m->stack, False); | 471 | unmanage(m->stack, False); |
| 489 | if(dc.font.set) | ||
| 490 | XFreeFontSet(dpy, dc.font.set); | ||
| 491 | else | ||
| 492 | XFreeFont(dpy, dc.font.xfont); | ||
| 493 | XUngrabKey(dpy, AnyKey, AnyModifier, root); | 472 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
| 494 | XFreePixmap(dpy, dc.drawable); | ||
| 495 | XFreeGC(dpy, dc.gc); | ||
| 496 | XFreeCursor(dpy, cursor[CurNormal]); | ||
| 497 | XFreeCursor(dpy, cursor[CurResize]); | ||
| 498 | XFreeCursor(dpy, cursor[CurMove]); | ||
| 499 | while(mons) | 473 | while(mons) |
| 500 | cleanupmon(mons); | 474 | cleanupmon(mons); |
| 475 | drw_cur_free(drw, cursor[CurNormal]); | ||
| 476 | drw_cur_free(drw, cursor[CurResize]); | ||
| 477 | drw_cur_free(drw, cursor[CurMove]); | ||
| 478 | drw_font_free(dpy, fnt); | ||
| 479 | drw_clr_free(thmnorm->border); | ||
| 480 | drw_clr_free(thmnorm->bg); | ||
| 481 | drw_clr_free(thmnorm->fg); | ||
| 482 | drw_clr_free(thmsel->border); | ||
| 483 | drw_clr_free(thmsel->bg); | ||
| 484 | drw_clr_free(thmsel->fg); | ||
| 485 | drw_free(drw); | ||
| 501 | XSync(dpy, False); | 486 | XSync(dpy, False); |
| 502 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); | 487 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
| 503 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 488 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
| @@ -581,9 +566,7 @@ configurenotify(XEvent *e) { | |||
| 581 | sw = ev->width; | 566 | sw = ev->width; |
| 582 | sh = ev->height; | 567 | sh = ev->height; |
| 583 | if(updategeom() || dirty) { | 568 | if(updategeom() || dirty) { |
| 584 | if(dc.drawable != 0) | 569 | drw_resize(drw, sw, bh); |
| 585 | XFreePixmap(dpy, dc.drawable); | ||
| 586 | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | ||
| 587 | updatebars(); | 570 | updatebars(); |
| 588 | for(m = mons; m; m = m->next) | 571 | for(m = mons; m; m = m->next) |
| 589 | XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); | 572 | XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); |
| @@ -710,9 +693,8 @@ dirtomon(int dir) { | |||
| 710 | 693 | ||
| 711 | void | 694 | void |
| 712 | drawbar(Monitor *m) { | 695 | drawbar(Monitor *m) { |
| 713 | int x; | 696 | int x, xx, w; |
| 714 | unsigned int i, occ = 0, urg = 0; | 697 | unsigned int i, occ = 0, urg = 0; |
| 715 | unsigned long *col; | ||
| 716 | Client *c; | 698 | Client *c; |
| 717 | 699 | ||
| 718 | for(c = m->clients; c; c = c->next) { | 700 | for(c = m->clients; c; c = c->next) { |
| @@ -720,42 +702,44 @@ drawbar(Monitor *m) { | |||
| 720 | if(c->isurgent) | 702 | if(c->isurgent) |
| 721 | urg |= c->tags; | 703 | urg |= c->tags; |
| 722 | } | 704 | } |
| 723 | dc.x = 0; | 705 | x = 0; |
| 724 | for(i = 0; i < LENGTH(tags); i++) { | 706 | for(i = 0; i < LENGTH(tags); i++) { |
| 725 | dc.w = TEXTW(tags[i]); | 707 | w = TEXTW(tags[i]); |
| 726 | col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; | 708 | drw_settheme(drw, m->tagset[m->seltags] & 1 << i ? thmsel : thmnorm); |
| 727 | drawtext(tags[i], col, urg & 1 << i); | 709 | drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); |
| 728 | drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, | 710 | drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, |
| 729 | occ & 1 << i, urg & 1 << i, col); | 711 | occ & 1 << i, urg & 1 << i); |
| 730 | dc.x += dc.w; | 712 | x += w; |
| 731 | } | 713 | } |
| 732 | dc.w = blw = TEXTW(m->ltsymbol); | 714 | w = blw = TEXTW(m->ltsymbol); |
| 733 | drawtext(m->ltsymbol, dc.norm, False); | 715 | drw_settheme(drw, thmnorm); |
| 734 | dc.x += dc.w; | 716 | drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); |
| 735 | x = dc.x; | 717 | x += w; |
| 718 | xx = x; | ||
| 736 | if(m == selmon) { /* status is only drawn on selected monitor */ | 719 | if(m == selmon) { /* status is only drawn on selected monitor */ |
| 737 | dc.w = TEXTW(stext); | 720 | w = TEXTW(stext); |
| 738 | dc.x = m->ww - dc.w; | 721 | x = m->ww - w; |
| 739 | if(dc.x < x) { | 722 | if(x < xx) { |
| 740 | dc.x = x; | 723 | x = xx; |
| 741 | dc.w = m->ww - x; | 724 | w = m->ww - xx; |
| 742 | } | 725 | } |
| 743 | drawtext(stext, dc.norm, False); | 726 | drw_text(drw, x, 0, w, bh, stext, 0); |
| 744 | } | 727 | } |
| 745 | else | 728 | else |
| 746 | dc.x = m->ww; | 729 | x = m->ww; |
| 747 | if((dc.w = dc.x - x) > bh) { | 730 | if((w = x - xx) > bh) { |
| 748 | dc.x = x; | 731 | x = xx; |
| 749 | if(m->sel) { | 732 | if(m->sel) { |
| 750 | col = m == selmon ? dc.sel : dc.norm; | 733 | drw_settheme(drw, m == selmon ? thmsel : thmnorm); |
| 751 | drawtext(m->sel->name, col, False); | 734 | drw_text(drw, x, 0, w, bh, m->sel->name, 0); |
| 752 | drawsquare(m->sel->isfixed, m->sel->isfloating, False, col); | 735 | drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0); |
| 736 | } | ||
| 737 | else { | ||
| 738 | drw_settheme(drw, thmnorm); | ||
| 739 | drw_text(drw, x, 0, w, bh, NULL, 0); | ||
| 753 | } | 740 | } |
| 754 | else | ||
| 755 | drawtext(NULL, dc.norm, False); | ||
| 756 | } | 741 | } |
| 757 | XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0); | 742 | drw_map(drw, m->barwin, 0, 0, m->ww, bh); |
| 758 | XSync(dpy, False); | ||
| 759 | } | 743 | } |
| 760 | 744 | ||
| 761 | void | 745 | void |
| @@ -767,45 +751,6 @@ drawbars(void) { | |||
| 767 | } | 751 | } |
| 768 | 752 | ||
| 769 | void | 753 | void |
| 770 | drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { | ||
| 771 | int x; | ||
| 772 | |||
| 773 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | ||
| 774 | x = (dc.font.ascent + dc.font.descent + 2) / 4; | ||
| 775 | if(filled) | ||
| 776 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); | ||
| 777 | else if(empty) | ||
| 778 | XDrawRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x, x); | ||
| 779 | } | ||
| 780 | |||
| 781 | void | ||
| 782 | drawtext(const char *text, unsigned long col[ColLast], Bool invert) { | ||
| 783 | char buf[256]; | ||
| 784 | int i, x, y, h, len, olen; | ||
| 785 | |||
| 786 | XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); | ||
| 787 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); | ||
| 788 | if(!text) | ||
| 789 | return; | ||
| 790 | olen = strlen(text); | ||
| 791 | h = dc.font.ascent + dc.font.descent; | ||
| 792 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | ||
| 793 | x = dc.x + (h / 2); | ||
| 794 | /* shorten text if necessary */ | ||
| 795 | for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); | ||
| 796 | if(!len) | ||
| 797 | return; | ||
| 798 | memcpy(buf, text, len); | ||
| 799 | if(len < olen) | ||
| 800 | for(i = len; i && i > len - 3; buf[--i] = '.'); | ||
| 801 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | ||
| 802 | if(dc.font.set) | ||
| 803 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | ||
| 804 | else | ||
| 805 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); | ||
| 806 | } | ||
| 807 | |||
| 808 | void | ||
| 809 | enternotify(XEvent *e) { | 754 | enternotify(XEvent *e) { |
| 810 | Client *c; | 755 | Client *c; |
| 811 | Monitor *m; | 756 | Monitor *m; |
| @@ -848,7 +793,7 @@ focus(Client *c) { | |||
| 848 | detachstack(c); | 793 | detachstack(c); |
| 849 | attachstack(c); | 794 | attachstack(c); |
| 850 | grabbuttons(c, True); | 795 | grabbuttons(c, True); |
| 851 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); | 796 | XSetWindowBorder(dpy, c->win, thmsel->border->rgb); |
| 852 | setfocus(c); | 797 | setfocus(c); |
| 853 | } | 798 | } |
| 854 | else { | 799 | else { |
| @@ -922,16 +867,6 @@ getatomprop(Client *c, Atom prop) { | |||
| 922 | return atom; | 867 | return atom; |
| 923 | } | 868 | } |
| 924 | 869 | ||
| 925 | unsigned long | ||
| 926 | getcolor(const char *colstr) { | ||
| 927 | Colormap cmap = DefaultColormap(dpy, screen); | ||
| 928 | XColor color; | ||
| 929 | |||
| 930 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) | ||
| 931 | die("error, cannot allocate color '%s'\n", colstr); | ||
| 932 | return color.pixel; | ||
| 933 | } | ||
| 934 | |||
| 935 | Bool | 870 | Bool |
| 936 | getrootptr(int *x, int *y) { | 871 | getrootptr(int *x, int *y) { |
| 937 | int di; | 872 | int di; |
| @@ -1028,40 +963,6 @@ incnmaster(const Arg *arg) { | |||
| 1028 | arrange(selmon); | 963 | arrange(selmon); |
| 1029 | } | 964 | } |
| 1030 | 965 | ||
| 1031 | void | ||
| 1032 | initfont(const char *fontstr) { | ||
| 1033 | char *def, **missing; | ||
| 1034 | int n; | ||
| 1035 | |||
| 1036 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | ||
| 1037 | if(missing) { | ||
| 1038 | while(n--) | ||
| 1039 | fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); | ||
| 1040 | XFreeStringList(missing); | ||
| 1041 | } | ||
| 1042 | if(dc.font.set) { | ||
| 1043 | XFontStruct **xfonts; | ||
| 1044 | char **font_names; | ||
| 1045 | |||
| 1046 | dc.font.ascent = dc.font.descent = 0; | ||
| 1047 | XExtentsOfFontSet(dc.font.set); | ||
| 1048 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | ||
| 1049 | while(n--) { | ||
| 1050 | dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); | ||
| 1051 | dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); | ||
| 1052 | xfonts++; | ||
| 1053 | } | ||
| 1054 | } | ||
| 1055 | else { | ||
| 1056 | if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) | ||
| 1057 | && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) | ||
| 1058 | die("error, cannot load font: '%s'\n", fontstr); | ||
| 1059 | dc.font.ascent = dc.font.xfont->ascent; | ||
| 1060 | dc.font.descent = dc.font.xfont->descent; | ||
| 1061 | } | ||
| 1062 | dc.font.height = dc.font.ascent + dc.font.descent; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | #ifdef XINERAMA | 966 | #ifdef XINERAMA |
| 1066 | static Bool | 967 | static Bool |
| 1067 | isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { | 968 | isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { |
| @@ -1140,7 +1041,7 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1140 | 1041 | ||
| 1141 | wc.border_width = c->bw; | 1042 | wc.border_width = c->bw; |
| 1142 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); | 1043 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); |
| 1143 | XSetWindowBorder(dpy, w, dc.norm[ColBorder]); | 1044 | XSetWindowBorder(dpy, w, thmnorm->border->rgb); |
| 1144 | configure(c); /* propagates border_width, if size doesn't change */ | 1045 | configure(c); /* propagates border_width, if size doesn't change */ |
| 1145 | updatewindowtype(c); | 1046 | updatewindowtype(c); |
| 1146 | updatesizehints(c); | 1047 | updatesizehints(c); |
| @@ -1232,7 +1133,7 @@ movemouse(const Arg *arg) { | |||
| 1232 | ocx = c->x; | 1133 | ocx = c->x; |
| 1233 | ocy = c->y; | 1134 | ocy = c->y; |
| 1234 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, | 1135 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
| 1235 | None, cursor[CurMove], CurrentTime) != GrabSuccess) | 1136 | None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) |
| 1236 | return; | 1137 | return; |
| 1237 | if(!getrootptr(&x, &y)) | 1138 | if(!getrootptr(&x, &y)) |
| 1238 | return; | 1139 | return; |
| @@ -1378,7 +1279,7 @@ resizemouse(const Arg *arg) { | |||
| 1378 | ocx = c->x; | 1279 | ocx = c->x; |
| 1379 | ocy = c->y; | 1280 | ocy = c->y; |
| 1380 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, | 1281 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
| 1381 | None, cursor[CurResize], CurrentTime) != GrabSuccess) | 1282 | None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) |
| 1382 | return; | 1283 | return; |
| 1383 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); | 1284 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
| 1384 | do { | 1285 | do { |
| @@ -1597,10 +1498,12 @@ setup(void) { | |||
| 1597 | /* init screen */ | 1498 | /* init screen */ |
| 1598 | screen = DefaultScreen(dpy); | 1499 | screen = DefaultScreen(dpy); |
| 1599 | root = RootWindow(dpy, screen); | 1500 | root = RootWindow(dpy, screen); |
| 1600 | initfont(font); | 1501 | fnt = drw_font_create(dpy, font); |
| 1601 | sw = DisplayWidth(dpy, screen); | 1502 | sw = DisplayWidth(dpy, screen); |
| 1602 | sh = DisplayHeight(dpy, screen); | 1503 | sh = DisplayHeight(dpy, screen); |
| 1603 | bh = dc.h = dc.font.height + 2; | 1504 | bh = fnt->h + 2; |
| 1505 | drw = drw_create(dpy, screen, root, sw, sh); | ||
| 1506 | drw_setfont(drw, fnt); | ||
| 1604 | updategeom(); | 1507 | updategeom(); |
| 1605 | /* init atoms */ | 1508 | /* init atoms */ |
| 1606 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); | 1509 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
| @@ -1616,21 +1519,16 @@ setup(void) { | |||
| 1616 | netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); | 1519 | netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); |
| 1617 | netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); | 1520 | netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); |
| 1618 | /* init cursors */ | 1521 | /* init cursors */ |
| 1619 | cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | 1522 | cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); |
| 1620 | cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); | 1523 | cursor[CurResize] = drw_cur_create(drw, XC_sizing); |
| 1621 | cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); | 1524 | cursor[CurMove] = drw_cur_create(drw, XC_fleur); |
| 1622 | /* init appearance */ | 1525 | /* init appearance */ |
| 1623 | dc.norm[ColBorder] = getcolor(normbordercolor); | 1526 | thmnorm->border = drw_clr_create(drw, normbordercolor); |
| 1624 | dc.norm[ColBG] = getcolor(normbgcolor); | 1527 | thmnorm->bg = drw_clr_create(drw, normbgcolor); |
| 1625 | dc.norm[ColFG] = getcolor(normfgcolor); | 1528 | thmnorm->fg = drw_clr_create(drw, normfgcolor); |
| 1626 | dc.sel[ColBorder] = getcolor(selbordercolor); | 1529 | thmsel->border = drw_clr_create(drw, selbordercolor); |
| 1627 | dc.sel[ColBG] = getcolor(selbgcolor); | 1530 | thmsel->bg = drw_clr_create(drw, selbgcolor); |
| 1628 | dc.sel[ColFG] = getcolor(selfgcolor); | 1531 | thmsel->fg = drw_clr_create(drw, selfgcolor); |
| 1629 | dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); | ||
| 1630 | dc.gc = XCreateGC(dpy, root, 0, NULL); | ||
| 1631 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | ||
| 1632 | if(!dc.font.set) | ||
| 1633 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | ||
| 1634 | /* init bars */ | 1532 | /* init bars */ |
| 1635 | updatebars(); | 1533 | updatebars(); |
| 1636 | updatestatus(); | 1534 | updatestatus(); |
| @@ -1639,7 +1537,7 @@ setup(void) { | |||
| 1639 | PropModeReplace, (unsigned char *) netatom, NetLast); | 1537 | PropModeReplace, (unsigned char *) netatom, NetLast); |
| 1640 | XDeleteProperty(dpy, root, netatom[NetClientList]); | 1538 | XDeleteProperty(dpy, root, netatom[NetClientList]); |
| 1641 | /* select for events */ | 1539 | /* select for events */ |
| 1642 | wa.cursor = cursor[CurNormal]; | 1540 | wa.cursor = cursor[CurNormal]->cursor; |
| 1643 | wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask | 1541 | wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask |
| 1644 | |EnterWindowMask|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; | 1542 | |EnterWindowMask|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; |
| 1645 | XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); | 1543 | XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); |
| @@ -1699,17 +1597,6 @@ tagmon(const Arg *arg) { | |||
| 1699 | sendmon(selmon->sel, dirtomon(arg->i)); | 1597 | sendmon(selmon->sel, dirtomon(arg->i)); |
| 1700 | } | 1598 | } |
| 1701 | 1599 | ||
| 1702 | int | ||
| 1703 | textnw(const char *text, unsigned int len) { | ||
| 1704 | XRectangle r; | ||
| 1705 | |||
| 1706 | if(dc.font.set) { | ||
| 1707 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 1708 | return r.width; | ||
| 1709 | } | ||
| 1710 | return XTextWidth(dc.font.xfont, text, len); | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | void | 1600 | void |
| 1714 | tile(Monitor *m) { | 1601 | tile(Monitor *m) { |
| 1715 | unsigned int i, n, h, mw, my, ty; | 1602 | unsigned int i, n, h, mw, my, ty; |
| @@ -1787,7 +1674,7 @@ unfocus(Client *c, Bool setfocus) { | |||
| 1787 | if(!c) | 1674 | if(!c) |
| 1788 | return; | 1675 | return; |
| 1789 | grabbuttons(c, False); | 1676 | grabbuttons(c, False); |
| 1790 | XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); | 1677 | XSetWindowBorder(dpy, c->win, thmnorm->border->rgb); |
| 1791 | if(setfocus) { | 1678 | if(setfocus) { |
| 1792 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | 1679 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
| 1793 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 1680 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
| @@ -1846,7 +1733,7 @@ updatebars(void) { | |||
| 1846 | m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), | 1733 | m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), |
| 1847 | CopyFromParent, DefaultVisual(dpy, screen), | 1734 | CopyFromParent, DefaultVisual(dpy, screen), |
| 1848 | CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); | 1735 | CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); |
| 1849 | XDefineCursor(dpy, m->barwin, cursor[CurNormal]); | 1736 | XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); |
| 1850 | XMapRaised(dpy, m->barwin); | 1737 | XMapRaised(dpy, m->barwin); |
| 1851 | } | 1738 | } |
| 1852 | } | 1739 | } |
