better double click processing

This commit is contained in:
Dana Jansens 2002-12-04 08:12:09 +00:00
parent 0a15728be4
commit 90ae66cc44
2 changed files with 16 additions and 26 deletions

View file

@ -15,8 +15,6 @@ const unsigned int OBActions::DOUBLECLICKDELAY = 300;
OBActions::OBActions() OBActions::OBActions()
: _button(0), _enter_win(0) : _button(0), _enter_win(0)
{ {
for (int i = 0; i < 2; ++i)
_presses[i] = new MousePressAction();
// XXX: load a configuration out of somewhere // XXX: load a configuration out of somewhere
@ -28,17 +26,6 @@ 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::buttonPressHandler(const XButtonEvent &e) void OBActions::buttonPressHandler(const XButtonEvent &e)
{ {
// XXX: run the PRESS guile hook // XXX: run the PRESS guile hook
@ -48,8 +35,6 @@ void OBActions::buttonPressHandler(const XButtonEvent &e)
if (_button) return; // won't count toward CLICK events if (_button) return; // won't count toward CLICK events
_button = e.button; _button = e.button;
insertPress(e.window, e.button, e.time);
} }
@ -60,7 +45,7 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e)
(long)e.window, e.state, e.button, e.time); (long)e.window, e.state, e.button, e.time);
// not for the button we're watching? // not for the button we're watching?
if (_button && _button != e.button) return; if (_button != e.button) return;
_button = 0; _button = 0;
@ -77,14 +62,22 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e)
printf("GUILE: CLICK: win %lx modifiers %u button %u time %lx\n", printf("GUILE: CLICK: win %lx modifiers %u button %u time %lx\n",
(long)e.window, e.state, e.button, e.time); (long)e.window, e.state, e.button, e.time);
if (_presses[0]->win == _presses[1]->win && if (e.time - _release.time < DOUBLECLICKDELAY &&
_presses[0]->button == _presses[1]->button && _release.win == e.window && _release.button == e.button) {
e.time - _presses[1]->time < DOUBLECLICKDELAY) {
// XXX: run the DOUBLECLICK guile hook // XXX: run the DOUBLECLICK guile hook
printf("GUILE: DOUBLECLICK: win %lx modifiers %u button %u time %lx\n", printf("GUILE: DOUBLECLICK: win %lx modifiers %u button %u time %lx\n",
(long)e.window, e.state, e.button, e.time); (long)e.window, e.state, e.button, e.time);
// reset so you cant triple click for 2 doubleclicks
_release.win = 0;
_release.button = 0;
_release.time = 0;
} else {
// save the button release, might be part of a double click
_release.win = e.window;
_release.button = e.button;
_release.time = e.time;
} }
} }

View file

@ -20,22 +20,19 @@ namespace ob {
*/ */
class OBActions : public otk::OtkEventHandler { class OBActions : public otk::OtkEventHandler {
public: public:
struct MousePressAction { struct MouseButtonAction {
Window win; Window win;
unsigned int button; unsigned int button;
Time time; Time time;
MousePressAction() { win = 0; button = 0; time = 0; } MouseButtonAction() { win = 0; button = 0; time = 0; }
}; };
private: private:
// milliseconds XXX: config option // milliseconds XXX: config option
static const unsigned int DOUBLECLICKDELAY; static const unsigned int DOUBLECLICKDELAY;
//! The last 2 button presses processed for CLICKs //! The last 2 button release processed for CLICKs
/*! MouseButtonAction _release;
Inserted such that index 0 is the latest action.
*/
MousePressAction *_presses[2];
//! The mouse button currently being watched from a press for a CLICK //! The mouse button currently being watched from a press for a CLICK
unsigned int _button; unsigned int _button;
//! The window the last enter action occured on (where the mouse is located) //! The window the last enter action occured on (where the mouse is located)