Re: [gtk-list] Re: 2 button press



> void handle_click( GtkWidget *widget, GdkEventButton *event )
[...]
>    if( lastClicked == NULL_TIME )
>       lastClicked = GetTime();
[...]
>       if( ValidDoubleClick( lastClicked ) )
> 	 g_print( "Double-click.\n" );
[...]
>       lastClicked = GetTime();

This is OK (well, *nearly* OK) on a single-user system like an Amiga
or a PC, but not on a multi-tasking system like *N*X. If you try to make
the application code use the 'time now' to evaluate the delay between
button press/release events, you can get indeterminate results.

After the X server has delivered the button press event, you must then
wait for the kernel to schedule your process before you get the chance
to examine the current time. There is *no guarantee* that your process
will be scheduled immediately. There may be a delay of several milliseconds,
particularly if the system is busy, which would defeat your calculation
of the time between the two events.

Similarly, a scheduling delay might make your application erroneously
interpret two clicks as a double-click, if it (the application) doesn't
get scheduled until after the second click has been queued by the server.

The way to do it (without examining the source code, I assume that GTK
does it this way) is to make the toolkit (i.e. GTK) calculate the time
between the events, based on the timestamp which the X server puts in
the event structure.

Allan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]