diff --git a/Cargo.lock b/Cargo.lock index b9f94530..e421acb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -614,24 +614,6 @@ dependencies = [ "xcb-util", ] -[[package]] -name = "baseview" -version = "0.1.0" -source = "git+https://github.com/RustAudio/baseview.git#f0639b787bbda506434d3f6b5c91e94ca59904c6" -dependencies = [ - "cocoa", - "core-foundation", - "keyboard-types", - "nix 0.22.3", - "objc", - "raw-window-handle 0.5.2", - "uuid", - "winapi", - "x11", - "xcb 0.9.0", - "xcb-util", -] - [[package]] name = "bindgen" version = "0.68.1" @@ -2228,9 +2210,9 @@ dependencies = [ [[package]] name = "iced_baseview" version = "0.0.3" -source = "git+https://github.com/robbert-vdh/iced_baseview.git?branch=feature/update-baseview#07f1b07d3a8bf2a9af0ce6ee57443105ac99de33" +source = "git+https://github.com/robbert-vdh/iced_baseview.git?branch=feature/update-baseview#df3a852a15cf0e9fcc8d2b32f5718e56780beaf3" dependencies = [ - "baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git)", + "baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=1d9806d5bd92275d0d8142d9c9c90198757b9b25)", "copypasta 0.7.1", "iced_core", "iced_futures", @@ -2928,11 +2910,12 @@ name = "nih_plug_iced" version = "0.0.0" dependencies = [ "atomic_refcell", - "baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git)", + "baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=1d9806d5bd92275d0d8142d9c9c90198757b9b25)", "crossbeam", "iced_baseview", "nih_plug", "nih_plug_assets", + "raw-window-handle 0.4.3", "serde", ] diff --git a/nih_plug_iced/Cargo.toml b/nih_plug_iced/Cargo.toml index efd6de5f..ae34e11d 100644 --- a/nih_plug_iced/Cargo.toml +++ b/nih_plug_iced/Cargo.toml @@ -59,11 +59,14 @@ smol = ["iced_baseview/smol"] nih_plug = { path = ".." } nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" } +# The currently targeted version of baseview uses a different version of +# `raw_window_handle` than NIH-plug, so we need to manually convert between them +raw-window-handle = "0.4" + atomic_refcell = "0.1" -baseview = { git = "https://github.com/RustAudio/baseview.git" } +baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" } crossbeam = "0.8" -# Upstream doesn't work with the current iced version, this branch also contains -# additional features +# This targets iced 0.4 iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default_features = false } # To make the state persistable serde = { version = "1.0", features = ["derive"] } diff --git a/nih_plug_iced/src/editor.rs b/nih_plug_iced/src/editor.rs index 0724cbd4..d2984d27 100644 --- a/nih_plug_iced/src/editor.rs +++ b/nih_plug_iced/src/editor.rs @@ -5,6 +5,7 @@ use crossbeam::atomic::AtomicCell; use crossbeam::channel; pub use iced_baseview::*; use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle}; +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -24,6 +25,32 @@ pub(crate) struct IcedEditorWrapper { pub(crate) parameter_updates_receiver: Arc>, } +/// This version of `baseview` uses a different version of `raw_window_handle than NIH-plug, so we +/// need to adapt it ourselves. +struct ParentWindowHandleAdapter(nih_plug::editor::ParentWindowHandle); + +unsafe impl HasRawWindowHandle for ParentWindowHandleAdapter { + fn raw_window_handle(&self) -> RawWindowHandle { + match self.0 { + ParentWindowHandle::X11Window(window) => { + let mut handle = raw_window_handle::XcbHandle::empty(); + handle.window = window; + RawWindowHandle::Xcb(handle) + } + ParentWindowHandle::AppKitNsView(ns_view) => { + let mut handle = raw_window_handle::AppKitHandle::empty(); + handle.ns_view = ns_view; + RawWindowHandle::AppKit(handle) + } + ParentWindowHandle::Win32Hwnd(hwnd) => { + let mut handle = raw_window_handle::Win32Handle::empty(); + handle.hwnd = hwnd; + RawWindowHandle::Win32(handle) + } + } + } +} + impl Editor for IcedEditorWrapper { fn spawn( &self, @@ -36,7 +63,7 @@ impl Editor for IcedEditorWrapper { // TODO: iced_baseview does not have gracefuly error handling for context creation failures. // This will panic if the context could not be created. let window = IcedWindow::>::open_parented( - &parent, + &ParentWindowHandleAdapter(parent), Settings { window: WindowOpenOptions { title: String::from("iced window"),