1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
7 # include "../config.h"
13 #include "bindings.hh"
18 %include "exception.i"
20 //%template(ClientList) std::list<OBClient*>;
22 %ignore ob::Openbox::instance;
24 ob::Openbox *Openbox_instance() { return ob::Openbox::instance; }
27 // stuff for scripting callbacks!
56 %rename(register) python_register;
58 /*PyObject * python_register(int action, PyObject *func, bool infront = false)
60 if (!PyCallable_Check(func)) {
61 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
65 if (!ob::Openbox::instance->actions()->registerCallback(
66 (ob::OBActions::ActionType)action, func, infront)) {
67 PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback.");
70 Py_INCREF(Py_None); return Py_None;
73 PyObject * unregister(int action, PyObject *func)
75 if (!PyCallable_Check(func)) {
76 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
80 if (!ob::Openbox::instance->actions()->unregisterCallback(
81 (ob::OBActions::ActionType)action, func)) {
82 PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback.");
85 Py_INCREF(Py_None); return Py_None;
88 PyObject * unregister_all(int action)
90 if (!ob::Openbox::instance->actions()->unregisterAllCallbacks(
91 (ob::OBActions::ActionType)action)) {
92 PyErr_SetString(PyExc_RuntimeError,
93 "Unable to unregister action callbacks.");
96 Py_INCREF(Py_None); return Py_None;
99 PyObject * mbind(const std::string &button, MouseContext context,
102 if (!PyCallable_Check(func)) {
103 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
107 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
108 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
111 Py_INCREF(Py_None); return Py_None;
114 PyObject * kbind(PyObject *keylist, KeyContext context, PyObject *func)
116 if (!PyCallable_Check(func)) {
117 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
120 if (!PyList_Check(keylist)) {
121 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
133 vectkeylist.push_back(PyString_AsString(str));
136 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
137 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
140 Py_INCREF(Py_None); return Py_None;
143 PyObject * kunbind(PyObject *keylist)
145 if (!PyList_Check(keylist)) {
146 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
158 vectkeylist.push_back(PyString_AsString(str));
161 ob::Openbox::instance->bindings()->remove(vectkeylist);
162 Py_INCREF(Py_None); return Py_None;
167 ob::Openbox::instance->bindings()->removeAll();
170 void set_reset_key(const std::string &key)
172 ob::Openbox::instance->bindings()->setResetKey(key);
176 %ignore ob::OBScreen::clients;
180 %extend ob::OBScreen {
181 OBClient *client(int i) {
182 if (i >= (int)self->clients.size())
184 ob::OBScreen::ClientList::iterator it = self->clients.begin();
188 int clientCount() const {
189 return (int) self->clients.size();
193 %import "../otk/eventdispatcher.hh"
194 %import "../otk/eventhandler.hh"
198 %include "openbox.hh"