Răsfoiți Sursa

win-capture: Hide cursor when in background (window capture)

Richard Stanway 8 ani în urmă
părinte
comite
0c167d27a6

+ 1 - 1
plugins/win-capture/dc-capture.c

@@ -167,7 +167,7 @@ void dc_capture_capture(struct dc_capture *capture, HWND window)
 
 	ReleaseDC(NULL, hdc_target);
 
-	if (capture->cursor_captured)
+	if (capture->cursor_captured && !capture->cursor_hidden)
 		draw_cursor(capture, hdc, window);
 
 	dc_capture_release_dc(capture);

+ 1 - 0
plugins/win-capture/dc-capture.h

@@ -23,6 +23,7 @@ struct dc_capture {
 
 	bool         capture_cursor;
 	bool         cursor_captured;
+	bool         cursor_hidden;
 	CURSORINFO   ci;
 
 	bool         valid;

+ 21 - 0
plugins/win-capture/window-capture.c

@@ -26,6 +26,7 @@ struct window_capture {
 	struct dc_capture    capture;
 
 	float                resize_timer;
+	float                cursor_check_time;
 
 	HWND                 window;
 	RECT                 last_rect;
@@ -134,6 +135,7 @@ static obs_properties_t *wc_properties(void *unused)
 }
 
 #define RESIZE_CHECK_TIME 0.2f
+#define CURSOR_CHECK_TIME 0.2f
 
 static void wc_tick(void *data, float seconds)
 {
@@ -162,6 +164,25 @@ static void wc_tick(void *data, float seconds)
 		return;
 	}
 
+	wc->cursor_check_time += seconds;
+	if (wc->cursor_check_time > CURSOR_CHECK_TIME) {
+		DWORD foreground_pid, target_pid;
+
+		// Can't just compare the window handle in case of app with child windows
+		if (!GetWindowThreadProcessId(GetForegroundWindow(), &foreground_pid))
+			foreground_pid = 0;
+
+		if (!GetWindowThreadProcessId(wc->window, &target_pid))
+			target_pid = 0;
+
+		if (foreground_pid && target_pid && foreground_pid != target_pid)
+			wc->capture.cursor_hidden = true;
+		else
+			wc->capture.cursor_hidden = false;
+
+		wc->cursor_check_time = 0.0f;
+	}
+
 	obs_enter_graphics();
 
 	GetClientRect(wc->window, &rect);