1

所以我有以下代码,不确定我是否添加了太多/很少,但无论如何它都在那里。

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"));

我遇到的问题是,如果没有 sleep(1),字符串将不会在屏幕上绘制,对于为什么有任何想法有点困惑?

我第一次打电话时,它需要睡觉,但第二次很好:/

4

1 回答 1

0

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

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

要以更可控的方式进行操作,请等待公开事件。

替换为sleep

XSelectInput(proc->display, root, ExposureMask);
XEvent ev;
XNextEvent(proc->display, &ev);
于 2013-08-09T13:15:41.183 回答