1

So I have the following code, notsure if I have added too much/little but its there for conext anyway.

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

The problem I am having is that without the sleep(1), the string will not get drawn on the screen, slightly confused as to why any ideas?

The first time i call it, it needs a sleep but the second time it is fine :/

cxzp
  • 652
  • 2
  • 14
  • 28

1 Answers1

0

It seems to be another variation of this and this.

Events don't seem to flush properly any more, the sleep gives time for the events to come through.

To do it a bit more of a controlled way, wait for the expose event.

Replace the sleep with:

XSelectInput(proc->display, root, ExposureMask);
XEvent ev;
XNextEvent(proc->display, &ev);
Community
  • 1
  • 1
parkydr
  • 7,596
  • 3
  • 32
  • 42