diff --git a/architecture/notes/pebrel_app/gpui_shell/wallpaper/2026-11-21-workspace-optics.md b/architecture/notes/pebrel_app/gpui_shell/wallpaper/2026-11-21-workspace-optics.md new file mode 100644 index 000000000..b2de97979 --- /dev/null +++ b/architecture/notes/pebrel_app/gpui_shell/wallpaper/2026-11-21-workspace-optics.md @@ -0,0 +1,62 @@ +# Precomputed wallpaper at the workspace sidebar + +## Status + +Accepted for dark workspace themes with the wallpaper extended into the chrome. + +## Context + +The selected L4-B prototype gives the left rail a softer image while preserving +the image detail to its right. The wallpaper slider also needs to preview the +image beneath the Settings surface and reach the full image in the terminal. + +## Evidence + +The approved prototype blends a 5.5 px kernel and a 2.6 px kernel into the sharp +image across a 64 px feather beyond the sidebar. Its strongest band reduces +contrast by 24 percent, then applies a theme tint and fine black-and-white grain. + +## Decision + +Sample the already decoded wallpaper into a window-local strip after fitting +and alignment. The file loader and strip baker share a serial preparation slot. +Each window retains one strip and limits it to 2 MiB of pixels. A short delay +coalesces geometry changes, and generation checks cancel outdated work and +prevent stale results from reaching the window. + +The existing 38 percent default and the Settings background retain their +composition. Above that default, a second draw of the fitted wallpaper reveals +the image over the terminal surface so the slider can reach the original at +100 percent. Holding the wallpaper slider temporarily fades the Settings chrome +and previews the same extended image contribution. Slider movements only change +opacity and use the cached texture. + +## Rejected alternatives + +- Filtering each frame would repeat the same work during scrolling and dragging. +- Retaining full-window variants would duplicate unaffected pixels in every window. +- Blurring the source before fitting would make the apparent kernel size depend + on image dimensions and the selected fit mode. + +## Consequences + +A changed source, fit, theme tint or settled viewport needs a new strip. The +sharp wallpaper is available while the strip is prepared. The CPU path and the +finished texture use the same BGRA and premultiplied filtering rules for +transparent edges as the existing wallpaper loader. + +## Validation + +The isolated loader and optics suite passed nine tests. On Linux ARM64, a +24-sample synthetic fixture measured 57–139 ms median preparation time with +0.81–2.00 MiB of retained strip pixels across 720p, 1080p and 2160p viewports. +The timing excludes image decode, the coalescing delay and texture upload. + +## Supersedes + +None. Settings continues to use its existing background treatment. + +## Revisit when + +More than one live animated source or an additional fitted effect needs to share +the preparation budget. diff --git a/pebrel_app/src/display/mod.rs b/pebrel_app/src/display/mod.rs index 3292c6abf..d6e711067 100644 --- a/pebrel_app/src/display/mod.rs +++ b/pebrel_app/src/display/mod.rs @@ -5647,7 +5647,7 @@ impl Display { self.nebula_window_opacity = 1.0; self.nebula_background = None; self.nebula_background_image = None; - self.nebula_background_image_opacity = 0.38; + self.nebula_background_image_opacity = nebula_settings::DEFAULT_BACKGROUND_IMAGE_OPACITY; self.nebula_background_image_fit = BackgroundImageFit::default(); self.nebula_background_image_alignment = BackgroundImageAlignment::default(); self.nebula_background_image_cover_chrome = false; diff --git a/pebrel_app/src/display/settings.rs b/pebrel_app/src/display/settings.rs index 28be42336..8684fbafc 100644 --- a/pebrel_app/src/display/settings.rs +++ b/pebrel_app/src/display/settings.rs @@ -859,7 +859,7 @@ pub(super) fn nebula_settings_load(config: &UiConfig) -> NebulaRuntimeSettings { opacity: config.window_opacity(), background: None, background_image: None, - background_image_opacity: 0.38, + background_image_opacity: nebula_settings::DEFAULT_BACKGROUND_IMAGE_OPACITY, background_image_fit: BackgroundImageFit::default(), background_image_alignment: BackgroundImageAlignment::default(), background_image_cover_chrome: false, diff --git a/pebrel_app/src/gpui_shell/file_editor/chrome.rs b/pebrel_app/src/gpui_shell/file_editor/chrome.rs index 6e476e3a8..2561cd04a 100644 --- a/pebrel_app/src/gpui_shell/file_editor/chrome.rs +++ b/pebrel_app/src/gpui_shell/file_editor/chrome.rs @@ -81,6 +81,9 @@ impl TextFileView { .flex_shrink_0() .icon(Icon::new(IconName::PanelRight).size(px(design::ICON_SIZE))) .selected(self.show_details) + .when(self.show_details, |button| { + crate::gpui_shell::theme::selected_glass(button, cx) + }) .tooltip(language.text(Message::EditorDetailsToggle)) .on_click(cx.listener(|this, _, _, cx| { if this.details_hosted { diff --git a/pebrel_app/src/gpui_shell/settings_pane.rs b/pebrel_app/src/gpui_shell/settings_pane.rs index dd38ee6d7..73e5e462a 100644 --- a/pebrel_app/src/gpui_shell/settings_pane.rs +++ b/pebrel_app/src/gpui_shell/settings_pane.rs @@ -18,9 +18,9 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ App, AppContext as _, Context, Entity, EventEmitter, FocusHandle, Focusable, Hsla, InteractiveElement as _, IntoElement, KeyDownEvent, ModifiersChangedEvent, MouseButton, - MouseMoveEvent, ParentElement as _, Render, RenderImage, Rgba as GpuiRgba, SharedString, - StatefulInteractiveElement as _, Styled as _, Subscription, Task, Window, anchored, deferred, - div, img, px, + MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Render, RenderImage, + Rgba as GpuiRgba, SharedString, StatefulInteractiveElement as _, Styled as _, Subscription, + Task, Window, anchored, deferred, div, img, px, }; use gpui_component::input::InputEvent; use gpui_component::select::{SelectEvent, SelectItem}; @@ -87,6 +87,7 @@ mod theme_transfer; mod theme_transfer_view; use localization::*; +pub(super) use navigation::SETTINGS_NAV_WIDTH; use navigation::*; use shell_picker::*; pub(super) use status::SshStatus; @@ -100,6 +101,7 @@ pub enum SettingsPaneEvent { Close, Changed, BackupRestored, + WallpaperPreview, /// 导入 Profile 已落盘;Tab 的 Shell 面板若正打开,需要重建候选快照。 TerminalProfilesChanged, /// 设置页"连接"按钮:宿主开 SSH tab(连接语义在业务层)。 @@ -170,6 +172,10 @@ pub struct SettingsPane { pub(super) theme_foreground_picker: theme_foreground::ThemeForegroundState, opacity_slider: Entity, wallpaper_opacity_slider: Entity, + wallpaper_peek: bool, + wallpaper_peek_changed: bool, + appearance_expanded: bool, + appearance_section: Option, scroll_speed_slider: Entity, scroll_speed_focus: FocusHandle, pub(super) proxy_url_input: Entity, @@ -548,13 +554,38 @@ impl SettingsPane { return; } self.runtime.background_image_opacity = opacity; + super::wallpaper::set_image_opacity_live(opacity, cx); cx.notify(); + if self.wallpaper_peek { + self.wallpaper_peek_changed = true; + } else { + self.persist_wallpaper_opacity(cx); + } + } + + fn persist_wallpaper_opacity(&mut self, cx: &mut Context) { + let opacity = self.runtime.background_image_opacity; self.schedule_slider_persist( vec![("background_image_opacity", format!("{opacity:.2}"))], cx, ); } + pub(super) fn wallpaper_peeking(&self) -> bool { + self.wallpaper_peek && self.active_section == 1 + } + + pub(super) fn set_wallpaper_peek(&mut self, active: bool, cx: &mut Context) { + if self.wallpaper_peek != active { + self.wallpaper_peek = active; + if !active && std::mem::take(&mut self.wallpaper_peek_changed) { + self.persist_wallpaper_opacity(cx); + } + cx.emit(SettingsPaneEvent::WallpaperPreview); + cx.notify(); + } + } + /// `Change` 同时覆盖鼠标拖动和键盘调整,因此统一用 debounce 延后落盘: /// 每个新事件覆盖上一个待落盘任务,旧 `Task` drop 即取消。 /// @@ -1048,7 +1079,26 @@ impl SettingsPane { .w(px(220.0)) .items_center() .gap_3() - .child(div().flex_1().min_w_0().child(Slider::new(state))) + .child( + div() + .flex_1() + .min_w_0() + .when( + state == &self.wallpaper_opacity_slider && cx.theme().is_dark(), + |slider| { + slider.capture_any_mouse_down(cx.listener( + |this, event: &MouseDownEvent, _, cx| { + if event.button == MouseButton::Left + && super::wallpaper::wallpaper_available_for_preview(cx) + { + this.set_wallpaper_peek(true, cx); + } + }, + )) + }, + ) + .child(Slider::new(state)), + ) .child(div() .w(px(48.0)) .flex_shrink_0() @@ -1565,8 +1615,10 @@ impl SettingsPane { let foreground = theme.foreground; let hover_bg = crate::gpui_shell::theme::settings_hover_bg(cx, false); let hairline = crate::gpui_shell::theme::settings_hairline(cx); + let glass = crate::gpui_shell::theme::selection_glass(cx); // 返回入口和分类共用紧凑菜单尺寸;字号与搜索框一致,不继承终端配置字号。 - let mut nav = v_flex() + let nav = v_flex() + .debug_selector(|| "settings-sidebar".to_owned()) .w(px(SETTINGS_NAV_WIDTH)) .h_full() .flex_shrink_0() @@ -1576,8 +1628,8 @@ impl SettingsPane { .gap(px(2.0)) .text_sm() .line_height(px(20.0)) - .border_r_1() - .border_color(hairline) + .opacity(if self.wallpaper_peeking() { 0.16 } else { 1.0 }) + .when(!theme.is_dark(), |nav| nav.border_r_1().border_color(hairline)) .child( div() .id("settings-back") @@ -1598,15 +1650,20 @@ impl SettingsPane { ) .child(self.render_nav_search(window, cx)); let searching = !self.settings_search_input.read(cx).value().trim().is_empty(); + let mut items = v_flex().w_full().gap(px(2.0)); let mut previous_group = None; for ix in self.matching_settings_sections(cx) { let group = NAV_GROUPS.iter().position(|(_, sections)| sections.contains(&ix)); if !searching && previous_group.is_some() && previous_group != group { - nav = nav.child(div().h(px(10.0)).flex_shrink_0()); + items = items.child(div().h(px(10.0)).flex_shrink_0()); } previous_group = group; + if ix == 1 && !searching { + items = items.child(self.appearance_navigation(glass, cx)); + continue; + } let active = ix == self.active_section; - nav = nav.child( + items = items.child( div() .id(("settings-nav", ix)) .debug_selector(move || format!("settings-nav-{ix}")) @@ -1619,9 +1676,18 @@ impl SettingsPane { .gap(px(10.0)) .rounded_md() .cursor_pointer() - // 底色和墨色表达选中,避免中文导航因字重匹配而突然变粗。 - .font_weight(gpui::FontWeight::NORMAL) - .when(active, |item| item.bg(active_bg).text_color(active_fg)) + // 选中态同时改变底色、墨色和字重,余光扫过也能确认当前位置。 + .font_weight(if active { + gpui::FontWeight::MEDIUM + } else { + gpui::FontWeight::NORMAL + }) + .when_some(glass, |item, glass| { + if active { glass.apply(item) } else { glass.reserve(item) } + }) + .when(active, |item| { + item.text_color(active_fg).when(glass.is_none(), |item| item.bg(active_bg)) + }) .when(!active, |item| item.text_color(muted).hover(|s| s.bg(hover_bg))) .on_click(cx.listener(move |this, _, _, cx| { this.active_section = ix; @@ -1638,7 +1704,7 @@ impl SettingsPane { .child(section_label(ix, language)), ); } - nav.child(div().flex_1().min_h(px(24.0))) + nav.child(div().flex_1().min_h_0().overflow_y_scrollbar().child(items)) .child( Button::new("settings-restore-defaults") .icon(IconName::Undo2) @@ -1687,11 +1753,22 @@ impl Render for SettingsPane { let mobile_page = self.active_section == MOBILE_SECTION; let form_page = matches!(self.active_section, 1 | 2 | 5 | 6 | 8); let has_cards = form_page || mobile_page || self.active_section == 9; + let peeking = self.wallpaper_peeking(); div() .size_full() .font(crate::gpui_shell::typography::ui_font(cx)) .track_focus(&self.focus_handle) + .when(peeking, |root| { + root.capture_any_mouse_up(cx.listener(|this, event: &MouseUpEvent, _, cx| { + if event.button == MouseButton::Left { + this.set_wallpaper_peek(false, cx); + } + })) + .on_mouse_up_out(MouseButton::Left, cx.listener(|this, _, _, cx| { + this.set_wallpaper_peek(false, cx); + })) + }) // 旧壳 `input/chrome.rs` 的合同是页面任何左键先撤销捕获。 // 行自身会 stop_propagation 并完成「同行取消 / 他行转移」;其它 // 控件的 mouse_down 仍先取得自己的焦点,这里只清状态,不抢焦点, @@ -1736,7 +1813,9 @@ impl Render for SettingsPane { .flex_1() .min_w_0() .h_full() + .debug_selector(|| "settings-content".to_owned()) .when(has_cards, |pane| pane.bg(crate::gpui_shell::theme::settings_canvas_tint(cx))) + .opacity(if peeking { 0.16 } else { 1.0 }) .child( v_flex() .flex_1() diff --git a/pebrel_app/src/gpui_shell/settings_pane/about.rs b/pebrel_app/src/gpui_shell/settings_pane/about.rs index 98a5c07a0..d82abeff6 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/about.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/about.rs @@ -79,6 +79,7 @@ impl SettingsPane { let warning = theme.warning; let danger = theme.danger; let base_px = self.font_size_px(cx); + let dark = theme.is_dark(); let cached_update = crate::update_download::cached_asset().filter(|asset| { !managed && (crate::update_check::is_newer(&asset.version, env!("CARGO_PKG_VERSION")) @@ -245,7 +246,7 @@ impl SettingsPane { .text_color(muted) .child(title) }; - let update_column = v_flex() + let update_column = crate::gpui_shell::theme::settings_card(v_flex(), cx) .flex_1() .min_w(px(280.0)) .child(section_title( @@ -280,7 +281,7 @@ impl SettingsPane { .when_some(distribution.message(), |column, message| { column.child(div().text_color(muted).child(language.text(message))) }); - let actions = v_flex() + let actions = crate::gpui_shell::theme::settings_card(v_flex(), cx) .flex_1() .min_w(px(280.0)) .child(section_title( @@ -320,7 +321,7 @@ impl SettingsPane { .w_full() .flex_wrap() .items_start() - .gap(px(64.0)) + .gap(px(if dark { 16.0 } else { 64.0 })) .child(update_column) .child(actions), ) diff --git a/pebrel_app/src/gpui_shell/settings_pane/appearance.rs b/pebrel_app/src/gpui_shell/settings_pane/appearance.rs index d4ee11f74..1657810bd 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/appearance.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/appearance.rs @@ -245,7 +245,13 @@ impl SettingsPane { ), ); let settings = self.appearance_advanced_settings(window, cx); - v_flex().w_full().gap(px(GROUP_GAP)).child(selectors).child(settings) + v_flex() + .w_full() + .gap(px(GROUP_GAP)) + .children( + self.show_appearance_section(AppearanceSection::Theme, cx).then_some(selectors), + ) + .child(settings) } } diff --git a/pebrel_app/src/gpui_shell/settings_pane/appearance_advanced.rs b/pebrel_app/src/gpui_shell/settings_pane/appearance_advanced.rs index 6f8881231..c9c83cfcb 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/appearance_advanced.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/appearance_advanced.rs @@ -192,10 +192,17 @@ impl SettingsPane { v_flex() .w_full() .gap(px(GROUP_GAP)) - .child(terminal) - .child(cursor) - .child(interface) - .child(custom_background) + .children( + self.show_appearance_section(AppearanceSection::Terminal, cx).then_some(terminal), + ) + .children(self.show_appearance_section(AppearanceSection::Cursor, cx).then_some(cursor)) + .children( + self.show_appearance_section(AppearanceSection::Interface, cx).then_some(interface), + ) + .children( + self.show_appearance_section(AppearanceSection::Background, cx) + .then_some(custom_background), + ) } pub(super) fn custom_effect_settings( diff --git a/pebrel_app/src/gpui_shell/settings_pane/design.rs b/pebrel_app/src/gpui_shell/settings_pane/design.rs index ab048a14c..8326865a6 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/design.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/design.rs @@ -311,12 +311,14 @@ impl SettingsPane { } pub(super) fn settings_card(cx: &App) -> gpui::Div { - v_flex() - .w_full() - .min_w_0() - .bg(crate::gpui_shell::theme::settings_card_fill(cx)) - .rounded(px(CARD_RADIUS)) - .shadow(crate::gpui_shell::theme::settings_card_shadow(cx)) + let card = v_flex().w_full().min_w_0(); + if cx.theme().is_dark() { + crate::gpui_shell::theme::settings_card(card, cx) + } else { + card.bg(crate::gpui_shell::theme::settings_card_fill(cx)) + .rounded(px(CARD_RADIUS)) + .shadow(crate::gpui_shell::theme::settings_card_shadow(cx)) + } } /// 设置分组卡。`ParentElement` 把子元素收进卡内,调用点保持 diff --git a/pebrel_app/src/gpui_shell/settings_pane/font_picker.rs b/pebrel_app/src/gpui_shell/settings_pane/font_picker.rs index aec3cc010..2cb8b9833 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/font_picker.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/font_picker.rs @@ -362,6 +362,7 @@ impl SettingsPane { let muted = cx.theme().muted_foreground; let hover_bg = cx.theme().list_hover; let selected_bg = cx.theme().list_active; + let glass = crate::gpui_shell::theme::selection_glass(cx); let warning = cx.theme().warning; let border = cx.theme().border; let families = self.configured_font_families(cx); @@ -411,6 +412,7 @@ impl SettingsPane { .items_center() .rounded_md() .bg(selected_bg) + .when_some(glass, |row, glass| glass.apply(row)) .child( div() .w(px(16.0)) diff --git a/pebrel_app/src/gpui_shell/settings_pane/initialization.rs b/pebrel_app/src/gpui_shell/settings_pane/initialization.rs index 4cb79173f..2591ce79d 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/initialization.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/initialization.rs @@ -2,6 +2,12 @@ use super::*; impl SettingsPane { pub fn new(window: &mut Window, cx: &mut Context) -> Self { + cx.observe_window_activation(window, |pane, window, cx| { + if !window.is_window_active() { + pane.set_wallpaper_peek(false, cx); + } + }) + .detach(); let runtime = RuntimeSettings::load(); let language = crate::gpui_shell::config::ui_language(cx); let mut selects: Vec<(&'static str, SharedSelect, &'static [&'static str])> = Vec::new(); @@ -717,6 +723,10 @@ impl SettingsPane { theme_foreground_picker: theme_foreground::ThemeForegroundState::new(cx), opacity_slider, wallpaper_opacity_slider, + wallpaper_peek: false, + wallpaper_peek_changed: false, + appearance_expanded: true, + appearance_section: None, scroll_speed_slider, scroll_speed_focus, proxy_url_input, diff --git a/pebrel_app/src/gpui_shell/settings_pane/navigation.rs b/pebrel_app/src/gpui_shell/settings_pane/navigation.rs index 30cdc6ce1..9d663ceed 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/navigation.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/navigation.rs @@ -82,10 +82,120 @@ pub(super) fn visible_nav_sections() -> impl Iterator { } // 导航使用组件的小字号,与搜索菜单一致;尺寸是逻辑像素,由窗口统一处理 DPI。 -pub(super) const SETTINGS_NAV_WIDTH: f32 = 248.0; +pub(in crate::gpui_shell) const SETTINGS_NAV_WIDTH: f32 = 248.0; pub(super) const SETTINGS_NAV_ROW_HEIGHT: f32 = 34.0; pub(super) const SETTINGS_NAV_ICON_SIZE: f32 = 16.0; +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(super) enum AppearanceSection { + Theme, + Terminal, + Cursor, + Interface, + Background, +} + +impl AppearanceSection { + const ALL: [Self; 5] = + [Self::Theme, Self::Terminal, Self::Cursor, Self::Interface, Self::Background]; + + pub(super) fn label(self, language: crate::display::UiLanguage) -> &'static str { + use crate::i18n::Message; + language.text(match self { + Self::Theme => Message::CommonTheme, + Self::Terminal => Message::SettingsAppearanceTerminalAppearance, + Self::Cursor => Message::CommonCursor, + Self::Interface => Message::ThemeEditorPreviewInterface, + Self::Background => Message::SettingsAppearanceCustomBackground, + }) + } +} + +impl SettingsPane { + pub(super) fn show_appearance_section(&self, section: AppearanceSection, cx: &App) -> bool { + self.appearance_section.is_none_or(|shown| shown == section) + || !self.settings_search_input.read(cx).value().trim().is_empty() + } + + pub(super) fn appearance_navigation( + &self, + glass: Option, + cx: &Context, + ) -> gpui::Div { + let language = crate::gpui_shell::config::ui_language(cx); + let open = self.appearance_expanded; + let active = self.active_section == 1; + let theme = cx.theme(); + let parent_selected = active && (!open || self.appearance_section.is_none()); + let parent = Button::new("settings-appearance-toggle") + .debug_selector(|| "settings-nav-1".to_owned()) + .w_full() + .h(px(SETTINGS_NAV_ROW_HEIGHT)) + .ghost() + .selected(parent_selected) + .toggled(open) + .label(section_label(1, language)) + .icon(IconName::Palette) + .justify_start() + .relative() + .text_color(if parent_selected { theme.foreground } else { theme.muted_foreground }) + .child( + h_flex().absolute().right_2().top_0().bottom_0().items_center().child( + Icon::new(if open { IconName::ChevronDown } else { IconName::ChevronRight }) + .xsmall(), + ), + ) + .when_some(glass.filter(|_| parent_selected), |button, glass| glass.apply(button)) + .on_click(cx.listener(|pane, _, _, cx| { + pane.appearance_expanded = pane.active_section != 1 || !pane.appearance_expanded; + pane.active_section = 1; + pane.about_sponsor_open = false; + cx.notify(); + })); + + v_flex().mx_1().gap_1().child(parent).when(open, |group| { + group.child( + v_flex() + .ml(px(16.0)) + .pl(px(9.0)) + .gap(px(2.0)) + .border_l_1() + .border_color(crate::gpui_shell::theme::settings_hairline(cx)) + .children(AppearanceSection::ALL.into_iter().enumerate().map( + |(index, section)| { + let selected = active && self.appearance_section == Some(section); + Button::new(("settings-appearance-child", index)) + .debug_selector(move || { + format!("settings-appearance-child-{index}") + }) + .label(section.label(language)) + .w_full() + .h(px(28.0)) + .small() + .justify_start() + .ghost() + .selected(selected) + .text_color(if selected { + theme.foreground + } else { + theme.muted_foreground + }) + .when_some(glass.filter(|_| selected), |button, glass| { + glass.apply(button) + }) + .on_click(cx.listener(move |pane, _, _, cx| { + pane.active_section = 1; + pane.appearance_section = Some(section); + pane.about_sponsor_open = false; + cx.notify(); + })) + }, + )), + ) + }) + } +} + // 正文分组与表单继续沿用现有几何节奏。 pub(super) const SETTINGS_GROUP_GAP: f32 = 32.0; pub(super) const SETTINGS_GROUP_TITLE_HEIGHT: f32 = 26.0; diff --git a/pebrel_app/src/gpui_shell/settings_pane/tests.rs b/pebrel_app/src/gpui_shell/settings_pane/tests.rs index 4e38a0365..88b688f84 100644 --- a/pebrel_app/src/gpui_shell/settings_pane/tests.rs +++ b/pebrel_app/src/gpui_shell/settings_pane/tests.rs @@ -729,3 +729,41 @@ mod shell_row_geometry { ); } } + +#[cfg(feature = "gpui-test-support")] +#[gpui::test] +fn appearance_parent_collapses_and_the_child_opens_its_settings(cx: &mut gpui::TestAppContext) { + cx.update(|cx| { + gpui_component::init(cx); + cx.set_global(crate::gpui_shell::config::Settings::load(ThemeName::Nord)); + }); + let mut pane_out = None; + let (_, cx) = cx.add_window_view(|window, cx| { + let pane = cx.new(|cx| SettingsPane::new(window, cx)); + pane_out = Some(pane.clone()); + gpui_component::Root::new(pane, window, cx) + }); + let pane = pane_out.unwrap(); + cx.simulate_resize(gpui::size(px(1280.0), px(900.0))); + cx.run_until_parked(); + let parent = cx.debug_bounds("settings-nav-1").unwrap().center(); + assert!(cx.debug_bounds("settings-appearance-child-1").is_some()); + cx.simulate_click(parent, gpui::Modifiers::default()); + cx.run_until_parked(); + assert!(cx.debug_bounds("settings-appearance-child-1").is_none()); + let general = cx.debug_bounds("settings-nav-0").unwrap().center(); + cx.simulate_click(general, gpui::Modifiers::default()); + cx.run_until_parked(); + assert_eq!(pane.read_with(cx, |pane, _| pane.active_section), 0); + cx.simulate_click(parent, gpui::Modifiers::default()); + cx.run_until_parked(); + assert_eq!(pane.read_with(cx, |pane, _| pane.active_section), 1); + let terminal = cx.debug_bounds("settings-appearance-child-1").unwrap().center(); + cx.simulate_click(terminal, gpui::Modifiers::default()); + cx.run_until_parked(); + assert_eq!( + pane.read_with(cx, |pane, _| pane.appearance_section), + Some(AppearanceSection::Terminal) + ); + assert!(cx.debug_bounds("font-family-cjk-input").is_some()); +} diff --git a/pebrel_app/src/gpui_shell/theme.rs b/pebrel_app/src/gpui_shell/theme.rs index 2787c81d7..d2e2568b1 100644 --- a/pebrel_app/src/gpui_shell/theme.rs +++ b/pebrel_app/src/gpui_shell/theme.rs @@ -1,7 +1,9 @@ mod transition; pub(crate) use transition::ThemeTransition; -use gpui::{App, Bounds, Hsla, Pixels, Rgba as GpuiRgba, Window, fill, hsla, point, px, size}; +use gpui::{ + App, Bounds, Hsla, Pixels, Rgba as GpuiRgba, Styled, Window, fill, hsla, point, px, size, +}; use gpui_component::{ActiveTheme as _, Theme, ThemeMode}; use crate::display::color::Rgb; @@ -679,6 +681,87 @@ fn soften(c: crate::display::color::Rgb, keep: f32) -> crate::display::color::Rg crate::display::color::Rgb::new(pull(c.r), pull(c.g), pull(c.b)) } +#[derive(Clone, Copy)] +pub(super) struct GlassSurface { + fill: Hsla, + border: Hsla, + sheen: Hsla, +} + +impl GlassSurface { + fn selection(accent: Hsla) -> Self { + let sheen = accent.blend(gpui::white().opacity(0.76)).opacity(0.18); + Self { fill: accent.opacity(0.17), border: accent.opacity(0.40), sheen } + } + + pub(super) fn apply(self, element: E) -> E { + element.border_1().border_color(self.border).bg(self.background(0.045)) + } + + pub(super) fn reserve(self, element: E) -> E { + element.border_1().border_color(gpui::transparent_black()) + } + + fn background(self, edge: f32) -> gpui::Background { + gpui::linear_gradient( + 180.0, + gpui::linear_color_stop(glass_over(self.fill, self.sheen), 0.0), + gpui::linear_color_stop(self.fill, edge), + ) + } +} + +fn glass_over(base: Hsla, sheen: Hsla) -> Hsla { + let mut base = GpuiRgba::from(base); + let sheen = GpuiRgba::from(sheen); + let alpha = base.a * (1.0 - sheen.a) + sheen.a; + let mix = |a, b| (a * base.a * (1.0 - sheen.a) + b * sheen.a) / alpha; + base = GpuiRgba { + r: mix(base.r, sheen.r), + g: mix(base.g, sheen.g), + b: mix(base.b, sheen.b), + a: alpha, + }; + base.into() +} + +pub(super) fn selection_glass(cx: &App) -> Option { + let theme = cx.theme(); + theme.is_dark().then(|| GlassSurface::selection(theme.primary)) +} + +pub(super) fn selected_glass(element: E, cx: &App) -> E { + if let Some(glass) = selection_glass(cx) { glass.apply(element) } else { element } +} + +pub(super) fn settings_segment_glass(cx: &App) -> Option { + cx.theme().is_dark().then(|| { + let white = gpui::white(); + GlassSurface { + fill: white.opacity(0.13), + border: white.opacity(0.10), + sheen: white.opacity(0.18), + } + }) +} + +pub(super) fn settings_card(element: gpui::Div, cx: &App) -> gpui::Div { + let skin = resolved_skin(cx); + if skin.is_light { + return element; + } + let mut fill = solid(skin.panel); + let backdrop = crate::gpui_shell::wallpaper::wallpaper_available_for_preview(cx); + fill.l += (1.0 - fill.l) * 0.035; + fill.a = if backdrop { 0.50 } else { 1.0 }; + let glass = GlassSurface { + fill, + border: gpui::white().opacity(0.10), + sheen: GlassSurface::selection(ink(skin.accent)).sheen, + }; + element.rounded(px(12.0)).border_1().border_color(glass.border).bg(glass.background(0.009)) +} + fn apply_skin_tokens(chrome: &ResolvedTheme, cx: &mut App) { let (ui_font_family, ui_font_size) = cx .try_global::() @@ -704,13 +787,13 @@ fn apply_skin_tokens(chrome: &ResolvedTheme, cx: &mut App) { // 悬停 / 选中水洗。 let hover = wash(sk.hover); - let selected = wash(sk.accent_soft); - let list_selected = selected; + let glass = GlassSurface::selection(ink(sk.accent)); + let selected = if sk.is_light { wash(sk.accent_soft) } else { glass.fill }; theme.accent = hover; theme.accent_foreground = ink(sk.ink_strong); theme.list_hover = ink(sk.ink).opacity(if sk.is_light { 0.06 } else { 0.08 }); - theme.list_active = ink(sk.accent).opacity(0.08); - theme.list_active_border = transparent; + theme.list_active = if sk.is_light { ink(sk.accent).opacity(0.08) } else { glass.fill }; + theme.list_active_border = if sk.is_light { transparent } else { glass.border }; theme.sidebar_foreground = ink(sk.ink); theme.sidebar_accent = selected; theme.sidebar_accent_foreground = ink(sk.ink_strong); @@ -737,7 +820,7 @@ fn apply_skin_tokens(chrome: &ResolvedTheme, cx: &mut App) { )); theme.secondary = wash(sk.surface); theme.secondary_hover = hover; - theme.secondary_active = list_selected; + theme.secondary_active = selected; theme.secondary_foreground = ink(sk.ink); // 语义三色。 diff --git a/pebrel_app/src/gpui_shell/theme/selection_tests.rs b/pebrel_app/src/gpui_shell/theme/selection_tests.rs index c5c87f43a..297797cc0 100644 --- a/pebrel_app/src/gpui_shell/theme/selection_tests.rs +++ b/pebrel_app/src/gpui_shell/theme/selection_tests.rs @@ -112,8 +112,12 @@ fn text_selection_and_search_matches_stay_distinct_from_the_document(cx: &mut Te } assert_eq!(theme.tokens.selection.color, selection, "{name:?}"); assert_eq!(theme.tokens.selection.background, selection.into(), "{name:?}"); - // List rows use a separate light wash, not the stronger text overlay. - assert_eq!(theme.list_active, expected_list_selection, "{name:?}"); + if theme.is_dark() { + assert_eq!(theme.list_active.a, 0.17, "{name:?}"); + assert_eq!(theme.list_active_border.a, 0.40, "{name:?}"); + } else { + assert_eq!(theme.list_active, expected_list_selection, "{name:?}"); + } } }); } diff --git a/pebrel_app/src/gpui_shell/wallpaper.rs b/pebrel_app/src/gpui_shell/wallpaper.rs index e014815cb..2d3d84f72 100644 --- a/pebrel_app/src/gpui_shell/wallpaper.rs +++ b/pebrel_app/src/gpui_shell/wallpaper.rs @@ -27,11 +27,13 @@ use image::{Frame, RgbaImage}; mod animated; mod budgets; mod image_loader; +mod optics; mod tab_bar; pub(crate) use tab_bar::{tab_bar_material_is_custom, tab_bar_surface_opacity}; pub(crate) mod preview; #[cfg(all(test, feature = "gpui-test-support"))] mod tests; +pub(super) mod workspace_strip; use pebrel_settings::BlurModeName; use crate::renderer::image::{BackgroundImageAlignment, BackgroundImageFit, wallpaper_rect}; @@ -357,6 +359,20 @@ fn underlay_composition(surface: f32, wallpaper: f32) -> (f32, f32) { (surface_alpha, layer.min(1.0)) } +pub(super) fn wallpaper_available_for_preview(cx: &App) -> bool { + cx.try_global::().is_some_and(|effects| { + effects.layout.opacity > 0.0 + && effects.wallpaper.as_ref().is_some_and(|wp| wp.image.is_some()) + }) +} + +pub(super) fn set_image_opacity_live(opacity: f32, cx: &mut App) { + if cx.try_global::().is_some_and(|effects| !effects.kind.is_animated()) { + cx.global_mut::().layout.opacity = opacity; + cx.refresh_windows(); + } +} + /// 开窗参数用。GPUI 通用层在窗口创建时就会把这个值下发到平台层 /// (`gpui::Window::new` → `platform_window.set_background_appearance`)。 /// Mica / Mica Alt 因此从首帧就走平台原生 backdrop,不再先挂一层普通透明背景。 @@ -570,30 +586,67 @@ pub fn paint_glass_overlay(bounds: Bounds, window: &mut Window, cx: &App }); } -/// Card-only wallpaper sits above the card background. Extended wallpaper sits -/// below the shell/card surfaces, preserving the original visible scrim. -/// Both modes reuse one image; opacity and layout never rebake its pixels. -pub fn card_layer(cx: &App) -> impl IntoElement { - layer(false, cx) +/// Preserve the usual extended-wallpaper scrim through the default setting, +/// then reveal the same fitted image above the terminal surface toward 100%. +pub(super) fn card_layer(strip: Option<(Pixels, Arc)>, cx: &App) -> impl IntoElement { + layer(WallpaperLayer::Card, strip, cx) +} + +pub(super) fn window_layer( + strip: Option<(Pixels, Arc)>, + cx: &App, +) -> impl IntoElement { + layer(WallpaperLayer::Window, strip, cx) } -pub fn window_layer(cx: &App) -> impl IntoElement { - layer(true, cx) +pub(super) fn peek_layer(strip: Option<(Pixels, Arc)>, cx: &App) -> impl IntoElement { + layer(WallpaperLayer::Preview, strip, cx) } -fn layer(under_chrome: bool, cx: &App) -> impl IntoElement { - let opacity = cx.try_global::().map_or(1.0, |effects| effects.layout.opacity); +#[derive(Clone, Copy)] +enum WallpaperLayer { + Card, + Window, + Preview, +} + +fn layer( + layer: WallpaperLayer, + strip: Option<(Pixels, Arc)>, + cx: &App, +) -> impl IntoElement { + let effects = cx.try_global::(); + let opacity = effects.map_or(1.0, |effects| effects.layout.opacity); + let extended_static = + effects.is_some_and(|effects| effects.layout.cover_chrome && !effects.kind.is_animated()); + let opacity = match layer { + WallpaperLayer::Card if extended_static => extended_card_reveal(opacity), + WallpaperLayer::Preview if extended_static => { + let underlay = opacity * (1.0 - chrome_surface_opacity(cx)); + underlay + (1.0 - underlay) * extended_card_reveal(opacity) + }, + _ => opacity, + }; // Canvas's style.paint does not apply element opacity in pinned GPUI; // Div owns that scope for its child, without baking alpha into the image. div().absolute().inset_0().opacity(opacity).child( gpui::canvas( |_, _, _| (), - move |bounds, _, window, cx| paint_wallpaper(bounds, under_chrome, window, cx), + move |bounds, _, window, cx| { + if opacity > 0.0 { + paint_wallpaper(bounds, layer, strip, window, cx); + } + }, ) .size_full(), ) } +fn extended_card_reveal(opacity: f32) -> f32 { + let baseline = pebrel_settings::DEFAULT_BACKGROUND_IMAGE_OPACITY; + ((opacity - baseline) / (1.0 - baseline)).clamp(0.0, 1.0) +} + fn image_bounds( wp: &Wallpaper, layout: WallpaperLayout, @@ -614,35 +667,81 @@ fn image_bounds( ) } -fn paint_wallpaper(bounds: Bounds, under_chrome: bool, window: &mut Window, cx: &mut App) { +fn paint_wallpaper( + bounds: Bounds, + layer: WallpaperLayer, + strip: Option<(Pixels, Arc)>, + window: &mut Window, + cx: &mut App, +) { let Some(effects) = cx.try_global::() else { return }; let layout = effects.layout; - // In the previous CPU crop path an offset card produced an empty overlay - // (negative crop offsets cast to u32). Repainting the source here would - // remove the visible scrim. Preserve that appearance directly, without - // retaining the broken crop arithmetic or an empty card-sized bitmap. - if layout.opacity <= 0.0 || under_chrome != layout.cover_chrome { + if layout.opacity <= 0.0 { return; } - if animated::paint(bounds, under_chrome, layout, window, cx) { + let under_chrome = matches!(layer, WallpaperLayer::Window); + if matches!(layer, WallpaperLayer::Window) && !layout.cover_chrome { + return; + } + if effects.kind.is_animated() { + if !matches!(layer, WallpaperLayer::Preview) && under_chrome == layout.cover_chrome { + animated::paint(bounds, under_chrome, layout, window, cx); + } return; } let effects = cx.global::(); let Some(wp) = effects.wallpaper.as_ref() else { return }; let Some(image) = wp.image.as_ref() else { return }; + let radius = if matches!(layer, WallpaperLayer::Card) { + crate::gpui_shell::theme::card_radius(cx) + } else { + px(0.0) + }; let anchor = if layout.cover_chrome { Bounds::new(point(px(0.0), px(0.0)), window.viewport_size()) } else { bounds }; let image_bounds = image_bounds(wp, layout, anchor, window.scale_factor().max(0.5)); - let radius = if under_chrome { px(0.0) } else { crate::gpui_shell::theme::card_radius(cx) }; let corners = image_corners(bounds, image_bounds, radius); - if let Err(error) = window.paint_image(bounds, image_bounds, corners, image.clone(), 0, false) { + let paint_sharp = |window: &mut Window| { + window.paint_image(bounds, image_bounds, corners, image.clone(), 0, false) + }; + let result = if let Some((width, strip)) = strip { + let strip_rect = Bounds::new(anchor.origin, size(width, anchor.size.height)); + let strip_corners = image_corners(bounds, strip_rect, radius); + let right = Bounds::from_corners( + point(bounds.left().max(strip_rect.right()), bounds.top()), + bounds.bottom_right(), + ); + window.paint_image(bounds, strip_rect, strip_corners, strip, 0, false).and_then(|()| { + if right.size.width > px(0.0) { + window.with_content_mask(Some(ContentMask { bounds: right }), paint_sharp) + } else { + Ok(()) + } + }) + } else { + paint_sharp(window) + }; + if let Err(error) = result { log::warn!("background image paint failed: {error}"); } } +#[cfg(test)] +mod opacity_tests { + use super::*; + + #[test] + fn extended_wallpaper_keeps_its_default_scrim_and_reveals_the_original_at_full_opacity() { + assert_eq!(extended_card_reveal(0.0), 0.0); + assert_eq!(extended_card_reveal(pebrel_settings::DEFAULT_BACKGROUND_IMAGE_OPACITY), 0.0); + assert!((extended_card_reveal(0.69) - 0.5).abs() < 1e-6); + assert_eq!(extended_card_reveal(1.0), 1.0); + } +} + fn image_corners(bounds: Bounds, image: Bounds, radius: Pixels) -> Corners { // GPUI rounds the visible intersection. Interior letterbox edges are square; // only corners shared with the card inherit its radius. diff --git a/pebrel_app/src/gpui_shell/wallpaper/image_loader.rs b/pebrel_app/src/gpui_shell/wallpaper/image_loader.rs index c589b9771..a897e7227 100644 --- a/pebrel_app/src/gpui_shell/wallpaper/image_loader.rs +++ b/pebrel_app/src/gpui_shell/wallpaper/image_loader.rs @@ -8,6 +8,8 @@ use std::time::SystemTime; use image::{DynamicImage, ImageDecoder, ImageError, ImageReader, RgbaImage}; +use super::optics::{self, StripGeometry}; + // These bound the resources owned by this loader, not the entire process or a // decoder's undocumented scratch space. One job runs at a time across windows. const MAX_FILE_BYTES: u64 = 64 * 1024 * 1024; @@ -83,6 +85,20 @@ pub(super) fn load_preview(request: Request) -> Result, Load Ok(Some(loaded)) } +pub(super) fn prepare_strip( + bytes: &[u8], + dimensions: (u32, u32), + geometry: StripGeometry, + tint: [u8; 3], + cancelled: impl Fn() -> bool, +) -> Option { + let _preparation = PREPARATION.lock().unwrap_or_else(|error| error.into_inner()); + if cancelled() { + return None; + } + optics::workspace_strip(bytes, dimensions, geometry, tint, cancelled) +} + fn load_inner(request: Request) -> Result, LoadError> { if request.cancelled() { return Ok(None); diff --git a/pebrel_app/src/gpui_shell/wallpaper/optics.rs b/pebrel_app/src/gpui_shell/wallpaper/optics.rs new file mode 100644 index 000000000..bca1ef46b --- /dev/null +++ b/pebrel_app/src/gpui_shell/wallpaper/optics.rs @@ -0,0 +1,265 @@ +//! Wallpaper filters and masks work on BGRA pixels off the UI thread. + +use image::{Rgba, RgbaImage, imageops}; + +pub(super) const FEATHER: f32 = 64.0; +const SOFT_OVERHANG: f32 = 20.0; +const PADDING: f32 = 26.0; +const MAX_STRIP_PIXELS: f32 = 512.0 * 1024.0; + +#[derive(Clone, Copy, PartialEq)] +pub(super) struct StripGeometry { + pub sidebar: f32, + pub width: f32, + pub height: f32, + pub scale: f32, + pub image: [f32; 4], +} + +pub(super) fn workspace_strip( + bytes: &[u8], + (source_width, source_height): (u32, u32), + geometry: StripGeometry, + tint: [u8; 3], + cancelled: impl Fn() -> bool, +) -> Option { + let StripGeometry { sidebar, width, height, scale, image } = geometry; + // Bound the strip and its filter intermediates even for giant virtual desktops. + let scale = scale + .min(1.5) + .min((MAX_STRIP_PIXELS / (width * height)).sqrt()) + .min(1024.0 / (width + 2.0 * PADDING)) + .min(2048.0 / (height + 2.0 * PADDING)); + let w = (width * scale).floor().max(1.0) as u32; + let h = (height * scale).floor().max(1.0) as u32; + let pad = (PADDING * scale).ceil() as u32; + let pitch_x = width / w as f32; + let pitch_y = height / h as f32; + let columns: Vec<_> = (0..w + 2 * pad) + .map(|x| sample_axis(x, pad, pitch_x, image[0], image[2], source_width)) + .collect(); + let weights: Vec<_> = (0..w).map(|x| masks((x as f32 + 0.5) * pitch_x, sidebar)).collect(); + + let mut source = RgbaImage::new(w + 2 * pad, h + 2 * pad); + for (y, row) in source.rows_mut().enumerate() { + if cancelled() { + return None; + } + if let Some(vertical) = + sample_axis(y as u32, pad, pitch_y, image[1], image[3], source_height) + { + let stride = source_width as usize * 4; + let top = &bytes[vertical.low * stride..][..stride]; + let bottom = &bytes[vertical.high * stride..][..stride]; + for (pixel, column) in row.zip(&columns) { + if let Some(horizontal) = column { + *pixel = bilinear(top, bottom, *horizontal, vertical.weight); + } + } + } + } + + let mut result = RgbaImage::new(w, h); + { + let mid = filtered(&source, 2.6 * scale, 0.55); + for (x, y, pixel) in result.enumerate_pixels_mut() { + let (mid_alpha, _) = weights[x as usize]; + *pixel = mix( + *source.get_pixel(x + pad, y + pad), + *mid.get_pixel(x + pad, y + pad), + mid_alpha, + ); + } + } + if cancelled() { + return None; + } + let soft = filtered(&source, 5.5 * scale, 1.0); + drop(source); + if cancelled() { + return None; + } + for (y, row) in result.rows_mut().enumerate() { + if cancelled() { + return None; + } + let logical_y = (y as f32 + 0.5) * pitch_y; + for (x, pixel) in row.enumerate() { + let logical_x = (x as f32 + 0.5) * pitch_x; + let (_, soft_alpha) = weights[x]; + if soft_alpha > 0.0 { + let mut frost = *soft.get_pixel(x as u32 + pad, y as u32 + pad); + let (grain_value, grain_alpha) = grain(logical_x as u32, logical_y as u32); + color_overlay(&mut frost, tint, 0.12); + color_overlay(&mut frost, [grain_value; 3], grain_alpha * 0.030); + *pixel = mix(*pixel, frost, soft_alpha); + } + *pixel = unpremultiply(*pixel); + } + } + Some(result) +} + +fn masks(x: f32, sidebar: f32) -> (f32, f32) { + let mid = (x - (sidebar - 12.0)) / (FEATHER + 12.0); + let soft = x / (sidebar + SOFT_OVERHANG); + ( + stops(mid, &[(0.0, 1.0), (0.45, 0.52), (0.78, 0.14), (1.0, 0.0)]), + stops(soft, &[(0.0, 1.0), (0.56, 0.92), (0.84, 0.34), (1.0, 0.0)]), + ) +} + +fn stops(position: f32, stops: &[(f32, f32)]) -> f32 { + for pair in stops.windows(2) { + let [(start, from), (end, to)] = [pair[0], pair[1]]; + if position <= end { + let weight = ((position - start) / (end - start)).max(0.0); + return from + (to - from) * weight; + } + } + 0.0 +} + +fn filtered(source: &RgbaImage, sigma: f32, strength: f32) -> RgbaImage { + let contrast = 1.0 - 0.24 * strength; + let exposure = 1.0 - 0.06 * strength; + let gain = contrast * exposure; + let offset = (1.0 - contrast) * exposure * 0.5; + let prepared = RgbaImage::from_fn(source.width(), source.height(), |x, y| { + let mut pixel = *source.get_pixel(x, y); + let [b, g, r, alpha] = pixel.0.map(f32::from); + let luma = 0.072 * b + 0.715 * g + 0.213 * r; + let bias = alpha * offset - luma * gain * 0.14; + // Contrast, exposure and saturation are affine in premultiplied color. + // Only saturation can clip at this stage. + for channel in &mut pixel.0[..3] { + *channel = byte((f32::from(*channel) * gain * 1.14 + bias).min(alpha)); + } + pixel + }); + imageops::fast_blur(&prepared, sigma) +} + +#[derive(Clone, Copy)] +struct Sample { + low: usize, + high: usize, + weight: u32, +} + +fn sample_axis( + index: u32, + pad: u32, + pitch: f32, + origin: f32, + length: f32, + extent: u32, +) -> Option { + let coordinate = ((index as f32 - pad as f32 + 0.5) * pitch - origin) / length; + if !(0.0..1.0).contains(&coordinate) { + return None; + } + let sample = (coordinate * extent as f32 - 0.5).clamp(0.0, (extent - 1) as f32); + let low = sample as usize; + Some(Sample { + low, + high: (low + 1).min(extent as usize - 1), + weight: (sample.fract() * 256.0 + 0.5) as u32, + }) +} + +fn bilinear(top: &[u8], bottom: &[u8], horizontal: Sample, vertical: u32) -> Rgba { + let x = horizontal.weight; + let sample = |row: &[u8], index: usize| { + let i = index * 4; + premultiply(Rgba([row[i], row[i + 1], row[i + 2], row[i + 3]])) + }; + let tl = sample(top, horizontal.low); + let tr = sample(top, horizontal.high); + let bl = sample(bottom, horizontal.low); + let br = sample(bottom, horizontal.high); + Rgba(std::array::from_fn(|i| { + let top = u32::from(tl[i]) * (256 - x) + u32::from(tr[i]) * x; + let bottom = u32::from(bl[i]) * (256 - x) + u32::from(br[i]) * x; + ((top * (256 - vertical) + bottom * vertical + 32768) >> 16) as u8 + })) +} + +fn premultiply(mut pixel: Rgba) -> Rgba { + let alpha = u16::from(pixel[3]); + if alpha != 255 { + for channel in &mut pixel.0[..3] { + *channel = ((u16::from(*channel) * alpha + 127) / 255) as u8; + } + } + pixel +} + +fn unpremultiply(mut pixel: Rgba) -> Rgba { + let alpha = u16::from(pixel[3]); + if alpha > 0 && alpha < 255 { + for channel in &mut pixel.0[..3] { + *channel = ((u16::from(*channel) * 255 + alpha / 2) / alpha).min(255) as u8; + } + } + pixel +} + +fn mix(a: Rgba, b: Rgba, weight: f32) -> Rgba { + Rgba(std::array::from_fn(|i| byte(f32::from(a[i]) * (1.0 - weight) + f32::from(b[i]) * weight))) +} + +fn color_overlay(pixel: &mut Rgba, color: [u8; 3], opacity: f32) { + let alpha = f32::from(pixel[3]) / 255.0; + for (channel, color) in pixel.0[..3].iter_mut().zip(color) { + *channel = byte(f32::from(*channel) * (1.0 - opacity) + f32::from(color) * opacity * alpha); + } +} + +fn grain(x: u32, y: u32) -> (u8, f32) { + // Fixed 128² tile. Black and white are equally likely, and a 3% strength + // applied to the tile's mean alpha yields roughly 1.2% in the soft band. + let mut hash = ((y % 128) * 128 + x % 128).wrapping_add(1); + hash = ((hash >> 16) ^ hash).wrapping_mul(0x45d9f3b); + hash = ((hash >> 16) ^ hash).wrapping_mul(0x45d9f3b); + hash ^= hash >> 16; + (if hash & 1 == 0 { 0 } else { 255 }, ((hash >> 8) % 190) as f32 / 255.0) +} + +fn byte(value: f32) -> u8 { + (value + 0.5) as u8 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn l4_masks_end_at_the_reference_distances() { + let (mid, soft) = masks(0.0, 234.0); + assert_eq!((mid, soft), (1.0, 1.0)); + let (mid, soft) = masks(254.0, 234.0); + assert!(mid > 0.0); + assert_eq!(soft, 0.0); + assert_eq!(masks(298.0, 234.0), (0.0, 0.0)); + } + + #[test] + fn white_wallpaper_is_compressed_at_the_sidebar_and_retains_its_right_edge() { + let source = RgbaImage::from_pixel(360, 80, Rgba([255; 4])); + let geo = StripGeometry { + sidebar: 234.0, + width: 298.0, + height: 80.0, + scale: 1.0, + image: [0.0, 0.0, 360.0, 80.0], + }; + let strip = + workspace_strip(source.as_raw(), source.dimensions(), geo, [24; 3], || false).unwrap(); + assert!(strip.get_pixel(20, 40)[0] < 200); + assert_eq!(strip.get_pixel(297, 40).0, [255; 4]); + assert!( + workspace_strip(source.as_raw(), source.dimensions(), geo, [24; 3], || true).is_none() + ); + } +} diff --git a/pebrel_app/src/gpui_shell/wallpaper/workspace_strip.rs b/pebrel_app/src/gpui_shell/wallpaper/workspace_strip.rs new file mode 100644 index 000000000..a9a982338 --- /dev/null +++ b/pebrel_app/src/gpui_shell/wallpaper/workspace_strip.rs @@ -0,0 +1,137 @@ +//! Owns the fitted wallpaper strip for one window. + +use super::{optics, *}; +use gpui::Context; +use std::time::Duration; + +#[derive(Clone, PartialEq)] +struct Request { + source: Arc, + geometry: optics::StripGeometry, + tint: [u8; 3], +} + +#[derive(Default)] +pub(in crate::gpui_shell) struct WorkspaceStrip { + request: Option, + image: Option>, + generation: Arc, + loading: bool, +} + +impl WorkspaceStrip { + pub(in crate::gpui_shell) fn new(cx: &mut Context) -> Self { + cx.on_release(|strip, cx| { + strip.generation.fetch_add(1, Ordering::Release); + strip.retire(cx); + }) + .detach(); + Self::default() + } + + pub(in crate::gpui_shell) fn configure( + &mut self, + sidebar: Option, + window: &Window, + cx: &mut Context, + ) -> Option<(Pixels, Arc)> { + let request = sidebar.and_then(|width| Request::for_window(width, window, cx)); + if self.request != request { + self.request = request; + self.generation.fetch_add(1, Ordering::Release); + self.retire(cx); + self.start(cx); + } + self.image + .as_ref() + .zip(self.request.as_ref()) + .map(|(image, request)| (px(request.geometry.width), image.clone())) + } + + fn retire(&mut self, cx: &mut App) { + retire_image(self.image.take(), cx); + } + + fn start(&mut self, cx: &mut Context) { + if self.loading { + return; + } + let Some(request) = self.request.clone() else { return }; + self.loading = true; + let generation = self.generation.clone(); + let version = generation.load(Ordering::Acquire); + let settle = cx.background_executor().timer(Duration::from_millis(90)); + let task = cx.background_executor().spawn(async move { + settle.await; + let cancelled = || generation.load(Ordering::Acquire) != version; + let dimensions = request.source.size(0); + image_loader::prepare_strip( + request.source.as_bytes(0)?, + (dimensions.width.0 as u32, dimensions.height.0 as u32), + request.geometry, + request.tint, + cancelled, + ) + }); + cx.spawn(async move |this, cx| { + let image = task.await; + let _ = this.update(cx, |strip, cx| { + strip.loading = false; + if strip.generation.load(Ordering::Acquire) != version { + strip.start(cx); + } else if let Some(pixels) = image { + strip.image = Some(Arc::new(RenderImage::new([Frame::new(pixels)]))); + cx.notify(); + } + }); + }) + .detach(); + } +} + +impl Request { + fn for_window(sidebar: f32, window: &Window, cx: &App) -> Option { + let skin = crate::gpui_shell::theme::resolved_skin(cx); + let effects = cx.try_global::()?; + let layout = effects.layout; + let wallpaper = effects.wallpaper.as_ref()?; + if skin.is_light + || effects.kind.is_animated() + || !layout.cover_chrome + || layout.opacity <= 0.0 + { + return None; + } + let source = wallpaper.image.as_ref()?.clone(); + let viewport = window.viewport_size(); + let scale = window.scale_factor().max(0.5); + let width = f32::from(viewport.width); + let height = f32::from(viewport.height); + if width <= 0.0 || height <= 0.0 { + return None; + } + let anchor = Bounds::new(point(px(0.0), px(0.0)), viewport); + let rect = image_bounds(wallpaper, layout, anchor, scale); + if rect.size.width <= px(0.0) || rect.size.height <= px(0.0) { + return None; + } + let bg = skin.panel; + let tint = [bg.b, bg.g, bg.r].map(|channel| (f32::from(channel) * 0.65).round() as u8); + Some(Self { + source, + geometry: optics::StripGeometry { + sidebar, + width: (sidebar + optics::FEATHER).min(width), + height, + scale, + image: [ + rect.origin.x.into(), + rect.origin.y.into(), + rect.size.width.into(), + rect.size.height.into(), + ], + }, + tint, + }) + } +} diff --git a/pebrel_app/src/gpui_shell/widgets/segmented.rs b/pebrel_app/src/gpui_shell/widgets/segmented.rs index 671ea216b..f8e24aa8f 100644 --- a/pebrel_app/src/gpui_shell/widgets/segmented.rs +++ b/pebrel_app/src/gpui_shell/widgets/segmented.rs @@ -173,7 +173,14 @@ impl RenderOnce for SegmentedRow { let selector = id.clone(); animate_indicator( self.id.clone(), - self.indicator.id(id).debug_selector(move || selector.to_string()).absolute(), + self.indicator + .when_some( + crate::gpui_shell::theme::settings_segment_glass(cx), + |surface, glass| glass.apply(surface.shadow(Vec::new())), + ) + .id(id) + .debug_selector(move || selector.to_string()) + .absolute(), left, Some([width, top, height]), window, diff --git a/pebrel_app/src/gpui_shell/workspace.rs b/pebrel_app/src/gpui_shell/workspace.rs index 15649bc77..f2abc0f11 100644 --- a/pebrel_app/src/gpui_shell/workspace.rs +++ b/pebrel_app/src/gpui_shell/workspace.rs @@ -683,7 +683,7 @@ pub struct NebulaWorkspace { /// pane 矩形的帧记录(ctrl+alt+方向 的最近邻导航用)。 pane_bounds: PaneBoundsStore, /// 标题栏背景使用本帧实际终端列边界,与两侧面板和卡缝连续衔接。 - titlebar_background: window_titlebar::TitleBarBackground, + window_backdrop: window_titlebar::WindowBackdrop, theme_transition: crate::gpui_shell::theme::ThemeTransition, /// GPUI presentation over the shared old-shell command catalog. command_palette_open: bool, @@ -953,7 +953,7 @@ impl NebulaWorkspace { reader_focus: None, split_bounds: Rc::new(RefCell::new(HashMap::new())), pane_bounds: PaneBoundsStore::default(), - titlebar_background: window_titlebar::TitleBarBackground::default(), + window_backdrop: window_titlebar::WindowBackdrop::new(cx), theme_transition: crate::gpui_shell::theme::ThemeTransition::default(), command_palette_open: false, command_palette_input, diff --git a/pebrel_app/src/gpui_shell/workspace/command_manager/groups.rs b/pebrel_app/src/gpui_shell/workspace/command_manager/groups.rs index 8279f57bb..5358ef42a 100644 --- a/pebrel_app/src/gpui_shell/workspace/command_manager/groups.rs +++ b/pebrel_app/src/gpui_shell/workspace/command_manager/groups.rs @@ -1,6 +1,7 @@ //! Command organization UI; persistence remains in `saved_commands`. use super::*; +use crate::gpui_shell::theme::selection_glass; use crate::i18n::Message; use crate::saved_commands::BUILTIN_GROUP_ID; use gpui::{Anchor, AnyElement, DismissEvent, Point, anchored, deferred}; @@ -222,6 +223,7 @@ impl NebulaWorkspace { let active = cx.theme().list_active; let muted = cx.theme().muted_foreground; let selected = index == self.command_manager_selection.cursor; + let glass = selection_glass(cx); let delete_id = Some(id.clone()); let rename_id = (id != BUILTIN_GROUP_ID).then(|| id.clone()); let click_id = id.clone(); @@ -244,6 +246,12 @@ impl NebulaWorkspace { .role(gpui::Role::Button) .aria_label(name.clone()) .when(selected, |row| row.bg(active)) + .when_some( + glass, + |row, glass| { + if selected { glass.apply(row) } else { glass.reserve(row) } + }, + ) .when(!selected, |row| row.hover(move |row| row.bg(hover))) .active(move |row| row.bg(active)) .drag_over::(move |row, _, _, _| row.bg(active)) diff --git a/pebrel_app/src/gpui_shell/workspace/command_manager/rows.rs b/pebrel_app/src/gpui_shell/workspace/command_manager/rows.rs index 369b70b38..3e18b13b3 100644 --- a/pebrel_app/src/gpui_shell/workspace/command_manager/rows.rs +++ b/pebrel_app/src/gpui_shell/workspace/command_manager/rows.rs @@ -1,5 +1,7 @@ //! Visible command rows, shared by folder contents and global search. + use super::*; +use crate::gpui_shell::theme::selection_glass; use gpui::AnyElement; impl NebulaWorkspace { @@ -22,6 +24,7 @@ impl NebulaWorkspace { let mono_family = theme.mono_font_family.clone(); let language = crate::gpui_shell::config::ui_language(cx); let selected = index == self.command_manager_selection.cursor; + let glass = selection_glass(cx); let selecting = self.command_manager_selection.selecting; let checked = self.command_manager_selection.ids.contains(&command.id); let select_id = command.id.clone(); @@ -87,6 +90,12 @@ impl NebulaWorkspace { .rounded(px(radius::CONTROL)) .cursor_pointer() .when(selected, |row| row.bg(selected_bg)) + .when_some( + glass, + |row, glass| { + if selected { glass.apply(row) } else { glass.reserve(row) } + }, + ) .when(!selected, |row| row.group_hover(hover_group.clone(), |row| row.bg(hover_bg))) .on_click(cx.listener(move |this, _, window, cx| { this.command_manager_selection.cursor = index; diff --git a/pebrel_app/src/gpui_shell/workspace/file_tree.rs b/pebrel_app/src/gpui_shell/workspace/file_tree.rs index ed1ccea09..08f85ac0f 100644 --- a/pebrel_app/src/gpui_shell/workspace/file_tree.rs +++ b/pebrel_app/src/gpui_shell/workspace/file_tree.rs @@ -3,6 +3,8 @@ //! 几何与密度以旧 OpenGL 壳的 `display::side_panel::panel_layout` //! (side_panel.rs:1695)和它的行水洗(同文件 2712-2800)为基准,不自创数字。 +use crate::gpui_shell::theme::selected_glass; + use crate::display::side_panel::PanelNotice; use std::ops::Range; use std::path::PathBuf; @@ -294,8 +296,8 @@ impl NebulaWorkspace { .border_1() .border_color(gpui::transparent_black()) .text_color(fg) - .when(selected, |item| item.bg(selected_bg).border_color(selected_ring)) - .hover(|item| item.bg(hover)) + .when(selected, |item| selected_glass(item.bg(selected_bg).border_color(selected_ring), cx)) + .when(!selected || !cx.theme().is_dark(), |item| item.hover(|item| item.bg(hover))) .when(!is_dir && crate::platform::file_preview::supports(&preview_path), |item| { item.tooltip(move |_, cx| { cx.new(|cx| crate::gpui_shell::file_preview::FilePreview::new(preview_path.clone(), cx)).into() diff --git a/pebrel_app/src/gpui_shell/workspace/palette.rs b/pebrel_app/src/gpui_shell/workspace/palette.rs index 4dda6d6e3..65cc5a8f9 100644 --- a/pebrel_app/src/gpui_shell/workspace/palette.rs +++ b/pebrel_app/src/gpui_shell/workspace/palette.rs @@ -1,4 +1,5 @@ use super::*; +use crate::gpui_shell::theme::selected_glass; #[cfg(all(test, feature = "gpui-test-support"))] mod tests; @@ -470,7 +471,7 @@ impl NebulaWorkspace { .tooltip(move |window, cx| { gpui_component::tooltip::Tooltip::new(row_tooltip.clone()).build(window, cx) }) - .when(selected, |row| row.bg(selected_bg)) + .when(selected, |row| selected_glass(row.bg(selected_bg), cx)) .when(!selected, |row| row.group_hover(hover_group.clone(), |row| row.bg(hover_bg))) .when_some(icon_slot, |row, icon| row.child(icon)) .child( diff --git a/pebrel_app/src/gpui_shell/workspace/pane_header.rs b/pebrel_app/src/gpui_shell/workspace/pane_header.rs index 959e347d2..09e736bbd 100644 --- a/pebrel_app/src/gpui_shell/workspace/pane_header.rs +++ b/pebrel_app/src/gpui_shell/workspace/pane_header.rs @@ -400,6 +400,9 @@ impl NebulaWorkspace { .ghost() .xsmall() .selected(broadcast) + .when(broadcast, |button| { + crate::gpui_shell::theme::selected_glass(button, cx) + }) .tooltip(if broadcast { language.text(Message::WorkspacePaneStopBroadcastInput) } else { @@ -427,6 +430,9 @@ impl NebulaWorkspace { .ghost() .xsmall() .selected(zoomed) + .when(zoomed, |button| { + crate::gpui_shell::theme::selected_glass(button, cx) + }) .tooltip(if zoomed { language.text(Message::WorkspacePaneRestoreLayout) } else { diff --git a/pebrel_app/src/gpui_shell/workspace/render.rs b/pebrel_app/src/gpui_shell/workspace/render.rs index b528a9e9d..6bbcb9028 100644 --- a/pebrel_app/src/gpui_shell/workspace/render.rs +++ b/pebrel_app/src/gpui_shell/workspace/render.rs @@ -16,7 +16,7 @@ impl Render for NebulaWorkspace { // 终端卡几何取一次,布局与壳色带共用同一个实例——两处各取一次也算 // 「各写一份」,主题在这一帧中途换掉就会出现半旧半新的卡缝。 let card_style = crate::gpui_shell::theme::PaneCardStyle::current(cx); - let titlebar_background = self.titlebar_background.clone(); + let window_backdrop = self.window_backdrop.clone(); let draw_file_divider = self.side_panel.open; let sidebar_logo_target_px = (TAB_LABEL_ICON_SIZE * window.scale_factor()).round().max(1.0) as u32; @@ -67,8 +67,21 @@ impl Render for NebulaWorkspace { } else { crate::gpui_shell::theme::card_content_bg(cx) }; + let wallpaper_peek = settings_active + && self + .settings_surface + .as_ref() + .is_some_and(|(pane, _)| pane.read(cx).wallpaper_peeking()); let top_tabs = self.tabs_position == pebrel_settings::TabsPositionName::Top; let reader_focus = self.reader_focus_active(cx); + let sidebar_collapsed = + self.settings_restore_sidebar_collapsed.unwrap_or(self.sidebar_collapsed); + let wallpaper_sidebar = + (!top_tabs && !reader_focus && !sidebar_collapsed).then_some(self.sidebar_width); + let workspace_strip = self + .window_backdrop + .wallpaper + .update(cx, |strip, cx| strip.configure(wallpaper_sidebar, window, cx)); // dock 预览:被拖 tab 悬于终端区时高亮目标半区(松手即挂到那侧)。 let dock_preview = self .tab_drag @@ -83,6 +96,7 @@ impl Render for NebulaWorkspace { .size_full() .flex() .flex_col() + .relative() // 旧壳每个像素只画一次:整窗先透明清屏,再分别画标题栏、侧栏、 // 卡外壳与卡底。根节点不能再铺一张半透明底。 .bg(gpui::transparent_black()) @@ -256,12 +270,11 @@ impl Render for NebulaWorkspace { .on_action(cx.listener(|this, _: &OpenQuickJump, window, cx| { this.open_quick_jump_palette(window, cx); })) - .child( - // 用户显式配置的背景图画在 chrome 之下;系统 Mica/Aero/Acrylic - // 位于整个 GPUI 内容层下方,由 DWM 合成,不能在这里读取壁纸仿画。 - // 拓展模式只在此绘图,壳/卡衬底在其上保留原有文字对比度。 - crate::gpui_shell::wallpaper::window_layer(cx), - ) + .child(if wallpaper_peek { + crate::gpui_shell::wallpaper::peek_layer(workspace_strip.clone(), cx).into_any_element() + } else { + crate::gpui_shell::wallpaper::window_layer(workspace_strip.clone(), cx).into_any_element() + }) .child( self.render_window_title_bar( settings_active, @@ -279,7 +292,9 @@ impl Render for NebulaWorkspace { .when(!top_tabs && !settings_active && !reader_focus, |row| { row.child(self.render_sidebar_slot(window, cx)) }) - .child( + .child(if settings_active { + div().flex_1().min_w_0().children(content) + } else { // 终端卡(一体化外壳):唯一的结构分界。圆角、卡缝、投影、 // 竖线四项全部来自 `PaneCardStyle`(主题默认叠用户覆盖), // 所以「浮起的圆角卡」和「铺满到窗口边 + 一条竖线」是同一 @@ -295,7 +310,7 @@ impl Render for NebulaWorkspace { .relative() .child( gpui::canvas( - move |bounds, _, _| titlebar_background.record_pane(bounds), + move |bounds, _, _| window_backdrop.record_pane(bounds), |bounds, _, window, cx| { // 卡缝、圆角、竖线全部读同一份 style 真源: // 布局的 padding 与这里的壳色带必须逐边对上, @@ -335,7 +350,7 @@ impl Render for NebulaWorkspace { // 壁纸层(卡底色之上、内容之下,覆盖整卡含 // 内边距带):卡模式按卡定位;拓展模式由 // 窗口底层统一绘图,此处不覆盖原有衬底。 - crate::gpui_shell::wallpaper::card_layer(cx), + crate::gpui_shell::wallpaper::card_layer(workspace_strip, cx), ) .children(content), ) @@ -351,12 +366,24 @@ impl Render for NebulaWorkspace { ) .absolute() .inset_0(), - ), - ) - .when(!reader_focus, |row| { + ) + }) + .when(!settings_active && !reader_focus, |row| { row.child(self.render_side_panel_slot(window, cx)) }), ) + .when(settings_active && cx.theme().is_dark(), |root| { + root.child( + div() + .debug_selector(|| "settings-sidebar-divider".to_owned()) + .absolute() + .top_0() + .bottom_0() + .left(px(crate::gpui_shell::settings_pane::SETTINGS_NAV_WIDTH - 1.0)) + .w(px(1.0)) + .bg(gpui::white().opacity(if wallpaper_peek { 0.012 } else { 0.075 })), + ) + }) .when_some(dock_preview, |root, (x, y, w, h)| { root.child( div() diff --git a/pebrel_app/src/gpui_shell/workspace/settings_navigation.rs b/pebrel_app/src/gpui_shell/workspace/settings_navigation.rs index ad76e7553..1d388b07c 100644 --- a/pebrel_app/src/gpui_shell/workspace/settings_navigation.rs +++ b/pebrel_app/src/gpui_shell/workspace/settings_navigation.rs @@ -33,6 +33,7 @@ impl NebulaWorkspace { ) { match event { SettingsPaneEvent::Close => self.close_settings(window, cx), + SettingsPaneEvent::WallpaperPreview => cx.notify(), SettingsPaneEvent::Changed | SettingsPaneEvent::BackupRestored => { crate::prompt_suggestions::service::invalidate_config(); self.apply_runtime_settings(cx); @@ -147,6 +148,9 @@ impl NebulaWorkspace { return; } self.settings_open = false; + if let Some((view, _)) = &self.settings_surface { + view.update(cx, |pane, cx| pane.set_wallpaper_peek(false, cx)); + } self.sync_settings_layout(tab_reveal_instant(cx)); let restore_panel = std::mem::take(&mut self.settings_restore_side_panel_open); if restore_panel && !self.side_panel.open { diff --git a/pebrel_app/src/gpui_shell/workspace/sidebar.rs b/pebrel_app/src/gpui_shell/workspace/sidebar.rs index 0fe53a71e..d454d32c3 100644 --- a/pebrel_app/src/gpui_shell/workspace/sidebar.rs +++ b/pebrel_app/src/gpui_shell/workspace/sidebar.rs @@ -179,6 +179,7 @@ impl NebulaWorkspace { let faint = crate::gpui_shell::theme::faint_ink(cx); let active_bg = theme.sidebar_accent; let active_fg = theme.sidebar_accent_foreground; + let glass = crate::gpui_shell::theme::selection_glass(cx); let hover_bg = theme.list_hover; let dark = theme.is_dark(); // 标题走 UI sans,路径/状态短标才用 Normal 等宽;有图标时才占图标槽。 @@ -356,7 +357,10 @@ impl NebulaWorkspace { // tab chrome 使用终端 Regular face,所有子文本从这里继承常规字重。 .font_weight(FontWeight::NORMAL) .cursor_pointer() - .when(active, |item| item.bg(active_bg).text_color(active_fg)) + .when(active, |item| { + let item = item.text_color(active_fg); + if let Some(glass) = glass { glass.apply(item) } else { item.bg(active_bg) } + }) .when(!active && !dragged, |item| { item.text_color(muted).hover(|style| style.bg(hover_bg)) }) diff --git a/pebrel_app/src/gpui_shell/workspace/top_tabs.rs b/pebrel_app/src/gpui_shell/workspace/top_tabs.rs index 05d9d6a49..777c22cfd 100644 --- a/pebrel_app/src/gpui_shell/workspace/top_tabs.rs +++ b/pebrel_app/src/gpui_shell/workspace/top_tabs.rs @@ -139,6 +139,7 @@ impl NebulaWorkspace { let muted = theme.muted_foreground; let active_bg = theme.sidebar_accent; let active_fg = theme.sidebar_accent_foreground; + let glass = crate::gpui_shell::theme::selection_glass(cx); let hover_bg = theme.list_hover; let dark = theme.is_dark(); let settings = cx.try_global::(); @@ -299,7 +300,10 @@ impl NebulaWorkspace { // TitleBar 的父层是 WindowControlArea::Drag;tab 必须自己 // 占住普通鼠标命中区,滚轮仍交给外层标签滚动容器。 .block_mouse_except_scroll() - .when(active, |item| item.bg(active_bg).text_color(active_fg)) + .when(active, |item| { + let item = item.text_color(active_fg); + if let Some(glass) = glass { glass.apply(item) } else { item.bg(active_bg) } + }) .when(!active && !dragged, |item| { item.text_color(muted).hover(|style| style.bg(hover_bg)) }) @@ -719,6 +723,9 @@ impl NebulaWorkspace { ) .debug_selector(|| "command-manager-toggle".into()) .selected(self.command_manager_open) + .when(self.command_manager_open, |button| { + crate::gpui_shell::theme::selected_glass(button, cx) + }) .tooltip(language.text(Message::ChromeCommandList)) .on_click(cx.listener(|this, _, window, cx| { this.toggle_command_manager(window, cx); diff --git a/pebrel_app/src/gpui_shell/workspace/vcs_panel/rows.rs b/pebrel_app/src/gpui_shell/workspace/vcs_panel/rows.rs index d3234d29d..86e05bf6e 100644 --- a/pebrel_app/src/gpui_shell/workspace/vcs_panel/rows.rs +++ b/pebrel_app/src/gpui_shell/workspace/vcs_panel/rows.rs @@ -1,6 +1,8 @@ //! Construct only the Git/SVN rows requested by the virtual list. + use super::list_model::{RowOps, VcsRow}; use super::*; +use crate::gpui_shell::theme::selected_glass; impl NebulaWorkspace { pub(super) fn render_vcs_list(&self, cx: &mut Context) -> gpui::AnyElement { @@ -223,8 +225,10 @@ impl NebulaWorkspace { .gap_2() .items_center() .rounded_md() - .when(selected_row, |row| row.bg(selected_bg)) - .hover(|row| row.bg(hover)) + .when(selected_row, |row| selected_glass(row.bg(selected_bg), cx)) + .when(!selected_row || !cx.theme().is_dark(), |row| { + row.hover(|row| row.bg(hover)) + }) .child( div() .w(px(14.0)) diff --git a/pebrel_app/src/gpui_shell/workspace/window_titlebar.rs b/pebrel_app/src/gpui_shell/workspace/window_titlebar.rs index be13e57c3..f4f05ea00 100644 --- a/pebrel_app/src/gpui_shell/workspace/window_titlebar.rs +++ b/pebrel_app/src/gpui_shell/workspace/window_titlebar.rs @@ -1,4 +1,5 @@ use super::*; +use crate::gpui_shell::wallpaper::workspace_strip::WorkspaceStrip; use crate::{ gpui_shell::widgets::toolbar_button, i18n::Message, platform::window_chrome::TitleBarLayout, }; @@ -18,16 +19,25 @@ pub(super) fn effective_title_bar_height( /// Prepaint records the actual pane column before any titlebar paint runs. Keep /// this cell for the workspace lifetime, so resizing and panel animations do not /// allocate a new shared slot or duplicate the body's layout calculations. -#[derive(Clone, Default)] -pub(super) struct TitleBarBackground(Rc>>>); +#[derive(Clone)] +pub(super) struct WindowBackdrop { + pane: Rc>>>, + pub(super) wallpaper: Entity, +} + +impl WindowBackdrop { + pub(super) fn new(cx: &mut Context) -> Self { + let wallpaper = cx.new(WorkspaceStrip::new); + cx.observe(&wallpaper, |_, _, cx| cx.notify()).detach(); + Self { pane: Rc::default(), wallpaper } + } -impl TitleBarBackground { pub(super) fn record_pane(&self, bounds: Bounds) { - self.0.set(Some(bounds)); + self.pane.set(Some(bounds)); } fn element(&self, top_tabs: bool) -> gpui::Canvas<()> { - let pane_bounds = self.0.clone(); + let pane_bounds = self.pane.clone(); canvas( |_, _, _| (), move |bounds, _, window, cx| { @@ -191,7 +201,7 @@ impl NebulaWorkspace { title_bar_frame() .debug_selector(|| "workspace-titlebar".to_owned()) - .when(!settings_active, |title| title.child(self.titlebar_background.element(top_tabs))) + .when(!settings_active, |title| title.child(self.window_backdrop.element(top_tabs))) .child(bar) } } diff --git a/pebrel_settings/src/lib.rs b/pebrel_settings/src/lib.rs index 84933061c..f642b5eac 100644 --- a/pebrel_settings/src/lib.rs +++ b/pebrel_settings/src/lib.rs @@ -1170,6 +1170,7 @@ pub struct ThemeCardGeometry { /// 旧壳默认快速终端热键。 pub const DEFAULT_QUICK_TERMINAL_HOTKEY: &str = "ctrl+`"; +pub const DEFAULT_BACKGROUND_IMAGE_OPACITY: f32 = 0.38; pub const DEFAULT_SIDEBAR_WIDTH: f32 = 230.0; pub const MIN_SIDEBAR_WIDTH: f32 = 170.0; pub const MAX_SIDEBAR_WIDTH: f32 = 420.0; @@ -1324,7 +1325,7 @@ impl RuntimeSettings { background_image_opacity: raw .f32("background_image_opacity") .map(|o| o.clamp(0.0, 1.0)) - .unwrap_or(0.38), + .unwrap_or(DEFAULT_BACKGROUND_IMAGE_OPACITY), background_image_fit: raw.value("background_image_fit").map(str::to_owned), background_image_alignment: raw.value("background_image_alignment").map(str::to_owned), background_image_cover_chrome: raw