diff --git a/Cargo.lock b/Cargo.lock index 3481aedc..b9f94530 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2919,6 +2919,7 @@ dependencies = [ "lazy_static", "nih_plug", "parking_lot 0.12.1", + "raw-window-handle 0.4.3", "serde", ] diff --git a/nih_plug_egui/Cargo.toml b/nih_plug_egui/Cargo.toml index a91625fc..848686be 100644 --- a/nih_plug_egui/Cargo.toml +++ b/nih_plug_egui/Cargo.toml @@ -19,6 +19,10 @@ opengl = [] [dependencies] nih_plug = { path = ".." } +# 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" + baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" } crossbeam = "0.8" # The `egui-default-features` feature enables the default features. This makes diff --git a/nih_plug_egui/src/editor.rs b/nih_plug_egui/src/editor.rs index 1e627c3b..276de167 100644 --- a/nih_plug_egui/src/editor.rs +++ b/nih_plug_egui/src/editor.rs @@ -7,6 +7,7 @@ use egui::Context; use egui_baseview::EguiWindow; use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle}; use parking_lot::RwLock; +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -28,6 +29,32 @@ pub(crate) struct EguiEditor { pub(crate) scaling_factor: AtomicCell>, } +/// 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 EguiEditor where T: 'static + Send + Sync, @@ -44,7 +71,7 @@ where let (unscaled_width, unscaled_height) = self.egui_state.size(); let scaling_factor = self.scaling_factor.load(); let window = EguiWindow::open_parented( - &parent, + &ParentWindowHandleAdapter(parent), WindowOpenOptions { title: String::from("egui window"), // Baseview should be doing the DPI scaling for us