summaryrefslogtreecommitdiffstats
path: root/draw
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--draw.c57
-rw-r--r--draw.h45
2 files changed, 70 insertions, 32 deletions
diff --git a/draw.c b/draw.c
index 932b2f6..688bd69 100644
--- a/draw.c
+++ b/draw.c
@@ -1,37 +1,20 @@
/* See LICENSE file for copyright and license details. */
-
-/* enums */
-enum { ColFG, ColBG, ColLast };
-
-/* typedefs */
-typedef struct {
- int x, y, w, h;
- unsigned long norm[ColLast];
- unsigned long sel[ColLast];
- Drawable drawable;
- GC gc;
- struct {
- XFontStruct *xfont;
- XFontSet set;
- int ascent;
- int descent;
- int height;
- } font;
-} DC; /* draw context */
-
-/* forward declarations */
-static void dccleanup(void);
-static void dcsetup(void);
-static void drawtext(const char *text, unsigned long col[ColLast]);
-static unsigned long getcolor(const char *colstr);
-static void initfont(const char *fontstr);
-static int textnw(const char *text, unsigned int len);
-static int textw(const char *text);
-
-static DC dc;
+#include <ctype.h>
+#include <locale.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <X11/Xlib.h>
+#include "draw.h"
+
+/* macros */
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
void
-dccleanup(void) {
+drawcleanup(void) {
if(dc.font.set)
XFreeFontSet(dpy, dc.font.set);
else
@@ -41,7 +24,7 @@ dccleanup(void) {
}
void
-dcsetup(void) {
+drawsetup(void) {
/* style */
dc.norm[ColBG] = getcolor(normbgcolor);
dc.norm[ColFG] = getcolor(normfgcolor);
@@ -84,6 +67,16 @@ drawtext(const char *text, unsigned long col[ColLast]) {
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
+void
+eprint(const char *errstr, ...) {
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
unsigned long
getcolor(const char *colstr) {
Colormap cmap = DefaultColormap(dpy, screen);
diff --git a/draw.h b/draw.h
new file mode 100644
index 0000000..79db37e
--- /dev/null
+++ b/draw.h
@@ -0,0 +1,45 @@
+/* See LICENSE file for copyright and license details. */
+
+/* enums */
+enum { ColFG, ColBG, ColLast };
+
+/* typedefs */
+typedef struct {
+ int x, y, w, h;
+ unsigned long norm[ColLast];
+ unsigned long sel[ColLast];
+ Drawable drawable;
+ GC gc;
+ struct {
+ XFontStruct *xfont;
+ XFontSet set;
+ int ascent;
+ int descent;
+ int height;
+ } font;
+} DC; /* draw context */
+
+/* forward declarations */
+void drawcleanup(void);
+void drawsetup(void);
+void drawtext(const char *text, unsigned long col[ColLast]);
+void eprint(const char *errstr, ...);
+unsigned long getcolor(const char *colstr);
+void initfont(const char *fontstr);
+int textnw(const char *text, unsigned int len);
+int textw(const char *text);
+
+/* variables */
+Display *dpy;
+DC dc;
+int screen;
+unsigned int mw, mh;
+unsigned int spaceitem;
+Window parent;
+
+/* style */
+const char *font;
+const char *normbgcolor;
+const char *normfgcolor;
+const char *selbgcolor;
+const char *selfgcolor;