feat(config): add icon theme property to CosmicTk config
This commit is contained in:
parent
3694304ee5
commit
4154428a63
5 changed files with 24 additions and 5 deletions
|
|
@ -46,6 +46,9 @@ pub struct Core {
|
|||
/// Enables debug features in cosmic/iced.
|
||||
pub debug: bool,
|
||||
|
||||
/// Disables loading the icon theme from cosmic-config.
|
||||
pub(super) icon_theme_override: bool,
|
||||
|
||||
/// Whether the window is too small for the nav bar + main content.
|
||||
is_condensed: bool,
|
||||
|
||||
|
|
@ -95,6 +98,7 @@ impl Default for Core {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
debug: false,
|
||||
icon_theme_override: false,
|
||||
is_condensed: false,
|
||||
keyboard_nav: true,
|
||||
nav_bar: NavBar {
|
||||
|
|
|
|||
|
|
@ -563,6 +563,13 @@ impl<T: Application> Cosmic<T> {
|
|||
}
|
||||
|
||||
Message::ToolkitConfig(config) => {
|
||||
// Change the icon theme if not defined by the application.
|
||||
if !self.app.core().icon_theme_override
|
||||
&& crate::icon_theme::default() != config.icon_theme
|
||||
{
|
||||
crate::icon_theme::set_default(config.icon_theme.clone());
|
||||
}
|
||||
|
||||
self.app.core_mut().toolkit_config = config;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ pub mod message {
|
|||
pub use self::command::Command;
|
||||
pub use self::core::Core;
|
||||
pub use self::settings::Settings;
|
||||
use crate::config::CosmicTk;
|
||||
use crate::prelude::*;
|
||||
use crate::theme::THEME;
|
||||
use crate::widget::{context_drawer, nav_bar, popover};
|
||||
|
|
@ -66,16 +67,19 @@ pub(crate) fn iced_settings<App: Application>(
|
|||
settings: Settings,
|
||||
flags: App::Flags,
|
||||
) -> iced::Settings<(Core, App::Flags)> {
|
||||
if let Some(icon_theme) = settings.default_icon_theme {
|
||||
crate::icon_theme::set_default(icon_theme);
|
||||
}
|
||||
|
||||
let mut core = Core::default();
|
||||
core.debug = settings.debug;
|
||||
core.icon_theme_override = settings.default_icon_theme.is_some();
|
||||
core.set_scale_factor(settings.scale_factor);
|
||||
core.set_window_width(settings.size.width as u32);
|
||||
core.set_window_height(settings.size.height as u32);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
THEME.with(move |t| {
|
||||
let mut cosmic_theme = t.borrow_mut();
|
||||
cosmic_theme.set_theme(settings.theme.theme_type);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ impl Default for Settings {
|
|||
client_decorations: true,
|
||||
debug: false,
|
||||
default_font: font::FONT,
|
||||
default_icon_theme: Some(String::from("Cosmic")),
|
||||
default_icon_theme: None,
|
||||
default_text_size: 14.0,
|
||||
resizable: Some(8.0),
|
||||
scale_factor: std::env::var("COSMIC_SCALE")
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ pub struct CosmicTk {
|
|||
|
||||
/// Show maximize button in window header.
|
||||
pub show_maximize: bool,
|
||||
|
||||
/// Preferred icon theme
|
||||
pub icon_theme: String,
|
||||
}
|
||||
|
||||
impl Default for CosmicTk {
|
||||
|
|
@ -24,6 +27,7 @@ impl Default for CosmicTk {
|
|||
Self {
|
||||
show_minimize: true,
|
||||
show_maximize: true,
|
||||
icon_theme: String::from("Cosmic"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue