我正在使用以下代码为某些集成测试创建假窗口:
class CXWindowsClipboardTests
{
protected:
virtual void
SetUp()
{
m_display = XOpenDisplay(NULL);
int screen = DefaultScreen(m_display);
Window root = XRootWindow(m_display, screen);
XSetWindowAttributes attr;
attr.do_not_propagate_mask = 0;
attr.override_redirect = True;
attr.cursor = Cursor();
m_window = XCreateWindow(
m_display, root, 0, 0, 1, 1, 0, 0,
InputOnly, CopyFromParent,
CWDontPropagate | CWEventMask |
CWOverrideRedirect | CWCursor,
&attr);
}
virtual void
TearDown()
{
XDestroyWindow(m_display, m_window);
XCloseDisplay(m_display);
}
};
以上是原始代码的修改版本,占用的空间更少(参见full source code)。
以上代码在CentOS 5.6上间歇性失败,并出现以下错误:
X Error of failed request: BadValue
(integer parameter out of range for operation)
Major opcode of failed request: 1 (X_CreateWindow)
Value in failed request: 0x844b530
Serial number of failed request: 7
Current serial number in output stream: 8
所以,真的有两个问题:
答案 0 :(得分:1)
您正在使用CWEventMask
但未初始化attr.event_mask
。这可能是你的问题。 (由于结构是在堆栈上创建的,因此它将包含该字段中的随机数据。)