diff options
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_query.c | 7 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 25 |
2 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index 2f5332e9672..9b9be6bb497 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -280,8 +280,11 @@ int WM_event_drag_threshold(const struct wmEvent *event) if (WM_event_is_tablet(event)) { drag_threshold = U.drag_threshold_tablet; } - else if (ISMOUSE(event->type)) { - /* Mouse button or mouse motion. */ + else if (ISMOUSE(event->prevtype)) { + BLI_assert(event->prevtype != MOUSEMOVE); + /* Using the previous type is important is we want to check the last pressed/released button, + * The `event->type` would include #MOUSEMOVE which is always the case when dragging + * and does not help us know which threshold to use. */ drag_threshold = U.drag_threshold_mouse; } else { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index a1a9c24d178..411ecb1cac8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -4458,6 +4458,19 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void event = *evt; event.is_repeat = false; + /** + * Always support accessing the last key press/release. This is set from `win->eventstate`, + * so it will always be a valid event type to store in the previous state. + * + * Note that these values are intentionally _not_ set in the `win->eventstate`, + * as copying these values only makes sense when `win->eventstate->{val/type}` would be + * written to (which only happens for some kinds of events). + * If this was done it could leave `win->eventstate` previous and current value + * set to the same key press/release state which doesn't make sense. + */ + event.prevtype = event.type; + event.prevval = event.val; + /* Ensure the event state is correct, any deviation from this may cause bugs. */ #ifndef NDEBUG if ((evt->type || evt->val) && /* Ignore cleared event state. */ @@ -4498,6 +4511,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void oevent = *oevt; + /* See comment for this operation on `event` for details. */ + oevent.prevtype = oevent.type; + oevent.prevval = oevent.val; + copy_v2_v2_int(&oevent.x, &event.x); oevent.type = MOUSEMOVE; { @@ -4593,8 +4610,12 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void if (owin) { wmEvent oevent = *(owin->eventstate); - oevent.x = event.x; - oevent.y = event.y; + /* See comment for this operation on `event` for details. */ + oevent.prevtype = oevent.type; + oevent.prevval = oevent.val; + + copy_v2_v2_int(&oevent.x, &event.x); + oevent.type = event.type; oevent.val = event.val; oevent.tablet = event.tablet; |