feat: CosmicTk::header_size density config
This commit is contained in:
parent
f0bfa87a36
commit
6720b8277c
8 changed files with 118 additions and 79 deletions
|
|
@ -31,7 +31,7 @@ desktop = ["process", "dep:freedesktop-desktop-entry", "dep:mime", "dep:shlex"]
|
|||
# Enables keycode serialization
|
||||
serde-keycode = ["iced_core/serde"]
|
||||
# Prevents multiple separate process instances.
|
||||
single-instance = ["dep:zbus", "serde", "ron"]
|
||||
single-instance = ["dep:zbus", "ron"]
|
||||
# smol async runtime
|
||||
smol = ["iced/smol", "zbus?/async-io"]
|
||||
tokio = [
|
||||
|
|
@ -80,7 +80,7 @@ mime = { version = "0.3.17", optional = true }
|
|||
nix = { version = "0.27", features = ["process"], optional = true }
|
||||
palette = "0.7.3"
|
||||
rfd = { version = "0.14.0", optional = true }
|
||||
serde = { version = "1.0.180", optional = true }
|
||||
serde = { version = "1.0.180", features = ["derive"]}
|
||||
slotmap = "1.0.6"
|
||||
thiserror = "1.0.44"
|
||||
tokio = { version = "1.24.2", optional = true }
|
||||
|
|
|
|||
|
|
@ -73,9 +73,6 @@ pub struct Core {
|
|||
/// Configured theme mode
|
||||
pub(super) system_theme_mode: ThemeMode,
|
||||
|
||||
/// Libcosmic toolkit configuration.
|
||||
pub(super) toolkit_config: CosmicTk,
|
||||
|
||||
pub(super) portal_is_dark: Option<bool>,
|
||||
|
||||
pub(super) portal_accent: Option<Srgba>,
|
||||
|
|
@ -123,16 +120,6 @@ impl Default for Core {
|
|||
})
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
toolkit_config: CosmicTk::config()
|
||||
.map(|c| {
|
||||
CosmicTk::get_entry(&c).unwrap_or_else(|(errors, mode)| {
|
||||
for why in errors {
|
||||
tracing::error!(?why, "CosmicTk config entry error");
|
||||
}
|
||||
mode
|
||||
})
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
window: Window {
|
||||
context_title: String::new(),
|
||||
header_title: String::new(),
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ where
|
|||
self.app.subscription().map(super::Message::App),
|
||||
self.app
|
||||
.core()
|
||||
.watch_config::<crate::config::CosmicTk>(crate::config::toolkit::ID)
|
||||
.watch_config::<crate::config::CosmicTk>(crate::config::ID)
|
||||
.map(|update| {
|
||||
for why in update.errors {
|
||||
tracing::error!(?why, "cosmic toolkit config update error");
|
||||
|
|
@ -628,7 +628,7 @@ impl<T: Application> Cosmic<T> {
|
|||
crate::icon_theme::set_default(config.icon_theme.clone());
|
||||
}
|
||||
|
||||
self.app.core_mut().toolkit_config = config;
|
||||
crate::config::COSMIC_TK.with(|tk| *tk.borrow_mut() = config);
|
||||
}
|
||||
|
||||
Message::Focus(f) => {
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ pub(crate) fn iced_settings<App: Application>(
|
|||
if let Some(icon_theme) = settings.default_icon_theme {
|
||||
crate::icon_theme::set_default(icon_theme);
|
||||
} else {
|
||||
crate::icon_theme::set_default(core.toolkit_config.icon_theme.clone());
|
||||
crate::icon_theme::set_default(crate::config::icon_theme());
|
||||
}
|
||||
|
||||
THEME.with(move |t| {
|
||||
|
|
@ -714,11 +714,11 @@ impl<App: Application> ApplicationExt for App {
|
|||
header = header.start(toggle);
|
||||
}
|
||||
|
||||
if core.window.show_maximize && core.toolkit_config.show_maximize {
|
||||
if core.window.show_maximize && crate::config::show_maximize() {
|
||||
header = header.on_maximize(Message::Cosmic(cosmic::Message::Maximize));
|
||||
}
|
||||
|
||||
if core.window.show_minimize && core.toolkit_config.show_minimize {
|
||||
if core.window.show_minimize && crate::config::show_minimize() {
|
||||
header = header.on_minimize(Message::Cosmic(cosmic::Message::Minimize));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,102 @@
|
|||
|
||||
//! Configurations available to libcosmic applications.
|
||||
|
||||
pub mod toolkit;
|
||||
#[doc(inline)]
|
||||
pub use toolkit::CosmicTk;
|
||||
use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
|
||||
use cosmic_config::{Config, CosmicConfigEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// ID for the `CosmicTk` config.
|
||||
pub const ID: &str = "com.system76.CosmicTk";
|
||||
|
||||
thread_local! {
|
||||
pub static COSMIC_TK: RefCell<CosmicTk> = RefCell::new(CosmicTk::config()
|
||||
.map(|c| {
|
||||
CosmicTk::get_entry(&c).unwrap_or_else(|(errors, mode)| {
|
||||
for why in errors {
|
||||
tracing::error!(?why, "CosmicTk config entry error");
|
||||
}
|
||||
mode
|
||||
})
|
||||
})
|
||||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Apply the theme to other toolkits.
|
||||
pub fn apply_theme_global() -> bool {
|
||||
COSMIC_TK.with(|tk| tk.borrow().apply_theme_global)
|
||||
}
|
||||
|
||||
/// Show minimize button in window header.
|
||||
pub fn show_minimize() -> bool {
|
||||
COSMIC_TK.with(|tk| tk.borrow().show_minimize)
|
||||
}
|
||||
|
||||
/// Show maximize button in window header.
|
||||
pub fn show_maximize() -> bool {
|
||||
COSMIC_TK.with(|tk| tk.borrow().show_maximize)
|
||||
}
|
||||
|
||||
/// Preferred icon theme.
|
||||
pub fn icon_theme() -> String {
|
||||
COSMIC_TK.with(|tk| tk.borrow().icon_theme.clone())
|
||||
}
|
||||
|
||||
/// Density of CSD/SSD header bars.
|
||||
pub fn header_size() -> Density {
|
||||
COSMIC_TK.with(|tk| tk.borrow().header_size)
|
||||
}
|
||||
|
||||
/// Interface density.
|
||||
pub fn interface_density() -> Density {
|
||||
COSMIC_TK.with(|tk| tk.borrow().interface_density)
|
||||
}
|
||||
|
||||
#[derive(Clone, CosmicConfigEntry, Debug, Eq, PartialEq)]
|
||||
#[version = 1]
|
||||
pub struct CosmicTk {
|
||||
/// Apply the theme to other toolkits.
|
||||
pub apply_theme_global: bool,
|
||||
|
||||
/// Show minimize button in window header.
|
||||
pub show_minimize: bool,
|
||||
|
||||
/// Show maximize button in window header.
|
||||
pub show_maximize: bool,
|
||||
|
||||
/// Preferred icon theme.
|
||||
pub icon_theme: String,
|
||||
|
||||
/// Density of CSD/SSD header bars.
|
||||
pub header_size: Density,
|
||||
|
||||
/// Interface density.
|
||||
pub interface_density: Density,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub enum Density {
|
||||
Compact,
|
||||
#[default]
|
||||
Standard,
|
||||
}
|
||||
|
||||
impl Default for CosmicTk {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
apply_theme_global: false,
|
||||
show_minimize: true,
|
||||
show_maximize: true,
|
||||
icon_theme: String::from("Cosmic"),
|
||||
header_size: Density::Standard,
|
||||
interface_density: Density::Standard,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CosmicTk {
|
||||
pub fn config() -> Result<Config, cosmic_config::Error> {
|
||||
Config::new(ID, Self::VERSION)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Configurations for the libcosmic toolkit.
|
||||
|
||||
use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
|
||||
use cosmic_config::{Config, CosmicConfigEntry};
|
||||
|
||||
/// ID for the `CosmicTk` config.
|
||||
pub const ID: &str = "com.system76.CosmicTk";
|
||||
|
||||
#[derive(Clone, CosmicConfigEntry, Debug, Eq, PartialEq)]
|
||||
#[version = 1]
|
||||
pub struct CosmicTk {
|
||||
/// Show minimize button in window header.
|
||||
pub show_minimize: bool,
|
||||
|
||||
/// Show maximize button in window header.
|
||||
pub show_maximize: bool,
|
||||
|
||||
/// Preferred icon theme.
|
||||
pub icon_theme: String,
|
||||
|
||||
/// Apply the theme to other toolkits.
|
||||
pub apply_theme_global: bool,
|
||||
}
|
||||
|
||||
impl Default for CosmicTk {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
show_minimize: true,
|
||||
show_maximize: true,
|
||||
icon_theme: String::from("Cosmic"),
|
||||
apply_theme_global: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CosmicTk {
|
||||
pub fn config() -> Result<Config, cosmic_config::Error> {
|
||||
Config::new(ID, Self::VERSION)
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
use crate::{ext::CollectionWidget, widget, Element};
|
||||
use apply::Apply;
|
||||
use derive_setters::Setters;
|
||||
use iced::Length;
|
||||
use iced::{Length, Padding};
|
||||
use iced_core::{widget::tree, Widget};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
#[must_use]
|
||||
pub fn build(self) -> HeaderBarWidget<'a, Message> {
|
||||
HeaderBarWidget {
|
||||
header_bar_inner: self.into_element(),
|
||||
header_bar_inner: self.view(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +253,7 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
|
|||
|
||||
impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
||||
/// Converts the headerbar builder into an Iced element.
|
||||
pub fn into_element(mut self) -> Element<'a, Message> {
|
||||
pub fn view(mut self) -> Element<'a, Message> {
|
||||
// Take ownership of the regions to be packed.
|
||||
let start = std::mem::take(&mut self.start);
|
||||
let center = std::mem::take(&mut self.center);
|
||||
|
|
@ -263,6 +263,11 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
end.push(widget::horizontal_space(Length::Fixed(12.0)).into());
|
||||
end.push(self.window_controls());
|
||||
|
||||
let (height, padding) = match crate::config::header_size() {
|
||||
crate::config::Density::Compact => (36.0, 2.0),
|
||||
crate::config::Density::Standard => (48.0, 8.0),
|
||||
};
|
||||
|
||||
// Creates the headerbar widget.
|
||||
let mut widget = widget::row::with_capacity(4)
|
||||
// If elements exist in the start region, append them here.
|
||||
|
|
@ -295,9 +300,9 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
.width(Length::Shrink),
|
||||
)
|
||||
.align_items(iced::Alignment::Center)
|
||||
.height(Length::Fixed(50.0))
|
||||
.padding(8)
|
||||
.spacing(8)
|
||||
.height(Length::Fixed(height))
|
||||
.padding(padding)
|
||||
.spacing(padding)
|
||||
.apply(widget::container)
|
||||
.style(crate::theme::Container::HeaderBar {
|
||||
focused: self.focused,
|
||||
|
|
@ -326,9 +331,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
let mut title = Cow::default();
|
||||
std::mem::swap(&mut title, &mut self.title);
|
||||
|
||||
widget::text(title)
|
||||
.size(16)
|
||||
.font(crate::font::FONT_SEMIBOLD)
|
||||
widget::text::heading(title)
|
||||
.apply(widget::container)
|
||||
.center_x()
|
||||
.center_y()
|
||||
|
|
|
|||
|
|
@ -42,13 +42,9 @@ impl<'a, Message: 'static + Clone> From<NavBarToggle<Message>> for Element<'a, M
|
|||
};
|
||||
|
||||
widget::button::icon(icon)
|
||||
.padding([8, 16, 8, 16])
|
||||
.on_press_maybe(nav_bar_toggle.on_toggle)
|
||||
.selected(nav_bar_toggle.selected)
|
||||
.style(nav_bar_toggle.style)
|
||||
.apply(widget::container)
|
||||
.center_y()
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue