Adding Platform/Unix/X11WindowEventHandler
This commit is contained in:
parent
2ab5c7fc41
commit
2788424516
3 changed files with 82 additions and 0 deletions
52
source/Platform/Unix/X11WindowEventHandler.cpp
Normal file
52
source/Platform/Unix/X11WindowEventHandler.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "X11Display.h"
|
||||
#include "X11SharedDisplay.h"
|
||||
#include "X11WindowEventHandler.h"
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Context used to store X11Display pointer.
|
||||
::XContext X11WindowEventHandler::win_context = None;
|
||||
|
||||
void X11WindowEventHandler::registerHandler(::Display* disp, ::Window window, X11Display *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) {
|
||||
X11Display* disp_ptr = (X11Display*) ptr;
|
||||
|
||||
// Delegate
|
||||
disp_ptr->processEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
Loading…
Add table
Add a link
Reference in a new issue