From c4ef90f5a0b1d05b16187eb6e32323defe6461c0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Mar 2021 18:19:13 +1100 Subject: Fix click-drag regression in fix for T86116 1638af109e46522a1a24645289016922bb9ca977 & bfc70a6a958b9c35bde765ea8a02e8b1fd36db8b caused a regression with click-drag (not tweak which has it's own logic). Restore some changes from these commits with added comments. Minor changes from previous functionality from 39919e35326c732141bfd2d740b19000b6bc1d51. - `prevval` & `prevtype` are now set for all kinds of new events in the queue previously this was not done for some kinds of events (mouse wheel, ndof - for example). - Set `prevval` & `prevtype` for other windows for mouse buttons. --- .../blender/windowmanager/intern/wm_event_query.c | 7 ++++-- .../blender/windowmanager/intern/wm_event_system.c | 25 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'source/blender') 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; -- cgit v1.2.3