mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 21:50:11 +02:00
Simplify GUI event handling
This commit is contained in:
@@ -7,8 +7,8 @@ Yet Another way to use Windows VST2 plugins in Linux VST hosts.
|
|||||||
There are a few things that should be done before releasing this, including:
|
There are a few things that should be done before releasing this, including:
|
||||||
|
|
||||||
- Implement missing features:
|
- Implement missing features:
|
||||||
- GUIs. Right now I'm just ignoring all of the opcodes related to GUIs so that
|
- GUIs. It mostly works right now, but there are a few small problems
|
||||||
the plugins don't crash when you open their GUI.
|
remaining regarding window placement and child windows (i.e. droopdowns).
|
||||||
- Add missing details if any to the architecture section.
|
- Add missing details if any to the architecture section.
|
||||||
- Document what this has been tested on and what does or does not work.
|
- Document what this has been tested on and what does or does not work.
|
||||||
- Document wine32 support.
|
- Document wine32 support.
|
||||||
|
|||||||
+13
-21
@@ -24,7 +24,7 @@ HWND Editor::open() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Editor::close() {
|
void Editor::close() {
|
||||||
// RAII does the rest for us
|
// RAII will destroy the window for us
|
||||||
win32_handle = std::nullopt;
|
win32_handle = std::nullopt;
|
||||||
|
|
||||||
// TODO: Do we need to do something on the X11 side or does the host do
|
// TODO: Do we need to do something on the X11 side or does the host do
|
||||||
@@ -44,26 +44,6 @@ bool Editor::resize(const VstRect& new_size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Below function shouldn't be needed
|
|
||||||
bool Editor::update() {
|
|
||||||
if (!win32_handle.has_value()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Doing this manually should not be needed
|
|
||||||
UpdateWindow(win32_handle->get());
|
|
||||||
|
|
||||||
// TODO: This should also be done somewhere else
|
|
||||||
// Pump events since the Win32 API won't do it for us
|
|
||||||
MSG msg;
|
|
||||||
while (PeekMessage(&msg, win32_handle->get(), 0, 0, PM_REMOVE)) {
|
|
||||||
TranslateMessage(&msg);
|
|
||||||
DispatchMessage(&msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Editor::embed_into(const size_t parent_window_handle) {
|
bool Editor::embed_into(const size_t parent_window_handle) {
|
||||||
if (!win32_handle.has_value()) {
|
if (!win32_handle.has_value()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -101,6 +81,18 @@ bool Editor::embed_into(const size_t parent_window_handle) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::handle_events() {
|
||||||
|
// Process any remaining events, otherwise we won't be able to interact with
|
||||||
|
// the window
|
||||||
|
if (win32_handle.has_value()) {
|
||||||
|
MSG msg;
|
||||||
|
while (PeekMessage(&msg, win32_handle->get(), 0, 0, PM_REMOVE)) {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<size_t> Editor::get_x11_handle() {
|
std::optional<size_t> Editor::get_x11_handle() {
|
||||||
if (!win32_handle.has_value()) {
|
if (!win32_handle.has_value()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
+10
-4
@@ -46,9 +46,12 @@ class Editor {
|
|||||||
*/
|
*/
|
||||||
bool resize(const VstRect& new_size);
|
bool resize(const VstRect& new_size);
|
||||||
|
|
||||||
// TODO: This should not be needed, and is just a test to see if this works
|
/**
|
||||||
// at all
|
* Pump messages from the editor GUI's event loop until all events are
|
||||||
bool update();
|
* process. Must be run from the same thread the GUI was created in because
|
||||||
|
* of Win32 limitations. I guess that's what `effEditIdle` is for.
|
||||||
|
*/
|
||||||
|
void handle_events();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Embed the (open) window into a parent window.
|
* Embed the (open) window into a parent window.
|
||||||
@@ -61,12 +64,15 @@ class Editor {
|
|||||||
*/
|
*/
|
||||||
bool embed_into(const size_t parent_window_handle);
|
bool embed_into(const size_t parent_window_handle);
|
||||||
|
|
||||||
|
private:
|
||||||
/**
|
/**
|
||||||
* Return the X11 window handle for the window if it's currently open.
|
* Return the X11 window handle for the window if it's currently open.
|
||||||
*/
|
*/
|
||||||
std::optional<size_t> get_x11_handle();
|
std::optional<size_t> get_x11_handle();
|
||||||
|
|
||||||
private:
|
/**
|
||||||
|
* The Win32 window class registered for the window window.
|
||||||
|
*/
|
||||||
ATOM window_class;
|
ATOM window_class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -199,13 +199,23 @@ intptr_t PluginBridge::dispatch_wrapper(AEffect* plugin,
|
|||||||
// the X11 window handle passed by the host
|
// the X11 window handle passed by the host
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case effEditIdle:
|
case effEditIdle:
|
||||||
// TODO: Hack, shouldn't be needed. We'll just have to process
|
// Because of the way the Win32 APi works we have to process events
|
||||||
// events somewhere else.
|
// on the same thread the window was created, and that thread is the
|
||||||
editor.update();
|
// `dispatch_handler` thread
|
||||||
|
editor.handle_events();
|
||||||
|
|
||||||
return plugin->dispatcher(plugin, opcode, index, value, data,
|
return plugin->dispatcher(plugin, opcode, index, value, data,
|
||||||
option);
|
option);
|
||||||
break;
|
break;
|
||||||
|
case effClose: {
|
||||||
|
// Closing the editor will also shut down the thread that's
|
||||||
|
// currently handling events
|
||||||
|
editor.close();
|
||||||
|
|
||||||
|
return plugin->dispatcher(plugin, opcode, index, value, data,
|
||||||
|
option);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case effEditOpen: {
|
case effEditOpen: {
|
||||||
const auto win32_handle = editor.open();
|
const auto win32_handle = editor.open();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user