Reputation: 47
I am learning X window programming and try a demo program here:
http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/simple-drawing.c
which is one sample code of Basic Graphics Programming With The Xlib Library; The link of that tutorial is http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming.html
The problem is that the demo above is always blank in my computer. The program should show some basic shapes on the screen but in my computer, the window is just totally white. I'm using Ubuntu 13.04.I compile the code above by gcc simple-drawing.c -o draw -lX11
Another question about Xcreatewindow(): I specify the origin of XCreatewindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes) by setting x = 200, y = 200, but the window still shows on the upper-left corner of my monitor. What does the x and y in XCreatewindow() refer to?
Upvotes: 1
Views: 1286
Reputation: 7782
This is the same problem as this one
For some reason the XFlush
and XSync
don't act as you'd expect.
The solution is to wait for the expose event then draw the shapes. So after
/* allocate a new GC (graphics context) for drawing in the window. */
gc = create_gc(display, win, 0);
XSync(display, False);
in main add
/* catch expose events */
XSelectInput(display, win, ExposureMask);
/* wait for the expose event */
XEvent ev;
XNextEvent(display, &ev);
For your other question, the X and Y in create window are the starting co-ordinates of the top left of the screen (the origin), not where the window is placed, which is determined by the window manager.
Upvotes: 1