Skip to content

Commit

Permalink
Add HostOptions.FriendlyGameName and set as SDL APP_NAME hint
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezyLemon committed Apr 23, 2024
1 parent 2e6cced commit 7fe8bcb
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IOSGameHost()
{
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new IOSWindow(preferredSurface);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new IOSWindow(preferredSurface, Options.FriendlyGameName);

protected override void SetupForRun()
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected set
}
}

public IOSWindow(GraphicsSurfaceType surfaceType)
: base(surfaceType)
public IOSWindow(GraphicsSurfaceType surfaceType, string appName)
: base(surfaceType, appName)
{
}

Expand Down
9 changes: 9 additions & 0 deletions osu.Framework/HostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@ public class HostOptions
/// If the SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR environment variable is set, this property will have no effect.
/// </remarks>
public bool BypassCompositor { get; set; } = true;

/// <summary>
/// The friendly name of the game to be hosted. This is used to display the name to the user,
/// for example in the window title bar or in OS windows and prompts.
/// </summary>
/// <remarks>
/// If empty, GameHost will choose a default name based on the gameName.
/// </remarks>
public string FriendlyGameName { get; set; } = string.Empty;
}
}
5 changes: 5 additions & 0 deletions osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ protected GameHost([NotNull] string gameName, [CanBeNull] HostOptions options =
{
Options = options ?? new HostOptions();

if (string.IsNullOrEmpty(Options.FriendlyGameName))
{
Options.FriendlyGameName = $@"osu!framework (running ""{gameName}"")";
}

Name = gameName;

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Platform/Linux/LinuxGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void SetupForRun()
base.SetupForRun();
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new SDL3DesktopWindow(preferredSurface);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new SDL3DesktopWindow(preferredSurface, Options.FriendlyGameName);

protected override ReadableKeyCombinationProvider CreateReadableKeyCombinationProvider() => new LinuxReadableKeyCombinationProvider();

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Platform/MacOS/MacOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal MacOSGameHost(string gameName, HostOptions options)
{
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new MacOSWindow(preferredSurface);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new MacOSWindow(preferredSurface, Options.FriendlyGameName);

public override IEnumerable<string> UserStoragePaths
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Platform/MacOS/MacOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ internal class MacOSWindow : SDL3DesktopWindow
private IntPtr originalScrollWheel;
private ScrollWheelDelegate scrollWheelHandler;

public MacOSWindow(GraphicsSurfaceType surfaceType)
: base(surfaceType)
public MacOSWindow(GraphicsSurfaceType surfaceType, string appName)
: base(surfaceType, appName)
{
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Platform/SDL3DesktopWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace osu.Framework.Platform
{
internal class SDL3DesktopWindow : SDL3Window
{
public SDL3DesktopWindow(GraphicsSurfaceType surfaceType)
: base(surfaceType)
public SDL3DesktopWindow(GraphicsSurfaceType surfaceType, string appName)
: base(surfaceType, appName)
{
}

Expand Down
4 changes: 3 additions & 1 deletion osu.Framework/Platform/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ public IntPtr DisplayHandle
/// </summary>
protected ObjectHandle<SDL3Window> ObjectHandle { get; private set; }

protected SDL3Window(GraphicsSurfaceType surfaceType)
protected SDL3Window(GraphicsSurfaceType surfaceType, string appName)
{
ObjectHandle = new ObjectHandle<SDL3Window>(this, GCHandleType.Normal);

SDL3.SDL_SetHint(SDL3.SDL_HINT_APP_NAME, appName);

if (SDL3.SDL_Init(SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_GAMEPAD) < 0)
{
throw new InvalidOperationException($"Failed to initialise SDL: {SDL3.SDL_GetError()}");
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Platform/Windows/WindowsGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void SetupForRun()
timePeriod = new TimePeriod(1);
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new WindowsWindow(preferredSurface);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new WindowsWindow(preferredSurface, Options.FriendlyGameName);

public override IEnumerable<KeyBinding> PlatformKeyBindings => base.PlatformKeyBindings.Concat(new[]
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Platform/Windows/WindowsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ internal class WindowsWindow : SDL3DesktopWindow
/// </summary>
private readonly bool applyBorderlessWindowHack;

public WindowsWindow(GraphicsSurfaceType surfaceType)
: base(surfaceType)
public WindowsWindow(GraphicsSurfaceType surfaceType, string appName)
: base(surfaceType, appName)
{
switch (surfaceType)
{
Expand Down

0 comments on commit 7fe8bcb

Please sign in to comment.