tony / oxwm

removed unneeded comments Browse files
tonybtw committed 2025-10-29 parent 2809716 commit c07ef1146c5e30b3fca93419618a5a0fc6636e29
Showing 3 changed files with 15 additions and 33 deletions. UnifiedSplit
+1 −3 src/bar/bar.rs
@@ -259,13 +259,11 @@ impl Bar {
259 self.scheme_normal.foreground, 259 self.scheme_normal.foreground,
260 text_x, 260 text_x,
261 text_y, 261 text_y,
262 - layout_symbol 262 + layout_symbol,
263 ); 263 );
264 264
265 - // Update x_position after layout symbol
266 x_position += font.text_width(layout_symbol) as i16; 265 x_position += font.text_width(layout_symbol) as i16;
267 266
268 - // Draw keychord indicator if present
269 if let Some(indicator) = keychord_indicator { 267 if let Some(indicator) = keychord_indicator {
270 x_position += 10; 268 x_position += 10;
271 269
+6 −6 src/config/mod.rs
@@ -199,11 +199,11 @@ struct ConfigData {
199 #[derive(Debug, Deserialize)] 199 #[derive(Debug, Deserialize)]
200 struct KeybindingData { 200 struct KeybindingData {
201 #[serde(default)] 201 #[serde(default)]
202 - keys: Option<Vec<KeyPressData>>, // New format 202 + keys: Option<Vec<KeyPressData>>,
203 #[serde(default)] 203 #[serde(default)]
204 - modifiers: Option<Vec<ModKey>>, // Old format (backwards compat) 204 + modifiers: Option<Vec<ModKey>>,
205 #[serde(default)] 205 #[serde(default)]
206 - key: Option<KeyData>, // Old format (backwards compat) 206 + key: Option<KeyData>,
207 action: KeyAction, 207 action: KeyAction,
208 #[serde(default)] 208 #[serde(default)]
209 arg: ArgData, 209 arg: ArgData,
@@ -263,7 +263,6 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
263 let mut keybindings = Vec::new(); 263 let mut keybindings = Vec::new();
264 for kb_data in data.keybindings { 264 for kb_data in data.keybindings {
265 let keys = if let Some(keys_data) = kb_data.keys { 265 let keys = if let Some(keys_data) = kb_data.keys {
266 - // New format: multiple keys
267 keys_data 266 keys_data
268 .into_iter() 267 .into_iter()
269 .map(|kp| { 268 .map(|kp| {
@@ -283,7 +282,6 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
283 }) 282 })
284 .collect() 283 .collect()
285 } else if let (Some(modifiers), Some(key)) = (kb_data.modifiers, kb_data.key) { 284 } else if let (Some(modifiers), Some(key)) = (kb_data.modifiers, kb_data.key) {
286 - // Old format: single key (backwards compatibility)
287 vec![KeyPress { 285 vec![KeyPress {
288 modifiers: modifiers 286 modifiers: modifiers
289 .iter() 287 .iter()
@@ -295,7 +293,9 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
295 key: key.to_keycode(), 293 key: key.to_keycode(),
296 }] 294 }]
297 } else { 295 } else {
298 - return Err(ConfigError::ValidationError("Keybinding must have either 'keys' or 'modifiers'+'key'".to_string())); 296 + return Err(ConfigError::ValidationError(
297 + "Keybinding must have either 'keys' or 'modifiers'+'key'".to_string(),
298 + ));
299 }; 299 };
300 300
301 let action = kb_data.action; 301 let action = kb_data.action;
+8 −24 src/keyboard/handlers.rs
@@ -45,14 +45,12 @@ impl Arg {
45 } 45 }
46 } 46 }
47 47
48 -// Individual key press in a sequence
49 #[derive(Clone, Debug)] 48 #[derive(Clone, Debug)]
50 pub struct KeyPress { 49 pub struct KeyPress {
51 pub(crate) modifiers: Vec<KeyButMask>, 50 pub(crate) modifiers: Vec<KeyButMask>,
52 pub(crate) key: Keycode, 51 pub(crate) key: Keycode,
53 } 52 }
54 53
55 -// Keybinding that can be a single key or a chord (sequence of keys)
56 #[derive(Clone)] 54 #[derive(Clone)]
57 pub struct KeyBinding { 55 pub struct KeyBinding {
58 pub(crate) keys: Vec<KeyPress>, 56 pub(crate) keys: Vec<KeyPress>,
@@ -65,7 +63,6 @@ impl KeyBinding {
65 Self { keys, func, arg } 63 Self { keys, func, arg }
66 } 64 }
67 65
68 - // Helper for backwards compatibility with single-key bindings
69 pub fn single_key(modifiers: Vec<KeyButMask>, key: Keycode, func: KeyAction, arg: Arg) -> Self { 66 pub fn single_key(modifiers: Vec<KeyButMask>, key: Keycode, func: KeyAction, arg: Arg) -> Self {
70 Self { 67 Self {
71 keys: vec![KeyPress { modifiers, key }], 68 keys: vec![KeyPress { modifiers, key }],
@@ -75,16 +72,13 @@ impl KeyBinding {
75 } 72 }
76 } 73 }
77 74
78 -// For backwards compatibility during migration
79 pub type Key = KeyBinding; 75 pub type Key = KeyBinding;
80 76
81 #[derive(Debug, Clone)] 77 #[derive(Debug, Clone)]
82 pub enum KeychordState { 78 pub enum KeychordState {
83 Idle, 79 Idle,
84 InProgress { 80 InProgress {
85 - // Indices of keybindings that could still match
86 candidates: Vec<usize>, 81 candidates: Vec<usize>,
87 - // How many keys have been pressed in the sequence
88 keys_pressed: usize, 82 keys_pressed: usize,
89 }, 83 },
90 } 84 }
@@ -155,19 +149,15 @@ pub fn handle_key_press(
155 } 149 }
156 150
157 match keychord_state { 151 match keychord_state {
158 - KeychordState::Idle => { 152 + KeychordState::Idle => handle_first_key(event, keybindings),
159 - handle_first_key(event, keybindings) 153 + KeychordState::InProgress {
160 - } 154 + candidates,
161 - KeychordState::InProgress { candidates, keys_pressed } => { 155 + keys_pressed,
162 - handle_next_key(event, keybindings, candidates, *keys_pressed) 156 + } => handle_next_key(event, keybindings, candidates, *keys_pressed),
163 - }
164 } 157 }
165 } 158 }
166 159
167 -fn handle_first_key( 160 +fn handle_first_key(event: KeyPressEvent, keybindings: &[KeyBinding]) -> KeychordResult {
168 - event: KeyPressEvent,
169 - keybindings: &[KeyBinding],
170 -) -> KeychordResult {
171 let mut candidates = Vec::new(); 161 let mut candidates = Vec::new();
172 162
173 for (keybinding_index, keybinding) in keybindings.iter().enumerate() { 163 for (keybinding_index, keybinding) in keybindings.iter().enumerate() {
@@ -180,10 +170,7 @@ fn handle_first_key(
180 170
181 if event.detail == first_key.key && event.state == modifier_mask.into() { 171 if event.detail == first_key.key && event.state == modifier_mask.into() {
182 if keybinding.keys.len() == 1 { 172 if keybinding.keys.len() == 1 {
183 - return KeychordResult::Completed( 173 + return KeychordResult::Completed(keybinding.func, keybinding.arg.clone());
184 - keybinding.func,
185 - keybinding.arg.clone(),
186 - );
187 } else { 174 } else {
188 candidates.push(keybinding_index); 175 candidates.push(keybinding_index);
189 } 176 }
@@ -224,10 +211,7 @@ fn handle_next_key(
224 211
225 if event.detail == next_key.key && modifiers_match { 212 if event.detail == next_key.key && modifiers_match {
226 if keys_pressed + 1 == keybinding.keys.len() { 213 if keys_pressed + 1 == keybinding.keys.len() {
227 - return KeychordResult::Completed( 214 + return KeychordResult::Completed(keybinding.func, keybinding.arg.clone());
228 - keybinding.func,
229 - keybinding.arg.clone(),
230 - );
231 } else { 215 } else {
232 new_candidates.push(candidate_index); 216 new_candidates.push(candidate_index);
233 } 217 }