summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDon Stewart <dons@cse.unsw.edu.au>2007-05-27 14:59:28 +0200
committerDon Stewart <dons@cse.unsw.edu.au>2007-05-27 14:59:28 +0200
commit793deacd432b8a3aeb227ffa3e7203a9ca0e5053 (patch)
treea0be2fddf283c6521ec3b8399ce61372c63b3532 /util
parentfb64aaf78368b7edf3affcb6e1fe4c48327f62d0 (diff)
downloadmetatile-793deacd432b8a3aeb227ffa3e7203a9ca0e5053.tar
metatile-793deacd432b8a3aeb227ffa3e7203a9ca0e5053.zip
mod-b, toggle on or off the status bar gap
darcs-hash:20070527125928-9c5c1-a16246810db9d4abfe81d0d5814721b64f59a14c
Diffstat (limited to 'util')
-rw-r--r--util/gapcalc.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/util/gapcalc.c b/util/gapcalc.c
new file mode 100644
index 0000000..4a4c3db
--- /dev/null
+++ b/util/gapcalc.c
@@ -0,0 +1,70 @@
+/* gapcalc - calculate height of given font
+ * Copyright (C) 2007 by Robert Manea <rob.manea@gmail.com>
+ *
+ * Compile with: cc -lX11 -o gapcalc gapcalc.c
+ */
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<stdarg.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+void
+eprint(const char *errstr, ...) {
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
+
+int
+main(int argc, char *argv[]) {
+ Display *dpy;
+ XFontStruct *xfont;
+ XFontSet set;
+ char *def, **missing;
+ char *fontstr;
+ int i, n, ascent, descent;
+
+ if(argc < 2)
+ eprint("Usage: gapcalc <font>\n");
+
+ if(!(dpy = XOpenDisplay(0)))
+ eprint("fatal: cannot open display\n");
+
+ fontstr = argv[1];
+ missing = NULL;
+
+ set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
+ if(missing)
+ XFreeStringList(missing);
+ if(set) {
+ XFontSetExtents *font_extents;
+ XFontStruct **xfonts;
+ char **font_names;
+ ascent = descent = 0;
+ font_extents = XExtentsOfFontSet(set);
+ n = XFontsOfFontSet(set, &xfonts, &font_names);
+ for(i = 0, ascent = 0, descent = 0; i < n; i++) {
+ if(ascent < (*xfonts)->ascent)
+ ascent = (*xfonts)->ascent;
+ if(descent < (*xfonts)->descent)
+ descent = (*xfonts)->descent;
+ xfonts++;
+ }
+ } else if(!set && (xfont = XLoadQueryFont(dpy, fontstr))) {
+ ascent = xfont->ascent;
+ descent = xfont->descent;
+ } else
+ eprint("fatal: cannot find specified font\n");
+
+ printf("%d\n", ascent + descent + 2);
+
+
+ return EXIT_SUCCESS;
+}
+