win32u: Move NtUserRegisterHotKey implementation from user32.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2022-02-24 01:27:57 +01:00 committed by Alexandre Julliard
parent 439fb25190
commit e560357df1
13 changed files with 126 additions and 68 deletions

View File

@ -119,15 +119,6 @@ void USER_unload_driver(void)
* These are fallbacks for entry points that are not implemented in the real driver.
*/
static BOOL CDECL nulldrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
return TRUE;
}
static void CDECL nulldrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
}
static BOOL CDECL nulldrv_SetCursorPos( INT x, INT y )
{
return TRUE;
@ -266,16 +257,6 @@ static void CDECL nulldrv_WindowPosChanged( HWND hwnd, HWND insert_after, UINT s
* Each entry point simply loads the real driver and chains to it.
*/
static BOOL CDECL loaderdrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
return load_driver()->pRegisterHotKey( hwnd, modifiers, vk );
}
static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
load_driver()->pUnregisterHotKey( hwnd, modifiers, vk );
}
static BOOL CDECL loaderdrv_SetCursorPos( INT x, INT y )
{
return load_driver()->pSetCursorPos( x, y );
@ -337,9 +318,9 @@ static struct user_driver_funcs lazy_load_driver =
NULL,
NULL,
NULL,
loaderdrv_RegisterHotKey,
NULL,
loaderdrv_UnregisterHotKey,
NULL,
NULL,
NULL,
/* cursor/icon functions */
NULL,
@ -400,8 +381,6 @@ void CDECL __wine_set_user_driver( const struct user_driver_funcs *funcs, UINT v
#define SET_USER_FUNC(name) \
do { if (!driver->p##name) driver->p##name = nulldrv_##name; } while(0)
SET_USER_FUNC(RegisterHotKey);
SET_USER_FUNC(UnregisterHotKey);
SET_USER_FUNC(SetCursorPos);
SET_USER_FUNC(ClipCursor);
SET_USER_FUNC(UpdateClipboard);

View File

@ -645,41 +645,6 @@ BOOL WINAPI BlockInput(BOOL fBlockIt)
}
/***********************************************************************
* RegisterHotKey (USER32.@)
*/
BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
{
BOOL ret;
int replaced=0;
TRACE_(keyboard)("(%p,%d,0x%08x,%X)\n",hwnd,id,modifiers,vk);
if ((hwnd == NULL || WIN_IsCurrentThread(hwnd)) &&
!USER_Driver->pRegisterHotKey(hwnd, modifiers, vk))
return FALSE;
SERVER_START_REQ( register_hotkey )
{
req->window = wine_server_user_handle( hwnd );
req->id = id;
req->flags = modifiers;
req->vkey = vk;
if ((ret = !wine_server_call_err( req )))
{
replaced = reply->replaced;
modifiers = reply->flags;
vk = reply->vkey;
}
}
SERVER_END_REQ;
if (ret && replaced)
USER_Driver->pUnregisterHotKey(hwnd, modifiers, vk);
return ret;
}
/***********************************************************************
* LoadKeyboardLayoutW (USER32.@)
*/

View File

@ -599,7 +599,7 @@
@ stdcall RegisterClipboardFormatW(wstr)
@ stdcall RegisterDeviceNotificationA(long ptr long)
@ stdcall RegisterDeviceNotificationW(long ptr long)
@ stdcall RegisterHotKey(long long long long)
@ stdcall RegisterHotKey(long long long long) NtUserRegisterHotKey
@ stdcall RegisterLogonProcess(long long)
# @ stub RegisterMessagePumpHook
@ stub RegisterNetworkCapabilities

View File

@ -76,9 +76,6 @@ static inline void WIN_ReleasePtr( WND *ptr )
USER_Unlock();
}
#define WND_OTHER_PROCESS ((WND *)1) /* returned by WIN_GetPtr on unknown window handles */
#define WND_DESKTOP ((WND *)2) /* returned by WIN_GetPtr on the desktop window */
extern LRESULT HOOK_CallHooks( INT id, INT code, WPARAM wparam, LPARAM lparam, BOOL unicode ) DECLSPEC_HIDDEN;
extern MINMAXINFO WINPOS_GetMinMaxInfo( HWND hwnd ) DECLSPEC_HIDDEN;

View File

@ -976,6 +976,11 @@ static INT CDECL loaderdrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
return load_driver()->pToUnicodeEx( virt, scan, state, str, size, flags, layout );
}
static BOOL CDECL loaderdrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
return load_driver()->pRegisterHotKey( hwnd, modifiers, vk );
}
static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
load_driver()->pUnregisterHotKey( hwnd, modifiers, vk );
@ -1042,6 +1047,7 @@ static const struct user_driver_funcs lazy_load_driver =
.pGetKeyboardLayoutList = loaderdrv_GetKeyboardLayoutList,
.pMapVirtualKeyEx = loaderdrv_MapVirtualKeyEx,
.pToUnicodeEx = loaderdrv_ToUnicodeEx,
.pRegisterHotKey = loaderdrv_RegisterHotKey,
.pUnregisterHotKey = loaderdrv_UnregisterHotKey,
.pVkKeyScanEx = loaderdrv_VkKeyScanEx,
/* cursor/icon functions */

