Source

pyGAP / game / src / platform / x11 / window_events.cpp

Full commit
#include "platform/x11/window_x11.h"
#include "platform/x11/display.h"

#include "common/log.h"
#include <X11/Xlib.h>


namespace platform {
namespace x11 {


int WindowX11::manage_events() {
    ::XEvent event;

    // Check window manager events
    while (::XCheckTypedEvent(display_, ClientMessage, &event)) {
        if(event.xclient.window == window_ &&
            event.xclient.message_type == wm_protocol_ &&
            event.xclient.format == 32 &&
            (::Atom)(event.xclient.data.l[0]) == wm_delete_)
        {
            LOG("Window close requested...\n")
            deleted_ = true;
        }
    }

    long event_mask = KeyPressMask|KeyReleaseMask|ExposureMask|ButtonPressMask|FocusChangeMask;

    // Check window events
    while (::XCheckWindowEvent(display_, window_, event_mask, &event)) {
        if ((event.type == KeyPress) || (event.type == KeyRelease)) {
            if (event.xkey.keycode < 256)
                LOG("Keycode: 0x%02x\n", event.xkey.keycode)
        }
        else if (event.type == ButtonPress)
            LOG("Button pressed...\n")
        else if (event.type == Expose) {
            ::XExposeEvent *ev = reinterpret_cast<XExposeEvent *>(&event);
            LOG("Exposition...\n")
            LOG("New size is %i x %i\n",ev->width, ev->height)
        }
        else if (event.type == FocusIn) {
            ::Cursor cursor = make_blank_cursor(); //TODO: move outside event loop
            ::XGrabPointer(display_, window_, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, window_, cursor, CurrentTime);
            LOG("Focus in\n")
        }
        else if (event.type == FocusOut) {
            ::XUngrabPointer(display_, CurrentTime);
            LOG("Focus out\n")
        }
    }
    return 0;
}


} // namespace x11
} // namespace platform