Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix shadow and gradient artifacts on transparent windows (#58981)
Nick Ebert715cd42d3667
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rsindex a4ae164c51f..316c7aaeeb5 100644--- a/crates/agent_ui/src/agent_diff.rs+++ b/crates/agent_ui/src/agent_diff.rs@@ -684,7 +684,10 @@ impl Render for AgentDiffPane {.on_action(cx.listener(Self::reject)).on_action(cx.listener(Self::reject_all)).on_action(cx.listener(Self::keep_all))- .bg(cx.theme().colors().editor_background)+ // Only paint the background for the empty state. When the diff editor+ // is shown it already paints `editor_background`; painting it again+ // here double-composites into a darker patch on transparent windows.+ .when(is_empty, |el| el.bg(cx.theme().colors().editor_background)).flex().items_center().justify_center()@@ -756,6 +759,9 @@ fn render_diff_hunk_controls(cx: &mut App,) -> AnyElement {let editor = editor.clone();+ // Drop shadows render as a dark halo on transparent windows.+ let opaque_window =+ cx.theme().window_background_appearance() == gpui::WindowBackgroundAppearance::Opaque;h_flex().h(line_height)@@ -770,7 +776,7 @@ fn render_diff_hunk_controls(.bg(cx.theme().colors().editor_background).gap_1().block_mouse_except_scroll()- .shadow_md()+ .when(opaque_window, |this| this.shadow_md()).children(vec![Button::new(("reject", row as u64), "Reject").disabled(is_created_file)diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex e376cf17bdb..4bf884c775d 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -5463,6 +5463,10 @@ impl AgentPanel {.width(px(64.0)).right(px(0.0)).gradient_stop(0.75);+ // The fade gradient renders as a visible patch on transparent windows+ // (the title already truncates).+ let opaque_window =+ cx.theme().window_background_appearance() == gpui::WindowBackgroundAppearance::Opaque;h_flex().key_context("TitleEditor")@@ -5474,19 +5478,20 @@ impl AgentPanel {.overflow_x_hidden().child(content).when(self.should_show_title_edit(window, cx), |this| {- this.child(gradient_overlay).child(- h_flex()- .visible_on_hover("title_editor")- .absolute()- .right_0()- .h_full()- .bg(cx.theme().colors().tab_bar_background)- .child(- IconButton::new("edit_tile", IconName::Pencil)- .icon_size(IconSize::Small)- .tooltip(Tooltip::text("Edit Thread Title")),- ),- )+ this.when(opaque_window, |this| this.child(gradient_overlay))+ .child(+ h_flex()+ .visible_on_hover("title_editor")+ .absolute()+ .right_0()+ .h_full()+ .bg(cx.theme().colors().tab_bar_background)+ .child(+ IconButton::new("edit_tile", IconName::Pencil)+ .icon_size(IconSize::Small)+ .tooltip(Tooltip::text("Edit Thread Title")),+ ),+ )}).into_any()}diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex 6180ad43f7d..201d553ee2d 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -2831,6 +2831,10 @@ impl ThreadView {let queue_expanded = self.queue_expanded;let max_content_width = AgentSettings::get_global(cx).max_content_width;+ // Drop shadows have no opaque surface to blend into on a transparent+ // window, so they render as a dark halo; only apply them when opaque.+ let opaque_window =+ cx.theme().window_background_appearance() == gpui::WindowBackgroundAppearance::Opaque;h_flex().w_full()@@ -2848,13 +2852,15 @@ impl ThreadView {.border_b_0().border_color(cx.theme().colors().border).rounded_t_md()- .shadow(vec![gpui::BoxShadow {- color: gpui::black().opacity(0.12),- offset: point(px(1.), px(-1.)),- blur_radius: px(2.),- spread_radius: px(0.),- inset: false,- }])+ .when(opaque_window, |this| {+ this.shadow(vec![gpui::BoxShadow {+ color: gpui::black().opacity(0.12),+ offset: point(px(1.), px(-1.)),+ blur_radius: px(2.),+ spread_radius: px(0.),+ inset: false,+ }])+ }).when_some(awaiting_permission, |this, element| this.child(element)).when(has_awaiting_permission@@ -5481,6 +5487,9 @@ impl ThreadView {let editing = self.editing_message == Some(entry_ix);let editor_focus = editor.focus_handle(cx).is_focused(window);let focus_border = cx.theme().colors().border_focused;+ // Drop shadows render as a dark halo on transparent windows.+ let opaque_window = cx.theme().window_background_appearance()+ == gpui::WindowBackgroundAppearance::Opaque;let has_checkpoint_button = message.checkpoint@@ -5539,7 +5548,9 @@ impl ThreadView {.bg(cx.theme().colors().editor_background).border_1().when(is_indented, |this| {- this.py_2().px_2().shadow_sm()+ this.py_2().px_2().when(opaque_window, |this| {+ this.shadow_sm()+ })}).border_color(cx.theme().colors().border).map(|this| {@@ -5555,9 +5566,10 @@ impl ThreadView {if editing && !editor_focus {return this.border_dashed()}- this.shadow_md().hover(|s| {- s.border_color(focus_border.opacity(0.8))- })+ this.when(opaque_window, |this| this.shadow_md())+ .hover(|s| {+ s.border_color(focus_border.opacity(0.8))+ })}).text_xs().child(editor.clone().into_any_element())diff --git a/crates/editor/src/element/header.rs b/crates/editor/src/element/header.rsindex 02dfebdfc31..052afe1de6a 100644--- a/crates/editor/src/element/header.rs+++ b/crates/editor/src/element/header.rs@@ -8,8 +8,8 @@ use gpui::{Action, AnyElement, App, AvailableSpace, Bounds, ClickEvent, ClipboardItem, ContentMask,CursorStyle, DefiniteLength, Entity, Focusable as _, Hitbox, HitboxBehavior, Hsla, IntoElement,Length, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, Pixels,- ShapedLine, SharedString, Styled, TextAlign, Window, div, fill, linear_color_stop,- linear_gradient, point, px, size,+ ShapedLine, SharedString, Styled, TextAlign, Window, WindowBackgroundAppearance, div, fill,+ linear_color_stop, linear_gradient, point, px, size,};use language::language_settings::ShowWhitespaceSetting;use multi_buffer::{Anchor, ExcerptBoundaryInfo};@@ -663,6 +663,11 @@ pub(crate) fn render_buffer_header(};let focus_handle = editor_read.focus_handle(cx);let colors = cx.theme().colors();+ // On transparent windows `editor_subheader_background` stacks over the+ // editor background into a darker bar (and the sticky shadow becomes a halo),+ // so skip both unless the window is opaque.+ let opaque_window =+ cx.theme().window_background_appearance() == WindowBackgroundAppearance::Opaque;let header = div().id(("buffer-header", buffer_id.to_proto()))@@ -678,7 +683,7 @@ pub(crate) fn render_buffer_header(.pr_2().rounded_sm().gap_1p5()- .when(is_sticky, |el| el.shadow_md())+ .when(is_sticky && opaque_window, |el| el.shadow_md()).border_1().map(|border| {let border_color =@@ -689,7 +694,9 @@ pub(crate) fn render_buffer_header(};border.border_color(border_color)})- .bg(colors.editor_subheader_background)+ .when(opaque_window, |el| {+ el.bg(colors.editor_subheader_background)+ }).hover(|style| style.bg(colors.element_hover)).map(|header| {let editor = editor.clone();diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rsindex 4f5f3d8d307..300d40d518a 100644--- a/crates/sidebar/src/sidebar.rs+++ b/crates/sidebar/src/sidebar.rs@@ -30,7 +30,8 @@ use feature_flags::{use gpui::{Action as _, AnyElement, App, ClickEvent, Context, DismissEvent, Entity, EntityId, FocusHandle,Focusable, KeyContext, ListState, Modifiers, Pixels, Render, SharedString, Task, TaskExt,- WeakEntity, Window, WindowHandle, linear_color_stop, linear_gradient, list, prelude::*, px,+ WeakEntity, Window, WindowBackgroundAppearance, WindowHandle, linear_color_stop,+ linear_gradient, list, prelude::*, px,};use itertools::Itertools;use language_model::LanguageModelRegistry;@@ -2288,13 +2289,20 @@ impl Sidebar {let key_for_toggle = key.clone();let key_for_focus = key.clone();+ // The fade gradient renders as a visible patch on transparent windows,+ // so truncate the label instead.+ let opaque_window =+ cx.theme().window_background_appearance() == WindowBackgroundAppearance::Opaque;+let label = if highlight_positions.is_empty() {Label::new(label.clone()).when(!is_active, |this| this.color(Color::Muted))+ .when(!opaque_window, |this| this.truncate()).into_any_element()} else {HighlightedLabel::new(label.clone(), highlight_positions.to_vec()).when(!is_active, |this| this.color(Color::Muted))+ .when(!opaque_window, |this| this.truncate()).into_any_element()};@@ -2402,12 +2410,12 @@ impl Sidebar {)}),)- .child(gradient_overlay())+ .children(opaque_window.then(|| gradient_overlay())).child(h_flex().gap_px().pr_1p5()- .child(gradient_overlay())+ .children(opaque_window.then(|| gradient_overlay())).child(self.render_new_thread_button(ix, id_prefix, key, &group_name, cx)).child(self.render_project_header_ellipsis_menu(ix,diff --git a/crates/ui/src/components/ai/thread_item.rs b/crates/ui/src/components/ai/thread_item.rsindex 6f72405c82b..caf36f41772 100644--- a/crates/ui/src/components/ai/thread_item.rs+++ b/crates/ui/src/components/ai/thread_item.rs@@ -1,7 +1,8 @@use crate::{CommonAnimationExt, DiffStat, GradientFade, HighlightedLabel, Tooltip, prelude::*};use gpui::{- Animation, AnimationExt, ClickEvent, Hsla, MouseButton, SharedString, pulsating_between,+ Animation, AnimationExt, ClickEvent, Hsla, MouseButton, SharedString,+ WindowBackgroundAppearance, pulsating_between,};use itertools::Itertools as _;use std::{path::PathBuf, sync::Arc, time::Duration};@@ -250,6 +251,11 @@ impl ThreadItem {impl RenderOnce for ThreadItem {fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {let color = cx.theme().colors();+ // The fade gradient paints a solid color over the title to blend it into+ // the row background, but a transparent window has no opaque surface to+ // fade into, so it renders as a visible patch; truncate the title instead.+ let opaque_window =+ cx.theme().window_background_appearance() == WindowBackgroundAppearance::Opaque;let sidebar_base_bg = color.title_bar_background.blend(color.panel_background.opacity(0.25));@@ -365,10 +371,12 @@ impl RenderOnce for ThreadItem {} else if highlight_positions.is_empty() {Label::new(title).when_some(self.title_label_color, |label, color| label.color(color))+ .when(!opaque_window, |label| label.truncate()).into_any_element()} else {HighlightedLabel::new(title, highlight_positions).when_some(self.title_label_color, |label, color| label.color(color))+ .when(!opaque_window, |label| label.truncate()).into_any_element()};@@ -449,20 +457,24 @@ impl RenderOnce for ThreadItem {.child(icon).child(title_label),)- .when(self.is_truncated, |this| this.child(gradient_overlay))+ .when(self.is_truncated && opaque_window, |this| {+ this.child(gradient_overlay)+ }).when(self.hovered, |this| {this.when_some(self.action_slot, |this, slot| {- let overlay = GradientFade::new(base_bg, hover_bg, hover_bg)- .width(px(120.0))- .right(px(8.))- .gradient_stop(0.90)- .group_name("thread-item");-this.child(h_flex().relative().pr_1p5()- .child(overlay)+ .when(opaque_window, |this| {+ this.child(+ GradientFade::new(base_bg, hover_bg, hover_bg)+ .width(px(120.0))+ .right(px(8.))+ .gradient_stop(0.90)+ .group_name("thread-item"),+ )+ }).child(slot).on_mouse_down(MouseButton::Left, |_, _, cx| {cx.stop_propagation()