make mouse movement and capture depend on window focus

This commit is contained in:
veclavtalica
2025-01-14 02:07:54 +03:00
parent dbe6217e24
commit 86bf16b680
3 changed files with 17 additions and 2 deletions

View File

@ -218,7 +218,7 @@ void input_state_deinit(InputState *input) {
void input_state_update(InputState *input) {
/* TODO: don't spam it if it happens */
if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture) != 0)
if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture && ctx.window_mouse_resident) != 0)
log_warn("(%s) Mouse capture isn't supported.", __func__);
int x, y;
@ -231,7 +231,9 @@ void input_state_update(InputState *input) {
input->mouse_relative_position = (Vec2){ (float)x, (float)y };
ctx.game.mouse_position = input->mouse_window_position;
ctx.game.mouse_movement = input->mouse_relative_position;
if (ctx.window_mouse_resident)
ctx.game.mouse_movement = input->mouse_relative_position;
for (size_t i = 0; i < shlenu(input->action_hash); ++i) {
Action *action = &input->action_hash[i].value;