Skip to content

Commit 11d1f4b

Browse files
committed
Add port related info to display ID
1 parent afefdfa commit 11d1f4b

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/platform/windows/display_device/windows_utils.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace display_device {
257257
// b) Either a bus number or has something to do with device capabilities - stable
258258
// c) Another ID, somehow tied to adapter (not an adapter ID from path list) - stable
259259
// d) Some sort of rotating counter thing, changes after driver reinstall - unstable
260-
// e) Seems to be the same as a target ID from path, it changes based on GPU port - unstable
260+
// e) Seems to be the same as a target ID from path, it changes based on GPU port - semi-stable
261261
//
262262
// The instance ID also seems to be a part of the registry key (in case some other info is needed in the future):
263263
// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\ACI27EC\5&4fd2de4&5&UID4352
@@ -273,22 +273,30 @@ namespace display_device {
273273
break;
274274
}
275275

276-
// We are going to discard the unstable parts of the instance ID and merge the stable parts with the edid buffer
277-
auto index = instance_id.find_first_of(L'&', 0);
278-
if (index != std::wstring::npos) {
279-
index++;
280-
index = index < instance_id.size() ? instance_id.find_first_of(L'&', index) : std::wstring::npos;
276+
// We are going to discard the unstable parts of the instance ID and merge the stable parts with the edid buffer (if available)
277+
auto unstable_part_index = instance_id.find_first_of(L'&', 0);
278+
if (unstable_part_index != std::wstring::npos) {
279+
unstable_part_index = instance_id.find_first_of(L'&', unstable_part_index + 1);
281280
}
282281

283-
if (index == std::wstring::npos) {
284-
BOOST_LOG(error) << "failed to split the instance id string " << convert_to_string(instance_id);
282+
if (unstable_part_index == std::wstring::npos) {
283+
BOOST_LOG(error) << "failed to split off the stable part from instance id string " << convert_to_string(instance_id);
285284
break;
286285
}
287286

288-
BOOST_LOG(verbose) << "creating device id for path " << convert_to_string(device_path) << " from EDID and instance ID: " << convert_to_string({ std::begin(instance_id), std::begin(instance_id) + index });
287+
auto semi_stable_part_index = instance_id.find_first_of(L'&', unstable_part_index + 1);
288+
if (semi_stable_part_index == std::wstring::npos) {
289+
BOOST_LOG(error) << "failed to split off the semi-stable part from instance id string " << convert_to_string(instance_id);
290+
break;
291+
}
292+
293+
BOOST_LOG(verbose) << "creating device id for path " << convert_to_string(device_path) << " from EDID and instance ID: " << convert_to_string({ std::begin(instance_id), std::begin(instance_id) + unstable_part_index }) << convert_to_string({ std::begin(instance_id) + semi_stable_part_index, std::end(instance_id) });
289294
device_id_data.insert(std::end(device_id_data),
290295
reinterpret_cast<const BYTE *>(instance_id.data()),
291-
reinterpret_cast<const BYTE *>(instance_id.data() + index));
296+
reinterpret_cast<const BYTE *>(instance_id.data() + unstable_part_index));
297+
device_id_data.insert(std::end(device_id_data),
298+
reinterpret_cast<const BYTE *>(instance_id.data() + semi_stable_part_index),
299+
reinterpret_cast<const BYTE *>(instance_id.data() + instance_id.size()));
292300
break;
293301
}
294302
}

0 commit comments

Comments
 (0)