|
下面这小段代码为什么不能收到任何的xevent呢?
取到的screen的分辨率和我桌面的分辨率是一样的,XOpenDisplay(NULL)这个应该是取当前桌面吧?
- #include <X11/Xlib.h>
- #include <assert.h>
- #include <unistd.h>
- #include <stdio.h>
-
- int main() {
- Display *display = XOpenDisplay(NULL);
- assert(display);
- Screen *screen=XDefaultScreenOfDisplay(display);
- int width=XWidthOfScreen(screen);
- int height=XHeightOfScreen(screen);
- printf("width:%d,height:%d\n", width, height);
-
- int f=1;
- while (f) {
- if (XPending(display)) {
- int eq=XEventsQueued(display, QueuedAlready);
- printf("events num in queue:%d\n", eq);
- XEvent e;
- XNextEvent(display, &e);
- printf("event type:%d\n", e.type);
- if (e.type == KeyPress) {
- XKeyEvent y=e.xkey;
- unsigned int keycode=y.keycode;
- unsigned int state=y.state;
- printf("keycode:%d,state:%d\n", keycode, state);
- break;
- }
- }
- }
- return 0;
- }
复制代码 |
|