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