#include <pbd/error.h>
#include "keyboard.h"
-#include "keyboard_target.h"
-#include "ardour_dialog.h"
#include "gui_thread.h"
#include "i18n.h"
_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);
}
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;
} else {
keyval = event->keyval;
}
-
if (event->type == GDK_KEY_PRESS) {
bool was_prefix = false;
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->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->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;
sort (state.begin(), state.end());
}
- if (target) {
-#if KBD_DEBUG
- if (debug_keyboard) {
- cerr << "RELEASE: delivering to target " << target << endl;
- }
-#endif
- target->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->key_release_event (event, state);
- }
}
- return TRUE;
+ return false;
}
bool
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)
}
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;
}
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)
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)
}
#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;
}
#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;
}
#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;
}
#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;
}
#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:
cerr << "REAL CROSSING ... out\n";
cerr << "clearing current target\n";
}
-
- set_target (0);
state.clear ();
clear_modifier_state ();
}
}
-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().enter_notify_event.connect (bind (mem_fun(*this, &Keyboard::enter_window), kt));
- kt->window().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<ArdourDialog *>(0)));
- current_dialog->Hiding.connect
- (bind (mem_fun(*this, &Keyboard::set_current_dialog),
- reinterpret_cast<ArdourDialog *>(0)));
-
- current_dialog->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)
{
return (state & RelevantModifierKeyMask) == (guint) mask;
}
-gint
-Keyboard::focus_in_handler (GdkEventFocus* ev)
-{
- allow_focus (true);
- return FALSE;
-}
-
-gint
-Keyboard::focus_out_handler (GdkEventFocus* ev)
-{
- allow_focus (false);
- return FALSE;
-}