user32: Move key state cache into a separate struct.

This commit is contained in:
Sebastian Lackner 2015-04-07 02:33:28 +02:00 committed by Alexandre Julliard
parent 4eff187961
commit 325c061bbd
5 changed files with 32 additions and 15 deletions

View File

@ -437,7 +437,10 @@ static LRESULT call_hook( struct hook_info *info, INT code, WPARAM wparam, LPARA
}
if (info->id == WH_KEYBOARD_LL || info->id == WH_MOUSE_LL)
get_user_thread_info()->key_state_time = 0; /* force refreshing the key state cache */
{
struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
if (key_state_info) key_state_info->time = 0; /* force refreshing the key state cache */
}
return ret;
}

View File

@ -368,7 +368,7 @@ static void check_for_events( UINT flags )
*/
SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
{
struct user_thread_info *thread_info = get_user_thread_info();
struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
SHORT ret;
if (key < 0 || key >= 256) return 0;
@ -377,24 +377,31 @@ SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1)
{
if (thread_info->key_state &&
!(thread_info->key_state[key] & 0xc0) &&
GetTickCount() - thread_info->key_state_time < 50)
if (key_state_info &&
!(key_state_info->state[key] & 0xc0) &&
GetTickCount() - key_state_info->time < 50)
{
/* use cached value */
return 0;
if (!thread_info->key_state) thread_info->key_state = HeapAlloc( GetProcessHeap(), 0, 256 );
}
else if (!key_state_info)
{
key_state_info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*key_state_info) );
get_user_thread_info()->key_state = key_state_info;
}
ret = 0;
SERVER_START_REQ( get_key_state )
{
req->tid = 0;
req->key = key;
if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
if (key_state_info) wine_server_set_reply( req, key_state_info->state,
sizeof(key_state_info->state) );
if (!wine_server_call( req ))
{
if (reply->state & 0x40) ret |= 0x0001;
if (reply->state & 0x80) ret |= 0x8000;
thread_info->key_state_time = GetTickCount();
if (key_state_info) key_state_info->time = GetTickCount();
}
}
SERVER_END_REQ;

View File

@ -3290,7 +3290,7 @@ static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BO
*/
NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
{
struct user_thread_info *thread_info = get_user_thread_info();
struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
struct send_message_info info;
int prev_x, prev_y, new_x, new_y;
NTSTATUS ret;
@ -3329,7 +3329,8 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
break;
}
if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
if (key_state_info) wine_server_set_reply( req, key_state_info->state,
sizeof(key_state_info->state) );
ret = wine_server_call( req );
wait = reply->wait;
prev_x = reply->prev_x;
@ -3341,7 +3342,7 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
if (!ret)
{
if (thread_info->key_state) thread_info->key_state_time = GetTickCount();
if (key_state_info) key_state_info->time = GetTickCount();
if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
USER_Driver->pSetCursorPos( new_x, new_y );
}

View File

@ -184,8 +184,7 @@ struct user_thread_info
DWORD GetMessagePosVal; /* Value for GetMessagePos */
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
UINT active_hooks; /* Bitmap of active hooks */
UINT key_state_time; /* Time of last key state refresh */
BYTE *key_state; /* Cache of global key state */
struct user_key_state_info *key_state; /* Cache of global key state */
HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */
RAWINPUT *rawinput;
@ -193,6 +192,12 @@ struct user_thread_info
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) );
struct user_key_state_info
{
UINT time; /* Time of last key state refresh */
BYTE state[256]; /* State for each key */
};
struct hook_extra_info
{
HHOOK handle;

View File

@ -399,9 +399,10 @@ BOOL WINAPI SetThreadDesktop( HDESK handle )
if (ret) /* reset the desktop windows */
{
struct user_thread_info *thread_info = get_user_thread_info();
struct user_key_state_info *key_state_info = thread_info->key_state;
thread_info->top_window = 0;
thread_info->msg_window = 0;
thread_info->key_state_time = 0;
if (key_state_info) key_state_info->time = 0;
}
return ret;
}