RustAudio / baseview

low-level window system interface for audio plugin UIs
Apache License 2.0
267 stars 57 forks source link

add ability to close window from user code, add HostWindowHandle #103

Closed BillyDM closed 2 years ago

BillyDM commented 2 years ago

I've added a method that allows the user to close the window from their code. This is fairly straightforward.

I've also added two new structs: HostHandle and HostWindowHandle. These are used when opening a window in parented mode. The HostWindowHandle is sent back to the user (which they will use as the UI handle in baseplug), and the HostHandle is stored internally in the baseview window.

When the HostWindowHandle is dropped, then the window is closed automatically Also vice versa, if the HostHandle drops unexpectedly, it will trip a flag in the HostWindowHandle, alerting the host/parent (I'm not sure how useful the latter case is, but it was trivial to add in).

I've tested the parentless version of this on Linux, Windows, and Mac. Also the parentless mode in Mac OS was broken anyway, so I've also made changes to fix that as well.

I have also tested this in a plugin context in Bitwig under Linux and Windows. This seems to fix an issue I was having before with the window not opening again after being closed.

Although I have not tested the plugin context in Mac yet since I can't seem to get baseplug working for some reason.

BillyDM commented 2 years ago

Alright, I've merged the latest commit to my branch. I tested the MacOS code on both unparented and as a plugin, and they both seem to work now (except for manually closing a plugin window from the user's code since I'm not sure how to get that to work. Custom "close window" buttons aren't common in plugins anyway so it's probably not a big deal right now).

I've also renamed the HostWindowHandle struct to ChildWindowHandle (and HostHandle to ParentHandle).