]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
3fbf3b8d773718b6598f95d334738998e8ac8d64
[chaz/openbox] / src / bindings.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __binding_hh
3 #define __binding_hh
4
5 /*! @file binding.hh
6 @brief I dunno.. some binding stuff?
7 */
8
9 #include "actions.hh"
10
11 #include <string>
12 #include <vector>
13
14 namespace ob {
15
16 class OBClient;
17
18 typedef struct Binding {
19 unsigned int modifiers;
20 unsigned int key;
21
22 bool operator==(struct Binding &b2) { return key == b2.key &&
23 modifiers == b2.modifiers; }
24 bool operator!=(struct Binding &b2) { return key != b2.key ||
25 modifiers != b2.modifiers; }
26 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
27 } Binding;
28
29 typedef struct BindingTree {
30 Binding binding;
31 std::string text;
32 int id; // the id given for the binding in add()
33 bool chain; // true if this is a chain to another key (not an action)
34
35 struct BindingTree *next_sibling; // the next binding in the tree at the same
36 // level
37 struct BindingTree *first_child; // the first child of this binding (next
38 // binding in a chained sequence).
39 BindingTree(int id) : binding(0, 0) {
40 this->id = id; chain = true; next_sibling = first_child = 0;
41 }
42 BindingTree() : binding(0, 0) {
43 this->id = -1; chain = true; next_sibling = first_child = 0;
44 }
45 } BindingTree;
46
47 class OBBindings {
48 public:
49 //! A list of strings
50 typedef std::vector<std::string> StringVect;
51
52 private:
53 BindingTree _keytree; // root node of the tree (this doesn't have siblings!)
54 BindingTree *_curpos; // position in the keytree
55
56 BindingTree *_mousetree; // this tree is a list. it has only siblings
57
58 int find_key(BindingTree *search) const;
59 bool translate(const std::string &str, Binding &b, bool askey) const;
60 BindingTree *buildtree(const StringVect &keylist, int id) const;
61 void assimilate(BindingTree *node);
62
63 void grabMouseOnAll(bool grab);
64 void grabKeys(bool grab);
65
66 public:
67 //! Initializes an OBBinding object
68 OBBindings();
69 //! Destroys the OBBinding object
70 virtual ~OBBindings();
71
72 //! Adds a new mouse binding
73 /*!
74 A binding will fail to be added if the binding already exists, or if the
75 string is invalid.
76 @return true if the binding could be added; false if it could not.
77 */
78 bool add_mouse(const std::string &button, int id);
79
80 //! Removes a mouse binding
81 /*!
82 @return The id of the binding that was removed, or '< 0' if none were
83 removed.
84 */
85 int remove_mouse(const std::string &button);
86
87 //! Adds a new key binding
88 /*!
89 A binding will fail to be added if the binding already exists (as part of
90 a chain or not), or if any of the strings in the keylist are invalid.
91 @return true if the binding could be added; false if it could not.
92 */
93 bool add_key(const StringVect &keylist, int id);
94
95 //! Removes a key binding
96 /*!
97 @return The id of the binding that was removed, or '< 0' if none were
98 removed.
99 */
100 int remove_key(const StringVect &keylist);
101
102 //! Removes all key bindings
103 void remove_all();
104
105 //! Finds a keybinding and returns its id or '< 0' if it isn't found.
106 /*!
107 @return -1 if the keybinding was not found but does not conflict with
108 any others; -2 if the keybinding conflicts with another.
109 */
110 int find_key(const StringVect &keylist);
111
112 void process(unsigned int modifiers, unsigned int key);
113
114 // XXX: need an exec() function or something that will be used by openbox
115 // and hold state for which chain we're in etc. (it could have a timer
116 // for reseting too...)
117
118 void display();
119
120 void fire(OBActions::ActionType type, Window window, unsigned int modifiers,
121 unsigned int key, Time time);
122
123 void grabMouse(bool grab, const OBClient *client);
124 };
125
126 }
127
128 #endif // __binding_hh
This page took 0.041415 seconds and 4 git commands to generate.