[fix] reset to initial monitor on connection close via ResetToInitialMonitor to fix black screen

This commit is contained in:
dijunkun
2026-03-02 15:42:44 +08:00
parent b13dac2093
commit 33d51b8ce5
15 changed files with 111 additions and 4 deletions

View File

@@ -56,6 +56,7 @@ int ScreenCapturerDxgi::Init(const int fps, cb_desktop_data cb) {
}
monitor_index_ = 0;
initial_monitor_index_ = monitor_index_;
return 0;
}
@@ -128,6 +129,28 @@ int ScreenCapturerDxgi::SwitchTo(int monitor_index) {
return 0;
}
int ScreenCapturerDxgi::ResetToInitialMonitor() {
if (display_info_list_.empty()) return -1;
int target = initial_monitor_index_;
if (target < 0 || target >= (int)display_info_list_.size()) return -1;
if (monitor_index_ == target) return 0;
if (running_) {
paused_ = true;
monitor_index_ = target;
ReleaseDuplication();
if (!CreateDuplicationForMonitor(monitor_index_)) {
paused_ = false;
return -2;
}
paused_ = false;
LOG_INFO("DXGI: reset to initial monitor {}:{}", monitor_index_.load(),
display_info_list_[monitor_index_].name);
} else {
monitor_index_ = target;
}
return 0;
}
bool ScreenCapturerDxgi::InitializeDxgi() {
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG