Ardour  9.0-pre0-582-g084a23a80d
libs/gtkmm2ext/gtkmm2ext/keyboard.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
5  * Copyright (C) 2015-2016 Nick Mainsbridge <mainsbridge@gmail.com>
6  * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __libgtkmm2ext_keyboard_h__
24 #define __libgtkmm2ext_keyboard_h__
25 
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 #include <gtk/gtk.h>
31 #include <gtkmm/accelkey.h>
32 
33 #include "pbd/signals.h"
34 #include "pbd/stateful.h"
35 
36 #include "gtkmm2ext/visibility.h"
37 
38 namespace Gtk
39 {
40  class Window;
41 }
42 
43 namespace Gtkmm2ext
44 {
45 class Bindings;
46 class ActionMap;
47 
48 class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
49 {
50 public:
53 
54  XMLNode& get_state () const;
55  int set_state (const XMLNode&, int version);
56 
57  virtual void setup_keybindings () = 0;
59 
60  typedef std::vector<uint32_t> State;
61  typedef uint32_t ModifierMask;
62 
63  static const uint32_t PrimaryModifier;
64  static const uint32_t SecondaryModifier;
65  static const uint32_t TertiaryModifier;
66  static const uint32_t Level4Modifier;
67 
68  static uint32_t CopyModifier;
69  static uint32_t RangeSelectModifier;
70  static uint32_t GainFineScaleModifier;
71  static uint32_t GainExtraFineScaleModifier;
72 
73  // Modifiers for scroll wheel
74  static uint32_t ScrollZoomVerticalModifier;
76  static uint32_t ScrollHorizontalModifier;
77 
78  static const char* primary_modifier_name ();
79  static const char* secondary_modifier_name ();
80  static const char* tertiary_modifier_name ();
81  static const char* level4_modifier_name ();
82 
83  static const char* primary_modifier_short_name ();
84  static const char* secondary_modifier_short_name ();
85  static const char* tertiary_modifier_short_name ();
86  static const char* level4_modifier_short_name ();
87 
88  static const char* button2_name ();
89  static const char* momentary_push_name ();
90  static const char* group_override_event_name ();
91 
92  static std::string format_modifier (uint32_t);
93 
94  bool key_is_down (uint32_t keyval);
95  guint modifier_state ();
96 
98 
100  {
101  return (ev->state & RelevantModifierKeyMask) == 0;
102  }
103 
105  {
106  return (ev->state & RelevantModifierKeyMask) == 0;
107  }
108 
113 
114  static bool modifier_state_contains (guint state, ModifierMask);
115  static bool modifier_state_equals (guint state, ModifierMask);
116 
117  static bool no_modifiers_active (guint state);
118 
119  static void set_copy_modifier (uint32_t newval)
120  {
121  set_modifier (newval, CopyModifier);
122  }
123  static void set_range_select_modifier (uint32_t newval)
124  {
125  set_modifier (newval, RangeSelectModifier);
126  }
127 
128  static void set_snap_modifier (guint);
129  static void set_snap_delta_modifier (guint);
130  static void set_edit_button (guint);
131  static void set_edit_modifier (guint);
132  static void set_delete_button (guint);
133  static void set_delete_modifier (guint);
134  static void set_insert_note_button (guint);
135  static void set_insert_note_modifier (guint);
136 
142  {
143  return ModifierMask (snap_mod);
144  }
145 
154  {
155  return ModifierMask (snap_delta_mod);
156  }
157 
158  static guint edit_button ()
159  {
160  return edit_but;
161  }
162  static guint edit_modifier ()
163  {
164  return edit_mod;
165  }
166  static guint delete_button ()
167  {
168  return delete_but;
169  }
170  static guint delete_modifier ()
171  {
172  return delete_mod;
173  }
174  static guint insert_note_button ()
175  {
176  return insert_note_but;
177  }
178  static guint insert_note_modifier ()
179  {
180  return insert_note_mod;
181  }
182  static guint button2_modifier ()
183  {
184  return button2_modifiers;
185  }
186  static guint momentary_push_modifier ()
187  {
188  return momentary_push_modifiers;
189  }
190  static guint group_override_modifier ()
191  {
192  return group_override_modifiers;
193  }
194 
202 
204  {
205  return *_the_keyboard;
206  }
207 
209  static void magic_widget_grab_focus ();
210  static void magic_widget_drop_focus ();
212  {
213  return current_window;
214  };
215 
216  static bool close_current_dialog ();
217 
218  static void keybindings_changed ();
219  static void save_keybindings ();
220  static void set_can_save_keybindings (bool yn);
221  static std::string current_binding_name ()
222  {
223  return _current_binding_name;
224  }
225  static std::map<std::string, std::string> binding_files;
226 
228 
229  static bool load_keybindings (std::string const& path);
230  static void save_keybindings (std::string const& path);
231 
232  static std::string binding_filename_suffix;
233  static const int close_window_key;
234  static guint close_window_modifier;
235 
237 
238  sigc::signal0<void> ZoomVerticalModifierReleased;
239  static sigc::signal0<void> RelevantModifierKeysChanged;
240  static sigc::signal1<void, Gtk::Window*> HideMightMeanQuit;
241 
242 protected:
244 
245  guint snooper_id;
247 
248  static guint edit_but;
249  static guint edit_mod;
250  static guint delete_but;
251  static guint delete_mod;
252  static guint insert_note_but;
253  static guint insert_note_mod;
254  static guint snap_mod;
255  static guint snap_delta_mod;
256  static guint button2_modifiers;
260  static std::string user_keybindings_path;
261  static bool can_save_keybindings;
263  static std::string _current_binding_name;
264 
265  typedef std::pair<std::string, std::string> two_strings;
266 
267  static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
269 
270  static void set_modifier (uint32_t newval, uint32_t& variable);
271 
273 
275 
276  static int read_keybindings (std::string const& path);
277  static int store_keybindings (std::string const& path);
278 };
279 
280 } // namespace Gtkmm2ext
281 
282 #endif /* __libgtkmm2ext_keyboard_h__ */
int set_state(const XMLNode &, int version)
static void set_insert_note_modifier(guint)
XMLNode & get_state() const
static bool no_modifier_keys_pressed(GdkEventButton *ev)
static void reset_relevant_modifier_key_mask()
static void magic_widget_grab_focus()
static int store_keybindings(std::string const &path)
bool focus_out_window(GdkEventFocus *ev, Gtk::Window *)
static bool close_current_dialog()
static void set_edit_modifier(guint)
static sigc::signal1< void, Gtk::Window * > HideMightMeanQuit
static const uint32_t TertiaryModifier
bool leave_window(GdkEventCrossing *ev, Gtk::Window *)
static void keybindings_changed()
static void set_snap_delta_modifier(guint)
static std::map< std::string, std::string > binding_files
static std::string format_modifier(uint32_t)
static bool is_insert_note_event(GdkEventButton *)
static void set_delete_modifier(guint)
static const char * level4_modifier_short_name()
static Gtk::Window * get_current_window()
static void set_range_select_modifier(uint32_t newval)
static const char * group_override_event_name()
static bool no_modifier_keys_pressed(GdkEventKey *ev)
bool enter_window(GdkEventCrossing *ev, Gtk::Window *)
static const char * tertiary_modifier_name()
static gint _snooper(GtkWidget *, GdkEventKey *, gpointer)
static bool catch_user_event_for_pre_dialog_focus(GdkEvent *ev, Gtk::Window *w)
static void set_edit_button(guint)
static void set_insert_note_button(guint)
static bool is_group_override_event(GdkEventButton *)
bool key_is_down(uint32_t keyval)
static sigc::signal0< void > RelevantModifierKeysChanged
static bool some_magic_widget_has_focus()
static const char * momentary_push_name()
static bool no_modifiers_active(guint state)
static ModifierMask snap_delta_modifier()
static bool is_edit_event(GdkEventButton *)
static void set_modifier(uint32_t newval, uint32_t &variable)
static void set_snap_modifier(guint)
std::pair< std::string, std::string > two_strings
static void save_keybindings(std::string const &path)
static const char * tertiary_modifier_short_name()
static void set_copy_modifier(uint32_t newval)
static const char * secondary_modifier_short_name()
static void save_keybindings()
bool focus_in_window(GdkEventFocus *ev, Gtk::Window *)
static bool modifier_state_equals(guint state, ModifierMask)
sigc::signal0< void > ZoomVerticalModifierReleased
static void set_can_save_keybindings(bool yn)
static const char * primary_modifier_short_name()
static int read_keybindings(std::string const &path)
static void set_delete_button(guint)
static const char * button2_name()
virtual void setup_keybindings()=0
static GdkModifierType RelevantModifierKeyMask
static bool modifier_state_contains(guint state, ModifierMask)
static bool is_context_menu_event(GdkEventButton *)
static Gtk::Window * pre_dialog_active_window
static const char * level4_modifier_name()
static void magic_widget_drop_focus()
static bool is_momentary_push_event(GdkEventButton *)
static const char * secondary_modifier_name()
static bool load_keybindings(std::string const &path)
static const uint32_t SecondaryModifier
static bool is_button2_event(GdkEventButton *)
gint snooper(GtkWidget *, GdkEventKey *)
static bool is_delete_event(GdkEventButton *)
static const char * primary_modifier_name()
Definition: Window.h:41
Definition: xml++.h:114
GdkModifierType
Definition: gdktypes.h:127
#define LIBGTKMM2EXT_API
Definition: ardour_ui.h:188
DebugBits Bindings
guint state
Definition: gdkevents.h:373