Skip to content

Commit

Permalink
use HasRawWindowHandle instead of RawWindowHandle (#20)
Browse files Browse the repository at this point in the history
* use TrustedWindowHandle instead of RawWindowHandle

* implement HasRawWindowHandle for VST2WindowHandle

* keep `Into<RawWindowHandle>` for VST2WindowHandle
  • Loading branch information
Billy Messenger authored Feb 8, 2021
1 parent bc53ab3 commit 0c9a54f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/api/vst2/ui.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use std::os::raw::c_void;

use raw_window_handle::RawWindowHandle;
use raw_window_handle::{RawWindowHandle, HasRawWindowHandle};


use super::*;


struct VST2WindowHandle(*mut c_void);

impl From<VST2WindowHandle> for RawWindowHandle {
impl From<&VST2WindowHandle> for RawWindowHandle {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
fn from(handle: VST2WindowHandle) -> RawWindowHandle {
fn from(handle: &VST2WindowHandle) -> RawWindowHandle {
use raw_window_handle::unix::*;

RawWindowHandle::Xcb(XcbHandle {
Expand All @@ -26,7 +25,7 @@ impl From<VST2WindowHandle> for RawWindowHandle {
}

#[cfg(target_os = "windows")]
fn from(handle: VST2WindowHandle) -> RawWindowHandle {
fn from(handle: &VST2WindowHandle) -> RawWindowHandle {
use raw_window_handle::windows::*;

RawWindowHandle::Windows(WindowsHandle {
Expand All @@ -36,7 +35,7 @@ impl From<VST2WindowHandle> for RawWindowHandle {
}

#[cfg(target_os = "macos")]
fn from(handle: VST2WindowHandle) -> RawWindowHandle {
fn from(handle: &VST2WindowHandle) -> RawWindowHandle {
use raw_window_handle::macos::*;

RawWindowHandle::MacOS(MacOSHandle {
Expand All @@ -46,6 +45,12 @@ impl From<VST2WindowHandle> for RawWindowHandle {
}
}

unsafe impl HasRawWindowHandle for VST2WindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
self.into()
}
}

pub(super) trait VST2UI {
fn has_ui() -> bool;

Expand Down Expand Up @@ -83,7 +88,7 @@ impl<P: PluginUI> VST2UI for VST2Adapter<P> {
let parent = VST2WindowHandle(parent);

if self.wrapped.ui_handle.is_none() {
P::ui_open(parent.into())
P::ui_open(&parent)
.map(|handle| self.wrapped.ui_handle = Some(handle))
} else {
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{
de::DeserializeOwned
};

use raw_window_handle::RawWindowHandle;
use raw_window_handle::HasRawWindowHandle;


use crate::parameter::*;
Expand Down Expand Up @@ -73,7 +73,7 @@ pub trait PluginUI: Plugin {

fn ui_size() -> (i16, i16);

fn ui_open(parent: RawWindowHandle) -> WindowOpenResult<Self::Handle>;
fn ui_open(parent: &impl HasRawWindowHandle) -> WindowOpenResult<Self::Handle>;
fn ui_close(handle: Self::Handle);

fn ui_param_notify(handle: &Self::Handle,
Expand Down

0 comments on commit 0c9a54f

Please sign in to comment.