]> icculus.org git repositories - dana/openbox.git/blob - src/python.hh
new/better/cleaner scripting interface
[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     NUM_MOUSE_CONTEXT
41   };
42 };
43
44 struct MouseAction {
45   enum MA {
46     Press,
47     Click,
48     DoubleClick,
49     Motion,
50     NUM_MOUSE_ACTION
51   };
52 };
53
54 struct KeyContext {
55   enum KC {
56     Menu,
57     All,
58     NUM_KEY_CONTEXT
59   };
60 };
61
62 struct KeyAction {
63   enum KA {
64     Press,
65     Release,
66     NUM_KEY_ACTION
67   };
68 };
69
70 struct EventAction {
71   enum EA {
72     EnterWindow,
73     LeaveWindow,
74     PlaceWindow,
75     NewWindow,
76     CloseWindow,
77     Startup,
78     Shutdown,
79     Focus,
80     Bell,
81     UrgentWindow,
82     NUM_EVENTS
83   };
84 };
85
86 class MouseData {
87 public:
88   int screen;
89   Client *client;
90   Time time;
91   unsigned int state;
92   unsigned int button;
93   MouseContext::MC context;
94   MouseAction::MA action;
95   int xroot;
96   int yroot;
97   int pressx;
98   int pressy;
99   int press_clientx;
100   int press_clienty;
101   int press_clientwidth;
102   int press_clientheight;
103
104   MouseData(int screen, Client *client, Time time, unsigned int state,
105             unsigned int button, MouseContext::MC context,
106             MouseAction::MA action, int xroot, int yroot,
107             const otk::Point &initpos, const otk::Rect &initarea) {
108     this->screen = screen;
109     this->client = client;
110     this->time   = time;
111     this->state  = state;
112     this->button = button;
113     this->context= context;
114     this->action = action;
115     this->xroot  = xroot;
116     this->yroot  = yroot;
117     this->pressx = initpos.x();
118     this->pressy = initpos.y();
119     this->press_clientx      = initarea.x();
120     this->press_clienty      = initarea.y();
121     this->press_clientwidth  = initarea.width();
122     this->press_clientheight = initarea.height();
123   }
124   MouseData(int screen, Client *client, Time time, unsigned int state,
125             unsigned int button, MouseContext::MC context,
126             MouseAction::MA action) {
127     this->screen = screen;
128     this->client = client;
129     this->time   = time;
130     this->state  = state;
131     this->button = button;
132     this->context= context;
133     this->action = action;
134     this->xroot  = xroot;
135     this->yroot  = yroot;
136     this->pressx = 0;
137     this->pressy = 0;
138     this->press_clientx      = 0;
139     this->press_clienty      = 0;
140     this->press_clientwidth  = 0;
141     this->press_clientheight = 0;
142   }
143 };
144
145 class EventData {
146 public:
147   int screen;
148   Client *client;
149   unsigned int state;
150   EventAction::EA action;
151
152   EventData(int screen, Client *client, EventAction::EA action,
153             unsigned int state) {
154     this->screen = screen;
155     this->client = client;
156     this->action = action;
157     this->state  = state;
158   }
159 };
160
161 class KeyData {
162 public:
163   int screen;
164   Client *client;
165   Time time;
166   unsigned int state;
167   char *key;
168   KeyAction::KA action;
169
170   KeyData(int screen, Client *client, Time time, unsigned int state,
171           unsigned int key, KeyAction::KA action) {
172     this->screen = screen;
173     this->client = client;
174     this->time   = time;
175     this->state  = state;
176     this->key    = XKeysymToString(XKeycodeToKeysym(**otk::display,
177                                                     key, 0));
178     this->action = action;
179   }
180 };
181
182 #ifndef SWIG
183
184 void python_init(char *argv0);
185 void python_destroy();
186 bool python_exec(const std::string &path);
187
188 bool python_get_long(const char *name, long *value);
189 bool python_get_string(const char *name, otk::ustring *value);
190 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value);
191
192 /***********************************************
193  * These are found in openbox.i, not python.cc *
194  ***********************************************/
195 void python_callback(PyObject *func, MouseData *data);
196 void python_callback(PyObject *func, EventData *data);
197 void python_callback(PyObject *func, KeyData *data);
198
199 #endif // SWIG
200
201 PyObject *mbind(const std::string &button, ob::MouseContext::MC context,
202                 ob::MouseAction::MA action, PyObject *func);
203
204 PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func);
205
206 PyObject *kgrab(int screen, PyObject *func);
207 PyObject *kungrab();
208
209 PyObject *ebind(ob::EventAction::EA action, PyObject *func);
210
211 void set_reset_key(const std::string &key);
212
213 PyObject *send_client_msg(Window target, Atom type, Window about,
214                           long data, long data1 = 0, long data2 = 0,
215                           long data3 = 0, long data4 = 0);
216
217
218 void execute(const std::string &bin, int screen=0);
219
220 }
221
222
223 #endif // __python_hh