Make GetTickCount not use the whole Unix epoch (since 1970) any more,

since that crashed several games or caused problems with them as they
aren't used to a high Windows uptime of more than 24.9 days.
oldstable
Andreas Mohr 2000-09-22 22:37:56 +00:00 committed by Alexandre Julliard
parent 19f8dda01b
commit c941effc24
12 changed files with 56 additions and 14 deletions

View File

@ -10,6 +10,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include "ts_xlib.h" #include "ts_xlib.h"
#include "ts_xutil.h" #include "ts_xutil.h"
@ -40,6 +42,8 @@ unsigned int screen_height;
unsigned int screen_depth; unsigned int screen_depth;
Window root_window; Window root_window;
unsigned int X11DRV_server_startticks;
/*********************************************************************** /***********************************************************************
* error_handler * error_handler
*/ */
@ -50,6 +54,20 @@ static int error_handler(Display *display, XErrorEvent *error_evt)
} }
/***********************************************************************
* 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();
}
/*********************************************************************** /***********************************************************************
* setup_options * setup_options
* *
@ -216,6 +234,7 @@ static void process_attach(void)
{ {
WND_Driver = &X11DRV_WND_Driver; WND_Driver = &X11DRV_WND_Driver;
get_server_startup();
setup_options(); setup_options();
/* Open display */ /* Open display */

View File

@ -22,6 +22,7 @@ struct options
extern struct options Options; extern struct options Options;
extern const char *argv0; extern const char *argv0;
extern const char *full_argv0; extern const char *full_argv0;
extern unsigned int server_startticks;
extern void OPTIONS_Usage(void) WINE_NORETURN; extern void OPTIONS_Usage(void) WINE_NORETURN;
extern void OPTIONS_ParseOptions( char *argv[] ); extern void OPTIONS_ParseOptions( char *argv[] );

View File

@ -181,6 +181,7 @@ struct init_process_request
IN void* ldt_flags; /* addr of LDT flags */ IN void* ldt_flags; /* addr of LDT flags */
IN int ppid; /* parent Unix pid */ IN int ppid; /* parent Unix pid */
OUT int start_flags; /* flags from startup info */ OUT int start_flags; /* flags from startup info */
OUT unsigned int server_start; /* server start time (GetTickCount) */
OUT int exe_file; /* file handle for main exe */ OUT int exe_file; /* file handle for main exe */
OUT int hstdin; /* handle for stdin */ OUT int hstdin; /* handle for stdin */
OUT int hstdout; /* handle for stdout */ OUT int hstdout; /* handle for stdout */
@ -1586,7 +1587,7 @@ union generic_request
struct set_serial_info_request set_serial_info; struct set_serial_info_request set_serial_info;
}; };
#define SERVER_PROTOCOL_VERSION 22 #define SERVER_PROTOCOL_VERSION 23
/* ### make_requests end ### */ /* ### make_requests end ### */
/* Everything above this line is generated automatically by tools/make_requests */ /* Everything above this line is generated automatically by tools/make_requests */

View File

@ -83,6 +83,8 @@ extern GC BITMAP_monoGC, BITMAP_colorGC;
extern DeviceCaps X11DRV_DevCaps; extern DeviceCaps X11DRV_DevCaps;
extern unsigned int X11DRV_server_startticks;
/* Wine driver X11 functions */ /* Wine driver X11 functions */
extern const DC_FUNCTIONS X11DRV_DC_Funcs; extern const DC_FUNCTIONS X11DRV_DC_Funcs;
@ -288,7 +290,7 @@ void X11DRV_GDI_Finalize(void);
/* X11 GDI palette driver */ /* X11 GDI palette driver */
#define X11DRV_PALETTE_FIXED 0x0001 /* read-only colormap - have to use XAllocColor (if not virtual)*/ #define X11DRV_PALETTE_FIXED 0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
#define X11DRV_PALETTE_VIRTUAL 0x0002 /* no mapping needed - pixel == pixel color */ #define X11DRV_PALETTE_VIRTUAL 0x0002 /* no mapping needed - pixel == pixel color */
#define X11DRV_PALETTE_PRIVATE 0x1000 /* private colormap, identity mapping */ #define X11DRV_PALETTE_PRIVATE 0x1000 /* private colormap, identity mapping */

View File

@ -229,11 +229,11 @@ FARPROC16 WINAPI FileCDR16(FARPROC16 x)
* GetTickCount (USER.13) (KERNEL32.299) * GetTickCount (USER.13) (KERNEL32.299)
* *
* Returns the number of milliseconds, modulo 2^32, since the start * Returns the number of milliseconds, modulo 2^32, since the start
* of the current session. * of the wineserver.
*/ */
DWORD WINAPI GetTickCount(void) DWORD WINAPI GetTickCount(void)
{ {
struct timeval t; struct timeval t;
gettimeofday( &t, NULL ); gettimeofday( &t, NULL );
return (t.tv_sec * 1000) + (t.tv_usec / 1000); return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks;
} }

