]> Dogcows Code - chaz/openbox/commitdiff
button press/releases WORK
authorDana Jansens <danakj@orodu.net>
Wed, 4 Dec 2002 07:55:52 +0000 (07:55 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 4 Dec 2002 07:55:52 +0000 (07:55 +0000)
otk/eventdispatcher.cc
otk/eventdispatcher.hh
src/actions.cc
src/actions.hh
src/openbox.cc

index d2e1a96eb20554f2cace1ae43164e2ee4b07c38b..a34dd9b4dd4575eed3574e4db06837e2f8539037 100644 (file)
@@ -11,7 +11,7 @@
 namespace otk {
 
 OtkEventDispatcher::OtkEventDispatcher()
-  : _fallback(0)
+  : _fallback(0), _master(0)
 {
 }
 
@@ -57,6 +57,9 @@ void OtkEventDispatcher::dispatchEvents(void)
 
     if (handler)
       handler->handle(e);
+
+    if (_master)
+      _master->handle(e);
   }
 }
 
index 28741d95bff9d942d46689501a371385824e0c92..b56445a4bbda18d3da599ebcabf09f505254d606 100644 (file)
@@ -24,9 +24,16 @@ public:
   { _fallback = fallback; }
   OtkEventHandler *getFallbackHandler(void) const { return _fallback; }
 
+  //! Sets an event handler that gets all events for all handlers after
+  //! any specific handlers have received them
+  inline void setMasterHandler(OtkEventHandler *master)
+  { _master = master; }
+  OtkEventHandler *getMasterHandler(void) const { return _master; }
+  
 private:
   OtkEventMap _map;
   OtkEventHandler *_fallback;
+  OtkEventHandler *_master;
 
   //! The time at which the last XEvent with a time was received
   Time _lasttime; // XXX: store this! also provide an accessor!
index 35f53db4719eb2004615e9f413f457085dbfff87..6750cc58e7dd02469753eafdff70adf2777c12be 100644 (file)
 
 namespace ob {
 
-const unsigned int OBActions::DOUBLECLICKDELAY;
+const unsigned int OBActions::DOUBLECLICKDELAY = 300;
 
 OBActions::OBActions()
   : _button(0), _enter_win(0)
 {
   _presses[0] = new MousePressAction();
   _presses[1] = new MousePressAction();
-  _presses[2] = new MousePressAction();
 
   // XXX: load a configuration out of somewhere
 
@@ -40,49 +39,51 @@ void OBActions::insertPress(Window win, unsigned int button, Time time)
 }
 
 
-void OBActions::bpress(Window win, unsigned int modifiers, unsigned int button,
-                       Time time)
+void OBActions::buttonPressHandler(const XButtonEvent &e)
 {
-  (void)modifiers;
   // XXX: run the PRESS guile hook
-  printf("GUILE: PRESS: win %lx modifiers %ux button %ud time %lx",
-         (long)win, modifiers, button, time);
+  printf("GUILE: PRESS: win %lx modifiers %u button %u time %lx\n",
+         (long)e.window, e.state, e.button, e.time);
     
   if (_button) return; // won't count toward CLICK events
 
-  _button = button;
+  _button = e.button;
 
-  insertPress(win, button, time);
+  insertPress(e.window, e.button, e.time);
 }
   
 
-void OBActions::brelease(Window win, const otk::Rect &area,
-                         const otk::Point &mpos, 
-                         unsigned int modifiers, unsigned int button,
-                         Time time)
+void OBActions::buttonReleaseHandler(const XButtonEvent &e)
 {
-  (void)modifiers;
   // XXX: run the RELEASE guile hook
-  printf("GUILE: RELEASE: win %lx modifiers %ux button %ud time %lx",
-         (long)win, modifiers, button, time);
+  printf("GUILE: RELEASE: win %lx modifiers %u button %u time %lx\n",
+         (long)e.window, e.state, e.button, e.time);
 
-  if (_button && _button != button) return; // not for the button we're watchin
+  // not for the button we're watching?
+  if (_button && _button != e.button) return;
 
   _button = 0;
 
-  if (!area.contains(mpos)) return; // not on the window any more
+  // find the area of the window
+  XWindowAttributes attr;
+  if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
+
+  // if not on the window any more, it isnt a CLICK
+  if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
+        e.x < attr.width && e.y < attr.height))
+    return;
 
   // XXX: run the CLICK guile hook
