]> icculus.org git repositories - mikachu/openbox.git/blob - src/openbox.i
trasitioning for new button event handling
[mikachu/openbox.git] / src / openbox.i
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 %module openbox
4
5 %{
6 #ifdef HAVE_CONFIG_H
7 #  include "../config.h"
8 #endif
9
10 #include "openbox.hh"
11 #include "screen.hh"
12 #include "client.hh"
13 #include "bindings.hh"
14 #include "actions.hh"
15 %}
16
17 %include "stl.i"
18 %include "exception.i"
19 //%include std_list.i
20 //%template(ClientList) std::list<OBClient*>;
21
22 %ignore ob::Openbox::instance;
23 %inline %{
24   ob::Openbox *Openbox_instance() { return ob::Openbox::instance; }
25 %};
26
27 // stuff for scripting callbacks!
28 %inline %{
29   enum ActionType {
30     Action_ButtonPress,
31     Action_Click,
32     Action_DoubleClick,
33     Action_EnterWindow,
34     Action_LeaveWindow,
35     Action_KeyPress,
36     Action_MouseMotion,
37     Action_NewWindow,
38     Action_CloseWindow
39   };
40   enum WidgetType {
41     Type_Frame,
42     Type_Titlebar,
43     Type_Handle,
44     Type_Plate,
45     Type_Label,
46     Type_MaximizeButton,
47     Type_CloseButton,
48     Type_IconifyButton,
49     Type_StickyButton,
50     Type_LeftGrip,
51     Type_RightGrip,
52     Type_Window,
53     Type_Root
54   };
55 %}
56 %rename(register) python_register;
57 %inline %{
58 /*PyObject * python_register(int action, PyObject *func, bool infront = false)
59 {
60   if (!PyCallable_Check(func)) {
61     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
62     return NULL;
63   }
64
65   if (!ob::Openbox::instance->actions()->registerCallback(
66         (ob::OBActions::ActionType)action, func, infront)) {
67     PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback.");
68     return NULL;
69   }
70   Py_INCREF(Py_None); return Py_None;
71 }
72
73 PyObject * unregister(int action, PyObject *func)
74 {
75   if (!PyCallable_Check(func)) {
76     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
77     return NULL;
78   }
79
80   if (!ob::Openbox::instance->actions()->unregisterCallback(
81         (ob::OBActions::ActionType)action, func)) {
82     PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback.");
83     return NULL;
84   }
85   Py_INCREF(Py_None); return Py_None;
86 }
87
88 PyObject * unregister_all(int action)
89 {
90   if (!ob::Openbox::instance->actions()->unregisterAllCallbacks(
91         (ob::OBActions::ActionType)action)) {
92     PyErr_SetString(PyExc_RuntimeError,
93                     "Unable to unregister action callbacks.");
94     return NULL;
95   }
96   Py_INCREF(Py_None); return Py_None;
97 }
98 */
99 PyObject * mbind(const std::string &button, MouseContext context,
100                  PyObject *func)
101 {
102   if (!PyCallable_Check(func)) {
103     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
104     return NULL;
105   }
106   
107   if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
108     PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
109     return NULL;
110   }
111   Py_INCREF(Py_None); return Py_None;
112 }
113
114 PyObject * kbind(PyObject *keylist, KeyContext context, PyObject *func)
115 {
116   if (!PyCallable_Check(func)) {
117     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
118     return NULL;
119   }
120   if (!PyList_Check(keylist)) {
121     PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
122     return NULL;
123   }
124
125   ob::OBBindings::StringVect vectkeylist;
126   for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
127     PyObject *str = PyList_GetItem(keylist, i);
128     if (!PyString_Check(str)) {
129       PyErr_SetString(PyExc_TypeError,
130                      "Invalid keylist. It must contain only strings.");
131       return NULL;
132     }
133     vectkeylist.push_back(PyString_AsString(str));
134   }
135
136   if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
137     PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
138     return NULL;
139   }
140   Py_INCREF(Py_None); return Py_None;
141 }
142
143 PyObject * kunbind(PyObject *keylist)
144 {
145   if (!PyList_Check(keylist)) {
146     PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
147     return NULL;
148   }
149
150   ob::OBBindings::StringVect vectkeylist;
151   for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
152     PyObject *str = PyList_GetItem(keylist, i);
153     if (!PyString_Check(str)) {
154       PyErr_SetString(PyExc_TypeError,
155                      "Invalid keylist. It must contain only strings.");
156       return NULL;
157     }
158     vectkeylist.push_back(PyString_AsString(str));
159   }
160
161   ob::Openbox::instance->bindings()->remove(vectkeylist);
162   Py_INCREF(Py_None); return Py_None;
163 }
164
165 void kunbind_all()
166 {
167   ob::Openbox::instance->bindings()->removeAll();
168 }
169
170 void set_reset_key(const std::string &key)
171 {
172   ob::Openbox::instance->bindings()->setResetKey(key);
173 }
174 %}
175
176 %ignore ob::OBScreen::clients;
177 %{
178   #include <iterator>
179 %}
180 %extend ob::OBScreen {
181   OBClient *client(int i) {
182     if (i >= (int)self->clients.size())
183       return NULL;
184     ob::OBScreen::ClientList::iterator it = self->clients.begin();
185     std::advance(it,i);
186     return *it;
187   }
188   int clientCount() const {
189     return (int) self->clients.size();
190   }
191 };
192
193 %import "../otk/eventdispatcher.hh"
194 %import "../otk/eventhandler.hh"
195 %import "widget.hh"
196 %import "actions.hh"
197
198 %include "openbox.hh"
199 %include "screen.hh"
200 %include "client.hh"
201 %include "python.hh"
202
203 // for Mod1Mask etc
204 %include "X11/X.h"