View File

@ -1171,6 +1171,7 @@ static struct unix_funcs unix_funcs =
NtUserGetUpdatedClipboardFormats,
NtUserIsClipboardFormatAvailable,
NtUserMapVirtualKeyEx,
NtUserRegisterHotKey,
NtUserScrollDC,
NtUserSelectPalette,
NtUserSetCursor,

View File

@ -913,6 +913,41 @@ BOOL WINAPI NtUserGetKeyboardLayoutName( WCHAR *name )
return TRUE;
}
/***********************************************************************
* NtUserRegisterHotKey (win32u.@)
*/
BOOL WINAPI NtUserRegisterHotKey( HWND hwnd, INT id, UINT modifiers, UINT vk )
{
BOOL ret;
int replaced = 0;
TRACE_(keyboard)( "(%p,%d,0x%08x,%X)\n", hwnd, id, modifiers, vk );
if ((!hwnd || is_current_thread_window( hwnd )) &&
!user_driver->pRegisterHotKey( hwnd, modifiers, vk ))
return FALSE;
SERVER_START_REQ( register_hotkey )
{
req->window = wine_server_user_handle( hwnd );
req->id = id;
req->flags = modifiers;
req->vkey = vk;
if ((ret = !wine_server_call_err( req )))
{
replaced = reply->replaced;
modifiers = reply->flags;
vk = reply->vkey;
}
}
SERVER_END_REQ;
if (ret && replaced)
user_driver->pUnregisterHotKey(hwnd, modifiers, vk);
return ret;
}
/***********************************************************************
* NtUserUnregisterHotKey (win32u.@)
*/

View File

@ -86,6 +86,9 @@ typedef struct tagWND
DWORD wExtra[1]; /* Window extra bytes */
} WND;
#define WND_OTHER_PROCESS ((WND *)1) /* returned by WIN_GetPtr on unknown window handles */
#define WND_DESKTOP ((WND *)2) /* returned by WIN_GetPtr on the desktop window */
WND *next_thread_window_ptr( HWND *hwnd );
/* this is the structure stored in TEB->Win32ClientInfo */

View File

@ -1126,7 +1126,7 @@
@ stub NtUserRegisterDManipHook
@ stub NtUserRegisterEdgy
@ stub NtUserRegisterErrorReportingDialog
@ stub NtUserRegisterHotKey
@ stdcall NtUserRegisterHotKey(long long long long)
@ stub NtUserRegisterManipulationThread
@ stub NtUserRegisterPointerDeviceNotifications
@ stub NtUserRegisterPointerInputTarget

View File

