hyprshell_core_lib/config/
structs.rs

1use serde::{Deserialize, Serialize};
2use smart_default::SmartDefault;
3use std::fmt::Display;
4
5pub(crate) const CURRENT_CONFIG_VERSION: u16 = 1;
6
7#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
8#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
9#[serde(deny_unknown_fields)]
10pub struct Config {
11    #[default = true]
12    pub layerrules: bool,
13    #[default = "ctrl+shift+alt, h"]
14    pub kill_bind: Box<str>,
15    #[default(Some(Windows::default()))]
16    pub windows: Option<Windows>,
17    #[default(CURRENT_CONFIG_VERSION)]
18    pub version: u16,
19}
20
21#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
22#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
23#[serde(deny_unknown_fields)]
24pub struct Windows {
25    #[default = 8.5]
26    pub scale: f64,
27    #[default = 5]
28    pub items_per_row: u8,
29    #[default(Some(Overview::default()))]
30    pub overview: Option<Overview>,
31    #[default(Some(Switch::default()))]
32    pub switch: Option<Switch>,
33}
34
35#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
36#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
37#[serde(deny_unknown_fields)]
38pub struct Overview {
39    #[default = true]
40    pub strip_html_from_workspace_title: bool,
41    pub launcher: Launcher,
42    #[default = "super_l"]
43    pub key: Box<str>,
44    #[default(Modifier::Super)]
45    pub modifier: Modifier,
46    #[default(Vec::new())]
47    pub filter_by: Vec<FilterBy>,
48    #[default = false]
49    pub hide_filtered: bool,
50}
51
52#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
53#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
54#[serde(deny_unknown_fields)]
55pub struct Launcher {
56    #[default(None)]
57    pub default_terminal: Option<Box<str>>,
58    #[default(Modifier::Ctrl)]
59    pub launch_modifier: Modifier,
60    #[default = 650]
61    pub width: u32,
62    #[default = 5]
63    pub max_items: u8,
64    #[default = true]
65    pub show_when_empty: bool,
66    #[default = 250]
67    pub animate_launch_ms: u64,
68    #[default(Plugins{
69        applications: Some(ApplicationsPluginConfig::default()),
70        terminal: Some(EmptyConfig::default()),
71        shell: None,
72        websearch: Some(WebSearchConfig::default()),
73        calc: Some(EmptyConfig::default()),
74    })]
75    pub plugins: Plugins,
76}
77
78// no default for this, if some elements are missing, they should be None.
79// if no config for plugins is provided, use the default value from the launcher.
80#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
81#[serde(deny_unknown_fields)]
82pub struct Plugins {
83    pub applications: Option<ApplicationsPluginConfig>,
84    pub terminal: Option<EmptyConfig>,
85    pub shell: Option<EmptyConfig>,
86    pub websearch: Option<WebSearchConfig>,
87    pub calc: Option<EmptyConfig>,
88}
89
90#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
91#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
92#[serde(deny_unknown_fields)]
93pub struct EmptyConfig {}
94
95#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
96#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
97#[serde(deny_unknown_fields)]
98pub struct ApplicationsPluginConfig {
99    #[default = 4]
100    pub run_cache_weeks: u8,
101    #[default = true]
102    pub show_execs: bool,
103    #[default = false]
104    pub show_actions_submenu: bool,
105}
106
107#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
108#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
109#[serde(deny_unknown_fields)]
110pub struct WebSearchConfig {
111    #[default(vec![SearchEngine {
112        url: "https://www.google.com/search?q={}".into(),
113        name: "Google".into(),
114        key: 'g',
115    }, SearchEngine {
116        url: "https://en.wikipedia.org/wiki/Special:Search?search={}".into(),
117        name: "Wikipedia".into(),
118        key: 'w',
119    }])]
120    pub engines: Vec<SearchEngine>,
121}
122
123#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
124#[serde(deny_unknown_fields)]
125pub struct SearchEngine {
126    pub url: Box<str>,
127    pub name: Box<str>,
128    pub key: char,
129}
130
131#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
132#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
133#[serde(deny_unknown_fields)]
134pub struct Switch {
135    #[default(Modifier::Alt)]
136    pub modifier: Modifier,
137    #[default(Vec::new())]
138    pub filter_by: Vec<FilterBy>,
139    #[default = false]
140    pub show_workspaces: bool,
141}
142
143#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
144#[serde(rename_all = "snake_case")]
145pub enum FilterBy {
146    SameClass,
147    CurrentWorkspace,
148    CurrentMonitor,
149}
150
151#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
152#[serde(rename_all = "snake_case")]
153pub enum Modifier {
154    Alt,
155    Ctrl,
156    Super,
157    Shift,
158}
159
160impl Display for Modifier {
161    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162        match self {
163            Modifier::Alt => write!(f, "Alt"),
164            Modifier::Ctrl => write!(f, "Ctrl"),
165            Modifier::Super => write!(f, "Super"),
166            Modifier::Shift => write!(f, "Shift"),
167        }
168    }
169}
170
171impl Modifier {
172    pub fn to_lr_key(self) -> &'static str {
173        match self {
174            Modifier::Alt => "alt_l",
175            Modifier::Ctrl => "control_l",
176            Modifier::Super => "super_l",
177            Modifier::Shift => "shift_l",
178        }
179    }
180}