1

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?

  • About your second question: see [this](http://stackoverflow.com/a/12466016/775806). – n. m. could be an AI May 30 '13 at 14:28
  • You may want to jump a bit ahead and try the "events" demo from the same site. If it works, try to adapt its repaint code to other demos. The simplistic approach of most X11 tutorials "let's draw some pictures once and talk about events later" may not work in modern environments, and it was never any good anyway, so you may just as well skip that stage. – n. m. could be an AI May 30 '13 at 14:34

1 Answers1

1

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.

Community
  • 1
  • 1
parkydr
  • 7,596
  • 3
  • 32
  • 42