13
0

NO-OP: clang format

This commit is contained in:
Robin Gareus 2022-06-21 21:16:12 +02:00
parent 696e05c3e5
commit f1eb45e129
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 389 additions and 279 deletions

View File

@ -24,40 +24,41 @@
#define __libgtkmm2ext_keyboard_h__ #define __libgtkmm2ext_keyboard_h__
#include <map> #include <map>
#include <vector>
#include <string> #include <string>
#include <vector>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtkmm/accelkey.h> #include <gtkmm/accelkey.h>
#include "pbd/stateful.h"
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/stateful.h"
#include "gtkmm2ext/visibility.h" #include "gtkmm2ext/visibility.h"
namespace Gtk { namespace Gtk
{
class Window; class Window;
} }
namespace Gtkmm2ext { namespace Gtkmm2ext
{
class Bindings; class Bindings;
class ActionMap; class ActionMap;
class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
{ {
public: public:
Keyboard (); Keyboard ();
~Keyboard (); ~Keyboard ();
XMLNode& get_state () const; XMLNode& get_state () const;
int set_state (const XMLNode&, int version); int set_state (const XMLNode&, int version);
virtual void setup_keybindings () = 0; virtual void setup_keybindings () = 0;
static void reset_relevant_modifier_key_mask (); static void reset_relevant_modifier_key_mask ();
typedef std::vector<uint32_t> State; typedef std::vector<uint32_t> State;
typedef uint32_t ModifierMask; typedef uint32_t ModifierMask;
static uint32_t PrimaryModifier; static uint32_t PrimaryModifier;
static uint32_t SecondaryModifier; static uint32_t SecondaryModifier;
@ -87,22 +88,28 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
static const char* tertiary_modifier_short_name (); static const char* tertiary_modifier_short_name ();
static const char* level4_modifier_short_name (); static const char* level4_modifier_short_name ();
static void set_primary_modifier (uint32_t newval) { static void set_primary_modifier (uint32_t newval)
{
set_modifier (newval, PrimaryModifier); set_modifier (newval, PrimaryModifier);
} }
static void set_secondary_modifier (uint32_t newval) { static void set_secondary_modifier (uint32_t newval)
{
set_modifier (newval, SecondaryModifier); set_modifier (newval, SecondaryModifier);
} }
static void set_tertiary_modifier (uint32_t newval) { static void set_tertiary_modifier (uint32_t newval)
{
set_modifier (newval, TertiaryModifier); set_modifier (newval, TertiaryModifier);
} }
static void set_level4_modifier (uint32_t newval) { static void set_level4_modifier (uint32_t newval)
{
set_modifier (newval, Level4Modifier); set_modifier (newval, Level4Modifier);
} }
static void set_copy_modifier (uint32_t newval) { static void set_copy_modifier (uint32_t newval)
{
set_modifier (newval, CopyModifier); set_modifier (newval, CopyModifier);
} }
static void set_range_select_modifier (uint32_t newval) { static void set_range_select_modifier (uint32_t newval)
{
set_modifier (newval, RangeSelectModifier); set_modifier (newval, RangeSelectModifier);
} }
@ -110,32 +117,44 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
static GdkModifierType RelevantModifierKeyMask; static GdkModifierType RelevantModifierKeyMask;
static bool no_modifier_keys_pressed(GdkEventButton* ev) { static bool no_modifier_keys_pressed (GdkEventButton* ev)
{
return (ev->state & RelevantModifierKeyMask) == 0; return (ev->state & RelevantModifierKeyMask) == 0;
} }
static bool no_modifier_keys_pressed(GdkEventKey* ev) { static bool no_modifier_keys_pressed (GdkEventKey* ev)
{
return (ev->state & RelevantModifierKeyMask) == 0; return (ev->state & RelevantModifierKeyMask) == 0;
} }
bool leave_window (GdkEventCrossing *ev, Gtk::Window*); bool leave_window (GdkEventCrossing* ev, Gtk::Window*);
bool enter_window (GdkEventCrossing *ev, Gtk::Window*); bool enter_window (GdkEventCrossing* ev, Gtk::Window*);
bool focus_in_window (GdkEventFocus *ev, Gtk::Window*); bool focus_in_window (GdkEventFocus* ev, Gtk::Window*);
bool focus_out_window (GdkEventFocus *ev, Gtk::Window*); bool focus_out_window (GdkEventFocus* ev, Gtk::Window*);
static bool modifier_state_contains (guint state, ModifierMask); static bool modifier_state_contains (guint state, ModifierMask);
static bool modifier_state_equals (guint state, ModifierMask); static bool modifier_state_equals (guint state, ModifierMask);
static bool no_modifiers_active (guint state); static bool no_modifiers_active (guint state);
static void set_snap_modifier (guint); static void set_snap_modifier (guint);
static void set_snap_delta_modifier (guint);
static void set_edit_button (guint);
static void set_edit_modifier (guint);
static void set_delete_button (guint);
static void set_delete_modifier (guint);
static void set_insert_note_button (guint);
static void set_insert_note_modifier (guint);
/** @return Modifier mask to temporarily toggle grid setting; with this modifier /** @return Modifier mask to temporarily toggle grid setting; with this modifier
* - magnetic or normal grid should become no grid and * - magnetic or normal grid should become no grid and
* - no grid should become normal grid * - no grid should become normal grid
*/ */
static ModifierMask snap_modifier () { return ModifierMask (snap_mod); } static ModifierMask snap_modifier ()
{
return ModifierMask (snap_mod);
}
static void set_snap_delta_modifier (guint);
/** @return Modifier mask to temporarily toggle between relative and absolute grid setting. /** @return Modifier mask to temporarily toggle between relative and absolute grid setting.
* Absolute grid is for aligning objects with the grid lines. * Absolute grid is for aligning objects with the grid lines.
* Relative grid is for maintaining an initial position relative to the grid lines. * Relative grid is for maintaining an initial position relative to the grid lines.
@ -143,22 +162,35 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
* - magnetic or normal grid should snap relative to an initial grid offset * - magnetic or normal grid should snap relative to an initial grid offset
* - no grid should snap relative to the grid. * - no grid should snap relative to the grid.
*/ */
static ModifierMask snap_delta_modifier () { return ModifierMask (snap_delta_mod); } static ModifierMask snap_delta_modifier ()
{
return ModifierMask (snap_delta_mod);
}
static guint edit_button() { return edit_but; } static guint edit_button ()
static void set_edit_button (guint); {
static guint edit_modifier() { return edit_mod; } return edit_but;
static void set_edit_modifier(guint); }
static guint edit_modifier ()
static guint delete_button() { return delete_but; } {
static void set_delete_button(guint); return edit_mod;
static guint delete_modifier() { return delete_mod; } }
static void set_delete_modifier(guint); static guint delete_button ()
{
static guint insert_note_button() { return insert_note_but; } return delete_but;
static void set_insert_note_button (guint); }
static guint insert_note_modifier() { return insert_note_mod; } static guint delete_modifier ()
static void set_insert_note_modifier(guint); {
return delete_mod;
}
static guint insert_note_button ()
{
return insert_note_but;
}
static guint insert_note_modifier ()
{
return insert_note_mod;
}
static bool is_edit_event (GdkEventButton*); static bool is_edit_event (GdkEventButton*);
static bool is_delete_event (GdkEventButton*); static bool is_delete_event (GdkEventButton*);
@ -168,74 +200,83 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
static bool is_momentary_push_event (GdkEventButton*); static bool is_momentary_push_event (GdkEventButton*);
static bool is_group_override_event (GdkEventButton*); static bool is_group_override_event (GdkEventButton*);
static Keyboard& the_keyboard() { return *_the_keyboard; } static Keyboard& the_keyboard ()
{
return *_the_keyboard;
}
static bool some_magic_widget_has_focus (); static bool some_magic_widget_has_focus ();
static void magic_widget_grab_focus (); static void magic_widget_grab_focus ();
static void magic_widget_drop_focus (); static void magic_widget_drop_focus ();
static Gtk::Window* get_current_window () { return current_window; }; static Gtk::Window* get_current_window ()
{
return current_window;
};
static bool close_current_dialog (); static bool close_current_dialog ();
static void keybindings_changed (); static void keybindings_changed ();
static void save_keybindings (); static void save_keybindings ();
static void set_can_save_keybindings (bool yn); static void set_can_save_keybindings (bool yn);
static std::string current_binding_name () { return _current_binding_name; } static std::string current_binding_name ()
static std::map<std::string,std::string> binding_files; {
return _current_binding_name;
}
static std::map<std::string, std::string> binding_files;
static bool catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w); static bool catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w);
static bool load_keybindings (std::string const& path); static bool load_keybindings (std::string const& path);
static void save_keybindings (std::string const& path); static void save_keybindings (std::string const& path);
static std::string binding_filename_suffix; static std::string binding_filename_suffix;
static const int close_window_key; static const int close_window_key;
static guint close_window_modifier; static guint close_window_modifier;
int reset_bindings (); int reset_bindings ();
sigc::signal0<void> ZoomVerticalModifierReleased; sigc::signal0<void> ZoomVerticalModifierReleased;
static sigc::signal0<void> RelevantModifierKeysChanged; static sigc::signal0<void> RelevantModifierKeysChanged;
static sigc::signal1<void,Gtk::Window*> HideMightMeanQuit; static sigc::signal1<void, Gtk::Window*> HideMightMeanQuit;
protected: protected:
static Keyboard* _the_keyboard; static Keyboard* _the_keyboard;
guint snooper_id; guint snooper_id;
State state; State state;
static guint edit_but; static guint edit_but;
static guint edit_mod; static guint edit_mod;
static guint delete_but; static guint delete_but;
static guint delete_mod; static guint delete_mod;
static guint insert_note_but; static guint insert_note_but;
static guint insert_note_mod; static guint insert_note_mod;
static guint snap_mod; static guint snap_mod;
static guint snap_delta_mod; static guint snap_delta_mod;
static guint button2_modifiers; static guint button2_modifiers;
static guint momentary_push_modifiers; static guint momentary_push_modifiers;
static guint group_override_modifiers; static guint group_override_modifiers;
static Gtk::Window* current_window; static Gtk::Window* current_window;
static std::string user_keybindings_path; static std::string user_keybindings_path;
static bool can_save_keybindings; static bool can_save_keybindings;
static bool bindings_changed_after_save_became_legal; static bool bindings_changed_after_save_became_legal;
static std::string _current_binding_name; static std::string _current_binding_name;
typedef std::pair<std::string,std::string> two_strings; typedef std::pair<std::string, std::string> two_strings;
static gint _snooper (GtkWidget*, GdkEventKey*, gpointer); static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
gint snooper (GtkWidget*, GdkEventKey*); gint snooper (GtkWidget*, GdkEventKey*);
static void set_modifier (uint32_t newval, uint32_t& variable); static void set_modifier (uint32_t newval, uint32_t& variable);
static bool _some_magic_widget_has_focus; static bool _some_magic_widget_has_focus;
static Gtk::Window* pre_dialog_active_window; static Gtk::Window* pre_dialog_active_window;
static int read_keybindings (std::string const& path); static int read_keybindings (std::string const& path);
static int store_keybindings (std::string const& path); static int store_keybindings (std::string const& path);
}; };
} /* namespace */ } // namespace Gtkmm2ext
#endif /* __libgtkmm2ext_keyboard_h__ */ #endif /* __libgtkmm2ext_keyboard_h__ */

