1
0
Fork 0

raw-window-handle 0.6.0

This commit is contained in:
Alex Janka 2024-02-08 15:20:59 +11:00
parent dfafe90349
commit 5fb5bcd018
7 changed files with 82 additions and 46 deletions

24
Cargo.lock generated
View file

@ -673,14 +673,14 @@ dependencies = [
[[package]] [[package]]
name = "baseview" name = "baseview"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/RustAudio/baseview.git?rev=579130ecb4f9f315ae52190af42f0ea46aeaa4a2#579130ecb4f9f315ae52190af42f0ea46aeaa4a2" source = "git+https://git.alexjanka.com/alex/baseview?rev=e31a11f1c73c0fdf1463db77105cf9a9b7c9240a#e31a11f1c73c0fdf1463db77105cf9a9b7c9240a"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"core-foundation", "core-foundation",
"keyboard-types", "keyboard-types",
"nix 0.22.3", "nix 0.22.3",
"objc", "objc",
"raw-window-handle 0.5.2", "raw-window-handle 0.6.2",
"uuid", "uuid",
"winapi", "winapi",
"x11", "x11",
@ -3045,7 +3045,7 @@ dependencies = [
"atomic_float", "atomic_float",
"atomic_refcell", "atomic_refcell",
"backtrace", "backtrace",
"baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=579130ecb4f9f315ae52190af42f0ea46aeaa4a2)", "baseview 0.1.0 (git+https://git.alexjanka.com/alex/baseview?rev=e31a11f1c73c0fdf1463db77105cf9a9b7c9240a)",
"bitflags 1.3.2", "bitflags 1.3.2",
"cfg-if", "cfg-if",
"clap", "clap",
@ -3062,7 +3062,7 @@ dependencies = [
"nih_plug_derive", "nih_plug_derive",
"objc", "objc",
"parking_lot 0.12.3", "parking_lot 0.12.3",
"raw-window-handle 0.5.2", "raw-window-handle 0.6.2",
"rtrb", "rtrb",
"serde", "serde",
"serde_json", "serde_json",
@ -3091,12 +3091,12 @@ dependencies = [
name = "nih_plug_egui" name = "nih_plug_egui"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=45465c5f46abed6c6ce370fffde5edc8e4cd5aa3)", "baseview 0.1.0 (git+https://git.alexjanka.com/alex/baseview?rev=e31a11f1c73c0fdf1463db77105cf9a9b7c9240a)",
"crossbeam", "crossbeam",
"egui-baseview", "egui-baseview",
"nih_plug", "nih_plug",
"parking_lot 0.12.3", "parking_lot 0.12.3",
"raw-window-handle 0.5.2", "raw-window-handle 0.6.2",
"serde", "serde",
] ]
@ -3105,12 +3105,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?rev=1d9806d5bd92275d0d8142d9c9c90198757b9b25)", "baseview 0.1.0 (git+https://git.alexjanka.com/alex/baseview?rev=e31a11f1c73c0fdf1463db77105cf9a9b7c9240a)",
"crossbeam", "crossbeam",
"iced_baseview", "iced_baseview",
"nih_plug", "nih_plug",
"nih_plug_assets", "nih_plug_assets",
"raw-window-handle 0.4.3", "raw-window-handle 0.6.2",
"serde", "serde",
] ]
@ -3118,7 +3118,7 @@ dependencies = [
name = "nih_plug_vizia" name = "nih_plug_vizia"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=2c1b1a7b0fef1a29a5150a6a8f6fef6a0cbab8c4)", "baseview 0.1.0 (git+https://git.alexjanka.com/alex/baseview?rev=e31a11f1c73c0fdf1463db77105cf9a9b7c9240a)",
"crossbeam", "crossbeam",
"nih_plug", "nih_plug",
"nih_plug_assets", "nih_plug_assets",
@ -3952,6 +3952,12 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "raw-window-handle"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539"
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.10.0" version = "1.10.0"

View file

@ -54,7 +54,14 @@ assert_process_allocs = ["dep:assert_no_alloc"]
# Enables an export target for standalone binaries through the # Enables an export target for standalone binaries through the
# `nih_export_standalone()` function. Disabled by default as this requires # `nih_export_standalone()` function. Disabled by default as this requires
# building additional dependencies for audio and MIDI handling. # building additional dependencies for audio and MIDI handling.
standalone = ["dep:baseview", "dep:clap", "dep:cpal", "dep:jack", "dep:midir", "dep:rtrb"] standalone = [
"dep:baseview",
"dep:clap",
"dep:cpal",
"dep:jack",
"dep:midir",
"dep:rtrb",
]
# Enables the `nih_export_vst3!()` macro. Enabled by default. This feature # Enables the `nih_export_vst3!()` macro. Enabled by default. This feature
# exists mostly for GPL-compliance reasons, since even if you don't use the VST3 # exists mostly for GPL-compliance reasons, since even if you don't use the VST3
# wrapper you might otherwise still include a couple (unused) symbols from the # wrapper you might otherwise still include a couple (unused) symbols from the
@ -89,20 +96,28 @@ log = { version = "0.4", features = ["std", "release_max_level_info"] }
midi-consts = "0.1" midi-consts = "0.1"
nih_log = "0.3.1" nih_log = "0.3.1"
parking_lot = "0.12" parking_lot = "0.12"
raw-window-handle = "0.5" raw-window-handle = "0.6"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
widestring = "1.0.0-beta.1" widestring = "1.0.0-beta.1"
# Used for the `assert_process_allocs` feature # Used for the `assert_process_allocs` feature
assert_no_alloc = { git = "https://github.com/robbert-vdh/rust-assert-no-alloc.git", branch = "feature/nested-permit-forbid", features = ["backtrace", "log"], optional = true } assert_no_alloc = { git = "https://github.com/robbert-vdh/rust-assert-no-alloc.git", branch = "feature/nested-permit-forbid", features = [
"backtrace",
"log",
], optional = true }
# Used for the `standalone` feature # Used for the `standalone` feature
# NOTE: OpenGL support is not needed here, but rust-analyzer gets confused when # NOTE: OpenGL support is not needed here, but rust-analyzer gets confused when
# some crates do use it and others don't # some crates do use it and others don't
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "579130ecb4f9f315ae52190af42f0ea46aeaa4a2", features = ["opengl"], optional = true } baseview = { git = "https://git.alexjanka.com/alex/baseview", rev = "e31a11f1c73c0fdf1463db77105cf9a9b7c9240a", features = [
"opengl",
], optional = true }
# All the claps! # All the claps!
clap = { version = "4.1.8", features = ["derive", "wrap_help"], optional = true } clap = { version = "4.1.8", features = [
"derive",
"wrap_help",
], optional = true }
cpal = { version = "0.15", optional = true } cpal = { version = "0.15", optional = true }
jack = { version = "0.11.4", optional = true } jack = { version = "0.11.4", optional = true }
midir = { version = "0.9.1", optional = true } midir = { version = "0.9.1", optional = true }

