title_bar.rs

  1use gpui::WindowButtonLayout;
  2use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
  3use serde::{Deserialize, Serialize};
  4use settings_macros::{MergeFrom, with_fallible_options};
  5
  6/// The layout of window control buttons as represented by user settings.
  7///
  8/// Custom layout strings use the GNOME `button-layout` format (e.g.
  9/// `"close:minimize,maximize"`).
 10#[derive(
 11    Clone,
 12    PartialEq,
 13    Debug,
 14    Serialize,
 15    Deserialize,
 16    JsonSchema,
 17    MergeFrom,
 18    Default,
 19    strum::EnumDiscriminants,
 20)]
 21#[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))]
 22#[schemars(schema_with = "window_button_layout_schema")]
 23#[serde(from = "String", into = "String")]
 24pub enum WindowButtonLayoutContent {
 25    /// Follow the system/desktop configuration.
 26    #[default]
 27    PlatformDefault,
 28    /// Use Zed's built-in standard layout, regardless of system config.
 29    Standard,
 30    /// A raw GNOME-style layout string.
 31    Custom(String),
 32}
 33
 34impl WindowButtonLayoutContent {
 35    #[cfg(any(target_os = "linux", target_os = "freebsd"))]
 36    pub fn into_layout(self) -> Option<WindowButtonLayout> {
 37        use util::ResultExt;
 38
 39        match self {
 40            Self::PlatformDefault => None,
 41            Self::Standard => Some(WindowButtonLayout::linux_default()),
 42            Self::Custom(layout) => WindowButtonLayout::parse(&layout).log_err(),
 43        }
 44    }
 45
 46    #[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
 47    pub fn into_layout(self) -> Option<WindowButtonLayout> {
 48        None
 49    }
 50}
 51
 52fn window_button_layout_schema(_: &mut SchemaGenerator) -> Schema {
 53    json_schema!({
 54        "anyOf": [
 55            { "enum": ["platform_default", "standard"] },
 56            { "type": "string" }
 57        ]
 58    })
 59}
 60
 61impl From<WindowButtonLayoutContent> for String {
 62    fn from(value: WindowButtonLayoutContent) -> Self {
 63        match value {
 64            WindowButtonLayoutContent::PlatformDefault => "platform_default".to_string(),
 65            WindowButtonLayoutContent::Standard => "standard".to_string(),
 66            WindowButtonLayoutContent::Custom(s) => s,
 67        }
 68    }
 69}
 70
 71impl From<String> for WindowButtonLayoutContent {
 72    fn from(layout_string: String) -> Self {
 73        match layout_string.as_str() {
 74            "platform_default" => Self::PlatformDefault,
 75            "standard" => Self::Standard,
 76            _ => Self::Custom(layout_string),
 77        }
 78    }
 79}
 80
 81#[with_fallible_options]
 82#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
 83pub struct TitleBarSettingsContent {
 84    /// Whether to show git status indicators on the branch icon in the title bar.
 85    /// When enabled, the branch icon changes to reflect the current repository
 86    /// status (e.g. modified, added, deleted, or conflict).
 87    ///
 88    /// Default: false
 89    pub show_branch_status_icon: Option<bool>,
 90    /// Whether to show onboarding banners in the title bar.
 91    ///
 92    /// Default: true
 93    pub show_onboarding_banner: Option<bool>,
 94    /// Whether to show user avatar in the title bar.
 95    ///
 96    /// Default: true
 97    pub show_user_picture: Option<bool>,
 98    /// Whether to show the branch name button in the titlebar.
 99    ///
100    /// Default: true
101    pub show_branch_name: Option<bool>,
102    /// Whether to show the project host and name in the titlebar.
103    ///
104    /// Default: true
105    pub show_project_items: Option<bool>,
106    /// Whether to show the sign in button in the title bar.
107    ///
108    /// Default: true
109    pub show_sign_in: Option<bool>,
110    /// Whether to show the user menu button in the title bar.
111    ///
112    /// Default: true
113    pub show_user_menu: Option<bool>,
114    /// Whether to show the menus in the title bar.
115    ///
116    /// Default: false
117    pub show_menus: Option<bool>,
118    /// The layout of window control buttons in the title bar (Linux only).
119    ///
120    /// This can be set to "platform_default" to follow the system configuration, or
121    /// "standard" to use Zed's built-in layout. For custom layouts, use a
122    /// GNOME-style layout string like "close:minimize,maximize".
123    ///
124    /// Default: "platform_default"
125    pub button_layout: Option<WindowButtonLayoutContent>,
126}