Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 14cba49

Browse files
committed
chore: improve keybind handling and debugging output
1. Add #[allow(dead_code)] attribute for ButtonConfig.label field to suppress warnings 2. Add detailed debug printing of loaded keybind configurations 3. Implement proper Unicode character handling for keybind matching 4. Add fallback to key name matching for non-character keys 5. Include additional context in trigger debug logs chore: 改进按键绑定处理和调试输出 1. 为 ButtonConfig.label 字段添加 #[allow(dead_code)] 属性以抑制警告 2. 添加对加载的按键绑定配置的详细调试打印 3. 实现正确的 Unicode 字符处理用于按键绑定匹配 4. 对非字符键添加键名匹配的回退机制 5. 在触发日志中包含更多上下文信息
1 parent 7a364e6 commit 14cba49

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::process::Command;
22

33
#[derive(Debug, Clone)]
44
pub struct ButtonConfig {
5+
#[allow(dead_code)]
56
pub label: String,
67
pub action: String,
78
pub text: String,

src/main.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ impl SimpleComponent for App {
5353

5454
// Load configuration
5555
let config = Config::load_from_kdl().expect("Failed to load configuration");
56+
57+
// Debug: print loaded keybinds
58+
println!("Loaded keybinds:");
59+
for button_config in &config.buttons {
60+
println!(" '{}' -> {} ({})",
61+
button_config.keybind,
62+
button_config.text,
63+
button_config.action);
64+
}
65+
5666
let model = App { config };
5767

5868
// Create dynamic UI based on configuration
@@ -101,12 +111,26 @@ impl SimpleComponent for App {
101111
if key == gdk::Key::Escape {
102112
sender_clone.input(AppInput::Quit);
103113
} else {
104-
// Check for keybind matches
105-
let key_name = key.name().unwrap_or_default().to_lowercase();
106-
for button_config in &config_clone {
107-
if button_config.keybind.to_lowercase() == key_name {
108-
sender_clone.input(AppInput::ExecuteAction(button_config.action.clone()));
109-
break;
114+
// Check for keybind matches using keyval
115+
let key_char = key.to_unicode();
116+
if let Some(ch) = key_char {
117+
let key_str = ch.to_lowercase().to_string();
118+
for button_config in &config_clone {
119+
if button_config.keybind.to_lowercase() == key_str {
120+
println!("Triggered keybind '{}' for action: {}", button_config.keybind, button_config.action);
121+
sender_clone.input(AppInput::ExecuteAction(button_config.action.clone()));
122+
break;
123+
}
124+
}
125+
} else {
126+
// 对于非字符键,使用键名匹配
127+
let key_name = key.name().unwrap_or_default().to_lowercase();
128+
for button_config in &config_clone {
129+
if button_config.keybind.to_lowercase() == key_name {
130+
println!("Triggered keybind '{}' for action: {}", button_config.keybind, button_config.action);
131+
sender_clone.input(AppInput::ExecuteAction(button_config.action.clone()));
132+
break;
133+
}
110134
}
111135
}
112136
}

0 commit comments

Comments
 (0)