WIP: Fix #109968: Win32 Mouse Warp Bounds #110937

Closed
Harley Acheson wants to merge 1 commits from Harley/blender:WarpBounds into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Use Cursor Grab bounds, rather than a portion of the window bounds, for
GHOST_kGrabHide


I was asked to look at this by @ideasman42 but this will probably require some consultation with him because this area of code has some odd history.

The minimum changes I can make to fix the reported behavior is just this:

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc
index 6eaf9cf9d03..3d21c92b242 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cc
+++ b/intern/ghost/intern/GHOST_SystemWin32.cc
@@ -1084,28 +1084,28 @@ GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *wind
       GHOST_TAxisFlag bounds_axis = GHOST_kAxisNone;
 
       if (window->getCursorGrabMode() == GHOST_kGrabHide) {
         window->getClientBounds(bounds);
 
         /* WARNING(@ideasman42): The current warping logic fails to warp on every event,
          * so the box needs to small enough not to let the cursor escape the window but large
          * enough that the cursor isn't being warped every time.
          * If this was not the case it would be less trouble to simply warp the cursor to the
          * center of the screen on every motion, see: D16558 (alternative fix for #102346). */
-        const int32_t subregion_div = 4; /* One quarter of the region. */
-        const int32_t size[2] = {bounds.getWidth(), bounds.getHeight()};
-        const int32_t center[2] = {(bounds.m_l + bounds.m_r) / 2, (bounds.m_t + bounds.m_b) / 2};
+        //const int32_t subregion_div = 4; /* One quarter of the region. */
+        //const int32_t size[2] = {bounds.getWidth(), bounds.getHeight()};
+        //const int32_t center[2] = {(bounds.m_l + bounds.m_r) / 2, (bounds.m_t + bounds.m_b) / 2};
         /* Shrink the box to prevent the cursor escaping. */
-        bounds.m_l = center[0] - (size[0] / (subregion_div * 2));
-        bounds.m_r = center[0] + (size[0] / (subregion_div * 2));
-        bounds.m_t = center[1] - (size[1] / (subregion_div * 2));
-        bounds.m_b = center[1] + (size[1] / (subregion_div * 2));
+        //bounds.m_l = center[0] - (size[0] / (subregion_div * 2));
+        //bounds.m_r = center[0] + (size[0] / (subregion_div * 2));
+        //bounds.m_t = center[1] - (size[1] / (subregion_div * 2));
+        //bounds.m_b = center[1] + (size[1] / (subregion_div * 2));
         bounds_margin = 0;
         bounds_axis = GHOST_TAxisFlag(GHOST_kAxisX | GHOST_kAxisY);
       }
       else {
         /* Fallback to window bounds. */
         if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) {
           window->getClientBounds(bounds);
         }
         bounds_margin = 2;
         bounds_axis = window->getCursorGrabAxis();

I can't find any reason why we want to wrap on a bounds smaller than the window (or grabBounds if set) when in GrabHide. So this PR just removes this in a nicer way than above.

Use Cursor Grab bounds, rather than a portion of the window bounds, for GHOST_kGrabHide --- I was asked to look at this by @ideasman42 but this will probably require some consultation with him because this area of code has some odd history. The minimum changes I can make to fix the reported behavior is just this: ``` diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc index 6eaf9cf9d03..3d21c92b242 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cc +++ b/intern/ghost/intern/GHOST_SystemWin32.cc @@ -1084,28 +1084,28 @@ GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *wind GHOST_TAxisFlag bounds_axis = GHOST_kAxisNone; if (window->getCursorGrabMode() == GHOST_kGrabHide) { window->getClientBounds(bounds); /* WARNING(@ideasman42): The current warping logic fails to warp on every event, * so the box needs to small enough not to let the cursor escape the window but large * enough that the cursor isn't being warped every time. * If this was not the case it would be less trouble to simply warp the cursor to the * center of the screen on every motion, see: D16558 (alternative fix for #102346). */ - const int32_t subregion_div = 4; /* One quarter of the region. */ - const int32_t size[2] = {bounds.getWidth(), bounds.getHeight()}; - const int32_t center[2] = {(bounds.m_l + bounds.m_r) / 2, (bounds.m_t + bounds.m_b) / 2}; + //const int32_t subregion_div = 4; /* One quarter of the region. */ + //const int32_t size[2] = {bounds.getWidth(), bounds.getHeight()}; + //const int32_t center[2] = {(bounds.m_l + bounds.m_r) / 2, (bounds.m_t + bounds.m_b) / 2}; /* Shrink the box to prevent the cursor escaping. */ - bounds.m_l = center[0] - (size[0] / (subregion_div * 2)); - bounds.m_r = center[0] + (size[0] / (subregion_div * 2)); - bounds.m_t = center[1] - (size[1] / (subregion_div * 2)); - bounds.m_b = center[1] + (size[1] / (subregion_div * 2)); + //bounds.m_l = center[0] - (size[0] / (subregion_div * 2)); + //bounds.m_r = center[0] + (size[0] / (subregion_div * 2)); + //bounds.m_t = center[1] - (size[1] / (subregion_div * 2)); + //bounds.m_b = center[1] + (size[1] / (subregion_div * 2)); bounds_margin = 0; bounds_axis = GHOST_TAxisFlag(GHOST_kAxisX | GHOST_kAxisY); } else { /* Fallback to window bounds. */ if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) { window->getClientBounds(bounds); } bounds_margin = 2; bounds_axis = window->getCursorGrabAxis(); ``` I can't find any reason why we want to wrap on a bounds smaller than the window (or grabBounds if set) when in GrabHide. So this PR just removes this in a nicer way than above.
Harley Acheson added 1 commit 2023-08-08 21:55:07 +02:00
af08b0e0af Fix #109968: Win32 Mouse Warp Bounds
Use Cursor Grab bounds, rather than a portion of the window bounds, for
GHOST_kGrabHide
Author
Member

