cosmic/app/
settings.rs

1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4//! Configure a new COSMIC application.
5
6use crate::{Theme, font};
7use iced_core::Font;
8use iced_core::layout::Limits;
9
10/// 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.
16    pub(crate) antialiasing: bool,
17
18    /// Autosize the window to fit its contents
19    #[cfg(feature = "wayland")]
20    pub(crate) autosize: bool,
21
22    /// Set the application to not create a main window
23    pub(crate) no_main_window: bool,
24
25    /// Whether the window should have a border, a title bar, etc. or not.
26    pub(crate) client_decorations: bool,
27
28    /// Enables debug features in cosmic/iced.
29    pub(crate) debug: bool,
30
31    /// The default [`Font`] to be used.
32    pub(crate) default_font: Font,
33
34    /// Name of the icon theme to search by default.
35    #[setters(skip)]
36    pub(crate) default_icon_theme: Option<String>,
37
38    /// Default size of fonts.
39    pub(crate) default_text_size: f32,
40
41    /// Set the default mmap threshold for malloc with mallopt.
42    pub(crate) default_mmap_threshold: Option<i32>,
43
44    /// Whether the window should be resizable or not.
45    /// and the size of the window border which can be dragged for a resize
46    pub(crate) resizable: Option<f64>,
47
48    /// Scale factor to use by default.
49    pub(crate) scale_factor: f32,
50
51    /// Initial size of the window.
52    pub(crate) size: iced::Size,
53
54    /// Limitations of the window size
55    pub(crate) size_limits: Limits,
56
57    /// The theme to apply to the application.
58    pub(crate) theme: Theme,
59
60    /// Whether the window should be transparent.
61    pub(crate) transparent: bool,
62
63    /// Whether the application window should close when the exit button is pressed
64    pub(crate) exit_on_close: bool,
65
66    /// Whether the application should act as a daemon
67    pub(crate) is_daemon: bool,
68}
69
70impl Settings {
71    /// Sets the default icon theme, passing an empty string will unset the theme.
72    pub fn default_icon_theme(mut self, value: impl Into<String>) -> Self {
73        let value: String = value.into();
74        self.default_icon_theme = if value.is_empty() { None } else { Some(value) };
75        self
76    }
77}
78
79impl Default for Settings {
80    fn default() -> Self {
81        Self {
82            antialiasing: true,
83            #[cfg(feature = "wayland")]
84            autosize: 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}