hyprshell_core_lib/config/
structs.rs

1use serde::{Deserialize, Serialize};
2use smart_default::SmartDefault;
3use std::fmt::Display;
4
5#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
6#[serde(default, deny_unknown_fields)]
7pub struct Config {
8    #[default = true]
9    pub layerrules: bool,
10    #[default(None)]
11    pub launcher: Option<Launcher>,
12    #[default(Some(Windows::default()))]
13    pub windows: Option<Windows>,
14}
15
16#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
17#[serde(default, deny_unknown_fields)]
18pub struct Windows {
19    #[default = 5.5]
20    pub size_factor: f64,
21    #[default = 5]
22    pub workspaces_per_row: u8,
23    #[default = true]
24    pub strip_html_from_workspace_title: bool,
25    pub overview: Option<Overview>,
26    pub switch: Option<Switch>,
27}
28
29#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
30#[serde(default, deny_unknown_fields)]
31pub struct Launcher {
32    #[default(None)]
33    pub default_terminal: Option<Box<str>>,
34    #[default = 650]
35    pub width: u32,
36    #[default = 5]
37    pub max_items: u8,
38    #[default(vec![
39        Plugins::Applications(ApplicationsPluginOptions::default()),
40        Plugins::Terminal(),
41        Plugins::Shell(),
42    ])]
43    pub plugins: Vec<Plugins>,
44}
45
46#[derive(Debug, Clone, Deserialize, Serialize)]
47pub enum Plugins {
48    Applications(ApplicationsPluginOptions),
49    Terminal(),
50    Shell(),
51}
52#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
53#[serde(default, deny_unknown_fields)]
54pub struct ApplicationsPluginOptions {
55    #[default = 4]
56    pub run_cache_weeks: u8,
57    #[default = true]
58    pub show_execs: bool,
59}
60
61#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
62#[serde(default, deny_unknown_fields)]
63pub struct Overview {
64    pub open: OpenOverview,
65    pub navigate: Navigate,
66    pub other: OtherOverview,
67}
68
69#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
70#[serde(default, deny_unknown_fields)]
71pub struct OtherOverview {
72    #[default = false]
73    pub hide_filtered: bool,
74    #[default(Vec::new())]
75    pub filter_by: Vec<FilterBy>,
76}
77
78#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
79#[serde(default, deny_unknown_fields)]
80pub struct OpenOverview {
81    #[default(Mod::Super)]
82    pub modifier: Mod,
83    #[default = "super"]
84    pub key: KeyMaybeMod,
85}
86
87#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
88#[serde(default, deny_unknown_fields)]
89pub struct Navigate {
90    #[default = "tab"]
91    pub forward: String,
92    #[default(Reverse::Mod(Mod::Shift))]
93    pub reverse: Reverse,
94}
95
96#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
97#[serde(default, deny_unknown_fields)]
98pub struct Switch {
99    pub open: OpenSwitch,
100    pub navigate: Navigate,
101    pub other: OtherSwitch,
102}
103
104#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
105#[serde(default, deny_unknown_fields)]
106pub struct OpenSwitch {
107    #[default(Mod::Super)]
108    pub modifier: Mod,
109}
110
111#[derive(SmartDefault, Debug, Clone, Deserialize, Serialize)]
112#[serde(default, deny_unknown_fields)]
113pub struct OtherSwitch {
114    #[default = true]
115    pub hide_filtered: bool,
116    #[default(Vec::new())]
117    pub filter_by: Vec<FilterBy>,
118}
119
120#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
121#[serde(rename_all = "snake_case")]
122pub enum FilterBy {
123    SameClass,
124    CurrentWorkspace,
125    CurrentMonitor,
126}
127
128#[derive(Debug, Clone, Deserialize, Serialize)]
129pub enum Reverse {
130    Key(String),
131    Mod(Mod),
132}
133#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
134#[serde(rename_all = "snake_case")]
135pub enum Mod {
136    Alt,
137    Ctrl,
138    Super,
139    Shift,
140}
141
142impl Display for Mod {
143    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
144        match self {
145            Mod::Alt => write!(f, "alt"),
146            Mod::Ctrl => write!(f, "ctrl"),
147            Mod::Super => write!(f, "super"),
148            Mod::Shift => write!(f, "shift"),
149        }
150    }
151}
152
153#[derive(Debug, Clone, Deserialize, Serialize)]
154pub struct KeyMaybeMod(String);
155impl From<&str> for KeyMaybeMod {
156    fn from(s: &str) -> Self {
157        Self(s.to_string())
158    }
159}
160
161pub trait ToKey {
162    fn to_key(&self) -> String;
163}
164
165// https://wiki.hyprland.org/Configuring/Variables/#variable-types
166// SHIFT CAPS CTRL/CONTROL ALT MOD2 MOD3 SUPER/WIN/LOGO/MOD4 MOD5
167impl ToKey for KeyMaybeMod {
168    fn to_key(&self) -> String {
169        match &*self.0.to_ascii_lowercase() {
170            "alt" => "alt_l".to_string(),
171            "ctrl" => "ctrl_l".to_string(),
172            "super" => "super_l".to_string(),
173            "shift" => "shift_l".to_string(),
174            a => a.to_string(),
175        }
176    }
177}
178
179impl ToKey for Mod {
180    fn to_key(&self) -> String {
181        match self {
182            Mod::Alt => "alt_l".to_string(),
183            Mod::Ctrl => "ctrl_l".to_string(),
184            Mod::Super => "super_l".to_string(),
185            Mod::Shift => "shift_l".to_string(),
186        }
187    }
188}