Custom toolbar Dark Mode problems

Hi All,

I’m using the following code that I picked up from this forum to create a custom toolbar.

[code]NewTitleBar(mycontrol as RectControl)

declare function contentView lib “Cocoa” selector “contentView” (id As integer) As Ptr
declare function superView lib “Cocoa” selector “superview” (id As Ptr) As Ptr
declare function subviews lib “Cocoa” selector “subviews” (id As Ptr) As Ptr
declare function objAtIdx lib “Cocoa” selector “objectAtIndex:” (id As Ptr, idx As UInt32) As Ptr
declare sub addSubView lib “Cocoa” selector “addSubview:positioned:relativeTo:” _
(id As Ptr, aView As integer, order As integer, rel As Ptr)

dim cv As Ptr = contentView(self.Handle)
dim themeFrame As Ptr = superView(cv)
dim firstSubView As Ptr = objAtIdx(subViews(themeFrame), 0)
addSubView(themeFrame, mycontrol.Handle, 0, firstSubView)[/code]

You pass it a RectControl, which in my case is a canvas that I use to layout my custom toolbar. It then adds the canvas at the top of the window, over to top of the normal windows titlebar, so I can create a complex toolbar like that of iTunes. This means I can paint buttons and text into the canvas and they will appear at the top of the screen as a toolbar.

This works great in Light Mode and the toolbar shows perfectly, however, when in Dark Mode none of the content of the canvas shows at all, so I only know the canvas is visible because I have made the background red (as a test).

Also, the canvas is now behind the normal titlebar of the window, whereas in Light Mode the canvas displays over the normal window titlebar (so I can use it as a custom toolbar).

So something is very different in Dark Mode. My guess is it’s somthing to do with the layer order, so my canvas and its sub-controls are appearing below other content. Anyone any ideas if there’s a way to use a canvas as a custom toolbar in Dark Mode?

Do you know that you can make the toolbar transparent and place your controls underneath it?

[NSWindow titlebarAppearsTransparent]

And set [NSWindow styleMask] with this option NSWindowStyleMaskFullSizeContentView = 1 << 15.

I use this for the recent HDR updates, https://www.ohanaware.com/hdr/

Awesome, thank you! Works prefectly.