Make editor route list rec button respect group settings.
[ardour.git] / gtk2_ardour / keyboard.cc
index ef8cc3438938be21d28d3b991a243b9927c1a813..f3542054aafad01d36673719dc2a8439e1259988 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 #include <vector>
-#include <ardour/ardour.h>
+#include "ardour/ardour.h"
 
 #include "ardour_ui.h"
 
 #include <gtkmm/accelmap.h>
 
 #include <gdk/gdkkeysyms.h>
-#include <pbd/error.h>
-#include <pbd/file_utils.h>
+#include "pbd/error.h"
+#include "pbd/file_utils.h"
 
-#include <ardour/filesystem_paths.h>
+#include "ardour/filesystem_paths.h"
 
 #include "keyboard.h"
 #include "gui_thread.h"
@@ -64,6 +64,7 @@ guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift
 guint Keyboard::Level4Modifier = GDK_CONTROL_MASK; // Control
 guint Keyboard::CopyModifier = GDK_MOD1_MASK;      // Alt/Option
 guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;   
+guint Keyboard::button2_modifiers = Keyboard::SecondaryModifier|Keyboard::Level4Modifier;
 #else
 guint Keyboard::PrimaryModifier = GDK_CONTROL_MASK; // Control
 guint Keyboard::SecondaryModifier = GDK_MOD1_MASK;  // Alt/Option
@@ -71,8 +72,10 @@ guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK;  // Shift
 guint Keyboard::Level4Modifier = GDK_MOD4_MASK;     // Mod4/Windows
 guint Keyboard::CopyModifier = GDK_CONTROL_MASK;    
 guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;   
+guint Keyboard::button2_modifiers = 0; /* not used */
 #endif
 
+
 Keyboard*    Keyboard::_the_keyboard = 0;
 Gtk::Window* Keyboard::current_window = 0;
 bool         Keyboard::_some_magic_widget_has_focus = false;
@@ -265,10 +268,20 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
                }
        }
 
-       if (event->type == GDK_KEY_RELEASE && event->keyval == GDK_w && modifier_state_equals (event->state, PrimaryModifier)) {
-               if (current_window) {
-                       current_window->hide ();
-                       current_window = 0;
+       /* Special keys that we want to handle in
+          any dialog, no matter whether it uses
+          the regular set of accelerators or not
+       */
+
+       if (event->type == GDK_KEY_RELEASE && modifier_state_equals (event->state, PrimaryModifier)) {
+               switch (event->keyval) {
+               case GDK_w:
+                       if (current_window) {
+                               current_window->hide ();
+                               current_window = 0;
+                               ret = true;
+                       }
+                       break;
                }
        }
 
@@ -282,34 +295,38 @@ Keyboard::key_is_down (uint32_t keyval)
 }
 
 bool
-Keyboard::enter_window (GdkEventCrossing *ev, Gtk::Window* win)
+Keyboard::enter_window (GdkEventCrossing *, Gtk::Window* win)
 {
        current_window = win;
        return false;
 }
 
 bool
-Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* win)
+Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* /*win*/)
 {
-       switch (ev->detail) {
-       case GDK_NOTIFY_INFERIOR:
-               if (debug_keyboard) {
-                       cerr << "INFERIOR crossing ... out\n";
-               }
-               break;
-
-       case GDK_NOTIFY_VIRTUAL:
-               if (debug_keyboard) {
-                       cerr << "VIRTUAL crossing ... out\n";
-               }
-               /* fallthru */
-
-       default:
-               if (debug_keyboard) {
-                       cerr << "REAL CROSSING ... out\n";
-                       cerr << "clearing current target\n";
+       if (ev) {
+               switch (ev->detail) {
+               case GDK_NOTIFY_INFERIOR:
+                       if (debug_keyboard) {
+                               cerr << "INFERIOR crossing ... out\n";
+                       }
+                       break;
+                       
+               case GDK_NOTIFY_VIRTUAL:
+                       if (debug_keyboard) {
+                               cerr << "VIRTUAL crossing ... out\n";
+                       }
+                       /* fallthru */
+                       
+               default:
+                       if (debug_keyboard) {
+                               cerr << "REAL CROSSING ... out\n";
+                               cerr << "clearing current target\n";
+                       }
+                       state.clear ();
+                       current_window = 0;
                }
-               state.clear ();
+       } else {
                current_window = 0;
        }
 
@@ -363,12 +380,23 @@ Keyboard::set_snap_modifier (guint mod)
 bool
 Keyboard::is_edit_event (GdkEventButton *ev)
 {
-
        return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) && 
                (ev->button == Keyboard::edit_button()) && 
                ((ev->state & RelevantModifierKeyMask) == Keyboard::edit_modifier());
 }
 
+bool
+Keyboard::is_button2_event (GdkEventButton* ev)
+{
+#ifdef GTKOSX
+       return (ev->button == 2) || 
+               ((ev->button == 1) && 
+                ((ev->state & Keyboard::button2_modifiers) == Keyboard::button2_modifiers));
+#else
+       return ev->button == 2;
+#endif 
+}
+
 bool
 Keyboard::is_delete_event (GdkEventButton *ev)
 {
@@ -419,11 +447,11 @@ Keyboard::selection_type (guint state)
 
 
 static void 
-accel_map_changed (GtkAccelMap* map,
-                  gchar* path,
-                  guint  key,
-                  GdkModifierType mod,
-                  gpointer arg)
+accel_map_changed (GtkAccelMap* /*map*/,
+                  gchar* /*path*/,
+                  guint /*key*/,
+                  GdkModifierType /*mod*/,
+                  gpointer /*arg*/)
 {
        Keyboard::keybindings_changed ();
 }
@@ -589,7 +617,7 @@ bool
 Keyboard::load_keybindings (string path)
 {
        try {
-               cerr << "loading bindings from " << path << endl;
+               cerr << "Loading bindings from " << path << endl;
 
                Gtk::AccelMap::load (path);
 
@@ -623,6 +651,24 @@ Keyboard::load_keybindings (string path)
 
        release_keys.clear ();
 
+       bool show_bindings = (getenv ("ARDOUR_SHOW_BINDINGS") != 0);
+       
+       for (n = names.begin(), b = bindings.begin(), g = groups.begin(); n != names.end(); ++n, ++b, ++g) {
+               
+               if (show_bindings) {
+                       
+                       cerr << "Action: " << (*n) << " Group: " << (*g) << " binding = ";
+                       
+                       if ((*b).get_key() != GDK_VoidSymbol) {
+                               cerr << (*b).get_key() << " w/mod = " << hex << (*b).get_mod() << dec << " = " << (*b).get_abbrev();
+                       } else {
+                               cerr << "unbound";
+                       }
+                       
+                       cerr << endl;
+               }
+       }
+
        for (n = names.begin(), b = bindings.begin(), g = groups.begin(); n != names.end(); ++n, ++b, ++g) {
                if ((*b).get_mod() & Gdk::RELEASE_MASK) {
                        release_keys.insert (pair<AccelKey,two_strings> (*b, two_strings (*g, *n)));