Fix #118694: snap cursor sometimes doesn't update when dragging and dropping assets #120475

Merged
Germano Cavalcante merged 5 commits from mano-wii/blender:fix_118694 into main 2024-04-12 15:27:16 +02:00

The problem happens because, on some OSs, wm->winactive is nullptr
or wm->winactive->eventstate does not update when the mouse moves.
So the snap cursor state doesn't update because event modifiers did not
change.

The solution in this commit is to use the eventstate of the window in
the context (CTX_wm_window(C)->eventstate).

This matches other code snippets where eventstate is used.


The behavior on each OS apparently happens like this:
Windows:

  • wm->winactive is updated if the cursor is over the window for a little less than 1 second
  • Events are sent to the window whose cursor is over.

MacOS:

  • wm->winactive is the last one selected
  • Events are sent to the active window and to the one whose cursor is over.

Linux:

  • wm->winactive is the last one selected
  • Events are sent to the window whose cursor is over.

Therefore, we cannot trust the eventstate of wm->winactive.

The problem happens because, on some OSs, `wm->winactive` is `nullptr` or `wm->winactive->eventstate` does not update when the mouse moves. So the snap cursor state doesn't update because event modifiers did not change. The solution in this commit is to use the `eventstate` of the window in the context (`CTX_wm_window(C)->eventstate`). This matches other code snippets where `eventstate` is used. --- The behavior on each OS apparently happens like this: **Windows:** - `wm->winactive` is updated if the cursor is over the window for a little less than 1 second - Events are sent to the window whose cursor is over. **MacOS:** - `wm->winactive` is the last one selected - Events are sent to the active window and to the one whose cursor is over. **Linux:** - `wm->winactive` is the last one selected - Events are sent to the window whose cursor is over. Therefore, we cannot trust the eventstate of `wm->winactive`.
Germano Cavalcante added 1 commit 2024-04-10 15:36:55 +02:00
db9a32734a Fix #118694: snap cursor sometimes doesn't update when dragging and dropping assets
The problem happens because, on some OSs, `wm->winactive->eventstate`
does not update when the mouse moves. So the snap cursor doesn't update
because apparently the mouse didn't move.

The solution in this commit is to use the `eventstate` of the window in
the context (`CTX_wm_window(C)->eventstate`).

This matches other code snippets where `eventstate` is used.

---
The behavior on each OS apparently happens like this:
**Windows:**
- `wm->winactive` is updated if the cursor is over the window for a little less than 1 second
- Events are sent to the window whose cursor is over.

**MacOS:**
- `wm->winactive` is the last one selected
- Events are sent to the active window and to the one whose cursor is over.

**Linux:**
- `wm->winactive` is the last one selected
- Events are sent to the window whose cursor is over.

Therefore, we cannot trust the eventstate of `wm->winactive`.
Germano Cavalcante requested review from Campbell Barton 2024-04-10 15:37:17 +02:00
Germano Cavalcante requested review from Hans Goudey 2024-04-10 15:37:17 +02:00
Campbell Barton requested changes 2024-04-11 09:37:03 +02:00
Dismissed
Campbell Barton left a comment
Owner

The fix seems fine, requesting to pass the modifier on it's own instead of the events.

The fix seems fine, requesting to pass the modifier on it's own instead of the events.
@ -490,3 +490,3 @@
static bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern,
V3DSnapCursorState *state,
const wmWindowManager *wm,
const wmEvent *event,

I'd rather the event_modifier flag is passed in here, so it's clearer which values are intended to control the updates.

