1
0
Fork 0

Adapt raw_window_handle 0.4 for nih_plug_iced

I tried updating iced instead, but after a couple hours porting things I
gave up. Supporting newer iced versions will probably require rebuilding
the crate from scratch.
This commit is contained in:
Robbert van der Helm 2023-11-05 19:35:13 +01:00
parent a16cbd6aad
commit 76ef4d0ff9
3 changed files with 38 additions and 25 deletions

25
Cargo.lock generated
View file

@ -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",
]

View file

@ -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"] }

View file

@ -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<E: IcedEditor> {
pub(crate) parameter_updates_receiver: Arc<channel::Receiver<ParameterUpdate>>,
}
/// 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<E: IcedEditor> Editor for IcedEditorWrapper<E> {
fn spawn(
&self,
@ -36,7 +63,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
// 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::<wrapper::IcedEditorWrapperApplication<E>>::open_parented(
&parent,
&ParentWindowHandleAdapter(parent),
Settings {
window: WindowOpenOptions {
title: String::from("iced window"),