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