Skip to content

Commit

Permalink
Removed foreground window HWND caching, the WinEventHookProc does not…
Browse files Browse the repository at this point in the history
… order the events it sends coherently.
  • Loading branch information
Kaldaien committed Dec 29, 2024
1 parent 438ae91 commit 1896bdb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
24.12.29.3
24.12.29.4
==========
+ Removed foreground window HWND caching, the WinEventHookProc does
not order the events it sends coherently.
+ Added extra checks to ensure mouse cursor can activate games when
clicking on the control panel while the window is in the background.

24.12.29.3
==========
+ Change SK_Thread_HybridSpinlock (Critical Section + Spinlock) w/
a recursive SRWLock implementation for testing.
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 12
#define SK_DATE 29
#define SK_REV_N 3
#define SK_REV 3
#define SK_REV_N 4
#define SK_REV 4

#ifndef _A2
#define _A2(a) #a
Expand Down
26 changes: 22 additions & 4 deletions src/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7251,7 +7251,7 @@ LRESULT
CALLBACK
SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
{
if (code < 0 || GImGui == nullptr || GImGui->CurrentWindow == nullptr) // We saw nothing (!!)
if (code < 0 || GImGui == nullptr) // We saw nothing (!!)
return CallNextHookEx (0, code, wParam, lParam);

auto& io =
Expand All @@ -7276,8 +7276,26 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
{
bPassthrough = false;

SK_ImGui_LastKnownCursorPos = POINT (mhs->pt);

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

SK_ImGui_Cursor.ClientToLocal (&pt);
SK_ImGui_Cursor.pos = pt;

io.MousePos = {
(float)pt.x,
(float)pt.y
};

io.AddMousePosEvent ((float)pt.x, (float)pt.y);
}

else
{
io.MousePos = {-FLT_MAX, -FLT_MAX};
io.AddMousePosEvent (-FLT_MAX, -FLT_MAX);
}
}
}
Expand All @@ -7293,7 +7311,7 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
// Only capture mouse clicks when the window is in the foreground, failure to let
// left-clicks passthrough would prevent activating the game window.
if ( game_window.active && SK_ImGui_WantMouseButtonCapture () &&
game_window.hWnd == SK_GetForegroundWindow () )
game_window.hWnd == SK_GetForegroundWindow () )
return 1;
}
break;
Expand Down Expand Up @@ -7444,9 +7462,9 @@ extern ULONG64 SK_ImGui_LastKeyboardInputFrame;

LRESULT
CALLBACK
SK_ImGui_KeyboardProc (int code, WPARAM wParam, LPARAM lParam)
SK_ImGui_KeyboardProc (int code, WPARAM wParam, LPARAM lParam)
{
if (code < 0 || (! SK_IsGameWindowActive ())) // We saw nothing (!!)
if (code < 0 || GImGui == nullptr) // We saw nothing (!!)
return CallNextHookEx (0, code, wParam, lParam);

const bool keyboard_capture =
Expand Down
6 changes: 0 additions & 6 deletions src/injection/injection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,6 @@ SK_Inject_WinEventHookProc (

if (event == EVENT_SYSTEM_FOREGROUND)
{
extern HWND SK_CachedForegroundWindow;
extern DWORD SK_CachedForegroundWindowTime;

SK_CachedForegroundWindow = hwnd;
SK_CachedForegroundWindowTime = dwmsEventTime;

bool is_smart_always_on_top =
config.window.always_on_top == SmartAlwaysOnTop;

Expand Down

0 comments on commit 1896bdb

Please sign in to comment.