Clean up the editor implementation

This commit is contained in:
Robbert van der Helm
2020-04-14 16:51:24 +02:00
parent 03608870cc
commit 03de09d77f
5 changed files with 144 additions and 182 deletions
+25 -36
View File
@@ -18,11 +18,11 @@
/**
* A wrapper around the win32 windowing API to create and destroy editor
* windows. A VST plugin can embed itself in that window, and we can then later
* embed the window in a VST host provided X11 window.
* windows. We can embed this window into the window provided by the host, and a
* VST plugin can then later embed itself in the window create here.
*
* This was originally implemented using XEmbed. While that sounded like the
* right thing to do, there were a few small issues with Wine's XEmbed
* This was originally implemented using XEmbed. Even though that sounded like
* the right thing to do, there were a few small issues with Wine's XEmbed
* implementation. The most important of which is that resizing GUIs sometimes
* works fine, but often fails to expand the embedded window's client area
* leaving part of the window inaccessible. There are also some a small number
@@ -32,41 +32,25 @@
* issues, please let me know and I'll switch to using XEmbed again.
*
* This workaround was inspired by LinVST.
*
* TODO: Refactor this so we don't need to stage initialization and just add an
* `std::optional<Editor>` to `PluginBridge` instead
*/
class Editor {
public:
/**
* @param window_class_name The name for the window class for editor
* windows.
*/
Editor(std::string window_class_name);
/**
* Open a window, embed it into the DAW's parent window and return a handle
* Open a window, embed it into the DAW's parent window and create a handle
* to the new Win32 window that can be used by the hosted VST plugin.
*
* @param window_class_name The name for the window class for editor
* windows.
* @param effect The plugin this window is being created for. Used to send
* `effEditIdle` messages on a timer.
*
* @return The Win32 window handle of the newly created window.
*/
HWND open(AEffect* effect);
void close();
/**
* Embed the (open) window into a parent window.
*
* @param parent_window_handle The X11 window handle passed by the VST host
* for the editor to embed itself into.
*
* @return Whether the embedding was succesful. Will return false if the
* window is not open.
* @see win32_handle
*/
bool embed_into(const size_t parent_window_handle);
Editor(const std::string& window_class_name,
AEffect* effect,
const size_t parent_window_handle);
/**
* Pump messages from the editor GUI's event loop until all events are
@@ -74,10 +58,23 @@ class Editor {
* of Win32 limitations. I guess that's what `effEditIdle` is for.
*/
void handle_events();
// Needed to handle idle updates through a timer
AEffect* plugin;
private:
/**
* The Win32 window class registered for the windows window.
*/
ATOM window_class;
public:
/**
* The handle for the window created through Wine that the plugin uses to
* embed itself in.
*/
const std::unique_ptr<std::remove_pointer_t<HWND>, decltype(&DestroyWindow)>
win32_handle;
private:
/**
* The window handle of the editor window created by the DAW.
@@ -88,18 +85,10 @@ class Editor {
*/
xcb_window_t child_window;
/**
* The Win32 window class registered for the windows window.
*/
ATOM window_class;
/**
* A pointer to the currently active window. Will be a null pointer if no
* window is active.
*/
std::optional<
std::unique_ptr<std::remove_pointer_t<HWND>, decltype(&DestroyWindow)>>
win32_handle;
std::unique_ptr<xcb_connection_t, decltype(&xcb_disconnect)> x11_connection;
};