Diff
diff --git a/src/bar/bar.rs b/src/bar/bar.rs
index 567e3cb..652d5df 100644
--- a/src/bar/bar.rs
+++ b/src/bar/bar.rs
@@ -259,13 +259,11 @@ impl Bar {
self.scheme_normal.foreground,
text_x,
text_y,
- layout_symbol
+ layout_symbol,
);
- // Update x_position after layout symbol
x_position += font.text_width(layout_symbol) as i16;
- // Draw keychord indicator if present
if let Some(indicator) = keychord_indicator {
x_position += 10;
diff --git a/src/config/mod.rs b/src/config/mod.rs
index ee93417..c63ee93 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -199,11 +199,11 @@ struct ConfigData {
#[derive(Debug, Deserialize)]
struct KeybindingData {
#[serde(default)]
- keys: Option<Vec<KeyPressData>>, // New format
+ keys: Option<Vec<KeyPressData>>,
#[serde(default)]
- modifiers: Option<Vec<ModKey>>, // Old format (backwards compat)
+ modifiers: Option<Vec<ModKey>>,
#[serde(default)]
- key: Option<KeyData>, // Old format (backwards compat)
+ key: Option<KeyData>,
action: KeyAction,
#[serde(default)]
arg: ArgData,
@@ -263,7 +263,6 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
let mut keybindings = Vec::new();
for kb_data in data.keybindings {
let keys = if let Some(keys_data) = kb_data.keys {
- // New format: multiple keys
keys_data
.into_iter()
.map(|kp| {
@@ -283,7 +282,6 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
})
.collect()
} else if let (Some(modifiers), Some(key)) = (kb_data.modifiers, kb_data.key) {
- // Old format: single key (backwards compatibility)
vec![KeyPress {
modifiers: modifiers
.iter()
@@ -295,7 +293,9 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
key: key.to_keycode(),
}]
} else {
- return Err(ConfigError::ValidationError("Keybinding must have either 'keys' or 'modifiers'+'key'".to_string()));
+ return Err(ConfigError::ValidationError(
+ "Keybinding must have either 'keys' or 'modifiers'+'key'".to_string(),
+ ));
};
let action = kb_data.action;
diff --git a/src/keyboard/handlers.rs b/src/keyboard/handlers.rs
index c7722c9..7e6ff2b 100644
--- a/src/keyboard/handlers.rs
+++ b/src/keyboard/handlers.rs
@@ -45,14 +45,12 @@ impl Arg {
}
}
-// Individual key press in a sequence
#[derive(Clone, Debug)]
pub struct KeyPress {
pub(crate) modifiers: Vec<KeyButMask>,
pub(crate) key: Keycode,
}
-// Keybinding that can be a single key or a chord (sequence of keys)
#[derive(Clone)]
pub struct KeyBinding {
pub(crate) keys: Vec<KeyPress>,
@@ -65,7 +63,6 @@ impl KeyBinding {
Self { keys, func, arg }
}
- // Helper for backwards compatibility with single-key bindings
pub fn single_key(modifiers: Vec<KeyButMask>, key: Keycode, func: KeyAction, arg: Arg) -> Self {
Self {
keys: vec![KeyPress { modifiers, key }],
@@ -75,16 +72,13 @@ impl KeyBinding {
}
}
-// For backwards compatibility during migration
pub type Key = KeyBinding;
#[derive(Debug, Clone)]
pub enum KeychordState {
Idle,
InProgress {
- // Indices of keybindings that could still match
candidates: Vec<usize>,
- // How many keys have been pressed in the sequence
keys_pressed: usize,
},
}
@@ -155,19 +149,15 @@ pub fn handle_key_press(
}
match keychord_state {
- KeychordState::Idle => {
- handle_first_key(event, keybindings)
- }
- KeychordState::InProgress { candidates, keys_pressed } => {
- handle_next_key(event, keybindings, candidates, *keys_pressed)
- }
+ KeychordState::Idle => handle_first_key(event, keybindings),
+ KeychordState::InProgress {
+ candidates,
+ keys_pressed,
+ } => handle_next_key(event, keybindings, candidates, *keys_pressed),
}
}
-fn handle_first_key(
- event: KeyPressEvent,
- keybindings: &[KeyBinding],
-) -> KeychordResult {
+fn handle_first_key(event: KeyPressEvent, keybindings: &[KeyBinding]) -> KeychordResult {
let mut candidates = Vec::new();
for (keybinding_index, keybinding) in keybindings.iter().enumerate() {
@@ -180,10 +170,7 @@ fn handle_first_key(
if event.detail == first_key.key && event.state == modifier_mask.into() {
if keybinding.keys.len() == 1 {
- return KeychordResult::Completed(
- keybinding.func,
- keybinding.arg.clone(),
- );
+ return KeychordResult::Completed(keybinding.func, keybinding.arg.clone());
} else {
candidates.push(keybinding_index);
}
@@ -224,10 +211,7 @@ fn handle_next_key(
if event.detail == next_key.key && modifiers_match {
if keys_pressed + 1 == keybinding.keys.len() {
- return KeychordResult::Completed(
- keybinding.func,
- keybinding.arg.clone(),
- );
+ return KeychordResult::Completed(keybinding.func, keybinding.arg.clone());
} else {
new_candidates.push(candidate_index);
}