ltkx

GUI toolkit for X11 (WIP)
git clone git://lumidify.org/ltkx.git
Log | Files | Refs | README | LICENSE

main.c (1396B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <X11/Xlib.h>
      4 #include <X11/Xutil.h>
      5 #include <X11/Xos.h>
      6 
      7 int main(int argc, char *argv[])
      8 {
      9 	Display *display;
     10 	int screen;
     11 	Window window;
     12 	GC gc;
     13 
     14 	unsigned long black, white;
     15 	XColor green;
     16 	Colormap colormap;
     17 	display = XOpenDisplay((char *) 0);
     18 	screen = DefaultScreen(display);
     19 	colormap = DefaultColormap(display, screen);
     20 	black = BlackPixel(display, screen);
     21 	white = WhitePixel(display, screen);
     22 	XParseColor(display, colormap, "#00FF00", &green);
     23 	XAllocColor(display, colormap, &green);
     24 	window =
     25 	    XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
     26 				200, 300, 0, white, green.pixel);
     27 	XSetStandardProperties(display, window, "Random Window", NULL,
     28 			       None, NULL, 0, NULL);
     29 	XSelectInput(display, window,
     30 		     ExposureMask | ButtonPressMask | KeyPressMask);
     31 	gc = XCreateGC(display, window, 0, 0);
     32 	XSetBackground(display, gc, white);
     33 	XSetForeground(display, gc, black);
     34 	XClearWindow(display, window);
     35 	XMapRaised(display, window);
     36 
     37 	XEvent event;
     38 	KeySym key;
     39 	char text[255];
     40 
     41 	while (1) {
     42 		XNextEvent(display, &event);
     43 		if (event.type == KeyPress
     44 		    && XLookupString(&event.xkey, text, 255, &key,
     45 				     0) == 1) {
     46 			if (text[0] == 'q') {
     47 				XFreeGC(display, gc);
     48 				XFreeColormap(display, colormap);
     49 				XDestroyWindow(display, window);
     50 				XCloseDisplay(display);
     51 				exit(0);
     52 			}
     53 		}
     54 	}
     55 }