X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fbindings.cc;h=97dd2aa1f8e8b1c183e38ee59e8938e8fe88f9c2;hb=4dd8520e929b76f95926ffc746b733a7e416f080;hp=2b81381c080925b48d15457531b150df9720a2d8;hpb=f8ea576460470ecc2e395cf43e31a67752adbbb5;p=chaz%2Fopenbox diff --git a/src/bindings.cc b/src/bindings.cc index 2b81381c..97dd2aa1 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -146,7 +146,10 @@ OBBindings::OBBindings() { _timer.setTimeout(5000); // chains reset after 5 seconds - setResetKey("C-g"); // set the default reset key +// setResetKey("C-g"); // set the default reset key + + for (int i = 0; i < NUM_EVENTS; ++i) + _events[i] = 0; } @@ -155,6 +158,7 @@ OBBindings::~OBBindings() grabKeys(false); removeAllKeys(); removeAllButtons(); + removeAllEvents(); } @@ -325,13 +329,14 @@ void OBBindings::grabKeys(bool grab) p = p->next_sibling; } - if (grab) - otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers, - root, true, GrabModeAsync, GrabModeAsync, - false); - else - otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers, - root); + if (_resetkey.key) + if (grab) + otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers, + root, false, GrabModeAsync, GrabModeAsync, + false); + else + otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers, + root); } } @@ -493,4 +498,42 @@ void OBBindings::fireButton(ButtonData *data) } } + +bool OBBindings::addEvent(EventAction action, PyObject *callback) +{ + if (action < 0 || action >= NUM_EVENTS) { + return false; + } + + Py_XDECREF(_events[action]); + _events[action] = callback; + Py_INCREF(callback); + return true; +} + +bool OBBindings::removeEvent(EventAction action) +{ + if (action < 0 || action >= NUM_EVENTS) { + return false; + } + + Py_XDECREF(_events[action]); + _events[action] = 0; + return true; +} + +void OBBindings::removeAllEvents() +{ + for (int i = 0; i < NUM_EVENTS; ++i) { + Py_XDECREF(_events[i]); + _events[i] = 0; + } +} + +void OBBindings::fireEvent(EventData *data) +{ + if (_events[data->action]) + python_callback(_events[data->action], (PyObject*)data); +} + }