From 115cb5abf398d0bc30f44d2e0550b39004e8ffc2 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 26 Apr 2022 17:12:55 -0400 Subject: displaying a hello message --- xbar.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'xbar.c') diff --git a/xbar.c b/xbar.c index 01090fa..d0c3732 100644 --- a/xbar.c +++ b/xbar.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -24,21 +25,44 @@ int main(int argc, char *argv[]) } int screen = DefaultScreen(dpy); + + Colormap cmap = XDefaultColormap(dpy, screen); + XColor bg; + if (XParseColor(dpy, cmap, "black", &bg) == 0) { + fprintf(stderr, "couldn't find black\n"); + bg.pixel = BlackPixel(dpy, 0); + } else if (XAllocColor(dpy, cmap, &bg) == 0) { + fprintf(stderr, "couldn't allocate black\n"); + bg.pixel = BlackPixel(dpy, 0); + } + + XColor fg; + if (XParseColor(dpy, cmap, "white", &fg) == 0) { + fprintf(stderr, "couldn't find white\n"); + fg.pixel = WhitePixel(dpy, 0); + } else if (XAllocColor(dpy, cmap, &fg) == 0) { + fprintf(stderr, "couldn't allocate white\n"); + fg.pixel = WhitePixel(dpy, 0); + } + int width = DisplayWidth(dpy, screen); int height = 20; Window win = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), - 0, 0, width, height, 0, - BlackPixel(dpy, screen), BlackPixel(dpy, screen)); + 0, 0, width, height, 0, 0, bg.pixel); + XStoreName(dpy, win, "xbar"); XSelectInput(dpy, win, ExposureMask | KeyPressMask); XMapWindow(dpy, win); + XMoveWindow(dpy, win, 0, 0); + + XSetForeground(dpy, DefaultGC(dpy, screen), fg.pixel); for (;;) { XEvent e; XNextEvent(dpy, &e); switch (e.type) { case Expose: - XDrawString(dpy, win, DefaultGC(dpy, screen), 0, 0, + XDrawString(dpy, win, DefaultGC(dpy, screen), 10, 10, "hello", strlen("hello")); break; -- cgit v1.2.1