]> icculus.org git repositories - dana/openbox.git/blob - src/bindings.hh
load config options from the python environment
[dana/openbox.git] / 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 #include "otk/timer.hh"
11
12 #include <string>
13 #include <vector>
14
15 namespace ob {
16
17 class OBClient;
18
19 typedef struct Binding {
20   unsigned int modifiers;
21   unsigned int key;
22
23   bool operator==(struct Binding &b2) { return key == b2.key &&
24                                           modifiers == b2.modifiers; }
25   bool operator!=(struct Binding &b2) { return key != b2.key ||
26                                           modifiers != b2.modifiers; }
27   Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
28 } Binding;
29
30 typedef struct BindingTree {
31   Binding binding;
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 _tree; // root node of the tree (this doesn't have siblings!)
54   BindingTree *_curpos; // position in the keytree
55
56   Binding _resetkey; // the key which resets the key chain status
57
58   otk::OBTimer _timer;
59   
60   int find(BindingTree *search) const;
61   bool translate(const std::string &str, Binding &b) const;
62   BindingTree *buildtree(const StringVect &keylist, int id) const;
63   void assimilate(BindingTree *node);
64
65   static void reset(OBBindings *self);
66
67 public:
68   //! Initializes an OBBinding object
69   OBBindings();
70   //! Destroys the OBBinding object
71   virtual ~OBBindings();
72
73   //! Adds a new key binding
74   /*!
75     A binding will fail to be added if the binding already exists (as part of
76     a chain or not), or if any of the strings in the keylist are invalid.    
77     @return true if the binding could be added; false if it could not.
78   */
79   bool add(const StringVect &keylist, int id);
80
81   //! Removes a key binding
82   /*!
83     @return The id of the binding that was removed, or '< 0' if none were
84             removed.
85   */
86   int remove(const StringVect &keylist);
87
88   //! Removes all key bindings
89   void remove_all();
90
91   //! Finds a keybinding and returns its id or '< 0' if it isn't found.
92   /*!
93     @return -1 if the keybinding was not found but does not conflict with
94     any others; -2 if the keybinding conflicts with another.
95   */
96   int find(const StringVect &keylist);
97
98   void fire(Window window, unsigned int modifiers,unsigned int key, Time time);
99
100   void setResetKey(const std::string &key);
101
102   void grabKeys(bool grab);
103 };
104
105 }
106
107 #endif // __binding_hh