X 窗口总是空白 [英] X window always blank

查看:18
本文介绍了X 窗口总是空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 X 窗口编程并在此处尝试演示程序:

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

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

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

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

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

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

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?

推荐答案

这个问题和 这个

出于某种原因,XFlushXSync 没有按照您的预期运行.

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

在主要添加

  /* catch expose events */
  XSelectInput(display, win, ExposureMask);

  /* wait for the expose event */
  XEvent ev;
  XNextEvent(display, &ev);

对于您的另一个问题,创建窗口中的 X 和 Y 是屏幕左上角(原点)的起始坐标,而不是放置窗口的位置,这是由窗口管理器决定的.

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.

这篇关于X 窗口总是空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