我不太确定为什么XFlush不起作用,但这是事件循环和冲洗的混合体。它等待暴露事件,绘制字符串并退出循环。
5秒钟后,它将取消映射窗口,然后5秒钟后退出。
#include <X11/Xlib.h>#include <X11/Xatom.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(void){ Display *d; Window w; XEvent e; const char *msg = "Hello, World!"; int s; bool done = false; d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open displayn"); exit(1); } s = DefaultScreen(d); w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 480, 320, 0,BlackPixel(d, s), WhitePixel(d, s)); Atom type = XInternAtom(d,"_NET_WM_WINDOW_TYPE", False); Atom value = XInternAtom(d,"_NET_WM_WINDOW_TYPE_SPLASH", False); XChangeProperty(d, w, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1); Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False); XSetWMProtocols(d, w, &wmDeleteMessage, 1); XSelectInput(d, w, ExposureMask); XMapWindow(d, w); while (!done) { XNextEvent(d, &e); if (e.type == Expose) { XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg)); done = true; } } XFlush(d); sleep(5); XUnmapWindow(d,w); XFlush(d); printf("unmappedn"); sleep(5); XCloseDisplay(d); return 0;}


