Skip to content

Add libgamemode support on Linux#6721

Open
Hato1125 wants to merge 3 commits intoppy:masterfrom
Hato1125:master
Open

Add libgamemode support on Linux#6721
Hato1125 wants to merge 3 commits intoppy:masterfrom
Hato1125:master

Conversation

@Hato1125
Copy link
Copy Markdown

Calls gamemode_request_start() on startup and gamemode_request_end() on shutdown via P/Invoke to libgamemode.so.0.

If libgamemode is not installed, the calls are silently ignored.

This allows osu-framework-based games (including osu!) to benefit from gamemode's CPU/GPU optimisations without requiring gamemoderun as a wrapper.

@peppy
Copy link
Copy Markdown
Member

peppy commented Mar 17, 2026

Are we sure this should be applied to all framework usage from the point of application startup? osu!framework may be used for non-games. Or even for games, it may be backgrounded in which case game mode might need to be switched off.

@Jinkku
Copy link
Copy Markdown

Jinkku commented Mar 17, 2026

Are we sure this should be applied to all framework usage from the point of application startup? osu!framework may be used for non-games. Or even for games, it may be backgrounded in which case game mode might need to be switched off.

it could be a toggle internally to be turned on before the initialization if it's a game and can be disabled if not a game.

@Hato1125
Copy link
Copy Markdown
Author

Thank you for the feedback!

You're right that enabling gamemode unconditionally may not be appropriate for all framework users.

Here's what I'd propose:

  • Opt-in via HostOptions — EnableGamemode defaults to false, so only applications that explicitly opt in will activate gamemode.
  • Focus-based toggling — Instead of activating at startup, gamemode is requested when the window gains focus and released when it loses focus.
  • Debounce on deactivation — To avoid rapid start/end calls when focus switches quickly, request_end is delayed by a short debounce period.

This should address both concerns: non-game uses of the framework are completely unaffected, and backgrounding is handled correctly.

@peppy
Copy link
Copy Markdown
Member

peppy commented Mar 17, 2026

need documentation on best practices, the things you're suggesting are coming from somewhere, but i'm not sure that somewhere is reliable.

@hwsmm
Copy link
Copy Markdown
Contributor

hwsmm commented Mar 17, 2026

This might not be exactly same if you mean to use this outside of osu!, but a similar discussion took place before: ppy/osu#11996

@Hato1125
Copy link
Copy Markdown
Author

I'm not sure what "best practices" refers to here, but this is my own design judgement rather than something based on documented best practices. If you're looking
for formal references, I'm afraid I don't have any.

My reasoning is as follows:

Depending on the application, I don't think there's much need to boost performance when the window is in the background or not focused, so enabling gamemode in
those cases would just be wasteful. As mentioned in the original comment, osu!framework can be used for non-game applications, and enabling gamemode for apps where
performance isn't critical would only increase power consumption.

For these reasons, I think it makes sense to have gamemode disabled by default and allow games or performance-critical apps to opt in.

Additionally, since gamemode requests use D-Bus communication internally, I felt it would be better to avoid calling them in rapid succession, which is why I added
a debounce with a short delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants