Skip to content

Commit

Permalink
Disable moving mouse cursor to pen position only on Linux SDL3
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Feb 22, 2025
1 parent 14dcd00 commit 5e9cd1b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public interface INeedsMousePositionFeedback
/// Receives the final mouse position from an <see cref="InputManager"/>.
/// </summary>
/// <param name="position">The final mouse position.</param>
/// <param name="isSelfFeedback">Whether the feedback was triggered from this handler.</param>
/// <param name="isOsCursor">Whether the position represents OS cursor.</param>
void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor);
/// <param name="handler">A handler that reported the final mouse position.</param>
void FeedbackMousePositionChange(Vector2 position, InputHandler handler);
}
}
2 changes: 0 additions & 2 deletions osu.Framework/Input/Handlers/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ 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
11 changes: 7 additions & 4 deletions osu.Framework/Input/Handlers/Mouse/MouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions osu.Framework/Input/Handlers/Pen/PenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ 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, mouseSource.IsOsCursor);
handler.FeedbackMousePositionChange(mouse.Position, mouseSource);
}

handleMouseMove(state, e.LastPosition);
Expand Down
5 changes: 3 additions & 2 deletions osu.Framework/Platform/Windows/WindowsMouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 5e9cd1b

Please sign in to comment.