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:
parent
a16cbd6aad
commit
76ef4d0ff9
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -614,24 +614,6 @@ dependencies = [
|
||||||
"xcb-util",
|
"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]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.68.1"
|
version = "0.68.1"
|
||||||
|
@ -2228,9 +2210,9 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_baseview"
|
name = "iced_baseview"
|
||||||
version = "0.0.3"
|
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 = [
|
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",
|
"copypasta 0.7.1",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"iced_futures",
|
"iced_futures",
|
||||||
|
@ -2928,11 +2910,12 @@ name = "nih_plug_iced"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic_refcell",
|
"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",
|
"crossbeam",
|
||||||
"iced_baseview",
|
"iced_baseview",
|
||||||
"nih_plug",
|
"nih_plug",
|
||||||
"nih_plug_assets",
|
"nih_plug_assets",
|
||||||
|
"raw-window-handle 0.4.3",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,14 @@ smol = ["iced_baseview/smol"]
|
||||||
nih_plug = { path = ".." }
|
nih_plug = { path = ".." }
|
||||||
nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }
|
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"
|
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"
|
crossbeam = "0.8"
|
||||||
# Upstream doesn't work with the current iced version, this branch also contains
|
# This targets iced 0.4
|
||||||
# additional features
|
|
||||||
iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default_features = false }
|
iced_baseview = { git = "https://github.com/robbert-vdh/iced_baseview.git", branch = "feature/update-baseview", default_features = false }
|
||||||
# To make the state persistable
|
# To make the state persistable
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crossbeam::atomic::AtomicCell;
|
||||||
use crossbeam::channel;
|
use crossbeam::channel;
|
||||||
pub use iced_baseview::*;
|
pub use iced_baseview::*;
|
||||||
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle};
|
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle};
|
||||||
|
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -24,6 +25,32 @@ pub(crate) struct IcedEditorWrapper<E: IcedEditor> {
|
||||||
pub(crate) parameter_updates_receiver: Arc<channel::Receiver<ParameterUpdate>>,
|
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> {
|
impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
|
||||||
fn spawn(
|
fn spawn(
|
||||||
&self,
|
&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.
|
// TODO: iced_baseview does not have gracefuly error handling for context creation failures.
|
||||||
// This will panic if the context could not be created.
|
// This will panic if the context could not be created.
|
||||||
let window = IcedWindow::<wrapper::IcedEditorWrapperApplication<E>>::open_parented(
|
let window = IcedWindow::<wrapper::IcedEditorWrapperApplication<E>>::open_parented(
|
||||||
&parent,
|
&ParentWindowHandleAdapter(parent),
|
||||||
Settings {
|
Settings {
|
||||||
window: WindowOpenOptions {
|
window: WindowOpenOptions {
|
||||||
title: String::from("iced window"),
|
title: String::from("iced window"),
|
||||||
|
|
Loading…
Reference in a new issue