View File

@ -42,6 +42,7 @@ static char **main_exe_argv;
static char main_exe_name[MAX_PATH]; static char main_exe_name[MAX_PATH];
static HFILE main_exe_file = INVALID_HANDLE_VALUE; static HFILE main_exe_file = INVALID_HANDLE_VALUE;
unsigned int server_startticks;
/*********************************************************************** /***********************************************************************
* PROCESS_CallUserSignalProc * PROCESS_CallUserSignalProc
@ -198,6 +199,7 @@ static BOOL process_init( char *argv[] )
main_exe_name[len] = 0; main_exe_name[len] = 0;
main_exe_file = req->exe_file; main_exe_file = req->exe_file;
current_startupinfo.dwFlags = req->start_flags; current_startupinfo.dwFlags = req->start_flags;
server_startticks = req->server_start;
current_startupinfo.wShowWindow = req->cmd_show; current_startupinfo.wShowWindow = req->cmd_show;
current_envdb.hStdin = current_startupinfo.hStdInput = req->hstdin; current_envdb.hStdin = current_startupinfo.hStdInput = req->hstdin;
current_envdb.hStdout = current_startupinfo.hStdOutput = req->hstdout; current_envdb.hStdout = current_startupinfo.hStdOutput = req->hstdout;

View File

@ -21,6 +21,8 @@
int debug_level = 0; int debug_level = 0;
int persistent_server = 0; int persistent_server = 0;
unsigned int server_start_ticks = 0;
/* parse-line args */ /* parse-line args */
/* FIXME: should probably use getopt, and add a help option */ /* FIXME: should probably use getopt, and add a help option */
static void parse_args( int argc, char *argv[] ) static void parse_args( int argc, char *argv[] )
@ -68,6 +70,14 @@ static void signal_init(void)
signal( SIGABRT, sigterm_handler ); signal( SIGABRT, sigterm_handler );
} }
/* get server start ticks used to calculate GetTickCount() in Wine clients */
static void get_start_ticks(void)
{
struct timeval t;
gettimeofday( &t, NULL );
server_start_ticks = (t.tv_sec * 1000) + (t.tv_usec / 1000);
}
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
parse_args( argc, argv ); parse_args( argc, argv );
@ -76,6 +86,7 @@ int main( int argc, char *argv[] )
setvbuf( stderr, NULL, _IOLBF, 0 ); setvbuf( stderr, NULL, _IOLBF, 0 );
if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() ); if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
get_start_ticks();
init_registry(); init_registry();
select_loop(); select_loop();
close_registry(); close_registry();

View File

@ -181,9 +181,13 @@ extern void close_registry(void);
extern void close_atom_table(void); extern void close_atom_table(void);
/* global variables (command-line options) */ /* global variables */
/* command-line options */
extern int debug_level; extern int debug_level;
extern int persistent_server; extern int persistent_server;
/* server start time used for GetTickCount() */
extern unsigned int server_start_ticks;
#endif /* __WINE_SERVER_OBJECT_H */ #endif /* __WINE_SERVER_OBJECT_H */

View File

@ -275,6 +275,7 @@ static void init_process( int ppid, struct init_process_request *req )
req->cmd_show = 0; req->cmd_show = 0;
set_req_data_size( req, 0 ); set_req_data_size( req, 0 );
} }
req->server_start = server_start_ticks;
error: error:
} }

View File

