From: Dana Jansens Date: Fri, 27 Dec 2002 08:39:53 +0000 (+0000) Subject: add an unregister_all for python callbacks X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=c645416035d64cc959d1dd0e937b31b07489e54b;p=chaz%2Fopenbox add an unregister_all for python callbacks --- diff --git a/src/openbox.i b/src/openbox.i index 20c8ea06..4d11507c 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -55,6 +55,7 @@ %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; %{ diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 5cf5d8ea..7f0d015f 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -2513,6 +2513,21 @@ static PyObject *_wrap_unregister(PyObject *self, PyObject *args) { } +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 @@ static PyMethodDef SwigMethods[] = { { (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 } }; diff --git a/src/python.cc b/src/python.cc index 97a3a4d2..ed171f9c 100644 --- a/src/python.cc +++ b/src/python.cc @@ -74,6 +74,20 @@ bool python_unregister(int action, PyObject *callback) 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) diff --git a/src/python.hh b/src/python.hh index 30cd752d..496b459d 100644 --- a/src/python.hh +++ b/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,