improve title bar
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 2m20s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 2m31s

This commit is contained in:
2026-01-16 18:39:57 +07:00
parent 81b1f2b293
commit ca38cc23d9
5 changed files with 66 additions and 71 deletions

View File

@@ -143,7 +143,7 @@ impl Render for TitleBar {
PlatformKind::Linux => {
#[cfg(target_os = "linux")]
if matches!(decorations, Decorations::Client { .. }) {
this.child(LinuxWindowControls::new(None))
this.child(LinuxWindowControls::new())
.when(supported_controls.window_menu, |this| {
this.on_mouse_down(MouseButton::Right, move |ev, window, _| {
window.show_window_menu(ev.position)

View File

@@ -4,23 +4,19 @@ use std::sync::OnceLock;
use gpui::prelude::FluentBuilder;
use gpui::{
img, Action, App, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce,
StatefulInteractiveElement, Styled, Window,
svg, App, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce,
SharedString, StatefulInteractiveElement, Styled, Window,
};
use linicon::{lookup_icon, IconType};
use theme::ActiveTheme;
use ui::{h_flex, Icon, IconName, Sizable};
#[derive(IntoElement)]
pub struct LinuxWindowControls {
close_window_action: Option<Box<dyn Action>>,
}
pub struct LinuxWindowControls {}
impl LinuxWindowControls {
pub fn new(close_window_action: Option<Box<dyn Action>>) -> Self {
Self {
close_window_action,
}
pub fn new() -> Self {
Self {}
}
}
@@ -42,12 +38,10 @@ impl RenderOnce for LinuxWindowControls {
WindowControl::new(LinuxControl::Maximize, IconName::WindowMaximize)
}
})
.child(
WindowControl::new(LinuxControl::Close, IconName::WindowClose)
.when_some(self.close_window_action, |this, close_action| {
this.close_action(close_action)
}),
)
.child(WindowControl::new(
LinuxControl::Close,
IconName::WindowClose,
))
}
}
@@ -55,21 +49,11 @@ impl RenderOnce for LinuxWindowControls {
pub struct WindowControl {
kind: LinuxControl,
fallback: IconName,
close_action: Option<Box<dyn Action>>,
}
impl WindowControl {
pub fn new(kind: LinuxControl, fallback: IconName) -> Self {
Self {
kind,
fallback,
close_action: None,
}
}
pub fn close_action(mut self, action: Box<dyn Action>) -> Self {
self.close_action = Some(action);
self
Self { kind, fallback }
}
pub fn is_gnome(&self) -> bool {
@@ -102,7 +86,20 @@ impl RenderOnce for WindowControl {
})
.map(|this| {
if let Some(Some(path)) = linux_controls().get(&self.kind).cloned() {
this.child(img(path).flex_grow().size_4())
this.child(
svg()
.external_path(SharedString::from(
path.into_os_string().into_string().unwrap(),
))
.map(|this| {
if cx.theme().is_dark() {
this.text_color(gpui::white())
} else {
this.text_color(gpui::black())
}
})
.size_4(),
)
} else {
this.child(Icon::new(self.fallback).flex_grow().small())
}
@@ -114,13 +111,7 @@ impl RenderOnce for WindowControl {
LinuxControl::Minimize => window.minimize_window(),
LinuxControl::Restore => window.zoom_window(),
LinuxControl::Maximize => window.zoom_window(),
LinuxControl::Close => window.dispatch_action(
self.close_action
.as_ref()
.expect("Use WindowControl::new_close() for close control.")
.boxed_clone(),
cx,
),
LinuxControl::Close => {}
}
})
}