22 #include <glib/gstdio.h>
38 uint32_t Bindings::_ignored_state = 0;
40 MouseButton::MouseButton (uint32_t state, uint32_t keycode)
42 uint32_t ignore = Bindings::ignored_state();
44 if (gdk_keyval_is_upper (keycode) && gdk_keyval_is_lower (keycode)) {
47 ignore |= GDK_SHIFT_MASK;
50 _val = (state & ~ignore);
60 if (str.find (
"Primary") != string::npos) {
61 s |= Keyboard::PrimaryModifier;
64 if (str.find (
"Secondary") != string::npos) {
65 s |= Keyboard::SecondaryModifier;
68 if (str.find (
"Tertiary") != string::npos) {
69 s |= Keyboard::TertiaryModifier;
72 if (str.find (
"Level4") != string::npos) {
73 s |= Keyboard::Level4Modifier;
76 string::size_type lastmod = str.find_last_of (
'-');
77 uint32_t button_number;
79 if (lastmod == string::npos) {
82 button_number =
PBD::atoi (str.substr (lastmod+1));
96 if (s & Keyboard::PrimaryModifier) {
99 if (s & Keyboard::SecondaryModifier) {
105 if (s & Keyboard::TertiaryModifier) {
111 if (s & Keyboard::Level4Modifier) {
123 snprintf (buf,
sizeof (buf),
"%u", button());
129 KeyboardKey::KeyboardKey (uint32_t state, uint32_t keycode)
131 uint32_t ignore = Bindings::ignored_state();
133 if (gdk_keyval_is_upper (keycode) && gdk_keyval_is_lower (keycode)) {
136 ignore |= GDK_SHIFT_MASK;
139 _val = (state & ~ignore);
152 if (s & Keyboard::PrimaryModifier) {
155 if (s & Keyboard::SecondaryModifier) {
161 if (s & Keyboard::TertiaryModifier) {
167 if (s & Keyboard::Level4Modifier) {
178 str += gdk_keyval_name (key());
188 if (str.find (
"Primary") != string::npos) {
189 s |= Keyboard::PrimaryModifier;
192 if (str.find (
"Secondary") != string::npos) {
193 s |= Keyboard::SecondaryModifier;
196 if (str.find (
"Tertiary") != string::npos) {
197 s |= Keyboard::TertiaryModifier;
200 if (str.find (
"Level4") != string::npos) {
201 s |= Keyboard::Level4Modifier;
204 string::size_type lastmod = str.find_last_of (
'-');
207 if (lastmod == string::npos) {
208 keyval = gdk_keyval_from_name (str.c_str());
210 keyval = gdk_keyval_from_name (str.substr (lastmod+1).c_str());
213 if (keyval == GDK_VoidSymbol) {
252 KeybindingMap::iterator k = kbm->find (kb);
254 if (k == kbm->end()) {
261 k->second->activate ();
279 KeybindingMap::iterator k = kbm->find (kb);
281 if (k == kbm->end()) {
282 pair<KeyboardKey,RefPtr<Action> > newpair (kb, what);
283 kbm->insert (newpair);
304 KeybindingMap::iterator k = kbm->find (kb);
306 if (k != kbm->end()) {
325 MouseButtonBindingMap::iterator b = bbm->find (bb);
327 if (b == bbm->end()) {
334 b->second->activate ();
352 MouseButtonBindingMap::iterator b = bbm->find (bb);
354 if (b == bbm->end()) {
355 pair<MouseButton,RefPtr<Action> > newpair (bb, what);
356 bbm->insert (newpair);
377 MouseButtonBindingMap::iterator b = bbm->find (bb);
379 if (b != bbm->end()) {
393 if (!tree.
write (path)) {
394 ::g_unlink (path.c_str());
411 string ap = k->second->get_accel_path();
412 child->
add_property (
X_(
"action"), ap.substr (ap.find (
'/') + 1));
420 string ap = k->second->get_accel_path();
421 child->
add_property (
X_(
"action"), ap.substr (ap.find (
'/') + 1));
432 string ap = k->second->get_accel_path();
433 child->
add_property (
X_(
"action"), ap.substr (ap.find (
'/') + 1));
441 string ap = k->second->get_accel_path();
442 child->
add_property (
X_(
"action"), ap.substr (ap.find (
'/') + 1));
457 if (!tree.
read (path)) {
467 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
477 if (node.
name() ==
X_(
"Press") || node.
name() ==
X_(
"Release")) {
481 if (node.
name() ==
X_(
"Press")) {
489 for (XMLNodeList::const_iterator p = children.begin(); p != children.end(); ++p) {
495 ap = (*p)->property (
"action");
496 kp = (*p)->property (
"key");
497 bp = (*p)->property (
"button");
499 if (!ap || (!kp && !bp)) {
510 string::size_type slash = ap->
value().find (
'/');
511 if (slash != string::npos) {
512 string group = ap->
value().substr (0, slash);
513 string action = ap->
value().substr (slash+1);
542 _ActionMap::iterator a =
actions.find (name);
548 return RefPtr<Action>();
553 const char*
name,
const char* label, sigc::slot<void> sl)
557 RefPtr<Action> act = Action::create (name, label);
559 act->signal_activate().connect (sl);
565 actions.insert (_ActionMap::value_type (fullpath, act));
571 const char*
name,
const char* label,
572 sigc::slot<void,GtkAction*> sl,
577 RefPtr<Action> act = RadioAction::create (rgroup, name, label);
578 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
579 ract->property_value() = value;
581 act->signal_activate().connect (sigc::bind (sl, act->gobj()));
587 actions.insert (_ActionMap::value_type (fullpath, act));
593 const char*
name,
const char* label, sigc::slot<void> sl)
597 RefPtr<Action> act = ToggleAction::create (name, label);
599 act->signal_activate().connect (sl);
605 actions.insert (_ActionMap::value_type (fullpath, act));
int atoi(const string &s)
void remove(KeyboardKey, Operation)
const std::string & value() const
MouseButtonBindingMap button_press_bindings
const std::string & name() const
bool activate(KeyboardKey, Operation)
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > get_action(const char *group, const char *name)
const XMLNodeList & children(const std::string &str=std::string()) const
void add(KeyboardKey, Operation, Glib::RefPtr< Gtk::Action >)
Glib::RefPtr< Gtk::Action > register_radio_action(const char *path, Gtk::RadioAction::Group &, const char *name, const char *label, sigc::slot< void, GtkAction * > sl, int value)
bool save(const std::string &path)
std::list< XMLNode * > XMLNodeList
std::map< KeyboardKey, Glib::RefPtr< Gtk::Action > > KeybindingMap
XMLNode * set_root(XMLNode *n)
static bool make_key(const std::string &, KeyboardKey &)
Glib::RefPtr< Gtk::Action > find_action(const std::string &name)
LIBGTKMM2EXT_API uint64_t Bindings
void set_action_map(ActionMap &)
XMLProperty * add_property(const char *name, const std::string &value)
void add_child_nocopy(XMLNode &)
bool load(const std::string &path)
KeybindingMap release_bindings
std::map< MouseButton, Glib::RefPtr< Gtk::Action > > MouseButtonBindingMap
Glib::RefPtr< Gtk::Action > register_toggle_action(const char *path, const char *name, const char *label, sigc::slot< void > sl)
Glib::RefPtr< Gtk::Action > register_action(const char *path, const char *name, const char *label, sigc::slot< void > sl)
MouseButtonBindingMap button_release_bindings
KeybindingMap press_bindings