Skip to content

Instantly share code, notes, and snippets.

@Siguza
Last active April 22, 2021 23:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Siguza/9947e491c4115c88bb231bbba0932359 to your computer and use it in GitHub Desktop.
Save Siguza/9947e491c4115c88bb231bbba0932359 to your computer and use it in GitHub Desktop.
// This is a patch for the macOS version of Graveyard Keeper (might work for arbitrary apps, but zero guarantees).
// The game completely fails to support fullscreen, yet runs beautifully with it if you force it to.
// So this patch simply brings back the functionality of the little green button in the window's upper left corner.
// I have sadly not found a way to automatically inject this by means of a Steam interface - if you do, please let me know!
// For the rest, you should probably be an advanced user to use this. No support or warranty.
// Compile and inject with:
// clang -shared -o FullScreen.dylib FullScreen.m -Wall -O3 -framework AppKit
// DYLD_INSERT_LIBRARIES=/path/to/FullScreen.dylib /path/to/Graveyard\ Keeper
#include <objc/runtime.h>
#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>
static id (*old_NSWindow_initWithContentRect_styleMask_backing_defer)(id self, SEL sel, CGRect contentRect, NSWindowStyleMask style, NSBackingStoreType backingStoreType, BOOL defer);
static id (*old_NSWindow_initWithContentRect_styleMask_backing_defer_screen)(id self, SEL sel, CGRect contentRect, NSWindowStyleMask style, NSBackingStoreType backingStoreType, BOOL defer, id screen);
static id (*old_NSWindow_setCollectionBehavior)(id self, SEL sel, NSWindowCollectionBehavior behavior);
static id _Nullable new_NSWindow_initWithContentRect_styleMask_backing_defer(id self, SEL sel, CGRect contentRect, NSWindowStyleMask style, NSBackingStoreType backingStoreType, BOOL defer)
{
style &= ~(NSWindowStyleMaskUtilityWindow | NSWindowStyleMaskDocModalWindow | NSWindowStyleMaskNonactivatingPanel | NSWindowStyleMaskHUDWindow);
NSWindow *win = old_NSWindow_initWithContentRect_styleMask_backing_defer(self, sel, contentRect, style, backingStoreType, defer);
[win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
return win;
}
static id _Nullable new_NSWindow_initWithContentRect_styleMask_backing_defer_screen(id self, SEL sel, CGRect contentRect, NSWindowStyleMask style, NSBackingStoreType backingStoreType, BOOL defer, id screen)
{
style &= ~(NSWindowStyleMaskUtilityWindow | NSWindowStyleMaskDocModalWindow | NSWindowStyleMaskNonactivatingPanel | NSWindowStyleMaskHUDWindow);
NSWindow *win = old_NSWindow_initWithContentRect_styleMask_backing_defer_screen(self, sel, contentRect, style, backingStoreType, defer, screen);
[win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
return win;
}
static id _Nullable new_NSWindow_setCollectionBehavior(id self, SEL sel, NSWindowCollectionBehavior behavior)
{
old_NSWindow_setCollectionBehavior(self, sel, NSWindowCollectionBehaviorFullScreenPrimary);
//old_NSWindow_setCollectionBehavior(self, sel, behavior);
return nil;
}
__attribute__((constructor)) void init(void)
{
#define HOOK(clazz, meth, func) old_ ## clazz ## _ ## func = (void*)method_setImplementation(class_getInstanceMethod([clazz class], @selector(meth)), (void*)& new_ ## clazz ## _ ## func)
HOOK(NSWindow, initWithContentRect:styleMask:backing:defer:, initWithContentRect_styleMask_backing_defer);
HOOK(NSWindow, initWithContentRect:styleMask:backing:defer:screen:, initWithContentRect_styleMask_backing_defer_screen);
HOOK(NSWindow, setCollectionBehavior:, setCollectionBehavior);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment