From 5ba16f06d596b075a437c12e25ab7b5e5bd67069 Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Sun, 13 Sep 2026 13:01:14 +0200 Subject: [PATCH 1/2] clippy fix --- examples/plugin_clack/Cargo.toml | 4 +- examples/plugin_clack/src/audio.rs | 2 +- examples/plugin_clack/src/gui.rs | 66 +++++++++--------- examples/plugin_clack/src/lib.rs | 20 ++++-- examples/plugin_clack_femtovg/Cargo.toml | 4 +- examples/plugin_clack_femtovg/src/audio.rs | 2 +- examples/plugin_clack_femtovg/src/gui.rs | 79 ++++++++++------------ examples/plugin_clack_femtovg/src/lib.rs | 20 ++++-- 8 files changed, 101 insertions(+), 96 deletions(-) diff --git a/examples/plugin_clack/Cargo.toml b/examples/plugin_clack/Cargo.toml index 13dbf784..2171f35a 100644 --- a/examples/plugin_clack/Cargo.toml +++ b/examples/plugin_clack/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -clack-plugin = "0.1.1" -clack-extensions = { version = "0.1.1", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] } +clack-plugin = "0.2.0" +clack-extensions = { version = "0.2.0", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] } baseview = { path = "../..", features = ["tracing"] } softbuffer = "0.4.8" diff --git a/examples/plugin_clack/src/audio.rs b/examples/plugin_clack/src/audio.rs index b3e34ee4..20b93579 100644 --- a/examples/plugin_clack/src/audio.rs +++ b/examples/plugin_clack/src/audio.rs @@ -5,7 +5,7 @@ pub struct ExamplePluginAudioProcessor; impl<'a> PluginAudioProcessor<'a, (), ExamplePluginMainThread<'a>> for ExamplePluginAudioProcessor { fn activate( - _host: HostAudioProcessorHandle<'a>, _main_thread: &mut ExamplePluginMainThread, + _host: HostAudioProcessorHandle<'a>, _main_thread: &ExamplePluginMainThread, _shared: &'a (), _audio_config: PluginAudioConfiguration, ) -> Result { Ok(Self) diff --git a/examples/plugin_clack/src/gui.rs b/examples/plugin_clack/src/gui.rs index 9b7a6883..c37caf82 100644 --- a/examples/plugin_clack/src/gui.rs +++ b/examples/plugin_clack/src/gui.rs @@ -15,19 +15,19 @@ pub struct ExamplePluginGui { } impl PluginGuiImpl for ExamplePluginMainThread<'_> { - fn is_api_supported(&mut self, configuration: GuiConfiguration) -> bool { + fn is_api_supported(&self, configuration: GuiConfiguration) -> bool { !configuration.is_floating && Some(configuration.api_type) == GuiApiType::default_for_current_platform() } - fn get_preferred_api(&mut self) -> Option> { + fn get_preferred_api(&self) -> Option> { Some(GuiConfiguration { api_type: GuiApiType::default_for_current_platform()?, is_floating: false, }) } - fn create(&mut self, _configuration: GuiConfiguration) -> Result<(), PluginError> { + fn create(&self, _configuration: GuiConfiguration) -> Result<(), PluginError> { let options = WindowSettings::new() .wait_for_parent() .with_size(PhysicalSize::new(400, 200)) @@ -46,43 +46,43 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { let window = Window::create_with_host(options, OpenWindowExample::new, host)?; - self.gui = Some(ExamplePluginGui { handle: window }); + self.gui.replace(Some(ExamplePluginGui { handle: window })); Ok(()) } - fn destroy(&mut self) { + fn destroy(&self) { let Some(gui) = self.gui.take() else { return }; gui.handle.close() } - fn set_scale(&mut self, scale: f64) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_scale(&self, scale: f64) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_scale called without a GUI active")); }; - gui.handle.suggest_fallback_scale_factor(scale)?; + gui.suggest_fallback_scale_factor(scale)?; Ok(()) } - fn get_size(&mut self) -> Option { - let Some(gui) = &self.gui else { + fn get_size(&self) -> Option { + let Some(gui) = self.borrow_window() else { eprintln!("get_size called without a GUI active"); return None; }; - let size = gui.handle.size().to_native_size(); + let size = gui.size().to_native_size(); Some(GuiSize { width: size.width, height: size.height }) } - fn can_resize(&mut self) -> bool { - let Some(gui) = &self.gui else { return false }; + fn can_resize(&self) -> bool { + let Some(gui) = self.borrow_window() else { return false }; - gui.handle.is_resizable() + gui.is_resizable() } - fn get_resize_hints(&mut self) -> Option { + fn get_resize_hints(&self) -> Option { let can_resize = self.can_resize(); Some(GuiResizeHints { @@ -93,60 +93,60 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { }) } - fn adjust_size(&mut self, size: GuiSize) -> Option { - let Some(gui) = &self.gui else { return None }; + fn adjust_size(&self, size: GuiSize) -> Option { + let Some(gui) = self.borrow_window() else { return None }; - let size = gui.handle.adjust_size(NativeSize::new(size.width, size.height)); + let size = gui.adjust_size(NativeSize::new(size.width, size.height)); Some(GuiSize { width: size.width, height: size.height }) } - fn set_size(&mut self, size: GuiSize) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_size(&self, size: GuiSize) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_size called without a GUI active")); }; - gui.handle.resize(NativeSize { width: size.width, height: size.height })?; + gui.resize(NativeSize { width: size.width, height: size.height })?; Ok(()) } - fn set_parent(&mut self, window: ClapWindow) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_parent(&self, window: ClapWindow) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_parent called without a GUI active")); }; // SAFETY: The CLAP spec ensures the parent window handle is valid for at least this call let parent = unsafe { window.borrow_handle_unchecked()? }; - gui.handle.set_parent(&parent)?; - gui.handle.show()?; + gui.set_parent(&parent)?; + gui.show()?; Ok(()) } - fn set_transient(&mut self, _window: ClapWindow) -> Result<(), PluginError> { + fn set_transient(&self, _window: ClapWindow) -> Result<(), PluginError> { unimplemented!() // Not supported yet } - fn suggest_title(&mut self, _title: &str) { + fn suggest_title(&self, _title: &str) { // Not supported yet } - fn show(&mut self) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn show(&self) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("show called without a GUI active")); }; - gui.handle.show()?; + gui.show()?; Ok(()) } - fn hide(&mut self) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn hide(&self) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("hide called without a GUI active")); }; - gui.handle.show()?; + gui.show()?; Ok(()) } diff --git a/examples/plugin_clack/src/lib.rs b/examples/plugin_clack/src/lib.rs index 316f258f..ba52d508 100644 --- a/examples/plugin_clack/src/lib.rs +++ b/examples/plugin_clack/src/lib.rs @@ -4,6 +4,7 @@ use clack_extensions::gui::{HostGui, PluginGui}; use clack_extensions::state::{PluginState, PluginStateImpl}; use clack_plugin::prelude::*; use clack_plugin::stream::{InputStream, OutputStream}; +use std::cell::{Ref, RefCell}; mod audio; mod gui; @@ -39,7 +40,7 @@ impl DefaultPluginFactory for ExamplePlugin { fn new_main_thread<'a>( host: HostMainThreadHandle<'a>, _shared: &'a Self::Shared<'a>, ) -> Result, PluginError> { - Ok(Self::MainThread { gui: None, host_gui: host.get_extension(), host }) + Ok(Self::MainThread { gui: None.into(), host_gui: host.get_extension(), host }) } } @@ -50,23 +51,30 @@ pub struct ExamplePluginMainThread<'a> { // The host GUI extension handle host_gui: Option, /// The plugin's GUI state and context - gui: Option, + gui: RefCell>, +} + +impl<'a> ExamplePluginMainThread<'a> { + fn borrow_window(&self) -> Option> { + let gui = self.gui.borrow(); + gui.is_some().then(|| Ref::map(gui, |g| &g.as_ref().unwrap().handle)) + } } impl<'a> PluginMainThread<'a, ()> for ExamplePluginMainThread<'a> { - fn on_main_thread(&mut self) { - if let Some(gui) = self.gui.as_mut() { + fn on_main_thread(&self) { + if let Some(gui) = self.gui.borrow().as_ref() { gui.handle.host_main_thread_callback(); } } } impl PluginStateImpl for ExamplePluginMainThread<'_> { - fn save(&mut self, _output: &mut OutputStream) -> Result<(), PluginError> { + fn save(&self, _output: &mut OutputStream) -> Result<(), PluginError> { Ok(()) } - fn load(&mut self, _input: &mut InputStream) -> Result<(), PluginError> { + fn load(&self, _input: &mut InputStream) -> Result<(), PluginError> { Ok(()) } } diff --git a/examples/plugin_clack_femtovg/Cargo.toml b/examples/plugin_clack_femtovg/Cargo.toml index 79df56ba..8b7fb7c6 100644 --- a/examples/plugin_clack_femtovg/Cargo.toml +++ b/examples/plugin_clack_femtovg/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -clack-plugin = "0.1.1" -clack-extensions = { version = "0.1.1", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] } +clack-plugin = "0.2.0" +clack-extensions = { version = "0.2.0", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] } baseview = { path = "../..", features = ["opengl", "tracing"] } femtovg = "0.26" raw-window-handle = { version = "0.6.2", features = ["std"] } diff --git a/examples/plugin_clack_femtovg/src/audio.rs b/examples/plugin_clack_femtovg/src/audio.rs index b3e34ee4..20b93579 100644 --- a/examples/plugin_clack_femtovg/src/audio.rs +++ b/examples/plugin_clack_femtovg/src/audio.rs @@ -5,7 +5,7 @@ pub struct ExamplePluginAudioProcessor; impl<'a> PluginAudioProcessor<'a, (), ExamplePluginMainThread<'a>> for ExamplePluginAudioProcessor { fn activate( - _host: HostAudioProcessorHandle<'a>, _main_thread: &mut ExamplePluginMainThread, + _host: HostAudioProcessorHandle<'a>, _main_thread: &ExamplePluginMainThread, _shared: &'a (), _audio_config: PluginAudioConfiguration, ) -> Result { Ok(Self) diff --git a/examples/plugin_clack_femtovg/src/gui.rs b/examples/plugin_clack_femtovg/src/gui.rs index c2a05241..e3fff20d 100644 --- a/examples/plugin_clack_femtovg/src/gui.rs +++ b/examples/plugin_clack_femtovg/src/gui.rs @@ -16,19 +16,19 @@ pub struct ExamplePluginGui { } impl PluginGuiImpl for ExamplePluginMainThread<'_> { - fn is_api_supported(&mut self, configuration: GuiConfiguration) -> bool { + fn is_api_supported(&self, configuration: GuiConfiguration) -> bool { !configuration.is_floating && Some(configuration.api_type) == GuiApiType::default_for_current_platform() } - fn get_preferred_api(&mut self) -> Option> { + fn get_preferred_api(&self) -> Option> { Some(GuiConfiguration { api_type: GuiApiType::default_for_current_platform()?, is_floating: false, }) } - fn create(&mut self, _configuration: GuiConfiguration) -> Result<(), PluginError> { + fn create(&self, _configuration: GuiConfiguration) -> Result<(), PluginError> { let options = WindowSettings::new() .wait_for_parent() .with_size(PhysicalSize::new(400, 200)) @@ -46,43 +46,43 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { let window = Window::create_with_host(options, FemtovgExample::new, host)?; - self.gui = Some(ExamplePluginGui { handle: window }); + self.gui.replace(Some(ExamplePluginGui { handle: window })); Ok(()) } - fn destroy(&mut self) { + fn destroy(&self) { let Some(gui) = self.gui.take() else { return }; gui.handle.close() } - fn set_scale(&mut self, scale: f64) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_scale(&self, scale: f64) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_scale called without a GUI active")); }; - gui.handle.suggest_fallback_scale_factor(scale)?; + gui.suggest_fallback_scale_factor(scale)?; Ok(()) } - fn get_size(&mut self) -> Option { - let Some(gui) = &self.gui else { + fn get_size(&self) -> Option { + let Some(gui) = self.borrow_window() else { eprintln!("get_size called without a GUI active"); return None; }; - let size = gui.handle.size().to_native_size(); + let size = gui.size().to_native_size(); Some(GuiSize { width: size.width, height: size.height }) } - fn can_resize(&mut self) -> bool { - let Some(gui) = &self.gui else { return false }; + fn can_resize(&self) -> bool { + let Some(gui) = self.borrow_window() else { return false }; - gui.handle.is_resizable() + gui.is_resizable() } - fn get_resize_hints(&mut self) -> Option { + fn get_resize_hints(&self) -> Option { let can_resize = self.can_resize(); Some(GuiResizeHints { @@ -93,71 +93,60 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { }) } - fn adjust_size(&mut self, mut size: GuiSize) -> Option { - let Some(gui) = &self.gui else { return None }; - let scale_factor = gui.handle.size().scale_factor; + fn adjust_size(&self, size: GuiSize) -> Option { + let Some(gui) = self.borrow_window() else { return None }; - if let Some(max_size) = gui.handle.max_size() { - let max_size = NativeSize::from_size(max_size, scale_factor); - size.width = size.width.min(max_size.width); - size.height = size.height.min(max_size.height); - } - - if let Some(min_size) = gui.handle.min_size() { - let min_size = NativeSize::from_size(min_size, scale_factor); - size.width = size.width.max(min_size.width); - size.height = size.height.max(min_size.height); - } + let size = gui.adjust_size(NativeSize::new(size.width, size.height)); - Some(size) + Some(GuiSize { width: size.width, height: size.height }) } - fn set_size(&mut self, size: GuiSize) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_size(&self, size: GuiSize) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_size called without a GUI active")); }; - gui.handle.resize(NativeSize { width: size.width, height: size.height })?; + gui.resize(NativeSize { width: size.width, height: size.height })?; Ok(()) } - fn set_parent(&mut self, window: ClapWindow) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn set_parent(&self, window: ClapWindow) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("set_parent called without a GUI active")); }; // SAFETY: The CLAP spec ensures the parent window handle is valid for at least this call let parent = unsafe { window.borrow_handle_unchecked()? }; - gui.handle.set_parent(&parent)?; - gui.handle.show()?; + gui.set_parent(&parent)?; + gui.show()?; Ok(()) } - fn set_transient(&mut self, _window: ClapWindow) -> Result<(), PluginError> { + fn set_transient(&self, _window: ClapWindow) -> Result<(), PluginError> { unimplemented!() // Not supported yet } - fn suggest_title(&mut self, _title: &str) { + fn suggest_title(&self, _title: &str) { // Not supported yet } - fn show(&mut self) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn show(&self) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("show called without a GUI active")); }; - gui.handle.show()?; + gui.show()?; Ok(()) } - fn hide(&mut self) -> Result<(), PluginError> { - let Some(gui) = &self.gui else { + fn hide(&self) -> Result<(), PluginError> { + let Some(gui) = self.borrow_window() else { return Err(PluginError::Message("hide called without a GUI active")); }; - gui.handle.show()?; + gui.show()?; Ok(()) } diff --git a/examples/plugin_clack_femtovg/src/lib.rs b/examples/plugin_clack_femtovg/src/lib.rs index a81ef789..3366f88e 100644 --- a/examples/plugin_clack_femtovg/src/lib.rs +++ b/examples/plugin_clack_femtovg/src/lib.rs @@ -4,6 +4,7 @@ use clack_extensions::gui::{HostGui, PluginGui}; use clack_extensions::state::{PluginState, PluginStateImpl}; use clack_plugin::prelude::*; use clack_plugin::stream::{InputStream, OutputStream}; +use std::cell::{Ref, RefCell}; mod audio; mod gui; @@ -42,7 +43,7 @@ impl DefaultPluginFactory for ExamplePlugin { fn new_main_thread<'a>( host: HostMainThreadHandle<'a>, _shared: &'a Self::Shared<'a>, ) -> Result, PluginError> { - Ok(Self::MainThread { gui: None, host_gui: host.get_extension(), host }) + Ok(Self::MainThread { gui: None.into(), host_gui: host.get_extension(), host }) } } @@ -53,23 +54,30 @@ pub struct ExamplePluginMainThread<'a> { // The host GUI extension handle host_gui: Option, /// The plugin's GUI state and context - gui: Option, + gui: RefCell>, +} + +impl<'a> ExamplePluginMainThread<'a> { + fn borrow_window(&self) -> Option> { + let gui = self.gui.borrow(); + gui.is_some().then(|| Ref::map(gui, |g| &g.as_ref().unwrap().handle)) + } } impl<'a> PluginMainThread<'a, ()> for ExamplePluginMainThread<'a> { - fn on_main_thread(&mut self) { - if let Some(gui) = self.gui.as_mut() { + fn on_main_thread(&self) { + if let Some(gui) = self.gui.borrow().as_ref() { gui.handle.host_main_thread_callback(); } } } impl PluginStateImpl for ExamplePluginMainThread<'_> { - fn save(&mut self, _output: &mut OutputStream) -> Result<(), PluginError> { + fn save(&self, _output: &mut OutputStream) -> Result<(), PluginError> { Ok(()) } - fn load(&mut self, _input: &mut InputStream) -> Result<(), PluginError> { + fn load(&self, _input: &mut InputStream) -> Result<(), PluginError> { Ok(()) } } From 0cd7ea727785e77e0874ce542e6f005a0063ecbb Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Sun, 13 Sep 2026 13:05:03 +0200 Subject: [PATCH 2/2] clippy fix --- examples/plugin_clack/src/gui.rs | 2 +- examples/plugin_clack_femtovg/src/gui.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/plugin_clack/src/gui.rs b/examples/plugin_clack/src/gui.rs index c37caf82..215195b1 100644 --- a/examples/plugin_clack/src/gui.rs +++ b/examples/plugin_clack/src/gui.rs @@ -94,7 +94,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { } fn adjust_size(&self, size: GuiSize) -> Option { - let Some(gui) = self.borrow_window() else { return None }; + let gui = self.borrow_window()?; let size = gui.adjust_size(NativeSize::new(size.width, size.height)); diff --git a/examples/plugin_clack_femtovg/src/gui.rs b/examples/plugin_clack_femtovg/src/gui.rs index e3fff20d..41ab05a1 100644 --- a/examples/plugin_clack_femtovg/src/gui.rs +++ b/examples/plugin_clack_femtovg/src/gui.rs @@ -94,7 +94,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> { } fn adjust_size(&self, size: GuiSize) -> Option { - let Some(gui) = self.borrow_window() else { return None }; + let gui = self.borrow_window()?; let size = gui.adjust_size(NativeSize::new(size.width, size.height));