浏览代码

[dx] Prevent ClipCursor when window have focus but is not foreground (#781)

Yuxiao Mao 4 月之前
父节点
当前提交
5da7d242c4
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      libs/directx/window.c

+ 8 - 1
libs/directx/window.c

@@ -83,7 +83,8 @@ typedef enum {
 	RButton = 8,
 	MButton = 16,
 	XButton1 = 32,
-	XButton2 = 64
+	XButton2 = 64,
+	NotForeground = 128
 } mouse_capture_flags;
 static int disable_capture = 0;
 static bool capture_mouse = false;
@@ -396,6 +397,12 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 		addState(Blur);
 		break;
 	case WM_WINDOWPOSCHANGED:
+		HWND wndFg = GetForegroundWindow();
+		if( wndFg != wnd ) {
+			disable_capture |= NotForeground;
+		} else {
+			disable_capture &= ~NotForeground;
+		}
 		updateClipCursor(wnd);
 		break;
 	case WM_GETMINMAXINFO: