From 9929fbbfdbc88e5121903c8312c0e9a7ab5d1a51 Mon Sep 17 00:00:00 2001 From: nanowu <140001136+nanuwo@users.noreply.github.com> Date: Thu, 7 Aug 2025 17:19:31 +0100 Subject: [PATCH] feat: add SSD support via config option --- src/app/cosmic.rs | 2 +- src/app/mod.rs | 38 ++++++++++++++++++++++++-------------- src/app/settings.rs | 3 +++ src/config/mod.rs | 12 ++++++++++++ src/core.rs | 2 ++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index ae554846..0c743bde 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -391,7 +391,7 @@ where pub fn style(&self, theme: &Theme) -> iced_runtime::Appearance { if let Some(style) = self.app.style() { style - } else if self.app.core().window.is_maximized { + } else if self.app.core().window.is_maximized || !self.app.core().window.client_decorations { let theme = THEME.lock().unwrap(); crate::style::iced::application::appearance(theme.borrow()) } else { diff --git a/src/app/mod.rs b/src/app/mod.rs index 67636dac..7d9ecee9 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -75,7 +75,14 @@ pub(crate) fn iced_settings( window_settings.resize_border = border_size as u32; window_settings.resizable = true; } - window_settings.decorations = !settings.client_decorations; + + core.window.client_decorations = if cfg!(any(target_os = "windows", target_os = "macos")) { + settings.client_decorations || crate::config::client_decorations() + } else { + settings.client_decorations && crate::config::client_decorations() + }; + window_settings.decorations = !core.window.client_decorations; + window_settings.size = settings.size; let min_size = settings.size_limits.min(); if min_size != iced::Size::ZERO { @@ -549,7 +556,7 @@ impl ApplicationExt for App { fn view_main(&self) -> Element<'_, crate::Action> { let core = self.core(); let is_condensed = core.is_condensed(); - let sharp_corners = core.window.sharp_corners; + let sharp_corners = core.window.sharp_corners || !core.window.client_decorations; let maximized = core.window.is_maximized; let content_container = core.window.content_container; let show_context = core.window.show_context; @@ -713,7 +720,6 @@ impl ApplicationExt for App { .maximized(maximized) .sharp_corners(sharp_corners) .transparent(content_container) - .title(&core.window.header_title) .on_drag(crate::Action::Cosmic(Action::Drag)) .on_right_click(crate::Action::Cosmic(Action::ShowWindowMenu)) .on_double_click(crate::Action::Cosmic(Action::Maximize)) @@ -731,19 +737,23 @@ impl ApplicationExt for App { header = header.start(toggle); } + if core.window.client_decorations { + header = header.title(&core.window.header_title); + + if core.window.show_close { + header = header.on_close(crate::Action::Cosmic(Action::Close)); + } + + if core.window.show_maximize && crate::config::show_maximize() { + header = header.on_maximize(crate::Action::Cosmic(Action::Maximize)); + } + + if core.window.show_minimize && crate::config::show_minimize() { + header = header.on_minimize(crate::Action::Cosmic(Action::Minimize)); + } - if core.window.show_close { - header = header.on_close(crate::Action::Cosmic(Action::Close)); } - - if core.window.show_maximize && crate::config::show_maximize() { - header = header.on_maximize(crate::Action::Cosmic(Action::Maximize)); - } - - if core.window.show_minimize && crate::config::show_minimize() { - header = header.on_minimize(crate::Action::Cosmic(Action::Minimize)); - } - + for element in self.header_start() { header = header.start(element.map(crate::Action::App)); } diff --git a/src/app/settings.rs b/src/app/settings.rs index 926181e1..b005657e 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -83,6 +83,9 @@ impl Default for Settings { #[cfg(feature = "wayland")] autosize: false, no_main_window: false, + #[cfg(any(target_os = "windows", target_os = "macos"))] + client_decorations: false, + #[cfg(target_os = "linux")] client_decorations: true, debug: false, default_font: font::default(), diff --git a/src/config/mod.rs b/src/config/mod.rs index 1253ce8d..cd8efb17 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -46,6 +46,11 @@ pub fn apply_theme_global() -> bool { COSMIC_TK.read().unwrap().apply_theme_global } +/// Enable client-side decorations. +pub fn client_decorations() -> bool { + COSMIC_TK.read().unwrap().client_decorations +} + /// Show minimize button in window header. #[allow(clippy::missing_panics_doc)] pub fn show_minimize() -> bool { @@ -98,6 +103,9 @@ pub struct CosmicTk { /// Show maximize button in window header. pub show_maximize: bool, + /// Enables client-side decorations. + pub client_decorations: bool, + /// Preferred icon theme. pub icon_theme: String, @@ -120,6 +128,10 @@ impl Default for CosmicTk { apply_theme_global: false, show_minimize: true, show_maximize: true, + #[cfg(any(target_os = "windows", target_os = "macos"))] + client_decorations: false, + #[cfg(target_os = "linux")] + client_decorations: true, icon_theme: String::from("Cosmic"), header_size: Density::Standard, interface_density: Density::Standard, diff --git a/src/core.rs b/src/core.rs index 4d50e764..9cf567c3 100644 --- a/src/core.rs +++ b/src/core.rs @@ -39,6 +39,7 @@ pub struct Window { pub show_maximize: bool, pub show_minimize: bool, pub is_maximized: bool, + pub client_decorations: bool, height: f32, width: f32, } @@ -143,6 +144,7 @@ impl Default for Core { show_minimize: true, show_window_menu: false, is_maximized: false, + client_decorations: true, height: 0., width: 0., },