Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: OSX Native fullscreen support (feature request)  (Read 785 times)

lsmoura

  • Bay Watcher
    • View Profile
    • The Codiac
OSX Native fullscreen support (feature request)
« on: September 08, 2014, 12:06:59 pm »

Hello!

I wonder if Dwarf Fortress could have a native full-screen mac experience be implemented?

It's really nice to work on full-screen apps on OS X the "right way". It does not block your working environment, it provides an simple and easy way to refer to references and cheatsheets, and it's also the "right way" to do things on a mac.

I realize that SDL 1.2 does not natively gives you the necessary resources to make this happen... But I have the solution.

I don't know how much Toady has knowledge about Objective-C objects and classes, but all you need to do is pass the following command to the NSWindow object:

Code: [Select]
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
Here's the result of doing so: https://imgur.com/a/ehLM2

Assuming that Dwarf Fortress is not developed on a OS X machine, I've made this code to ease up the implementation of the feature. This is written in "C" and must be called AFTER the game window is created.

Code: [Select]
#include <objc/objc.h>
#include <objc/objc-runtime.h>

void fullScreenWindowSetup() {
    /* This is ugly, but it works. */
    struct utsname v;
    uname(&v);
    int i;
   
    int version = 0;
    for (i = 0; v.release[i] != '.'; i++) {
        version = version * 10 + (v.release[i] - '0');
    }
    /* printf("Version: %s (%d)\n", v.release, version); */
    /* Done retrieving version information */
   
    if (version < 11) {
        /* Not supported on versions earlier than 10.7 */
        return;
    }
   
    Class app_class = objc_getClass("NSApplication");
    SEL sharedApplication = sel_getUid("sharedApplication");
    SEL mainWindow = sel_getUid("mainWindow");
    SEL sel_windows = sel_getUid("windows");
    SEL sel_objectAtIndex_ = sel_getUid("objectAtIndex:");
   
    id app = objc_msgSend((id)app_class, sharedApplication);
    id window;
   
    window = objc_msgSend(app, mainWindow);
   
    if (window == NULL) {
        id windowArray = objc_msgSend(app, sel_windows);
        if (windowArray != NULL) {
            window = objc_msgSend(windowArray, sel_objectAtIndex_, 0);
        }
    }
   
    if (window != NULL) {
        /*
         NSWindowCollectionBehaviorFullScreenPrimary is defined on Cocoa, but not on this environment.
         It won't be called if we have a version below 10.7, so, nothing to fear here.
         */
        unsigned int NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7;
        SEL sel_setCollectionBehavior = sel_getUid("setCollectionBehavior:");
        objc_msgSend(window, sel_setCollectionBehavior, NSWindowCollectionBehaviorFullScreenPrimary);
    }
}

That is the exact code that is used to reproduce the behaviour on the screenshots linked above.

Thanks for everyone's time and thanks Toady for such a great game!

- Sergio Moura
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: OSX Native fullscreen support (feature request)
« Reply #1 on: September 08, 2014, 08:47:00 pm »

I think Toady uses OS X 10.6 - does this require 10.7+?
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

lsmoura

  • Bay Watcher
    • View Profile
    • The Codiac
Re: OSX Native fullscreen support (feature request)
« Reply #2 on: September 09, 2014, 07:09:19 am »

Yes. Fullscreen requires 10.7 to USE. But the above code should compile and run in any 10.x version. He just would not see the results (as it is not supported by the OS and the code automatically returns if the version is lower than 10.7).

- Sergio
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: OSX Native fullscreen support (feature request)
« Reply #3 on: September 09, 2014, 02:00:32 pm »

I just remembered that mifki built a modified SDL framework that implements native fullscreen support here (I'm not sure if this breaks on 10.6, or if Toady would distribute it, but it's fairly easy to replace the default SDL library with it).
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Madd the Sane

  • Escaped Lunatic
  • Crazy, rabid squirrel.
    • View Profile
    • PlayerPRO SourceForge
Re: OSX Native fullscreen support (feature request)
« Reply #4 on: December 18, 2014, 08:48:16 pm »

This functionality is automatically used in SDL2.
Logged
Get out of my mind, idea! I already have an idea in there!