put event bindings in OBBindings too
This commit is contained in:
parent
a0350e27b3
commit
a9a5f0d751
5 changed files with 71 additions and 70 deletions
|
@ -23,9 +23,6 @@ OBActions::OBActions()
|
||||||
{
|
{
|
||||||
for (int i=0; i<BUTTONS; ++i)
|
for (int i=0; i<BUTTONS; ++i)
|
||||||
_posqueue[i] = new ButtonPressAction();
|
_posqueue[i] = new ButtonPressAction();
|
||||||
|
|
||||||
for (int i = 0; i < NUM_EVENTS; ++i)
|
|
||||||
_callback[i] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,11 +147,9 @@ void OBActions::enterHandler(const XCrossingEvent &e)
|
||||||
OtkEventHandler::enterHandler(e);
|
OtkEventHandler::enterHandler(e);
|
||||||
|
|
||||||
// run the ENTER python hook
|
// run the ENTER python hook
|
||||||
if (_callback[EventEnterWindow]) {
|
EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
|
||||||
EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
|
Openbox::instance->bindings()->fireEvent(data);
|
||||||
python_callback(_callback[EventEnterWindow], (PyObject*)data);
|
Py_DECREF((PyObject*)data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,11 +158,9 @@ void OBActions::leaveHandler(const XCrossingEvent &e)
|
||||||
OtkEventHandler::leaveHandler(e);
|
OtkEventHandler::leaveHandler(e);
|
||||||
|
|
||||||
// run the LEAVE python hook
|
// run the LEAVE python hook
|
||||||
if (_callback[EventLeaveWindow]) {
|
EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
|
||||||
EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
|
Openbox::instance->bindings()->fireEvent(data);
|
||||||
python_callback(_callback[EventLeaveWindow], (PyObject*)data);
|
Py_DECREF((PyObject*)data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,64 +214,27 @@ void OBActions::mapRequestHandler(const XMapRequestEvent &e)
|
||||||
{
|
{
|
||||||
OtkEventHandler::mapRequestHandler(e);
|
OtkEventHandler::mapRequestHandler(e);
|
||||||
|
|
||||||
if (_callback[EventNewWindow]) {
|
EventData *data = new_event_data(e.window, EventNewWindow, 0);
|
||||||
EventData *data = new_event_data(e.window, EventNewWindow, 0);
|
Openbox::instance->bindings()->fireEvent(data);
|
||||||
python_callback(_callback[EventNewWindow], (PyObject*)data);
|
Py_DECREF((PyObject*)data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBActions::unmapHandler(const XUnmapEvent &e)
|
void OBActions::unmapHandler(const XUnmapEvent &e)
|
||||||
{
|
{
|
||||||
OtkEventHandler::unmapHandler(e);
|
OtkEventHandler::unmapHandler(e);
|
||||||
|
|
||||||
if (_callback[EventCloseWindow]) {
|
EventData *data = new_event_data(e.window, EventCloseWindow, 0);
|
||||||
EventData *data = new_event_data(e.window, EventCloseWindow, 0);
|
Openbox::instance->bindings()->fireEvent(data);
|
||||||
python_callback(_callback[EventCloseWindow], (PyObject*)data);
|
Py_DECREF((PyObject*)data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBActions::destroyHandler(const XDestroyWindowEvent &e)
|
void OBActions::destroyHandler(const XDestroyWindowEvent &e)
|
||||||
{
|
{
|
||||||
OtkEventHandler::destroyHandler(e);
|
OtkEventHandler::destroyHandler(e);
|
||||||
|
|
||||||
if (_callback[EventCloseWindow]) {
|
EventData *data = new_event_data(e.window, EventCloseWindow, 0);
|
||||||
EventData *data = new_event_data(e.window, EventCloseWindow, 0);
|
Openbox::instance->bindings()->fireEvent(data);
|
||||||
python_callback(_callback[EventCloseWindow], (PyObject*)data);
|
Py_DECREF((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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,6 @@ private:
|
||||||
void insertPress(const XButtonEvent &e);
|
void insertPress(const XButtonEvent &e);
|
||||||
void removePress(const XButtonEvent &e);
|
void removePress(const XButtonEvent &e);
|
||||||
|
|
||||||
PyObject *_callback[NUM_EVENTS];
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructs an OBActions object
|
//! Constructs an OBActions object
|
||||||
OBActions();
|
OBActions();
|
||||||
|
@ -82,14 +80,6 @@ public:
|
||||||
virtual void unmapHandler(const XUnmapEvent &e);
|
virtual void unmapHandler(const XUnmapEvent &e);
|
||||||
virtual void destroyHandler(const XDestroyWindowEvent &e);
|
virtual void destroyHandler(const XDestroyWindowEvent &e);
|
||||||
|
|
||||||
//! Bind a callback for an action
|
|
||||||
bool bind(EventAction action, PyObject *func);
|
|
||||||
|
|
||||||
//! Unbind the callback function from an action
|
|
||||||
bool unbind(EventAction action);
|
|
||||||
|
|
||||||
//! Remove all callback functions
|
|
||||||
void unbindAll();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,9 @@ OBBindings::OBBindings()
|
||||||
_timer.setTimeout(5000); // chains reset after 5 seconds
|
_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);
|
grabKeys(false);
|
||||||
removeAllKeys();
|
removeAllKeys();
|
||||||
removeAllButtons();
|
removeAllButtons();
|
||||||
|
removeAllEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -493,4 +497,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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,8 @@ private:
|
||||||
void grabButton(bool grab, const Binding &b, MouseContext context,
|
void grabButton(bool grab, const Binding &b, MouseContext context,
|
||||||
OBClient *client);
|
OBClient *client);
|
||||||
|
|
||||||
|
PyObject *_events[NUM_EVENTS];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Initializes an OBBindings object
|
//! Initializes an OBBindings object
|
||||||
OBBindings();
|
OBBindings();
|
||||||
|
@ -127,6 +129,17 @@ public:
|
||||||
void removeAllButtons();
|
void removeAllButtons();
|
||||||
|
|
||||||
void fireButton(ButtonData *data);
|
void fireButton(ButtonData *data);
|
||||||
|
|
||||||
|
//! Bind a callback for an event
|
||||||
|
bool addEvent(EventAction action, PyObject *callback);
|
||||||
|
|
||||||
|
//! Unbind the callback function from an event
|
||||||
|
bool removeEvent(EventAction action);
|
||||||
|
|
||||||
|
//! Remove all callback functions
|
||||||
|
void removeAllEvents();
|
||||||
|
|
||||||
|
void fireEvent(EventData *data);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,7 +455,7 @@ PyObject *ebind(ob::EventAction action, PyObject *func)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ob::Openbox::instance->actions()->bind(action, func)) {
|
if (!ob::Openbox::instance->bindings()->addEvent(action, func)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
|
PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue