commit 87312cd7e93aa59de79d55c4a70a51ab3fe14750 Author: Wesley Kerfoot Date: Thu Jun 20 14:17:24 2019 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cba7efc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +a.out diff --git a/blit.c b/blit.c new file mode 100644 index 0000000..08130ec --- /dev/null +++ b/blit.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +int +main(void) { + Display *display; + Window window; + XEvent event; + + const char *msg = "Hello, world!\n"; + + int screen; + + // Opens the current display + display = XOpenDisplay(NULL); + + if (display == NULL) { + fprintf(stderr, "Could not open the display! :(\n"); + exit(1); + } + + printf("%p\n", display); + + screen = DefaultScreen(display); + + window = XCreateSimpleWindow(display, + RootWindow(display, screen), + 10, + 10, + 100, + 100, + 1, + BlackPixel(display, screen), + WhitePixel(display, screen)); + + printf("%p\n", window); + + XSelectInput(display, + window, + ExposureMask | KeyPressMask); + + XMapWindow(display, window); + + while (1) { + /* Event loop that handles events from the X server's event queue */ + /* Will actually block if there are no events */ + + XNextEvent(display, &event); + if (event.type == Expose) { + + XFillRectangle(display, + window, + DefaultGC(display, screen), + 20, + 20, + 10, + 10); + + XDrawString(display, + window, + DefaultGC(display, screen), + 10, + 50, + msg, + strlen(msg)); + } + + if (event.type == KeyPress) { + break; + } + + } + + XCloseDisplay(display); + + return 0; +} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6772165 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash + + +xlib=$(pkg-config --cflags --libs x11) + +gcc $xlib blit.c