@@ -92,6 +92,7 @@ static struct {
92
92
float mouse_wheel[2 ];
93
93
LARGE_INTEGER previous_present_time;
94
94
bool is_mouse_captured;
95
+ bool in_focus;
95
96
96
97
void (*on_fullscreen_changed)(bool is_now_fullscreen);
97
98
bool (*on_key_down)(int scancode);
@@ -438,10 +439,14 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
438
439
GetMonitorHzPeriod (dxgi.h_Monitor , dxgi.detected_hz , dxgi.display_period );
439
440
break ;
440
441
case WM_SETFOCUS:
442
+ dxgi.in_focus = true ;
441
443
if (dxgi.is_mouse_captured ) {
442
444
apply_mouse_capture_clip ();
443
445
}
444
446
break ;
447
+ case WM_KILLFOCUS:
448
+ dxgi.in_focus = false ;
449
+ break ;
445
450
default :
446
451
return DefWindowProcW (h_wnd, message, w_param, l_param);
447
452
}
@@ -567,13 +572,16 @@ static void gfx_dxgi_get_mouse_pos(int32_t* x, int32_t* y) {
567
572
}
568
573
569
574
static void gfx_dxgi_get_mouse_delta (int32_t * x, int32_t * y) {
570
- if (dxgi.is_mouse_captured ) {
575
+ if (dxgi.is_mouse_captured && dxgi. in_focus ) {
571
576
POINT p;
572
577
GetCursorPos (&p);
573
578
ScreenToClient (dxgi.h_wnd , &p);
574
- *x = p.x - dxgi.current_width / 2 ;
575
- *y = p.y - dxgi.current_height / 2 ;
576
- SetCursorPos (dxgi.current_width / 2 , dxgi.current_height / 2 );
579
+ int32_t centerX, centerY;
580
+ centerX = dxgi.current_width / 2 ;
581
+ centerY = dxgi.current_height / 2 ;
582
+ *x = p.x - centerX;
583
+ *y = p.y - centerY;
584
+ SetCursorPos (dxgi.posX + centerX, dxgi.posY + centerY);
577
585
} else {
578
586
*x = 0 ;
579
587
*y = 0 ;
0 commit comments