Skip to content

Commit

Permalink
Fix Mouse handler moving OS pen cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Feb 20, 2025
1 parent 29be2c8 commit 14dcd00
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface INeedsMousePositionFeedback
/// </summary>
/// <param name="position">The final mouse position.</param>
/// <param name="isSelfFeedback">Whether the feedback was triggered from this handler.</param>
void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback);
/// <param name="isOsCursor">Whether the position represents OS cursor.</param>
void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor);
}
}
2 changes: 2 additions & 0 deletions osu.Framework/Input/Handlers/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public abstract class InputHandler : IDisposable, IHasDescription

private bool isInitialized;

public virtual bool IsOsCursor => false;

/// <summary>
/// Used to initialize resources specific to this InputHandler. It gets called once.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions osu.Framework/Input/Handlers/Mouse/MouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Input/Handlers/Pen/PenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class PenHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<PenHandler>(), "Total events");

public override bool IsOsCursor => true;

public override bool IsActive => true;

public override bool Initialize(GameHost host)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Platform/Windows/WindowsMouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 14dcd00

Please sign in to comment.