kill button release events
[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_Client,
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 * bind(PyObject *keylist, PyObject *func)
100 {
101   if (!PyCallable_Check(func)) {
102     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
103     return NULL;
104   }
105   if (!PyList_Check(keylist)) {
106     PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
107     return NULL;
108   }
109
110   ob::OBBindings::StringVect vectkeylist;
111   for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
112     PyObject *str = PyList_GetItem(keylist, i);
113     if (!PyString_Check(str)) {
114       PyErr_SetString(PyExc_TypeError,
115                      "Invalid keylist. It must contain only strings.");
116       return NULL;
117     }
118     vectkeylist.push_back(PyString_AsString(str));
119   }
120
121   if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
122     PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
123     return NULL;
124   }
125   Py_INCREF(Py_None); return Py_None;
126 }
127
128 PyObject * unbind(PyObject *keylist)
129 {
130   if (!PyList_Check(keylist)) {
131     PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
132     return NULL;
133   }
134
135   ob::OBBindings::StringVect vectkeylist;
136   for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
137     PyObject *str = PyList_GetItem(keylist, i);
138     if (!PyString_Check(str)) {
139       PyErr_SetString(PyExc_TypeError,
140                      "Invalid keylist. It must contain only strings.");
141       return NULL;
142     }
143     vectkeylist.push_back(PyString_AsString(str));
144   }
145
146   ob::Openbox::instance->bindings()->remove(vectkeylist);
147   Py_INCREF(Py_None); return Py_None;
148 }
149
150 void unbind_all()
151 {
152   ob::Openbox::instance->bindings()->removeAll();
153 }
154
155 void set_reset_key(const std::string &key)
156 {
157   ob::Openbox::instance->bindings()->setResetKey(key);
158 }
159 %}
160
161 %ignore ob::OBScreen::clients;
162 %{
163   #include <iterator>
164 %}
165 %extend ob::OBScreen {
166   OBClient *client(int i) {
167     if (i >= (int)self->clients.size())
168       return NULL;
169     ob::OBScreen::ClientList::iterator it = self->clients.begin();
170     std::advance(it,i);
171     return *it;
172   }
173   int clientCount() const {
174     return (int) self->clients.size();
175   }
176 };
177
178 %import "../otk/eventdispatcher.hh"
179 %import "../otk/eventhandler.hh"
180 %import "widget.hh"
181 %import "actions.hh"
182
183 %include "openbox.hh"
184 %include "screen.hh"
185 %include "client.hh"
186
187 // for Mod1Mask etc
188 %include "X11/X.h"