View file

@ -17,8 +17,8 @@ rayon = ["egui-baseview/rayon"]
[dependencies] [dependencies]
nih_plug = { path = "..", default-features = false } nih_plug = { path = "..", default-features = false }
raw-window-handle = "0.5" raw-window-handle = "0.6.2"
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "45465c5f46abed6c6ce370fffde5edc8e4cd5aa3" } baseview = { git = "https://git.alexjanka.com/alex/baseview", rev = "e31a11f1c73c0fdf1463db77105cf9a9b7c9240a" }
crossbeam = "0.8" crossbeam = "0.8"
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "68c4d0e8e5c1c702a888a245f4ac50eddfdfcaed", default-features = false } egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "68c4d0e8e5c1c702a888a245f4ac50eddfdfcaed", default-features = false }
parking_lot = "0.12" parking_lot = "0.12"

View file

@ -61,10 +61,10 @@ nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }
# The currently targeted version of baseview uses a different version of # 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` than NIH-plug, so we need to manually convert between them
raw-window-handle = "0.4" raw-window-handle = "0.6.2"
atomic_refcell = "0.1" atomic_refcell = "0.1"
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" } baseview = { git = "https://git.alexjanka.com/alex/baseview", rev = "e31a11f1c73c0fdf1463db77105cf9a9b7c9240a" }
crossbeam = "0.8" crossbeam = "0.8"
# This targets iced 0.4 # This targets iced 0.4
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 }

View file

@ -11,10 +11,14 @@ description = "An adapter to use VIZIA GUIs with NIH-plug"
nih_plug = { path = "..", default-features = false } nih_plug = { path = "..", default-features = false }
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" }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "2c1b1a7b0fef1a29a5150a6a8f6fef6a0cbab8c4" } baseview = { git = "https://git.alexjanka.com/alex/baseview", rev = "e31a11f1c73c0fdf1463db77105cf9a9b7c9240a" }
# This contains an as of writing not yet merged patch for rounding errors when # This contains an as of writing not yet merged patch for rounding errors when
# resizing, and a workaround for certain events not firing when resizing # resizing, and a workaround for certain events not firing when resizing
vizia = { git = "https://github.com/robbert-vdh/vizia.git", tag = "patched-2024-05-06", default-features = false, features = ["baseview", "clipboard", "x11"] } vizia = { git = "https://github.com/robbert-vdh/vizia.git", tag = "patched-2024-05-06", default-features = false, features = [
"baseview",
"clipboard",
"x11",
] }
crossbeam = "0.8" crossbeam = "0.8"
# To make the state persistable # To make the state persistable