I'd rather the `event_modifier` flag is passed in here, so it's clearer which values are intended to control the updates.
@ -606,3 +608,3 @@
static void v3d_cursor_snap_update(V3DSnapCursorState *state,
const bContext *C,
wmWindowManager *wm,
const wmEvent *event,

This can replaced by event_modifier and moved after x,y arguments.

This can replaced by `event_modifier` and moved after x,y arguments.
Germano Cavalcante added 2 commits 2024-04-11 14:41:32 +02:00
Author
Member

In fact, this change of passing event_state makes the code clearer.
It became clear that the problem happens because wm->winactive or wm->winactive->eventstate is nullptr (not because wm->winactive->eventstate does not update).

In fact, this change of passing `event_state` makes the code clearer. It became clear that the problem happens because `wm->winactive` or `wm->winactive->eventstate` is `nullptr` (not because `wm->winactive->eventstate` does not update).
Campbell Barton reviewed 2024-04-11 14:48:31 +02:00
@ -867,2 +857,4 @@
wmWindow *win = CTX_wm_window(C);
ScrArea *area = CTX_wm_area(C);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
uint8_t event_modifier = win->eventstate ? win->eventstate->modifier : KM_NOTHING;

The previous logic returned when event was null, I think it'd be better to skip running v3d_cursor_eventstate_has_changed if win->eventstate is null, because the logic here implies that KM_NOTHING is a valid fallback, when it could actually change the state if the user had modifiers held.

The previous logic returned when `event` was null, I think it'd be better to skip running `v3d_cursor_eventstate_has_changed` if `win->eventstate` is null, because the logic here implies that `KM_NOTHING` is a valid fallback, when it could actually change the state if the user had modifiers held.
Germano Cavalcante added 1 commit 2024-04-11 15:14:18 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
d3a1752cdf
Reuse last `event_modifier` if `win->eventstate` is `nullptr`
Author
Member

I'm not sure when win->eventstate is nullptr, but that should never happen, and should be a rare situation.
In these cases, we don't exactly know if modifier keys have changed :\

I changed the code to reuse the last stored modifier key. It's as if the Ctrl state remains untouched.

I'm not sure when `win->eventstate` is `nullptr`, but that should never happen, and should be a rare situation. In these cases, we don't exactly know if modifier keys have changed :\\ I changed the code to reuse the last stored modifier key. It's as if the Ctrl state remains untouched.
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR120475) when ready.

@mano-wii we could even remove the

I'm not sure when win->eventstate is nullptr, but that should never happen, and should be a rare situation.
In these cases, we don't exactly know if modifier keys have changed :\

I changed the code to reuse the last stored modifier key. It's as if the Ctrl state remains untouched.

We could even remove the null check on win->eventstate the cases where it is null are on file load where this logic wont run.

My concern with the change you made was as follows:

  • The existing code does nothing if the event couldn't be accessed.
  • The newer code (before your last update) ran code which passed in a "cleared" modifier state - which could be wrong. Even though in practice this probably never runs it's misleading to suggest that modifiers can assumed to be all released as a fallback since this may actually change the state if the assumption is made elsewhere.

The current patch seems OK, although as noted already, we could assume the eventstate to be set and avoid having to comments and fallbacks for something which never happens in practice.

Or, if this seems too risky, simply not call functions when the eventstate is null, as this is what's done currently.

@mano-wii we could even remove the > I'm not sure when `win->eventstate` is `nullptr`, but that should never happen, and should be a rare situation. > In these cases, we don't exactly know if modifier keys have changed :\\ > > I changed the code to reuse the last stored modifier key. It's as if the Ctrl state remains untouched. We could even remove the null check on `win->eventstate` the cases where it is null are on file load where this logic wont run. My concern with the change you made was as follows: - The existing code does nothing if the `event` couldn't be accessed. - The newer code (before your last update) ran code which passed in a "cleared" modifier state - which could be wrong. Even though in practice this probably never runs it's misleading to suggest that modifiers can assumed to be all released as a fallback since this may actually change the state if the assumption is made elsewhere. The current patch seems OK, although as noted already, we _could_ assume the eventstate to be set and avoid having to comments and fallbacks for something which never happens in practice. Or, if this seems too risky, simply not call functions when the eventstate is null, as this is what's done currently.
Germano Cavalcante added 1 commit 2024-04-12 13:59:41 +02:00
Author
Member

Good to know that win->eventstate is never null in these cases.

I added the check still in any case. But I can study it better and remove it later.

Good to know that `win->eventstate` is never null in these cases. I added the check still in any case. But I can study it better and remove it later.
Campbell Barton approved these changes 2024-04-12 14:42:12 +02:00
Germano Cavalcante merged commit c30afb7bf6 into main 2024-04-12 15:27:16 +02:00
Germano Cavalcante deleted branch fix_118694 2024-04-12 15:27:18 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120475
No description provided.