1

我正在尝试单击窗口。所以我假设我需要将 XButtonEvents 传递给我的正下方的窗口。它正在选择正确的窗口,但是当在应该接收 xevent 的窗口上运行 xev 时,它没有检测到任何东西。更新:所以 xev 仍然没有报告任何内容,但是它抓住了我释放它的窗口。但是,它不会单击按钮。

XButtonEvent createButtonEvent(Display *dp, Window win, bool press){
        Window parent, rootwin, dischild;
        rootwin = DefaultRootWindow(dp);
        Window *child;
        unsigned int numberChildern;
        int px, py, i, rx, ry; 
        XWindowAttributes childAttr;
        XButtonEvent buttonEvent;
        buttonEvent.type=press?ButtonPress:ButtonRelease;
        buttonEvent.send_event=false;
        buttonEvent.display=dp;
        buttonEvent.root=rootwin;
        buttonEvent.subwindow=None;
        buttonEvent.state=Button1Mask;
        buttonEvent.same_screen=true;
        XQueryTree(dp, rootwin, &rootwin, &parent, &child, &numberChildern);

        px=0;
        py=0;
        if(!XQueryPointer(dp, rootwin, &buttonEvent.root, &dischild,
                &px, &py, &rx, &ry, &buttonEvent.state))
                {   
                fprintf(stderr, "Error cound not query pointer");
                return buttonEvent;
                }   

        for(i=0; i<numberChildern; i++)
        {   
                if(child[i]==win)continue;
                XGetWindowAttributes(dp, child[i], &childAttr);    
                if((px<childAttr.x)||(py<childAttr.y)||(px>(childAttr.x+childAttr.width))
                        ||(py>(childAttr.y+childAttr.height)))continue;
                else{
                buttonEvent.x_root=rx;
                buttonEvent.y_root=ry;
                buttonEvent.x=px-childAttr.x;
                buttonEvent.y=py-childAttr.y;
                buttonEvent.window=child[i];
                fprintf(stderr,"%d x=%d,y=%d,px=%d,py=%d\n",i,childAttr.x,childAttr.y,px,py);
                return buttonEvent;
                }   
}
                return buttonEvent;
}

然后我调用并发送如下:

    buttonPress=createButtonEvent(dp, win, true);
    buttonRelease=createButtonEvent(dp, win, false);
    XSendEvent(dp, buttonPress.window, true, ButtonPressMask, (XEvent *)&buttonPress);
    XSendEvent(dp, buttonRelease.window, true, ButtonReleaseMask, (XEvent *)&buttonRelease);
4

0 回答 0