summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-04-15 09:53:56 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2017-04-15 09:53:56 +0200
commit2a373d19a912fdd6b713bcb2150f19333d583174 (patch)
treeb272667c57d5997d925ceb9c5a22f1cfe13c6b80 /plugingui
parent8b3506186e5c9c810bcbe4a4206874d9fd4dfe9b (diff)
Fix erronous event skips from mouse move event filter.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/eventhandler.cc16
-rw-r--r--plugingui/eventhandler.h9
2 files changed, 14 insertions, 11 deletions
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc
index 2177433..a57e74b 100644
--- a/plugingui/eventhandler.cc
+++ b/plugingui/eventhandler.cc
@@ -35,7 +35,6 @@ namespace GUI
EventHandler::EventHandler(NativeWindow& nativeWindow, Window& window)
: window(window)
, nativeWindow(nativeWindow)
-// , last_click(0)
, lastWasDoubleClick(false)
{}
@@ -44,6 +43,12 @@ bool EventHandler::hasEvent()
return !events.empty();
}
+bool EventHandler::queryNextEventType(EventType type)
+{
+ return !events.empty() &&
+ (events.front()->type() == type);
+}
+
std::shared_ptr<Event> EventHandler::getNextEvent()
{
if(events.empty())
@@ -94,13 +99,9 @@ void EventHandler::processEvents()
case EventType::mouseMove:
{
- while(true)
+ // Skip all consecutive mouse move events and handle only the last one.
+ while(queryNextEventType(EventType::mouseMove))
{
- if(!hasEvent())
- {
- break;
- }
-
event = getNextEvent();
}
@@ -147,7 +148,6 @@ void EventHandler::processEvents()
case EventType::button:
{
auto buttonEvent = static_cast<ButtonEvent*>(event.get());
-
if(lastWasDoubleClick && (buttonEvent->direction == Direction::down))
{
lastWasDoubleClick = false;
diff --git a/plugingui/eventhandler.h b/plugingui/eventhandler.h
index 7e9966c..bd79084 100644
--- a/plugingui/eventhandler.h
+++ b/plugingui/eventhandler.h
@@ -43,13 +43,16 @@ class EventHandler
public:
EventHandler(NativeWindow& nativeWindow, Window& window);
- //! \brief Process all events currently in the event queue.
+ //! Process all events currently in the event queue.
void processEvents();
- //! \brief Query if any events are currently in the event queue.
+ //! Query if any events are currently in the event queue.
bool hasEvent();
- //! \brief Get a single event from the event queue.
+ //! Query if the topmost event in the event queue is of type.
+ bool queryNextEventType(EventType type);
+
+ //! Get a single event from the event queue.
//! \return A pointer to the event or nullptr if there are none.
std::shared_ptr<Event> getNextEvent();