macOS: Add an setting to have the option key not behave as alt

This commit is contained in:
Kovid Goyal 2017-11-08 09:14:19 +05:30
parent 1f9acf99b0
commit 505ae90fd7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 19 additions and 3 deletions

View File

@ -12,8 +12,8 @@ version 0.5.0 [future]
- Add an option to have window focus follow mouse - 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 - macOS: Fix handling of option key. It now behaves just like the alt key on
Linux. Linux. There is an option to make it type unicode characters instead.
- Linux: Add support for startup notification on X11 desktops. kitty will - Linux: Add support for startup notification on X11 desktops. kitty will
now inform the window manager when its startup is complete. now inform the window manager when its startup is complete.

View File

@ -261,6 +261,7 @@ type_map = {
'initial_window_height': positive_int, 'initial_window_height': positive_int,
'use_system_wcwidth': to_bool, 'use_system_wcwidth': to_bool,
'macos_hide_titlebar': to_bool, 'macos_hide_titlebar': to_bool,
'macos_option_as_alt': to_bool,
} }
for name in ( for name in (

View File

@ -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 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 void
set_special_key_combo(int glfw_key, int mods) { set_special_key_combo(int glfw_key, int mods) {
@ -42,12 +43,15 @@ active_window() {
void void
on_text_input(unsigned int codepoint, int mods) { on_text_input(unsigned int codepoint, int mods) {
Window *w = active_window(); Window *w = active_window();
static char buf[10]; static char buf[16];
unsigned int sz = 0; unsigned int sz = 0;
if (w != NULL) { if (w != NULL) {
bool is_text = mods <= GLFW_MOD_SHIFT; bool is_text = mods <= GLFW_MOD_SHIFT;
if (is_text) sz = encode_utf8(codepoint, buf); 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); 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)) { if (screen->scrolled_by && action == GLFW_PRESS && !is_modifier_key(key)) {
screen_history_scroll(screen, SCROLL_FULL, false); // scroll back to bottom 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 ( if (
action == GLFW_PRESS || action == GLFW_PRESS ||
(action == GLFW_REPEAT && screen->modes.mDECARM) || (action == GLFW_REPEAT && screen->modes.mDECARM) ||

View File

@ -319,3 +319,9 @@ map ctrl+shift+backspace restore_font_size
# Hide the kitty window's title bar on macOS. # Hide the kitty window's title bar on macOS.
macos_hide_titlebar no 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

View File

@ -162,6 +162,7 @@ PYWRAP1(set_options) {
S(url_color, color_as_int); S(url_color, color_as_int);
S(repaint_delay, repaint_delay); S(repaint_delay, repaint_delay);
S(input_delay, repaint_delay); S(input_delay, repaint_delay);
S(macos_option_as_alt, PyObject_IsTrue);
PyObject *chars = PyObject_GetAttrString(args, "select_by_word_characters"); PyObject *chars = PyObject_GetAttrString(args, "select_by_word_characters");
if (chars == NULL) return NULL; if (chars == NULL) return NULL;

View File

@ -19,6 +19,7 @@ typedef struct {
color_type url_color; color_type url_color;
double repaint_delay, input_delay; double repaint_delay, input_delay;
bool focus_follows_mouse; bool focus_follows_mouse;
bool macos_option_as_alt;
} Options; } Options;
typedef struct { typedef struct {