]> icculus.org git repositories - mikachu/openbox.git/blob - src/actions.hh
new code for bindings/callbacks. much sexier. now passes python classes back to the...
[mikachu/openbox.git] / src / actions.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __actions_hh
3 #define __actions_hh
4
5 /*! @file actions.hh
6   @brief The action interface for user-available actions
7 */
8
9 #include "widget.hh"
10 #include "otk/point.hh"
11 #include "otk/rect.hh"
12 #include "otk/eventhandler.hh"
13
14 extern "C" {
15 #include <X11/Xlib.h>
16 #include <Python.h>
17 }
18
19 #include <map>
20
21 namespace ob {
22
23 //! The action interface for user-available actions
24 /*!
25   When these actions are fired, hooks to the guile engine are fired so that
26   guile code is run.
27 */
28 class OBActions : public otk::OtkEventHandler {
29 public:
30   // update the same enum in openbox.i when making changes to this
31   enum ActionType {
32     Action_ButtonPress,
33     Action_ButtonRelease,
34     Action_Click,
35     Action_DoubleClick,
36     Action_EnterWindow,
37     Action_LeaveWindow,
38     Action_KeyPress,
39     Action_MouseMotion,
40     Action_NewWindow,
41     Action_CloseWindow,
42     NUM_ACTIONS
43   };
44   
45   struct ButtonReleaseAction {
46     Window win;
47     unsigned int button;
48     Time time;
49     ButtonReleaseAction() { win = 0; button = 0; time = 0; }
50   };
51
52 private:
53   // milliseconds XXX: config option
54   static const unsigned int DOUBLECLICKDELAY;
55   
56   //! The mouse button currently being watched from a press for a CLICK
57   unsigned int _button;
58   //! The last button release processed for CLICKs
59   ButtonReleaseAction _release;
60
61   typedef std::multimap<ActionType, PyObject*> CallbackMap;
62   typedef std::pair<ActionType, PyObject*> CallbackMapPair;
63   CallbackMap _callbacks;
64
65   void doCallback(ActionType action, Window window, OBWidget::WidgetType type,
66                   unsigned int state, unsigned int button,
67                   int xroot, int yroot, Time time);
68   
69 public:
70   //! Constructs an OBActions object
71   OBActions();
72   //! Destroys the OBActions object
73   virtual ~OBActions();
74
75   virtual void buttonPressHandler(const XButtonEvent &e);
76   virtual void buttonReleaseHandler(const XButtonEvent &e);
77   
78   virtual void enterHandler(const XCrossingEvent &e);
79   virtual void leaveHandler(const XCrossingEvent &e);
80
81   virtual void keyPressHandler(const XKeyEvent &e);
82
83   virtual void motionHandler(const XMotionEvent &e);
84
85   virtual void mapRequestHandler(const XMapRequestEvent &e);
86   virtual void unmapHandler(const XUnmapEvent &e);
87   virtual void destroyHandler(const XDestroyWindowEvent &e);
88
89
90   //! Add a callback funtion to the back of the hook list
91   /*!
92     Registering functions for KeyPress events is pointless. Use
93     OBSCript::bindKey instead to do this.
94   */
95   bool registerCallback(ActionType action, PyObject *func, bool atfront);
96
97   //! Remove a callback function from the hook list
98   bool unregisterCallback(ActionType action, PyObject *func);
99
100   //! Remove all callback functions from the hook list
101   bool unregisterAllCallbacks(ActionType action);
102 };
103
104 }
105
106 #endif // __actions_hh