diff --git a/Cargo.lock b/Cargo.lock index c60f0d7dcf4f87..5e40b5a4a107df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19236,6 +19236,7 @@ dependencies = [ "markdown", "menu", "settings", + "theme", "theme_settings", "ui", "workspace", diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index cf4203dc763a6b..ab49877c6bb961 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -25,7 +25,8 @@ use std::sync::Arc; use gpui::BorrowAppContext; use gpui::Global; use gpui::{ - App, AssetSource, Hsla, Pixels, SharedString, WindowAppearance, WindowBackgroundAppearance, px, + App, AssetSource, Hsla, Pixels, SharedString, Styled, Tiling, WindowAppearance, + WindowBackgroundAppearance, px, }; use serde::Deserialize; @@ -49,6 +50,28 @@ pub const CLIENT_SIDE_DECORATION_ROUNDING: Pixels = px(10.0); /// Defines window shadow size for platforms that use client side decorations. pub const CLIENT_SIDE_DECORATION_SHADOW: Pixels = px(10.0); +/// Styling helpers for elements that follow client-side window decorations. +pub trait ClientDecorationsExt: Styled { + /// Rounds each corner whose two adjacent edges are both untiled. + fn rounded_client_corners(mut self, tiling: Tiling) -> Self { + if !tiling.top && !tiling.left { + self = self.rounded_tl(CLIENT_SIDE_DECORATION_ROUNDING); + } + if !tiling.top && !tiling.right { + self = self.rounded_tr(CLIENT_SIDE_DECORATION_ROUNDING); + } + if !tiling.bottom && !tiling.left { + self = self.rounded_bl(CLIENT_SIDE_DECORATION_ROUNDING); + } + if !tiling.bottom && !tiling.right { + self = self.rounded_br(CLIENT_SIDE_DECORATION_ROUNDING); + } + self + } +} + +impl ClientDecorationsExt for T {} + /// The appearance of the theme. #[derive(Debug, PartialEq, Clone, Copy, Deserialize)] pub enum Appearance { diff --git a/crates/ui_prompt/Cargo.toml b/crates/ui_prompt/Cargo.toml index 9bcce107f3f7d6..b8425a1a661b53 100644 --- a/crates/ui_prompt/Cargo.toml +++ b/crates/ui_prompt/Cargo.toml @@ -19,6 +19,7 @@ gpui.workspace = true markdown.workspace = true menu.workspace = true settings.workspace = true +theme.workspace = true theme_settings.workspace = true ui.workspace = true workspace.workspace = true diff --git a/crates/ui_prompt/src/ui_prompt.rs b/crates/ui_prompt/src/ui_prompt.rs index 92b1c9e74dcd2f..33b72deedf5fee 100644 --- a/crates/ui_prompt/src/ui_prompt.rs +++ b/crates/ui_prompt/src/ui_prompt.rs @@ -1,10 +1,11 @@ use gpui::{ - App, Entity, EventEmitter, FocusHandle, Focusable, PromptButton, PromptHandle, PromptLevel, - PromptResponse, RenderablePromptHandle, SharedString, TextStyleRefinement, Window, div, - prelude::*, + App, Decorations, Entity, EventEmitter, FocusHandle, Focusable, PromptButton, PromptHandle, + PromptLevel, PromptResponse, RenderablePromptHandle, SharedString, TextStyleRefinement, Window, + div, prelude::*, }; use markdown::{Markdown, MarkdownElement, MarkdownStyle}; use settings::{Settings, SettingsStore}; +use theme::ClientDecorationsExt; use theme_settings::ThemeSettings; use ui::{FluentBuilder, TintColor, prelude::*}; use workspace::WorkspaceSettings; @@ -154,20 +155,28 @@ impl Render for ZedPromptRenderer { })), ); - div() - .size_full() - .occlude() - .bg(gpui::black().opacity(0.2)) - .child( - v_flex() - .size_full() - .absolute() - .top_0() - .left_0() - .items_center() - .justify_center() - .child(dialog), - ) + let decorations = window.window_decorations(); + let inset = window.client_inset().unwrap_or(Pixels::ZERO); + + div().size_full().child( + v_flex() + .occlude() + .absolute() + .inset_0() + .bg(gpui::black().opacity(0.2)) + .map(|this| match decorations { + Decorations::Server => this, + Decorations::Client { tiling } => this + .when(!tiling.top, |this| this.top(inset)) + .when(!tiling.bottom, |this| this.bottom(inset)) + .when(!tiling.left, |this| this.left(inset)) + .when(!tiling.right, |this| this.right(inset)) + .rounded_client_corners(tiling), + }) + .items_center() + .justify_center() + .child(dialog), + ) } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index dbe132add88cee..4bd919f08c2b3f 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -138,7 +138,7 @@ use std::{ time::Duration, }; use task::{DebugScenario, SharedTaskContext, SpawnInTerminal}; -use theme::{ActiveTheme, SystemAppearance}; +use theme::{ActiveTheme, ClientDecorationsExt, SystemAppearance}; use theme_settings::ThemeSettings; pub use toolbar::{ PaneSearchBarCallbacks, Toolbar, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, @@ -10498,6 +10498,12 @@ pub fn client_side_decorations( Decorations::Server => Tiling::default(), Decorations::Client { tiling } => tiling, }; + let corner_tiling = Tiling { + top: tiling.top || border_radius_tiling.top, + bottom: tiling.bottom || border_radius_tiling.bottom, + left: tiling.left || border_radius_tiling.left, + right: tiling.right || border_radius_tiling.right, + }; match decorations { Decorations::Client { .. } => window.set_client_inset(theme::CLIENT_SIDE_DECORATION_SHADOW), @@ -10513,34 +10519,7 @@ pub fn client_side_decorations( .map(|div| match decorations { Decorations::Server => div, Decorations::Client { .. } => div - .when( - !(tiling.top - || tiling.right - || border_radius_tiling.top - || border_radius_tiling.right), - |div| div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.top - || tiling.left - || border_radius_tiling.top - || border_radius_tiling.left), - |div| div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.bottom - || tiling.right - || border_radius_tiling.bottom - || border_radius_tiling.right), - |div| div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.bottom - || tiling.left - || border_radius_tiling.bottom - || border_radius_tiling.left), - |div| div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) + .rounded_client_corners(corner_tiling) .when(!tiling.top, |div| { div.pt(theme::CLIENT_SIDE_DECORATION_SHADOW) }) @@ -10595,34 +10574,7 @@ pub fn client_side_decorations( Decorations::Server => div, Decorations::Client { .. } => div .border_color(cx.theme().colors().border) - .when( - !(tiling.top - || tiling.right - || border_radius_tiling.top - || border_radius_tiling.right), - |div| div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.top - || tiling.left - || border_radius_tiling.top - || border_radius_tiling.left), - |div| div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.bottom - || tiling.right - || border_radius_tiling.bottom - || border_radius_tiling.right), - |div| div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) - .when( - !(tiling.bottom - || tiling.left - || border_radius_tiling.bottom - || border_radius_tiling.left), - |div| div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING), - ) + .rounded_client_corners(corner_tiling) .when(!tiling.top, |div| div.border_t(BORDER_SIZE)) .when(!tiling.bottom, |div| div.border_b(BORDER_SIZE)) .when(!tiling.left, |div| div.border_l(BORDER_SIZE))