Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix error prompt darkened background exceeding window boundaries on Linux (#57608)

Albert Bogusz112d16057c77
diff --git a/Cargo.lock b/Cargo.lock
index 6728dadcf8c..9fb85c94da1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19505,6 +19505,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 cf4203dc763..ab49877c6bb 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<T: Styled> 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 9bcce107f3f..b8425a1a661 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 92b1c9e74dc..33b72deedf5 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 248a554c187..870060d2ba4 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,
@@ -10686,6 +10686,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),
@@ -10701,34 +10707,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)
})
@@ -10783,34 +10762,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))