1
0
Fork 0
spectre/source/Platform/Unix/X11EventQueue.cpp
Henrik Hautakoski 7356bdebdd Platform/Unix/X11EventQueue: Fix bug where messeges where not flushed to the event queue.
XEventsQueued(disp, QueuedAlready) only returns the number of events currently in the queue and
does not flush new events. So this must happen elsewhere and if it does not we
will never see any events. i noticed this bug when removing the call to glXSwapBuffers().

Fix this by using XPending() instead as this flushes new events
if the queue is empty before returning the length.

see https://tronche.com/gui/x/xlib/event-handling/XEventsQueued.html
and https://tronche.com/gui/x/xlib/event-handling/XPending.html
2020-12-19 18:55:11 +01:00

74 lines
1.3 KiB
C++

#include <Spectre/System/Log.h>
#include "X11EventQueue.h"
#include "X11SharedDisplay.h"
#include "X11Keyboard.h"
#include "X11WindowEventHandler.h"
namespace sp {
X11EventQueue::X11EventQueue()
{
m_disp = XGetDisplay();
}
X11EventQueue::~X11EventQueue()
{
if (m_disp) {
XReleaseDisplay();
}
}
bool X11EventQueue::poll(Event& event)
{
Atom del_win = getAtom("WM_DELETE_WINDOW");
Atom wm_proto = getAtom("WM_PROTOCOLS");
if (m_disp == NULL) {
return false;
}
if (XPending(m_disp)) {
XEvent xevent;
XNextEvent(m_disp, &xevent);
switch(xevent.type) {
case ClientMessage:
Log::info("X11: ClientMessage");
if (xevent.xclient.message_type == wm_proto
&& xevent.xclient.data.l[0] == del_win) {
event.type = Event::Quit;
return true;
}
break;
case ResizeRequest:
Log::info("X11: Resize event");
break;
case KeyPress:
case KeyRelease:
if (X11Keyboard::handleMessage(&xevent.xkey, event)) {
return true;
}
break;
case ButtonPress:
case ButtonRelease:
Log::info("X11: MouseButtonEvent");
break;
case MotionNotify:
// This generates alot of events :)
//Log::info("X11: MouseMotionEvent");
break;
default:
// Pass to window.
Log::info("X11: Window Event");
X11WindowEventHandler::process(m_disp, xevent);
}
}
return false;
}
} //namespace sp