about summary refs log tree commit diff stats
path: root/font.c
diff options
context:
space:
mode:
Diffstat (limited to 'font.c')
-rw-r--r--font.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/font.c b/font.c
new file mode 100644
index 0000000..99301b5
--- /dev/null
+++ b/font.c
@@ -0,0 +1,81 @@
+/*
+ * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+unsigned int
+textwidth_l(BlitzFont *font, char *text, unsigned int len)
+{
+	if(font->set) {
+		XRectangle r;
+		XmbTextExtents(font->set, text, len, nil, &r);
+		return r.width;
+	}
+	return XTextWidth(font->xfont, text, len);
+}
+
+unsigned int
+textwidth(BlitzFont *font, char *text)
+{
+	return blitz_textwidth_l(font, text, strlen(text));
+}
+
+void
+loadfont(Blitz *blitz, BlitzFont *font)
+{
+	char *fontname = font->fontstr;
+	char **missing = nil, *def = "?";
+	int n;
+
+	setlocale(LC_ALL, "");
+	if(font->set)
+		XFreeFontSet(blitz->dpy, font->set);
+	font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
+	if(missing) {
+		while(n--)
+			fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
+		XFreeStringList(missing);
+		if(font->set) {
+			XFreeFontSet(blitz->dpy, font->set);
+			font->set = nil;
+		}
+	}
+	if(font->set) {
+		XFontSetExtents *font_extents;
+		XFontStruct **xfonts;
+		char **font_names;
+		unsigned int i;
+
+		font->ascent = font->descent = 0;
+		font_extents = XExtentsOfFontSet(font->set);
+		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
+		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
+			if(font->ascent < (*xfonts)->ascent)
+				font->ascent = (*xfonts)->ascent;
+			if(font->descent < (*xfonts)->descent)
+				font->descent = (*xfonts)->descent;
+			xfonts++;
+		}
+	}
+	else {
+		if(font->xfont)
+			XFreeFont(blitz->dpy, font->xfont);
+		font->xfont = nil;
+		font->xfont = XLoadQueryFont(blitz->dpy, fontname);
+		if (!font->xfont) {
+			fontname = "fixed";
+			font->xfont = XLoadQueryFont(blitz->dpy, fontname);
+		}
+		if (!font->xfont) {
+			fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
+			exit(1);
+		}
+		font->ascent = font->xfont->ascent;
+		font->descent = font->xfont->descent;
+	}
+}
committer Anselm R. Garbe <garbeam@wmii.de> 2006-07-13 01:04:38 +0200 before leaning things up' href='/acidbong/suckless/dwm/commit/kb.c?h=5.8.1&id=da2bbd371c522d63d737d43a127601a3fdbcb9d8'>da2bbd3 ^
366d81e ^
d7e1708 ^
366d81e ^










16c67f3 ^












586f663 ^
16c67f3 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59








                                                              

                                 
                       
                                                                     
                                                               

  
                    
                                                               

                                         

                                            
                                       
                                                     
                                                   

  

                                 
    
                 










                                                                                          












                                                                            
                                                        


                               
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include "wm.h"

#include <X11/keysym.h>

/********** CUSTOMIZE **********/

const char *term[] = { 
	"aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
	"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
};

static Key key[] = {
	{ Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
	{ Mod1Mask, XK_k, sel, "prev" }, 
	{ Mod1Mask, XK_j, sel, "next" }, 
	{ Mod1Mask, XK_g, grid, NULL }, 
	{ Mod1Mask, XK_f, floating, NULL }, 
	{ Mod1Mask, XK_m, max, NULL }, 
	{ Mod1Mask | ShiftMask, XK_c, ckill, NULL }, 
	{ Mod1Mask | ShiftMask, XK_q, quit, NULL },
};

/********** CUSTOMIZE **********/

void
update_keys(void)
{
	unsigned int i, len;
	KeyCode code;

	len = sizeof(key) / sizeof(key[0]);
	for(i = 0; i < len; i++) {
		code = XKeysymToKeycode(dpy, key[i].keysym);
		XUngrabKey(dpy, code, key[i].mod, root);
		XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
	}
}

void
keypress(XEvent *e)
{
	XKeyEvent *ev = &e->xkey;
	unsigned int i, len;
	KeySym keysym;

	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
	len = sizeof(key) / sizeof(key[0]);
	for(i = 0; i < len; i++)
		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
			if(key[i].func)
				key[i].func(key[i].aux);
			return;
		}
}