This PR adds support for full client side decorations on X11 and Wayland TODO: - [x] Adjust GPUI APIs to expose CSD related information - [x] Implement remaining CSD features (Resizing, window border, window shadow) - [x] Integrate with existing background appearance and window transparency - [x] Figure out how to check if the window is tiled on X11 - [x] Implement in Zed - [x] Repeatedly maximizing and unmaximizing can panic - [x] Resizing is strangely slow - [x] X11 resizing and movement doesn't work for this: https://discord.com/channels/869392257814519848/1204679850208657418/1256816908519604305 - [x] The top corner can clip with current styling - [x] Pressing titlebar buttons doesn't work - [x] Not showing maximize / unmaximize buttons - [x] Noisy transparency logs / surface transparency problem https://github.com/zed-industries/zed/pull/13611#issuecomment-2201685030 - [x] Strange offsets when dragging the project panel https://github.com/zed-industries/zed/pull/13611#pullrequestreview-2154606261 - [x] Shadow inset with `_GTK_FRAME_EXTENTS` doesn't respect tiling on X11 (observe by snapping an X11 window in any direction) Release Notes: - N/A --------- Co-authored-by: conrad <conrad@zed.dev> Co-authored-by: Owen Law <81528246+someone13574@users.noreply.github.com> Co-authored-by: apricotbucket28 <71973804+apricotbucket28@users.noreply.github.com> Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
186 lines
4.4 KiB
Rust
186 lines
4.4 KiB
Rust
//! # Theme
|
|
//!
|
|
//! This crate provides the theme system for Zed.
|
|
//!
|
|
//! ## Overview
|
|
//!
|
|
//! A theme is a collection of colors used to build a consistent appearance for UI components across the application.
|
|
|
|
mod default_colors;
|
|
mod default_theme;
|
|
mod one_themes;
|
|
pub mod prelude;
|
|
mod registry;
|
|
mod scale;
|
|
mod schema;
|
|
mod settings;
|
|
mod styles;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use ::settings::{Settings, SettingsStore};
|
|
pub use default_colors::*;
|
|
pub use default_theme::*;
|
|
pub use registry::*;
|
|
pub use scale::*;
|
|
pub use schema::*;
|
|
pub use settings::*;
|
|
pub use styles::*;
|
|
|
|
use gpui::{
|
|
px, AppContext, AssetSource, Hsla, Pixels, SharedString, WindowAppearance,
|
|
WindowBackgroundAppearance,
|
|
};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
|
|
pub enum Appearance {
|
|
Light,
|
|
Dark,
|
|
}
|
|
|
|
pub const CLIENT_SIDE_DECORATION_ROUNDING: Pixels = px(10.0);
|
|
pub const CLIENT_SIDE_DECORATION_SHADOW: Pixels = px(10.0);
|
|
|
|
impl Appearance {
|
|
pub fn is_light(&self) -> bool {
|
|
match self {
|
|
Self::Light => true,
|
|
Self::Dark => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<WindowAppearance> for Appearance {
|
|
fn from(value: WindowAppearance) -> Self {
|
|
match value {
|
|
WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::Dark,
|
|
WindowAppearance::Light | WindowAppearance::VibrantLight => Self::Light,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum LoadThemes {
|
|
/// Only load the base theme.
|
|
///
|
|
/// No user themes will be loaded.
|
|
JustBase,
|
|
|
|
/// Load all of the built-in themes.
|
|
All(Box<dyn AssetSource>),
|
|
}
|
|
|
|
pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
|
|
let (assets, load_user_themes) = match themes_to_load {
|
|
LoadThemes::JustBase => (Box::new(()) as Box<dyn AssetSource>, false),
|
|
LoadThemes::All(assets) => (assets, true),
|
|
};
|
|
ThemeRegistry::set_global(assets, cx);
|
|
|
|
if load_user_themes {
|
|
ThemeRegistry::global(cx).load_bundled_themes();
|
|
}
|
|
|
|
ThemeSettings::register(cx);
|
|
|
|
let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
|
cx.observe_global::<SettingsStore>(move |cx| {
|
|
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
|
if buffer_font_size != prev_buffer_font_size {
|
|
prev_buffer_font_size = buffer_font_size;
|
|
reset_buffer_font_size(cx);
|
|
}
|
|
})
|
|
.detach();
|
|
}
|
|
|
|
pub trait ActiveTheme {
|
|
fn theme(&self) -> &Arc<Theme>;
|
|
}
|
|
|
|
impl ActiveTheme for AppContext {
|
|
fn theme(&self) -> &Arc<Theme> {
|
|
&ThemeSettings::get_global(self).active_theme
|
|
}
|
|
}
|
|
|
|
pub struct ThemeFamily {
|
|
pub id: String,
|
|
pub name: SharedString,
|
|
pub author: SharedString,
|
|
pub themes: Vec<Theme>,
|
|
pub scales: ColorScales,
|
|
}
|
|
|
|
impl ThemeFamily {}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Theme {
|
|
pub id: String,
|
|
pub name: SharedString,
|
|
pub appearance: Appearance,
|
|
pub styles: ThemeStyles,
|
|
}
|
|
|
|
impl Theme {
|
|
/// Returns the [`SystemColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn system(&self) -> &SystemColors {
|
|
&self.styles.system
|
|
}
|
|
|
|
/// Returns the [`AccentColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn accents(&self) -> &AccentColors {
|
|
&self.styles.accents
|
|
}
|
|
|
|
/// Returns the [`PlayerColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn players(&self) -> &PlayerColors {
|
|
&self.styles.player
|
|
}
|
|
|
|
/// Returns the [`ThemeColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn colors(&self) -> &ThemeColors {
|
|
&self.styles.colors
|
|
}
|
|
|
|
/// Returns the [`SyntaxTheme`] for the theme.
|
|
#[inline(always)]
|
|
pub fn syntax(&self) -> &Arc<SyntaxTheme> {
|
|
&self.styles.syntax
|
|
}
|
|
|
|
/// Returns the [`StatusColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn status(&self) -> &StatusColors {
|
|
&self.styles.status
|
|
}
|
|
|
|
/// Returns the color for the syntax node with the given name.
|
|
#[inline(always)]
|
|
pub fn syntax_color(&self, name: &str) -> Hsla {
|
|
self.syntax().color(name)
|
|
}
|
|
|
|
/// Returns the [`Appearance`] for the theme.
|
|
#[inline(always)]
|
|
pub fn appearance(&self) -> Appearance {
|
|
self.appearance
|
|
}
|
|
|
|
/// Returns the [`WindowBackgroundAppearance`] for the theme.
|
|
#[inline(always)]
|
|
pub fn window_background_appearance(&self) -> WindowBackgroundAppearance {
|
|
self.styles.window_background_appearance
|
|
}
|
|
}
|
|
|
|
pub fn color_alpha(color: Hsla, alpha: f32) -> Hsla {
|
|
let mut color = color;
|
|
color.a = alpha;
|
|
color
|
|
}
|