+uint32_t Bindings::_ignored_state = 0;
+
+MouseButton::MouseButton (uint32_t state, uint32_t keycode)
+{
+ uint32_t ignore = Bindings::ignored_state();
+
+ if (gdk_keyval_is_upper (keycode) && gdk_keyval_is_lower (keycode)) {
+ /* key is not subject to case, so ignore SHIFT
+ */
+ ignore |= GDK_SHIFT_MASK;
+ }
+
+ _val = (state & ~ignore);
+ _val <<= 32;
+ _val |= keycode;
+};
+
+bool
+MouseButton::make_button (const string& str, MouseButton& b)
+{
+ int s = 0;
+
+ if (str.find ("Primary") != string::npos) {
+ s |= Keyboard::PrimaryModifier;
+ }
+
+ if (str.find ("Secondary") != string::npos) {
+ s |= Keyboard::SecondaryModifier;
+ }
+
+ if (str.find ("Tertiary") != string::npos) {
+ s |= Keyboard::TertiaryModifier;
+ }
+
+ if (str.find ("Level4") != string::npos) {
+ s |= Keyboard::Level4Modifier;
+ }
+
+ string::size_type lastmod = str.find_last_of ('-');
+ uint32_t button_number;
+
+ if (lastmod == string::npos) {
+ button_number = PBD::atoi (str);
+ } else {
+ button_number = PBD::atoi (str.substr (lastmod+1));
+ }
+
+ b = MouseButton (s, button_number);
+ return true;
+}
+
+string
+MouseButton::name () const
+{
+ int s = state();
+
+ string str;
+
+ if (s & Keyboard::PrimaryModifier) {
+ str += "Primary";
+ }
+ if (s & Keyboard::SecondaryModifier) {
+ if (!str.empty()) {
+ str += '-';
+ }
+ str += "Secondary";
+ }
+ if (s & Keyboard::TertiaryModifier) {
+ if (!str.empty()) {
+ str += '-';
+ }
+ str += "Tertiary";
+ }
+ if (s & Keyboard::Level4Modifier) {
+ if (!str.empty()) {
+ str += '-';
+ }
+ str += "Level4";
+ }
+
+ if (!str.empty()) {
+ str += '-';
+ }
+
+ char buf[16];
+ snprintf (buf, sizeof (buf), "%u", button());
+ str += buf;
+
+ return str;
+}