From 2af9441d35ee84c352e1df675adccd293af22046 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 2 Aug 2021 16:14:58 +0200 Subject: [PATCH] Create separate wnd_proc functions for winraw --- gfx/common/win32_common.c | 235 +++++++++++++++++++++++++++++++++ gfx/common/win32_common.h | 8 ++ gfx/drivers/d3d10.c | 5 + gfx/drivers/d3d11.c | 5 + gfx/drivers/d3d12.c | 5 + gfx/drivers/d3d8.c | 5 + gfx/drivers/d3d9.c | 5 + gfx/drivers/gdi_gfx.c | 5 + gfx/drivers_context/w_vk_ctx.c | 5 + gfx/drivers_context/wgl_ctx.c | 5 + 10 files changed, 283 insertions(+) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 04bb22f342..8e1b31cab6 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -967,6 +967,130 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, bool quit = false; win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + switch (message) + { + case WM_KEYUP: /* Key released */ + case WM_SYSKEYUP: /* Key released */ + keydown = false; + /* fall-through */ + case WM_KEYDOWN: /* Key pressed */ + case WM_SYSKEYDOWN: /* Key pressed */ + quit = true; + { + uint16_t mod = 0; + unsigned keycode = 0; + unsigned keysym = (lparam >> 16) & 0xff; + + if (GetKeyState(VK_SHIFT) & 0x80) + mod |= RETROKMOD_SHIFT; + if (GetKeyState(VK_CONTROL) & 0x80) + mod |= RETROKMOD_CTRL; + if (GetKeyState(VK_MENU) & 0x80) + mod |= RETROKMOD_ALT; + if (GetKeyState(VK_CAPITAL) & 0x81) + mod |= RETROKMOD_CAPSLOCK; + if (GetKeyState(VK_SCROLL) & 0x81) + mod |= RETROKMOD_SCROLLOCK; + if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80) + mod |= RETROKMOD_META; + + keysym = (unsigned)wparam; + /* fix key binding issues on winraw when + * DirectInput is not available */ + switch (keysym) + { + /* Mod & Keypad handling done in winraw_callback */ + case VK_SHIFT: + case VK_CONTROL: + case VK_MENU: + case VK_INSERT: + case VK_DELETE: + case VK_HOME: + case VK_END: + case VK_PRIOR: + case VK_NEXT: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + case VK_CLEAR: + case VK_RETURN: + return 0; + } + + keycode = input_keymaps_translate_keysym_to_rk(keysym); + + input_keyboard_event(keydown, keycode, + 0, mod, RETRO_DEVICE_KEYBOARD); + + if (message != WM_SYSKEYDOWN) + return 0; + + if ( + wparam == VK_F10 || + wparam == VK_MENU || + wparam == VK_RSHIFT + ) + return 0; + } + break; + case WM_MOUSEMOVE: + case WM_POINTERDOWN: + case WM_POINTERUP: + case WM_POINTERUPDATE: + case WM_DEVICECHANGE: + case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: + case WM_NCLBUTTONDBLCLK: +#if _WIN32_WINNT >= 0x0500 /* 2K */ + if (g_win32->taskbar_message && message == g_win32->taskbar_message) + taskbar_is_created = true; +#endif + break; + case WM_DROPFILES: + case WM_SYSCOMMAND: + case WM_CHAR: + case WM_CLOSE: + case WM_DESTROY: + case WM_QUIT: + case WM_MOVE: + case WM_SIZE: + case WM_COMMAND: + ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam); + if (quit) + return ret; +#if _WIN32_WINNT >= 0x0500 /* 2K */ + if (g_win32->taskbar_message && message == g_win32->taskbar_message) + taskbar_is_created = true; +#endif + break; +#ifdef HAVE_CLIP_WINDOW + case WM_SETFOCUS: + if (input_mouse_grabbed()) + win32_clip_window(true); + break; + case WM_KILLFOCUS: + if (input_mouse_grabbed()) + win32_clip_window(false); + break; +#endif + case WM_DISPLAYCHANGE: /* fix size after display mode switch when using SR */ + win32_resize_after_display_change(hwnd); + break; + } + + return DefWindowProc(hwnd, message, wparam, lparam); +} + +#ifdef HAVE_WINRAWINPUT +static LRESULT CALLBACK wnd_proc_winraw_common_internal(HWND hwnd, + UINT message, WPARAM wparam, LPARAM lparam) +{ + LRESULT ret; + bool keydown = true; + bool quit = false; + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + switch (message) { case WM_KEYUP: /* Key released */ @@ -1086,6 +1210,7 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, return DefWindowProc(hwnd, message, wparam, lparam); } +#endif #ifdef HAVE_DINPUT static LRESULT CALLBACK wnd_proc_common_dinput_internal(HWND hwnd, @@ -1226,6 +1351,25 @@ LRESULT CALLBACK wnd_proc_d3d_common(HWND hwnd, UINT message, return wnd_proc_common_internal(hwnd, message, wparam, lparam); } +#ifdef HAVE_WINRAWINPUT +LRESULT CALLBACK wnd_proc_d3d_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam) +{ + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + + if (message == WM_CREATE) + { + if (DragAcceptFiles_func) + DragAcceptFiles_func(hwnd, true); + + g_win32_inited = true; + return 0; + } + + return wnd_proc_winraw_common_internal(hwnd, message, wparam, lparam); +} +#endif + #ifdef HAVE_DINPUT LRESULT CALLBACK wnd_proc_d3d_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1259,6 +1403,7 @@ LRESULT CALLBACK wnd_proc_wgl_dinput(HWND hwnd, UINT message, create_wgl_context(hwnd, &g_win32->quit); if (DragAcceptFiles_func) DragAcceptFiles_func(hwnd, true); + g_win32_inited = true; return 0; } @@ -1266,6 +1411,25 @@ LRESULT CALLBACK wnd_proc_wgl_dinput(HWND hwnd, UINT message, } #endif +#ifdef HAVE_WINRAWINPUT +LRESULT CALLBACK wnd_proc_wgl_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam) +{ + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + + if (message == WM_CREATE) + { + create_wgl_context(hwnd, &g_win32->quit); + if (DragAcceptFiles_func) + DragAcceptFiles_func(hwnd, true); + g_win32_inited = true; + return 0; + } + + return wnd_proc_winraw_common_internal(hwnd, message, wparam, lparam); +} +#endif + LRESULT CALLBACK wnd_proc_wgl_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { @@ -1284,6 +1448,7 @@ LRESULT CALLBACK wnd_proc_wgl_common(HWND hwnd, UINT message, #endif #ifdef HAVE_VULKAN + #ifdef HAVE_DINPUT LRESULT CALLBACK wnd_proc_vk_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1295,6 +1460,7 @@ LRESULT CALLBACK wnd_proc_vk_dinput(HWND hwnd, UINT message, create_vk_context(hwnd, &g_win32->quit); if (DragAcceptFiles_func) DragAcceptFiles_func(hwnd, true); + g_win32_inited = true; return 0; } @@ -1302,6 +1468,25 @@ LRESULT CALLBACK wnd_proc_vk_dinput(HWND hwnd, UINT message, } #endif +#ifdef HAVE_WINRAWINPUT +LRESULT CALLBACK wnd_proc_vk_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam) +{ + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + + if (message == WM_CREATE) + { + create_vk_context(hwnd, &g_win32->quit); + if (DragAcceptFiles_func) + DragAcceptFiles_func(hwnd, true); + g_win32_inited = true; + return 0; + } + + return wnd_proc_winraw_common_internal(hwnd, message, wparam, lparam); +} +#endif + LRESULT CALLBACK wnd_proc_vk_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { @@ -1320,6 +1505,7 @@ LRESULT CALLBACK wnd_proc_vk_common(HWND hwnd, UINT message, #endif #ifdef HAVE_GDI + #ifdef HAVE_DINPUT LRESULT CALLBACK wnd_proc_gdi_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1369,6 +1555,55 @@ LRESULT CALLBACK wnd_proc_gdi_dinput(HWND hwnd, UINT message, } #endif +#ifdef HAVE_WINRAWINPUT +LRESULT CALLBACK wnd_proc_gdi_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam) +{ + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + + if (message == WM_CREATE) + { + create_gdi_context(hwnd, &g_win32->quit); + if (DragAcceptFiles_func) + DragAcceptFiles_func(hwnd, true); + return 0; + } + else if (message == WM_PAINT) + { + gdi_t *gdi = (gdi_t*)video_driver_get_ptr(); + + if (gdi && gdi->memDC) + { + gdi->bmp_old = (HBITMAP)SelectObject(gdi->memDC, gdi->bmp); + + /* Draw video content */ + StretchBlt( + gdi->winDC, + 0, + 0, + gdi->screen_width, + gdi->screen_height, + gdi->memDC, + 0, + 0, + gdi->video_width, + gdi->video_height, + SRCCOPY); + + SelectObject(gdi->memDC, gdi->bmp_old); + } + +#if _WIN32_WINNT >= 0x0500 /* 2K */ + if ( g_win32->taskbar_message + && message == g_win32->taskbar_message) + taskbar_is_created = true; +#endif + } + + return wnd_proc_winraw_common_internal(hwnd, message, wparam, lparam); +} +#endif + LRESULT CALLBACK wnd_proc_gdi_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index 5730a1b91c..94c0bc238a 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -127,6 +127,8 @@ float win32_get_refresh_rate(void *data); #if defined(HAVE_D3D8) || defined(HAVE_D3D9) || defined (HAVE_D3D10) || defined (HAVE_D3D11) || defined (HAVE_D3D12) LRESULT CALLBACK wnd_proc_d3d_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); +LRESULT CALLBACK wnd_proc_d3d_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); LRESULT CALLBACK wnd_proc_d3d_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #endif @@ -134,6 +136,8 @@ LRESULT CALLBACK wnd_proc_d3d_common(HWND hwnd, UINT message, #if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) LRESULT CALLBACK wnd_proc_wgl_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); +LRESULT CALLBACK wnd_proc_wgl_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); LRESULT CALLBACK wnd_proc_wgl_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #endif @@ -141,12 +145,16 @@ LRESULT CALLBACK wnd_proc_wgl_common(HWND hwnd, UINT message, #if defined(HAVE_VULKAN) LRESULT CALLBACK wnd_proc_vk_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); +LRESULT CALLBACK wnd_proc_vk_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); LRESULT CALLBACK wnd_proc_vk_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #endif LRESULT CALLBACK wnd_proc_gdi_dinput(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); +LRESULT CALLBACK wnd_proc_gdi_winraw(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); LRESULT CALLBACK wnd_proc_gdi_common(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index d6d758e1b7..60457d4264 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -651,6 +651,11 @@ static void *d3d10_gfx_init(const video_info_t* video, #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_d3d_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_d3d_winraw; #endif #ifdef HAVE_WINDOW win32_window_init(&wndclass, true, NULL); diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index 22cf320e93..f321bd2e6e 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -814,6 +814,11 @@ static void *d3d11_gfx_init(const video_info_t* video, #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_d3d_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_d3d_winraw; #endif #ifdef HAVE_WINDOW win32_window_init(&wndclass, true, NULL); diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c index 01177669d8..a4ad51b9c6 100644 --- a/gfx/drivers/d3d12.c +++ b/gfx/drivers/d3d12.c @@ -923,6 +923,11 @@ static void *d3d12_gfx_init(const video_info_t* video, #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_d3d_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_d3d_winraw; #endif #ifdef HAVE_WINDOW win32_window_init(&wndclass, true, NULL); diff --git a/gfx/drivers/d3d8.c b/gfx/drivers/d3d8.c index 9e814cd031..fb59eec34b 100644 --- a/gfx/drivers/d3d8.c +++ b/gfx/drivers/d3d8.c @@ -1152,6 +1152,11 @@ static bool d3d8_init_internal(d3d8_video_t *d3d, #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) d3d->windowClass.lpfnWndProc = wnd_proc_d3d_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + d3d->windowClass.lpfnWndProc = wnd_proc_d3d_winraw; #endif win32_window_init(&d3d->windowClass, true, NULL); #endif diff --git a/gfx/drivers/d3d9.c b/gfx/drivers/d3d9.c index 4434de247a..632d384bf3 100644 --- a/gfx/drivers/d3d9.c +++ b/gfx/drivers/d3d9.c @@ -1152,6 +1152,11 @@ static bool d3d9_init_internal(d3d9_video_t *d3d, #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) d3d->windowClass.lpfnWndProc = wnd_proc_d3d_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + d3d->windowClass.lpfnWndProc = wnd_proc_d3d_winraw; #endif win32_window_init(&d3d->windowClass, true, NULL); #endif diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c index 6a1bfe6a1a..807bc3a6d1 100644 --- a/gfx/drivers/gdi_gfx.c +++ b/gfx/drivers/gdi_gfx.c @@ -104,6 +104,11 @@ static bool gfx_ctx_gdi_init(void) #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_gdi_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_gdi_winraw; #endif if (!win32_window_init(&wndclass, true, NULL)) return false; diff --git a/gfx/drivers_context/w_vk_ctx.c b/gfx/drivers_context/w_vk_ctx.c index 670f86b2c0..467d5f8417 100644 --- a/gfx/drivers_context/w_vk_ctx.c +++ b/gfx/drivers_context/w_vk_ctx.c @@ -222,6 +222,11 @@ static void *gfx_ctx_w_vk_init(void *video_driver) #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_vk_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_vk_winraw; #endif } if (!win32_window_init(&wndclass, true, NULL)) diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 3f551cbca7..7142b87551 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -636,6 +636,11 @@ static void *gfx_ctx_wgl_init(void *video_driver) #ifdef HAVE_DINPUT if (string_is_equal(settings->arrays.input_driver, "dinput")) wndclass.lpfnWndProc = wnd_proc_wgl_dinput; + else +#endif +#ifdef HAVE_WINRAWINPUT + if (string_is_equal(settings->arrays.input_driver, "raw")) + wndclass.lpfnWndProc = wnd_proc_wgl_winraw; #endif }