1
0
Fork 0
spectre/source/Platform/Unix/X11WindowEventHandler.cpp

51 lines
1.1 KiB
C++

#include <Spectre/System/Log.h>
#include "X11Window.h"
#include "X11WindowEventHandler.h"
#include <X11/Xresource.h>
namespace sp {
// Context used to store X11Window pointer.
::XContext X11WindowEventHandler::win_context = None;
void X11WindowEventHandler::registerHandler(::Display* disp, ::Window window, X11Window *ptr)
{
// Initialize context before use.
if (win_context == None) {
win_context = XUniqueContext();
}
// Save pointer to window.
XSaveContext(disp, window, win_context, (XPointer) ptr);
}
void X11WindowEventHandler::unregisterHandler(::Display* disp, ::Window window)
{
// No context. nothing to do.
if (win_context == None) {
return;
}
XDeleteContext(disp, window, win_context);
}
void X11WindowEventHandler::process(::Display* disp, const ::XEvent& event)
{
XPointer ptr;
// No context. nothing to do.
if (win_context == None) {
return;
}
// Get the pointer for window ID.
if (XFindContext(disp, event.xany.window, win_context, &ptr) == 0) {
X11Window* disp_ptr = (X11Window*) ptr;
// Delegate
disp_ptr->processEvent(event);
}
}
} // namespace sp