diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 29686cc85..5417b3893 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,8 +12,8 @@ version 0.5.0 [future] - Add an option to have window focus follow mouse -- Fix handling of option key on macOS. It now behaves just like the alt key on - Linux. +- macOS: Fix handling of option key. It now behaves just like the alt key on + Linux. There is an option to make it type unicode characters instead. - Linux: Add support for startup notification on X11 desktops. kitty will now inform the window manager when its startup is complete. diff --git a/kitty/config.py b/kitty/config.py index d4de5a07e..1edd3b8d3 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -261,6 +261,7 @@ type_map = { 'initial_window_height': positive_int, 'use_system_wcwidth': to_bool, 'macos_hide_titlebar': to_bool, + 'macos_option_as_alt': to_bool, } for name in ( diff --git a/kitty/keys.c b/kitty/keys.c index f487722f4..ec8362bb4 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -21,6 +21,7 @@ key_to_bytes(int glfw_key, bool smkx, bool extended, int mods, int action) { } #define SPECIAL_INDEX(key) ((key & 0x7f) | ( (mods & 0xF) << 7)) +#define IS_ALT_MODS(mods) (mods == GLFW_MOD_ALT || mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT)) void set_special_key_combo(int glfw_key, int mods) { @@ -42,12 +43,15 @@ active_window() { void on_text_input(unsigned int codepoint, int mods) { Window *w = active_window(); - static char buf[10]; + static char buf[16]; unsigned int sz = 0; if (w != NULL) { bool is_text = mods <= GLFW_MOD_SHIFT; if (is_text) sz = encode_utf8(codepoint, buf); +#ifdef __APPLE__ + if (!OPT(macos_option_as_alt) && IS_ALT_MODS(mods)) sz = encode_utf8(codepoint, buf); +#endif if (sz) schedule_write_to_child(w->id, buf, sz); } } @@ -156,6 +160,9 @@ on_key_input(int key, int scancode, int action, int mods) { if (screen->scrolled_by && action == GLFW_PRESS && !is_modifier_key(key)) { screen_history_scroll(screen, SCROLL_FULL, false); // scroll back to bottom } +#ifdef __APPLE__ + if (!OPT(macos_option_as_alt) && IS_ALT_MODS(mods)) return; +#endif if ( action == GLFW_PRESS || (action == GLFW_REPEAT && screen->modes.mDECARM) || diff --git a/kitty/kitty.conf b/kitty/kitty.conf index c46a8aadd..c087b7b2a 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -319,3 +319,9 @@ map ctrl+shift+backspace restore_font_size # Hide the kitty window's title bar on macOS. macos_hide_titlebar no + +# Use the option key as an alt key. With this set to no, kitty will use +# the macOS native Option+Key = unicode character behavior. This will +# break any Alt+key keyboard shortcuts in your terminal programs, but you +# can use the macOS unicode input technique. +macos_option_as_alt yes diff --git a/kitty/state.c b/kitty/state.c index ec18364c0..ef5b867aa 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -162,6 +162,7 @@ PYWRAP1(set_options) { S(url_color, color_as_int); S(repaint_delay, repaint_delay); S(input_delay, repaint_delay); + S(macos_option_as_alt, PyObject_IsTrue); PyObject *chars = PyObject_GetAttrString(args, "select_by_word_characters"); if (chars == NULL) return NULL; diff --git a/kitty/state.h b/kitty/state.h index 21ff8ea7c..6b22f4ceb 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -19,6 +19,7 @@ typedef struct { color_type url_color; double repaint_delay, input_delay; bool focus_follows_mouse; + bool macos_option_as_alt; } Options; typedef struct {