How can I move window controls (traffic lights) down in an NSWindow?

109 Views Asked by At

I am writing an application using React Native on macOS. By default, the window shows as such:

enter image description here

I have managed to hide the title and make the titlebar transparent, as such (ignore the title in the screenshot):

enter image description here

I would now like to move the 'traffic lights' down/set the toolbar style to match the style shown below:

enter image description here

Unfortunately, I can't seem to figure out the combination of settings or so required to do this.

I am constrained to extending an objective-c AppDelegate implementation. I have the current code;

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
}

This works to get to the second stage. I have tried variations such as ;

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
  NSToolbar *toolbar = [NSToolbar init];
  window.toolbar = toolbar;
}

or

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
  window.toolbarStyle = NSWindowToolbarStyleUnified;
}

and other variations of toolbarStyle, to no avail.

1

There are 1 best solutions below

0
jnpdx On

The following code works for me:

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
    NSWindow *window = [[[NSApplication sharedApplication] windows] firstObject];
    window.titleVisibility = NSWindowTitleHidden;
    window.titlebarAppearsTransparent = true;
    window.styleMask |= NSWindowStyleMaskFullSizeContentView;
    window.toolbar = [NSToolbar new]; // <-- Note this is `new` and not `init`
    window.toolbarStyle = NSWindowToolbarStyleUnified;
}

enter image description here