From d0f806456cae55c6e9695427d0efc57b47568b78 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 16 Apr 2025 00:47:00 +0800 Subject: [PATCH] gpui: Fix `snap_to_window_with_margin` when window has client inset (#27330) Release Notes: - Fixed popup menu snap to window to leave margin on Linux. This change to continue #17159 to fix same thing on Linux. | Before | After | | -- | -- | | ![Pasted image](https://github.com/user-attachments/assets/3129d42c-7253-4a3f-a428-86e2a3df38ff) | ![image](https://github.com/user-attachments/assets/8dc83377-9df7-45ba-805b-1cfdea612ae0) | --- crates/gpui/src/elements/anchored.rs | 6 ++++-- crates/gpui/src/window.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/elements/anchored.rs b/crates/gpui/src/elements/anchored.rs index 2e33f138b9b9dff30f7daffc26f6cb75dc07d812..05aa22c15eec82bd1b1a1c6e4e14380e4a03fce4 100644 --- a/crates/gpui/src/elements/anchored.rs +++ b/crates/gpui/src/elements/anchored.rs @@ -3,7 +3,7 @@ use taffy::style::{Display, Position}; use crate::{ AnyElement, App, Axis, Bounds, Corner, Edges, Element, GlobalElementId, IntoElement, LayoutId, - ParentElement, Pixels, Point, Size, Style, Window, point, + ParentElement, Pixels, Point, Size, Style, Window, point, px, }; /// The state that the anchored element element uses to track its children. @@ -175,10 +175,12 @@ impl Element for Anchored { } } + let client_inset = window.client_inset.unwrap_or(px(0.)); let edges = match self.fit_mode { AnchoredFitMode::SnapToWindowWithMargin(edges) => edges, _ => Edges::default(), - }; + } + .map(|edge| *edge + client_inset); // Snap the horizontal edges of the anchored element to the horizontal edges of the window if // its horizontal bounds overflow, aligning to the left if it is wider than the limits. diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index de044ea9dff9313778024cf266d0f3b4183f8d80..bfb0f46161f53691f5eef2c687d818b4ba5e686c 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -646,6 +646,7 @@ pub struct Window { pending_modifier: ModifierState, pub(crate) pending_input_observers: SubscriberSet<(), AnyObserver>, prompt: Option, + pub(crate) client_inset: Option, } #[derive(Clone, Debug, Default)] @@ -931,6 +932,7 @@ impl Window { pending_modifier: ModifierState::default(), pending_input_observers: SubscriberSet::new(), prompt: None, + client_inset: None, }) } @@ -1387,10 +1389,16 @@ impl Window { } /// When using client side decorations, set this to the width of the invisible decorations (Wayland and X11) - pub fn set_client_inset(&self, inset: Pixels) { + pub fn set_client_inset(&mut self, inset: Pixels) { + self.client_inset = Some(inset); self.platform_window.set_client_inset(inset); } + /// Returns the client_inset value by [`Self::set_client_inset`]. + pub fn client_inset(&self) -> Option { + self.client_inset + } + /// Returns whether the title bar window controls need to be rendered by the application (Wayland and X11) pub fn window_decorations(&self) -> Decorations { self.platform_window.window_decorations()