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!
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 * bind(PyObject *keylist, PyObject *func)
101 if (!PyCallable_Check(func)) {
102 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
105 if (!PyList_Check(keylist)) {
106 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
118 vectkeylist.push_back(PyString_AsString(str));
121 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
122 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
125 Py_INCREF(Py_None); return Py_None;
128 PyObject * unbind(PyObject *keylist)
130 if (!PyList_Check(keylist)) {
131 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
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.");
143 vectkeylist.push_back(PyString_AsString(str));
146 ob::Openbox::instance->bindings()->remove(vectkeylist);
147 Py_INCREF(Py_None); return Py_None;
152 ob::Openbox::instance->bindings()->removeAll();
155 void set_reset_key(const std::string &key)
157 ob::Openbox::instance->bindings()->setResetKey(key);
161 %ignore ob::OBScreen::clients;
165 %extend ob::OBScreen {
166 OBClient *client(int i) {
167 if (i >= (int)self->clients.size())
169 ob::OBScreen::ClientList::iterator it = self->clients.begin();
173 int clientCount() const {
174 return (int) self->clients.size();
178 %import "../otk/eventdispatcher.hh"
179 %import "../otk/eventhandler.hh"
183 %include "openbox.hh"