Commit 0c6d042c authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move call_current_hook implementation from user32.

parent fcc15819
......@@ -558,35 +558,6 @@ LRESULT WINAPI CallNextHookEx( HHOOK hhook, INT code, WPARAM wparam, LPARAM lpar
}
LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam )
{
struct hook_info info;
ZeroMemory( &info, sizeof(info) - sizeof(info.module) );
SERVER_START_REQ( get_hook_info )
{
req->handle = wine_server_user_handle( hhook );
req->get_next = 0;
req->event = EVENT_MIN;
wine_server_set_reply( req, info.module, sizeof(info.module)-sizeof(WCHAR) );
if (!wine_server_call_err( req ))
{
info.module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
info.handle = wine_server_ptr_handle( reply->handle );
info.id = reply->id;
info.pid = reply->pid;
info.tid = reply->tid;
info.proc = wine_server_get_ptr( reply->proc );
info.next_unicode = reply->unicode;
}
}
SERVER_END_REQ;
info.prev_unicode = TRUE; /* assume Unicode for this function */
return call_hook( &info, code, wparam, lparam );
}
/***********************************************************************
* CallMsgFilterA (USER32.@)
*/
......@@ -646,7 +617,7 @@ HWINEVENTHOOK WINAPI SetWinEventHook(DWORD event_min, DWORD event_max,
return NtUserSetWinEventHook( event_min, event_max, inst, &str, proc, pid, tid, flags );
}
BOOL WINAPI User32CallWinEventHook( const struct win_hook_proc_params *params, ULONG size )
BOOL WINAPI User32CallWinEventHook( const struct win_event_hook_params *params, ULONG size )
{
WINEVENTPROC proc = params->proc;
HMODULE free_module = 0;
......@@ -668,6 +639,21 @@ BOOL WINAPI User32CallWinEventHook( const struct win_hook_proc_params *params, U
return TRUE;
}
BOOL WINAPI User32CallWindowsHook( const struct win_hook_params *params, ULONG size )
{
HOOKPROC proc = params->proc;
HMODULE free_module = 0;
LRESULT ret;
if (params->module[0] && !(proc = get_hook_proc( proc, params->module, &free_module ))) return FALSE;
ret = call_hook_proc( proc, params->id, params->code, params->wparam, params->lparam,
params->prev_unicode, params->next_unicode );
if (free_module) FreeLibrary( free_module );
return ret;
}
/***********************************************************************
* IsWinEventHookInstalled [USER32.@]
*
......
......@@ -1878,13 +1878,6 @@ LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpar
case WM_WINE_SETACTIVEWINDOW:
if (!wparam && NtUserGetForegroundWindow() == hwnd) return 0;
return (LRESULT)SetActiveWindow( (HWND)wparam );
case WM_WINE_KEYBOARD_LL_HOOK:
case WM_WINE_MOUSE_LL_HOOK:
{
struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
}
case WM_WINE_UPDATEWINDOWSTATE:
update_window_state( hwnd );
return 0;
......@@ -3350,9 +3343,9 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, const RAWINPUT *r
* Same as SendMessageTimeoutW but sends the message to a specific thread
* without requiring a window handle. Only works for internal Wine messages.
*/
LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr )
LRESULT WINAPI MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr )
{
struct send_message_info info;
LRESULT ret, result;
......
......@@ -141,6 +141,7 @@ static const struct user_callbacks user_funcs =
RedrawWindow,
SendMessageTimeoutW,
WindowFromDC,
MSG_SendInternalMessageTimeout,
};
static void WINAPI User32CallFreeIcon( ULONG *param, ULONG size )
......@@ -152,6 +153,7 @@ static const void *kernel_callback_table[NtUserCallCount] =
{
User32CallEnumDisplayMonitor,
User32CallWinEventHook,
User32CallWindowsHook,
User32CallFreeIcon,
};
......
......@@ -86,12 +86,6 @@ extern void (WINAPI *imm_unregister_window)(HWND) DECLSPEC_HIDDEN;
#define IME_INTERNAL_ACTIVATE 0x17
#define IME_INTERNAL_DEACTIVATE 0x18
struct hook_extra_info
{
HHOOK handle;
LPARAM lparam;
};
static inline struct user_thread_info *get_user_thread_info(void)
{
return (struct user_thread_info *)NtCurrentTeb()->Win32ClientInfo;
......@@ -135,13 +129,12 @@ extern void wait_graphics_driver_ready(void) DECLSPEC_HIDDEN;
extern void *get_hook_proc( void *proc, const WCHAR *module, HMODULE *free_module ) DECLSPEC_HIDDEN;
extern RECT get_virtual_screen_rect(void) DECLSPEC_HIDDEN;
extern RECT get_primary_monitor_rect(void) DECLSPEC_HIDDEN;
extern LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam ) DECLSPEC_HIDDEN;
extern DWORD get_input_codepage( void ) DECLSPEC_HIDDEN;
extern BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping ) DECLSPEC_HIDDEN;
extern NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, const RAWINPUT *rawinput, UINT flags ) DECLSPEC_HIDDEN;
extern LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr ) DECLSPEC_HIDDEN;
extern LRESULT WINAPI MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr ) DECLSPEC_HIDDEN;
extern HPEN SYSCOLOR_GetPen( INT index ) DECLSPEC_HIDDEN;
extern HBRUSH SYSCOLOR_Get55AABrush(void) DECLSPEC_HIDDEN;
extern void SYSPARAMS_Init(void) DECLSPEC_HIDDEN;
......@@ -172,7 +165,8 @@ extern const WCHAR *CLASS_GetVersionedName(const WCHAR *classname, UINT *basenam
/* kernel callbacks */
BOOL WINAPI User32CallEnumDisplayMonitor( struct enum_display_monitor_params *params, ULONG size );
BOOL WINAPI User32CallWinEventHook( const struct win_hook_proc_params *params, ULONG size );
BOOL WINAPI User32CallWinEventHook( const struct win_event_hook_params *params, ULONG size );
BOOL WINAPI User32CallWindowsHook( const struct win_hook_params *params, ULONG size );
/* message spy definitions */
......
......@@ -23,6 +23,7 @@
#pragma makedep unix
#endif
#include <assert.h>
#include "win32u_private.h"
#include "ntuser_private.h"
#include "wine/server.h"
......@@ -171,6 +172,122 @@ BOOL unhook_windows_hook( INT id, HOOKPROC proc )
return !status;
}
static UINT get_ll_hook_timeout(void)
{
/* FIXME: should retrieve LowLevelHooksTimeout in HKEY_CURRENT_USER\Control Panel\Desktop */
return 2000;
}
/***********************************************************************
* call_hook
*
* Call hook either in current thread or send message to the destination
* thread.
*/
static LRESULT call_hook( struct win_hook_params *info )
{
DWORD_PTR ret = 0;
if (info->tid)
{
struct hook_extra_info h_extra;
h_extra.handle = info->handle;
h_extra.lparam = info->lparam;
TRACE( "calling hook in thread %04x %s code %x wp %lx lp %lx\n",
info->tid, hook_names[info->id-WH_MINHOOK], info->code, info->wparam, info->lparam );
switch(info->id)
{
case WH_KEYBOARD_LL:
if (!user_callbacks) break;
user_callbacks->send_ll_message( info->pid, info->tid, WM_WINE_KEYBOARD_LL_HOOK,
info->wparam, (LPARAM)&h_extra, SMTO_ABORTIFHUNG,
get_ll_hook_timeout(), &ret );
break;
case WH_MOUSE_LL:
if (!user_callbacks) break;
user_callbacks->send_ll_message( info->pid, info->tid, WM_WINE_MOUSE_LL_HOOK,
info->wparam, (LPARAM)&h_extra, SMTO_ABORTIFHUNG,
get_ll_hook_timeout(), &ret );
break;
default:
ERR("Unknown hook id %d\n", info->id);
assert(0);
break;
}
}
else if (info->proc)
{
struct user_thread_info *thread_info = get_user_thread_info();
HHOOK prev = thread_info->hook;
BOOL prev_unicode = thread_info->hook_unicode;
size_t len = lstrlenW( info->module );
void *ret_ptr;
ULONG ret_len;
/*
* Windows protects from stack overflow in recursive hook calls. Different Windows
* allow different depths.
*/
if (thread_info->hook_call_depth >= 25)
{
WARN("Too many hooks called recursively, skipping call.\n");
return 0;
}
TRACE( "calling hook %p %s code %x wp %lx lp %lx module %s\n",
info->proc, hook_names[info->id-WH_MINHOOK], info->code, info->wparam,
info->lparam, debugstr_w(info->module) );
thread_info->hook = info->handle;
thread_info->hook_unicode = info->next_unicode;
thread_info->hook_call_depth++;
ret = KeUserModeCallback( NtUserCallWindowsHook, info,
FIELD_OFFSET( struct win_hook_params, module[len + 1] ),
&ret_ptr, &ret_len );
thread_info->hook = prev;
thread_info->hook_unicode = prev_unicode;
thread_info->hook_call_depth--;
}
if (info->id == WH_KEYBOARD_LL || info->id == WH_MOUSE_LL)
InterlockedIncrement( &global_key_state_counter ); /* force refreshing the key state cache */
return ret;
}
LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam )
{
struct win_hook_params info;
memset( &info, 0, sizeof(info) - sizeof(info.module) );
SERVER_START_REQ( get_hook_info )
{
req->handle = wine_server_user_handle( hhook );
req->get_next = 0;
req->event = EVENT_MIN;
wine_server_set_reply( req, info.module, sizeof(info.module)-sizeof(WCHAR) );
if (!wine_server_call_err( req ))
{
info.module[wine_server_reply_size(req) / sizeof(WCHAR)] = 0;
info.handle = wine_server_ptr_handle( reply->handle );
info.id = reply->id;
info.pid = reply->pid;
info.tid = reply->tid;
info.proc = wine_server_get_ptr( reply->proc );
info.next_unicode = reply->unicode;
}
}
SERVER_END_REQ;
info.code = code;
info.wparam = wparam;
info.lparam = lparam;
info.prev_unicode = TRUE; /* assume Unicode for this function */
return call_hook( &info );
}
/***********************************************************************
* NtUserSetWinEventHook (win32u.@)
*/
......@@ -247,7 +364,7 @@ BOOL WINAPI NtUserUnhookWinEvent( HWINEVENTHOOK handle )
void WINAPI NtUserNotifyWinEvent( DWORD event, HWND hwnd, LONG object_id, LONG child_id )
{
struct user_thread_info *thread_info = get_user_thread_info();
struct win_hook_proc_params info;
struct win_event_hook_params info;
void *ret_ptr;
ULONG ret_len;
BOOL ret;
......@@ -299,7 +416,7 @@ void WINAPI NtUserNotifyWinEvent( DWORD event, HWND hwnd, LONG object_id, LONG c
info.proc, event, hwnd, object_id, child_id, debugstr_w(info.module) );
KeUserModeCallback( NtUserCallWinEventHook, &info,
FIELD_OFFSET( struct win_hook_proc_params, module[lstrlenW(info.module) + 1] ),
FIELD_OFFSET( struct win_hook_params, module[lstrlenW(info.module) + 1] ),
&ret_ptr, &ret_len );
SERVER_START_REQ( get_hook_info )
......
......@@ -25,6 +25,7 @@
#endif
#include "win32u_private.h"
#include "ntuser_private.h"
#include "wine/server.h"
#include "wine/debug.h"
......@@ -40,6 +41,13 @@ LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpar
{
switch(msg)
{
case WM_WINE_KEYBOARD_LL_HOOK:
case WM_WINE_MOUSE_LL_HOOK:
{
struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
}
case WM_WINE_CLIPCURSOR:
if (wparam)
{
......
......@@ -33,6 +33,7 @@ struct user_callbacks
BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT );
LRESULT (WINAPI *pSendMessageTimeoutW)( HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR );
HWND (WINAPI *pWindowFromDC)( HDC );
LRESULT (WINAPI *send_ll_message)( DWORD, DWORD, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR );
};
struct user_object
......@@ -128,6 +129,12 @@ struct user_key_state_info
BYTE state[256]; /* State for each key */
};
struct hook_extra_info
{
HHOOK handle;
LPARAM lparam;
};
/* cursoricon.c */
HICON alloc_cursoricon_handle( BOOL is_icon ) DECLSPEC_HIDDEN;
......
......@@ -253,6 +253,7 @@ extern ULONG_PTR get_icon_param( HICON handle ) DECLSPEC_HIDDEN;
extern ULONG_PTR set_icon_param( HICON handle, ULONG_PTR param ) DECLSPEC_HIDDEN;
/* hook.c */
extern LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam ) DECLSPEC_HIDDEN;
extern BOOL unhook_windows_hook( INT id, HOOKPROC proc ) DECLSPEC_HIDDEN;
/* input.c */
......
......@@ -29,6 +29,7 @@ enum
/* user32 callbacks */
NtUserCallEnumDisplayMonitor,
NtUserCallWinEventHook,
NtUserCallWindowsHook,
/* win16 hooks */
NtUserCallFreeIcon,
/* Vulkan support */
......@@ -48,7 +49,7 @@ struct enum_display_monitor_params
};
/* NtUserCallWinEventHook params */
struct win_hook_proc_params
struct win_event_hook_params
{
DWORD event;
HWND hwnd;
......@@ -59,6 +60,22 @@ struct win_hook_proc_params
WCHAR module[MAX_PATH];
};
/* NtUserCallWindowsHook params */
struct win_hook_params
{
void *proc;
void *handle;
DWORD pid;
DWORD tid;
int id;
int code;
WPARAM wparam;
LPARAM lparam;
BOOL prev_unicode;
BOOL next_unicode;
WCHAR module[MAX_PATH];
};
/* process DPI awareness contexts */
#define NTUSER_DPI_UNAWARE 0x00006010
#define NTUSER_DPI_SYSTEM_AWARE 0x00006011
......
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