奇怪的屁股XLib bug; XDrawString仅在睡眠后起作用

时间:2013-08-07 08:43:03

标签: c user-interface xlib

所以我有以下代码,不知道我是否添加了太多/很少但是它仍然用于conext。

Window root = XCreateWindow(proc->display,    
                           RootWindow(proc->display, screen),
                           0, 0, width + 500, height + 500, 0, 
                           CopyFromParent, InputOutput,
                           CopyFromParent, CWEventMask, &attr);

XSetWindowBackground(proc->display, root, WhitePixel(proc->display, screen));

XFlush(proc->display);
XMapWindow(proc->display, root);

Window avaliableDevices = XCreateSimpleWindow(proc->display, root, 10, 50,
            220, 650, 5, BlackPixel(proc->display, screen), 
            WhitePixel(proc->display, screen));

XFlush(proc->display);
XMapWindow(proc->display, avaliableDevices);

sleep(1);
XDrawString(proc->display, root, DefaultGC(proc->display, DefaultScreen(proc->display))
    , 20, 20, "hello", strlen("hello"));

Window networkedDevices = XCreateSimpleWindow(proc->display, root, /* display, parent */
            900, 50, /* x, y: the window manager will place the window elsewhere */
            220, 650, /* width, height */
            5, BlackPixel(proc->display, screen), /* border width & colour, unless you have a window manager */
            WhitePixel(proc->display, screen)); /* background colour */

XDrawString(proc->display, root, DefaultGC(proc->display, DefaultScreen(proc->display))
    , 920, 40, "NETWORKED DEVICES", strlen("NETWORKED DEVICES"));

我遇到的问题是没有睡眠(1),字符串不会在屏幕上绘制,为什么有任何想法有点混淆?

我第一次打电话给它,它需要一个睡眠,但第二次没问题:/

1 个答案:

答案 0 :(得分:0)

它似乎是thisthis的另一种变体。

事件似乎不再正常冲洗,睡眠为事件提供了时间。

要做一些受控制的方式,等待曝光事件。

sleep替换为:

XSelectInput(proc->display, root, ExposureMask);
XEvent ev;
XNextEvent(proc->display, &ev);