Skip to content

Commit 1978c56

Browse files
committed
relative mouse movement suppresion
1 parent c89024c commit 1978c56

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

sources/libengine/window/window.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace cage
5959
bool focus = true;
6060
bool mouseIntendVisible = true;
6161
bool mouseIntendRelative = false;
62-
bool mouseAllowRelativeMovement = false; // prevent mouse jumping shortly after switching from absolute to relative movement
62+
uint8 mouseSupressRelativeMovement = 0; // prevent mouse jumping shortly after switching from absolute to relative movement
6363

6464
#ifdef GCHL_WINDOWS_THREAD
6565
Holder<Thread> windowThread;
@@ -191,7 +191,7 @@ namespace cage
191191
if constexpr (std::is_same_v<T, input::MouseRelativeMove>)
192192
{
193193
CAGE_ASSERT(i.relative);
194-
if (!mouseAllowRelativeMovement)
194+
if (mouseSupressRelativeMovement > 0)
195195
return;
196196
const Vec2 n = i.position;
197197
if (valid(lastRelativePosition))
@@ -298,7 +298,8 @@ namespace cage
298298
}
299299
}
300300

301-
mouseAllowRelativeMovement = true;
301+
if (mouseSupressRelativeMovement > 0)
302+
mouseSupressRelativeMovement--;
302303
}
303304
};
304305

@@ -646,7 +647,7 @@ namespace cage
646647
if (impl->mouseIntendRelative != relative)
647648
impl->lastRelativePosition = Vec2::Nan();
648649
impl->mouseIntendRelative = relative;
649-
impl->mouseAllowRelativeMovement = false;
650+
impl->mouseSupressRelativeMovement = 2;
650651
}
651652

652653
Vec2 Window::mousePosition() const

0 commit comments

Comments
 (0)