macosui / macos_window_utils.dart

macos_window_utils is a Flutter package that provides a set of methods for modifying the NSWindow of a Flutter application on macOS.
https://pub.dev/packages/macos_window_utils
MIT License
49 stars 9 forks source link

[Question] Transparency compatibility with desktop_multi_window #49

Closed damywise closed 4 months ago

damywise commented 4 months ago

Hello, I saw that it is possible to make sub window transparent like so: https://github.com/macosui/macos_ui/discussions/322#discussioncomment-4869430 image

How did you manage to make it work? I want to implement it in a fork of this since it would be unreasonable to introduce breaking changes. It could be helpful for others too, as I honestly don't see official multi-window implementation happening this year.

As of now, calling WindowManipulator.makeWindowFullyTransparent() on sub windows really doesn't do anything as far as I notice.

Adrian-Samoticha commented 4 months ago

Frankly, it’s been so long that I don’t really recall any details. However, it seems that I have used the FlutterMultiWindowPlugin.setOnWindowCreatedCallback to retrieve the FlutterViewController of the newly created window (which is the controller variable in the callback). I’ve probably just called the MainFlutterWindowManipulator.start function with the FlutterViewController’s window as the mainFlutterWindow argument, at which point macos_window_utils was interfacing with the new window, rather than the old one.

Again, my memory of this is quite murky at this point, but I think that’s the gist of it.

damywise commented 4 months ago

Thanks for your reply! I'll share an example when I got it working

damywise commented 4 months ago

Okay I remembered this macos embedder api docs https://main-api.flutter.dev/macos-embedder/interface_flutter_view_controller.html And found this backgroundColor, which defaults to black. I set it to clear and voila, transparent sub window. I wanna cry I spent so much time on this lol.

anyway here's the code:

FlutterMultiWindowPlugin.setOnWindowCreatedCallback { controller in
  // Register macos window utils on sub window. Not really needed, but just as a reminder how to register plugins.
  MacOSWindowUtilsPlugin.register(with: controller.registrar(forPlugin: "MacOSWindowUtilsPlugin"))
  // Set the background color of the Flutter view to clear/transparent
  controller.backgroundColor = NSColor.clear
}
Adrian-Samoticha commented 4 months ago

Oh yeah, that was a change that Flutter pushed in (I believe) version 3.7.0. It caused macos_window_utils to break and it took a while for the community to figure out what had happened.