@ -210,6 +210,7 @@ struct unix_funcs
BOOL (WINAPI *pNtUserGetUpdatedClipboardFormats)( UINT *formats, UINT size, UINT *out_size );
BOOL (WINAPI *pNtUserIsClipboardFormatAvailable)( UINT format );
UINT (WINAPI *pNtUserMapVirtualKeyEx)( UINT code, UINT type, HKL layout );
BOOL (WINAPI *pNtUserRegisterHotKey)( HWND hwnd, INT id, UINT modifiers, UINT vk );
BOOL (WINAPI *pNtUserScrollDC)( HDC hdc, INT dx, INT dy, const RECT *scroll, const RECT *clip,
HRGN ret_update_rgn, RECT *update_rect );
HPALETTE (WINAPI *pNtUserSelectPalette)( HDC hdc, HPALETTE hpal, WORD bkg );
@ -269,15 +270,23 @@ extern POINT map_dpi_point( POINT pt, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDD
extern RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN;
extern HMONITOR monitor_from_point( POINT pt, DWORD flags, UINT dpi ) DECLSPEC_HIDDEN;
extern HMONITOR monitor_from_rect( const RECT *rect, DWORD flags, UINT dpi ) DECLSPEC_HIDDEN;
/* window.c */
extern void flush_window_surfaces( BOOL idle ) DECLSPEC_HIDDEN;
extern void register_window_surface( struct window_surface *old,
struct window_surface *new ) DECLSPEC_HIDDEN;
extern void user_lock(void) DECLSPEC_HIDDEN;
extern void user_unlock(void) DECLSPEC_HIDDEN;
extern void user_check_not_lock(void) DECLSPEC_HIDDEN;
/* window.c */
struct tagWND;
extern HWND is_current_thread_window( HWND hwnd ) DECLSPEC_HIDDEN;
extern void flush_window_surfaces( BOOL idle ) DECLSPEC_HIDDEN;
extern void register_window_surface( struct window_surface *old,
struct window_surface *new ) DECLSPEC_HIDDEN;
/* to release pointers retrieved by win_get_ptr */
static inline void release_win_ptr( struct tagWND *ptr )
{
user_unlock();
}
extern void wrappers_init( unixlib_handle_t handle ) DECLSPEC_HIDDEN;
extern NTSTATUS gdi_init(void) DECLSPEC_HIDDEN;
extern NTSTATUS callbacks_init( void *args ) DECLSPEC_HIDDEN;

View File

@ -188,6 +188,62 @@ done:
pthread_mutex_unlock( &surfaces_lock );
}
/*******************************************************************
* is_desktop_window
*
* Check if window is the desktop or the HWND_MESSAGE top parent.
*/
static BOOL is_desktop_window( HWND hwnd )
{
struct user_thread_info *thread_info = get_user_thread_info();
if (!hwnd) return FALSE;
if (hwnd == thread_info->top_window) return TRUE;
if (hwnd == thread_info->msg_window) return TRUE;
if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff)
{
if (LOWORD(thread_info->top_window) == LOWORD(hwnd)) return TRUE;
if (LOWORD(thread_info->msg_window) == LOWORD(hwnd)) return TRUE;
}
return FALSE;
}
/***********************************************************************
* win_get_ptr
*
* Return a pointer to the WND structure if local to the process,
* or WND_OTHER_PROCESS if handle may be valid in other process.
* If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
*/
static WND *get_win_ptr( HWND hwnd )
{
WND *win;
if ((win = get_user_handle_ptr( hwnd, NTUSER_OBJ_WINDOW )) == WND_OTHER_PROCESS)
{
if (is_desktop_window( hwnd )) win = WND_DESKTOP;
}
return win;
}
/***********************************************************************
* is_current_thread_window
*
* Check whether a given window belongs to the current process (and return the full handle).
*/
HWND is_current_thread_window( HWND hwnd )
{
WND *win;
HWND ret = 0;
if (!(win = get_win_ptr( hwnd )) || win == WND_OTHER_PROCESS || win == WND_DESKTOP)
return 0;
if (win->tid == GetCurrentThreadId()) ret = win->obj.handle;
release_win_ptr( win );
return ret;
}
/***********************************************************************
* NtUserGetProp (win32u.@)
*

View File

@ -833,6 +833,12 @@ UINT WINAPI NtUserMapVirtualKeyEx( UINT code, UINT type, HKL layout )
return unix_funcs->pNtUserMapVirtualKeyEx( code, type, layout );
}
BOOL WINAPI NtUserRegisterHotKey( HWND hwnd, INT id, UINT modifiers, UINT vk )
{
if (!unix_funcs) return FALSE;
return unix_funcs->pNtUserRegisterHotKey( hwnd, id, modifiers, vk );
}
BOOL WINAPI NtUserScrollDC( HDC hdc, INT dx, INT dy, const RECT *scroll, const RECT *clip,
HRGN ret_update_rgn, RECT *update_rect )
{

View File

@ -240,6 +240,7 @@ HWINSTA WINAPI NtUserOpenWindowStation( OBJECT_ATTRIBUTES *attr, ACCESS_MASK acc
BOOL WINAPI NtUserSetObjectInformation( HANDLE handle, INT index, void *info, DWORD len );
HDESK WINAPI NtUserOpenDesktop( OBJECT_ATTRIBUTES *attr, DWORD flags, ACCESS_MASK access );
HDESK WINAPI NtUserOpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access );
BOOL WINAPI NtUserRegisterHotKey( HWND hwnd, INT id, UINT modifiers, UINT vk );
BOOL WINAPI NtUserRemoveClipboardFormatListener( HWND hwnd );
HANDLE WINAPI NtUserRemoveProp( HWND hwnd, const WCHAR *str );
BOOL WINAPI NtUserScrollDC( HDC hdc, INT dx, INT dy, const RECT *scroll, const RECT *clip,