macOS "traffic light buttons" position

I’m trying to achieve this look in an app:

I’m partially there using declares (thanks to a post from @Sam_Rowlands):

#If TargetCocoa Then
  Const NSFullSizeContentViewWindowMask = 32768
  Declare Function NSClassFromString Lib "Foundation" (aClassName As CFStringRef) As Ptr
  If NSClassFromString( "NSVisualEffectView" ) <> Nil Then
    Declare Sub setStyleMask Lib "AppKit" Selector "setStyleMask:" (handle As Ptr, value As Integer)
    Declare Function styleMask Lib "AppKit" Selector "styleMask" (handle As Ptr ) As Integer
    setStyleMask(Me.Handle, styleMask(Me.Handle) + NSFullSizeContentViewWindowMask)
    Declare Sub titlebarAppearsTransparent Lib "AppKit" Selector "setTitlebarAppearsTransparent:" (handle As Ptr, value As Boolean)
    titleBarAppearsTransparent(Me.Handle, True)
  End If
#EndIf

This is what I currently have:

Notice how the position of the traffic lights is closer to the top edge and left edge of the window than what I’m trying to achieve. Many apps in macOS (including Safari):

Screenshot 2023-07-15 at 09.06.17

position the traffic lights lower. How do I achieve this? How I currently have it means things just look too cluttered.

If i remember correctly, they move down if the window uses the unified style for Toolbar and title bar.

Hmm, I tried adding a toolbar to the window but they don’t move…

But is your toolbar updated?

Declare Sub SetToolbarStyle Lib "AppKit" Selector "setToolbarStyle:" (handle As Ptr, value As Integer)
SetToolbarStyle(Me.Handle, 3) ' 3 = Unified, 0 = Automatic works as well.

With this in the Window open event my window looks like this with a Toolbar:

and this when it is hidden:

Screenshot 2023-07-15 at 11.42.45

UnifiedCompact (4) looks like this:

Spot on.

Looks like if I just add an empty ToolBar and use this code:

Declare Sub SetToolbarStyle Lib "AppKit" Selector "setToolbarStyle:" (handle As Ptr, value As Integer)
SetToolbarStyle(Me.Handle, 4) ' 3 = Unified, 0 = Automatic works as well, 4 = unified compact.

Then all is good.

Thanks @Ian_Kennedy.

2 Likes