From b37150e7ae111808be79714eba52dad34b975689 Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 19 Aug 2022 17:30:54 -0400 Subject: X1/X2 commands --- README.md | 9 +++++++-- config.c | 2 ++ main.c | 18 ++++++++---------- ted.c | 13 +++++++++++++ ted.cfg | 3 +++ ted.h | 4 +++- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index dc546bd..8b9c22d 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,13 @@ Comments begin with `#`, and all other lines are of the form `key = value`. By default ted's settings will automatically update when you save the config file. The `core` section's settings should be pretty familiar (font size, etc.) or should have comments on the previous line -explaining what they do. Keyboard shortcuts are of the form `key combo = action`, where `action` is an argument (number or string), +explaining what they do. + +Keyboard shortcuts are of the form `key combo = action`, where `action` is an argument (number or string), followed by a command. The commands match the things in the command palette (Ctrl+Shift+p), but `:` is added to the beginning to make -it clear it's a command. Colors are formatted like `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, where r, g, b, and a are red, green, +it clear it's a command. + +Colors are formatted like `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, where r, g, b, and a are red, green, blue, and alpha (transparency/opacity). You can use a [color picker](https://www.google.com/search?q=color+picker) to help you out. The extensions section is fairly self-explanatory. @@ -156,6 +160,7 @@ Then, open windows\_installer\\ted\\ted.sln, and build. 1.0r3 Better TeX syntax highlighting, move to cursor on backspace/delete 2022 Jul 7 1.1 Minor fixes, syntax highlighting for JavaScript, Java, and Go 2022 Jul 22 1.2 Bug fixes, per-language settings 2022 Jul 29 +1.2r1 Mouse X1/X2 bug fix, support for X1/X2 commands. 2022 Aug 19 ## License diff --git a/config.c b/config.c index 5a52151..4190fe9 100644 --- a/config.c +++ b/config.c @@ -107,6 +107,8 @@ static u32 config_parse_key_combo(ConfigReader *cfg, char const *str) { {"Question Mark", "?", SDL_SCANCODE_SLASH, 1}, {"Question", 0, SDL_SCANCODE_SLASH, 1}, {"Tilde", "~", SDL_SCANCODE_GRAVE, 1}, + {"X1", "x1", SCANCODE_MOUSE_X1, 0}, + {"X2", "x2", SCANCODE_MOUSE_X2, 0} }; // @OPTIMIZE: sort key_names (and split keyname1/2); do a binary search diff --git a/main.c b/main.c index 1687099..66f3d93 100644 --- a/main.c +++ b/main.c @@ -597,6 +597,13 @@ int main(int argc, char **argv) { Uint32 button = event.button.button; u8 times = event.button.clicks; // number of clicks float x = (float)event.button.x, y = (float)event.button.y; + + if (button == SDL_BUTTON_X1) { + ted_press_key(ted, SCANCODE_MOUSE_X1, key_modifier); + } else if (button == SDL_BUTTON_X2) { + ted_press_key(ted, SCANCODE_MOUSE_X2, key_modifier); + } + if (button < arr_count(ted->nmouse_clicks) && ted->nmouse_clicks[button] < arr_count(ted->mouse_clicks[button])) { v2 pos = V2(x, y); @@ -667,16 +674,7 @@ int main(int argc, char **argv) { case SDL_KEYDOWN: { SDL_Scancode scancode = event.key.keysym.scancode; SDL_Keymod modifier = event.key.keysym.mod; - u32 key_combo = (u32)scancode << 3 | - (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); - } - } + ted_press_key(ted, scancode, modifier); } break; case SDL_TEXTINPUT: { char *text = event.text.text; diff --git a/ted.c b/ted.c index 52ce7ed..eba5aad 100644 --- a/ted.c +++ b/ted.c @@ -392,3 +392,16 @@ void ted_load_configs(Ted *ted, bool reloading) { ted_load_fonts(ted); } } + +void ted_press_key(Ted *ted, SDL_Scancode scancode, SDL_Keymod modifier) { + u32 key_combo = (u32)scancode << 3 | + (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); + } + } +} diff --git a/ted.cfg b/ted.cfg index 823cd02..7392494 100644 --- a/ted.cfg +++ b/ted.cfg @@ -142,6 +142,9 @@ Alt+7 = 6 :tab-switch Alt+8 = 7 :tab-switch Alt+9 = 8 :tab-switch Alt+0 = 9 :tab-switch +# (for if you have those fancy extra buttons on your mouse) +X1 = :tab-prev +X2 = :tab-next Ctrl++ = 3 :increase-text-size Ctrl+- = 3 :decrease-text-size diff --git a/ted.h b/ted.h index 30358a4..0eb0786 100644 --- a/ted.h +++ b/ted.h @@ -113,7 +113,9 @@ ENUM_U8 { #define SYNTAX_LINK SYNTAX_CONSTANT // for markdown -#define SCANCODE_COUNT 0x120 // SDL scancodes should be less than this value. +#define SCANCODE_MOUSE_X1 (SDL_NUM_SCANCODES) +#define SCANCODE_MOUSE_X2 (SDL_NUM_SCANCODES+1) +#define SCANCODE_COUNT (SDL_NUM_SCANCODES+2) // a "key combo" is some subset of {control, shift, alt} + some key. #define KEY_COMBO_COUNT (SCANCODE_COUNT << 3) #define KEY_MODIFIER_CTRL_BIT 0 -- cgit v1.2.3