add an unregister_all for python callbacks
Dana Jansens danakj@orodu.net
4 files changed,
34 insertions(+),
0 deletions(-)
M
src/openbox.i
→
src/openbox.i
@@ -55,6 +55,7 @@ %ignore ob::python_callback;
%rename(register) ob::python_register; %rename(preregister) ob::python_preregister; %rename(unregister) ob::python_unregister; +%rename(unregister_all) ob::python_unregister_all; %ignore ob::OBScreen::clients; %{
M
src/openbox_wrap.cc
→
src/openbox_wrap.cc
@@ -2513,6 +2513,21 @@ return NULL;
} +static PyObject *_wrap_unregister_all(PyObject *self, PyObject *args) { + PyObject *resultobj; + int arg1 ; + bool result; + + if(!PyArg_ParseTuple(args,(char *)"i:unregister_all",&arg1)) goto fail; + result = (bool)ob::python_unregister_all(arg1); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"Openbox_instance", _wrap_Openbox_instance, METH_VARARGS }, { (char *)"Cursors_session_set", _wrap_Cursors_session_set, METH_VARARGS },@@ -2609,6 +2624,7 @@ { (char *)"OBClient_swigregister", OBClient_swigregister, METH_VARARGS },
{ (char *)"register", _wrap_register, METH_VARARGS }, { (char *)"preregister", _wrap_preregister, METH_VARARGS }, { (char *)"unregister", _wrap_unregister, METH_VARARGS }, + { (char *)"unregister_all", _wrap_unregister_all, METH_VARARGS }, { NULL, NULL } };
M
src/python.cc
→
src/python.cc
@@ -74,6 +74,20 @@ }
return true; } +bool python_unregister_all(int action) +{ + if (action < 0 || action >= OBActions::NUM_ACTIONS) { + PyErr_SetString(PyExc_AssertionError, "Invalid action type."); + return false; + } + + while (!callbacks[action].empty()) { + Py_XDECREF(callbacks[action].back()); + callbacks[action].pop_back(); + } + return true; +} + void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state, long d1, long d2, long d3, long d4)
M
src/python.hh
→
src/python.hh
@@ -22,6 +22,9 @@ bool python_preregister(int action, PyObject *callback);
//! Remove a python callback function from the hook list bool python_unregister(int action, PyObject *callback); +//! Removes all python callback functions from the hook list +bool python_unregister_all(int action); + //! Fire a python callback function void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state,