diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c index aa0ea81469c..4bcb35ba832 100644 --- a/dlls/x11drv/event.c +++ b/dlls/x11drv/event.c @@ -187,6 +187,40 @@ DWORD X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, return ret; } +/*********************************************************************** + * EVENT_x11_time_to_win32_time + * + * Make our timer and the X timer line up as best we can + * Pass 0 to retrieve the current adjustment value (times -1) + */ +DWORD EVENT_x11_time_to_win32_time(Time time) +{ + static DWORD adjust = 0; + DWORD now = GetTickCount(); + DWORD ret; + + if (! adjust && time != 0) + { + ret = now; + adjust = time - now; + } + else + { + /* If we got an event in the 'future', then our clock is clearly wrong. + If we got it more than 10000 ms in the future, then it's most likely + that the clock has wrapped. */ + + ret = time - adjust; + if (ret > now && ((ret - now) < 10000) && time != 0) + { + adjust += ret - now; + ret -= ret - now; + } + } + + return ret; + +} /*********************************************************************** * EVENT_ProcessEvent diff --git a/dlls/x11drv/keyboard.c b/dlls/x11drv/keyboard.c index 9047f17b038..900f2ec292e 100644 --- a/dlls/x11drv/keyboard.c +++ b/dlls/x11drv/keyboard.c @@ -1103,7 +1103,7 @@ void X11DRV_KeyEvent( HWND hwnd, XKeyEvent *event ) DWORD dwFlags; int ascii_chars; XIC xic = X11DRV_get_ic( hwnd ); - DWORD event_time = event->time - X11DRV_server_startticks; + DWORD event_time = EVENT_x11_time_to_win32_time(event->time); Status status = 0; TRACE_(key)("type %d, window %lx, state 0x%04x, keycode 0x%04x\n", diff --git a/dlls/x11drv/mouse.c b/dlls/x11drv/mouse.c index 120e142918f..9d5bb4016cb 100644 --- a/dlls/x11drv/mouse.c +++ b/dlls/x11drv/mouse.c @@ -141,7 +141,7 @@ static void send_mouse_event( HWND hwnd, DWORD flags, DWORD posX, DWORD posY, input.u.mi.dy = posY; input.u.mi.mouseData = data; input.u.mi.dwFlags = flags; - input.u.mi.time = time - X11DRV_server_startticks; + input.u.mi.time = EVENT_x11_time_to_win32_time(time); input.u.mi.dwExtraInfo = (ULONG_PTR)hwnd; SendInput( 1, &input, sizeof(input) ); } diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c index 34acea9c0dc..70979f02a10 100644 --- a/dlls/x11drv/window.c +++ b/dlls/x11drv/window.c @@ -1317,7 +1317,8 @@ void X11DRV_SetFocus( HWND hwnd ) /* we must not use CurrentTime (ICCCM), so try to use last message time instead */ /* FIXME: this is not entirely correct */ XSetInputFocus( display, win, RevertToParent, - /*CurrentTime*/ GetMessageTime() + X11DRV_server_startticks ); + /* CurrentTime */ + GetMessageTime() - EVENT_x11_time_to_win32_time(0)); if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE) XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap ); } diff --git a/dlls/x11drv/wintab.c b/dlls/x11drv/wintab.c index e0827b79f61..ea4ab0b28cc 100644 --- a/dlls/x11drv/wintab.c +++ b/dlls/x11drv/wintab.c @@ -598,7 +598,7 @@ int X11DRV_ProcessTabletEvent(HWND hwnd, XEvent *event) TRACE_(event)("Received tablet motion event (%p)\n",hwnd); TRACE("Received tablet motion event (%p)\n",hwnd); - gMsgPacket.pkTime = motion->time; + gMsgPacket.pkTime = EVENT_x11_time_to_win32_time(motion->time); gMsgPacket.pkSerialNumber = gSerial++; gMsgPacket.pkCursor = motion->deviceid; gMsgPacket.pkX = motion->axis_data[0]; diff --git a/dlls/x11drv/x11drv.h b/dlls/x11drv/x11drv.h index 42c3494a2ef..80a92a12268 100644 --- a/dlls/x11drv/x11drv.h +++ b/dlls/x11drv/x11drv.h @@ -110,8 +110,6 @@ extern Pixmap BITMAP_stock_pixmap; /* pixmap for the default stock bitmap */ #define BITMAP_GC(bmp) \ (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC) -extern unsigned int X11DRV_server_startticks; - /* Wine driver X11 functions */ extern BOOL X11DRV_AlphaBlend( X11DRV_PDEVICE *physDevDst, INT xDst, INT yDst, @@ -504,6 +502,7 @@ extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type); void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ; #endif +extern DWORD EVENT_x11_time_to_win32_time(Time time); extern int X11DRV_ProcessTabletEvent(HWND hwnd, XEvent *event); /* x11drv private window data */ diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c index aa1c7849ecb..68d39b4b50a 100644 --- a/dlls/x11drv/x11drv_main.c +++ b/dlls/x11drv/x11drv_main.c @@ -98,8 +98,6 @@ int client_side_antialias_with_core = 1; int client_side_antialias_with_render = 1; int using_wine_desktop = 0; -unsigned int X11DRV_server_startticks; - static BOOL synchronous; /* run in synchronous mode? */ static BOOL desktop_dbl_buf = TRUE; static char *desktop_geometry; @@ -214,19 +212,6 @@ void wine_tsx11_unlock(void) LeaveCriticalSection( &X11DRV_CritSection ); } -/*********************************************************************** - * get_server_startup - * - * Get the server startup time - * Won't be exact, but should be sufficient - */ -static void get_server_startup(void) -{ - struct timeval t; - gettimeofday( &t, NULL ); - X11DRV_server_startticks = ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - GetTickCount(); -} - /*********************************************************************** * get_config_key @@ -341,7 +326,6 @@ static BOOL process_attach(void) { Display *display; - get_server_startup(); setup_options(); /* Open display */