mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Use atomic fetch-and-add for unique window classes
This commit is contained in:
@@ -379,13 +379,7 @@ intptr_t Vst2Bridge::dispatch_wrapper(AEffect* plugin,
|
|||||||
// provided by the host, and let the plugin embed itself into
|
// provided by the host, and let the plugin embed itself into
|
||||||
// the Wine window
|
// the Wine window
|
||||||
const auto x11_handle = reinterpret_cast<size_t>(data);
|
const auto x11_handle = reinterpret_cast<size_t>(data);
|
||||||
// Win32 window classes have to be unique for the whole application.
|
Editor& editor_instance = editor.emplace(config, x11_handle);
|
||||||
// When hosting multiple plugins in a group process, all plugins
|
|
||||||
// should get a unique window class
|
|
||||||
const std::string window_class =
|
|
||||||
"yabridge plugin " + sockets.base_dir.string();
|
|
||||||
Editor& editor_instance =
|
|
||||||
editor.emplace(config, window_class, x11_handle);
|
|
||||||
|
|
||||||
return plugin->dispatcher(plugin, opcode, index, value,
|
return plugin->dispatcher(plugin, opcode, index, value,
|
||||||
editor_instance.get_win32_handle(),
|
editor_instance.get_win32_handle(),
|
||||||
|
|||||||
@@ -397,9 +397,6 @@ void Vst3Bridge::run() {
|
|||||||
// and if it's actually needed (for instance when the host
|
// and if it's actually needed (for instance when the host
|
||||||
// resizes the window without informing the plugin)
|
// resizes the window without informing the plugin)
|
||||||
const auto x11_handle = static_cast<size_t>(request.parent);
|
const auto x11_handle = static_cast<size_t>(request.parent);
|
||||||
const std::string window_class =
|
|
||||||
"yabridge plugin " + sockets.base_dir.string() + " " +
|
|
||||||
std::to_string(request.owner_instance_id);
|
|
||||||
|
|
||||||
// Creating the window and having the plugin embed in it should
|
// Creating the window and having the plugin embed in it should
|
||||||
// be done in the main UI thread
|
// be done in the main UI thread
|
||||||
@@ -407,8 +404,7 @@ void Vst3Bridge::run() {
|
|||||||
.run_in_context<tresult>([&]() {
|
.run_in_context<tresult>([&]() {
|
||||||
Editor& editor_instance =
|
Editor& editor_instance =
|
||||||
object_instances[request.owner_instance_id]
|
object_instances[request.owner_instance_id]
|
||||||
.editor.emplace(config, window_class,
|
.editor.emplace(config, x11_handle);
|
||||||
x11_handle);
|
|
||||||
|
|
||||||
const tresult result =
|
const tresult result =
|
||||||
object_instances[request.owner_instance_id]
|
object_instances[request.owner_instance_id]
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ constexpr uint32_t xembed_focus_in_msg = 4;
|
|||||||
|
|
||||||
constexpr uint32_t xembed_focus_first = 1;
|
constexpr uint32_t xembed_focus_first = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to generate a globally unique identifier for a window class. This is
|
||||||
|
* needed because every window's window class name should be unique.
|
||||||
|
*/
|
||||||
|
std::atomic_size_t window_class_id{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the topmost window (i.e. the window before the root window in the window
|
* Find the topmost window (i.e. the window before the root window in the window
|
||||||
* tree) starting from a certain window.
|
* tree) starting from a certain window.
|
||||||
@@ -94,13 +100,12 @@ WindowClass::~WindowClass() {
|
|||||||
UnregisterClass(reinterpret_cast<LPCSTR>(atom), GetModuleHandle(nullptr));
|
UnregisterClass(reinterpret_cast<LPCSTR>(atom), GetModuleHandle(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor::Editor(const Configuration& config,
|
Editor::Editor(const Configuration& config, const size_t parent_window_handle)
|
||||||
const std::string& window_class_name,
|
|
||||||
const size_t parent_window_handle)
|
|
||||||
: use_xembed(config.editor_xembed),
|
: use_xembed(config.editor_xembed),
|
||||||
x11_connection(xcb_connect(nullptr, nullptr), xcb_disconnect),
|
x11_connection(xcb_connect(nullptr, nullptr), xcb_disconnect),
|
||||||
client_area(get_maximum_screen_dimensions(*x11_connection)),
|
client_area(get_maximum_screen_dimensions(*x11_connection)),
|
||||||
window_class(window_class_name),
|
window_class("yabridge plugin " +
|
||||||
|
std::to_string(window_class_id.fetch_add(1))),
|
||||||
// Create a window without any decoratiosn for easy embedding. The
|
// Create a window without any decoratiosn for easy embedding. The
|
||||||
// combination of `WS_EX_TOOLWINDOW` and `WS_POPUP` causes the window to
|
// combination of `WS_EX_TOOLWINDOW` and `WS_POPUP` causes the window to
|
||||||
// be drawn without any decorations (making resizes behave as you'd
|
// be drawn without any decorations (making resizes behave as you'd
|
||||||
|
|||||||
@@ -97,16 +97,12 @@ class Editor {
|
|||||||
*
|
*
|
||||||
* @param config This instance's configuration, used to enable alternative
|
* @param config This instance's configuration, used to enable alternative
|
||||||
* editor behaviours.
|
* editor behaviours.
|
||||||
* @param window_class_name The name for the window class for editor
|
|
||||||
* windows.
|
|
||||||
* @param parent_window_handle The X11 window handle passed by the VST host
|
* @param parent_window_handle The X11 window handle passed by the VST host
|
||||||
* for the editor to embed itself into.
|
* for the editor to embed itself into.
|
||||||
*
|
*
|
||||||
* @see win32_handle
|
* @see win32_handle
|
||||||
*/
|
*/
|
||||||
Editor(const Configuration& config,
|
Editor(const Configuration& config, const size_t parent_window_handle);
|
||||||
const std::string& window_class_name,
|
|
||||||
const size_t parent_window_handle);
|
|
||||||
|
|
||||||
~Editor();
|
~Editor();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user