From 14dcd007bec7fdc7bd4d1b707bb80d03f9caad70 Mon Sep 17 00:00:00 2001 From: hwsmm <9151706+hwsmm@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:49:09 +0900 Subject: [PATCH 1/3] Fix Mouse handler moving OS pen cursor --- osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs | 3 ++- osu.Framework/Input/Handlers/InputHandler.cs | 2 ++ osu.Framework/Input/Handlers/Mouse/MouseHandler.cs | 6 ++++-- osu.Framework/Input/Handlers/Pen/PenHandler.cs | 2 ++ osu.Framework/Input/InputManager.cs | 2 +- osu.Framework/Platform/Windows/WindowsMouseHandler.cs | 4 ++-- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs index d98eaf1bea..3eaba25347 100644 --- a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs +++ b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs @@ -15,6 +15,7 @@ public interface INeedsMousePositionFeedback /// /// The final mouse position. /// Whether the feedback was triggered from this handler. - void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback); + /// Whether the position represents OS cursor. + void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor); } } diff --git a/osu.Framework/Input/Handlers/InputHandler.cs b/osu.Framework/Input/Handlers/InputHandler.cs index 752d6cb776..1b98e3005e 100644 --- a/osu.Framework/Input/Handlers/InputHandler.cs +++ b/osu.Framework/Input/Handlers/InputHandler.cs @@ -32,6 +32,8 @@ public abstract class InputHandler : IDisposable, IHasDescription private bool isInitialized; + public virtual bool IsOsCursor => false; + /// /// Used to initialize resources specific to this InputHandler. It gets called once. /// diff --git a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs index aa480152c3..3f496ccf2d 100644 --- a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs +++ b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs @@ -37,6 +37,8 @@ public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePosi Precision = 0.01 }; + public override bool IsOsCursor => true; + public override string Description => "Mouse"; public override bool IsActive => true; @@ -137,12 +139,12 @@ public override bool Initialize(GameHost host) return true; } - public virtual void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback) + public virtual void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor) { if (!Enabled.Value) return; - if (!isSelfFeedback && isActive.Value) + if (!isSelfFeedback && !isOsCursor && isActive.Value) // if another handler has updated the cursor position, handle updating the OS cursor so we can seamlessly revert // to mouse control at any point. window.UpdateMousePosition(position); diff --git a/osu.Framework/Input/Handlers/Pen/PenHandler.cs b/osu.Framework/Input/Handlers/Pen/PenHandler.cs index 09df050a1c..c44ea9013c 100644 --- a/osu.Framework/Input/Handlers/Pen/PenHandler.cs +++ b/osu.Framework/Input/Handlers/Pen/PenHandler.cs @@ -16,6 +16,8 @@ public class PenHandler : InputHandler { private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public override bool IsOsCursor => true; + public override bool IsActive => true; public override bool Initialize(GameHost host) diff --git a/osu.Framework/Input/InputManager.cs b/osu.Framework/Input/InputManager.cs index 87efb4345b..dd89c65cca 100644 --- a/osu.Framework/Input/InputManager.cs +++ b/osu.Framework/Input/InputManager.cs @@ -964,7 +964,7 @@ protected virtual void HandleMousePositionChange(MousePositionChangeEvent e) foreach (var h in InputHandlers) { if (h.Enabled.Value && h is INeedsMousePositionFeedback handler) - handler.FeedbackMousePositionChange(mouse.Position, h == mouseSource); + handler.FeedbackMousePositionChange(mouse.Position, h == mouseSource, mouseSource.IsOsCursor); } handleMouseMove(state, e.LastPosition); diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index 4abe150a6e..c1fe7d6ccd 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -31,10 +31,10 @@ public override bool Initialize(GameHost host) return base.Initialize(host); } - public override void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback) + public override void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor) { window.LastMousePosition = position; - base.FeedbackMousePositionChange(position, isSelfFeedback); + base.FeedbackMousePositionChange(position, isSelfFeedback, isOsCursor); } } } From 5e9cd1bdfe8738bcb0e49fc261b7f7ce581f4c24 Mon Sep 17 00:00:00 2001 From: hwsmm <9151706+hwsmm@users.noreply.github.com> Date: Sat, 22 Feb 2025 13:15:25 +0900 Subject: [PATCH 2/3] Disable moving mouse cursor to pen position only on Linux SDL3 --- .../Input/Handlers/INeedsMousePositionFeedback.cs | 5 ++--- osu.Framework/Input/Handlers/InputHandler.cs | 2 -- osu.Framework/Input/Handlers/Mouse/MouseHandler.cs | 11 +++++++---- osu.Framework/Input/Handlers/Pen/PenHandler.cs | 2 -- osu.Framework/Input/InputManager.cs | 2 +- osu.Framework/Platform/Windows/WindowsMouseHandler.cs | 5 +++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs index 3eaba25347..1111210fdb 100644 --- a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs +++ b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs @@ -14,8 +14,7 @@ public interface INeedsMousePositionFeedback /// Receives the final mouse position from an . /// /// The final mouse position. - /// Whether the feedback was triggered from this handler. - /// Whether the position represents OS cursor. - void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor); + /// A handler that reported the final mouse position. + void FeedbackMousePositionChange(Vector2 position, InputHandler handler); } } diff --git a/osu.Framework/Input/Handlers/InputHandler.cs b/osu.Framework/Input/Handlers/InputHandler.cs index 1b98e3005e..752d6cb776 100644 --- a/osu.Framework/Input/Handlers/InputHandler.cs +++ b/osu.Framework/Input/Handlers/InputHandler.cs @@ -32,8 +32,6 @@ public abstract class InputHandler : IDisposable, IHasDescription private bool isInitialized; - public virtual bool IsOsCursor => false; - /// /// Used to initialize resources specific to this InputHandler. It gets called once. /// diff --git a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs index 3f496ccf2d..8e9b885194 100644 --- a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs +++ b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using osu.Framework.Bindables; using osu.Framework.Extensions.EnumExtensions; +using osu.Framework.Input.Handlers.Pen; using osu.Framework.Input.StateChanges; using osu.Framework.Platform; using osu.Framework.Statistics; @@ -37,8 +38,6 @@ public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePosi Precision = 0.01 }; - public override bool IsOsCursor => true; - public override string Description => "Mouse"; public override bool IsActive => true; @@ -139,12 +138,16 @@ public override bool Initialize(GameHost host) return true; } - public virtual void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor) + public virtual void FeedbackMousePositionChange(Vector2 position, InputHandler handler) { if (!Enabled.Value) return; - if (!isSelfFeedback && !isOsCursor && isActive.Value) + // https://github.com/ppy/osu/issues/31948 + // Pen malfunctions if MouseHandler tries to move the mouse cursor to pen position on Linux/X11. + bool disableUpdatingMousePosition = handler is PenHandler && RuntimeInfo.OS == RuntimeInfo.Platform.Linux && FrameworkEnvironment.UseSDL3; + + if (handler != this && isActive.Value && !disableUpdatingMousePosition) // if another handler has updated the cursor position, handle updating the OS cursor so we can seamlessly revert // to mouse control at any point. window.UpdateMousePosition(position); diff --git a/osu.Framework/Input/Handlers/Pen/PenHandler.cs b/osu.Framework/Input/Handlers/Pen/PenHandler.cs index c44ea9013c..09df050a1c 100644 --- a/osu.Framework/Input/Handlers/Pen/PenHandler.cs +++ b/osu.Framework/Input/Handlers/Pen/PenHandler.cs @@ -16,8 +16,6 @@ public class PenHandler : InputHandler { private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); - public override bool IsOsCursor => true; - public override bool IsActive => true; public override bool Initialize(GameHost host) diff --git a/osu.Framework/Input/InputManager.cs b/osu.Framework/Input/InputManager.cs index dd89c65cca..8e039c4c9e 100644 --- a/osu.Framework/Input/InputManager.cs +++ b/osu.Framework/Input/InputManager.cs @@ -964,7 +964,7 @@ protected virtual void HandleMousePositionChange(MousePositionChangeEvent e) foreach (var h in InputHandlers) { if (h.Enabled.Value && h is INeedsMousePositionFeedback handler) - handler.FeedbackMousePositionChange(mouse.Position, h == mouseSource, mouseSource.IsOsCursor); + handler.FeedbackMousePositionChange(mouse.Position, mouseSource); } handleMouseMove(state, e.LastPosition); diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index c1fe7d6ccd..4e3d86714e 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Runtime.Versioning; +using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers.Mouse; using osuTK; @@ -31,10 +32,10 @@ public override bool Initialize(GameHost host) return base.Initialize(host); } - public override void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor) + public override void FeedbackMousePositionChange(Vector2 position, InputHandler handler) { window.LastMousePosition = position; - base.FeedbackMousePositionChange(position, isSelfFeedback, isOsCursor); + base.FeedbackMousePositionChange(position, handler); } } } From 42f7260cc9d88aa8338e33d6e671e0b608a8389f Mon Sep 17 00:00:00 2001 From: hwsmm <9151706+hwsmm@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:14:31 +0900 Subject: [PATCH 3/3] Edit a comment for less confusion --- osu.Framework/Input/Handlers/Mouse/MouseHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs index 8e9b885194..8c815f2c1e 100644 --- a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs +++ b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs @@ -144,7 +144,7 @@ public virtual void FeedbackMousePositionChange(Vector2 position, InputHandler h return; // https://github.com/ppy/osu/issues/31948 - // Pen malfunctions if MouseHandler tries to move the mouse cursor to pen position on Linux/X11. + // Pen malfunctions if MouseHandler tries to move the mouse cursor to pen position on Linux. bool disableUpdatingMousePosition = handler is PenHandler && RuntimeInfo.OS == RuntimeInfo.Platform.Linux && FrameworkEnvironment.UseSDL3; if (handler != this && isActive.Value && !disableUpdatingMousePosition)