Re: distinguishing double click and single click and drag
Ah yes, I do seem to recall this sort of approach some time ago.
I haven't had a chance to play with it yet, but I think this will do
the trick; thank you!
My next question may be (and I'll ask it explicitly if it comes up)
is whether there's a nice way to encode these in terms of the
capi:define-command? It seems that the commands provide a
nice abstraction for some of things, e.g., if I decide to use
ctrl-shift-x-button-1-second-press instead of something else
to make a selection later, I can just change the capi:define-command
and leave :make-selection in the input model. It seems awkward
if conceptually distinct gestures, e.g., double-click, single-click,
etc., could be thrown into the mix, but maybe that's not feasible.
We'll see if I get there. ^_^
Thanks!
On 12/29/06, Paul Tarvydas <tarvydas@visualframeworksinc.com> wrote:
> On Friday 29 December 2006 11:41 am, Taylor, Joshua wrote:
> > I'd like to have an input model which does one action on a double click,
> > and a different action after a single-click -> drag -> release. I need to
> > record the starting point of the drag, which I think would be a :press, but
> > whatever I specify to happen on the :press gets invoked when I try to
> > double click. I hope it doesn't make a difference, but I'm on LWM 4.4.6.
> > How does one distinguish between a single and double click? I know about
> > :press and
> >
> > :second-press, but with
> >
> > (:button-1 :press) foo
> > (:button-1 :second-press) bar
> > If I double click (or try to) foo gets called. Thoughts?
>
> My recollection might be rusty, but I think that :second-press comes
> after :press. So, when a double-click happens, you see :press
> then :second-press then :release. When a click-drag happens, you see :press
> followed by one or more :motions followed by :release.
>
> The best way to think about this problem is to use a state machine, which I
> will sketch using an impromptu textual language:
>
> state-machine MOUSE-TRACKER:
>
> state IDLE:
> on :press execute 'save-mouse-coordinates and goto-state PRESSED
> otherwise ignore
> end state
>
> state PRESSED:
> on :release execute 'clicked and goto-state IDLE
> on :second-press execute 'double-click and goto-state IDLE
> on :motion execute 'relative-motion and goto-state DRAGGING
> otherwise ignore
> end state
>
> state DRAGGING:
> on :release execute 'finalize-drag and goto-state IDLE
> on :motion execute 'relative-motion and goto-state DRAGGING
> otherwise ignore
> end state
>
> end state-machine
>
> A much better way to do this is to draw the state machine on paper - use one
> circle / oval for each state, and transitions (goto-state) are drawn as
> arrows from one state bubble to another. You won't regret going to the
> trouble of drawing out the state diagram when you try to incorporate all of
> the other mouse actions and buttons into your mouse-handling code.
>
> pt
>
>
--
=====================
Joshua Taylor
tayloj@rpi.edu
"A lot of good things went down one time,
back in the goodle days."
John Hartford