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