窗口中只有一个ButtonPress(Xlib)事件在一个指针坐标处。

时间:2014-02-09 22:15:51

标签: c++ xlib

我正在使用xlib在cpp中编写bspwm面板。我有关于更改为next / prev桌面的事件的问题。面板正在工作,我将鼠标移动到面板并滚动。问题是面板只接收一个关于滚动鼠标的事件。如果我不移动鼠标,我可以滚动几个小时,不会有下一个事件。但是当我移动鼠标(甚至是轻微的)并进行下一次滚动时,面板会收到一个事件并再次阻止。我写的是关于滚动,但它也不适用于鼠标按钮。

以下是代码: X11backend.cpp

void X11Backend::createWindow(int width, int height)
{
panelW = XCreateSimpleWindow(display, DefaultRootWindow(display)
        , 0, 0, width, height, 0, BlackPixel(display, screen), 
        BlackPixel(display,screen));
XSelectInput(display, panelW, ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
Atom tmp = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False);
XChangeProperty(display, panelW, 
        XInternAtom(display, "_NET_WM_WINDOW_TYPE", False), 
        XA_ATOM, 32, PropModeReplace, (const unsigned char*)&tmp, 1);
XFlush(display);
XMapWindow(display, panelW);
XSync(display, 0);
cs = cairo_xlib_surface_create(display, panelW, DefaultVisual(display, screen),
        16, 800);
ct = cairo_create(cs);
while(1)
{
    getNextEvent();
}
}

DesktopEvent* X11Backend::getNextEvent()
{
if(XPending(display) == 0) return nullptr;
XEvent e;
XNextEvent(display, &e);

DesktopEvent* event = nullptr;

switch(e.type) {
    case ButtonPress: 
        event = (DesktopEvent*)new MouseClickEvent(e.xbutton.x, e.xbutton.y, e.xbutton.button); break;
    default: event = new DesktopEvent(255); break;
}   
return event;

}

monitoring.cpp

void HwMonitor::operator()()
{
    while(true) {
    DesktopEvent* event = backend->getNextEvent();
    if (event != nullptr) {
        e->enqueueEvent(event);
    } else {
        std::this_thread::sleep_for(std::chrono::milliseconds(5));
    }
}
};

我在main.cpp中有这段代码

X11Backend b;
b.createWindow(16,800);
EventQueue eventQueue;
HwMonitor hm(eventQueue, b);
std::thread hwThread(hm);
while (true) {
    DesktopEvent* event = eventQueue.dequeueEvent();
    b.handleEvent(event);
    if ( event != NULL ) delete event;
}

请帮我解决这个问题。

0 个答案:

没有答案