Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ANSH3LL committed Sep 16, 2021
1 parent 46d87bd commit 59a3252
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions shared/PluginHwCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int luaopen_plugin_hwcursor(lua_State *L) {
// ----------------------------------------------------------------------------

HWND windowHandle;
LONG_PTR prevWndProc;
WNDPROC prevWndProc;
HCURSOR currentCursor;
bool cursorHidden = false;

Expand All @@ -59,7 +59,10 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
else {
result = CallWindowProc((WNDPROC)prevWndProc, hwnd, uMsg, wParam, lParam);
if(uMsg == WM_NCDESTROY) {
currentCursor = NULL;
}
result = CallWindowProc(prevWndProc, hwnd, uMsg, wParam, lParam);
}

return result;
Expand All @@ -69,8 +72,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

static int initPlugin(lua_State *L) {
windowHandle = GetForegroundWindow();
prevWndProc = SetWindowLongPtr(windowHandle, GWLP_WNDPROC, (LONG)WindowProc);
CoronaLuaLog(L, "init");
prevWndProc = (WNDPROC)SetWindowLongPtr(windowHandle, GWLP_WNDPROC, (LONG_PTR)&WindowProc);
return 0;
}

Expand All @@ -80,7 +82,6 @@ static int loadCursor(lua_State *L) {
std::string cursorLoc = lua_tostring(L, 1);
currentCursor = LoadCursorFromFile(s2ws(cursorLoc).c_str());
SetCursor(currentCursor);
CoronaLuaLog(L, cursorLoc.c_str());
return 0;
}

Expand All @@ -95,15 +96,17 @@ static int freeCursor(lua_State *L) {
static int showCursor(lua_State *L) {
if(cursorHidden) {
ShowCursor(true);
cursorHidden = false;
}
return 0;
}

// ----------------------------------------------------------------------------

static int hideCursor(lua_State *L) {
if (!cursorHidden) {
if(!cursorHidden) {
ShowCursor(false);
cursorHidden = true;
}
return 0;
}
Expand All @@ -113,4 +116,4 @@ static int hideCursor(lua_State *L) {
static int resetCursor(lua_State *L) {
currentCursor = NULL;
return 0;
}
}

0 comments on commit 59a3252

Please sign in to comment.