Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SDL3, bringing in support for Windows Ink pen input, and enable it on desktop platforms once again #6511

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Framework/FrameworkEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static FrameworkEnvironment()
if (DebugUtils.IsDebugBuild)
AllowInsecureRequests = parseBool(Environment.GetEnvironmentVariable("OSU_INSECURE_REQUESTS")) ?? false;

UseSDL3 = RuntimeInfo.IsMobile || (parseBool(Environment.GetEnvironmentVariable("OSU_SDL3")) ?? false);
UseSDL3 = RuntimeInfo.IsMobile || (parseBool(Environment.GetEnvironmentVariable("OSU_SDL3")) ?? true);
}

private static bool? parseBool(string? value)
Expand Down
13 changes: 0 additions & 13 deletions osu.Framework/Platform/SDL3/SDL3Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics.Primitives;
Expand Down Expand Up @@ -1128,17 +1127,5 @@ public static string ReadableName(this SDL_LogPriority priority)
SDL_ClearError();
return error;
}

/// <summary>
/// Gets the <paramref name="name"/> of the touch device for this <see cref="SDL_TouchFingerEvent"/>.
/// </summary>
/// <remarks>
/// On Windows, this will return <c>"touch"</c> for touchscreen events or <c>"pen"</c> for pen/tablet events.
/// </remarks>
public static bool TryGetTouchName(this SDL_TouchFingerEvent e, [NotNullWhen(true)] out string? name)
{
name = SDL_GetTouchDeviceName(e.touchID);
return name != null;
}
}
}
5 changes: 4 additions & 1 deletion osu.Framework/Platform/SDL3/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public virtual void Create()
SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, "0"u8);
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"u8); // disable touch events generating synthetic mouse events on desktop platforms
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0"u8); // disable mouse events generating synthetic touch events on mobile platforms
SDL_SetHint(SDL_HINT_PEN_TOUCH_EVENTS, "0"u8);
SDL_SetHint(SDL_HINT_PEN_MOUSE_EVENTS, "0"u8);
SDL_SetHint(SDL_HINT_IME_IMPLEMENTED_UI, "composition"u8);

SDLWindowHandle = SDL_CreateWindow(title, Size.Width, Size.Height, flags);
Expand Down Expand Up @@ -570,7 +572,8 @@ protected virtual void HandleEvent(SDL_Event e)
case SDL_EventType.SDL_EVENT_FINGER_DOWN:
case SDL_EventType.SDL_EVENT_FINGER_UP:
case SDL_EventType.SDL_EVENT_FINGER_MOTION:
HandleTouchFingerEvent(e.tfinger);
case SDL_EventType.SDL_EVENT_FINGER_CANCELED:
handleTouchFingerEvent(e.tfinger);
break;

case SDL_EventType.SDL_EVENT_DROP_FILE:
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework/Platform/SDL3/SDL3Window_Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void handleDropEvent(SDL_DropEvent evtDrop)
return null;
}

protected virtual void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger)
private void handleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger)
{
var existingSource = getTouchSource(evtTfinger.fingerID);

Expand Down Expand Up @@ -305,6 +305,7 @@ protected virtual void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger)
break;

case SDL_EventType.SDL_EVENT_FINGER_UP:
case SDL_EventType.SDL_EVENT_FINGER_CANCELED:
TouchUp?.Invoke(touch);
activeTouches[(int)existingSource] = null;
break;
Expand Down
28 changes: 0 additions & 28 deletions osu.Framework/Platform/Windows/SDL3WindowsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using osu.Framework.Platform.SDL3;
using osu.Framework.Platform.Windows.Native;
using osuTK;
using osuTK.Input;
using SDL;
using Icon = osu.Framework.Platform.Windows.Native.Icon;
using static SDL.SDL3;
Expand Down Expand Up @@ -101,33 +100,6 @@ public override void StartTextInput(TextInputProperties properties)

public override void ResetIme() => ScheduleCommand(() => Imm.CancelComposition(WindowHandle));

protected override void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger)
{
if (evtTfinger.TryGetTouchName(out string? name) && name == "pen")
{
// Windows Ink tablet/pen handling
// InputManager expects to receive this as mouse events, to have proper `mouseSource` input priority (see InputManager.GetPendingInputs)
// osu! expects to get tablet events as mouse events, and touch events as touch events for touch device (TD mod) handling (see https://github.com/ppy/osu/issues/25590)

TriggerMouseMove(evtTfinger.x * ClientSize.Width, evtTfinger.y * ClientSize.Height);

switch (evtTfinger.type)
{
case SDL_EventType.SDL_EVENT_FINGER_DOWN:
TriggerMouseDown(MouseButton.Left);
break;

case SDL_EventType.SDL_EVENT_FINGER_UP:
TriggerMouseUp(MouseButton.Left);
break;
}

return;
}

base.HandleTouchFingerEvent(evtTfinger);
}

public override Size Size
{
protected set
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.211" />
<PackageReference Include="StbiSharp" Version="1.1.0" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.741-alpha" />
<PackageReference Include="ppy.SDL3-CS" Version="2025.104.0" />
<PackageReference Include="ppy.SDL3-CS" Version="2025.127.0" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2024.1128.0" />

<!-- DO NOT use ProjectReference for native packaging project.
Expand Down
Loading