mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-05 02:37:50 -04:00
Use same conditions for cursor grabbing as for capture
This commit is contained in:
+1
-25
@@ -42,10 +42,6 @@ bool wantMouseCapture() {
|
||||
return getSettings().game.enableMouseCamera.getValue() || queryMouseAimContext();
|
||||
}
|
||||
|
||||
bool wantMouseGrab() {
|
||||
return getSettings().game.enableMouseCamera.getValue() || getSettings().game.enableMouseAim.getValue();
|
||||
}
|
||||
|
||||
bool isWindowFocused(SDL_Window* window) {
|
||||
if (window == nullptr) {
|
||||
return false;
|
||||
@@ -60,13 +56,6 @@ bool shouldCaptureMouse(SDL_Window* window) {
|
||||
return wantMouseCapture() && isWindowFocused(window);
|
||||
}
|
||||
|
||||
bool shouldGrabMouse(SDL_Window* window) {
|
||||
if (window == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return wantMouseGrab() && isWindowFocused(window);
|
||||
}
|
||||
|
||||
bool syncCaptureState(SDL_Window* window, bool should_capture) {
|
||||
if (window == nullptr) {
|
||||
reset_deltas();
|
||||
@@ -75,6 +64,7 @@ bool syncCaptureState(SDL_Window* window, bool should_capture) {
|
||||
|
||||
const bool was_captured = SDL_GetWindowRelativeMouseMode(window);
|
||||
if (was_captured != should_capture) {
|
||||
SDL_SetWindowMouseGrab(window, should_capture);
|
||||
SDL_SetWindowRelativeMouseMode(window, should_capture);
|
||||
}
|
||||
|
||||
@@ -96,17 +86,6 @@ bool syncCaptureState(SDL_Window* window, bool should_capture) {
|
||||
return is_captured;
|
||||
}
|
||||
|
||||
void syncGrabState(SDL_Window* window, bool should_grab) {
|
||||
if (window == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool was_grabbed = SDL_GetWindowMouseGrab(window);
|
||||
if (was_grabbed != should_grab) {
|
||||
SDL_SetWindowMouseGrab(window, should_grab);
|
||||
}
|
||||
}
|
||||
|
||||
void accumulateDeltas(float mx_rel, float my_rel, bool camera_active, bool aim_active) {
|
||||
const auto& game = getSettings().game;
|
||||
const bool mirror_mode = game.enableMirrorMode.getValue();
|
||||
@@ -174,7 +153,6 @@ void read() {
|
||||
SDL_Window* window = aurora::window::get_sdl_window();
|
||||
const bool capture_active = syncCaptureState(window, shouldCaptureMouse(window));
|
||||
update_cursor_visibility(window, capture_active);
|
||||
syncGrabState(window, shouldGrabMouse(window));
|
||||
|
||||
if (!capture_active) {
|
||||
return;
|
||||
@@ -221,7 +199,6 @@ void onFocusLost() {
|
||||
SDL_Window* window = aurora::window::get_sdl_window();
|
||||
if (window != nullptr) {
|
||||
syncCaptureState(window, false);
|
||||
syncGrabState(window, false);
|
||||
}
|
||||
s_idle_frames = 0;
|
||||
set_cursor_visible(true);
|
||||
@@ -230,6 +207,5 @@ void onFocusLost() {
|
||||
void onFocusGained() {
|
||||
SDL_Window* window = aurora::window::get_sdl_window();
|
||||
syncCaptureState(window, shouldCaptureMouse(window));
|
||||
syncGrabState(window, shouldGrabMouse(window));
|
||||
}
|
||||
} // namespace dusk::mouse
|
||||
|
||||
Reference in New Issue
Block a user