【发布时间】:2013-10-10 20:51:20
【问题描述】:
我不确定为什么会发生这种情况,但是当我尝试关闭使用 X 按钮时,我在 C++ 中使用 Xlib 创建的任何窗口都会向终端输出错误。我可以无错误地以编程方式关闭它,只需 X 按钮即可。
错误如下:
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 483 requests (483 known processed) with 0 events remaining.
每次请求的数量都不一样,但总是剩下 0 个事件。为什么会这样?原因似乎不是我的代码,因为无论如何它都会这样做并且不会向队列发送关闭事件。我试过拦截 Atom WM_WINDOW_DELETE,当我关闭窗口时它没有运行在预期的代码上。
编辑:添加事件循环代码。
while(XPending(display)) {
XNextEvent(display, &event);
pthread_mutex_unlock(&mutex);
if(event.type == Expose) {
XWindowAttributes getWindowAttributes;
pthread_mutex_lock(&mutex);
XGetWindowAttributes(display, window, &getWindowAttributes);
if(state.currentState == STATE_NORMAL) {
state.normX = getWindowAttributes.x;
state.normY = getWindowAttributes.y;
state.normWidth = getWindowAttributes.width;
state.normHeight = getWindowAttributes.height;
}
pthread_mutex_unlock(&mutex);
glViewport(0, 0, getWindowAttributes.width, getWindowAttributes.height);
} else if(event.type == KeyPress) {
return false;
} else if(event.type == ClientMessage) {
std::cout<<"X Button pressed"<<std::endl; //Never run when X-ing window
if(event.xclient.message_type == XInternAtom(display, "WM_DELETE_WINDOW", True)) {
return false;
}
} else if(event.type == ButtonPress) {
if(state.currentState != STATE_FULLSCREEN) {
fullscreen();
} else {
normalize();
}
} else if(!handleEvent(event)){
return false;
}
pthread_mutex_lock(&mutex);
}
【问题讨论】:
-
任何窗口,甚至是弹出窗口或瞬态窗口?
-
除了
WM_WINDOW_DELETE,你还需要监听和处理ClientMessage事件。显示您的代码。WM_WINDOW_DELETE. -
添加了事件循环代码 - 我已经在寻找 ClientMessage。关闭错误是关闭窗口的行为,因此不会收到任何消息。
-
到目前为止我只使用过普通的 XWindows,所以可能没有弹出窗口或瞬态。