main.c
changeset 795 3b23c75920a3
parent 793 79cb72e82b21
child 800 6133edf536de
equal deleted inserted replaced
794:6fa07beba3a7 795:3b23c75920a3
    60 	XSync(dpy, False);
    60 	XSync(dpy, False);
    61 	free(seltag);
    61 	free(seltag);
    62 }
    62 }
    63 
    63 
    64 static unsigned long
    64 static unsigned long
    65 getcolor(const char *colstr) {
    65 initcolor(const char *colstr) {
    66 	Colormap cmap = DefaultColormap(dpy, screen);
    66 	Colormap cmap = DefaultColormap(dpy, screen);
    67 	XColor color;
    67 	XColor color;
    68 
    68 
    69 	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
    69 	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
    70 		eprint("error, cannot allocate color '%s'\n", colstr);
    70 		eprint("error, cannot allocate color '%s'\n", colstr);
    71 	return color.pixel;
    71 	return color.pixel;
    72 }
    72 }
    73 
    73 
    74 static void
    74 static void
    75 scan(void) {
    75 initfont(const char *fontstr) {
    76 	unsigned int i, num;
       
    77 	Window *wins, d1, d2;
       
    78 	XWindowAttributes wa;
       
    79 
       
    80 	wins = NULL;
       
    81 	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
       
    82 		for(i = 0; i < num; i++) {
       
    83 			if(!XGetWindowAttributes(dpy, wins[i], &wa)
       
    84 			|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
       
    85 				continue;
       
    86 			if(wa.map_state == IsViewable)
       
    87 				manage(wins[i], &wa);
       
    88 		}
       
    89 	}
       
    90 	if(wins)
       
    91 		XFree(wins);
       
    92 }
       
    93 
       
    94 static void
       
    95 setfont(const char *fontstr) {
       
    96 	char *def, **missing;
    76 	char *def, **missing;
    97 	int i, n;
    77 	int i, n;
    98 
    78 
    99 	missing = NULL;
    79 	missing = NULL;
   100 	if(dc.font.set)
    80 	if(dc.font.set)
   128 			eprint("error, cannot load font: '%s'\n", fontstr);
   108 			eprint("error, cannot load font: '%s'\n", fontstr);
   129 		dc.font.ascent = dc.font.xfont->ascent;
   109 		dc.font.ascent = dc.font.xfont->ascent;
   130 		dc.font.descent = dc.font.xfont->descent;
   110 		dc.font.descent = dc.font.xfont->descent;
   131 	}
   111 	}
   132 	dc.font.height = dc.font.ascent + dc.font.descent;
   112 	dc.font.height = dc.font.ascent + dc.font.descent;
       
   113 }
       
   114 
       
   115 static void
       
   116 scan(void) {
       
   117 	unsigned int i, num;
       
   118 	Window *wins, d1, d2;
       
   119 	XWindowAttributes wa;
       
   120 
       
   121 	wins = NULL;
       
   122 	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
       
   123 		for(i = 0; i < num; i++) {
       
   124 			if(!XGetWindowAttributes(dpy, wins[i], &wa)
       
   125 			|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
       
   126 				continue;
       
   127 			if(wa.map_state == IsViewable)
       
   128 				manage(wins[i], &wa);
       
   129 		}
       
   130 	}
       
   131 	if(wins)
       
   132 		XFree(wins);
   133 }
   133 }
   134 
   134 
   135 static void
   135 static void
   136 setup(void) {
   136 setup(void) {
   137 	int i, j;
   137 	int i, j;
   171 	compileregs();
   171 	compileregs();
   172 	for(ntags = 0; tags[ntags]; ntags++);
   172 	for(ntags = 0; tags[ntags]; ntags++);
   173 	seltag = emallocz(sizeof(Bool) * ntags);
   173 	seltag = emallocz(sizeof(Bool) * ntags);
   174 	seltag[0] = True;
   174 	seltag[0] = True;
   175 	/* style */
   175 	/* style */
   176 	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
   176 	dc.norm[ColBorder] = initcolor(NORMBORDERCOLOR);
   177 	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
   177 	dc.norm[ColBG] = initcolor(NORMBGCOLOR);
   178 	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
   178 	dc.norm[ColFG] = initcolor(NORMFGCOLOR);
   179 	dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
   179 	dc.sel[ColBorder] = initcolor(SELBORDERCOLOR);
   180 	dc.sel[ColBG] = getcolor(SELBGCOLOR);
   180 	dc.sel[ColBG] = initcolor(SELBGCOLOR);
   181 	dc.sel[ColFG] = getcolor(SELFGCOLOR);
   181 	dc.sel[ColFG] = initcolor(SELFGCOLOR);
   182 	setfont(FONT);
   182 	initfont(FONT);
   183 	/* geometry */
   183 	/* geometry */
   184 	sx = sy = 0;
   184 	sx = sy = 0;
   185 	sw = DisplayWidth(dpy, screen);
   185 	sw = DisplayWidth(dpy, screen);
   186 	sh = DisplayHeight(dpy, screen);
   186 	sh = DisplayHeight(dpy, screen);
   187 	initlayouts();
   187 	initlayouts();