OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef __PLATFORM_WINDOW_MANAGER_KEY_BINDINGS_H__ | 5 #ifndef WINDOW_MANAGER_KEY_BINDINGS_H_ |
6 #define __PLATFORM_WINDOW_MANAGER_KEY_BINDINGS_H__ | 6 #define WINDOW_MANAGER_KEY_BINDINGS_H_ |
7 | 7 |
8 // KeyBindings | 8 // KeyBindings |
9 // | 9 // |
10 // The KeyBindings class supports installing named actions and keyboard combos | 10 // The KeyBindings class supports installing named actions and keyboard combos |
11 // that trigger an installed action. | 11 // that trigger an installed action. |
12 // | 12 // |
13 // A named action can have begin, repeat, and end callbacks associated with it | 13 // A named action can have begin, repeat, and end callbacks associated with it |
14 // which correspond to key down, key repeat, and key release respectively. | 14 // which correspond to key down, key repeat, and key release respectively. |
15 // Any of these callbacks may be NULL. Any number of KeyCombo's can be bound | 15 // Any of these callbacks may be NULL. Any number of KeyCombo's can be bound |
16 // to a given action. A KeyCombo is a keysym and modifier combination such as | 16 // to a given action. A KeyCombo is a keysym and modifier combination such as |
(...skipping 14 matching lines...) Expand all Loading... |
31 #include <X11/Xlib.h> | 31 #include <X11/Xlib.h> |
32 } | 32 } |
33 #include <map> | 33 #include <map> |
34 #include <string> | 34 #include <string> |
35 | 35 |
36 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
37 #include "chromeos/callback.h" | 37 #include "chromeos/callback.h" |
38 | 38 |
39 typedef ::Window XWindow; | 39 typedef ::Window XWindow; |
40 | 40 |
41 namespace chromeos { | 41 namespace window_manager { |
42 | 42 |
43 struct Action; | 43 struct Action; |
44 class XConnection; | 44 class XConnection; |
45 | 45 |
46 class KeyBindings { | 46 class KeyBindings { |
47 public: | 47 public: |
48 // Set of possible modifer mask bits. OR these together to create a KeyCombo | 48 // Set of possible modifer mask bits. OR these together to create a KeyCombo |
49 // modifiers value. | 49 // modifiers value. |
50 static const uint kShiftMask = ShiftMask; | 50 static const uint kShiftMask = ShiftMask; |
51 static const uint kLockMask = LockMask; | 51 static const uint kLockMask = LockMask; |
(...skipping 16 matching lines...) Expand all Loading... |
68 }; | 68 }; |
69 struct KeyComboComparator { | 69 struct KeyComboComparator { |
70 bool operator()(const KeyCombo& a, | 70 bool operator()(const KeyCombo& a, |
71 const KeyCombo& b) const; | 71 const KeyCombo& b) const; |
72 }; | 72 }; |
73 | 73 |
74 KeyBindings(XConnection* xconn); | 74 KeyBindings(XConnection* xconn); |
75 ~KeyBindings(); | 75 ~KeyBindings(); |
76 | 76 |
77 // Add a new action. This will fail if the action already exists. | 77 // Add a new action. This will fail if the action already exists. |
78 // NOTE: The KeyBindings class will take ownership of passed in callbacks. | 78 // NOTE: The KeyBindings class will take ownership of passed-in |
| 79 // callbacks, any of which may be NULL. |
79 bool AddAction(const std::string& action_name, | 80 bool AddAction(const std::string& action_name, |
80 Closure* begin_closure, // [optional] On combo press | 81 chromeos::Closure* begin_closure, // On combo press |
81 Closure* repeat_closure, // [optional] On combo auto-repeat | 82 chromeos::Closure* repeat_closure, // On combo auto-repeat |
82 Closure* end_closure); // [optional] On combo release | 83 chromeos::Closure* end_closure); // On combo release |
83 | 84 |
84 // Removes an action. Any key bindings to this action will also be removed. | 85 // Removes an action. Any key bindings to this action will also be removed. |
85 bool RemoveAction(const std::string& action_name); | 86 bool RemoveAction(const std::string& action_name); |
86 | 87 |
87 // Add a binding from the given KeyCombo to the action. KeyCombo's must be | 88 // Add a binding from the given KeyCombo to the action. KeyCombo's must be |
88 // unique, but it is fine to have more than one combo map to a given action. | 89 // unique, but it is fine to have more than one combo map to a given action. |
89 bool AddBinding(const KeyCombo& combo, | 90 bool AddBinding(const KeyCombo& combo, |
90 const std::string& action_name); | 91 const std::string& action_name); |
91 | 92 |
92 // Remove the KeyCombo. This may fail if the action to which the combo was | 93 // Remove the KeyCombo. This may fail if the action to which the combo was |
(...skipping 13 matching lines...) Expand all Loading... |
106 | 107 |
107 typedef std::map<std::string, Action*> ActionMap; | 108 typedef std::map<std::string, Action*> ActionMap; |
108 ActionMap actions_; | 109 ActionMap actions_; |
109 | 110 |
110 typedef std::map<KeyCombo, std::string, KeyComboComparator> BindingsMap; | 111 typedef std::map<KeyCombo, std::string, KeyComboComparator> BindingsMap; |
111 BindingsMap bindings_; | 112 BindingsMap bindings_; |
112 | 113 |
113 DISALLOW_COPY_AND_ASSIGN(KeyBindings); | 114 DISALLOW_COPY_AND_ASSIGN(KeyBindings); |
114 }; | 115 }; |
115 | 116 |
116 } // namespace chromeos | 117 } // namespace window_manager |
117 | 118 |
118 #endif // __PLATFORM_WINDOW_MANAGER_KEY_BINDINGS_H__ | 119 #endif |
OLD | NEW |