X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=wrap%2Fcallback.i;h=b13a3e9d14167a0a55d2709273d7e6b952944345;hb=c217a730901137252cde2d3a39b59c4ebd53e879;hp=c4bec25728362553df5655ea76c1ef47f96e8112;hpb=7c8c9e998ffc3a9b22e15feeffe77823142ce531;p=chaz%2Fopenbox diff --git a/wrap/callback.i b/wrap/callback.i index c4bec257..b13a3e9d 100644 --- a/wrap/callback.i +++ b/wrap/callback.i @@ -1,23 +1,21 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +%include "std_string.i" + %{ /* Calls a python callback for the MouseCallback function type */ static void PythonMouseCallback(ob::MouseData *data, void *pyfunc) { - PyObject *func, *arglist, *pdata; - PyObject *result; - double dres = 0; - - func = (PyObject*) pyfunc; + PyObject *arglist, *pdata, *result; pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__MouseData, 0); arglist = Py_BuildValue("(O)", pdata); Py_DECREF(pdata); // call the callback - result = PyEval_CallObject(func, arglist); + result = PyEval_CallObject((PyObject*)pyfunc, arglist); if (!result || PyErr_Occurred()) { // an exception occured in the script, display it PyErr_Print(); @@ -32,18 +30,14 @@ static void PythonMouseCallback(ob::MouseData *data, void *pyfunc) */ static void PythonKeyCallback(ob::KeyData *data, void *pyfunc) { - PyObject *func, *arglist, *pdata; - PyObject *result; - double dres = 0; - - func = (PyObject*) pyfunc; + PyObject *arglist, *pdata, *result; pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__KeyData, 0); arglist = Py_BuildValue("(O)", pdata); Py_DECREF(pdata); // call the callback - result = PyEval_CallObject(func, arglist); + result = PyEval_CallObject((PyObject*)pyfunc, arglist); if (!result || PyErr_Occurred()) { // an exception occured in the script, display it PyErr_Print(); @@ -58,18 +52,14 @@ static void PythonKeyCallback(ob::KeyData *data, void *pyfunc) */ static void PythonEventCallback(ob::EventData *data, void *pyfunc) { - PyObject *func, *arglist, *pdata; - PyObject *result; - double dres = 0; - - func = (PyObject*) pyfunc; + PyObject *arglist, *pdata, *result; pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__EventData, 0); arglist = Py_BuildValue("(O)", pdata); Py_DECREF(pdata); // call the callback - result = PyEval_CallObject(func, arglist); + result = PyEval_CallObject((PyObject*)pyfunc, arglist); if (!result || PyErr_Occurred()) { // an exception occured in the script, display it PyErr_Print(); @@ -112,6 +102,8 @@ static void PythonEventCallback(ob::EventData *data, void *pyfunc) } %inline %{ +#include "bindings.hh" + bool mbind(const std::string &button, ob::MouseContext::MC context, ob::MouseAction::MA action, PyObject *func) { @@ -129,6 +121,7 @@ bool mbind(const std::string &button, ob::MouseContext::MC context, PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } + Py_INCREF(func); return true; } @@ -143,6 +136,7 @@ bool ebind(ob::EventAction::EA action, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } + Py_INCREF(func); return true; } @@ -153,6 +147,7 @@ bool kgrab(int screen, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to grab keybaord."); return false; } + Py_INCREF(func); return true; } @@ -202,6 +197,7 @@ bool kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } + Py_INCREF(func); return true; }