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

This commit is contained in:
Richard Stanway 2017-05-10 23:47:44 +02:00
parent 9e95b2eb6f
commit 0c167d27a6
No known key found for this signature in database
GPG Key ID: AAC1E5265D71B3FD
3 changed files with 23 additions and 1 deletions

View File

@ -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);

View File

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

View File

@ -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);