x11: Wrap platform functions in XWindowsEventQueueBuffer class

This commit is contained in:
Monika Kairaityte 2018-11-11 11:23:20 +02:00 committed by Adrian Lucrèce Céleste
parent 2c32270d49
commit 51118014b1
6 changed files with 19 additions and 8 deletions

View File

@ -230,4 +230,5 @@ public:
int level, int eGroup) = 0;
virtual unsigned char do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
KeyCode keycode) = 0;
virtual int XNextEvent(Display* display, XEvent* event_return) = 0;
};

View File

@ -52,17 +52,18 @@ class EventQueueTimer { };
// XWindowsEventQueueBuffer
//
XWindowsEventQueueBuffer::XWindowsEventQueueBuffer(
XWindowsEventQueueBuffer::XWindowsEventQueueBuffer(IXWindowsImpl* impl,
Display* display, Window window, IEventQueue* events) :
m_events(events),
m_display(display),
m_window(window),
m_waiting(false)
{
m_impl = impl;
assert(m_display != NULL);
assert(m_window != None);
m_userEvent = XInternAtom(m_display, "BARRIER_USER_EVENT", False);
m_userEvent = m_impl->XInternAtom(m_display, "BARRIER_USER_EVENT", False);
// set up for pipe hack
int result = pipe(m_pipefd);
assert(result == 0);
@ -206,7 +207,7 @@ XWindowsEventQueueBuffer::getEvent(Event& event, UInt32& dataID)
flush();
// get next event
XNextEvent(m_display, &m_event);
m_impl->XNextEvent(m_display, &m_event);
// process event
if (m_event.xany.type == ClientMessage &&
@ -262,7 +263,7 @@ bool
XWindowsEventQueueBuffer::isEmpty() const
{
Lock lock(&m_mutex);
return (XPending(m_display) == 0 );
return (m_impl->XPending(m_display) == 0 );
}
EventQueueTimer*
@ -284,8 +285,8 @@ XWindowsEventQueueBuffer::flush()
// flush the posted event list to the X server
for (size_t i = 0; i < m_postedEvents.size(); ++i) {
XSendEvent(m_display, m_window, False, 0, &m_postedEvents[i]);
m_impl->XSendEvent(m_display, m_window, False, 0, &m_postedEvents[i]);
}
XFlush(m_display);
m_impl->XFlush(m_display);
m_postedEvents.clear();
}

View File

@ -21,6 +21,7 @@
#include "mt/Mutex.h"
#include "base/IEventQueueBuffer.h"
#include "common/stdvector.h"
#include "XWindowsImpl.h"
#if X_DISPLAY_MISSING
# error X11 is required to build barrier
@ -33,7 +34,8 @@ class IEventQueue;
//! Event queue buffer for X11
class XWindowsEventQueueBuffer : public IEventQueueBuffer {
public:
XWindowsEventQueueBuffer(Display*, Window, IEventQueue* events);
XWindowsEventQueueBuffer(IXWindowsImpl* impl, Display*, Window,
IEventQueue* events);
virtual ~XWindowsEventQueueBuffer();
// IEventQueueBuffer overrides
@ -51,6 +53,7 @@ private:
private:
typedef std::vector<XEvent> EventList;
IXWindowsImpl* m_impl;
Mutex m_mutex;
Display* m_display;

View File

@ -639,3 +639,8 @@ unsigned char XWindowsImpl::do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
{
return do_XkbKeyGroupInfo(m_xkb, keycode);
}
int XWindowsImpl::XNextEvent(Display* display, XEvent* event_return)
{
return ::XNextEvent(display, event_return);
}

View File

@ -192,4 +192,5 @@ public:
int level, int eGroup);
virtual unsigned char do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
KeyCode keycode);
virtual int XNextEvent(Display* display, XEvent* event_return);
};

View File

@ -160,7 +160,7 @@ XWindowsScreen::XWindowsScreen(
&XWindowsScreen::handleSystemEvent));
// install the platform event queue
m_events->adoptBuffer(new XWindowsEventQueueBuffer(
m_events->adoptBuffer(new XWindowsEventQueueBuffer(m_impl,
m_display, m_window, m_events));
}