go-flutter-desktop/go-flutter

Support custom title bar color on OSX

zakiso opened this issue · 11 comments

Some OSX app has a great view, like this:
image

Is there any chance of getting this for go flutter app?

This can be achieved by using the following flags on NSWindow, assuming the window background color is set accordingly (example in Swift).

window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.styleMask.insert(NSWindowStyleMask.fullSizeContentView)

This may be possible to implement as plugin, maybe even compatible with https://github.com/mchome/flutter_statusbarcolor (I'm not sure if osx supports all features of flutter_statusbarcolor?)

I don't know glfw if provide this capability, if glfw has this capability add an option on options.go is more simple maybe.
I don't really understand go and glfw, when I‘m free I will investigate it.
Also hope someone implement it early.

I've looked into it, and started to write a plugin. It seems that go implementation of GLFW doesn't support title bar etc.
It only supports func (w *Window) SetTitle(title string).
But GLFW in C seems to support C.glfwGetCurrentContext().glClearColor() which apparently changes background color.
Here's the code I've started writing : https://github.com/zephylac/statusbarcolor.
I've followed the implementation from https://github.com/mchome/flutter_statusbarcolor

Even if we can change color by using GLFW, we won't be able to differentiate status bar and navigation bar.

@zephylac @zakiso here is a blog describing how to set titlebarAppearsTransparent and backgroundColor on a GLFW window. http://svenandersson.se/2016/rendering-to-full-size-of-an-nswindow-using-glfw3.html

It's possible to get the native NSWindow using go-glfw

IMO, I think the plugin should call window.GetCocoaWindow() in golang. And then, with the uintptr, you could call some objective-c code to do the actual modification. example of CGO objective-c bindings

Ok but we want the plugin to be cross-platform? We will need to implement for each patform then.

we want the plugin to be cross-platform?

Yes and No, The feature asked by @zakiso is about an OSX dependent request. To resolve the issue, OSX code needs to be written.
If someone has the same request on another platform (windows for example), then we will have to write windows code to solves the windows issue.

A shared interface can be exposed to each platform, (same way we handle textinput). But for now this isn't the question.
Let's start by writing a OSX only plugin.

I'll draft a PR on plugins then to follow the WIP.

Now we can:

  • Change status bar color
  • Change status transparency
  • Hide / show status bar
  • Hide / show minimize widget button
  • Hide / show close widget button

I found out that we could also implement some others features like fullscreen (which we already handle) and transparency but this is more related to the window in itself than status bar.

I decided to not follow https://github.com/mchome/flutter_statusbarcolor since we add much more feature available.

I have tested this plugin, but found a weird problem. I called the method channel function on program started, but status bar color not changed. I have two display, when I drag the window into another display then the status bar color changed.

Can you send your example, I'll try to replicate it.

I'm pleased to see the community making plugins. The proof of concept made by zephylac is quite impressive.
Closing the issue, please use the zephylac/title_bar issue tracker.