hyprshell-config-edit-lib 4.9.3

A library for editing the config file with a gui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
use std::fmt;
use std::fmt::Formatter;

#[derive(Debug, Clone)]
pub struct Config {
    pub windows: Windows,
}

#[derive(Debug, Clone)]
pub struct Windows {
    pub enabled: bool,
    pub scale: f64,
    pub items_per_row: u8,
    pub overview: Overview,
    pub switch: Switch,
    pub switch_2: Switch,
}

#[derive(Debug, Clone)]
pub struct Overview {
    pub enabled: bool,
    pub launcher: Launcher,
    pub key: String,
    pub modifier: ConfigModifier,
    pub same_class: bool,
    pub current_workspace: bool,
    pub current_monitor: bool,
    pub exclude_special_workspaces: String,
}

#[derive(Debug, Clone)]
pub struct Launcher {
    pub default_terminal: Option<String>,
    pub launch_modifier: ConfigModifier,
    pub width: u32,
    pub max_items: u8,
    pub show_when_empty: bool,
    pub plugins: Plugins,
}

#[derive(Debug, Clone)]
pub struct Plugins {
    pub applications: ApplicationsPluginConfig,
    pub terminal: EmptyConfig,
    pub shell: EmptyConfig,
    pub websearch: WebSearchConfig,
    pub calc: EmptyConfig,
    pub path: EmptyConfig,
    pub actions: ActionsPluginConfig,
}

#[derive(Debug, Clone)]
pub struct WebSearchConfig {
    pub enabled: bool,
    pub engines: Vec<config_lib::SearchEngine>,
}

#[derive(Debug, Clone)]
pub struct EmptyConfig {
    pub enabled: bool,
}

#[derive(Debug, Clone)]
pub struct ActionsPluginConfig {
    pub enabled: bool,
    pub actions: Vec<config_lib::ActionsPluginAction>,
}

#[derive(Debug, Clone)]
pub struct ApplicationsPluginConfig {
    pub enabled: bool,
    pub run_cache_weeks: u8,
    pub show_execs: bool,
    pub show_actions_submenu: bool,
}

#[derive(Debug, Clone)]
#[allow(clippy::struct_field_names)]
pub struct Switch {
    pub enabled: bool,
    pub modifier: ConfigModifier,
    pub key: String,
    pub same_class: bool,
    pub current_workspace: bool,
    pub current_monitor: bool,
    pub switch_workspaces: bool,
    pub exclude_special_workspaces: String,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ConfigModifier {
    None,
    Alt,
    Super,
    Ctrl,
}

#[allow(dead_code)]
impl ConfigModifier {
    pub const fn strings() -> &'static [&'static str] {
        &["Alt", "Super", "Ctrl"]
    }
    pub const fn strings_with_none() -> &'static [&'static str] {
        &["None", "Alt", "Super", "Ctrl"]
    }
}

impl fmt::Display for ConfigModifier {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::None => write!(f, ""),
            Self::Alt => write!(f, "Alt"),
            Self::Super => write!(f, "Super"),
            Self::Ctrl => write!(f, "Ctrl"),
        }
    }
}

impl TryFrom<u32> for ConfigModifier {
    type Error = ();
    fn try_from(value: u32) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::None),
            1 => Ok(Self::Super),
            2 => Ok(Self::Ctrl),
            3 => Ok(Self::Alt),
            _ => Err(()),
        }
    }
}

impl From<ConfigModifier> for u32 {
    fn from(value: ConfigModifier) -> Self {
        match value {
            ConfigModifier::None => 0,
            ConfigModifier::Super => 1,
            ConfigModifier::Ctrl => 2,
            ConfigModifier::Alt => 3,
        }
    }
}

impl From<config_lib::Modifier> for ConfigModifier {
    fn from(value: config_lib::Modifier) -> Self {
        match value {
            config_lib::Modifier::None => Self::None,
            config_lib::Modifier::Alt => Self::Alt,
            config_lib::Modifier::Super => Self::Super,
            config_lib::Modifier::Ctrl => Self::Ctrl,
        }
    }
}