View File

@ -29,23 +29,23 @@
#include "pbd/gstdio_compat.h" #include "pbd/gstdio_compat.h"
#include <gdk/gdkkeysyms.h>
#include <gtkmm/accelmap.h>
#include <gtkmm/widget.h> #include <gtkmm/widget.h>
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <gtkmm/accelmap.h>
#include <gdk/gdkkeysyms.h>
#include "pbd/error.h"
#include "pbd/convert.h" #include "pbd/convert.h"
#include "pbd/debug.h"
#include "pbd/error.h"
#include "pbd/file_utils.h" #include "pbd/file_utils.h"
#include "pbd/search_path.h" #include "pbd/search_path.h"
#include "pbd/xml++.h"
#include "pbd/debug.h"
#include "pbd/unwind.h" #include "pbd/unwind.h"
#include "pbd/xml++.h"
#include "gtkmm2ext/actions.h" #include "gtkmm2ext/actions.h"
#include "gtkmm2ext/bindings.h" #include "gtkmm2ext/bindings.h"
#include "gtkmm2ext/keyboard.h"
#include "gtkmm2ext/debug.h" #include "gtkmm2ext/debug.h"
#include "gtkmm2ext/keyboard.h"
#include "gtkmm2ext/utils.h" #include "gtkmm2ext/utils.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -55,98 +55,178 @@ using namespace Gtk;
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
using namespace std; using namespace std;
guint Keyboard::edit_but = 3; guint Keyboard::edit_but = 3;
guint Keyboard::edit_mod = GDK_CONTROL_MASK; guint Keyboard::edit_mod = GDK_CONTROL_MASK;
guint Keyboard::delete_but = 3; guint Keyboard::delete_but = 3;
guint Keyboard::delete_mod = GDK_SHIFT_MASK; guint Keyboard::delete_mod = GDK_SHIFT_MASK;
guint Keyboard::insert_note_but = 1; guint Keyboard::insert_note_but = 1;
guint Keyboard::insert_note_mod = GDK_CONTROL_MASK; guint Keyboard::insert_note_mod = GDK_CONTROL_MASK;
#ifdef __APPLE__ #ifdef __APPLE__
guint Keyboard::PrimaryModifier = GDK_MOD2_MASK; // Command guint Keyboard::PrimaryModifier = GDK_MOD2_MASK; // Command
guint Keyboard::SecondaryModifier = GDK_CONTROL_MASK; // Control guint Keyboard::SecondaryModifier = GDK_CONTROL_MASK; // Control
guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift
guint Keyboard::Level4Modifier = GDK_MOD1_MASK; // Alt/Option guint Keyboard::Level4Modifier = GDK_MOD1_MASK; // Alt/Option
guint Keyboard::CopyModifier = GDK_CONTROL_MASK; // Control guint Keyboard::CopyModifier = GDK_CONTROL_MASK; // Control
guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK; guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;
guint Keyboard::button2_modifiers = Keyboard::SecondaryModifier|Keyboard::Level4Modifier; guint Keyboard::button2_modifiers = Keyboard::SecondaryModifier | Keyboard::Level4Modifier;
guint Keyboard::momentary_push_modifiers = Keyboard::PrimaryModifier; guint Keyboard::momentary_push_modifiers = Keyboard::PrimaryModifier;
const char* Keyboard::primary_modifier_name() { return _("Command"); } const char*
const char* Keyboard::secondary_modifier_name() { return _("Control"); } Keyboard::primary_modifier_name ()
const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); } {
const char* Keyboard::level4_modifier_name() { return _("Option"); } return _("Command");
}
const char*
Keyboard::secondary_modifier_name ()
{
return _("Control");
}
const char*
Keyboard::tertiary_modifier_name ()
{
return S_("Key|Shift");
}
const char*
Keyboard::level4_modifier_name ()
{
return _("Option");
}
const char*
Keyboard::button2_name ()
{
return _("Middle Click (or Ctrl+Alt+Click)");
}
const char*
Keyboard::momentary_push_name ()
{
return _("Cmd+Click (or Middle-Click)");
}
const char*
Keyboard::primary_modifier_short_name ()
{
return _("Cmd");
}
const char*
Keyboard::secondary_modifier_short_name ()
{
return _("Ctrl");
}
const char*
Keyboard::tertiary_modifier_short_name ()
{
return S_("Key|Shift");
}
const char*
Keyboard::level4_modifier_short_name ()
{
return _("Opt");
}
const char* Keyboard::button2_name() { return _("Middle Click (or Ctrl+Alt+Click)"); } // TODO build dynamically depending on Keyboard::button2_modifiers guint Keyboard::snap_mod = Keyboard::Level4Modifier | Keyboard::TertiaryModifier; // XXX this is probably completely wrong
const char* Keyboard::momentary_push_name() { return _("Cmd+Click (or Middle-Click)"); } // TODO formay dynamically depending on Keyboard::momentary_push_modifiers -- Keyboard::tertiary_modifier_name
const char* Keyboard::primary_modifier_short_name() { return _("Cmd"); }
const char* Keyboard::secondary_modifier_short_name() { return _("Ctrl"); }
const char* Keyboard::tertiary_modifier_short_name() { return S_("Key|Shift"); }
const char* Keyboard::level4_modifier_short_name() { return _("Opt"); }
guint Keyboard::snap_mod = Keyboard::Level4Modifier|Keyboard::TertiaryModifier; // XXX this is probably completely wrong
guint Keyboard::snap_delta_mod = Keyboard::Level4Modifier; guint Keyboard::snap_delta_mod = Keyboard::Level4Modifier;
#else #else
guint Keyboard::PrimaryModifier = GDK_CONTROL_MASK; // Control guint Keyboard::PrimaryModifier = GDK_CONTROL_MASK; // Control
guint Keyboard::SecondaryModifier = GDK_MOD1_MASK; // Alt/Option guint Keyboard::SecondaryModifier = GDK_MOD1_MASK; // Alt/Option
guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift
guint Keyboard::Level4Modifier = GDK_MOD4_MASK|GDK_SUPER_MASK; // Mod4/Windows guint Keyboard::Level4Modifier = GDK_MOD4_MASK | GDK_SUPER_MASK; // Mod4/Windows
guint Keyboard::CopyModifier = GDK_CONTROL_MASK; guint Keyboard::CopyModifier = GDK_CONTROL_MASK;
guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK; guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;
guint Keyboard::button2_modifiers = 0; /* not used */ guint Keyboard::button2_modifiers = 0; /* not used */
guint Keyboard::momentary_push_modifiers = 0; /* not used */ guint Keyboard::momentary_push_modifiers = 0; /* not used */
const char* Keyboard::primary_modifier_name() { return _("Control"); } const char*
const char* Keyboard::secondary_modifier_name() { return _("Alt"); } Keyboard::primary_modifier_name ()
const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); } {
const char* Keyboard::level4_modifier_name() { return _("Windows"); } return _("Control");
}
const char*
Keyboard::secondary_modifier_name ()
{
return _("Alt");
}
const char*
Keyboard::tertiary_modifier_name ()
{
return S_("Key|Shift");
}
const char*
Keyboard::level4_modifier_name ()
{
return _("Windows");
}
const char*
Keyboard::button2_name ()
{
return _("Middle-Click");
}
const char*
Keyboard::momentary_push_name ()
{
return _("Middle-Click");
}
const char*
Keyboard::primary_modifier_short_name ()
{
return _("Ctrl");
}
const char*
Keyboard::secondary_modifier_short_name ()
{
return _("Alt");
}
const char*
Keyboard::tertiary_modifier_short_name ()
{
return S_("Key|Shift");
}
const char*
Keyboard::level4_modifier_short_name ()
{
return _("Win");
}
const char* Keyboard::button2_name() { return _("Middle-Click"); } guint Keyboard::snap_mod = Keyboard::SecondaryModifier;
const char* Keyboard::momentary_push_name() { return _("Middle-Click"); } guint Keyboard::snap_delta_mod = Keyboard::SecondaryModifier | Keyboard::Level4Modifier;
const char* Keyboard::primary_modifier_short_name() { return _("Ctrl"); }
const char* Keyboard::secondary_modifier_short_name() { return _("Alt"); }
const char* Keyboard::tertiary_modifier_short_name() { return S_("Key|Shift"); }
const char* Keyboard::level4_modifier_short_name() { return _("Win"); }
guint Keyboard::snap_mod = Keyboard::SecondaryModifier;
guint Keyboard::snap_delta_mod = Keyboard::SecondaryModifier|Keyboard::Level4Modifier;
#endif #endif
guint Keyboard::group_override_modifiers = Keyboard::TertiaryModifier; guint Keyboard::group_override_modifiers = Keyboard::TertiaryModifier;
const char* Keyboard::group_override_event_name() { return tertiary_modifier_name(); } const char*
Keyboard::group_override_event_name ()
{
return tertiary_modifier_name ();
}
guint Keyboard::GainFineScaleModifier = Keyboard::PrimaryModifier; guint Keyboard::GainFineScaleModifier = Keyboard::PrimaryModifier;
guint Keyboard::GainExtraFineScaleModifier = Keyboard::SecondaryModifier; guint Keyboard::GainExtraFineScaleModifier = Keyboard::SecondaryModifier;
guint Keyboard::ScrollZoomVerticalModifier = Keyboard::SecondaryModifier; guint Keyboard::ScrollZoomVerticalModifier = Keyboard::SecondaryModifier;
guint Keyboard::ScrollZoomHorizontalModifier = Keyboard::PrimaryModifier; guint Keyboard::ScrollZoomHorizontalModifier = Keyboard::PrimaryModifier;
guint Keyboard::ScrollHorizontalModifier = Keyboard::TertiaryModifier; guint Keyboard::ScrollHorizontalModifier = Keyboard::TertiaryModifier;
Keyboard* Keyboard::_the_keyboard = 0; Keyboard* Keyboard::_the_keyboard = 0;
Gtk::Window* Keyboard::current_window = 0; Gtk::Window* Keyboard::current_window = 0;
bool Keyboard::_some_magic_widget_has_focus = false; bool Keyboard::_some_magic_widget_has_focus = false;
const int Keyboard::close_window_key = GDK_w; const int Keyboard::close_window_key = GDK_w;
guint Keyboard::close_window_modifier = Keyboard::PrimaryModifier; guint Keyboard::close_window_modifier = Keyboard::PrimaryModifier;
std::string Keyboard::user_keybindings_path; std::string Keyboard::user_keybindings_path;
bool Keyboard::can_save_keybindings = false; bool Keyboard::can_save_keybindings = false;
bool Keyboard::bindings_changed_after_save_became_legal = false; bool Keyboard::bindings_changed_after_save_became_legal = false;
map<string,string> Keyboard::binding_files; map<string, string> Keyboard::binding_files;
string Keyboard::_current_binding_name; string Keyboard::_current_binding_name;
string Keyboard::binding_filename_suffix = X_(".keys"); string Keyboard::binding_filename_suffix = X_(".keys");
Gtk::Window* Keyboard::pre_dialog_active_window = 0; Gtk::Window* Keyboard::pre_dialog_active_window = 0;
/* set this to initially contain the modifiers we care about, then track changes in ::set_edit_modifier() etc. */ /* set this to initially contain the modifiers we care about, then track changes in ::set_edit_modifier() etc. */
GdkModifierType Keyboard::RelevantModifierKeyMask; GdkModifierType Keyboard::RelevantModifierKeyMask;
sigc::signal0<void> Keyboard::RelevantModifierKeysChanged; sigc::signal0<void> Keyboard::RelevantModifierKeysChanged;
sigc::signal1<void,Gtk::Window*> Keyboard::HideMightMeanQuit; sigc::signal1<void, Gtk::Window*> Keyboard::HideMightMeanQuit;
void void
Keyboard::magic_widget_grab_focus () Keyboard::magic_widget_grab_focus ()
@ -169,13 +249,13 @@ Keyboard::some_magic_widget_has_focus ()
Keyboard::Keyboard () Keyboard::Keyboard ()
{ {
if (_the_keyboard == 0) { if (_the_keyboard == 0) {
_the_keyboard = this; _the_keyboard = this;
_current_binding_name = _("Unknown"); _current_binding_name = _("Unknown");
} }
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
snooper_id = gtk_key_snooper_install (_snooper, (gpointer) this); snooper_id = gtk_key_snooper_install (_snooper, (gpointer)this);
} }
Keyboard::~Keyboard () Keyboard::~Keyboard ()
@ -218,26 +298,23 @@ Keyboard::set_state (const XMLNode& node, int /*version*/)
} }
gint gint
Keyboard::_snooper (GtkWidget *widget, GdkEventKey *event, gpointer data) Keyboard::_snooper (GtkWidget* widget, GdkEventKey* event, gpointer data)
{ {
return ((Keyboard *) data)->snooper (widget, event); return ((Keyboard*)data)->snooper (widget, event);
} }
gint gint
Keyboard::snooper (GtkWidget *widget, GdkEventKey *event) Keyboard::snooper (GtkWidget* widget, GdkEventKey* event)
{ {
uint32_t keyval; uint32_t keyval;
bool ret = false; bool ret = false;
DEBUG_TRACE ( DEBUG_TRACE (
DEBUG::Keyboard, DEBUG::Keyboard,
string_compose ( string_compose (
"Snoop widget %1 name: [%6] key %2 [%8] type %3 state %4 [%7] magic %5\n", "Snoop widget %1 name: [%6] key %2 [%8] type %3 state %4 [%7] magic %5\n",
widget, event->keyval, event->type, event->state, _some_magic_widget_has_focus, widget, event->keyval, event->type, event->state, _some_magic_widget_has_focus,
gtk_widget_get_name (widget), show_gdk_event_state (event->state), gdk_keyval_name (event->keyval) gtk_widget_get_name (widget), show_gdk_event_state (event->state), gdk_keyval_name (event->keyval)));
)
);
if (event->keyval == GDK_Shift_R) { if (event->keyval == GDK_Shift_R) {
keyval = GDK_Shift_L; keyval = GDK_Shift_L;
@ -261,13 +338,11 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
} }
if (event->type == GDK_KEY_PRESS) { if (event->type == GDK_KEY_PRESS) {
if (find (state.begin (), state.end (), keyval) == state.end ()) {
if (find (state.begin(), state.end(), keyval) == state.end()) {
state.push_back (keyval); state.push_back (keyval);
sort (state.begin(), state.end()); sort (state.begin (), state.end ());
} else { } else {
/* key is already down. if its also used for release, /* key is already down. if its also used for release,
prevent auto-repeat events. prevent auto-repeat events.
*/ */
@ -291,43 +366,41 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
} }
if (event->type == GDK_KEY_RELEASE) { if (event->type == GDK_KEY_RELEASE) {
State::iterator k = find (state.begin (), state.end (), keyval);
State::iterator k = find (state.begin(), state.end(), keyval); if (k != state.end ()) {
if (k != state.end()) {
/* this cannot change the ordering, so need to sort */ /* this cannot change the ordering, so need to sort */
state.erase (k); state.erase (k);
if (state.empty()) { if (state.empty ()) {
DEBUG_TRACE (DEBUG::Keyboard, "no keys down\n"); DEBUG_TRACE (DEBUG::Keyboard, "no keys down\n");
} else { } else {
#ifndef NDEBUG #ifndef NDEBUG
if (DEBUG_ENABLED(DEBUG::Keyboard)) { if (DEBUG_ENABLED (DEBUG::Keyboard)) {
DEBUG_STR_DECL(a); DEBUG_STR_DECL (a);
DEBUG_STR_APPEND(a, "keyboard, keys still down: "); DEBUG_STR_APPEND (a, "keyboard, keys still down: ");
for (State::iterator i = state.begin(); i != state.end(); ++i) { for (State::iterator i = state.begin (); i != state.end (); ++i) {
DEBUG_STR_APPEND(a, gdk_keyval_name (*i)); DEBUG_STR_APPEND (a, gdk_keyval_name (*i));
DEBUG_STR_APPEND(a, ','); DEBUG_STR_APPEND (a, ',');
} }
DEBUG_STR_APPEND(a, '\n'); DEBUG_STR_APPEND (a, '\n');
DEBUG_TRACE (DEBUG::Keyboard, DEBUG_STR(a).str()); DEBUG_TRACE (DEBUG::Keyboard, DEBUG_STR (a).str ());
} }
#endif /* NDEBUG */ #endif /* NDEBUG */
} }
} }
if (modifier_state_equals (event->state, PrimaryModifier)) { if (modifier_state_equals (event->state, PrimaryModifier)) {
/* Special keys that we want to handle in /* Special keys that we want to handle in
any dialog, no matter whether it uses any dialog, no matter whether it uses
the regular set of accelerators or not the regular set of accelerators or not
*/ */
switch (event->keyval) { switch (event->keyval) {
case close_window_key: case close_window_key:
if (close_current_dialog ()) { if (close_current_dialog ()) {
ret = true; ret = true;
} }
break; break;
} }
} }
} }
@ -340,7 +413,7 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
void void
Keyboard::reset_relevant_modifier_key_mask () Keyboard::reset_relevant_modifier_key_mask ()
{ {
RelevantModifierKeyMask = (GdkModifierType) gtk_accelerator_get_default_mod_mask (); RelevantModifierKeyMask = (GdkModifierType)gtk_accelerator_get_default_mod_mask ();
RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | PrimaryModifier); RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | PrimaryModifier);
RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | SecondaryModifier); RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | SecondaryModifier);
@ -351,25 +424,24 @@ Keyboard::reset_relevant_modifier_key_mask ()
gtk_accelerator_set_default_mod_mask (RelevantModifierKeyMask); gtk_accelerator_set_default_mod_mask (RelevantModifierKeyMask);
RelevantModifierKeysChanged(); /* EMIT SIGNAL */ RelevantModifierKeysChanged (); /* EMIT SIGNAL */
} }
bool bool
Keyboard::close_current_dialog () Keyboard::close_current_dialog ()
{ {
if (current_window) { if (current_window) {
HideMightMeanQuit (current_window); /* EMIT SIGNAL */ HideMightMeanQuit (current_window); /* EMIT SIGNAL */
current_window->hide (); current_window->hide ();
current_window = 0; current_window = 0;
if (pre_dialog_active_window) { if (pre_dialog_active_window) {
pre_dialog_active_window->present (); pre_dialog_active_window->present ();
pre_dialog_active_window = 0; pre_dialog_active_window = 0;
} }
return true; return true;
} }
return false; return false;
@ -378,58 +450,58 @@ Keyboard::close_current_dialog ()
bool bool
Keyboard::catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w) Keyboard::catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w)
{ {
switch (ev->type) { switch (ev->type) {
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
case GDK_BUTTON_RELEASE: case GDK_BUTTON_RELEASE:
case GDK_KEY_PRESS: case GDK_KEY_PRESS:
case GDK_KEY_RELEASE: case GDK_KEY_RELEASE:
pre_dialog_active_window = w; pre_dialog_active_window = w;
break; break;
case GDK_FOCUS_CHANGE: case GDK_FOCUS_CHANGE:
if (ev->focus_change.in) { if (ev->focus_change.in) {
pre_dialog_active_window = w; pre_dialog_active_window = w;
} }
break; break;
default: default:
break; break;
} }
return false; return false;
} }
bool bool
Keyboard::key_is_down (uint32_t keyval) Keyboard::key_is_down (uint32_t keyval)
{ {
return find (state.begin(), state.end(), keyval) != state.end(); return find (state.begin (), state.end (), keyval) != state.end ();
} }
bool bool
Keyboard::enter_window (GdkEventCrossing *, Gtk::Window* win) Keyboard::enter_window (GdkEventCrossing*, Gtk::Window* win)
{ {
current_window = win; current_window = win;
DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Entering window, title = %1\n", win->get_title())); DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Entering window, title = %1\n", win->get_title ()));
return false; return false;
} }
bool bool
Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* /*win*/) Keyboard::leave_window (GdkEventCrossing* ev, Gtk::Window* /*win*/)
{ {
if (ev) { if (ev) {
switch (ev->detail) { switch (ev->detail) {
case GDK_NOTIFY_INFERIOR: case GDK_NOTIFY_INFERIOR:
DEBUG_TRACE (DEBUG::Keyboard, "INFERIOR crossing ... out\n"); DEBUG_TRACE (DEBUG::Keyboard, "INFERIOR crossing ... out\n");
break; break;
case GDK_NOTIFY_VIRTUAL: case GDK_NOTIFY_VIRTUAL:
DEBUG_TRACE (DEBUG::Keyboard, "VIRTUAL crossing ... out\n"); DEBUG_TRACE (DEBUG::Keyboard, "VIRTUAL crossing ... out\n");
/* fallthrough */ /* fallthrough */
default: default:
DEBUG_TRACE (DEBUG::Keyboard, "REAL crossing ... out\n"); DEBUG_TRACE (DEBUG::Keyboard, "REAL crossing ... out\n");
DEBUG_TRACE (DEBUG::Keyboard, "Clearing current target\n"); DEBUG_TRACE (DEBUG::Keyboard, "Clearing current target\n");
state.clear (); state.clear ();
current_window = 0; current_window = 0;
} }
} else { } else {
DEBUG_TRACE (DEBUG::Keyboard, "LEAVE window without event\n"); DEBUG_TRACE (DEBUG::Keyboard, "LEAVE window without event\n");
@ -440,26 +512,26 @@ Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* /*win*/)
} }
bool bool
Keyboard::focus_in_window (GdkEventFocus *, Gtk::Window* win) Keyboard::focus_in_window (GdkEventFocus*, Gtk::Window* win)
{ {
current_window = win; current_window = win;
DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Focusing in window, title = %1\n", win->get_title())); DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Focusing in window, title = %1\n", win->get_title ()));
return false; return false;
} }
bool bool
Keyboard::focus_out_window (GdkEventFocus * ev, Gtk::Window* win) Keyboard::focus_out_window (GdkEventFocus* ev, Gtk::Window* win)
{ {
if (ev) { if (ev) {
state.clear (); state.clear ();
current_window = 0; current_window = 0;
} else { } else {
if (win == current_window) { if (win == current_window) {
current_window = 0; current_window = 0;
} }
} }
DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Foucusing out window, title = %1\n", win->get_title())); DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Foucusing out window, title = %1\n", win->get_title ()));
return false; return false;
} }
@ -474,7 +546,7 @@ void
Keyboard::set_edit_modifier (guint mod) Keyboard::set_edit_modifier (guint mod)
{ {
edit_mod = mod; edit_mod = mod;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
void void
@ -487,7 +559,7 @@ void
Keyboard::set_delete_modifier (guint mod) Keyboard::set_delete_modifier (guint mod)
{ {
delete_mod = mod; delete_mod = mod;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
void void
@ -500,61 +572,60 @@ void
Keyboard::set_insert_note_modifier (guint mod) Keyboard::set_insert_note_modifier (guint mod)
{ {
insert_note_mod = mod; insert_note_mod = mod;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
void void
Keyboard::set_modifier (uint32_t newval, uint32_t& var) Keyboard::set_modifier (uint32_t newval, uint32_t& var)
{ {
var = newval; var = newval;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
void void
Keyboard::set_snap_modifier (guint mod) Keyboard::set_snap_modifier (guint mod)
{ {
snap_mod = mod; snap_mod = mod;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
void void
Keyboard::set_snap_delta_modifier (guint mod) Keyboard::set_snap_delta_modifier (guint mod)
{ {
snap_delta_mod = mod; snap_delta_mod = mod;
reset_relevant_modifier_key_mask(); reset_relevant_modifier_key_mask ();
} }
bool bool
Keyboard::is_edit_event (GdkEventButton *ev) Keyboard::is_edit_event (GdkEventButton* ev)
{ {
return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) && return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
(ev->button == Keyboard::edit_button()) && (ev->button == Keyboard::edit_button ()) &&
((ev->state & RelevantModifierKeyMask) == Keyboard::edit_modifier()); ((ev->state & RelevantModifierKeyMask) == Keyboard::edit_modifier ());
} }
bool bool
Keyboard::is_insert_note_event (GdkEventButton *ev) Keyboard::is_insert_note_event (GdkEventButton* ev)
{ {
return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) && return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
(ev->button == Keyboard::insert_note_button()) && (ev->button == Keyboard::insert_note_button ()) &&
((ev->state & RelevantModifierKeyMask) == Keyboard::insert_note_modifier()); ((ev->state & RelevantModifierKeyMask) == Keyboard::insert_note_modifier ());
} }
bool bool
Keyboard::is_button2_event (GdkEventButton* ev) Keyboard::is_button2_event (GdkEventButton* ev)
{ {
return (ev->button == 2) || return (ev->button == 2) ||
((ev->button == 1) && Keyboard::button2_modifiers != 0 && ((ev->button == 1) && Keyboard::button2_modifiers != 0 &&
((ev->state & Keyboard::button2_modifiers) == Keyboard::button2_modifiers)); ((ev->state & Keyboard::button2_modifiers) == Keyboard::button2_modifiers));
} }
bool bool
Keyboard::is_momentary_push_event (GdkEventButton* ev) Keyboard::is_momentary_push_event (GdkEventButton* ev)
{ {
return (is_button2_event(ev)) || return (is_button2_event (ev)) ||
((ev->button == 1) && Keyboard::momentary_push_modifiers != 0 && ((ev->button == 1) && Keyboard::momentary_push_modifiers != 0 &&
((ev->state & RelevantModifierKeyMask) == Keyboard::momentary_push_modifiers)); ((ev->state & RelevantModifierKeyMask) == Keyboard::momentary_push_modifiers));
} }
bool bool
@ -564,19 +635,19 @@ Keyboard::is_group_override_event (GdkEventButton* ev)
} }
bool bool
Keyboard::is_delete_event (GdkEventButton *ev) Keyboard::is_delete_event (GdkEventButton* ev)
{ {
return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) && return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
(ev->button == Keyboard::delete_button()) && (ev->button == Keyboard::delete_button ()) &&
((ev->state & RelevantModifierKeyMask) == Keyboard::delete_modifier()); ((ev->state & RelevantModifierKeyMask) == Keyboard::delete_modifier ());
} }
bool bool
Keyboard::is_context_menu_event (GdkEventButton *ev) Keyboard::is_context_menu_event (GdkEventButton* ev)
{ {
return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) && return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
(ev->button == 3) && (ev->button == 3) &&
((ev->state & RelevantModifierKeyMask) == 0); ((ev->state & RelevantModifierKeyMask) == 0);
} }
bool bool
@ -588,13 +659,13 @@ Keyboard::no_modifiers_active (guint state)
bool bool
Keyboard::modifier_state_contains (guint state, ModifierMask mask) Keyboard::modifier_state_contains (guint state, ModifierMask mask)
{ {
return (state & mask) == (guint) mask; return (state & mask) == (guint)mask;
} }
bool bool
Keyboard::modifier_state_equals (guint state, ModifierMask mask) Keyboard::modifier_state_equals (guint state, ModifierMask mask)
{ {
return (state & RelevantModifierKeyMask) == (guint) mask; return (state & RelevantModifierKeyMask) == (guint)mask;
} }
void void
@ -623,7 +694,7 @@ Keyboard::save_keybindings ()
} }
bool bool
Keyboard::load_keybindings (string const & path) Keyboard::load_keybindings (string const& path)
{ {
try { try {
info << "Loading bindings from " << path << endl; info << "Loading bindings from " << path << endl;
@ -633,14 +704,13 @@ Keyboard::load_keybindings (string const & path)
_current_binding_name = _("Unknown"); _current_binding_name = _("Unknown");
for (map<string,string>::iterator x = binding_files.begin(); x != binding_files.end(); ++x) { for (map<string, string>::iterator x = binding_files.begin (); x != binding_files.end (); ++x) {
if (path == x->second) { if (path == x->second) {
_current_binding_name = x->first; _current_binding_name = x->first;
break; break;
} }
} }
} catch (...) { } catch (...) {
error << string_compose (_("key bindings file not found at \"%2\" or contains errors."), path) error << string_compose (_("key bindings file not found at \"%2\" or contains errors."), path)
<< endmsg; << endmsg;
@ -651,47 +721,47 @@ Keyboard::load_keybindings (string const & path)
} }
int int
Keyboard::read_keybindings (string const & path) Keyboard::read_keybindings (string const& path)
{ {
XMLTree tree; XMLTree tree;
if (!tree.read (path.c_str())) { if (!tree.read (path.c_str ())) {
return -1; return -1;
} }
/* toplevel node is "BindingSet; children are "Bindings" */ /* toplevel node is "BindingSet; children are "Bindings" */
XMLNodeList const& children = tree.root()->children(); XMLNodeList const& children = tree.root ()->children ();
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) { for (XMLNodeList::const_iterator i = children.begin (); i != children.end (); ++i) {
XMLNode const * child = *i; XMLNode const* child = *i;
if (child->name() == X_("Bindings")) { if (child->name () == X_("Bindings")) {
XMLProperty const* name = child->property (X_("name")); XMLProperty const* name = child->property (X_("name"));
if (!name) { if (!name) {
warning << _("Keyboard binding found without a name") << endmsg; warning << _("Keyboard binding found without a name") << endmsg;
continue; continue;
} }
Bindings* b = new Bindings (name->value()); Bindings* b = new Bindings (name->value ());
b->load (**i); b->load (**i);
} }
} }
return 0; return 0;
} }
int int
Keyboard::store_keybindings (string const & path) Keyboard::store_keybindings (string const& path)
{ {
XMLNode* node = new XMLNode (X_("BindingSet")); XMLNode* node = new XMLNode (X_("BindingSet"));
XMLNode* bnode; XMLNode* bnode;
int ret = 0; int ret = 0;
DEBUG_TRACE (DEBUG::Bindings, string_compose ("save bindings to %1\n", path)); DEBUG_TRACE (DEBUG::Bindings, string_compose ("save bindings to %1\n", path));
for (list<Bindings*>::const_iterator b = Bindings::bindings.begin(); b != Bindings::bindings.end(); ++b) { for (list<Bindings*>::const_iterator b = Bindings::bindings.begin (); b != Bindings::bindings.end (); ++b) {
bnode = new XMLNode (X_("Bindings")); bnode = new XMLNode (X_("Bindings"));
bnode->set_property (X_("name"), (*b)->name()); bnode->set_property (X_("name"), (*b)->name ());
(*b)->save (*bnode); (*b)->save (*bnode);
node->add_child_nocopy (*bnode); node->add_child_nocopy (*bnode);
} }
@ -710,12 +780,11 @@ Keyboard::store_keybindings (string const & path)
int int
Keyboard::reset_bindings () Keyboard::reset_bindings ()
{ {
if (Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) { if (Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) {
string new_path = user_keybindings_path; string new_path = user_keybindings_path;
new_path += ".old"; new_path += ".old";
if (::g_rename (user_keybindings_path.c_str(), new_path.c_str())) { if (::g_rename (user_keybindings_path.c_str (), new_path.c_str ())) {
error << string_compose (_("Cannot rename your own keybinding file (%1)"), strerror (errno)) << endmsg; error << string_compose (_("Cannot rename your own keybinding file (%1)"), strerror (errno)) << endmsg;
return -1; return -1;
} }