]> icculus.org git repositories - dana/openbox.git/blob - src/python.hh
handle modal windows better (bugfixes).
[dana/openbox.git] / src / python.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __python_hh
3 #define   __python_hh
4
5 /*! @file python.hh
6   @brief wee
7 */
8
9 #include "otk/point.hh"
10 #include "otk/rect.hh"
11 #include "otk/property.hh"
12 #include "otk/display.hh"
13 #include "otk/ustring.hh"
14
15 extern "C" {
16 #include <X11/Xlib.h>
17 #include <Python.h>
18 }
19
20 #include <string>
21 #include <vector>
22
23 namespace ob {
24
25 class Client;
26
27 struct MouseContext {
28   enum MC {
29     Frame,
30     Titlebar,
31     Handle,
32     Window,
33     MaximizeButton,
34     CloseButton,
35     IconifyButton,
36     AllDesktopsButton,
37     Grip,
38     Root,
39     MenuItem
40 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
41     , NUM_MOUSE_CONTEXT
42 #endif
43   };
44 };
45
46 struct MouseAction {
47   enum MA {
48     Press,
49     Release,
50     Click,
51     DoubleClick,
52     Motion
53 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
54     , NUM_MOUSE_ACTION
55 #endif
56   };
57 };
58
59 struct KeyContext {
60   enum KC {
61     Menu,
62     All
63 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
64     , NUM_KEY_CONTEXT
65 #endif
66   };
67 };
68
69 struct KeyAction {
70   enum KA {
71     Press,
72     Release
73 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
74     , NUM_KEY_ACTION
75 #endif
76   };
77 };
78
79 struct EventAction {
80   enum EA {
81     EnterWindow,        //!< Occurs when the mouse enters a window
82     LeaveWindow,        //!< Occurs when the mouse leaves a window
83     //! Occurs while a window is being managed. The handler should call
84     //! Client::move on the window
85     PlaceWindow,
86     //! Occurs while a window is being managed, just before the window is
87     //! displayed
88     /*!
89       Note that the window's state may not be completely stabilized by this
90       point. The NewWindow event should be used when possible.
91     */
92     DisplayingWindow,
93     //! Occurs when a window is finished being managed
94     NewWindow,
95     //! Occurs when a window has been closed and is going to be unmanaged
96     CloseWindow,
97     //! Occurs when the window manager manages a screen
98     /*!
99       This event occurs on each managed screen during startup.
100     */
101     Startup,
102     //! Occurs when the window manager unmanages a screen
103     /*!
104       This event occurs on each managed screen during shutdown.
105     */
106     Shutdown,
107     //! Occurs when the input focus target changes
108     /*!
109       The data.client will be None of no client is focused.
110     */
111     Focus,
112     //! Occurs when the system is fired through X.
113     /*!
114       The data.client will hold the client associated with the bell if
115       one has been specified, or None.
116     */
117     Bell,
118     //! Occurs when a client toggles its urgent status.
119     /*!
120       The Client::urgent method can be used to get the status.
121     */
122     UrgentWindow
123 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
124     , NUM_EVENTS
125 #endif
126   };
127 };
128
129 class MouseData {
130 public:
131   int screen;
132   Client *client;
133   Time time;
134   unsigned int state;
135   unsigned int button;
136   MouseContext::MC context;
137   MouseAction::MA action;
138   int xroot;
139   int yroot;
140   int pressx;
141   int pressy;
142   int press_clientx;
143   int press_clienty;
144   int press_clientwidth;
145   int press_clientheight;
146
147   MouseData(int screen, Client *client, Time time, unsigned int state,
148             unsigned int button, MouseContext::MC context,
149             MouseAction::MA action, int xroot, int yroot,
150             const otk::Point &initpos, const otk::Rect &initarea) {
151     this->screen = screen;
152     this->client = client;
153     this->time   = time;
154     this->state  = state;
155     this->button = button;
156     this->context= context;
157     this->action = action;
158     this->xroot  = xroot;
159     this->yroot  = yroot;
160     this->pressx = initpos.x();
161     this->pressy = initpos.y();
162     this->press_clientx      = initarea.x();
163     this->press_clienty      = initarea.y();
164     this->press_clientwidth  = initarea.width();
165     this->press_clientheight = initarea.height();
166   }
167   MouseData(int screen, Client *client, Time time, unsigned int state,
168             unsigned int button, MouseContext::MC context,
169             MouseAction::MA action) {
170     this->screen = screen;
171     this->client = client;
172     this->time   = time;
173     this->state  = state;
174     this->button = button;
175     this->context= context;
176     this->action = action;
177     this->xroot  = xroot;
178     this->yroot  = yroot;
179     this->pressx = 0;
180     this->pressy = 0;
181     this->press_clientx      = 0;
182     this->press_clienty      = 0;
183     this->press_clientwidth  = 0;
184     this->press_clientheight = 0;
185   }
186 };
187
188 class EventData {
189 public:
190   int screen;
191   Client *client;
192   unsigned int state;
193   EventAction::EA action;
194
195   EventData(int screen, Client *client, EventAction::EA action,
196             unsigned int state) {
197     this->screen = screen;
198     this->client = client;
199     this->action = action;
200     this->state  = state;
201   }
202 };
203
204 class KeyData {
205 public:
206   int screen;
207   Client *client;
208   Time time;
209   unsigned int state;
210   char *key;
211   KeyAction::KA action;
212
213   KeyData(int screen, Client *client, Time time, unsigned int state,
214           unsigned int key, KeyAction::KA action) {
215     this->screen = screen;
216     this->client = client;
217     this->time   = time;
218     this->state  = state;
219     this->key    = XKeysymToString(XKeycodeToKeysym(**otk::display,
220                                                     key, 0));
221     this->action = action;
222   }
223 };
224
225 #ifndef SWIG
226
227 void python_init(char *argv0);
228 void python_destroy();
229 bool python_exec(const std::string &path);
230
231 bool python_get_long(const char *name, long *value);
232 bool python_get_string(const char *name, otk::ustring *value);
233 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value);
234
235 /***********************************************
236  * These are found in openbox.i, not python.cc *
237  ***********************************************/
238 void python_callback(PyObject *func, MouseData *data);
239 void python_callback(PyObject *func, EventData *data);
240 void python_callback(PyObject *func, KeyData *data);
241
242 #endif // SWIG
243
244 PyObject *mbind(const std::string &button, ob::MouseContext::MC context,
245                 ob::MouseAction::MA action, PyObject *func);
246
247 PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func);
248
249 PyObject *kgrab(int screen, PyObject *func);
250 PyObject *kungrab();
251
252 PyObject *mgrab(int screen);
253 PyObject *mungrab();
254
255 PyObject *ebind(ob::EventAction::EA action, PyObject *func);
256
257 void set_reset_key(const std::string &key);
258
259 PyObject *send_client_msg(Window target, Atom type, Window about,
260                           long data, long data1 = 0, long data2 = 0,
261                           long data3 = 0, long data4 = 0);
262
263
264 void execute(const std::string &bin, int screen=0);
265
266 }
267
268
269 #endif // __python_hh