Fix setting command key bindings on OSX.
authorDavid Robillard <d@drobilla.net>
Thu, 15 Jan 2015 01:31:38 +0000 (20:31 -0500)
committerDavid Robillard <d@drobilla.net>
Thu, 15 Jan 2015 01:31:38 +0000 (20:31 -0500)
gtk2_ardour/keyeditor.cc
gtk2_ardour/utils.cc
libs/gtkmm2ext/gtkmm2ext/utils.h
libs/gtkmm2ext/utils.cc

index 85522a7e41ae13955ade7547f2211e6cc9f96547..f8b5f2da4e945062004d53f2b950dc0187d46221 100644 (file)
@@ -203,11 +203,14 @@ KeyEditor::on_key_release_event (GdkEventKey* ev)
                        goto out;
                }
 
+               GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & ev->state);
+
                Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
+               Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator (mod);
 
                bool result = AccelMap::change_entry (path,
                                                      last_keyval,
-                                                     ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
+                                                     Gdk::ModifierType(mod),
                                                      true);
 
                if (result) {
index c9d3abe1115cc3d3a94f3ab1e6f71cf2c497b055..a88ee7f9a5e15431f48c694858b29bf69e029b93 100644 (file)
@@ -450,24 +450,7 @@ ARDOUR_UI_UTILS::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEv
                        GdkModifierType mod = GdkModifierType (ev->state);
 
                        mod = GdkModifierType (mod & gtk_accelerator_get_default_mod_mask());
-#ifdef GTKOSX
-                       /* GTK on OS X is currently (February 2012) setting both
-                          the Meta and Mod2 bits in the event modifier state if 
-                          the Command key is down.
-
-                          gtk_accel_groups_activate() does not invoke any of the logic
-                          that gtk_window_activate_key() will that sorts out that stupid
-                          state of affairs, and as a result it fails to find a match
-                          for the key event and the current set of accelerators.
-
-                          to fix this, if the meta bit is set, remove the mod2 bit
-                          from the modifier. this assumes that our bindings use Primary
-                          which will have set the meta bit in the accelerator entry.
-                       */
-                       if (mod & GDK_META_MASK) {
-                               mod = GdkModifierType (mod & ~GDK_MOD2_MASK);
-                       }
-#endif
+                       Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator(mod);
 
                        if (allow_activating && gtk_accel_groups_activate(G_OBJECT(win), fakekey, mod)) {
                                DEBUG_TRACE (DEBUG::Accelerators, "\taccel group activated by fakekey\n");
index daae1b78aa6f2b1277d5d201b8132566ac69ae7c..53c8ea2fdf87cb0a983b42aff543b39309cc2a00 100644 (file)
@@ -110,6 +110,7 @@ namespace Gtkmm2ext {
        LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Window> window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent);
 
         LIBGTKMM2EXT_API bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
+        LIBGTKMM2EXT_API bool possibly_translate_mod_to_make_legal_accelerator (GdkModifierType& mod);
         LIBGTKMM2EXT_API uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
 
         LIBGTKMM2EXT_API int physical_screen_height (Glib::RefPtr<Gdk::Window>);
index b4926ac43b0177761e1293c94fa74f4123fb7a92..f7e96f09c8a0ba8b67d33b0beb8bcf067607b354 100644 (file)
@@ -337,6 +337,30 @@ Gtkmm2ext::detach_menu (Gtk::Menu& menu)
        }
 }
 
+bool
+Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator (GdkModifierType& mod)
+{
+#ifdef GTKOSX
+       /* GTK on OS X is currently (February 2012) setting both
+          the Meta and Mod2 bits in the event modifier state if
+          the Command key is down.
+
+          gtk_accel_groups_activate() does not invoke any of the logic
+          that gtk_window_activate_key() will that sorts out that stupid
+          state of affairs, and as a result it fails to find a match
+          for the key event and the current set of accelerators.
+
+          to fix this, if the meta bit is set, remove the mod2 bit
+          from the modifier. this assumes that our bindings use Primary
+          which will have set the meta bit in the accelerator entry.
+       */
+       if (mod & GDK_META_MASK) {
+               mod = GdkModifierType (mod & ~GDK_MOD2_MASK);
+       }
+#endif
+       return true;
+}
+
 bool
 Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval)
 {