2010-11-18 1 views
2

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

プログラムは以下の通りです:私はSubstructureRedirectMaskを削除した場合

/* 
    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; 
} 

を示すがエラーではありませんされています。 誰でも何が間違っているのか分かりますか?

+0

xinitで直接実行していますか? – WhyMe

答えて

0

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

関連する問題