hyprshell_config_lib/
structs.rs

1use crate::Modifier;
2use serde::{Deserialize, Serialize};
3use smart_default::SmartDefault;
4
5#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
6#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
7#[serde(deny_unknown_fields)]
8pub struct Config {
9    #[cfg_attr(
10        not(feature = "no-default-config-values"),
11        default(Some(crate::CURRENT_CONFIG_VERSION))
12    )]
13    #[cfg_attr(feature = "no-default-config-values", default(None))]
14    pub version: Option<u16>,
15    #[default(None)]
16    pub windows: Option<Windows>,
17}
18
19#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
20#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
21#[serde(deny_unknown_fields)]
22pub struct Windows {
23    #[default = 8.5]
24    pub scale: f64,
25    #[default = 5]
26    pub items_per_row: u8,
27    #[default(None)]
28    pub overview: Option<Overview>,
29    #[default(None)]
30    pub switch: Option<Switch>,
31}
32
33#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
34#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
35#[serde(deny_unknown_fields)]
36pub struct Overview {
37    pub launcher: Launcher,
38    #[default = "super_l"]
39    pub key: Box<str>,
40    #[default(Modifier::Super)]
41    pub modifier: Modifier,
42    #[default(Vec::new())]
43    pub filter_by: Vec<FilterBy>,
44    #[default = false]
45    pub hide_filtered: bool,
46}
47
48#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
49#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
50#[serde(deny_unknown_fields)]
51pub struct Launcher {
52    #[default(None)]
53    pub default_terminal: Option<Box<str>>,
54    #[default(Modifier::Ctrl)]
55    pub launch_modifier: Modifier,
56    #[default = 650]
57    pub width: u32,
58    #[default = 5]
59    pub max_items: u8,
60    #[default = true]
61    pub show_when_empty: bool,
62    #[default(Plugins{
63        applications: Some(ApplicationsPluginConfig::default()),
64        terminal: Some(EmptyConfig::default()),
65        shell: None,
66        websearch: Some(WebSearchConfig::default()),
67        calc: Some(EmptyConfig::default()),
68        path: Some(EmptyConfig::default()),
69        actions: Some(ActionsPluginConfig::default()),
70    })]
71    pub plugins: Plugins,
72}
73
74// no default for this, if some elements are missing, they should be None.
75// if no config for plugins is provided, use the default value from the launcher.
76#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
77#[serde(deny_unknown_fields)]
78pub struct Plugins {
79    pub applications: Option<ApplicationsPluginConfig>,
80    pub terminal: Option<EmptyConfig>,
81    pub shell: Option<EmptyConfig>,
82    pub websearch: Option<WebSearchConfig>,
83    pub calc: Option<EmptyConfig>,
84    pub path: Option<EmptyConfig>,
85    pub actions: Option<ActionsPluginConfig>,
86}
87
88#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
89#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
90#[serde(deny_unknown_fields)]
91pub struct EmptyConfig {}
92
93#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
94#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
95#[serde(deny_unknown_fields)]
96pub struct ActionsPluginConfig {
97    #[default(vec![
98        ActionsPluginAction::LockScreen,
99        ActionsPluginAction::Hibernate,
100        ActionsPluginAction::Logout,
101        ActionsPluginAction::Reboot,
102        ActionsPluginAction::Shutdown,
103        ActionsPluginAction::Suspend,
104        ActionsPluginAction::Custom(ActionsPluginActionCustom {
105            names: vec!["Kill".into(), "Stop".into()],
106            details: "Kill or stop a process by name".into(),
107            command: "pkill \"{}\" && notify-send hyprshell \"stopped {}\"".into(),
108            icon: "remove".into(),
109        }),
110        ActionsPluginAction::Custom(ActionsPluginActionCustom {
111            names: vec!["Reload Hyprshell".into()],
112            details: "Reload Hyprshell".into(),
113            command: "sleep 1; hyprshell socat '\"Restart\"'".into(),
114            icon: "system-restart".into(),
115        }),
116    ])]
117    pub actions: Vec<ActionsPluginAction>,
118}
119
120#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
121#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
122#[serde(deny_unknown_fields)]
123pub struct ApplicationsPluginConfig {
124    #[default = 8]
125    pub run_cache_weeks: u8,
126    #[default = true]
127    pub show_execs: bool,
128    #[default = true]
129    pub show_actions_submenu: bool,
130}
131
132#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
133#[serde(rename_all = "snake_case")]
134pub enum ActionsPluginAction {
135    LockScreen,
136    Hibernate,
137    Logout,
138    Reboot,
139    Shutdown,
140    Suspend,
141    Custom(ActionsPluginActionCustom),
142}
143
144#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
145#[serde(deny_unknown_fields)]
146pub struct ActionsPluginActionCustom {
147    pub names: Vec<Box<str>>,
148    pub details: Box<str>,
149    pub command: Box<str>,
150    pub icon: Box<str>,
151}
152
153#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
154#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
155#[serde(deny_unknown_fields)]
156pub struct WebSearchConfig {
157    #[default(vec![SearchEngine {
158        url: "https://www.google.com/search?q={}".into(),
159        name: "Google".into(),
160        key: 'g',
161    }, SearchEngine {
162        url: "https://en.wikipedia.org/wiki/Special:Search?search={}".into(),
163        name: "Wikipedia".into(),
164        key: 'w',
165    }])]
166    pub engines: Vec<SearchEngine>,
167}
168
169#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
170#[serde(deny_unknown_fields)]
171pub struct SearchEngine {
172    pub url: Box<str>,
173    pub name: Box<str>,
174    pub key: char,
175}
176
177#[derive(SmartDefault, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
178#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
179#[serde(deny_unknown_fields)]
180pub struct Switch {
181    #[default(Modifier::Alt)]
182    pub modifier: Modifier,
183    #[default(Vec::new())]
184    pub filter_by: Vec<FilterBy>,
185    #[default = false]
186    pub switch_workspaces: bool,
187}
188
189#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
190#[serde(rename_all = "snake_case")]
191pub enum FilterBy {
192    SameClass,
193    CurrentWorkspace,
194    CurrentMonitor,
195}