summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-03 15:38:54 -0500
committerpommicket <pommicket@gmail.com>2023-01-03 15:38:54 -0500
commitbaae904ed2c97ba5c701442ec5ef6900715f785d (patch)
tree6e6c10265624510dd73bb8bd0213a59fc02e3617 /ted.c
parentc37d493327ded5952f46cbf39aef920e47c1d7d9 (diff)
switch from scancodes to keycodes
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/ted.c b/ted.c
index 5033467..389bd53 100644
--- a/ted.c
+++ b/ted.c
@@ -549,17 +549,28 @@ void ted_load_configs(Ted *ted, bool reloading) {
}
}
-void ted_press_key(Ted *ted, SDL_Scancode scancode, SDL_Keymod modifier) {
- u32 key_combo = (u32)scancode << 3 |
+void ted_press_key(Ted *ted, SDL_Keycode keycode, SDL_Keymod modifier) {
+ u32 key_combo = KEY_COMBO(
(u32)((modifier & (KMOD_LCTRL|KMOD_RCTRL)) != 0) << KEY_MODIFIER_CTRL_BIT |
(u32)((modifier & (KMOD_LSHIFT|KMOD_RSHIFT)) != 0) << KEY_MODIFIER_SHIFT_BIT |
- (u32)((modifier & (KMOD_LALT|KMOD_RALT)) != 0) << KEY_MODIFIER_ALT_BIT;
- if (key_combo < KEY_COMBO_COUNT) {
- KeyAction *action = &ted_active_settings(ted)->key_actions[key_combo];
- if (action->command) {
- command_execute(ted, action->command, action->argument);
+ (u32)((modifier & (KMOD_LALT|KMOD_RALT)) != 0) << KEY_MODIFIER_ALT_BIT,
+ keycode);
+
+ const KeyAction *const key_actions = ted_active_settings(ted)->key_actions;
+ u32 lo = 0;
+ u32 hi = arr_len(key_actions);
+ while (lo < hi) {
+ u32 mid = (lo + hi) / 2;
+ if (key_actions[mid].key_combo < key_combo) {
+ lo = mid + 1;
+ } else if (key_actions[mid].key_combo > key_combo) {
+ hi = mid;
+ } else {
+ command_execute(ted, key_actions[mid].command, key_actions[mid].argument);
+ return;
}
}
+ // nothing bound to this key
}
bool ted_get_mouse_buffer_pos(Ted *ted, TextBuffer **pbuffer, BufferPos *ppos) {