Commit 325c061b authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

user32: Move key state cache into a separate struct.

parent 4eff1879
...@@ -437,7 +437,10 @@ static LRESULT call_hook( struct hook_info *info, INT code, WPARAM wparam, LPARA ...@@ -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) 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; return ret;
} }
......
...@@ -368,7 +368,7 @@ static void check_for_events( UINT flags ) ...@@ -368,7 +368,7 @@ static void check_for_events( UINT flags )
*/ */
SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key ) 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; SHORT ret;
if (key < 0 || key >= 256) return 0; if (key < 0 || key >= 256) return 0;
...@@ -377,24 +377,31 @@ SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key ) ...@@ -377,24 +377,31 @@ SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1) if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1)
{ {
if (thread_info->key_state && if (key_state_info &&
!(thread_info->key_state[key] & 0xc0) && !(key_state_info->state[key] & 0xc0) &&
GetTickCount() - thread_info->key_state_time < 50) GetTickCount() - key_state_info->time < 50)
{
/* use cached value */
return 0; 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; ret = 0;
SERVER_START_REQ( get_key_state ) SERVER_START_REQ( get_key_state )
{ {
req->tid = 0; req->tid = 0;
req->key = key; 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 (!wine_server_call( req ))
{ {
if (reply->state & 0x40) ret |= 0x0001; if (reply->state & 0x40) ret |= 0x0001;
if (reply->state & 0x80) ret |= 0x8000; if (reply->state & 0x80) ret |= 0x8000;
thread_info->key_state_time = GetTickCount(); if (key_state_info) key_state_info->time = GetTickCount();
} }
} }
SERVER_END_REQ; SERVER_END_REQ;
......
...@@ -3290,7 +3290,7 @@ static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BO ...@@ -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 ) 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; struct send_message_info info;
int prev_x, prev_y, new_x, new_y; int prev_x, prev_y, new_x, new_y;
NTSTATUS ret; NTSTATUS ret;
...@@ -3329,7 +3329,8 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags ) ...@@ -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 ); req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
break; 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 ); ret = wine_server_call( req );
wait = reply->wait; wait = reply->wait;
prev_x = reply->prev_x; prev_x = reply->prev_x;
...@@ -3341,7 +3342,7 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags ) ...@@ -3341,7 +3342,7 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
if (!ret) 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)) if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
USER_Driver->pSetCursorPos( new_x, new_y ); USER_Driver->pSetCursorPos( new_x, new_y );
} }
......
...@@ -184,8 +184,7 @@ struct user_thread_info ...@@ -184,8 +184,7 @@ struct user_thread_info
DWORD GetMessagePosVal; /* Value for GetMessagePos */ DWORD GetMessagePosVal; /* Value for GetMessagePos */
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */ ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
UINT active_hooks; /* Bitmap of active hooks */ UINT active_hooks; /* Bitmap of active hooks */
UINT key_state_time; /* Time of last key state refresh */ struct user_key_state_info *key_state; /* Cache of global key state */
BYTE *key_state; /* Cache of global key state */
HWND top_window; /* Desktop window */ HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */ HWND msg_window; /* HWND_MESSAGE parent window */
RAWINPUT *rawinput; RAWINPUT *rawinput;
...@@ -193,6 +192,12 @@ struct user_thread_info ...@@ -193,6 +192,12 @@ struct user_thread_info
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) ); 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 struct hook_extra_info
{ {
HHOOK handle; HHOOK handle;
......
...@@ -399,9 +399,10 @@ BOOL WINAPI SetThreadDesktop( HDESK handle ) ...@@ -399,9 +399,10 @@ BOOL WINAPI SetThreadDesktop( HDESK handle )
if (ret) /* reset the desktop windows */ if (ret) /* reset the desktop windows */
{ {
struct user_thread_info *thread_info = get_user_thread_info(); 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->top_window = 0;
thread_info->msg_window = 0; thread_info->msg_window = 0;
thread_info->key_state_time = 0; if (key_state_info) key_state_info->time = 0;
} }
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment