2

すべてのウィンドウのイベントを xlib で取得しようとしています。XChangeWindowAttributes を使用して SubstructureRedirectMask をルート ウィンドウに追加しました。しかし、このプログラムを実行すると、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;
}

SubstructureRedirectMask を削除すると、エラーは表示されません。誰がそれの何が悪いのか知っていますか?

4

1 に答える 1

0

一度に 1 人のクライアントのみが実行できます。あなたはすでにそのようなクライアントを持っています。それはあなたのウィンドウマネージャーです。

于 2011-07-28T18:44:34.240 に答える