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