Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Revert "gpui: Fix `RefCell already borrowed` in `WindowsPlatform::run`" (#42481)
Lukas Wirth854c6873c799
diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rsindex cc17f19bcfa..4e6df63106f 100644--- a/crates/gpui/src/platform/windows/events.rs+++ b/crates/gpui/src/platform/windows/events.rs@@ -487,12 +487,14 @@ impl WindowsWindowInner {let scale_factor = lock.scale_factor;let wheel_scroll_amount = match modifiers.shift {true => {- self.system_settings()+ self.system_settings+ .borrow().mouse_wheel_settings.wheel_scroll_chars}false => {- self.system_settings()+ self.system_settings+ .borrow().mouse_wheel_settings.wheel_scroll_lines}@@ -539,7 +541,8 @@ impl WindowsWindowInner {};let scale_factor = lock.scale_factor;let wheel_scroll_chars = self- .system_settings()+ .system_settings+ .borrow().mouse_wheel_settings.wheel_scroll_chars;drop(lock);@@ -674,7 +677,8 @@ impl WindowsWindowInner {// used by Chrome. However, it may result in one row of pixels being obscured// in our client area. But as Chrome says, "there seems to be no better solution."if is_maximized- && let Some(ref taskbar_position) = self.system_settings().auto_hide_taskbar_position+ && let Some(ref taskbar_position) =+ self.system_settings.borrow().auto_hide_taskbar_position{// For the auto-hide taskbar, adjust in by 1 pixel on taskbar edge,// so the window isn't treated as a "fullscreen app", which would cause@@ -1068,7 +1072,7 @@ impl WindowsWindowInner {lock.border_offset.update(handle).log_err();// system settings may emit a window message which wants to take the refcell lock, so drop itdrop(lock);- self.system_settings_mut().update(display, wparam.0);+ self.system_settings.borrow_mut().update(display, wparam.0);} else {self.handle_system_theme_changed(handle, lparam)?;};diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rsindex 72f427beb55..b985cc14b01 100644--- a/crates/gpui/src/platform/windows/platform.rs+++ b/crates/gpui/src/platform/windows/platform.rs@@ -342,8 +342,9 @@ impl Platform for WindowsPlatform {}}- self.inner- .with_callback(|callbacks| &mut callbacks.quit, |callback| callback());+ if let Some(ref mut callback) = self.inner.state.borrow_mut().callbacks.quit {+ callback();+ }}fn quit(&self) {@@ -577,13 +578,14 @@ impl Platform for WindowsPlatform {fn set_cursor_style(&self, style: CursorStyle) {let hcursor = load_cursor(style);- if self.inner.state.borrow_mut().current_cursor.map(|c| c.0) != hcursor.map(|c| c.0) {+ let mut lock = self.inner.state.borrow_mut();+ if lock.current_cursor.map(|c| c.0) != hcursor.map(|c| c.0) {self.post_message(WM_GPUI_CURSOR_STYLE_CHANGED,WPARAM(0),LPARAM(hcursor.map_or(0, |c| c.0 as isize)),);- self.inner.state.borrow_mut().current_cursor = hcursor;+ lock.current_cursor = hcursor;}}@@ -722,18 +724,6 @@ impl WindowsPlatformInner {}))}- /// Calls `project` to project to the corresponding callback field, removes it from callbacks, calls `f` with the callback and then puts the callback back.- fn with_callback<T>(- &self,- project: impl Fn(&mut PlatformCallbacks) -> &mut Option<T>,- f: impl FnOnce(&mut T),- ) {- if let Some(mut callback) = project(&mut self.state.borrow_mut().callbacks).take() {- f(&mut callback);- *project(&mut self.state.borrow_mut().callbacks) = Some(callback)- }- }-fn handle_msg(self: &Rc<Self>,handle: HWND,@@ -817,36 +807,40 @@ impl WindowsPlatformInner {}fn handle_dock_action_event(&self, action_idx: usize) -> Option<isize> {- let Some(action) = self- .state- .borrow_mut()+ let mut lock = self.state.borrow_mut();+ let mut callback = lock.callbacks.app_menu_action.take()?;+ let Some(action) = lock.jump_list.dock_menus.get(action_idx).map(|dock_menu| dock_menu.action.boxed_clone())else {+ lock.callbacks.app_menu_action = Some(callback);log::error!("Dock menu for index {action_idx} not found");return Some(1);};- self.with_callback(- |callbacks| &mut callbacks.app_menu_action,- |callback| callback(&*action),- );+ drop(lock);+ callback(&*action);+ self.state.borrow_mut().callbacks.app_menu_action = Some(callback);Some(0)}fn handle_keyboard_layout_change(&self) -> Option<isize> {- self.with_callback(- |callbacks| &mut callbacks.keyboard_layout_change,- |callback| callback(),- );+ let mut callback = self+ .state+ .borrow_mut()+ .callbacks+ .keyboard_layout_change+ .take()?;+ callback();+ self.state.borrow_mut().callbacks.keyboard_layout_change = Some(callback);Some(0)}fn handle_device_lost(&self, lparam: LPARAM) -> Option<isize> {+ let mut lock = self.state.borrow_mut();let directx_devices = lparam.0 as *const DirectXDevices;let directx_devices = unsafe { &*directx_devices };- let mut lock = self.state.borrow_mut();lock.directx_devices.take();lock.directx_devices = Some(directx_devices.clone());diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rsindex 4b89fcffb39..0050fa4bc0e 100644--- a/crates/gpui/src/platform/windows/window.rs+++ b/crates/gpui/src/platform/windows/window.rs@@ -63,7 +63,7 @@ pub(crate) struct WindowsWindowInner {hwnd: HWND,drop_target_helper: IDropTargetHelper,pub(crate) state: RefCell<WindowsWindowState>,- system_settings: RefCell<WindowsSystemSettings>,+ pub(crate) system_settings: RefCell<WindowsSystemSettings>,pub(crate) handle: AnyWindowHandle,pub(crate) hide_title_bar: bool,pub(crate) is_movable: bool,@@ -321,14 +321,6 @@ impl WindowsWindowInner {}Ok(())}-- pub(crate) fn system_settings(&self) -> std::cell::Ref<'_, WindowsSystemSettings> {- self.system_settings.borrow()- }-- pub(crate) fn system_settings_mut(&self) -> std::cell::RefMut<'_, WindowsSystemSettings> {- self.system_settings.borrow_mut()- }}#[derive(Default)]