libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.3k stars 1.73k forks source link

How I can enable Game Mode on macos sonoma? #8452

Open dortamiguel opened 10 months ago

dortamiguel commented 10 months ago

There is a new Game Mode in Sonoma that priorizes game performance when the application starts in fullscreen. https://support.apple.com/en-asia/HT213658

I tried with a few games and it seems to toggle when I start them, but somehow I can't get it on my own one when using SDL.

This is basically how I create my window

SDL_CreateWindow(
    nullptr,
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    1920,
    1080,
    SDL_WINDOW_FULLSCREEN | SDL_WINDOW_VULKAN | SDL_WINDOW_ALLOW_HIGHDPI
);

Is there anything else I should do to enable this?

slime73 commented 10 months ago

Have you tried with fullscreen desktop (SDL_WINDOW_FULLSCREEN_DESKTOP) instead of exclusive fullscreen (SDL_WINDOW_FULLSCREEN)?

dortamiguel commented 10 months ago

@slime73 I just tried and I got no luck with it. Also I noticed something else,

If I use the maximize button to go fullscreen the menubar appears if I touch the top edge of the window

image

But if I use this SDL function then the fullscreen will lock the mouse cursor and the menubar won't appear when moving the cursor to the top

SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);

might be possible that SDL is handling fullscreen differently than what macos expects these days?

jsm174 commented 9 months ago

@dortamiguel - Is your app by chance a plain executable or bundled as an .app?

I "think" I'm noticing with a plain executable, the mode doesn't kick in.

When bundling as an app, I see the notification, but if I use SDL_WINDOW_FULLSCREEN_DESKTOP or SDL_WINDOW_FULLSCREEN I don't see it unless I quickly close the game. It's almost like the notification is behind the full screen window.

dortamiguel commented 9 months ago

@jsm174 yes I just bundle the plain executable inside an .app

In my case it doesn't matter if I use SDL_WINDOW_FULLSCREEN, usually if I go back to the desktop and the game is still running I see in the menubar a controller icon that tells gamemode is enabled, but with my game I just don't see it.

It might be possible that the problem is that my info.plist is incomplete or my app is not signed?

jsm174 commented 9 months ago

Okay, we spent some time on this, and I think you need to add:

    <key>LSApplicationCategoryType</key>
    <string>public.app-category.games</string>

to your Info.plist

That seems to work for our app:

https://developer.apple.com/forums/thread/739387

dortamiguel commented 9 months ago

@jsm174 do you make anything else like signing the executable?

jsm174 commented 9 months ago

Currently right now I'm not signing the app, and it's definitely getting activated.

dortamiguel commented 9 months ago

can I see your complete info.plist?

jsm174 commented 9 months ago
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleIdentifier</key>
    <string>org.vpinball.VPinballX_GL</string>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>VPinballX_GL</string>
    <key>CFBundleExecutable</key>
    <string>VPinballX_GL</string>
    <key>CFBundleDocumentTypes</key>
    <array>
       <dict>
          <key>CFBundleTypeExtensions</key>
          <array>
             <string>vpx</string>
          </array>
          <key>CFBundleTypeName</key>
          <string>Visual Pinball X Table</string>
          <key>CFBundleTypeRole</key>
          <string>Viewer</string>
       </dict>
    </array>
    <key>CFBundleGetInfoString</key>
    <string>VPinballX_GL 10.8.0</string>
    <key>CFBundleIconFile</key>
    <string>VPinballX_GL.icns</string>
    <key>CFBundleName</key>
    <string>VPinballX_GL</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>ESDE</string>
    <key>CFBundleShortVersionString</key>
    <string>2.2.1</string>
    <key>CFBundleVersion</key>
    <string>2.2.1</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>LSApplicationCategoryType</key>
    <string>public.app-category.games</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.15.0</string>
    <key>LSUIPresentationMode</key>
    <integer>3</integer>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>NSMainNibFile</key>
    <string>VPinballX_GL</string>
    <key>NSHumanReadableCopyright</key>
    <string></string>
</dict>
</plist>
dortamiguel commented 9 months ago

@jsm174 thank you! I had no luck, somehow is not working

icculus commented 3 months ago

So did we decide this isn't an SDL bug, or is this still an open question?

slouken commented 3 months ago

This is still an open question.

slime73 commented 3 months ago

Game mode in maximized-fullscreen and desktop-fullscreen is working fine for my stuff for what it's worth, with SDL2 and SDL3 and with OpenGL and Metal. I haven't tried with SDL_Render though.

My app is a normal packaged .app, without any LSApplicationCategoryType key in its info.plist (nevermind, it does have that - it's just had it for such a long time that I didn't remember it's there. But removing it doesn't prevent game mode from working, for me).

edit: If you're using MoltenVK, I wonder if that's preventing it from activating if it's doing something weird with Metal device selection under the hood?

dortamiguel commented 3 months ago

@slime73 I'm using MoltenVK but if I switch to OpenGL I get the same result, if you run the test/testsprite from SDL do you get the Game Mode?

I'm using SDL3, maybe the issue is there?

slime73 commented 3 months ago

With testsprite, I just had to set the app category to Games in its info plist, and then clean and rebuild. I guess the reason why it continued working when I removed the Games category from my own app is I didn't do the clean step.

So I think this issue is resolved now.

dortamiguel commented 3 months ago

@slime73 Could you upload an app with testsprite? I just tried but is still not working for me, I cleaned my cache too and copied your info.plist but I can't make it work. If I open other games from steam I get the notification for game mode so it seems like is working, I just can't make it work on my game somehow.