#include "mouse.hpp" void Mouse::setButton( int button, int state ) { for (unsigned int i=0;idisplay, x11->root, &root, &child, &mx, &my, &wx, &wy, &mask ); return glm::vec2( mx, my ); } void Mouse::setCursor( int cursor ) { if ( currentCursor == cursor ) { return; } XFreeCursor( x11->display, xcursor ); xcursor = XCreateFontCursor( x11->display, cursor ); XChangeActivePointerGrab( x11->display, PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask, xcursor, CurrentTime ); } Mouse::Mouse(X11* x11) { this->x11 = x11; currentCursor = XC_cross; xcursor = XCreateFontCursor( x11->display, XC_cross ); XGrabPointer( x11->display, x11->root, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask, GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime ); } Mouse::~Mouse() { XUngrabPointer( x11->display, CurrentTime ); } void Mouse::tick() { XEvent event; while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) { setButton( event.xbutton.button, 1 ); } while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) { setButton( event.xbutton.button, 0 ); } while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) { if ( event.xcrossing.subwindow != None ) { hoverWindow = event.xcrossing.subwindow; } else { hoverWindow = event.xcrossing.window; } } }