X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fkeyboard.cc;h=92dce01bb6a90fe57ab7c1ea8f402b46119862e5;hb=ce6c41c060c700489a9ac9fc5080bf2920c17ae2;hp=738f7ab7ca5e3ffaacfa7faf4108e3a4e2479322;hpb=08d33fcb0d35b6448ac1b5a4bcc54095cacbfccd;p=ardour.git diff --git a/gtk2_ardour/keyboard.cc b/gtk2_ardour/keyboard.cc index 738f7ab7ca..92dce01bb6 100644 --- a/gtk2_ardour/keyboard.cc +++ b/gtk2_ardour/keyboard.cc @@ -31,8 +31,6 @@ #include #include "keyboard.h" -#include "keyboard_target.h" -#include "ardour_dialog.h" #include "gui_thread.h" #include "i18n.h" @@ -56,7 +54,7 @@ Keyboard* Keyboard::_the_keyboard = 0; /* set this to initially contain the modifiers we care about, then track changes in ::set_edit_modifier() etc. */ GdkModifierType Keyboard::RelevantModifierKeyMask = - GdkModifierType (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_MOD3_MASK); + GdkModifierType (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_MOD1_MASK|GDK_MOD3_MASK); Keyboard::Keyboard () @@ -65,23 +63,12 @@ Keyboard::Keyboard () _the_keyboard = this; } - target = 0; - default_target = 0; - _queue_events = false; - _flush_queue = false; - playback_ignore_count = 0; - focus_allowed = false; collecting_prefix = false; - current_dialog = 0; get_modifier_masks (); snooper_id = gtk_key_snooper_install (_snooper, (gpointer) this); - /* some global key actions */ - - KeyboardTarget::add_action ("close-dialog", mem_fun(*this, &Keyboard::close_current_dialog)); - XMLNode* node = ARDOUR_UI::instance()->keyboard_settings(); set_state (*node); } @@ -149,26 +136,15 @@ Keyboard::_snooper (GtkWidget *widget, GdkEventKey *event, gpointer data) gint Keyboard::snooper (GtkWidget *widget, GdkEventKey *event) { - bool handled = false; uint32_t keyval; #if KBD_DEBUG if (debug_keyboard) { cerr << "snoop widget " << widget << " key " << event->keyval << " type: " << event->type - << " focus allowed? " << focus_allowed << " current dialog = " << current_dialog << endl; } #endif - /* Only allow key events to propagate to the - usual GTK model when specifically allowed. - Returning FALSE here does that. - */ - - if (focus_allowed) { - return FALSE; - } - if (event->keyval == GDK_Shift_R) { keyval = GDK_Shift_L; @@ -178,7 +154,6 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event) } else { keyval = event->keyval; } - if (event->type == GDK_KEY_PRESS) { bool was_prefix = false; @@ -241,57 +216,6 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event) sort (state.begin(), state.end()); } -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "STATE: "; - for (State::iterator i = state.begin(); i != state.end(); ++i) { - cerr << (*i) << ' '; - } - cerr << endl; - } -#endif - - if (!was_prefix) { - - bool old_collecting_prefix = collecting_prefix; - - if (target) { -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "PRESS: delivering to target " << target << endl; - } -#endif - target->signal_key_press_event (event, state, handled); - } - - if (!handled && default_target) { -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "PRESS: not handled, delivering to default target " << default_target << endl; - } -#endif - default_target->signal_key_press_event (event, state, handled); - } - -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "PRESS: handled ? " << handled << endl; - } -#endif - - if (handled) { - - /* don't reset collecting prefix is start_prefix() - was called by the handler. - */ - - if (collecting_prefix == old_collecting_prefix) { - collecting_prefix = false; - current_prefix = ""; - } - } - } - } else if (event->type == GDK_KEY_RELEASE) { State::iterator i; @@ -301,26 +225,9 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event) sort (state.begin(), state.end()); } - if (target) { -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "RELEASE: delivering to target " << target << endl; - } -#endif - target->signal_key_release_event (event, state); - } - - if (default_target) { -#if KBD_DEBUG - if (debug_keyboard) { - cerr << "RELEASE: delivering to default target " << default_target << endl; - } -#endif - default_target->signal_key_release_event (event, state); - } } - return TRUE; + return false; } bool @@ -329,35 +236,6 @@ Keyboard::key_is_down (uint32_t keyval) return find (state.begin(), state.end(), keyval) != state.end(); } -void -Keyboard::set_target (KeyboardTarget *kt) -{ - /* XXX possible thread issues here */ - target = kt; -} - -void -Keyboard::maybe_unset_target (KeyboardTarget* kt) -{ - if (target == kt) { - target = 0; - } -} - -void -Keyboard::set_default_target (KeyboardTarget *kt) -{ - /* XXX possible thread issues here */ - - default_target = kt; -} - -void -Keyboard::allow_focus (bool yn) -{ - focus_allowed = yn; -} - Keyboard::State Keyboard::translate_key_name (const string& name) @@ -416,7 +294,7 @@ Keyboard::translate_key_name (const string& name) } if ((keycode = gdk_keyval_from_name(get_real_keyname (keyname).c_str())) == GDK_VoidSymbol) { - error << compose(_("KeyboardTarget: keyname \"%1\" is unknown."), keyname) << endmsg; + error << string_compose(_("KeyboardTarget: keyname \"%1\" is unknown."), keyname) << endmsg; result.clear(); return result; } @@ -642,7 +520,7 @@ Keyboard::check_meta_numlock (char keycode, guint mod, string modname) alternate_meta_modname = "Mod2"; break; default: - error << compose (_("Your system is completely broken - NumLock uses \"%1\"" + error << string_compose (_("Your system is completely broken - NumLock uses \"%1\"" "as its modifier. This is madness - see the man page " "for xmodmap to find out how to fix this."), modname) @@ -650,7 +528,7 @@ Keyboard::check_meta_numlock (char keycode, guint mod, string modname) return; } - warning << compose (_("Your system generates \"%1\" when the NumLock key " + warning << string_compose (_("Your system generates \"%1\" when the NumLock key " "is pressed. This can cause problems when editing " "so Ardour will use %2 to mean Meta rather than %1"), modname, alternate_meta_modname) @@ -711,7 +589,7 @@ Keyboard::get_modifier_masks () } #ifdef WARN_ABOUT_DUPLICATE_MODIFIERS if (bound > 1) { - warning << compose (_("You have %1 keys bound to \"mod1\""), bound) << endmsg; + warning << string_compose (_("You have %1 keys bound to \"mod1\""), bound) << endmsg; } #endif bound = 0; @@ -726,7 +604,7 @@ Keyboard::get_modifier_masks () } #ifdef WARN_ABOUT_DUPLICATE_MODIFIERS if (bound > 1) { - warning << compose (_("You have %1 keys bound to \"mod2\""), bound) << endmsg; + warning << string_compose (_("You have %1 keys bound to \"mod2\""), bound) << endmsg; } #endif bound = 0; @@ -741,7 +619,7 @@ Keyboard::get_modifier_masks () } #ifdef WARN_ABOUT_DUPLICATE_MODIFIERS if (bound > 1) { - warning << compose (_("You have %1 keys bound to \"mod3\""), bound) << endmsg; + warning << string_compose (_("You have %1 keys bound to \"mod3\""), bound) << endmsg; } #endif bound = 0; @@ -756,7 +634,7 @@ Keyboard::get_modifier_masks () } #ifdef WARN_ABOUT_DUPLICATE_MODIFIERS if (bound > 1) { - warning << compose (_("You have %1 keys bound to \"mod4\""), bound) << endmsg; + warning << string_compose (_("You have %1 keys bound to \"mod4\""), bound) << endmsg; } #endif bound = 0; @@ -771,44 +649,32 @@ Keyboard::get_modifier_masks () } #ifdef WARN_ABOUT_DUPLICATE_MODIFIERS if (bound > 1) { - warning << compose (_("You have %1 keys bound to \"mod5\""), bound) << endmsg; + warning << string_compose (_("You have %1 keys bound to \"mod5\""), bound) << endmsg; } #endif XFreeModifiermap (modifiers); } -gint -Keyboard::enter_window (GdkEventCrossing *ev, KeyboardTarget *kt) +bool +Keyboard::enter_window (GdkEventCrossing *ev, Gtk::Window* win) { switch (ev->detail) { case GDK_NOTIFY_INFERIOR: - if (debug_keyboard) { - cerr << "INFERIOR crossing to " << kt->name() << endl; - } break; case GDK_NOTIFY_VIRTUAL: - if (debug_keyboard) { - cerr << "VIRTUAL crossing to " << kt->name() << endl; - } /* fallthru */ default: - if (debug_keyboard) { - cerr << "REAL crossing to " << kt->name() << endl; - cerr << "set current target to " << kt->name() << endl; - } - - set_target (kt); check_modifier_state (); } return FALSE; } -gint -Keyboard::leave_window (GdkEventCrossing *ev) +bool +Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* win) { switch (ev->detail) { case GDK_NOTIFY_INFERIOR: @@ -828,8 +694,6 @@ Keyboard::leave_window (GdkEventCrossing *ev) cerr << "REAL CROSSING ... out\n"; cerr << "clearing current target\n"; } - - set_target (0); state.clear (); clear_modifier_state (); } @@ -837,70 +701,6 @@ Keyboard::leave_window (GdkEventCrossing *ev) } -void -Keyboard::register_target (KeyboardTarget *kt) -{ - /* do not register the default - its not meant to be - an actual window, just a fallback if the current - target for keyboard events doesn't handle an event. - */ - - if (kt->name() == X_("default")) { - return; - } - - kt->window().signal_enter_notify_event.connect (bind (mem_fun(*this, &Keyboard::enter_window), kt)); - kt->window().signal_leave_notify_event.connect (mem_fun(*this, &Keyboard::leave_window)); - - kt->GoingAway.connect (bind (mem_fun(*this, &Keyboard::maybe_unset_target), kt)); - kt->Hiding.connect (bind (mem_fun(*this, &Keyboard::maybe_unset_target), kt)); -} - -void -Keyboard::set_current_dialog (ArdourDialog* dialog) -{ - ENSURE_GUI_THREAD(bind (mem_fun(*this, &Keyboard::set_current_dialog), dialog)); - - current_dialog = dialog; - - if (current_dialog) { - - if (find (known_dialogs.begin(), known_dialogs.end(), dialog) == known_dialogs.end()) { - - current_dialog->GoingAway.connect - (bind (mem_fun(*this, &Keyboard::set_current_dialog), - reinterpret_cast(0))); - current_dialog->Hiding.connect - (bind (mem_fun(*this, &Keyboard::set_current_dialog), - reinterpret_cast(0))); - - current_dialog->signal_unmap_event.connect (mem_fun(*this, &Keyboard::current_dialog_vanished)); - - known_dialogs.push_back (dialog); - } - } -} - -gint -Keyboard::current_dialog_vanished (GdkEventAny *ev) -{ - current_dialog = 0; - state.clear (); - focus_allowed = false; - clear_modifier_state (); - current_prefix = ""; - - return FALSE; -} - -void -Keyboard::close_current_dialog () -{ - if (current_dialog) { - current_dialog->hide (); - } -} - void Keyboard::set_edit_button (guint but) { @@ -991,16 +791,14 @@ Keyboard::modifier_state_equals (guint state, ModifierMask mask) return (state & RelevantModifierKeyMask) == (guint) mask; } -gint -Keyboard::focus_in_handler (GdkEventFocus* ev) -{ - allow_focus (true); - return FALSE; -} - -gint -Keyboard::focus_out_handler (GdkEventFocus* ev) +Selection::Operation +Keyboard::selection_type (guint state) { - allow_focus (false); - return FALSE; + if (modifier_state_equals (state, Shift)) { + return Selection::Extend; + } else if (modifier_state_equals (state, Control)) { + return Selection::Toggle; + } else { + return Selection::Set; + } }