View file

@ -1,6 +1,6 @@
//! Traits for working with plugin editors. //! Traits for working with plugin editors.
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use raw_window_handle::{HasWindowHandle, RawWindowHandle, WindowHandle};
use std::any::Any; use std::any::Any;
use std::ffi::c_void; use std::ffi::c_void;
use std::sync::Arc; use std::sync::Arc;
@ -90,24 +90,33 @@ pub enum ParentWindowHandle {
Win32Hwnd(*mut c_void), Win32Hwnd(*mut c_void),
} }
unsafe impl HasRawWindowHandle for ParentWindowHandle { impl HasWindowHandle for ParentWindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle { fn window_handle(
match *self { &self,
) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
Ok(unsafe {
WindowHandle::borrow_raw(match *self {
ParentWindowHandle::X11Window(window) => { ParentWindowHandle::X11Window(window) => {
let mut handle = raw_window_handle::XcbWindowHandle::empty(); RawWindowHandle::Xcb(raw_window_handle::XcbWindowHandle::new(
handle.window = window; window
RawWindowHandle::Xcb(handle) .try_into()
.map_err(|_| raw_window_handle::HandleError::Unavailable)?,
))
} }
ParentWindowHandle::AppKitNsView(ns_view) => { ParentWindowHandle::AppKitNsView(ns_view) => {
let mut handle = raw_window_handle::AppKitWindowHandle::empty(); RawWindowHandle::AppKit(raw_window_handle::AppKitWindowHandle::new(
handle.ns_view = ns_view; std::ptr::NonNull::new(ns_view)
RawWindowHandle::AppKit(handle) .ok_or(raw_window_handle::HandleError::Unavailable)?,
))
} }
ParentWindowHandle::Win32Hwnd(hwnd) => { ParentWindowHandle::Win32Hwnd(hwnd) => {
let mut handle = raw_window_handle::Win32WindowHandle::empty(); RawWindowHandle::Win32(raw_window_handle::Win32WindowHandle::new(
handle.hwnd = hwnd; (hwnd as isize)
RawWindowHandle::Win32(handle) .try_into()
} .map_err(|_| raw_window_handle::HandleError::Unavailable)?,
} ))
}
})
})
} }
} }

View file

@ -3,7 +3,7 @@ use baseview::{EventStatus, Window, WindowHandler, WindowOpenOptions};
use crossbeam::channel::{self, Sender}; use crossbeam::channel::{self, Sender};
use crossbeam::queue::ArrayQueue; use crossbeam::queue::ArrayQueue;
use parking_lot::Mutex; use parking_lot::Mutex;
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasWindowHandle;
use std::any::Any; use std::any::Any;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
@ -345,18 +345,20 @@ impl<P: Plugin, B: Backend<P>> Wrapper<P, B> {
gl_config: None, gl_config: None,
}, },
move |window| { move |window| {
let parent_handle = match window.raw_window_handle() { let parent_handle = match window.window_handle().unwrap().as_raw() {
raw_window_handle::RawWindowHandle::Xlib(handle) => { raw_window_handle::RawWindowHandle::Xlib(handle) => {
ParentWindowHandle::X11Window(handle.window as u32) ParentWindowHandle::X11Window(handle.window as u32)
} }
raw_window_handle::RawWindowHandle::Xcb(handle) => { raw_window_handle::RawWindowHandle::Xcb(handle) => {
ParentWindowHandle::X11Window(handle.window) ParentWindowHandle::X11Window(handle.window.into())
} }
raw_window_handle::RawWindowHandle::AppKit(handle) => { raw_window_handle::RawWindowHandle::AppKit(handle) => {
ParentWindowHandle::AppKitNsView(handle.ns_view) ParentWindowHandle::AppKitNsView(handle.ns_view.as_ptr())
} }
raw_window_handle::RawWindowHandle::Win32(handle) => { raw_window_handle::RawWindowHandle::Win32(handle) => {
ParentWindowHandle::Win32Hwnd(handle.hwnd) ParentWindowHandle::Win32Hwnd(
handle.hwnd.get() as *mut core::ffi::c_void
)
} }
handle => unimplemented!("Unsupported window handle: {handle:?}"), handle => unimplemented!("Unsupported window handle: {handle:?}"),
}; };