Fixed Mac Borderless window code

Started by GreyAlien, January 19, 2018, 21:03:30

Previous topic - Next topic

GreyAlien

There's a module tweak from the old site that made Borderless Window work on PC but it only sort of worked on Mac because it still left a bar along the top of the screen and the app menu bar thing along the bottom.

http://www.mojolabs.nz//posts.php?topic=102797

Anyway, I finally got round to fixing it today. Basically you need to use HideMenuBar() and ShowMenuBar() (otherwise Windowed mode isn't correct if switching from borderless mode) as per the code below. This code works in BlitzMax V1.51.

Basically REPLACE THIS CODE:


window=[[BBGLWindow alloc]
initWithContentRect:NSMakeRect( 0,0,width,height )
styleMask:NSTitledWindowMask|NSClosableWindowMask
backing:NSBackingStoreBuffered
defer:YES];

if( !window ) return 0;

[window setDelegate:window];
[window setAcceptsMouseMovedEvents:YES];
[window setTitle:[NSString stringWithUTF8String:bbTmpUTF8String(bbAppTitle)]];
[window center];


WITH THIS:


NSUInteger m = NSTitledWindowMask|NSClosableWindowMask;
if (flags & FLAGS_BORDERLESS) m = NSBorderlessWindowMask;
window=[[BBGLWindow alloc]
initWithContentRect:NSMakeRect( 0,0,width,height )
styleMask:m
backing:NSBackingStoreBuffered
defer:YES];

if( !window ) return 0;

[window setDelegate:window];
[window setAcceptsMouseMovedEvents:YES];

if (flags & FLAGS_BORDERLESS){
HideMenuBar();
}else{
ShowMenuBar();
[window setTitle:[NSString stringWithUTF8String:bbTmpUTF8String(bbAppTitle)]];
[window center];
}


You still have to do some other stuff like add FLAGS_BORDERLESS to brl.mod/glgraphics.mod/glgraphics.macos.m but that's all mentioned in the thread linked to above.

Also you might want to make the window minimisable in which case you need to use this instead and add a couple of functions as a mod tweak by GfK that is floating around somewhere.
NSUInteger m = NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask;

Pingus

Wow ! Thanks, that may come in handy !