1

我正在学习 X 窗口编程并在这里尝试一个演示程序:

http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/simple-drawing.c

这是使用 Xlib 库进行基本图形编程的示例代码之一;该教程的链接是http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming.html

问题是上面的演示在我的电脑中总是空白的。程序应该在屏幕上显示一些基本的形状,但在我的电脑中,窗口完全是白色的。我使用的是 Ubuntu 13.04。我通过 gcc simple-drawing.c -o draw -lX11 编译了上面的代码

关于 Xcreatewindow() 的另一个问题:我通过设置 x = 200, y = 200 来指定 XCreatewindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes) 的原点,但是窗口仍然显示在我的显示器的左上角。XCreatewindow() 中的 x 和 y 指的是什么?

4

1 回答 1

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.

于 2013-05-31T08:57:50.710 回答