From 7de242e72cbe45b808097e20b7d30d1c71d6dcba Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 13 May 2015 22:39:20 -0700 Subject: [PATCH] Added SDL_SetWindowsMessageHook() to facilitate full IME support on Windows --- include/SDL_system.h | 6 ++++++ src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + src/video/SDL_egl.c | 0 src/video/windows/SDL_windowsevents.c | 13 +++++++++++++ 5 files changed, 21 insertions(+) mode change 100755 => 100644 src/video/SDL_egl.c diff --git a/include/SDL_system.h b/include/SDL_system.h index ee9bb48166700..2bb64c27c4f54 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -42,6 +42,12 @@ extern "C" { /* Platform specific functions for Windows */ #ifdef __WIN32__ + +/** + \brief Set a function that is called for every windows message, before TranslateMessage() +*/ +typedef void (*SDL_WindowsMessageHook)(void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam); +extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback); /** \brief Returns the D3D9 adapter index that matches the specified display index. diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index dcc6d4677693f..663feea2f5577 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -592,3 +592,4 @@ #define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL #define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL #define SDL_GetGrabbedWindow SDL_GetGrabbedWindow_REAL +#define SDL_SetWindowsMessageHook SDL_SetWindowsMessageHook_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 6408e3f892d7c..e25bbda82559e 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -624,3 +624,4 @@ SDL_DYNAPI_PROC(int,SDL_QueueAudio,(SDL_AudioDeviceID a, const void *b, Uint32 c SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return) SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return) +SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a),(a),) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c old mode 100755 new mode 100644 diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 524e67adf7c05..6d0c5957de112 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -24,6 +24,7 @@ #include "SDL_windowsvideo.h" #include "SDL_windowsshape.h" +#include "SDL_system.h" #include "SDL_syswm.h" #include "SDL_timer.h" #include "SDL_vkeys.h" @@ -925,6 +926,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } } +/* A message hook called before TranslateMessage() */ +static SDL_WindowsMessageHook g_WindowsMessageHook = NULL; + +void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback) +{ + g_WindowsMessageHook = callback; +} + void WIN_PumpEvents(_THIS) { @@ -934,6 +943,10 @@ WIN_PumpEvents(_THIS) if (g_WindowsEnableMessageLoop) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (g_WindowsMessageHook) { + g_WindowsMessageHook(msg.hwnd, msg.message, msg.wParam, msg.lParam); + } + /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */ TranslateMessage(&msg); DispatchMessage(&msg);