1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
34//! Configure a new COSMIC application.
56use crate::{Theme, font};
7use iced_core::Font;
8use iced_core::layout::Limits;
910/// Configure a new COSMIC application.
11#[allow(clippy::struct_excessive_bools)]
12#[must_use]
13#[derive(derive_setters::Setters)]
14pub struct Settings {
15/// Produces a smoother result in some widgets, at a performance cost.
16pub(crate) antialiasing: bool,
1718/// Autosize the window to fit its contents
19#[cfg(feature = "wayland")]
20pub(crate) autosize: bool,
2122/// Set the application to not create a main window
23pub(crate) no_main_window: bool,
2425/// Whether the window should have a border, a title bar, etc. or not.
26pub(crate) client_decorations: bool,
2728/// Enables debug features in cosmic/iced.
29pub(crate) debug: bool,
3031/// The default [`Font`] to be used.
32pub(crate) default_font: Font,
3334/// Name of the icon theme to search by default.
35#[setters(skip)]
36pub(crate) default_icon_theme: Option<String>,
3738/// Default size of fonts.
39pub(crate) default_text_size: f32,
4041/// Set the default mmap threshold for malloc with mallopt.
42pub(crate) default_mmap_threshold: Option<i32>,
4344/// Whether the window should be resizable or not.
45 /// and the size of the window border which can be dragged for a resize
46pub(crate) resizable: Option<f64>,
4748/// Scale factor to use by default.
49pub(crate) scale_factor: f32,
5051/// Initial size of the window.
52pub(crate) size: iced::Size,
5354/// Limitations of the window size
55pub(crate) size_limits: Limits,
5657/// The theme to apply to the application.
58pub(crate) theme: Theme,
5960/// Whether the window should be transparent.
61pub(crate) transparent: bool,
6263/// Whether the application window should close when the exit button is pressed
64pub(crate) exit_on_close: bool,
6566/// Whether the application should act as a daemon
67pub(crate) is_daemon: bool,
68}
6970impl Settings {
71/// Sets the default icon theme, passing an empty string will unset the theme.
72pub fn default_icon_theme(mut self, value: impl Into<String>) -> Self {
73let value: String = value.into();
74self.default_icon_theme = if value.is_empty() { None } else { Some(value) };
75self
76}
77}
7879impl Default for Settings {
80fn default() -> Self {
81Self {
82 antialiasing: true,
83#[cfg(feature = "wayland")]
84autosize: false,
85 no_main_window: false,
86 client_decorations: true,
87 debug: false,
88 default_font: font::default(),
89 default_icon_theme: None,
90 default_text_size: 14.0,
91 default_mmap_threshold: Some(128 * 1024),
92 resizable: Some(8.0),
93 scale_factor: std::env::var("COSMIC_SCALE")
94 .ok()
95 .and_then(|scale| scale.parse::<f32>().ok())
96 .unwrap_or(1.0),
97 size: iced::Size::new(1024.0, 768.0),
98 size_limits: Limits::NONE.min_height(1.0).min_width(1.0),
99 theme: crate::theme::system_preference(),
100 transparent: true,
101 exit_on_close: true,
102 is_daemon: true,
103 }
104 }
105}