impl From<ConfigModifier> for config_lib::Modifier {
    fn from(value: ConfigModifier) -> Self {
        match value {
            ConfigModifier::None => Self::None,
            ConfigModifier::Alt => Self::Alt,
            ConfigModifier::Super => Self::Super,
            ConfigModifier::Ctrl => Self::Ctrl,
        }
    }
}

impl From<config_lib::Config> for Config {
    fn from(value: config_lib::Config) -> Self {
        Self {
            windows: value.windows.into(),
        }
    }
}

impl From<Config> for config_lib::Config {
    fn from(value: Config) -> Self {
        Self {
            version: config_lib::CURRENT_CONFIG_VERSION,
            windows: value.windows.into(),
        }
    }
}

impl From<Option<config_lib::Windows>> for Windows {
    fn from(value: Option<config_lib::Windows>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            scale: v.scale,
            items_per_row: v.items_per_row,
            overview: v.overview.into(),
            switch: v.switch.into(),
            switch_2: v.switch_2.into(),
        }
    }
}

impl From<Windows> for Option<config_lib::Windows> {
    fn from(value: Windows) -> Self {
        if value.enabled {
            Some(config_lib::Windows {
                scale: value.scale,
                items_per_row: value.items_per_row,
                overview: value.overview.into(),
                switch: value.switch.into(),
                switch_2: value.switch_2.into(),
            })
        } else {
            None
        }
    }
}

impl From<Option<config_lib::Switch>> for Switch {
    fn from(value: Option<config_lib::Switch>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            modifier: v.modifier.into(),
            key: v.key.to_string(),
            same_class: v.filter_by.contains(&config_lib::FilterBy::SameClass),
            current_workspace: v
                .filter_by
                .contains(&config_lib::FilterBy::CurrentWorkspace),
            current_monitor: v.filter_by.contains(&config_lib::FilterBy::CurrentMonitor),
            switch_workspaces: v.switch_workspaces,
            exclude_special_workspaces: v.exclude_special_workspaces.to_string(),
        }
    }
}

impl From<Switch> for Option<config_lib::Switch> {
    fn from(value: Switch) -> Self {
        if value.enabled {
            let mut vec = vec![];
            if value.same_class {
                vec.push(config_lib::FilterBy::SameClass);
            }
            if value.current_workspace {
                vec.push(config_lib::FilterBy::CurrentWorkspace);
            }
            if value.current_monitor {
                vec.push(config_lib::FilterBy::CurrentMonitor);
            }
            Some(config_lib::Switch {
                modifier: value.modifier.into(),
                key: Box::from(value.key),
                filter_by: vec,
                switch_workspaces: value.switch_workspaces,
                exclude_special_workspaces: Box::from(value.exclude_special_workspaces),
            })
        } else {
            None
        }
    }
}

impl From<Option<config_lib::Overview>> for Overview {
    fn from(value: Option<config_lib::Overview>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            launcher: v.launcher.into(),
            key: v.key.to_string(),
            modifier: v.modifier.into(),
            same_class: v.filter_by.contains(&config_lib::FilterBy::SameClass),
            current_workspace: v
                .filter_by
                .contains(&config_lib::FilterBy::CurrentWorkspace),
            current_monitor: v.filter_by.contains(&config_lib::FilterBy::CurrentMonitor),
            exclude_special_workspaces: v.exclude_special_workspaces.to_string(),
        }
    }
}

impl From<Overview> for Option<config_lib::Overview> {
    fn from(value: Overview) -> Self {
        if value.enabled {
            let mut vec = vec![];
            if value.same_class {
                vec.push(config_lib::FilterBy::SameClass);
            }
            if value.current_workspace {
                vec.push(config_lib::FilterBy::CurrentWorkspace);
            }
            if value.current_monitor {
                vec.push(config_lib::FilterBy::CurrentMonitor);
            }
            Some(config_lib::Overview {
                launcher: value.launcher.into(),
                key: Box::from(value.key),
                modifier: value.modifier.into(),
                filter_by: vec,
                hide_filtered: false,
                exclude_special_workspaces: Box::from(value.exclude_special_workspaces),
            })
        } else {
            None
        }
    }
}

