Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mouse _MOUSEMOVEMENTX/Y issue on Windows on ARM with C++ optimizations #599

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions internal/c/parts/core/freeglut/freeglut_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,8 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
{
// QB64-PE: custom code begin
static int raw_setup = 0;
static RAWINPUTDEVICE Rid[1];
static RAWINPUTDEVICE rawInputDevice;
static RAWINPUT rawInput;
int qb64_os_event_info = 0;
LRESULT qb64_os_event_return = 1;

Expand Down Expand Up @@ -2051,16 +2052,14 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
return 0;

// QB64-PE: custom code begin
// Adapted from https://learn.microsoft.com/en-us/windows/win32/dxtecharts/taking-advantage-of-high-dpi-mouse-movement
case WM_INPUT: {
if (raw_setup) {
// Adapted from http://msdn.microsoft.com/en-us/library/windows/desktop/ee418864%28v=vs.85%29.aspx#WM_INPUT
UINT dwSize = sizeof(RAWINPUT);
static BYTE lpb[sizeof(RAWINPUT)];
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
RAWINPUT *raw = (RAWINPUT *)lpb;
if (raw->header.dwType == RIM_TYPEMOUSE) {
int xPosRelative = raw->data.mouse.lLastX;
int yPosRelative = raw->data.mouse.lLastY;
UINT dwSize = sizeof(rawInput);
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, (LPVOID)&rawInput, &dwSize, sizeof(RAWINPUTHEADER));
if (rawInput.header.dwType == RIM_TYPEMOUSE) {
LONG xPosRelative = rawInput.data.mouse.lLastX;
LONG yPosRelative = rawInput.data.mouse.lLastY;
if (xPosRelative || yPosRelative)
qb64_custom_event(QB64_EVENT_RELATIVE_MOUSE_MOVEMENT, xPosRelative, yPosRelative, 0, 0, 0, 0, 0, 0, NULL, NULL);
}
Expand All @@ -2071,7 +2070,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,

case WM_MOUSEMOVE:
{
// QB64-PE: custom code begin
// QB64-PE: custom code begin
if (!raw_setup) {
raw_setup = 1;
# ifndef HID_USAGE_PAGE_GENERIC
Expand All @@ -2080,13 +2079,13 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
# ifndef HID_USAGE_GENERIC_MOUSE
# define HID_USAGE_GENERIC_MOUSE ((USHORT)0x02)
# endif
Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE;
Rid[0].dwFlags = RIDEV_INPUTSINK;
Rid[0].hwndTarget = window->Window.Handle;
RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));
rawInputDevice.usUsagePage = HID_USAGE_PAGE_GENERIC;
rawInputDevice.usUsage = HID_USAGE_GENERIC_MOUSE;
rawInputDevice.dwFlags = RIDEV_INPUTSINK;
rawInputDevice.hwndTarget = window->Window.Handle;
RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice));
}
// QB64-PE: custom code end
// QB64-PE: custom code end

#if defined(_WIN32_WCE)
window->State.MouseX = 320-HIWORD( lParam );
Expand Down
16 changes: 8 additions & 8 deletions setup_mingw.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ rem MINGW_DIR is actually the internal directory name inside the zip file
rem It needs to be updated whenever the toolchains are updated
if "%ARCH%" == "ARM" (
if %BITS% == 64 (
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20241203/llvm-mingw-20241203-ucrt-aarch64.zip"
set MINGW_DIR=llvm-mingw-20241203-ucrt-aarch64
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-aarch64.zip"
set MINGW_DIR=llvm-mingw-20250114-ucrt-aarch64
) else (
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20241203/llvm-mingw-20241203-ucrt-armv7.zip"
set MINGW_DIR=llvm-mingw-20241203-ucrt-armv7
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-armv7.zip"
set MINGW_DIR=llvm-mingw-20250114-ucrt-armv7
)
) else (
if %BITS% == 64 (
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20241203/llvm-mingw-20241203-ucrt-x86_64.zip"
set MINGW_DIR=llvm-mingw-20241203-ucrt-x86_64
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-x86_64.zip"
set MINGW_DIR=llvm-mingw-20250114-ucrt-x86_64
) else (
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20241203/llvm-mingw-20241203-ucrt-i686.zip"
set MINGW_DIR=llvm-mingw-20241203-ucrt-i686
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-i686.zip"
set MINGW_DIR=llvm-mingw-20250114-ucrt-i686
)
)

Expand Down