Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use nih_plug::prelude::{Editor, GuiContext, ParamSetter};
use serde_json::Value;
use std::{
borrow::Cow,
cell::RefCell,
sync::{
atomic::{AtomicU32, Ordering},
Arc,
Expand Down Expand Up @@ -115,6 +116,8 @@ pub struct WindowHandler {
events_receiver: Receiver<Value>,
pub width: Arc<AtomicU32>,
pub height: Arc<AtomicU32>,
// GUI-thread only resize queue - uses RefCell instead of Mutex since it never crosses threads
pending_resizes: RefCell<Vec<(u32, u32)>>,
}

impl WindowHandler {
Expand All @@ -134,6 +137,28 @@ impl WindowHandler {
});
}

/// Queue a resize request to be processed later
/// This allows deferring resize operations to avoid borrow checker conflicts
pub fn queue_resize(&self, width: u32, height: u32) {
self.pending_resizes.borrow_mut().push((width, height));
}

/// Process any pending resize requests
/// Returns the size that was applied, if any
pub fn process_pending_resizes(&self, window: &mut baseview::Window) -> Option<(u32, u32)> {
let mut queue = self.pending_resizes.borrow_mut();
if let Some((width, height)) = queue.pop() {
// Only process the most recent resize request to avoid lag
queue.clear();
drop(queue); // Release the borrow before calling resize

self.resize(window, width, height);
Some((width, height))
} else {
None
}
}

pub fn send_json(&self, json: Value) {
let json_str = json.to_string();
let json_str_quoted =
Expand Down Expand Up @@ -255,6 +280,7 @@ impl Editor for WebViewEditor {
mouse_handler,
width,
height,
pending_resizes: RefCell::new(Vec::new()),
}
});
return Box::new(Instance { window_handle });
Expand Down