summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c84
1 files changed, 3 insertions, 81 deletions
diff --git a/main.c b/main.c
index 26bec25..de38cbc 100644
--- a/main.c
+++ b/main.c
@@ -17,8 +17,7 @@
17 17
18char stext[256]; 18char stext[256];
19int screen, sx, sy, sw, sh, wax, way, waw, wah; 19int screen, sx, sy, sw, sh, wax, way, waw, wah;
20unsigned int bh, ntags; 20unsigned int ntags;
21unsigned int bpos = BARPOS;
22unsigned int numlockmask = 0; 21unsigned int numlockmask = 0;
23Atom wmatom[WMLast], netatom[NetLast]; 22Atom wmatom[WMLast], netatom[NetLast];
24Bool *seltags; 23Bool *seltags;
@@ -28,8 +27,7 @@ Client *sel = NULL;
28Client *stack = NULL; 27Client *stack = NULL;
29Cursor cursor[CurLast]; 28Cursor cursor[CurLast];
30Display *dpy; 29Display *dpy;
31DC dc = {0}; 30Window root;
32Window root, barwin;
33 31
34/* static */ 32/* static */
35 33
@@ -60,57 +58,6 @@ cleanup(void) {
60 free(seltags); 58 free(seltags);
61} 59}
62 60
63static unsigned long
64initcolor(const char *colstr) {
65 Colormap cmap = DefaultColormap(dpy, screen);
66 XColor color;
67
68 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
69 eprint("error, cannot allocate color '%s'\n", colstr);
70 return color.pixel;
71}
72
73static void
74initfont(const char *fontstr) {
75 char *def, **missing;
76 int i, n;
77
78 missing = NULL;
79 if(dc.font.set)
80 XFreeFontSet(dpy, dc.font.set);
81 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
82 if(missing) {
83 while(n--)
84 fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
85 XFreeStringList(missing);
86 }
87 if(dc.font.set) {
88 XFontSetExtents *font_extents;
89 XFontStruct **xfonts;
90 char **font_names;
91 dc.font.ascent = dc.font.descent = 0;
92 font_extents = XExtentsOfFontSet(dc.font.set);
93 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
94 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
95 if(dc.font.ascent < (*xfonts)->ascent)
96 dc.font.ascent = (*xfonts)->ascent;
97 if(dc.font.descent < (*xfonts)->descent)
98 dc.font.descent = (*xfonts)->descent;
99 xfonts++;
100 }
101 }
102 else {
103 if(dc.font.xfont)
104 XFreeFont(dpy, dc.font.xfont);
105 dc.font.xfont = NULL;
106 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
107 eprint("error, cannot load font: '%s'\n", fontstr);
108 dc.font.ascent = dc.font.xfont->ascent;
109 dc.font.descent = dc.font.xfont->descent;
110 }
111 dc.font.height = dc.font.ascent + dc.font.descent;
112}
113
114static long 61static long
115getstate(Window w) { 62getstate(Window w) {
116 int format, status; 63 int format, status;
@@ -197,37 +144,12 @@ setup(void) {
197 for(ntags = 0; tags[ntags]; ntags++); 144 for(ntags = 0; tags[ntags]; ntags++);
198 seltags = emallocz(sizeof(Bool) * ntags); 145 seltags = emallocz(sizeof(Bool) * ntags);
199 seltags[0] = True; 146 seltags[0] = True;
200 /* style */
201 dc.norm[ColBorder] = initcolor(NORMBORDERCOLOR);
202 dc.norm[ColBG] = initcolor(NORMBGCOLOR);
203 dc.norm[ColFG] = initcolor(NORMFGCOLOR);
204 dc.sel[ColBorder] = initcolor(SELBORDERCOLOR);
205 dc.sel[ColBG] = initcolor(SELBGCOLOR);
206 dc.sel[ColFG] = initcolor(SELFGCOLOR);
207 initfont(FONT);
208 /* geometry */ 147 /* geometry */
209 sx = sy = 0; 148 sx = sy = 0;
210 sw = DisplayWidth(dpy, screen); 149 sw = DisplayWidth(dpy, screen);
211 sh = DisplayHeight(dpy, screen); 150 sh = DisplayHeight(dpy, screen);
212 initlayouts(); 151 initlayouts();
213 /* bar */ 152 initbar();
214 dc.h = bh = dc.font.height + 2;
215 wa.override_redirect = 1;
216 wa.background_pixmap = ParentRelative;
217 wa.event_mask = ButtonPressMask | ExposureMask;
218 barwin = XCreateWindow(dpy, root, sx, sy, sw, bh, 0,
219 DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
220 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
221 XDefineCursor(dpy, barwin, cursor[CurNormal]);
222 updatebarpos();
223 XMapRaised(dpy, barwin);
224 strcpy(stext, "dwm-"VERSION);
225 /* pixmap for everything */
226 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
227 dc.gc = XCreateGC(dpy, root, 0, 0);
228 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
229 if(!dc.font.set)
230 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
231 /* multihead support */ 153 /* multihead support */
232 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 154 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
233} 155}