View Issue Details

IDProjectCategoryView StatusLast Update
0008260Dwarf FortressGeneralpublic2014-09-08 09:44
Reporterlsmoura Assigned Touser6 
PrioritynoneSeverityfeatureReproducibilityalways
Status resolvedResolutionno change required 
PlatformMacOSOS XOS Version10.10
Product Version0.40.11 
Summary0008260: Can a native full-screen mac experience be implemented on Dwarf Fortress?
DescriptionIt'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:

[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];

Here's the result of doing so: https://imgur.com/a/ehLM2
Additional InformationAssuming 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 pure-C and must be called AFTER the game window is created.

#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) {
            fprintf(stderr, "no windows!\n");
        }
        else {
            window = objc_msgSend(windowArray, sel_objectAtIndex_, 0);
            if (window == NULL) {
                fprintf(stderr, "No window!");
            }
            else {
                printf("We got a window!!\n");
            }
        }
    }
    
    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.
Tagsmac

Activities

user6

2014-09-08 09:44

  ~0030035

We only use the bug tracker for bugs. Please feel free to post suggestions in the DF Suggestions forum: http://www.bay12forums.com/smf/index.php?board=5.0

Issue History

Date Modified Username Field Change
2014-09-08 09:22 lsmoura New Issue
2014-09-08 09:23 lsmoura Tag Attached: mac
2014-09-08 09:44 user6 Note Added: 0030035
2014-09-08 09:44 user6 Status new => resolved
2014-09-08 09:44 user6 Resolution open => no change required
2014-09-08 09:44 user6 Assigned To => user6