Skip to content

Commit 2cc45a4

Browse files
committed
Fix cursor lock making inspector non-interactive (fixes #2)
1 parent 415d87f commit 2cc45a4

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

UnityInspector/src/gui/window/window.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void Window::OnPresent()
8383
io.IniFilename = nullptr;
8484
io.IniSavingRate = 0.f;
8585
io.LogFilename = nullptr;
86+
io.MouseDrawCursor = true;
8687
SetMenuStyle();
8788

8889
if (ImGui_ImplWin32_Init(dx_hook::Hk11::GetHwnd()) && ImGui_ImplDX11_Init(device, context))
@@ -142,23 +143,37 @@ LRESULT Window::MyWndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
142143
return 2;
143144
}
144145
}
145-
146-
if (ImGui::GetIO().WantCaptureKeyboard) {
147-
switch (uMsg) {
148-
case WM_KEYDOWN:
149-
case WM_KEYUP:
150-
case WM_CHAR:
151-
if (uMsg == WM_KEYDOWN && wParam == VK_INSERT) {
152-
Core::config->inspector.Enabled = !Core::config->inspector.Enabled;
153-
}
154-
return 2;
155-
}
156-
}
157146
}
158147

159-
if (uMsg == WM_KEYDOWN && wParam == VK_INSERT) {
160-
Core::config->inspector.Enabled = !Core::config->inspector.Enabled;
161-
return 2;
148+
if (uMsg == WM_KEYDOWN)
149+
{
150+
switch (wParam)
151+
{
152+
case VK_INSERT:
153+
{
154+
auto& menu = Core::config->inspector.Enabled;
155+
menu = !menu;
156+
ImGui::GetIO().MouseDrawCursor = menu;
157+
ClipCursor(nullptr);
158+
return 2;
159+
}
160+
case VK_F5:
161+
{
162+
// toggles cursor visibility
163+
static bool cursor = false;
164+
cursor = !cursor;
165+
cursor ? ShowCursor(TRUE) : ShowCursor(FALSE);
166+
return 2;
167+
}
168+
case VK_F6:
169+
{
170+
// unlocks cursor
171+
ClipCursor(nullptr);
172+
return 2;
173+
}
174+
default:
175+
break;
176+
}
162177
}
163178

164179
return 1;

0 commit comments

Comments
 (0)