#include #include #include #include using namespace std; // Globals--sue me. Display *dpy; GC gc; Window win; // The window needs repainting. Do so. void refresh() { XWindowAttributes xwa; if (XGetWindowAttributes(dpy, win, &xwa) == 0) return; // Draw a big thick X const auto w = xwa.width, h = xwa.height; XSetForeground(dpy, gc, random() & 0xffffff); XFillRectangle(dpy, win, gc, 0, 0, w, h); XSetForeground(dpy, gc, random() & 0xffffff); XSetLineAttributes(dpy, gc, w/6, LineSolid, CapButt, JoinMiter); XDrawLine(dpy, win, gc, 0, 0, w-1, h-1); XDrawLine(dpy, win, gc, w-1, 0, 0, h-1); XFlush(dpy); } int main() { dpy = XOpenDisplay(nullptr); if (dpy == nullptr) { cerr << "Can't open display\n"; return 1; } const int screen = DefaultScreen(dpy); gc = DefaultGC(dpy, screen); win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 50, 50, 800, 800, 0, 0xffffff, 0x000000); XSelectInput(dpy, win, ExposureMask); XMapWindow(dpy, win); for (int event_counter=0; ; ) { cout << "\rWaiting for event #" << ++event_counter << ' ' << flush; XEvent event; // Event received XNextEvent(dpy, &event); // Wait for the next event if (event.type == Expose && event.xexpose.count == 0) refresh(); } }