impl From<config_lib::Launcher> for Launcher {
    fn from(value: config_lib::Launcher) -> Self {
        Self {
            default_terminal: value.default_terminal.map(|s| s.to_string()),
            launch_modifier: value.launch_modifier.into(),
            width: value.width,
            max_items: value.max_items,
            show_when_empty: value.show_when_empty,
            plugins: value.plugins.into(),
        }
    }
}

impl From<Launcher> for config_lib::Launcher {
    fn from(value: Launcher) -> Self {
        Self {
            default_terminal: value.default_terminal.map(Box::from),
            launch_modifier: value.launch_modifier.into(),
            width: value.width,
            max_items: value.max_items,
            show_when_empty: value.show_when_empty,
            plugins: value.plugins.into(),
        }
    }
}

impl From<Option<config_lib::EmptyConfig>> for EmptyConfig {
    fn from(value: Option<config_lib::EmptyConfig>) -> Self {
        let enabled = value.is_some();
        Self { enabled }
    }
}

impl From<EmptyConfig> for Option<config_lib::EmptyConfig> {
    fn from(value: EmptyConfig) -> Self {
        if value.enabled {
            Some(config_lib::EmptyConfig {})
        } else {
            None
        }
    }
}

impl From<Option<config_lib::ActionsPluginConfig>> for ActionsPluginConfig {
    fn from(value: Option<config_lib::ActionsPluginConfig>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            actions: v.actions,
        }
    }
}

impl From<ActionsPluginConfig> for Option<config_lib::ActionsPluginConfig> {
    fn from(value: ActionsPluginConfig) -> Self {
        if value.enabled {
            Some(config_lib::ActionsPluginConfig {
                actions: value.actions,
            })
        } else {
            None
        }
    }
}

impl From<Option<config_lib::ApplicationsPluginConfig>> for ApplicationsPluginConfig {
    fn from(value: Option<config_lib::ApplicationsPluginConfig>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            run_cache_weeks: v.run_cache_weeks,
            show_execs: v.show_execs,
            show_actions_submenu: v.show_actions_submenu,
        }
    }
}

impl From<ApplicationsPluginConfig> for Option<config_lib::ApplicationsPluginConfig> {
    fn from(value: ApplicationsPluginConfig) -> Self {
        if value.enabled {
            Some(config_lib::ApplicationsPluginConfig {
                run_cache_weeks: value.run_cache_weeks,
                show_execs: value.show_execs,
                show_actions_submenu: value.show_actions_submenu,
            })
        } else {
            None
        }
    }
}

impl From<Option<config_lib::WebSearchConfig>> for WebSearchConfig {
    fn from(value: Option<config_lib::WebSearchConfig>) -> Self {
        let enabled = value.is_some();
        let v = value.unwrap_or_default();
        Self {
            enabled,
            engines: v.engines,
        }
    }
}

impl From<WebSearchConfig> for Option<config_lib::WebSearchConfig> {
    fn from(value: WebSearchConfig) -> Self {
        if value.enabled {
            Some(config_lib::WebSearchConfig {
                engines: value.engines,
            })
        } else {
            None
        }
    }
}

impl From<config_lib::Plugins> for Plugins {
    fn from(value: config_lib::Plugins) -> Self {
        Self {
            applications: value.applications.into(),
            terminal: value.terminal.into(),
            shell: value.shell.into(),
            websearch: value.websearch.into(),
            calc: value.calc.into(),
            path: value.path.into(),
            actions: value.actions.into(),
        }
    }
}

impl From<Plugins> for config_lib::Plugins {
    fn from(value: Plugins) -> Self {
        Self {
            applications: value.applications.into(),
            terminal: value.terminal.into(),
            shell: value.shell.into(),
            websearch: value.websearch.into(),
            calc: value.calc.into(),
            path: value.path.into(),
            actions: value.actions.into(),
        }
    }
}