J'essaie de récupérer tous les événements de Windows par xlib. J'ai utilisé XChangeWindowAttributes pour ajouter SubstructureRedirectMask à la fenêtre racine. Mais quand j'exécuté ce programme, il a montré Badaccess comme suit:Utilisez Xlib XChangeWindowAttributes pour récupérer tous les événements XWindow
[email protected]:~/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
Le programme est le suivant:
/*
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;
}
Si je retire SubstructureRedirectMask, il y a erreur non représenté. Quelqu'un sait ce qui ne va pas avec ça?
Vous exécutez directement sur xinit? – WhyMe