|
| 1 | +#include <X11/Xlib.h> |
| 2 | +#include <X11/Xutil.h> |
| 3 | +#include <X11/Xos.h> |
| 4 | + |
| 5 | +static Display *display; |
| 6 | +static Window root; |
| 7 | +static int screen; |
| 8 | + |
| 9 | +Window createWindow(int x, int y, int width, int height, int border, long borderColor, long rgb) { |
| 10 | + Window window = XCreateSimpleWindow(display, root, x, y, width, height, border, borderColor, rgb); |
| 11 | + return window; |
| 12 | +} |
| 13 | + |
| 14 | +long rgb(int r, int g, int b) { |
| 15 | + return b + (g<<8) + (r<<16); |
| 16 | +} |
| 17 | + |
| 18 | +int start(int x, int y, int width, int height, int border, long borderColor, long rgb, char[] windowTitle) { |
| 19 | + Window window; |
| 20 | + |
| 21 | + if((display = XOpenDisplay(NULL)) == NULL) { |
| 22 | + printf("%s\n", "Couldn't open display"); |
| 23 | + return 1; |
| 24 | + } |
| 25 | + |
| 26 | + /* Get default screen and root window */ |
| 27 | + screen = DefaultScreen(display); |
| 28 | + root = RootWindow(display, screen); |
| 29 | + |
| 30 | + window = createWindow(x, y, width, height, border, borderColor, rgb); |
| 31 | + XSetStandardProperties(display, window, windowTitle, "", None, NULL, 0, NULL); |
| 32 | + /* Map window to display server */ |
| 33 | + XMapWindow(display, window); |
| 34 | + |
| 35 | + /* Unmap window */ |
| 36 | + XUnmapWindow(display, window); |
| 37 | + XDestroyWindow(display, window); |
| 38 | + /* Close connection with display server */ |
| 39 | + XCloseDisplay(display); |
| 40 | + return 0; |
| 41 | +} |
0 commit comments