Problem with function GetTimeInMillis

Elmar Krieger elmar at cmbi.ru.nl
Fri Aug 21 23:32:03 PDT 2009


Dear all,

my application depends critically on knowing how long a certain mouse 
button has been pressed so far.

The only way I found to obtain this information: Get the current time 
and subtract the timestamp of the initial button press event 
(XButtonEvent.time).

Unfortunately, the current time is returned by function GetTimeInMillis, 
and this function is private and not exported in the Xlibs for unknown 
reasons, so my application cannot call it.

The simple hack was to just look up GetTimeInMillis in the Xorg code and 
duplicate it in my own application:

CARD32 GetTimeInMillis(void)
{
   struct timeval tp;

   gettimeofday(&tp,(struct timezone*)0);
   return((tp.tv_sec*1000)+(tp.tv_usec/1000)); }


This worked well, until some time ago, someone changed Xorg's 
GetTimeInMillis. It now reads...


CARD32
GetTimeInMillis(void)
{
     struct timeval  tp;
     register CARD32 val;
     register INT32 diff;
     static CARD32 oldval = 0;
     static CARD32 time = 0;

     X_GETTIMEOFDAY(&tp);
     val = (tp.tv_sec * 1000) + (tp.tv_usec / 1000);
     if (oldval) {
         diff = val - oldval;
         if (diff > 0)
             time += diff;
     }
     oldval = val;

     return time;
}


This now puts the returned time on a relative scale to the first call of 
the function, which makes it essentially impossible to duplicate in my 
own application.

Since I'm now screwed completely, you guys are my last hope...
Does anyone have a clever idea what to do? Any tricky way to indirectly 
call GetTimeInMillis and deliver the result to my application? Or any 
more 'official' way to determine how long a mouse button has been 
pressed so far?

Many thanks for your time and help,
Elmar




More information about the xorg-devel mailing list