@@ -396,18 +396,16 @@ namespace display_device::w_utils {
396396
397397 boost::optional<UINT32 >
398398 get_source_index (const DISPLAYCONFIG_PATH_INFO &path, const std::vector<DISPLAYCONFIG_MODE_INFO > &modes) {
399- UINT32 index {};
400- if (path.flags & DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE ) {
401- index = path.sourceInfo .sourceModeInfoIdx ;
402- if (index == DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID ) {
403- return boost::none;
404- }
405- }
406- else {
407- index = path.sourceInfo .modeInfoIdx ;
408- if (index == DISPLAYCONFIG_PATH_MODE_IDX_INVALID ) {
409- return boost::none;
410- }
399+ // The MS docs is not clear when to access union struct or not. It appears that union struct is available,
400+ // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying.
401+ //
402+ // The docs state, however, that it is only available when
403+ // DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but that is just BS (maybe copy-pasta mistake), because some cases
404+ // were found where the flag is not set and the union is still being used.
405+
406+ const UINT32 index { path.sourceInfo .sourceModeInfoIdx };
407+ if (index == DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID ) {
408+ return boost::none;
411409 }
412410
413411 if (index >= modes.size ()) {
@@ -420,65 +418,69 @@ namespace display_device::w_utils {
420418
421419 void
422420 set_source_index (DISPLAYCONFIG_PATH_INFO &path, const boost::optional<UINT32 > &index) {
423- if (path.flags & DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE ) {
424- if (index) {
425- path.sourceInfo .sourceModeInfoIdx = *index;
426- }
427- else {
428- path.sourceInfo .sourceModeInfoIdx = DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID ;
429- }
421+ // The MS docs is not clear when to access union struct or not. It appears that union struct is available,
422+ // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying.
423+ //
424+ // The docs state, however, that it is only available when
425+ // DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but that is just BS (maybe copy-pasta mistake), because some cases
426+ // were found where the flag is not set and the union is still being used.
427+
428+ if (index) {
429+ path.sourceInfo .sourceModeInfoIdx = *index;
430430 }
431431 else {
432- if (index) {
433- path.sourceInfo .modeInfoIdx = *index;
434- }
435- else {
436- path.sourceInfo .modeInfoIdx = DISPLAYCONFIG_PATH_MODE_IDX_INVALID ;
437- }
432+ path.sourceInfo .sourceModeInfoIdx = DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID ;
438433 }
439434 }
440435
441436 void
442437 set_target_index (DISPLAYCONFIG_PATH_INFO &path, const boost::optional<UINT32 > &index) {
443- if (path.flags & DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE ) {
444- if (index) {
445- path.targetInfo .targetModeInfoIdx = *index;
446- }
447- else {
448- path.targetInfo .targetModeInfoIdx = DISPLAYCONFIG_PATH_TARGET_MODE_IDX_INVALID ;
449- }
438+ // The MS docs is not clear when to access union struct or not. It appears that union struct is available,
439+ // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying.
440+ //
441+ // The docs state, however, that it is only available when
442+ // DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but that is just BS (maybe copy-pasta mistake), because some cases
443+ // were found where the flag is not set and the union is still being used.
444+
445+ if (index) {
446+ path.targetInfo .targetModeInfoIdx = *index;
450447 }
451448 else {
452- if (index) {
453- path.targetInfo .modeInfoIdx = *index;
454- }
455- else {
456- path.targetInfo .modeInfoIdx = DISPLAYCONFIG_PATH_MODE_IDX_INVALID ;
457- }
449+ path.targetInfo .targetModeInfoIdx = DISPLAYCONFIG_PATH_TARGET_MODE_IDX_INVALID ;
458450 }
459451 }
460452
461453 void
462454 set_desktop_index (DISPLAYCONFIG_PATH_INFO &path, const boost::optional<UINT32 > &index) {
463- if (path.flags & DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE ) {
464- if (index) {
465- path.targetInfo .desktopModeInfoIdx = *index;
466- }
467- else {
468- path.targetInfo .desktopModeInfoIdx = DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID ;
469- }
455+ // The MS docs is not clear when to access union struct or not. It appears that union struct is available,
456+ // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying.
457+ //
458+ // The docs state, however, that it is only available when
459+ // DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but that is just BS (maybe copy-pasta mistake), because some cases
460+ // were found where the flag is not set and the union is still being used.
461+
462+ if (index) {
463+ path.targetInfo .desktopModeInfoIdx = *index;
464+ }
465+ else {
466+ path.targetInfo .desktopModeInfoIdx = DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID ;
470467 }
471468 }
472469
473470 void
474471 set_clone_group_id (DISPLAYCONFIG_PATH_INFO &path, const boost::optional<UINT32 > &id) {
475- if (path.flags & DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE ) {
476- if (id) {
477- path.sourceInfo .cloneGroupId = *id;
478- }
479- else {
480- path.sourceInfo .cloneGroupId = DISPLAYCONFIG_PATH_CLONE_GROUP_INVALID ;
481- }
472+ // The MS docs is not clear when to access union struct or not. It appears that union struct is available,
473+ // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying.
474+ //
475+ // The docs state, however, that it is only available when
476+ // DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but that is just BS (maybe copy-pasta mistake), because some cases
477+ // were found where the flag is not set and the union is still being used.
478+
479+ if (id) {
480+ path.sourceInfo .cloneGroupId = *id;
481+ }
482+ else {
483+ path.sourceInfo .cloneGroupId = DISPLAYCONFIG_PATH_CLONE_GROUP_INVALID ;
482484 }
483485 }
484486
0 commit comments