From a4eeb6ed02ff29b4d4b66f3d4a9cbea75ac025a4 Mon Sep 17 00:00:00 2001 From: Thomas la Cour Date: Mon, 29 Jul 2024 17:33:35 +0200 Subject: [PATCH 1/2] rawinput code --- core/sys/windows/user32.odin | 15 +++++++++++++-- tests/core/sys/windows/test_user32.odin | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/core/sys/windows/test_user32.odin diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 02cf0a54d..f1232c680 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -373,8 +373,9 @@ GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD return HIWORD(cast(DWORD)wParam) } -GET_RAWINPUT_CODE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> BYTE { - return BYTE(wParam) & 0xFF +// Retrieves the input code from wParam in WM_INPUT message. +GET_RAWINPUT_CODE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> RAWINPUT_CODE { + return RAWINPUT_CODE(wParam & 0xFF) } MAKEINTRESOURCEW :: #force_inline proc "contextless" (#any_int i: int) -> LPWSTR { @@ -398,6 +399,16 @@ DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE :: DPI_AWARENESS_CONTEXT(~uintptr(2)) DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 :: DPI_AWARENESS_CONTEXT(~uintptr(3)) // -4 DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED :: DPI_AWARENESS_CONTEXT(~uintptr(4)) // -5 +RAWINPUT_CODE :: enum { + // The input is in the regular message flow, + // the app is required to call DefWindowProc + // so that the system can perform clean ups. + RIM_INPUT = 0, + // The input is sink only. The app is expected + // to behave nicely. + RIM_INPUTSINK = 1, +} + RAWINPUTHEADER :: struct { dwType: DWORD, dwSize: DWORD, diff --git a/tests/core/sys/windows/test_user32.odin b/tests/core/sys/windows/test_user32.odin new file mode 100644 index 000000000..0778fdf41 --- /dev/null +++ b/tests/core/sys/windows/test_user32.odin @@ -0,0 +1,13 @@ +//+build windows +package test_core_sys_windows + +import "core:testing" +import win32 "core:sys/windows" + +@(test) +verify_rawinput_code :: proc(t: ^testing.T) { + testing.expect_value(t, win32.GET_RAWINPUT_CODE_WPARAM(0), win32.RAWINPUT_CODE.RIM_INPUT) + testing.expect_value(t, win32.GET_RAWINPUT_CODE_WPARAM(1), win32.RAWINPUT_CODE.RIM_INPUTSINK) + testing.expect_value(t, win32.GET_RAWINPUT_CODE_WPARAM(0x100), win32.RAWINPUT_CODE.RIM_INPUT) + testing.expect_value(t, win32.GET_RAWINPUT_CODE_WPARAM(0x101), win32.RAWINPUT_CODE.RIM_INPUTSINK) +} From 3d0519fe6c5d2db56877d9d5db5a54512cca7878 Mon Sep 17 00:00:00 2001 From: Thomas la Cour Date: Thu, 8 Aug 2024 18:05:41 +0200 Subject: [PATCH 2/2] trim whitespace --- core/sys/windows/gdi32.odin | 2 +- core/sys/windows/types.odin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index 6788ed2ea..5cbafddba 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -28,7 +28,7 @@ foreign gdi32 { SetPixelFormat :: proc(hdc: HDC, format: INT, ppfd: ^PIXELFORMATDESCRIPTOR) -> BOOL --- ChoosePixelFormat :: proc(hdc: HDC, ppfd: ^PIXELFORMATDESCRIPTOR) -> INT --- - DescribePixelFormat :: proc(hdc: HDC, iPixelFormat: INT, nBytes: UINT, ppfd: ^PIXELFORMATDESCRIPTOR) -> INT --- + DescribePixelFormat :: proc(hdc: HDC, iPixelFormat: INT, nBytes: UINT, ppfd: ^PIXELFORMATDESCRIPTOR) -> INT --- SwapBuffers :: proc(hdc: HDC) -> BOOL --- SetDCBrushColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF --- diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index e10e53cf9..d9a6bd1fd 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -2781,7 +2781,7 @@ CONTEXT :: struct { PCONTEXT :: ^CONTEXT LPCONTEXT :: ^CONTEXT -when size_of(uintptr) == 32 { +when size_of(uintptr) == 32 { XSAVE_FORMAT :: struct #align(16) { ControlWord: WORD, StatusWord: WORD,