gpui: Remove unneeded weak Rc cycle in WindowsWindowInner (#42119)

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-11-06 17:33:09 +00:00
committed by GitHub
parent bf8864d106
commit a7fac65d62
2 changed files with 42 additions and 41 deletions
+40 -39
View File
@@ -61,7 +61,6 @@ pub struct WindowsWindowState {
pub(crate) struct WindowsWindowInner {
hwnd: HWND,
pub(super) this: Weak<Self>,
drop_target_helper: IDropTargetHelper,
pub(crate) state: RefCell<WindowsWindowState>,
pub(crate) system_settings: RefCell<WindowsSystemSettings>,
@@ -215,9 +214,8 @@ impl WindowsWindowInner {
context.disable_direct_composition,
)?);
Ok(Rc::new_cyclic(|this| Self {
Ok(Rc::new(Self {
hwnd,
this: this.clone(),
drop_target_helper: context.drop_target_helper.clone(),
state,
handle: context.handle,
@@ -232,11 +230,8 @@ impl WindowsWindowInner {
}))
}
fn toggle_fullscreen(&self) {
let Some(this) = self.this.upgrade() else {
log::error!("Unable to toggle fullscreen: window has been dropped");
return;
};
fn toggle_fullscreen(self: &Rc<Self>) {
let this = self.clone();
self.executor
.spawn(async move {
let mut lock = this.state.borrow_mut();
@@ -246,36 +241,42 @@ impl WindowsWindowInner {
y,
cx,
cy,
} = if let Some(state) = lock.fullscreen.take() {
state
} else {
let (window_bounds, _) = lock.calculate_window_bounds();
lock.fullscreen_restore_bounds = window_bounds;
let style = WINDOW_STYLE(unsafe { get_window_long(this.hwnd, GWL_STYLE) } as _);
let mut rc = RECT::default();
unsafe { GetWindowRect(this.hwnd, &mut rc) }
.context("failed to get window rect")
.log_err();
let _ = lock.fullscreen.insert(StyleAndBounds {
style,
x: rc.left,
y: rc.top,
cx: rc.right - rc.left,
cy: rc.bottom - rc.top,
});
let style = style
& !(WS_THICKFRAME
| WS_SYSMENU
| WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
| WS_CAPTION);
let physical_bounds = lock.display.physical_bounds();
StyleAndBounds {
style,
x: physical_bounds.left().0,
y: physical_bounds.top().0,
cx: physical_bounds.size.width.0,
cy: physical_bounds.size.height.0,
} = match lock.fullscreen.take() {
Some(state) => state,
None => {
let (window_bounds, _) = lock.calculate_window_bounds();
lock.fullscreen_restore_bounds = window_bounds;
drop(lock);
let style =
WINDOW_STYLE(unsafe { get_window_long(this.hwnd, GWL_STYLE) } as _);
let mut rc = RECT::default();
unsafe { GetWindowRect(this.hwnd, &mut rc) }
.context("failed to get window rect")
.log_err();
lock = this.state.borrow_mut();
let _ = lock.fullscreen.insert(StyleAndBounds {
style,
x: rc.left,
y: rc.top,
cx: rc.right - rc.left,
cy: rc.bottom - rc.top,
});
let style = style
& !(WS_THICKFRAME
| WS_SYSMENU
| WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
| WS_CAPTION);
let physical_bounds = lock.display.physical_bounds();
StyleAndBounds {
style,
x: physical_bounds.left().0,
y: physical_bounds.top().0,
cx: physical_bounds.size.width.0,
cy: physical_bounds.size.height.0,
}
}
};
drop(lock);
@@ -296,7 +297,7 @@ impl WindowsWindowInner {
.detach();
}
fn set_window_placement(&self) -> Result<()> {
fn set_window_placement(self: &Rc<Self>) -> Result<()> {
let Some(open_status) = self.state.borrow_mut().initial_placement.take() else {
return Ok(());
};