halley_config/keybinds/
modifiers.rs1use super::types::KeyModifiers;
2
3pub fn modifiers_empty(m: KeyModifiers) -> bool {
4 !m.super_key
5 && !m.left_super
6 && !m.right_super
7 && !m.alt
8 && !m.left_alt
9 && !m.right_alt
10 && !m.ctrl
11 && !m.left_ctrl
12 && !m.right_ctrl
13 && !m.shift
14 && !m.left_shift
15 && !m.right_shift
16}
17
18pub fn parse_modifiers(text: &str) -> Option<KeyModifiers> {
19 let mut out = KeyModifiers::default();
20 let mut any = false;
21
22 for raw in text.split('+') {
23 let t = raw.trim().to_ascii_lowercase();
24 match t.as_str() {
25 "" => {}
26 "none" => {}
27 "super" | "win" | "windows" | "logo" | "meta" => {
28 out.super_key = true;
29 any = true;
30 }
31 "lsuper" | "lwin" => {
32 out.left_super = true;
33 any = true;
34 }
35 "rsuper" | "rwin" => {
36 out.right_super = true;
37 any = true;
38 }
39 "alt" => {
40 out.alt = true;
41 any = true;
42 }
43 "lalt" => {
44 out.left_alt = true;
45 any = true;
46 }
47 "ralt" => {
48 out.right_alt = true;
49 any = true;
50 }
51 "ctrl" | "control" => {
52 out.ctrl = true;
53 any = true;
54 }
55 "lctrl" => {
56 out.left_ctrl = true;
57 any = true;
58 }
59 "rctrl" => {
60 out.right_ctrl = true;
61 any = true;
62 }
63 "shift" => {
64 out.shift = true;
65 any = true;
66 }
67 "lshift" => {
68 out.left_shift = true;
69 any = true;
70 }
71 "rshift" => {
72 out.right_shift = true;
73 any = true;
74 }
75 _ => return None,
76 }
77 }
78
79 if any {
80 Some(out)
81 } else {
82 Some(KeyModifiers::default())
83 }
84}