@ -315,6 +315,7 @@ static void dump_init_process_request( const struct init_process_request *req )
static void dump_init_process_reply( const struct init_process_request *req ) static void dump_init_process_reply( const struct init_process_request *req )
{ {
fprintf( stderr, " start_flags=%d,", req->start_flags ); fprintf( stderr, " start_flags=%d,", req->start_flags );
fprintf( stderr, " server_start=%08x,", req->server_start );
fprintf( stderr, " exe_file=%d,", req->exe_file ); fprintf( stderr, " exe_file=%d,", req->exe_file );
fprintf( stderr, " hstdin=%d,", req->hstdin ); fprintf( stderr, " hstdin=%d,", req->hstdin );
fprintf( stderr, " hstdout=%d,", req->hstdout ); fprintf( stderr, " hstdout=%d,", req->hstdout );

View File

@ -717,12 +717,12 @@ static void EVENT_MotionNotify( HWND hWnd, XMotionEvent *event )
X11DRV_SendEvent( MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, X11DRV_SendEvent( MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE,
xOffset + event->x, yOffset + event->y, xOffset + event->x, yOffset + event->y,
X11DRV_EVENT_XStateToKeyState( event->state ), X11DRV_EVENT_XStateToKeyState( event->state ),
event->time, hWnd); event->time - X11DRV_server_startticks, hWnd);
} else { } else {
X11DRV_SendEvent( MOUSEEVENTF_MOVE, X11DRV_SendEvent( MOUSEEVENTF_MOVE,
event->x_root, event->y_root, event->x_root, event->y_root,
X11DRV_EVENT_XStateToKeyState( event->state ), X11DRV_EVENT_XStateToKeyState( event->state ),
event->time, hWnd); event->time - X11DRV_server_startticks, hWnd);
} }
} }
@ -776,7 +776,7 @@ static void EVENT_ButtonPress( HWND hWnd, XButtonEvent *event )
X11DRV_SendEvent( statusCodes[buttonNum], X11DRV_SendEvent( statusCodes[buttonNum],
xOffset + event->x, yOffset + event->y, xOffset + event->x, yOffset + event->y,
MAKEWPARAM(keystate,wData), MAKEWPARAM(keystate,wData),
event->time, hWnd); event->time - X11DRV_server_startticks, hWnd);
} }
@ -823,7 +823,7 @@ static void EVENT_ButtonRelease( HWND hWnd, XButtonEvent *event )
X11DRV_SendEvent( statusCodes[buttonNum], X11DRV_SendEvent( statusCodes[buttonNum],
xOffset + event->x, yOffset + event->y, xOffset + event->x, yOffset + event->y,
keystate, event->time, hWnd); keystate, event->time - X11DRV_server_startticks, hWnd);
} }
@ -1942,7 +1942,7 @@ static void EVENT_DGAMotionEvent( XDGAMotionEvent *event )
X11DRV_SendEvent( MOUSEEVENTF_MOVE, X11DRV_SendEvent( MOUSEEVENTF_MOVE,
event->dx, event->dy, event->dx, event->dy,
X11DRV_EVENT_XStateToKeyState( event->state ), X11DRV_EVENT_XStateToKeyState( event->state ),
event->time, DGAhwnd ); event->time - X11DRV_server_startticks, DGAhwnd );
} }
static void EVENT_DGAButtonPressEvent( XDGAButtonEvent *event ) static void EVENT_DGAButtonPressEvent( XDGAButtonEvent *event )
@ -1970,7 +1970,7 @@ static void EVENT_DGAButtonPressEvent( XDGAButtonEvent *event )
break; break;
} }
X11DRV_SendEvent( statusCodes[buttonNum], 0, 0, keystate, event->time, DGAhwnd ); X11DRV_SendEvent( statusCodes[buttonNum], 0, 0, keystate, event->time - X11DRV_server_startticks, DGAhwnd );
} }
static void EVENT_DGAButtonReleaseEvent( XDGAButtonEvent *event ) static void EVENT_DGAButtonReleaseEvent( XDGAButtonEvent *event )
@ -1998,7 +1998,7 @@ static void EVENT_DGAButtonReleaseEvent( XDGAButtonEvent *event )
break; break;
} }
X11DRV_SendEvent( statusCodes[buttonNum], 0, 0, keystate, event->time, DGAhwnd ); X11DRV_SendEvent( statusCodes[buttonNum], 0, 0, keystate, event->time - X11DRV_server_startticks, DGAhwnd );
} }
#endif #endif

View File

@ -606,7 +606,7 @@ void X11DRV_KEYBOARD_HandleEvent( WND *pWnd, XKeyEvent *event )
INT event_x = (pWnd? pWnd->rectWindow.left : 0) + event->x; INT event_x = (pWnd? pWnd->rectWindow.left : 0) + event->x;
INT event_y = (pWnd? pWnd->rectWindow.top : 0) + event->y; INT event_y = (pWnd? pWnd->rectWindow.top : 0) + event->y;
DWORD event_time = event->time; DWORD event_time = event->time - X11DRV_server_startticks;
/* this allows support for dead keys */ /* this allows support for dead keys */
if ((event->keycode >> 8) == 0x10) if ((event->keycode >> 8) == 0x10)
@ -614,7 +614,7 @@ void X11DRV_KEYBOARD_HandleEvent( WND *pWnd, XKeyEvent *event )
ascii_chars = TSXLookupString(event, Str, 1, &keysym, &cs); ascii_chars = TSXLookupString(event, Str, 1, &keysym, &cs);
TRACE_(key)("EVENT_key : state = %X\n", event->state); TRACE_(key)("state = %X\n", event->state);
/* If XKB extensions is used, the state mask for AltGr will used the group /* If XKB extensions is used, the state mask for AltGr will used the group
index instead of the modifier mask. The group index is set in bits index instead of the modifier mask. The group index is set in bits