]> icculus.org git repositories - mikachu/openbox.git/blob - src/bindings.hh
add click_raise global var
[mikachu/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
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   int id;     // the id given for the binding in add()
32   bool chain; // true if this is a chain to another key (not an action)
33
34   struct BindingTree *next_sibling; // the next binding in the tree at the same
35                                     // level
36   struct BindingTree *first_child;  // the first child of this binding (next
37                                     // binding in a chained sequence).
38   BindingTree(int id) : binding(0, 0) {
39     this->id = id; chain = true; next_sibling = first_child = 0;
40   }
41   BindingTree() : binding(0, 0) {
42     this->id = -1; chain = true; next_sibling = first_child = 0;
43   }
44 } BindingTree;
45
46 class OBBindings {
47 public:
48   //! A list of strings
49   typedef std::vector<std::string> StringVect;
50
51 private:
52   BindingTree _tree; // root node of the tree (this doesn't have siblings!)
53   BindingTree *_curpos; // position in the keytree
54
55   Binding _resetkey; // the key which resets the key chain status
56   
57   int find(BindingTree *search) const;
58   bool translate(const std::string &str, Binding &b) const;
59   BindingTree *buildtree(const StringVect &keylist, int id) const;
60   void assimilate(BindingTree *node);
61
62 public:
63   //! Initializes an OBBinding object
64   OBBindings();
65   //! Destroys the OBBinding object
66   virtual ~OBBindings();
67
68   //! Adds a new key binding
69   /*!
70     A binding will fail to be added if the binding already exists (as part of
71     a chain or not), or if any of the strings in the keylist are invalid.    
72     @return true if the binding could be added; false if it could not.
73   */
74   bool add(const StringVect &keylist, int id);
75
76   //! Removes a key binding
77   /*!
78     @return The id of the binding that was removed, or '< 0' if none were
79             removed.
80   */
81   int remove(const StringVect &keylist);
82
83   //! Removes all key bindings
84   void remove_all();
85
86   //! Finds a keybinding and returns its id or '< 0' if it isn't found.
87   /*!
88     @return -1 if the keybinding was not found but does not conflict with
89     any others; -2 if the keybinding conflicts with another.
90   */
91   int find(const StringVect &keylist);
92
93   void fire(Window window, unsigned int modifiers,unsigned int key, Time time);
94
95   void setResetKey(const std::string &key);
96
97   void grabKeys(bool grab);
98 };
99
100 }
101
102 #endif // __binding_hh