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 the branch icon beside branch switcher in the title bar.
 85    ///
 86    /// Default: false
 87    pub show_branch_icon: Option<bool>,
 88    /// Whether to show onboarding banners in the title bar.
 89    ///
 90    /// Default: true
 91    pub show_onboarding_banner: Option<bool>,
 92    /// Whether to show user avatar in the title bar.
 93    ///
 94    /// Default: true
 95    pub show_user_picture: Option<bool>,
 96    /// Whether to show the branch name button in the titlebar.
 97    ///
 98    /// Default: true
 99    pub show_branch_name: Option<bool>,
100    /// Whether to show the project host and name in the titlebar.
101    ///
102    /// Default: true
103    pub show_project_items: Option<bool>,
104    /// Whether to show the sign in button in the title bar.
105    ///
106    /// Default: true
107    pub show_sign_in: Option<bool>,
108    /// Whether to show the user menu button in the title bar.
109    ///
110    /// Default: true
111    pub show_user_menu: Option<bool>,
112    /// Whether to show the menus in the title bar.
113    ///
114    /// Default: false
115    pub show_menus: Option<bool>,
116    /// The layout of window control buttons in the title bar (Linux only).
117    ///
118    /// This can be set to "platform_default" to follow the system configuration, or
119    /// "standard" to use Zed's built-in layout. For custom layouts, use a
120    /// GNOME-style layout string like "close:minimize,maximize".
121    ///
122    /// Default: "platform_default"
123    pub button_layout: Option<WindowButtonLayoutContent>,
124}