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 (!PyCallable_Check(func)) {
103 PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
106 if (!PyList_Check(keylist)) {
107 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
111 ob::OBBindings::StringVect vectkeylist;
112 for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
113 PyObject *str = PyList_GetItem(keylist, i);
114 if (!PyString_Check(str)) {
115 PyErr_SetString(PyExc_TypeError,
116 "Invalid keylist. It must contain only strings.");
119 vectkeylist.push_back(PyString_AsString(str));
122 if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
123 PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
126 Py_INCREF(Py_None); return Py_None;
129 PyObject * unbind(PyObject *keylist)
131 if (!PyList_Check(keylist)) {
132 PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
136 ob::OBBindings::StringVect vectkeylist;
137 for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
138 PyObject *str = PyList_GetItem(keylist, i);
139 if (!PyString_Check(str)) {
140 PyErr_SetString(PyExc_TypeError,
141 "Invalid keylist. It must contain only strings.");
144 vectkeylist.push_back(PyString_AsString(str));
147 ob::Openbox::instance->bindings()->remove(vectkeylist);
148 Py_INCREF(Py_None); return Py_None;
153 ob::Openbox::instance->bindings()->removeAll();
156 void set_reset_key(const std::string &key)
158 ob::Openbox::instance->bindings()->setResetKey(key);
162 %ignore ob::OBScreen::clients;
166 %extend ob::OBScreen {
167 OBClient *client(int i) {
168 if (i >= (int)self->clients.size())
170 ob::OBScreen::ClientList::iterator it = self->clients.begin();
174 int clientCount() const {
175 return (int) self->clients.size();
179 %import "../otk/eventdispatcher.hh"
180 %import "../otk/eventhandler.hh"
184 %include "openbox.hh"