main.c
changeset 988 aea51354bbe6
parent 987 ea0cef59c3a3
child 989 5f7018237edb
equal deleted inserted replaced
987:ea0cef59c3a3 988:aea51354bbe6
    15 
    15 
    16 /* extern */
    16 /* extern */
    17 
    17 
    18 char stext[256];
    18 char stext[256];
    19 int screen, sx, sy, sw, sh, wax, way, waw, wah;
    19 int screen, sx, sy, sw, sh, wax, way, waw, wah;
    20 unsigned int bh, ntags;
    20 unsigned int ntags;
    21 unsigned int bpos = BARPOS;
       
    22 unsigned int numlockmask = 0;
    21 unsigned int numlockmask = 0;
    23 Atom wmatom[WMLast], netatom[NetLast];
    22 Atom wmatom[WMLast], netatom[NetLast];
    24 Bool *seltags;
    23 Bool *seltags;
    25 Bool selscreen = True;
    24 Bool selscreen = True;
    26 Client *clients = NULL;
    25 Client *clients = NULL;
    27 Client *sel = NULL;
    26 Client *sel = NULL;
    28 Client *stack = NULL;
    27 Client *stack = NULL;
    29 Cursor cursor[CurLast];
    28 Cursor cursor[CurLast];
    30 Display *dpy;
    29 Display *dpy;
    31 DC dc = {0};
    30 Window root;
    32 Window root, barwin;
       
    33 
    31 
    34 /* static */
    32 /* static */
    35 
    33 
    36 static int (*xerrorxlib)(Display *, XErrorEvent *);
    34 static int (*xerrorxlib)(Display *, XErrorEvent *);
    37 static Bool otherwm, readin;
    35 static Bool otherwm, readin;
    56 	XFreeCursor(dpy, cursor[CurResize]);
    54 	XFreeCursor(dpy, cursor[CurResize]);
    57 	XFreeCursor(dpy, cursor[CurMove]);
    55 	XFreeCursor(dpy, cursor[CurMove]);
    58 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
    56 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
    59 	XSync(dpy, False);
    57 	XSync(dpy, False);
    60 	free(seltags);
    58 	free(seltags);
    61 }
       
    62 
       
    63 static unsigned long
       
    64 initcolor(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 
       
    73 static void
       
    74 initfont(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 }
    59 }
   113 
    60 
   114 static long
    61 static long
   115 getstate(Window w) {
    62 getstate(Window w) {
   116 	int format, status;
    63 	int format, status;
   195 	grabkeys();
   142 	grabkeys();
   196 	compileregs();
   143 	compileregs();
   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 }
   234 
   156 
   235 /*
   157 /*