diff options
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/nativewindow_x11.cc | 36 | ||||
-rw-r--r-- | plugingui/nativewindow_x11.h | 6 |
2 files changed, 22 insertions, 20 deletions
diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index 3fffcd5..da6cb6d 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -266,23 +266,22 @@ void NativeWindowX11::grabMouse(bool grab) std::queue<std::shared_ptr<Event>> NativeWindowX11::getEvents() { - std::queue<std::shared_ptr<Event>> events; - while(XPending(display)) { XEvent xEvent; XNextEvent(display, &xEvent); - events.push(translateXMessage(xEvent)); + translateXMessage(xEvent); } + std::queue<std::shared_ptr<Event>> events; + std::swap(events, event_queue); return events; } -std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) +void NativeWindowX11::translateXMessage(XEvent& xevent) { - std::shared_ptr<Event> event = nullptr; - - switch(xevent.type) { + switch(xevent.type) + { case MotionNotify: //DEBUG(x11, "MotionNotify"); { @@ -290,7 +289,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) mouseMoveEvent->window_id = xevent.xmotion.window; mouseMoveEvent->x = xevent.xmotion.x; mouseMoveEvent->y = xevent.xmotion.y; - event = mouseMoveEvent; + event_queue.push(mouseMoveEvent); } break; @@ -304,7 +303,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) repaintEvent->y = xevent.xexpose.y; repaintEvent->width = xevent.xexpose.width; repaintEvent->height = xevent.xexpose.height; - event = repaintEvent; + event_queue.push(repaintEvent); } break; @@ -318,16 +317,17 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) resizeEvent->window_id = xevent.xconfigure.window; resizeEvent->width = xevent.xconfigure.width; resizeEvent->height = xevent.xconfigure.height; - event = resizeEvent; + event_queue.push(resizeEvent); } - else if((window.windowX() != (std::size_t)xevent.xconfigure.x) || - (window.windowY() != (std::size_t)xevent.xconfigure.y)) + + if((window.windowX() != (std::size_t)xevent.xconfigure.x) || + (window.windowY() != (std::size_t)xevent.xconfigure.y)) { auto moveEvent = std::make_shared<MoveEvent>(); moveEvent->window_id = xevent.xconfigure.window; moveEvent->x = xevent.xconfigure.x; moveEvent->y = xevent.xconfigure.y; - event = moveEvent; + event_queue.push(moveEvent); } } break; @@ -344,7 +344,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) scrollEvent->x = xevent.xbutton.x; scrollEvent->y = xevent.xbutton.y; scrollEvent->delta = scroll * ((xevent.xbutton.button == 4) ? -1 : 1); - event = scrollEvent; + event_queue.push(scrollEvent); } else { @@ -390,7 +390,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) { last_click = xevent.xbutton.time; } - event = buttonEvent; + event_queue.push(buttonEvent); } } break; @@ -430,7 +430,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) keyEvent->direction = (xevent.type == KeyPress) ? Direction::down : Direction::up; - event = keyEvent; + event_queue.push(keyEvent); } break; @@ -439,7 +439,7 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) if(((unsigned int)xevent.xclient.data.l[0] == wmDeleteMessage)) { auto closeEvent = std::make_shared<CloseEvent>(); - event = closeEvent; + event_queue.push(closeEvent); } break; @@ -455,8 +455,6 @@ std::shared_ptr<Event> NativeWindowX11::translateXMessage(XEvent& xevent) WARN(X11, "Unhandled xevent.type: %d\n", xevent.type); break; } - - return event; } void NativeWindowX11::allocateShmImage(std::size_t width, std::size_t height) diff --git a/plugingui/nativewindow_x11.h b/plugingui/nativewindow_x11.h index abc8af0..b2021c0 100644 --- a/plugingui/nativewindow_x11.h +++ b/plugingui/nativewindow_x11.h @@ -26,6 +26,8 @@ */ #pragma once +#include <queue> + #include <X11/Xlib.h> #include <X11/extensions/XShm.h> @@ -58,7 +60,7 @@ public: std::queue<std::shared_ptr<Event>> getEvents() override; private: - std::shared_ptr<Event> translateXMessage(XEvent& xevent); + void translateXMessage(XEvent& xevent); //! Allocate new shared memory buffer for the pixel buffer. //! Frees the existing buffer if there is one. @@ -85,6 +87,8 @@ private: int depth{0}; Visual* visual{nullptr}; Atom wmDeleteMessage{0}; + + std::queue<std::shared_ptr<Event>> event_queue; }; } // GUI:: |