hyprshell_core_lib/config/
structs.rs1use 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 = 650]
59 pub width: u32,
60 #[default = 5]
61 pub max_items: u8,
62 #[default = true]
63 pub show_when_empty: bool,
64 #[default = 250]
65 pub animate_launch_ms: u64,
66 #[default(Plugins{
67 applications: Some(ApplicationsPluginConfig::default()),
68 terminal: Some(EmptyConfig::default()),
69 shell: None,
70 websearch: Some(WebSearchConfig::default()),
71 calc: Some(EmptyConfig::default()),
72 })]
73 pub plugins: Plugins,
74}
75
76#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
79#[serde(deny_unknown_fields)]
80pub struct Plugins {
81 pub applications: Option<ApplicationsPluginConfig>,
82 pub terminal: Option<EmptyConfig>,
83 pub shell: Option<EmptyConfig>,
84 pub websearch: Option<WebSearchConfig>,
85 pub calc: Option<EmptyConfig>,
86}
87
88#[derive(SmartDefault, Debug, Clone, PartialEq, 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, Deserialize, Serialize)]
94#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
95#[serde(deny_unknown_fields)]
96pub struct ApplicationsPluginConfig {
97 #[default = 4]
98 pub run_cache_weeks: u8,
99 #[default = true]
100 pub show_execs: bool,
101 #[default = false]
102 pub show_actions_submenu: bool,
103}
104
105#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
106#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
107#[serde(deny_unknown_fields)]
108pub struct WebSearchConfig {
109 #[default(vec![SearchEngine {
110 url: "https://www.google.com/search?q={}".into(),
111 name: "Google".into(),
112 key: 'g',
113 }, SearchEngine {
114 url: "https://en.wikipedia.org/wiki/Special:Search?search={}".into(),
115 name: "Wikipedia".into(),
116 key: 'w',
117 }])]
118 pub engines: Vec<SearchEngine>,
119}
120
121#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
122#[serde(deny_unknown_fields)]
123pub struct SearchEngine {
124 pub url: Box<str>,
125 pub name: Box<str>,
126 pub key: char,
127}
128
129#[derive(SmartDefault, Debug, Clone, PartialEq, Deserialize, Serialize)]
130#[cfg_attr(not(feature = "no-default-config-values"), serde(default))]
131#[serde(deny_unknown_fields)]
132pub struct Switch {
133 #[default(Modifier::Alt)]
134 pub modifier: Modifier,
135 #[default(Vec::new())]
136 pub filter_by: Vec<FilterBy>,
137 #[default = false]
138 pub show_workspaces: bool,
139}
140
141#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
142#[serde(rename_all = "snake_case")]
143pub enum FilterBy {
144 SameClass,
145 CurrentWorkspace,
146 CurrentMonitor,
147}
148
149#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
150#[serde(rename_all = "snake_case")]
151pub enum Modifier {
152 Alt,
153 Ctrl,
154 Super,
155 Shift,
156}
157
158impl Display for Modifier {
159 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
160 match self {
161 Modifier::Alt => write!(f, "alt"),
162 Modifier::Ctrl => write!(f, "ctrl"),
163 Modifier::Super => write!(f, "super"),
164 Modifier::Shift => write!(f, "shift"),
165 }
166 }
167}
168
169impl Modifier {
170 pub fn to_key(self) -> &'static str {
171 match self {
172 Modifier::Alt => "alt_l",
173 Modifier::Ctrl => "control_l",
174 Modifier::Super => "super_l",
175 Modifier::Shift => "shift_l",
176 }
177 }
178}