]> Dogcows Code - chaz/openbox/blob - src/openbox.i
new code for bindings/callbacks. much sexier. now passes python classes back to the...
[chaz/openbox] / 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_ButtonRelease,
32 Action_Click,
33 Action_DoubleClick,
34 Action_EnterWindow,
35 Action_LeaveWindow,
36 Action_KeyPress,
37 Action_MouseMotion
38 };
39 enum WidgetType {
40 Type_Frame,
41 Type_Titlebar,
42 Type_Handle,
43 Type_Plate,
44 Type_Label,
45 Type_MaximizeButton,
46 Type_CloseButton,
47 Type_IconifyButton,
48 Type_StickyButton,
49 Type_LeftGrip,
50 Type_RightGrip,
51 Type_Client,
52 Type_Root
53 };
54 %}
55 %rename(register) python_register;
56 %inline %{
57 PyObject * python_register(int action, PyObject *func, bool infront = false)
58 {
59 if (!PyCallable_Check(func)) {
60 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
61 return NULL;
62 }
63
64 if (!ob::Openbox::instance->actions()->registerCallback(
65 (ob::OBActions::ActionType)action, func, infront)) {
66 PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback.");
67 return NULL;
68 }
69 Py_INCREF(Py_None); return Py_None;
70 }
71
72 PyObject * unregister(int action, PyObject *func)
73 {
74 if (!PyCallable_Check(func)) {
75 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
76 return NULL;
77 }
78
79 if (!ob::Openbox::instance->actions()->unregisterCallback(
80 (ob::OBActions::ActionType)action, func)) {
81 PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback.");
82 return NULL;
83 }
84 Py_INCREF(Py_None); return Py_None;
85 }
86
87 PyObject * unregister_all(int action)
88 {
89 if (!ob::Openbox::instance->actions()->unregisterAllCallbacks(
90 (ob::OBActions::ActionType)action)) {
91 PyErr_SetString(PyExc_RuntimeError,
92 "Unable to unregister action callbacks.");
93 return NULL;
94 }
95 Py_INCREF(Py_None); return Py_None;
96 }
97
98 PyObject * bind(PyObject *keylist, PyObject *func)
99 {
100 if (!PyList_Check(keylist)) {
101 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
102 return NULL;
103 }
104
105 ob::OBBindings::StringVect vectkeylist;
106 for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
107 PyObject *str = PyList_GetItem(keylist, i);
108 if (!PyString_Check(str)) {
109 PyErr_SetString(PyExc_TypeError,
110 "Invalid keylist. It must contain only strings.");
111 return NULL;
112 }
113 vectkeylist.push_back(PyString_AsString(str));
114 }
115
116 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
117 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
118 return NULL;
119 }
120 Py_INCREF(Py_None); return Py_None;
121 }
122
123 PyObject * unbind(PyObject *keylist)
124 {
125 if (!PyList_Check(keylist)) {
126 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
127 return NULL;
128 }
129
130 ob::OBBindings::StringVect vectkeylist;
131 for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
132 PyObject *str = PyList_GetItem(keylist, i);
133 if (!PyString_Check(str)) {
134 PyErr_SetString(PyExc_TypeError,
135 "Invalid keylist. It must contain only strings.");
136 return NULL;
137 }
138 vectkeylist.push_back(PyString_AsString(str));
139 }
140
141 ob::Openbox::instance->bindings()->remove(vectkeylist);
142 Py_INCREF(Py_None); return Py_None;
143 }
144
145 void unbind_all()
146 {
147 ob::Openbox::instance->bindings()->removeAll();
148 }
149
150 void set_reset_key(const std::string &key)
151 {
152 ob::Openbox::instance->bindings()->setResetKey(key);
153 }
154 %}
155
156 %ignore ob::OBScreen::clients;
157 %{
158 #include <iterator>
159 %}
160 %extend ob::OBScreen {
161 OBClient *client(int i) {
162 if (i >= (int)self->clients.size())
163 return NULL;
164 ob::OBScreen::ClientList::iterator it = self->clients.begin();
165 std::advance(it,i);
166 return *it;
167 }
168 int clientCount() const {
169 return (int) self->clients.size();
170 }
171 };
172
173 %import "../otk/eventdispatcher.hh"
174 %import "../otk/eventhandler.hh"
175 %import "widget.hh"
176 %import "actions.hh"
177
178 %include "openbox.hh"
179 %include "screen.hh"
180 %include "client.hh"
181
182 // for Mod1Mask etc
183 %include "X11/X.h"
This page took 0.041128 seconds and 4 git commands to generate.