00001
00002 #ifndef __binding_hh
00003 #define __binding_hh
00004
00005
00006
00007
00008
00009 #include "actions.hh"
00010 #include "python.hh"
00011 #include "otk/timer.hh"
00012
00013 extern "C" {
00014 #include <Python.h>
00015 }
00016
00017 #include <string>
00018 #include <list>
00019 #include <vector>
00020
00021 namespace ob {
00022
00023 class Client;
00024
00025 typedef std::list<PyObject *> CallbackList;
00026
00027 typedef struct Binding {
00028 unsigned int modifiers;
00029 unsigned int key;
00030
00031 bool operator==(struct Binding &b2) { return key == b2.key &&
00032 modifiers == b2.modifiers; }
00033 bool operator!=(struct Binding &b2) { return key != b2.key ||
00034 modifiers != b2.modifiers; }
00035 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
00036 } Binding;
00037
00038 typedef struct KeyBindingTree {
00039 Binding binding;
00040 CallbackList callbacks;
00041 bool chain;
00042
00043 struct KeyBindingTree *next_sibling;
00044
00045 struct KeyBindingTree *first_child;
00046
00047 KeyBindingTree() : binding(0, 0) {
00048 chain = true; next_sibling = first_child = 0;
00049 }
00050 } KeyBindingTree;
00051
00052 typedef struct ButtonBinding {
00053 Binding binding;
00054 CallbackList callbacks[MouseAction::NUM_MOUSE_ACTION];
00055 ButtonBinding() : binding(0, 0) {}
00056 };
00057
00058 class Bindings {
00059 public:
00060
00061 typedef std::vector<std::string> StringVect;
00062
00063 private:
00064
00065 KeyBindingTree _keytree;
00066 KeyBindingTree *_curpos;
00067
00068 Binding _resetkey;
00069
00070 otk::Timer *_timer;
00071
00072 KeyBindingTree *find(KeyBindingTree *search, bool *conflict) const;
00073 KeyBindingTree *buildtree(const StringVect &keylist,
00074 PyObject *callback) const;
00075 void assimilate(KeyBindingTree *node);
00076
00077 static void resetChains(Bindings *self);
00078
00079 typedef std::list <ButtonBinding*> ButtonBindingList;
00080 ButtonBindingList _buttons[MouseContext::NUM_MOUSE_CONTEXT];
00081
00082 void grabButton(bool grab, const Binding &b, MouseContext::MC context,
00083 Client *client);
00084
00085 CallbackList _eventlist[EventAction::NUM_EVENTS];
00086
00087 PyObject *_keybgrab_callback;
00088
00089 public:
00090
00091 Bindings();
00092
00093 virtual ~Bindings();
00094
00095
00096 bool translate(const std::string &str, Binding &b, bool askey = true) const;
00097
00098
00099
00100
00101
00102
00103
00104 bool addKey(const StringVect &keylist, PyObject *callback);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void removeAllKeys();
00115
00116 void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time,
00117 KeyAction::KA action);
00118
00119 void setResetKey(const std::string &key);
00120
00121 void grabKeys(bool grab);
00122
00123 bool grabKeyboard(int screen, PyObject *callback);
00124 void ungrabKeyboard();
00125
00126 bool grabPointer(int screen);
00127 void ungrabPointer();
00128
00129 bool addButton(const std::string &but, MouseContext::MC context,
00130 MouseAction::MA action, PyObject *callback);
00131
00132 void grabButtons(bool grab, Client *client);
00133
00134
00135 void removeAllButtons();
00136
00137 void fireButton(MouseData *data);
00138
00139
00140 bool addEvent(EventAction::EA action, PyObject *callback);
00141
00142
00143 bool removeEvent(EventAction::EA action, PyObject *callback);
00144
00145
00146 void removeAllEvents();
00147
00148 void fireEvent(EventData *data);
00149 };
00150
00151 }
00152
00153 #endif // __binding_hh