-  printf("GUILE: CLICK: win %lx modifiers %ux button %ud time %lx",
-         (long)win, modifiers, button, time);
+  printf("GUILE: CLICK: win %lx modifiers %u button %u time %lx\n",
+         (long)e.window, e.state, e.button, e.time);
 
   if (_presses[0]->win == _presses[1]->win &&
       _presses[0]->button == _presses[1]->button &&
-      time - _presses[1]->time < DOUBLECLICKDELAY) {
+      e.time - _presses[1]->time < DOUBLECLICKDELAY) {
 
     // XXX: run the DOUBLECLICK guile hook
-    printf("GUILE: DOUBLECLICK: win %lx modifiers %ux button %ud time %lx",
-           (long)win, modifiers, button, time);
+    printf("GUILE: DOUBLECLICK: win %lx modifiers %u button %u time %lx\n",
+           (long)e.window, e.state, e.button, e.time);
 
   }
 }
@@ -94,7 +95,7 @@ void OBActions::enter(Window win, unsigned int modifiers)
 
   (void)modifiers;
   // XXX: run the ENTER guile hook
-  printf("GUILE: ENTER: win %lx modifiers %ux", (long)win, modifiers);
+  printf("GUILE: ENTER: win %lx modifiers %u\n", (long)win, modifiers);
 
 }
 
@@ -103,7 +104,7 @@ void OBActions::leave(unsigned int modifiers)
 {
   (void)modifiers;
   // XXX: run the LEAVE guile hook
-  printf("GUILE: LEAVE: win %lx modifiers %ux", (long)_enter_win, modifiers);
+  printf("GUILE: LEAVE: win %lx modifiers %u\n", (long)_enter_win, modifiers);
 
   _enter_win = 0;
 }
index 4c001be716aab2feb49745f896bcffa55f0aac14..924a8dc0c29bfe5307dc65b612334ee80b8cd215 100644 (file)
@@ -9,6 +9,7 @@
 #include "otk/display.hh"
 #include "otk/point.hh"
 #include "otk/rect.hh"
+#include "otk/eventhandler.hh"
 
 namespace ob {
 
@@ -17,7 +18,7 @@ namespace ob {
   When these actions are fired, hooks to the guile engine are fired so that
   guile code is run.
 */
-class OBActions {
+class OBActions : public otk::OtkEventHandler {
 public:
   struct MousePressAction {
     Window win;
@@ -28,7 +29,7 @@ public:
   
 private:
   // milliseconds XXX: config option
-  static const unsigned int DOUBLECLICKDELAY = 200;
+  static const unsigned int DOUBLECLICKDELAY;
   
   //! The last 2 button presses processed for CLICKs
   /*!
@@ -46,27 +47,11 @@ public:
   OBActions();
   virtual ~OBActions();
 
-  //! Notify that a mouse button press has occured on a window.
-  /*!
-    @param win The window on which the action was performed.
-    @param modifiers The modifier state for the action.
-    @param button The mouse button the action is for.
-    @param time The time at which the event occured (from the XEvent).
-  */
-  void bpress(Window win, unsigned int modifiers, unsigned int button,
-              Time time);
+  virtual void buttonPressHandler(const XButtonEvent &e);
+  virtual void buttonReleaseHandler(const XButtonEvent &e);
+  
+
 
-  //! Notify that a mouse button release has occured on a window.
-  /*!
-    @param win The window on which the action was performed.
-    @param area The area of the window on which the action was performed.
-    @param mpos The position of the mouse pointer relative to the root window.
-    @param modifiers The modifier state for the action.
-    @param button The mouse button the action is for.
-    @param time The time at which the event occured (from the XEvent).
-  */
-  void brelease(Window win, const otk::Rect &area, const otk::Point &mpos,
-                unsigned int modifiers, unsigned int button, Time time);
 
   //! Notify that a mouse enter action has occured on a window.
   /*!
index d95de520ed3530e97a2c001e3d76c48de47f45dc..24ea9b2e07c75a7749b4c4f3df8d7f7d38f64b0a 100644 (file)
@@ -126,6 +126,8 @@ Openbox::Openbox(int argc, char **argv)
 
   Openbox::actions = new OBActions();
 
+  setMasterHandler(Openbox::actions); // set as the master event handler
+
   // create the mouse cursors we'll use
   _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
   _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
This page took 0.032003 seconds and 4 git commands to generate.