1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
7 # include "../config.h"
13 #include "bindings.hh"
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!
57 %rename(register) python_register;
59 PyObject * python_register(int action, PyObject *func, bool infront = false)
61 if (!PyCallable_Check(func)) {
62 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
66 if (!ob::Openbox::instance->actions()->registerCallback(
67 (ob::OBActions::ActionType)action, func, infront)) {
68 PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback.");
71 Py_INCREF(Py_None); return Py_None;
74 PyObject * unregister(int action, PyObject *func)
76 if (!PyCallable_Check(func)) {
77 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
81 if (!ob::Openbox::instance->actions()->unregisterCallback(
82 (ob::OBActions::ActionType)action, func)) {
83 PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback.");
86 Py_INCREF(Py_None); return Py_None;
89 PyObject * unregister_all(int action)
91 if (!ob::Openbox::instance->actions()->unregisterAllCallbacks(
92 (ob::OBActions::ActionType)action)) {
93 PyErr_SetString(PyExc_RuntimeError,
94 "Unable to unregister action callbacks.");
97 Py_INCREF(Py_None); return Py_None;
100 PyObject * bind(PyObject *keylist, PyObject *func)
102 if (!PyList_Check(keylist)) {
103 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
115 vectkeylist.push_back(PyString_AsString(str));
118 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
119 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
122 Py_INCREF(Py_None); return Py_None;
125 PyObject * unbind(PyObject *keylist)
127 if (!PyList_Check(keylist)) {
128 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
140 vectkeylist.push_back(PyString_AsString(str));
143 ob::Openbox::instance->bindings()->remove(vectkeylist);
144 Py_INCREF(Py_None); return Py_None;
149 ob::Openbox::instance->bindings()->removeAll();
152 void set_reset_key(const std::string &key)
154 ob::Openbox::instance->bindings()->setResetKey(key);
158 %ignore ob::OBScreen::clients;
162 %extend ob::OBScreen {
163 OBClient *client(int i) {
164 if (i >= (int)self->clients.size())
166 ob::OBScreen::ClientList::iterator it = self->clients.begin();
170 int clientCount() const {
171 return (int) self->clients.size();
175 %import "../otk/eventdispatcher.hh"
176 %import "../otk/eventhandler.hh"
180 %include "openbox.hh"