From 7a6bfa4573161485a62e68786be32903e431ff2d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Feb 2022 00:06:01 +0100 Subject: [PATCH] Add a HasRawWindowHandle wrapper struct --- src/lib.rs | 3 ++- src/plugin.rs | 17 +++++++++++++---- src/wrapper/vst3.rs | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3f6fd650..412e1cb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,8 @@ pub use param::range::Range; pub use param::smoothing::{Smoother, SmoothingStyle}; pub use param::{BoolParam, FloatParam, IntParam, Param}; pub use plugin::{ - BufferConfig, BusConfig, Editor, NoteEvent, Plugin, ProcessStatus, RawWindowHandle, Vst3Plugin, + BufferConfig, BusConfig, Editor, EditorWindowHandle, NoteEvent, Plugin, ProcessStatus, + Vst3Plugin, }; // The rest is either internal or already re-exported diff --git a/src/plugin.rs b/src/plugin.rs index 1df91d71..7d69403e 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use std::pin::Pin; use std::sync::Arc; @@ -21,9 +22,6 @@ use crate::buffer::Buffer; use crate::context::{GuiContext, ProcessContext}; use crate::param::internals::Params; -/// A raw window handle for platform and GUI framework agnostic editors. -pub use raw_window_handle::RawWindowHandle; - /// Basic functionality that needs to be implemented by a plugin. The wrappers will use this to /// expose the plugin in a particular plugin format. /// @@ -85,7 +83,7 @@ pub trait Plugin: Default + Send + Sync + 'static { // instance. fn create_editor<'a, 'context: 'a>( &'a self, - parent: RawWindowHandle, + parent: EditorWindowHandle, context: Arc, ) -> Option> { None @@ -162,6 +160,17 @@ pub trait Editor { // TODO: Resizing } +/// A raw window handle for platform and GUI framework agnostic editors. +pub struct EditorWindowHandle { + pub handle: RawWindowHandle, +} + +unsafe impl HasRawWindowHandle for EditorWindowHandle { + fn raw_window_handle(&self) -> RawWindowHandle { + self.handle + } +} + /// We only support a single main input and output bus at the moment. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct BusConfig { diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 437e3b75..3eb6f4bb 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -51,6 +51,7 @@ use crate::plugin::{ }; use crate::wrapper::state::{ParamValue, State}; use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy, u16strlcpy}; +use crate::EditorWindowHandle; // Alias needed for the VST3 attribute macro use vst3_sys as vst3_com; @@ -1363,7 +1364,7 @@ impl IPlugView for WrapperView

{ .inner .plugin .write() - .create_editor(handle, self.inner.clone()); + .create_editor(EditorWindowHandle { handle }, self.inner.clone()); kResultOk } else { kResultFalse