From 4f01802c8cd0e0efc26896cf80e69dd9b6c06ec1 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 4 Dec 2002 07:12:13 +0000 Subject: [PATCH] actions class can sorta handle mouse enter/leave and press/release events --- otk/eventdispatcher.cc | 4 +- otk/rect.cc | 6 +++ otk/rect.hh | 8 +++ src/actions.cc | 109 +++++++++++++++++++++++++++++++++++++++++ src/actions.hh | 79 ++++++++++++++++++++++++++++- 5 files changed, 203 insertions(+), 3 deletions(-) diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc index 5be1c6b1..d2e1a96e 100644 --- a/otk/eventdispatcher.cc +++ b/otk/eventdispatcher.cc @@ -34,7 +34,7 @@ void OtkEventDispatcher::clearHandler(Window id) _map.erase(id); } -#include +//#include void OtkEventDispatcher::dispatchEvents(void) { XEvent e; @@ -44,7 +44,7 @@ void OtkEventDispatcher::dispatchEvents(void) while (XPending(OBDisplay::display)) { XNextEvent(OBDisplay::display, &e); -#ifdef DEBUG +#if defined(DEBUG) && 0 printf("Event %d window %lx\n", e.type, e.xany.window); #endif diff --git a/otk/rect.cc b/otk/rect.cc index 40d369e9..7ec5c2c4 100644 --- a/otk/rect.cc +++ b/otk/rect.cc @@ -136,6 +136,12 @@ bool Rect::contains(int x, int y) const } +bool Rect::contains(const Point &p) const +{ + return contains(p.x(), p.y()); +} + + bool Rect::contains(const Rect& a) const { return a._x1 >= _x1 && a._x2 <= _x2 && diff --git a/otk/rect.hh b/otk/rect.hh index 83c2b225..23ca0d12 100644 --- a/otk/rect.hh +++ b/otk/rect.hh @@ -213,6 +213,14 @@ public: @return true if the point is contained within this Rect; otherwise, false */ bool contains(int x, int y) const; + //! Determines if this Rect contains a point + /*! + The rectangle contains the point if it falls within the rectangle's + boundaries. + @param p The point to operate on + @return true if the point is contained within this Rect; otherwise, false + */ + bool contains(const Point &p) const; //! Determines if this Rect contains another Rect entirely /*! This rectangle contains the second rectangle if it is entirely within this diff --git a/src/actions.cc b/src/actions.cc index 2ee6bc57..35f53db4 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -6,10 +6,21 @@ #include "actions.hh" +#include + namespace ob { +const unsigned int OBActions::DOUBLECLICKDELAY; + 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 + } @@ -17,4 +28,102 @@ OBActions::~OBActions() { } + +void OBActions::insertPress(Window win, unsigned int button, Time time) +{ + MousePressAction *a = _presses[1]; + _presses[1] = _presses[0]; + _presses[0] = a; + a->win = win; + a->button = button; + a->time = time; +} + + +void OBActions::bpress(Window win, unsigned int modifiers, unsigned int button, + Time time) +{ + (void)modifiers; + // XXX: run the PRESS guile hook + printf("GUILE: PRESS: win %lx modifiers %ux button %ud time %lx", + (long)win, modifiers, button, time); + + if (_button) return; // won't count toward CLICK events + + _button = button; + + insertPress(win, button, time); +} + + +void OBActions::brelease(Window win, const otk::Rect &area, + const otk::Point &mpos, + unsigned int modifiers, unsigned int button, + Time time) +{ + (void)modifiers; + // XXX: run the RELEASE guile hook + printf("GUILE: RELEASE: win %lx modifiers %ux button %ud time %lx", + (long)win, modifiers, button, time); + + if (_button && _button != button) return; // not for the button we're watchin + + _button = 0; + + if (!area.contains(mpos)) return; // not on the window any more + + // XXX: run the CLICK guile hook + printf("GUILE: CLICK: win %lx modifiers %ux button %ud time %lx", + (long)win, modifiers, button, time); + + if (_presses[0]->win == _presses[1]->win && + _presses[0]->button == _presses[1]->button && + 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); + + } +} + + +void OBActions::enter(Window win, unsigned int modifiers) +{ + _enter_win = win; + + (void)modifiers; + // XXX: run the ENTER guile hook + printf("GUILE: ENTER: win %lx modifiers %ux", (long)win, modifiers); + +} + + +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); + + _enter_win = 0; +} + + +void OBActions::drag(Window win, otk::Point delta, unsigned int modifiers, + unsigned int button, Time time) +{ + (void)win;(void)delta;(void)modifiers;(void)button;(void)time; + + // XXX: some guile shit... +} + + +void OBActions::key(Window win, unsigned int modifiers, unsigned int keycode) +{ + (void)win;(void)modifiers;(void)keycode; + + // XXX: some guile shit... +} + + } diff --git a/src/actions.hh b/src/actions.hh index 1013e527..4c001be7 100644 --- a/src/actions.hh +++ b/src/actions.hh @@ -6,20 +6,97 @@ @brief The action interface for user-available actions */ +#include "otk/display.hh" +#include "otk/point.hh" +#include "otk/rect.hh" + namespace ob { //! The action interface for user-available actions /*! + When these actions are fired, hooks to the guile engine are fired so that + guile code is run. */ class OBActions { public: + struct MousePressAction { + Window win; + unsigned int button; + Time time; + MousePressAction() { win = 0; button = 0; time = 0; } + }; private: + // milliseconds XXX: config option + static const unsigned int DOUBLECLICKDELAY = 200; + + //! The last 2 button presses processed for CLICKs + /*! + Inserted such that index 0 is the latest action. + */ + MousePressAction *_presses[2]; + //! The mouse button currently being watched from a press for a CLICK + unsigned int _button; + //! The window the last enter action occured on (where the mouse is located) + Window _enter_win; + void insertPress(Window win, unsigned int button, Time time); + 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); + + //! 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. + /*! + @param win The window on which the action was performed. + @param modifiers The modifier state for the action. + */ + void enter(Window win, unsigned int modifiers); + + //! Notify that a mouse leave action has occured on a window. + /*! + @param modifiers The modifier state for the action. + */ + void leave(unsigned int modifiers); + + //! Notify that a mouse drag is taking place. + /*! + @param win The window the drag is on + @param delta The change in position of the mouse pointer + @param modifiers The modifier state during the drag. + */ + void drag(Window win, otk::Point delta, unsigned int modifiers, + unsigned int button, Time time); + + //! Notify that a key press has occured on a window. + /*! + @param win The window the key press was on + @param modifiers The modifier state for the action. + @param keycode The keycode of the key pressed. + */ + void key(Window win, unsigned int modifiers, unsigned int keycode); }; } -- 2.39.2