From a98d134e89a42909721dcefd426118af38628048 Mon Sep 17 00:00:00 2001 From: EliteTK Date: Thu, 24 Apr 2014 09:06:24 +0100 Subject: Latest random crap. --- xlibtest.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 xlibtest.c (limited to 'xlibtest.c') diff --git a/xlibtest.c b/xlibtest.c new file mode 100644 index 0000000..670dcf6 --- /dev/null +++ b/xlibtest.c @@ -0,0 +1,59 @@ +/* + * Simple Xlib application drawing a box in a window. + * gcc input.c -o output -lX11 + */ + +#include +#include +#include +#include + +int main(void) +{ + Display *display; + Window window; + XEvent event; + char *msg = "Hello, World!"; + int s; + + /* open connection with the server */ + display = XOpenDisplay(NULL); + if (display == NULL) + { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } + + s = DefaultScreen(display); + + /* create window */ + window = XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1, + BlackPixel(display, s), WhitePixel(display, s)); + + /* select kind of events we are interested in */ + XSelectInput(display, window, ExposureMask | KeyPressMask); + + /* map (show) the window */ + XMapWindow(display, window); + + /* event loop */ + for (;;) + { + XNextEvent(display, &event); + + /* draw or redraw the window */ + if (event.type == Expose) + { + XFillRectangle(display, window, DefaultGC(display, s), 20, 20, 10, 10); + XDrawString(display, window, DefaultGC(display, s), 50, 50, msg, strlen(msg)); + } + /* exit on key press */ + if (event.type == KeyPress) + break; + } + + /* close connection to server */ + XCloseDisplay(display); + + return 0; +} -- cgit v1.2.3-54-g00ecf