[comp.windows.x] Detecting a double-click

kdoshi@oracle.com (Ketan Doshi) (09/28/90)

Is there a general way to detect a double-click in a window ?

I want to be able to distinguish between 3 things the user can do.
viz. 

a) Button press, drag and release.
b) Single click.
c) Double click.

Let's say I need to take actions A, B and C in the 3 cases,
respectively. Now, if I receive a click, I don't know whether it is a
single-click (and should perform action B) or the first click of a
double-click (and should perorm action C).

I hope I was able to explain this properly. Any advice?

Thanks,

Ketan Doshi.




--
#########################################################################
Ketan Doshi						kdoshi@oracle.com
Oracle Corp						(415) 506-6239
Tools and User Interfaces
#########################################################################

schoch@trident.arc.nasa.gov (Steve Schoch) (09/29/90)

In article <KDOSHI.90Sep27114058@ketan.oracle.com>, kdoshi@oracle.com (Ketan Doshi) writes:
|> 
|> a) Button press, drag and release.
|> b) Single click.
|> c) Double click.
|> 
|>  Now, if I receive a click, I don't know whether it is a
|> single-click (and should perform action B) or the first click of a
|> double-click (and should perorm action C).

In most applications (like on the Mac, for instance), action B is something
simple, like hilighting an icon.  It doesn't matter if action B has already
been done when you do action A or action C.

Thus when you get the first event, do action B and save the keyButtonPointer.time
and the current position.

If the next event is another button press, check it's time and see if it's
within the "double-click-time" of the saved time.

If the next event is a motion event, check to see if it's position is
enough different from the saved position to make it a drag.  (Like "delta"
in uwm.) 

mouse@LARRY.MCRCIM.MCGILL.EDU (10/01/90)

> Is there a general way to detect a double-click in a window ?

No.

> I want to be able to distinguish between 3 things the user can do.

> a) Button press, drag and release.
> b) Single click.
> c) Double click.

> Let's say I need to take actions A, B and C in the 3 cases,
> respectively.  Now, if I receive a click, I don't know whether it is
> a single-click (and should perform action B) or the first click of a
> double-click (and should perorm action C).

That's right, you don't.  X does not provide the tools to do proper
double-click recognition; I am hoping that R5 will improve this.  At
present you have to either (i) make sure that action B can be undone or
subsumed into action C or (ii) do the timing for double-click detection
in the client and hope network delays don't bite you.

There are many possible solutions, of varying degrees of generality and
usefulness; the one I currently prefer is some way to ask the server to
send a timeout event following each other event after some delay.  Some
of the variable factors would be what types of events timeouts can be
requested for, how the timeout is specified (globally, per event type,
per client, etc), what (if any) other events occurring in the interim
will suppress the timeout event, etc.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

msm@src.dec.com (Mark S. Manasse) (10/21/90)

It's not quite true that you can't do this with the existing protocol.  You
could set a time to some appropriate timeout value (which you might need
to precompute by guessing at the round-trip latency to the server).  You
could then cancel that timer if you get a subsequent event from the
server; if you don't, then, upon expiration of the timer, send some query
to the server.  If there are no events in your queue at that point, you
know it's not a double-click.

If the round-trip latency exceeds your double-click timeout, you'll wind
up waiting longer than you ought to to respond, but that's a bad situation
to be in anyhow.  If it's shorter, you can set your timer to some value
that allows you to keep probing the server until the server's idea of time
exceeds the allowed double-click, if you want to get fussy (at least in R4
you can do this).  While it might be simpler to ask the server to run the
timer for you, you can do destructive double-click detection if you really
want.

Mark