0
我是一個xlib的初學者。我嘗試使用基於此示例的select()編寫Xwindow應用程序:how to quit the blocking of xlib's XNextEvent。C和xlib:XPending()在一個非常簡單的程序中崩潰
但上面提到的代碼在XPending函數中崩潰。所以我試圖隔離問題,並在我的系統上,甚至從我的角度來看,非常簡單的示例崩潰在第28行。由於幾個測試,我認爲通過調用XFlush()內部崩潰。在標有「// < - CRASH」的行上,我認爲XPending應返回0.是否正確?
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Display *dis;
Window win;
int x11_fd;
fd_set in_fds;
struct timeval tv;
XKeyEvent ev;
int main() {
dis = XOpenDisplay(NULL);
win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 256, 256, \
0, BlackPixel (dis, 0), BlackPixel(dis, 0));
XSelectInput(dis, win,
KeyPressMask | KeyReleaseMask);
XMapWindow(dis, win);
XFlush(dis);
printf("Xpending: %d\n",XPending(dis));
printf("Xpending: %d\n",XPending(dis));
XPeekEvent(dis, (XEvent*) &ev);
printf("type: %d button: 0x%X state: 0x%x\n",ev.type, ev.keycode, ev.state);
int j = XPending(dis); // <- CRASH
printf("XPending: %d\n",j);
return 0;
}
這是一個錯誤還是我誤解了xlib中的一個主要概念?