@PratikPB2123 - can you test?

@PratikPB2123 - can you test?
Harley Acheson requested review from Campbell Barton 2023-08-08 21:56:43 +02:00

First of all, it would be good to find the root cause of #109968, if the cursor is hidden it should not matter where it's wrapped internally.

The intended behavior is:

  • The cursor is hidden.
  • It wraps around the center of the window to prevent "escape" (#102346)
  • The operation finishes and the cursor is made visible and it's location restored.

If these steps are not working properly, that seems like a bug in hiding/restoring the cursor, not in it's wrapping.

It would be good to attempt to resolve this problem at the level of hiding/restoring instead of changing internal wrapping logic.
If that's not possible a detailed explanation should be included for why a hidden cursor's location matters on WIN32 that is different from other platforms.

From looking at the video it seems the cursor is being made visible when it shouldn't be (although the screen-recording software could be adding in a software cursor). That doesn't account for the cursor being warped to a different location once color picking is complete.

The change to GHOST_Window.cc looks like it will impact other platforms, it may be OK but I couldn't say for sure without checking. For an isolated fix, I'd rather remove this change, perform the spesific check in GHOST/Win32 and consider a change that impacts all platforms separately (testing X11/Wayland/macOS to see it's not causing problems).

First of all, it would be good to find the root cause of #109968, if the cursor is hidden it should not matter where it's wrapped internally. The intended behavior is: - The cursor is hidden. - It wraps around the center of the window to prevent "escape" (#102346) - The operation finishes and the cursor is made visible and it's location restored. If these steps are not working properly, that seems like a bug in hiding/restoring the cursor, not in it's wrapping. It would be good to attempt to resolve this problem at the level of hiding/restoring instead of changing internal wrapping logic. If that's not possible a detailed explanation should be included for why a hidden cursor's location matters on WIN32 that is different from other platforms. From looking at the video it seems the cursor is being made visible when it shouldn't be _(although the screen-recording software could be adding in a software cursor)_. That doesn't account for the cursor being warped to a different location once color picking is complete. The change to `GHOST_Window.cc` looks like it will impact other platforms, it may be OK but I couldn't say for sure without checking. For an isolated fix, I'd rather remove this change, perform the spesific check in GHOST/Win32 and consider a change that impacts all platforms separately (testing X11/Wayland/macOS to see it's not causing problems).
Member

@Harley , this restores 3.3 behavior (last working version) i.e. both the issues mentioned in the #109968 do not appear anymore with PR applied


The cursor is hidden.

In some cases, cursor is visible (even in 3.3) during click-drag on redo panel properties, I'm not sure why.

From looking at the video it seems the cursor is being made visible when it shouldn't be

Actually, reporter is just clicking at random points (and not click-dragging 😅 )

@Harley , this restores 3.3 behavior (last working version) i.e. both the issues mentioned in the #109968 do not appear anymore with PR applied - - - > The cursor is hidden. In some cases, cursor is visible (even in 3.3) during click-drag on [redo panel properties](https://projects.blender.org/blender/blender/issues/109968#issuecomment-992576), I'm not sure why. > From looking at the video it seems the cursor is being made visible when it shouldn't be Actually, reporter is just clicking at random points (and not click-dragging 😅 )
Author
Member
  • It wraps around the center of the window to prevent "escape" (#102346)

With this patch applied I can still get the mouse to escaped as described in #102346. Frustratingly this happens even if I use a Windows API call (ClipCursor) to keep it within bounds.

From looking at the video it seems the cursor is being made visible when it shouldn't be (although the screen-recording software could be adding in a software cursor). That doesn't account for the cursor being warped to a different location once color picking is complete.

It isn't that the cursor is moved to a different location at the end of color picking. It is more that it unexpectedly moves there while doing multiple short and fast little drags within the area. That unexpected move is outside of the "mouse close" bounds and that ends the operation.

So far not having a lot of luck here.

> - It wraps around the center of the window to prevent "escape" (#102346) With this patch applied I can still get the mouse to escaped as described in #102346. Frustratingly this happens even if I use a Windows API call (ClipCursor) to keep it within bounds. > From looking at the video it seems the cursor is being made visible when it shouldn't be _(although the screen-recording software could be adding in a software cursor)_. That doesn't account for the cursor being warped to a different location once color picking is complete. It isn't that the cursor is moved to a different location at the end of color picking. It is more that it unexpectedly moves there while doing multiple short and fast little drags within the area. That unexpected move is outside of the "mouse close" bounds and that ends the operation. So far not having a lot of luck here.
Harley Acheson changed title from Fix #109968: Win32 Mouse Warp Bounds to WIP: Fix #109968: Win32 Mouse Warp Bounds 2023-08-10 00:10:00 +02:00
Author
Member

Alternate fix #111020 by @guishe does not have the bad "mouse escape" behavior from #102346.

Alternate fix #111020 by @guishe does **not** have the bad "mouse escape" behavior from #102346.
Author
Member

Closing in favor of #113066

Closing in favor of #113066
Harley Acheson closed this pull request 2023-10-09 21:13:48 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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#110937
No description provided.