refactor: popup dropping path

This commit is contained in:
drendog 2025-11-27 10:40:09 +01:00
parent 5e7c53252b
commit c2d5b7ed12
Signed by: dwenya
GPG key ID: 8DD77074645332D0
7 changed files with 35 additions and 25 deletions

7
Cargo.lock generated
View file

@ -1866,7 +1866,6 @@ dependencies = [
"layer-shika-domain", "layer-shika-domain",
"log", "log",
"raw-window-handle", "raw-window-handle",
"slab",
"slint", "slint",
"slint-interpreter", "slint-interpreter",
"smithay-client-toolkit 0.20.0", "smithay-client-toolkit 0.20.0",
@ -3329,12 +3328,12 @@ dependencies = [
[[package]] [[package]]
name = "smithay-clipboard" name = "smithay-clipboard"
version = "0.7.2" version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc8216eec463674a0e90f29e0ae41a4db573ec5b56b1c6c1c71615d249b6d846" checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
dependencies = [ dependencies = [
"libc", "libc",
"smithay-client-toolkit 0.19.2", "smithay-client-toolkit 0.20.0",
"wayland-backend", "wayland-backend",
] ]

View file

@ -36,7 +36,6 @@ glutin = { version = "0.32.3", default-features = false, features = [
spin_on = "0.1" spin_on = "0.1"
log = "0.4.28" log = "0.4.28"
raw-window-handle = "0.6.2" raw-window-handle = "0.6.2"
slab = "0.4"
slint = { version = "1.14.1", default-features = false, features = [ slint = { version = "1.14.1", default-features = false, features = [
"compat-1-2", "compat-1-2",
"renderer-femtovg", "renderer-femtovg",

View file

@ -18,7 +18,6 @@ glutin.workspace = true
layer-shika-domain.workspace = true layer-shika-domain.workspace = true
log.workspace = true log.workspace = true
raw-window-handle.workspace = true raw-window-handle.workspace = true
slab.workspace = true
slint.workspace = true slint.workspace = true
slint-interpreter.workspace = true slint-interpreter.workspace = true
smithay-client-toolkit.workspace = true smithay-client-toolkit.workspace = true

View file

@ -131,7 +131,7 @@ impl Drop for EGLContext {
if let Err(e) = self.context.make_not_current_in_place() { if let Err(e) = self.context.make_not_current_in_place() {
log::error!("Failed to make EGL context not current during cleanup: {e}"); log::error!("Failed to make EGL context not current during cleanup: {e}");
} else { } else {
log::debug!("Successfully made EGL context not current during cleanup"); log::info!("Successfully made EGL context not current during cleanup");
} }
} }
} }

View file

@ -9,7 +9,7 @@ use slint::{
platform::{Renderer, WindowAdapter, WindowEvent, femtovg_renderer::FemtoVGRenderer}, platform::{Renderer, WindowAdapter, WindowEvent, femtovg_renderer::FemtoVGRenderer},
}; };
use slint_interpreter::ComponentInstance; use slint_interpreter::ComponentInstance;
use std::cell::{Cell, OnceCell}; use std::cell::{Cell, OnceCell, RefCell};
use std::rc::{Rc, Weak}; use std::rc::{Rc, Weak};
pub struct PopupWindow { pub struct PopupWindow {
@ -21,7 +21,7 @@ pub struct PopupWindow {
popup_handle: Cell<Option<PopupHandle>>, popup_handle: Cell<Option<PopupHandle>>,
on_close: OnceCell<OnCloseCallback>, on_close: OnceCell<OnCloseCallback>,
configured: Cell<bool>, configured: Cell<bool>,
component_instance: OnceCell<ComponentInstance>, component_instance: RefCell<Option<ComponentInstance>>,
} }
impl PopupWindow { impl PopupWindow {
@ -38,7 +38,7 @@ impl PopupWindow {
popup_handle: Cell::new(None), popup_handle: Cell::new(None),
on_close: OnceCell::new(), on_close: OnceCell::new(),
configured: Cell::new(false), configured: Cell::new(false),
component_instance: OnceCell::new(), component_instance: RefCell::new(None),
} }
}) })
} }
@ -54,13 +54,26 @@ impl PopupWindow {
self.popup_handle.set(Some(handle)); self.popup_handle.set(Some(handle));
} }
pub fn close_popup(&self) { pub(crate) fn cleanup_resources(&self) {
info!("Closing popup window - cleaning up resources"); info!("Cleaning up popup window resources to break reference cycles");
if let Err(e) = self.window.hide() { if let Err(e) = self.window.hide() {
info!("Failed to hide popup window: {e}"); info!("Failed to hide popup window: {e}");
} }
if let Some(component) = self.component_instance.borrow_mut().take() {
info!("Dropping ComponentInstance to break reference cycle");
drop(component);
}
info!("Popup window resource cleanup complete");
}
pub fn close_popup(&self) {
info!("Closing popup window - cleaning up resources");
self.cleanup_resources();
if let Some(handle) = self.popup_handle.get() { if let Some(handle) = self.popup_handle.get() {
info!("Destroying popup with handle {:?}", handle); info!("Destroying popup with handle {:?}", handle);
if let Some(on_close) = self.on_close.get() { if let Some(on_close) = self.on_close.get() {
@ -88,9 +101,11 @@ impl PopupWindow {
pub fn set_component_instance(&self, instance: ComponentInstance) { pub fn set_component_instance(&self, instance: ComponentInstance) {
info!("Setting component instance for popup window"); info!("Setting component instance for popup window");
if self.component_instance.set(instance).is_err() { let mut comp = self.component_instance.borrow_mut();
info!("Component instance already set for popup window"); if comp.is_some() {
info!("Component instance already set for popup window - replacing");
} }
*comp = Some(instance);
} }
pub fn request_resize(&self, width: f32, height: f32) { pub fn request_resize(&self, width: f32, height: f32) {
@ -177,6 +192,13 @@ impl Deref for PopupWindow {
impl Drop for PopupWindow { impl Drop for PopupWindow {
fn drop(&mut self) { fn drop(&mut self) {
info!("PopupWindow being dropped - resources will be released"); info!("PopupWindow being dropped - cleaning up resources");
if let Some(component) = self.component_instance.borrow_mut().take() {
info!("Dropping any remaining ComponentInstance in PopupWindow::drop");
drop(component);
}
info!("PopupWindow drop complete");
} }
} }

View file

@ -144,15 +144,6 @@ impl AppState {
self.output_mapping.get(output_id) self.output_mapping.get(output_id)
} }
pub fn register_popup_surface(
&mut self,
popup_surface_id: ObjectId,
output_handle: OutputHandle,
) {
self.surface_to_output
.insert(popup_surface_id, output_handle);
}
pub fn set_active_output_handle(&mut self, handle: Option<OutputHandle>) { pub fn set_active_output_handle(&mut self, handle: Option<OutputHandle>) {
self.output_registry.set_active(handle); self.output_registry.set_active(handle);
} }

View file

@ -425,7 +425,7 @@ impl PopupManager {
fn destroy_popup(&self, id: PopupId) { fn destroy_popup(&self, id: PopupId) {
if let Some(popup) = self.state.borrow_mut().popups.remove(&id) { if let Some(popup) = self.state.borrow_mut().popups.remove(&id) {
info!("Destroying popup with id {:?}", id); info!("Destroying popup with id {:?}", id);
popup.window.cleanup_resources();
popup.surface.destroy(); popup.surface.destroy();
} }
} }