Skip to content
Open
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
13 changes: 13 additions & 0 deletions osu.Framework/Platform/Linux/LinuxGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Platform.Linux.Native;

namespace osu.Framework.Platform.Linux
{
Expand Down Expand Up @@ -46,5 +47,17 @@ protected override IEnumerable<InputHandler> CreateAvailableInputHandlers()

return handlers;
}

protected override void SetupForRun()
{
Gamemode.RequestStart();
base.SetupForRun();
}

protected override void Dispose(bool isDisposing)
{
Gamemode.RequestEnd();
base.Dispose(isDisposing);
}
}
}
62 changes: 62 additions & 0 deletions osu.Framework/Platform/Linux/Native/Gamemode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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;
using System.Runtime.InteropServices;
using osu.Framework.Logging;

namespace osu.Framework.Platform.Linux.Native
{
internal class Gamemode
{
[DllImport("libgamemode.so.0", EntryPoint = "real_gamemode_request_start", ExactSpelling = true)]
private static extern int gamemode_request_start();

[DllImport("libgamemode.so.0", EntryPoint = "real_gamemode_request_end", ExactSpelling = true)]
private static extern int gamemode_request_end();

/// <summary>
/// Requests gamemode activation. Silently does nothing if libgamemode is not installed.
/// </summary>
public static void RequestStart()
{
try
{
if (gamemode_request_start() < 0)
{
Logger.Log("gamemode_request_start: failed.", LoggingTarget.Runtime, LogLevel.Debug);
}
}
catch (DllNotFoundException)
{
// libgamemode is not installed; this is not an error.
}
catch (Exception e)
{
Logger.Log($"gamemode_request_start threw an unexpected exception: {e}", LoggingTarget.Runtime, LogLevel.Debug);
}
}

/// <summary>
/// Requests gamemode deactivation. Silently does nothing if libgamemode is not installed.
/// </summary>
public static void RequestEnd()
{
try
{
if (gamemode_request_end() < 0)
{
Logger.Log("gamemode_request_end: failed.", LoggingTarget.Runtime, LogLevel.Debug);
}
}
catch (DllNotFoundException)
{
// libgamemode is not installed; this is not an error.
}
catch (Exception e)
{
Logger.Log($"gamemode_request_end threw an unexpected exception: {e}", LoggingTarget.Runtime, LogLevel.Debug);
}
}
}
}
Loading