Skip to content

Commit

Permalink
Allow moving windows to different monitors by dragging without trigge…
Browse files Browse the repository at this point in the history
…ring SK's monitor-change message (causes games to maximize the game window)
  • Loading branch information
Kaldaien committed Nov 24, 2024
1 parent 2d2a92a commit 841e49b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 32 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
24.11.24.1
24.11.24.2
==========
+ Allow moving windows to different monitors by dragging without triggering
SK's monitor-change message (causes games to maximize the game window).

24.11.24.1
==========
+ Fixed accidentally using ImGuiKey_MouseLeft to index the ImGuiIO::MouseDown
array (which only has 5 buttons; the value of ImGuiKey_MouseLeft is 653!)
Expand Down
4 changes: 2 additions & 2 deletions include/SpecialK/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#define SK_YEAR 24
#define SK_MONTH 11
#define SK_DATE 24
#define SK_REV_N 1
#define SK_REV 1
#define SK_REV_N 2
#define SK_REV 2

#ifndef _A2
#define _A2(a) #a
Expand Down
20 changes: 10 additions & 10 deletions include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -515,24 +515,24 @@ SK_ImGui_ProcessRawInput ( _In_ HRAWINPUT hRawInput,
{
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN )
io.AddMouseButtonEvent (ImGuiKey_MouseLeft, true);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_UP )
io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);
//if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_UP )
// io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN )
io.AddMouseButtonEvent (ImGuiKey_MouseRight, true);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_UP )
io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);
//if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_UP )
// io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN )
io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, true);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_UP )
io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);
//if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_UP )
// io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_4_DOWN )
io.AddMouseButtonEvent (ImGuiKey_MouseX1, true);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_4_UP )
io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
//if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_4_UP )
// io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_5_DOWN )
io.AddMouseButtonEvent (ImGuiKey_MouseX2, true);
if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_5_UP )
io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);
//if ( ((RAWINPUT *)pData)->data.mouse.ulButtons & RI_MOUSE_BUTTON_5_UP )
// io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);

if ( ((RAWINPUT *)pData)->data.mouse.usButtonFlags & RI_MOUSE_WHEEL )
{
Expand Down
21 changes: 9 additions & 12 deletions src/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7275,9 +7275,6 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)

io.KeyCtrl |= ((mhs->dwExtraInfo & MK_CONTROL) != 0);
io.KeyShift |= ((mhs->dwExtraInfo & MK_SHIFT ) != 0);

io.AddMousePosEvent (static_cast <float> (pt.x),
static_cast <float> (pt.y));
}
}
}
Expand All @@ -7301,7 +7298,7 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONUP:
if (! bPassthrough)
{
io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);

if (SK_ImGui_WantMouseButtonCapture ())
return 1;
Expand All @@ -7322,7 +7319,7 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONUP:
if (! bPassthrough)
{
io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);

if (SK_ImGui_WantMouseButtonCapture ())
return 1;
Expand All @@ -7343,7 +7340,7 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
case WM_MBUTTONUP:
if (! bPassthrough)
{
io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);

if (SK_ImGui_WantMouseButtonCapture ())
return 1;
Expand All @@ -7369,13 +7366,13 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
case WM_XBUTTONUP:
if (! bPassthrough)
{
MOUSEHOOKSTRUCTEX* mhsx =
(MOUSEHOOKSTRUCTEX*)lParam;
// MOUSEHOOKSTRUCTEX* mhsx =
//(MOUSEHOOKSTRUCTEX*)lParam;

if (((HIWORD (mhsx->mouseData)) == XBUTTON1))
io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
if (((HIWORD (mhsx->mouseData)) == XBUTTON2))
io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);
//if (((HIWORD (mhsx->mouseData)) == XBUTTON1))
// io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
//if (((HIWORD (mhsx->mouseData)) == XBUTTON2))
// io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);

if (SK_ImGui_WantMouseButtonCapture ())
return 1;
Expand Down
7 changes: 7 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4409,6 +4409,13 @@ SK_EndBufferSwap (HRESULT hr, IUnknown* device, SK_TLS* pTLS)
void SK_ImGui_DrawGraph_Latency (bool predraw);
SK_ImGui_DrawGraph_Latency (true);

// While in the size/move modal loop, continually evaluate
// window size/position and unrestrict the mouse.
if (game_window.size_move)
{
SK_Window_RepositionIfNeeded ();
}

return hr;
}

Expand Down
14 changes: 7 additions & 7 deletions src/input/winhook_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,24 @@ SK_Proxy_MouseProc (
} break;

case WM_LBUTTONUP:
io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseLeft, false);
break;

case WM_RBUTTONUP:
io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseRight, false);
break;

case WM_MBUTTONUP:
io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);
//io.AddMouseButtonEvent (ImGuiKey_MouseMiddle, false);
break;

case WM_XBUTTONUP:
{
MOUSEHOOKSTRUCTEX* mhsx =
(MOUSEHOOKSTRUCTEX*)lParam;
//MOUSEHOOKSTRUCTEX* mhsx =
// (MOUSEHOOKSTRUCTEX*)lParam;

if ((HIWORD (mhsx->mouseData)) == XBUTTON1) io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
if ((HIWORD (mhsx->mouseData)) == XBUTTON2) io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);
//if ((HIWORD (mhsx->mouseData)) == XBUTTON1) io.AddMouseButtonEvent (ImGuiKey_MouseX1, false);
//if ((HIWORD (mhsx->mouseData)) == XBUTTON2) io.AddMouseButtonEvent (ImGuiKey_MouseX2, false);
} break;
}
} break;
Expand Down
6 changes: 6 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,8 @@ SK_Window_RepositionIfNeeded (void)

SK_RunOnce (rb.updateOutputTopology ());

bool move_monitors = rb.monitor != rb.next_monitor && rb.next_monitor != 0;

//HMONITOR hMonitorBeforeRepos =
// MonitorFromWindow (game_window.hWnd, MONITOR_DEFAULTTONEAREST);

Expand Down Expand Up @@ -3619,6 +3621,10 @@ SK_Window_RepositionIfNeeded (void)
SK_Display_ResolutionSelectUI (true);
rb.gsync_state.update (true);

// We programatically moved the window to a different monitor, so we need to
// send the game a few messages to get the SwapChain to be owned by that
// monitor...
if (move_monitors || !config.display.monitor_path_ccd.empty ())
// This generally helps (Unity engine games mostly) to apply SwapChain overrides
// immediately, but ATLUS games will respond by moving the game back to the primary
// monitor...
Expand Down

0 comments on commit 841e49b

Please sign in to comment.