{
for (int i=0; i<BUTTONS; ++i)
_posqueue[i] = new ButtonPressAction();
-
- for (int i = 0; i < NUM_EVENTS; ++i)
- _callback[i] = 0;
}
OtkEventHandler::enterHandler(e);
// run the ENTER python hook
- if (_callback[EventEnterWindow]) {
- EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
- python_callback(_callback[EventEnterWindow], (PyObject*)data);
- Py_DECREF((PyObject*)data);
- }
+ EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
+ Openbox::instance->bindings()->fireEvent(data);
+ Py_DECREF((PyObject*)data);
}
OtkEventHandler::leaveHandler(e);
// run the LEAVE python hook
- if (_callback[EventLeaveWindow]) {
- EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
- python_callback(_callback[EventLeaveWindow], (PyObject*)data);
- Py_DECREF((PyObject*)data);
- }
+ EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
+ Openbox::instance->bindings()->fireEvent(data);
+ Py_DECREF((PyObject*)data);
}
{
OtkEventHandler::mapRequestHandler(e);
- if (_callback[EventNewWindow]) {
- EventData *data = new_event_data(e.window, EventNewWindow, 0);
- python_callback(_callback[EventNewWindow], (PyObject*)data);
- Py_DECREF((PyObject*)data);
- }
+ EventData *data = new_event_data(e.window, EventNewWindow, 0);
+ Openbox::instance->bindings()->fireEvent(data);
+ Py_DECREF((PyObject*)data);
}
void OBActions::unmapHandler(const XUnmapEvent &e)
{
OtkEventHandler::unmapHandler(e);
- if (_callback[EventCloseWindow]) {
- EventData *data = new_event_data(e.window, EventCloseWindow, 0);
- python_callback(_callback[EventCloseWindow], (PyObject*)data);
- Py_DECREF((PyObject*)data);
- }
+ EventData *data = new_event_data(e.window, EventCloseWindow, 0);
+ Openbox::instance->bindings()->fireEvent(data);
+ Py_DECREF((PyObject*)data);
}
void OBActions::destroyHandler(const XDestroyWindowEvent &e)
{
OtkEventHandler::destroyHandler(e);
- if (_callback[EventCloseWindow]) {
- EventData *data = new_event_data(e.window, EventCloseWindow, 0);
- python_callback(_callback[EventCloseWindow], (PyObject*)data);
- Py_DECREF((PyObject*)data);
- }
-}
-
-bool OBActions::bind(EventAction action, PyObject *func)
-{
- if (action < 0 || action >= NUM_EVENTS) {
- return false;
- }
-
- Py_XDECREF(_callback[action]);
- _callback[action] = func;
- Py_INCREF(func);
- return true;
-}
-
-bool OBActions::unbind(EventAction action)
-{
- if (action < 0 || action >= NUM_EVENTS) {
- return false;
- }
-
- Py_XDECREF(_callback[action]);
- _callback[action] = 0;
- return true;
-}
-
-void OBActions::unbindAll()
-{
- for (int i = 0; i < NUM_EVENTS; ++i) {
- Py_XDECREF(_callback[i]);
- _callback[i] = 0;
- }
+ EventData *data = new_event_data(e.window, EventCloseWindow, 0);
+ Openbox::instance->bindings()->fireEvent(data);
+ Py_DECREF((PyObject*)data);
}
}
_timer.setTimeout(5000); // chains reset after 5 seconds
setResetKey("C-g"); // set the default reset key
+
+ for (int i = 0; i < NUM_EVENTS; ++i)
+ _events[i] = 0;
}
grabKeys(false);
removeAllKeys();
removeAllButtons();
+ removeAllEvents();
}
}
}
+
+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);
+}
+
}