]> icculus.org git repositories - mikachu/openbox.git/blob - src/python.hh
new python callbacks data, infrastructure. going to rework bindings code. cvs wont...
[mikachu/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
14 extern "C" {
15 #include <X11/Xlib.h>
16 #include <Python.h>
17 }
18
19 #include <string>
20 #include <vector>
21
22 namespace ob {
23
24 class OBClient;
25
26 enum MouseContext {
27   MC_Frame,
28   MC_Titlebar,
29   MC_Handle,
30   MC_Window,
31   MC_MaximizeButton,
32   MC_CloseButton,
33   MC_IconifyButton,
34   MC_StickyButton,
35   MC_Grip,
36   MC_Root,
37   MC_MenuItem,
38   NUM_MOUSE_CONTEXT
39 };
40
41 enum MouseAction {
42   MousePress,
43   MouseClick,
44   MouseDoubleClick,
45   MouseMotion,
46   NUM_MOUSE_ACTION
47 };
48
49 enum KeyContext {
50   KC_Menu,
51   KC_All,
52   NUM_KEY_CONTEXT
53 };
54
55 enum EventAction {
56   EventEnterWindow,
57   EventLeaveWindow,
58   EventPlaceWindow,
59   EventNewWindow,
60   EventCloseWindow,
61   EventStartup,
62   EventShutdown,
63   EventFocus,
64   EventBell,
65   NUM_EVENTS
66 };
67
68 // *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
69 class MotionData {
70 public:
71   int screen;
72   OBClient *client;
73   Time time;
74   unsigned int state;
75   unsigned int button;
76   MouseContext context;
77   MouseAction action;
78   int xroot;
79   int yroot;
80   int pressx;
81   int pressy;
82   int press_clientx;
83   int press_clienty;
84   int press_clientwidth;
85   int press_clientheight;
86
87   MotionData(int screen, OBClient *client, Time time, unsigned int state,
88              unsigned int button, MouseContext context, MouseAction action,
89              int xroot, int yroot, const otk::Point &initpos,
90              const otk::Rect &initarea) {
91     this->screen = screen;
92     this->client = client;
93     this->time   = time;
94     this->state  = state;
95     this->button = button;
96     this->context= context;
97     this->action = action;
98     this->xroot  = xroot;
99     this->yroot  = yroot;
100     this->pressx = initpos.x();
101     this->pressy = initpos.y();
102     this->press_clientx      = initarea.x();
103     this->press_clienty      = initarea.y();
104     this->press_clientwidth  = initarea.width();
105     this->press_clientheight = initarea.height();
106   }
107 };
108
109 // *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
110 class ButtonData {
111 public:
112   int screen;
113   OBClient *client;
114   Time time;
115   unsigned int state;
116   unsigned int button;
117   MouseContext context;
118   MouseAction action;
119
120   ButtonData(int screen, OBClient *client, Time time, unsigned int state,
121              unsigned int button, MouseContext context, MouseAction action) {
122     this->screen = screen;
123     this->client = client;
124     this->time   = time;
125     this->state  = state;
126     this->button = button;
127     this->context= context;
128     this->action = action;
129   }
130 };
131
132 class EventData {
133 public:
134   int screen;
135   OBClient *client;
136   unsigned int state;
137   EventAction action;
138
139   EventData(int screen, OBClient *client, EventAction action,
140             unsigned int state) {
141     this->screen = screen;
142     this->client = client;
143     this->action = action;
144     this->state  = state;
145   }
146 };
147
148 class KeyData {
149 public:
150   int screen;
151   OBClient *client;
152   Time time;
153   unsigned int state;
154   std::string key;
155
156   KeyData(int screen, OBClient *client, Time time, unsigned int state,
157           unsigned int key) {
158     this->screen = screen;
159     this->client = client;
160     this->time   = time;
161     this->state  = state;
162     this->key    = XKeysymToString(XKeycodeToKeysym(otk::OBDisplay::display,
163                                                     key, 0));
164   }
165 };
166
167 #ifndef SWIG
168
169 void python_init(char *argv0);
170 void python_destroy();
171 bool python_exec(const std::string &path);
172
173 bool python_get_long(const char *name, long *value);
174 bool python_get_string(const char *name, std::string *value);
175 bool python_get_stringlist(const char *name, std::vector<std::string> *value);
176
177 /***********************************************
178  * These are found in openbox.i, not python.cc *
179  ***********************************************/
180 void python_callback(PyObject *func, MotionData *data);
181 void python_callback(PyObject *func, ButtonData *data);
182 void python_callback(PyObject *func, EventData *data);
183 void python_callback(PyObject *func, KeyData *data);
184
185 #endif // SWIG
186
187 PyObject *mbind(const std::string &button, ob::MouseContext context,
188                 ob::MouseAction action, PyObject *func);
189
190 PyObject *kbind(PyObject *keylist, ob::KeyContext context, PyObject *func);
191
192 PyObject *ebind(ob::EventAction action, PyObject *func);
193
194 void set_reset_key(const std::string &key);
195
196 PyObject *send_client_msg(Window target, int type, Window about,
197                           long data, long data1 = 0, long data2 = 0,
198                           long data3 = 0, long data4 = 0);
199 }
200
201
202 #endif // __python_hh