使用 xlib XChangeWindowAttributes 检索所有 XWindow 事件
我正在尝试通过 xlib 检索所有 Windows 事件。我使用 XChangeWindowAttributes 将 SubstructRedirectMask 添加到根窗口。但是当我执行这个程序时,它显示 BadAccess 如下:
dorowu@dorowu-F3JP:~/src/xwindow$ sudo ./tmp
X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 2 (X_ChangeWindowAttributes)
Serial number of failed request: 7
Current serial number in output stream: 8
程序如下:
/*
Simple Xlib application drawing a box in a window.
To Compile: gcc -O2 -Wall -o test test.c -L /usr/X11R6/lib -lX11 -lm
*/
#include<X11/Xlib.h>
#include<stdio.h>
#include<stdlib.h> // prevents error for exit on line 18 when compiling with gcc
int main() {
Display *d;
XEvent e;
/* open connection with the server */
d = XOpenDisplay(NULL);
if (d == NULL) {
printf("Cannot open display\n");
exit(1);
}
// sniffer events
XSetWindowAttributes attr;
attr.override_redirect = 1;
attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
KeyReleaseMask | PointerMotionMask ;
XChangeWindowAttributes(d, XDefaultRootWindow(d), CWEventMask , &attr);
XSync(d, False);
/* event loop */
while(1) {
XNextEvent(d, &e);
printf("event: %d\n", e.type);
}
/* close connection to server */
XCloseDisplay(d);
return 0;
}
如果我删除 SubstructRedirectMask,则不会显示错误。 有人知道这是怎么回事吗?
I'm trying to retrieve all windows's events by xlib. I used XChangeWindowAttributes to add SubstructureRedirectMask to root window. But when I executed this program, it showed BadAccess as following:
dorowu@dorowu-F3JP:~/src/xwindow$ sudo ./tmp
X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 2 (X_ChangeWindowAttributes)
Serial number of failed request: 7
Current serial number in output stream: 8
The program is following:
/*
Simple Xlib application drawing a box in a window.
To Compile: gcc -O2 -Wall -o test test.c -L /usr/X11R6/lib -lX11 -lm
*/
#include<X11/Xlib.h>
#include<stdio.h>
#include<stdlib.h> // prevents error for exit on line 18 when compiling with gcc
int main() {
Display *d;
XEvent e;
/* open connection with the server */
d = XOpenDisplay(NULL);
if (d == NULL) {
printf("Cannot open display\n");
exit(1);
}
// sniffer events
XSetWindowAttributes attr;
attr.override_redirect = 1;
attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
KeyReleaseMask | PointerMotionMask ;
XChangeWindowAttributes(d, XDefaultRootWindow(d), CWEventMask , &attr);
XSync(d, False);
/* event loop */
while(1) {
XNextEvent(d, &e);
printf("event: %d\n", e.type);
}
/* close connection to server */
XCloseDisplay(d);
return 0;
}
If I remove SubstructureRedirectMask, there are not error shown.
Anyone know what's wrong with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一次只允许一名客户执行此操作。你已经有了这样的客户端,它就是你的窗口管理器。
Only one client at a time is allowed to do it. You already have such client, it's your window manager.