From 1904c404ed426a3c6b7151e5a21a8d9a1678f611 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 18 Dec 2017 10:43:13 +0000 Subject: [PATCH] OS X: pass Command key back to GTK if it's not being Meta. This fixes the problem I'd previously noticed, that if you don't configure the "Command key acts as Meta" setting, then keystrokes like Command-Q which _ought_ to function as accelerators for the application menu bar don't. Turns out that this was for the totally obvious reason: the keyboard event was still being processed by gtkwin.c's key_event() and translated via the GTK IM into ordinary keyboard input. If instead I return FALSE from key_event on detecting that a key event has a non-Meta-configured Command modifier, then it will go to the next- level key-event handler inside GTK itself which implements the menu accelerator behaviour. Another problem ticked off the OS X checklist. --- unix/gtkapp.c | 9 --------- unix/gtkwin.c | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/unix/gtkapp.c b/unix/gtkapp.c index 1c057f21..2a592eb3 100644 --- a/unix/gtkapp.c +++ b/unix/gtkapp.c @@ -27,15 +27,6 @@ and you should get unix/PuTTY.app and unix/PTerm.app as output. TODO list for a sensible GTK3 PuTTY/pterm on OS X: -Menu items' keyboard shortcuts (Command-Q for Quit, Command-V for -Paste) do not currently work. It's intentional that if you turn on -'Command key acts as Meta' in the configuration then those shortcuts -should be superseded by the Meta-key functionality (e.g. Cmd-Q should -send ESC Q to the session), for the benefit of people whose non-Mac -keyboard reflexes expect the Meta key to be in that position; but if -you don't turn that option on, then these shortcuts should work as an -ordinary Mac user expects, and currently they don't. - Mouse wheel events and trackpad scrolling gestures don't work quite right in the terminal drawing area. diff --git a/unix/gtkwin.c b/unix/gtkwin.c index e1ac33ed..feaa2e18 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -168,6 +168,9 @@ struct gui_data { int cursor_type; int drawtype; int meta_mod_mask; +#ifdef OSX_META_KEY_CONFIG + int system_mod_mask; +#endif }; static void cache_conf_values(struct gui_data *inst) @@ -181,6 +184,7 @@ static void cache_conf_values(struct gui_data *inst) inst->meta_mod_mask |= GDK_MOD1_MASK; if (conf_get_int(inst->conf, CONF_osx_command_meta)) inst->meta_mod_mask |= GDK_MOD2_MASK; + inst->system_mod_mask = GDK_MOD2_MASK & ~inst->meta_mod_mask; #else inst->meta_mod_mask = GDK_MOD1_MASK; #endif @@ -780,6 +784,11 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) int ucsval, start, end, special, output_charset, use_ucsoutput; int nethack_mode, app_keypad_mode; +#ifdef OSX_META_KEY_CONFIG + if (event->state & inst->system_mod_mask) + return FALSE; /* let GTK process OS X Command key */ +#endif + /* Remember the timestamp. */ inst->input_event_time = event->time;