Skip to content

Commit

Permalink
Optimized mouse cursor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Dec 29, 2024
1 parent 0170de9 commit 05052fc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/SpecialK/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,8 @@ bool SK_Window_IsCursorActive (void);
bool SK_ImGui_CursorWarpingCooledDown (void);
void SK_ImGui_UpdateLastCursorWarpTime (void);

extern bool SK_ImGui_IsHWCursorVisible;

enum SK_InputEnablement {
Enabled = 0,
Disabled = 1,
Expand Down
15 changes: 9 additions & 6 deletions include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3243,7 +3243,8 @@ SK_ImGui_UpdateClassCursor (void)
extern HWND SK_CachedForegroundWindow;
extern DWORD SK_CachedForegroundWindowTime;

HANDLE hPollCursorEvent;
HANDLE hPollCursorEvent;
bool SK_ImGui_IsHWCursorVisible = false;

DWORD
WINAPI
Expand All @@ -3260,6 +3261,8 @@ SK_ImGui_CursorPollingThread (LPVOID)
SK_GetCursorPos (&SK_ImGui_LastKnownCursorPos);
SK_ImGui_LastKnownCursor =
SK_GetCursor ();
SK_ImGui_IsHWCursorVisible =
SK_InputUtil_IsHWCursorVisible ();
}

SK_Thread_CloseSelf ();
Expand All @@ -3286,10 +3289,10 @@ SK_ImGui_User_NewFrame (void)

SetEvent (hPollCursorEvent);

bool capture_mouse = SK_ImGui_WantMouseCapture (false, &cursor_pos);
bool anything_hovered = SK_ImGui_IsAnythingHovered ();
HWND hWndForeground = SK_GetForegroundWindow ();
BOOL bHWCursorVisible = SK_InputUtil_IsHWCursorVisible ();
bool capture_mouse = SK_ImGui_WantMouseCapture (false, &cursor_pos);
bool anything_hovered = SK_ImGui_IsAnythingHovered ();
HWND hWndForeground = SK_GetForegroundWindow ();
BOOL bHWCursorVisible = SK_ImGui_IsHWCursorVisible;

SK_CachedForegroundWindow = hWndForeground;
SK_CachedForegroundWindowTime = SK::ControlPanel::current_time;
Expand Down Expand Up @@ -3707,7 +3710,7 @@ SK_ImGui_User_NewFrame (void)
}

io.MouseDrawCursor =
(! SK_InputUtil_IsHWCursorVisible ());
(! SK_ImGui_IsHWCursorVisible);
}

else
Expand Down
2 changes: 1 addition & 1 deletion src/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ SK_Display_ResolutionSelectUI (bool bMarkDirty)
ImGui::PopItemWidth ();
}

static BOOL bDPIAware =
static bool bDPIAware =
IsProcessDPIAware (),
bImmutableDPI = FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/control_panel/cfg_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ SK_ImGui_CursorBoundaryConfig (bool window_mgmt = false)
{
if (SK_ImGui_Cursor.force == sk_cursor_state::None)
{
if (! SK_InputUtil_IsHWCursorVisible ())
if (! SK_ImGui_IsHWCursorVisible)
{
if (ImGui::Button (" Force Mouse Cursor Visible "))
{
Expand Down
6 changes: 3 additions & 3 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ ImGuiCursor_Impl (void)
if (SK_ImGui_WantHWCursor ())
{
io.MouseDrawCursor =
( (! SK_ImGui_Cursor.idle) && SK_ImGui_IsMouseRelevant () && (! SK_InputUtil_IsHWCursorVisible ()));
( (! SK_ImGui_Cursor.idle) && SK_ImGui_IsMouseRelevant () && (! SK_ImGui_IsHWCursorVisible));
}

//
Expand All @@ -505,7 +505,7 @@ ImGuiCursor_Impl (void)
SK_SendMsgSetCursor (0);
}

io.MouseDrawCursor = (! SK_ImGui_Cursor.idle) && (! SK_InputUtil_IsHWCursorVisible ());
io.MouseDrawCursor = (! SK_ImGui_Cursor.idle) && (! SK_ImGui_IsHWCursorVisible);
}
}

Expand Down Expand Up @@ -609,7 +609,7 @@ SK_ImGui_WantMouseCaptureEx (DWORD dwReasonMask, POINT *pptCursor)
if (game_window.mouse.can_track && (! game_window.mouse.inside) && config.input.mouse.disabled_to_game == SK_InputEnablement::DisabledInBackground)
imgui_capture = true;

else if (config.input.ui.capture_hidden && (! SK_InputUtil_IsHWCursorVisible ()))
else if (config.input.ui.capture_hidden && (! SK_ImGui_IsHWCursorVisible))
imgui_capture = true;

if (game_window.active && ReadULong64Acquire (&config.input.mouse.temporarily_allow) > SK_GetFramesDrawn () - 20)
Expand Down
2 changes: 1 addition & 1 deletion src/render/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ SK_ScreenshotManager::setSnipState (SK_ScreenshotManager::SnippingState state)
else if (state == SnippingRequested ||
state == SnippingActive)
{
if (! SK_InputUtil_IsHWCursorVisible ())
if (! SK_ImGui_IsHWCursorVisible)
{
do
{
Expand Down

0 comments on commit 05052fc

Please sign in to comment.