|
@@ -36,6 +36,7 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*);
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
|
+// 2023-02-15: Inputs: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse position over non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162)
|
|
|
// 2023-02-02: Inputs: Flipping WM_MOUSEHWHEEL (horizontal mouse-wheel) value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
|
|
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
|
// 2022-09-28: Inputs: Convert WM_CHAR values with MultiByteToWideChar() when window class was registered as MBCS (not Unicode).
|
|
@@ -91,7 +92,7 @@ struct ImGui_ImplWin32_Data
|
|
|
{
|
|
|
HWND hWnd;
|
|
|
HWND MouseHwnd;
|
|
|
- bool MouseTracked;
|
|
|
+ int MouseTrackedArea; // 0: not tracked, 1: client are, 2: non-client area
|
|
|
int MouseButtonsDown;
|
|
|
INT64 Time;
|
|
|
INT64 TicksPerSecond;
|
|
@@ -290,7 +291,8 @@ static void ImGui_ImplWin32_UpdateMouseData()
|
|
|
}
|
|
|
|
|
|
// (Optional) Fallback to provide mouse position when focused (WM_MOUSEMOVE already provides this when hovered or captured)
|
|
|
- if (!io.WantSetMousePos && !bd->MouseTracked && has_mouse_screen_pos)
|
|
|
+ // This also fills a short gap when clicking non-client area: WM_NCMOUSELEAVE -> modal OS move -> gap -> WM_NCMOUSEMOVE
|
|
|
+ if (!io.WantSetMousePos && bd->MouseTrackedArea == 0 && has_mouse_screen_pos)
|
|
|
{
|
|
|
// Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
|
|
// (This is the position you can get with ::GetCursorPos() + ::ScreenToClient() or WM_MOUSEMOVE.)
|
|
@@ -587,27 +589,42 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
|
|
|
switch (msg)
|
|
|
{
|
|
|
case WM_MOUSEMOVE:
|
|
|
+ case WM_NCMOUSEMOVE:
|
|
|
{
|
|
|
// We need to call TrackMouseEvent in order to receive WM_MOUSELEAVE events
|
|
|
+ const int area = (msg == WM_MOUSEMOVE) ? 1 : 2;
|
|
|
bd->MouseHwnd = hwnd;
|
|
|
- if (!bd->MouseTracked)
|
|
|
+ if (bd->MouseTrackedArea != area)
|
|
|
{
|
|
|
- TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hwnd, 0 };
|
|
|
- ::TrackMouseEvent(&tme);
|
|
|
- bd->MouseTracked = true;
|
|
|
+ TRACKMOUSEEVENT tme_cancel = { sizeof(tme_cancel), TME_CANCEL, hwnd, 0 };
|
|
|
+ TRACKMOUSEEVENT tme_track = { sizeof(tme_track), (DWORD)((area == 2) ? (TME_LEAVE | TME_NONCLIENT) : TME_LEAVE), hwnd, 0 };
|
|
|
+ if (bd->MouseTrackedArea != 0)
|
|
|
+ ::TrackMouseEvent(&tme_cancel);
|
|
|
+ ::TrackMouseEvent(&tme_track);
|
|
|
+ bd->MouseTrackedArea = area;
|
|
|
}
|
|
|
POINT mouse_pos = { (LONG)GET_X_LPARAM(lParam), (LONG)GET_Y_LPARAM(lParam) };
|
|
|
- if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
|
|
+ bool want_absolute_pos = (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0;
|
|
|
+ if (msg == WM_MOUSEMOVE && want_absolute_pos) // WM_MOUSEMOVE are client-relative coordinates.
|
|
|
::ClientToScreen(hwnd, &mouse_pos);
|
|
|
+ if (msg == WM_NCMOUSEMOVE && !want_absolute_pos) // WM_NCMOUSEMOVE are absolute coordinates.
|
|
|
+ ::ScreenToClient(hwnd, &mouse_pos);
|
|
|
io.AddMousePosEvent((float)mouse_pos.x, (float)mouse_pos.y);
|
|
|
break;
|
|
|
}
|
|
|
case WM_MOUSELEAVE:
|
|
|
- if (bd->MouseHwnd == hwnd)
|
|
|
- bd->MouseHwnd = nullptr;
|
|
|
- bd->MouseTracked = false;
|
|
|
- io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
|
+ case WM_NCMOUSELEAVE:
|
|
|
+ {
|
|
|
+ const int area = (msg == WM_MOUSELEAVE) ? 1 : 2;
|
|
|
+ if (bd->MouseTrackedArea == area)
|
|
|
+ {
|
|
|
+ if (bd->MouseHwnd == hwnd)
|
|
|
+ bd->MouseHwnd = nullptr;
|
|
|
+ bd->MouseTrackedArea = 0;
|
|
|
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
|
|
+ }
|
|
|
break;
|
|
|
+ }
|
|
|
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
|
|
|
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:
|
|
|
case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK:
|