]> Dogcows Code - chaz/openbox/commitdiff
put event bindings in OBBindings too
authorDana Jansens <danakj@orodu.net>
Fri, 3 Jan 2003 21:48:11 +0000 (21:48 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 3 Jan 2003 21:48:11 +0000 (21:48 +0000)
src/actions.cc
src/actions.hh
src/bindings.cc
src/bindings.hh
src/python.cc

index 00d4c1bffe8a5aaa65b87880f7e4dfd265293909..fba1eaf1f27f3694b177e2a92c5fc1115940d5c4 100644 (file)
@@ -23,9 +23,6 @@ OBActions::OBActions()
 {
   for (int i=0; i<BUTTONS; ++i)
     _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);
   
   // 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);
 }
 
 
@@ -163,11 +158,9 @@ void OBActions::leaveHandler(const XCrossingEvent &e)
   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);
 }
 
 
@@ -221,64 +214,27 @@ void OBActions::mapRequestHandler(const XMapRequestEvent &e)
 {
   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);
 }
 
 }
index 970a18a49ab32b14e23c2079b42bcc81ac910b4c..1da6e278c6afab4dc9c75d79b56e537290659f9f 100644 (file)
@@ -60,8 +60,6 @@ private:
   void insertPress(const XButtonEvent &e);
   void removePress(const XButtonEvent &e);
 
-  PyObject *_callback[NUM_EVENTS];
-
 public:
   //! Constructs an OBActions object
   OBActions();
@@ -82,14 +80,6 @@ public:
   virtual void unmapHandler(const XUnmapEvent &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();
 };
 
 }
index 2b81381c080925b48d15457531b150df9720a2d8..3df98da92056b77b320bb85f57b3331aeb487e52 100644 (file)
@@ -147,6 +147,9 @@ OBBindings::OBBindings()
   _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;
 }
 
 
@@ -155,6 +158,7 @@ OBBindings::~OBBindings()
   grabKeys(false);
   removeAllKeys();
   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);
+}
+
 }
index 71df301105343c8fc1eeaf8fe37bbde8c757fc9b..8e91b5b681323acb63fe4b48c39f2aca0d44a400 100644 (file)
@@ -84,6 +84,8 @@ private:
 
   void grabButton(bool grab, const Binding &b, MouseContext context,
                   OBClient *client);
+
+  PyObject *_events[NUM_EVENTS];
   
 public:
   //! Initializes an OBBindings object
@@ -127,6 +129,17 @@ public:
   void removeAllButtons();
 
   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);
 };
 
 }
index 4bddce8f63be59cd4d7ba47200f6d4d32640fa4f..e5224921a1ee327e36efea20899c3e7f81912460 100644 (file)
@@ -455,7 +455,7 @@ PyObject *ebind(ob::EventAction action, PyObject *func)
     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.");
     return NULL;
   }
This page took 0.028235 seconds and 4 git commands to generate.