00001
00002 #ifndef __python_hh
00003 #define __python_hh
00004
00005
00006
00007
00008
00009 #include "otk/point.hh"
00010 #include "otk/rect.hh"
00011 #include "otk/property.hh"
00012 #include "otk/display.hh"
00013 #include "otk/ustring.hh"
00014
00015 extern "C" {
00016 #include <X11/Xlib.h>
00017 #include <Python.h>
00018 }
00019
00020 #include <string>
00021 #include <vector>
00022
00023 namespace ob {
00024
00025 class Client;
00026
00027 struct MouseContext {
00028 enum MC {
00029 Frame,
00030 Titlebar,
00031 Handle,
00032 Window,
00033 MaximizeButton,
00034 CloseButton,
00035 IconifyButton,
00036 AllDesktopsButton,
00037 Grip,
00038 Root,
00039 MenuItem
00040 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
00041 , NUM_MOUSE_CONTEXT
00042 #endif
00043 };
00044 };
00045
00046 struct MouseAction {
00047 enum MA {
00048 Press,
00049 Release,
00050 Click,
00051 DoubleClick,
00052 Motion
00053 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
00054 , NUM_MOUSE_ACTION
00055 #endif
00056 };
00057 };
00058
00059 struct KeyContext {
00060 enum KC {
00061 Menu,
00062 All
00063 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
00064 , NUM_KEY_CONTEXT
00065 #endif
00066 };
00067 };
00068
00069 struct KeyAction {
00070 enum KA {
00071 Press,
00072 Release
00073 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
00074 , NUM_KEY_ACTION
00075 #endif
00076 };
00077 };
00078
00079 struct EventAction {
00080 enum EA {
00081 EnterWindow,
00082 LeaveWindow,
00083
00084
00085 PlaceWindow,
00086
00087
00088
00089
00090
00091
00092 DisplayingWindow,
00093
00094 NewWindow,
00095
00096 CloseWindow,
00097
00098
00099
00100
00101 Startup,
00102
00103
00104
00105
00106 Shutdown,
00107
00108
00109
00110
00111 Focus,
00112
00113
00114
00115
00116
00117 Bell,
00118
00119
00120
00121
00122 UrgentWindow
00123 #if ! (defined(DOXYGEN_IGNORE) || defined(SWIG))
00124 , NUM_EVENTS
00125 #endif
00126 };
00127 };
00128
00129 class MouseData {
00130 public:
00131 int screen;
00132 Client *client;
00133 Time time;
00134 unsigned int state;
00135 unsigned int button;
00136 MouseContext::MC context;
00137 MouseAction::MA action;
00138 int xroot;
00139 int yroot;
00140 int pressx;
00141 int pressy;
00142 int press_clientx;
00143 int press_clienty;
00144 int press_clientwidth;
00145 int press_clientheight;
00146
00147 MouseData(int screen, Client *client, Time time, unsigned int state,
00148 unsigned int button, MouseContext::MC context,
00149 MouseAction::MA action, int xroot, int yroot,
00150 const otk::Point &initpos, const otk::Rect &initarea) {
00151 this->screen = screen;
00152 this->client = client;
00153 this->time = time;
00154 this->state = state;
00155 this->button = button;
00156 this->context= context;
00157 this->action = action;
00158 this->xroot = xroot;
00159 this->yroot = yroot;
00160 this->pressx = initpos.x();
00161 this->pressy = initpos.y();
00162 this->press_clientx = initarea.x();
00163 this->press_clienty = initarea.y();
00164 this->press_clientwidth = initarea.width();
00165 this->press_clientheight = initarea.height();
00166 }
00167 MouseData(int screen, Client *client, Time time, unsigned int state,
00168 unsigned int button, MouseContext::MC context,
00169 MouseAction::MA action) {
00170 this->screen = screen;
00171 this->client = client;
00172 this->time = time;
00173 this->state = state;
00174 this->button = button;
00175 this->context= context;
00176 this->action = action;
00177 this->xroot = xroot;
00178 this->yroot = yroot;
00179 this->pressx = 0;
00180 this->pressy = 0;
00181 this->press_clientx = 0;
00182 this->press_clienty = 0;
00183 this->press_clientwidth = 0;
00184 this->press_clientheight = 0;
00185 }
00186 };
00187
00188 class EventData {
00189 public:
00190 int screen;
00191 Client *client;
00192 unsigned int state;
00193 EventAction::EA action;
00194
00195 EventData(int screen, Client *client, EventAction::EA action,
00196 unsigned int state) {
00197 this->screen = screen;
00198 this->client = client;
00199 this->action = action;
00200 this->state = state;
00201 }
00202 };
00203
00204 class KeyData {
00205 public:
00206 int screen;
00207 Client *client;
00208 Time time;
00209 unsigned int state;
00210 char *key;
00211 KeyAction::KA action;
00212
00213 KeyData(int screen, Client *client, Time time, unsigned int state,
00214 unsigned int key, KeyAction::KA action) {
00215 this->screen = screen;
00216 this->client = client;
00217 this->time = time;
00218 this->state = state;
00219 this->key = XKeysymToString(XKeycodeToKeysym(**otk::display,
00220 key, 0));
00221 this->action = action;
00222 }
00223 };
00224
00225 #ifndef SWIG
00226
00227 void python_init(char *argv0);
00228 void python_destroy();
00229 bool python_exec(const std::string &path);
00230
00231 bool python_get_long(const char *name, long *value);
00232 bool python_get_string(const char *name, otk::ustring *value);
00233 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value);
00234
00235
00236
00237
00238 void python_callback(PyObject *func, MouseData *data);
00239 void python_callback(PyObject *func, EventData *data);
00240 void python_callback(PyObject *func, KeyData *data);
00241
00242 #endif // SWIG
00243
00244 PyObject *mbind(const std::string &button, ob::MouseContext::MC context,
00245 ob::MouseAction::MA action, PyObject *func);
00246
00247 PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func);
00248
00249 PyObject *kgrab(int screen, PyObject *func);
00250 PyObject *kungrab();
00251
00252 PyObject *mgrab(int screen);
00253 PyObject *mungrab();
00254
00255 PyObject *ebind(ob::EventAction::EA action, PyObject *func);
00256
00257 void set_reset_key(const std::string &key);
00258
00259 PyObject *send_client_msg(Window target, Atom type, Window about,
00260 long data, long data1 = 0, long data2 = 0,
00261 long data3 = 0, long data4 = 0);
00262
00263
00264 void execute(const std::string &bin, int screen=0);
00265
00266 }
00267
00268
00269 #endif // __python_hh