libdisplaydevice v2026.322.2407
C++ library to modify display devices.
display_device::win_utils Namespace Reference

Shared "utility-level" code for Settings. More...

Functions

void blankHdrStates (WinDisplayDeviceInterface &win_dd, const std::optional< std::chrono::milliseconds > &delay)
 Toggle enabled HDR states off and on again if quick succession.
 
PathSourceIndexDataMap collectSourceDataForMatchingPaths (const WinApiLayerInterface &w_api, const std::vector< DISPLAYCONFIG_PATH_INFO > &paths)
 Collect arbitrary source data from provided paths.
 
std::optional< SingleDisplayConfigState::InitialcomputeInitialState (const std::optional< SingleDisplayConfigState::Initial > &prev_state, const ActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices)
 Compute the new intial state from arbitrary data.
 
DeviceDisplayModeMap computeNewDisplayModes (const std::optional< Resolution > &resolution, const std::optional< FloatingPoint > &refresh_rate, bool configuring_primary_devices, const std::string &device_to_configure, const std::set< std::string > &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes)
 Compute new display modes from arbitrary data.
 
HdrStateMap computeNewHdrStates (const std::optional< HdrState > &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set< std::string > &additional_devices_to_configure, const HdrStateMap &original_states)
 Compute new HDR states from arbitrary data.
 
ActiveTopology computeNewTopology (SingleDisplayConfiguration::DevicePreparation device_prep, bool configuring_primary_devices, const std::string &device_to_configure, const std::set< std::string > &additional_devices_to_configure, const ActiveTopology &initial_topology)
 Compute new topology from arbitrary data.
 
std::tuple< ActiveTopology, std::string, std::set< std::string > > computeNewTopologyAndMetadata (SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state)
 Compute new topology + metadata from config settings and initial state.
 
ActiveTopology createFullExtendedTopology (WinDisplayDeviceInterface &win_dd)
 Create extended topology from all the available devices.
 
std::set< std::string > flattenTopology (const ActiveTopology &topology)
 Get all the device ids in the topology.
 
bool fuzzyCompareModes (const DisplayMode &lhs, const DisplayMode &rhs)
 Check if the display modes are almost equal.
 
bool fuzzyCompareRefreshRates (const Rational &lhs, const Rational &rhs)
 Check if the refresh rates are almost equal.
 
const DISPLAYCONFIG_PATH_INFO * getActivePath (const WinApiLayerInterface &w_api, const std::string &device_id, const std::vector< DISPLAYCONFIG_PATH_INFO > &paths)
 Get the active path matching the device id.
 
DISPLAYCONFIG_PATH_INFO * getActivePath (const WinApiLayerInterface &w_api, const std::string &device_id, std::vector< DISPLAYCONFIG_PATH_INFO > &paths)
 
std::set< std::string > getAllDeviceIdsAndMatchingDuplicates (const WinApiLayerInterface &w_api, const std::set< std::string > &device_ids)
 Get all the missing duplicate device ids for the provided device ids.
 
std::optional< ValidatedDeviceInfogetDeviceInfoForValidPath (const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, ValidatedPathType type)
 Validate the path and get the commonly used information from it.
 
std::string getPrimaryDevice (WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
 Get one primary device from the provided topology.
 
std::optional< UINT32 > getSourceIndex (const DISPLAYCONFIG_PATH_INFO &path, const std::vector< DISPLAYCONFIG_MODE_INFO > &modes)
 Get the source mode index from the path.
 
const DISPLAYCONFIG_SOURCE_MODE * getSourceMode (const std::optional< UINT32 > &index, const std::vector< DISPLAYCONFIG_MODE_INFO > &modes)
 Get the source mode from the list at the specified index.
 
DISPLAYCONFIG_SOURCE_MODE * getSourceMode (const std::optional< UINT32 > &index, std::vector< DISPLAYCONFIG_MODE_INFO > &modes)
 
DdGuardFn hdrStateGuardFn (WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
 Make guard function for the HDR states.
 
DdGuardFn hdrStateGuardFn (WinDisplayDeviceInterface &win_dd, const HdrStateMap &states)
 Make guard function for the HDR states.
 
bool isActive (const DISPLAYCONFIG_PATH_INFO &path)
 Check if the display device path is marked as active.
 
bool isAvailable (const DISPLAYCONFIG_PATH_INFO &path)
 Check if the display device path's target is available.
 
bool isPrimary (const DISPLAYCONFIG_SOURCE_MODE &mode)
 Check if the display's source mode is primary - if the associated device is a primary display device.
 
std::vector< DISPLAYCONFIG_PATH_INFO > makePathsForNewTopology (const ActiveTopology &new_topology, const PathSourceIndexDataMap &path_source_data, const std::vector< DISPLAYCONFIG_PATH_INFO > &paths)
 Select the best possible paths to be used for the requested topology based on the data that is available to us.
 
DdGuardFn modeGuardFn (WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
 Make guard function for the display modes.
 
DdGuardFn modeGuardFn (WinDisplayDeviceInterface &win_dd, const DeviceDisplayModeMap &modes)
 Make guard function for the display modes.
 
DdGuardFn primaryGuardFn (WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
 Make guard function for the primary display.
 
DdGuardFn primaryGuardFn (WinDisplayDeviceInterface &win_dd, const std::string &primary_device)
 Make guard function for the primary display.
 
void setActive (DISPLAYCONFIG_PATH_INFO &path)
 Mark the display device path as active.
 
void setCloneGroupId (DISPLAYCONFIG_PATH_INFO &path, const std::optional< UINT32 > &id)
 Set the clone group id in the path.
 
void setDesktopIndex (DISPLAYCONFIG_PATH_INFO &path, const std::optional< UINT32 > &index)
 Set the desktop mode index in the path.
 
void setSourceIndex (DISPLAYCONFIG_PATH_INFO &path, const std::optional< UINT32 > &index)
 Set the source mode index in the path.
 
void setTargetIndex (DISPLAYCONFIG_PATH_INFO &path, const std::optional< UINT32 > &index)
 Set the target mode index in the path.
 
std::optional< SingleDisplayConfigState::InitialstripInitialState (const SingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices)
 Strip the initial state of non-existing devices.
 
DdGuardFn topologyGuardFn (WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
 Make guard function for the topology.
 

Detailed Description

Shared "utility-level" code for Settings.

Shared "utility-level" code for Windows.

Function Documentation

◆ blankHdrStates()

void display_device::win_utils::blankHdrStates ( WinDisplayDeviceInterface & win_dd,
const std::optional< std::chrono::milliseconds > & delay )

Toggle enabled HDR states off and on again if quick succession.

This is a workaround for a HDR highcontrast color bug which prominently happens for IDD HDR displays, but also sometimes (very VERY rarely) for dongles.

The bug is cause my more or less any change to the display settings, such as enabling HDR display, enabling HDR state, changing display mode of OTHER device and so on.

The workaround is to simply turn of HDR, wait a little and then turn it back on.

This is what this function does, but only if there are HDR enabled displays at the moment.

Parameters
win_ddInterface for interacting with the OS.
delayDelay between OFF and ON states (ON -> OFF -> DELAY -> ON). If null optional is provided, the function does nothing.

◆ collectSourceDataForMatchingPaths()

PathSourceIndexDataMap display_device::win_utils::collectSourceDataForMatchingPaths ( const WinApiLayerInterface & w_api,
const std::vector< DISPLAYCONFIG_PATH_INFO > & paths )
nodiscard

Collect arbitrary source data from provided paths.

This function filters paths that can be used later on and collects for a quick lookup.

Parameters
w_apiReference to the Windows API layer.
pathsList of paths.
Returns
Data for valid paths.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths from the system.

*Examples**

std::vector<DISPLAYCONFIG_PATH_INFO> paths;
const WinApiLayerInterface* iface = getIface(...);
const auto path_data = collectSourceDataForMatchingPaths(*iface, paths);
Lowest level Windows API wrapper for easy mocking.
Definition win_api_layer_interface.h:14
PathSourceIndexDataMap collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector< DISPLAYCONFIG_PATH_INFO > &paths)
Collect arbitrary source data from provided paths.
Definition win_api_utils.cpp:228

◆ computeInitialState()

std::optional< SingleDisplayConfigState::Initial > display_device::win_utils::computeInitialState ( const std::optional< SingleDisplayConfigState::Initial > & prev_state,
const ActiveTopology & topology_before_changes,
const EnumeratedDeviceList & devices )

Compute the new intial state from arbitrary data.

Parameters
prev_statePrevious initial state if available.
topology_before_changesTopology before any changes were made.
devicesCurrently available device list.
Returns
New initial state that should be used.

*Examples**

const SingleDisplayConfigState::Initial prev_state { { { "DeviceId1", "DeviceId2" }, { "DeviceId3" } } };
const ActiveTopology topology_before_changes { { "DeviceId3" } };
const EnumeratedDeviceList devices { ... };
const auto new_initial_state { computeInitialState(prev_state, topology_before_changes, devices) };
std::vector< EnumeratedDevice > EnumeratedDeviceList
A list of EnumeratedDevice objects.
Definition types.h:124
std::optional< SingleDisplayConfigState::Initial > computeInitialState(const std::optional< SingleDisplayConfigState::Initial > &prev_state, const ActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices)
Compute the new intial state from arbitrary data.
Definition settings_utils.cpp:166
Data that represents the original system state and is used as a base when trying to re-apply settings...
Definition types.h:119
std::vector< std::vector< std::string > > ActiveTopology
A LIST[LIST[DEVICE_ID]] structure which represents an active topology.
Definition types.h:86

◆ computeNewDisplayModes()

DeviceDisplayModeMap display_device::win_utils::computeNewDisplayModes ( const std::optional< Resolution > & resolution,
const std::optional< FloatingPoint > & refresh_rate,
bool configuring_primary_devices,
const std::string & device_to_configure,
const std::set< std::string > & additional_devices_to_configure,
const DeviceDisplayModeMap & original_modes )

Compute new display modes from arbitrary data.

Parameters
resolutionSpecify resolution that should be used to override the original modes.
refresh_rateSpecify refresh rate that should be used to override the original modes.
configuring_primary_devicesSpecify whether the device_to_configure was unspecified (primary device was selected).
device_to_configureMain device to be configured.
additional_devices_to_configureAdditional devices that belong to the same group as device_to_configure.
original_modesDisplay modes to be used as a base onto which changes are made.
Returns
New display modes that should be set.

◆ computeNewHdrStates()

HdrStateMap display_device::win_utils::computeNewHdrStates ( const std::optional< HdrState > & hdr_state,
bool configuring_primary_devices,
const std::string & device_to_configure,
const std::set< std::string > & additional_devices_to_configure,
const HdrStateMap & original_states )

Compute new HDR states from arbitrary data.

Parameters
hdr_stateSpecify state that should be used to override the original states.
configuring_primary_devicesSpecify whether the device_to_configure was unspecified (primary device was selected).
device_to_configureMain device to be configured.
additional_devices_to_configureAdditional devices that belong to the same group as device_to_configure.
original_statesHDR states to be used as a base onto which changes are made.
Returns
New HDR states that should be set.

◆ computeNewTopology()

ActiveTopology display_device::win_utils::computeNewTopology ( SingleDisplayConfiguration::DevicePreparation device_prep,
bool configuring_primary_devices,
const std::string & device_to_configure,
const std::set< std::string > & additional_devices_to_configure,
const ActiveTopology & initial_topology )

Compute new topology from arbitrary data.

Parameters
device_prepSpecify how to compute the new topology.
configuring_primary_devicesSpecify whether the device_to_configure was unspecified (primary device was selected).
device_to_configureMain device to be configured.
additional_devices_to_configureAdditional devices that belong to the same group as device_to_configure.
initial_topologyThe initial topology from computeInitialState(...).
Returns
New topology that should be set.

◆ computeNewTopologyAndMetadata()

std::tuple< ActiveTopology, std::string, std::set< std::string > > display_device::win_utils::computeNewTopologyAndMetadata ( SingleDisplayConfiguration::DevicePreparation device_prep,
const std::string & device_id,
const SingleDisplayConfigState::Initial & initial_state )

Compute new topology + metadata from config settings and initial state.

Parameters
device_prepSpecify how to to compute the new topology.
device_idSpecify which device whould be used for computation (can be empty if primary device should be used).
initial_stateThe initial topology from computeInitialState(...) or stripInitialState(...) (or both).
Returns
A tuple of (new_topology, device_to_configure, addotional_devices_to_configure).

◆ createFullExtendedTopology()

ActiveTopology display_device::win_utils::createFullExtendedTopology ( WinDisplayDeviceInterface & win_dd)

Create extended topology from all the available devices.

Parameters
win_ddInterface for interacting with the OS.
Returns
Extended topology with all the available devices.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const auto extended_topology { stripTopologyOfUnavailableDevices(*iface) };
Higher level abstracted API for interacting Windows' display device(s).
Definition win_display_device_interface.h:17

◆ flattenTopology()

std::set< std::string > display_device::win_utils::flattenTopology ( const ActiveTopology & topology)

Get all the device ids in the topology.

Parameters
topologyTopology to be "flattened".
Returns
Device ids found in the topology.

*Examples**

const ActiveTopology topology { { "DeviceId1", "DeviceId2" }, { "DeviceId3" } };
const auto device_ids { flattenTopology(topology) };
std::set< std::string > flattenTopology(const ActiveTopology &topology)
Get all the device ids in the topology.
Definition settings_utils.cpp:129

◆ fuzzyCompareModes()

bool display_device::win_utils::fuzzyCompareModes ( const DisplayMode & lhs,
const DisplayMode & rhs )
nodiscard

Check if the display modes are almost equal.

Parameters
lhsFirst mode.
rhsSecond mode.
Returns
True if display modes are almost equal, false otherwise.

*Examples**

const bool almost_equal = fuzzyCompareModes(DisplayMode { { 1920, 1080 }, { 60, 1 } },
DisplayMode { { 1920, 1080 }, { 5985, 100 } });
const bool not_equal = fuzzyCompareModes(DisplayMode { { 1920, 1080 }, { 60, 1 } },
DisplayMode { { 1920, 1080 }, { 5585, 100 } });
bool fuzzyCompareModes(const DisplayMode &lhs, const DisplayMode &rhs)
Check if the display modes are almost equal.
Definition win_api_utils.cpp:465
Display's mode (resolution + refresh rate).
Definition types.h:91

◆ fuzzyCompareRefreshRates()

bool display_device::win_utils::fuzzyCompareRefreshRates ( const Rational & lhs,
const Rational & rhs )
nodiscard

Check if the refresh rates are almost equal.

Parameters
lhsFirst refresh rate.
rhsSecond refresh rate.
Returns
True if refresh rates are almost equal, false otherwise.

*Examples**

const bool almost_equal = fuzzyCompareRefreshRates(Rational { 60, 1 }, Rational { 5985, 100 });
const bool not_equal = fuzzyCompareRefreshRates(Rational { 60, 1 }, Rational { 5585, 100 });
bool fuzzyCompareRefreshRates(const Rational &lhs, const Rational &rhs)
Check if the refresh rates are almost equal.
Definition win_api_utils.cpp:455
Floating point stored in a "numerator/denominator" form.
Definition types.h:52

◆ getActivePath() [1/2]

const DISPLAYCONFIG_PATH_INFO * display_device::win_utils::getActivePath ( const WinApiLayerInterface & w_api,
const std::string & device_id,
const std::vector< DISPLAYCONFIG_PATH_INFO > & paths )
nodiscard

Get the active path matching the device id.

Parameters
w_apiReference to the Windows API layer.
device_idId to search for in the the list.
pathsList to be searched.
Returns
A pointer to an active path matching our id, nullptr otherwise.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths and modes from the system.

*Examples**

const std::vector<DISPLAYCONFIG_PATH_INFO> paths;
const WinApiLayerInterface* iface = getIface(...);
const DISPLAYCONFIG_PATH_INFO* active_path = get_active_path(*iface, "MY_DEVICE_ID", paths);

◆ getActivePath() [2/2]

DISPLAYCONFIG_PATH_INFO * display_device::win_utils::getActivePath ( const WinApiLayerInterface & w_api,
const std::string & device_id,
std::vector< DISPLAYCONFIG_PATH_INFO > & paths )
nodiscard
See also
getActivePath (const version) for the description.

◆ getAllDeviceIdsAndMatchingDuplicates()

std::set< std::string > display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates ( const WinApiLayerInterface & w_api,
const std::set< std::string > & device_ids )
nodiscard

Get all the missing duplicate device ids for the provided device ids.

Parameters
w_apiReference to the Windows API layer.
device_idsDevice ids to find the missing duplicate ids for.
Returns
A list of device ids containing the provided device ids and all unspecified ids for duplicated displays.

*Examples**

const WinApiLayerInterface* iface = getIface(...);
const auto device_ids_with_duplicates = getAllDeviceIdsAndMatchingDuplicates(*iface, { "MY_ID1" });
std::set< std::string > getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set< std::string > &device_ids)
Get all the missing duplicate device ids for the provided device ids.
Definition win_api_utils.cpp:399

◆ getDeviceInfoForValidPath()

std::optional< ValidatedDeviceInfo > display_device::win_utils::getDeviceInfoForValidPath ( const WinApiLayerInterface & w_api,
const DISPLAYCONFIG_PATH_INFO & path,
ValidatedPathType type )
nodiscard

Validate the path and get the commonly used information from it.

This a convenience function to ensure that our concept of "valid path" remains the same throughout the code.

Currently, for use, a valid path is:

  • a path with and available display target;
  • a path that is active (optional);
  • a path that has a non-empty device path;
  • a path that has a non-empty device id;
  • a path that has a non-empty device name assigned.
Parameters
w_apiReference to the Windows API layer.
pathPath to validate and get info for.
typeAdditional constraints for the path.
Returns
Commonly used info for the path, or empty optional if the path is invalid.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
const WinApiLayerInterface* iface = getIface(...);
const auto device_info = getDeviceInfoForValidPath(*iface, path, ValidatedPathType::Active);
std::optional< ValidatedDeviceInfo > getDeviceInfoForValidPath(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, ValidatedPathType type)
Validate the path and get the commonly used information from it.
Definition win_api_utils.cpp:179

◆ getPrimaryDevice()

std::string display_device::win_utils::getPrimaryDevice ( WinDisplayDeviceInterface & win_dd,
const ActiveTopology & topology )

Get one primary device from the provided topology.

Parameters
win_ddInterface for interacting with the OS.
topologyTopology to be searched.
Returns
Id of a primary device or an empty string if not found or an error has occured.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const ActiveTopology topology { { "DeviceId1", "DeviceId2" }, { "DeviceId3" } };
const auto primary_device_id { getPrimaryDevice(*iface, topology) };
std::string getPrimaryDevice(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
Get one primary device from the provided topology.
Definition settings_utils.cpp:155

◆ getSourceIndex()

std::optional< UINT32 > display_device::win_utils::getSourceIndex ( const DISPLAYCONFIG_PATH_INFO & path,
const std::vector< DISPLAYCONFIG_MODE_INFO > & modes )
nodiscard

Get the source mode index from the path.

It performs sanity checks on the modes list that the index is indeed correct.

Parameters
pathPath to get the source mode index for.
modesA list of various modes (source, target, desktop and probably more in the future).
Returns
Valid index value if it's found in the modes list and the mode at that index is of a type "source" mode, empty optional otherwise.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
std::vector<DISPLAYCONFIG_MODE_INFO> modes;
const auto source_index = getSourceIndex(path, modes);
std::optional< UINT32 > getSourceIndex(const DISPLAYCONFIG_PATH_INFO &path, const std::vector< DISPLAYCONFIG_MODE_INFO > &modes)
Get the source mode index from the path.
Definition win_api_utils.cpp:75

◆ getSourceMode() [1/2]

const DISPLAYCONFIG_SOURCE_MODE * display_device::win_utils::getSourceMode ( const std::optional< UINT32 > & index,
const std::vector< DISPLAYCONFIG_MODE_INFO > & modes )
nodiscard

Get the source mode from the list at the specified index.

This function does additional sanity checks for the modes list and ensures that the mode at the specified index is indeed a source mode.

Parameters
indexIndex to get the mode for. It is of boost::optional type as the function is intended to be used with getSourceIndex function.
modesList to get the mode from.
Returns
A pointer to a valid source mode from to list at the specified index, nullptr otherwise.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths and modes from the system.
getSourceIndex

*Examples**

DISPLAYCONFIG_PATH_INFO path;
const std::vector<DISPLAYCONFIG_MODE_INFO> modes;
const DISPLAYCONFIG_SOURCE_MODE* source_mode = getSourceMode(getSourceIndex(path, modes), modes);
const DISPLAYCONFIG_SOURCE_MODE * getSourceMode(const std::optional< UINT32 > &index, const std::vector< DISPLAYCONFIG_MODE_INFO > &modes)
Get the source mode from the list at the specified index.
Definition win_api_utils.cpp:156

◆ getSourceMode() [2/2]

DISPLAYCONFIG_SOURCE_MODE * display_device::win_utils::getSourceMode ( const std::optional< UINT32 > & index,
std::vector< DISPLAYCONFIG_MODE_INFO > & modes )
nodiscard
See also
getSourceMode (const version) for the description.

◆ hdrStateGuardFn() [1/2]

DdGuardFn display_device::win_utils::hdrStateGuardFn ( WinDisplayDeviceInterface & win_dd,
const ActiveTopology & topology )

Make guard function for the HDR states.

Parameters
win_ddInterface for interacting with the OS.
topologyTopology to be used when making a guard.
Returns
Function that once called will try to revert HDR states to the ones that were initially set for the provided topology.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
boost::scope::scope_exit guard { hdrStateGuardFn(*iface, iface->getCurrentTopology()) };
virtual ActiveTopology getCurrentTopology() const =0
Get the active (current) topology.
DdGuardFn hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
Make guard function for the HDR states.
Definition settings_utils.cpp:433

◆ hdrStateGuardFn() [2/2]

DdGuardFn display_device::win_utils::hdrStateGuardFn ( WinDisplayDeviceInterface & win_dd,
const HdrStateMap & states )

Make guard function for the HDR states.

Parameters
win_ddInterface for interacting with the OS.
statesHDR states to restore when the guard is executed.
Returns
Function that once called will try to revert HDR states to the ones that were provided.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const HdrStateMap states { };
boost::scope::scope_exit guard { hdrStateGuardFn(*iface, states) };
std::map< std::string, std::optional< HdrState > > HdrStateMap
Ordered map of [DEVICE_ID -> std::optional<HdrState>].
Definition types.h:109

◆ isActive()

bool display_device::win_utils::isActive ( const DISPLAYCONFIG_PATH_INFO & path)
nodiscard

Check if the display device path is marked as active.

Parameters
pathPath to check.
Returns
True if path is marked as active, false otherwise.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
const bool active = isActive(path);
bool isActive(const DISPLAYCONFIG_PATH_INFO &path)
Check if the display device path is marked as active.
Definition win_api_utils.cpp:63

◆ isAvailable()

bool display_device::win_utils::isAvailable ( const DISPLAYCONFIG_PATH_INFO & path)
nodiscard

Check if the display device path's target is available.

In most cases this this would mean physically connected to the system, but it also possible force the path to persist. It is not clear if it be counted as available or not.

Parameters
pathPath to check.
Returns
True if path's target is marked as available, false otherwise.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
const bool available = isAvailable(path);
bool isAvailable(const DISPLAYCONFIG_PATH_INFO &path)
Check if the display device path's target is available.
Definition win_api_utils.cpp:59

◆ isPrimary()

bool display_device::win_utils::isPrimary ( const DISPLAYCONFIG_SOURCE_MODE & mode)

Check if the display's source mode is primary - if the associated device is a primary display device.

Parameters
modeMode to check.
Returns
True if the mode's origin point is at (0, 0) coordinate (primary), false otherwise.
Note
It is possible to have multiple primary source modes at the same time.

*Examples**

DISPLAYCONFIG_SOURCE_MODE mode;
const bool is_primary = isPrimary(mode);
bool isPrimary(const DISPLAYCONFIG_SOURCE_MODE &mode)
Check if the display's source mode is primary - if the associated device is a primary display device.
Definition win_api_utils.cpp:71

◆ makePathsForNewTopology()

std::vector< DISPLAYCONFIG_PATH_INFO > display_device::win_utils::makePathsForNewTopology ( const ActiveTopology & new_topology,
const PathSourceIndexDataMap & path_source_data,
const std::vector< DISPLAYCONFIG_PATH_INFO > & paths )
nodiscard

Select the best possible paths to be used for the requested topology based on the data that is available to us.

If the paths will be used for a completely new topology (Windows has never had it set), we need to take into account the source id availability per the adapter - duplicated displays must share the same source id (if they belong to the same adapter) and have different ids if they are not duplicated displays.

There are limited amount of available ids (see comments in the code) so we will abort early if we are out of ids.

The paths for a topology that already exists (Windows has set it at least once) does not have to follow the mentioned "source id" rule. Windows can simply ignore them (we will ask it later) and select paths that were previously configured (that might differ in source ids) based on the paths that we provide.

Parameters
new_topologyTopology that we want to have in the end.
path_source_dataCollected source data from paths.
pathsDisplay paths that were used for collecting source data.
Returns
A list of path that will make up new topology, or an empty list if function fails.

◆ modeGuardFn() [1/2]

DdGuardFn display_device::win_utils::modeGuardFn ( WinDisplayDeviceInterface & win_dd,
const ActiveTopology & topology )

Make guard function for the display modes.

Parameters
win_ddInterface for interacting with the OS.
topologyTopology to be used when making a guard.
Returns
Function that once called will try to revert display modes to the ones that were initially set for the provided topology.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
boost::scope::scope_exit guard { modeGuardFn(*iface, iface->getCurrentTopology()) };
DdGuardFn modeGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
Make guard function for the display modes.
Definition settings_utils.cpp:403

◆ modeGuardFn() [2/2]

DdGuardFn display_device::win_utils::modeGuardFn ( WinDisplayDeviceInterface & win_dd,
const DeviceDisplayModeMap & modes )

Make guard function for the display modes.

Parameters
win_ddInterface for interacting with the OS.
modesDisplay modes to restore when the guard is executed.
Returns
Function that once called will try to revert display modes to the ones that were provided.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const DeviceDisplayModeMap modes { };
boost::scope::scope_exit guard { modeGuardFn(*iface, modes) };
std::map< std::string, DisplayMode > DeviceDisplayModeMap
Ordered map of [DEVICE_ID -> DisplayMode].
Definition types.h:104

◆ primaryGuardFn() [1/2]

DdGuardFn display_device::win_utils::primaryGuardFn ( WinDisplayDeviceInterface & win_dd,
const ActiveTopology & topology )

Make guard function for the primary display.

Parameters
win_ddInterface for interacting with the OS.
topologyTopology to be used when making a guard.
Returns
Function that once called will try to revert primary display to the one that was initially set for the provided topology.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
boost::scope::scope_exit guard { primaryGuardFn(*iface, iface->getCurrentTopology()) };
DdGuardFn primaryGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
Make guard function for the primary display.
Definition settings_utils.cpp:418

◆ primaryGuardFn() [2/2]

DdGuardFn display_device::win_utils::primaryGuardFn ( WinDisplayDeviceInterface & win_dd,
const std::string & primary_device )

Make guard function for the primary display.

Parameters
win_ddInterface for interacting with the OS.
primary_devicePrimary device to restore when the guard is executed.
Returns
Function that once called will try to revert primary display to the one that was provided.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const std::string prev_primary_device { "MyDeviceId" };
boost::scope::scope_exit guard { primaryGuardFn(*iface, prev_primary_device) };

◆ setActive()

void display_device::win_utils::setActive ( DISPLAYCONFIG_PATH_INFO & path)

Mark the display device path as active.

Parameters
pathPath to mark.
See also
WinApiLayerInterface::queryDisplayConfig on how to get paths from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
if (!isActive(path)) {
setActive(path);
}
void setActive(DISPLAYCONFIG_PATH_INFO &path)
Mark the display device path as active.
Definition win_api_utils.cpp:67

◆ setCloneGroupId()

void display_device::win_utils::setCloneGroupId ( DISPLAYCONFIG_PATH_INFO & path,
const std::optional< UINT32 > & id )

Set the clone group id in the path.

Parameters
pathPath to modify.
idId value to set or empty optional to mark the id as invalid.
See also
query_display_config on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
set_clone_group_id(path, 5);
set_clone_group_id(path, std::nullopt);

◆ setDesktopIndex()

void display_device::win_utils::setDesktopIndex ( DISPLAYCONFIG_PATH_INFO & path,
const std::optional< UINT32 > & index )

Set the desktop mode index in the path.

Parameters
pathPath to modify.
indexIndex value to set or empty optional to mark the index as invalid.
See also
query_display_config on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
set_desktop_index(path, 5);
set_desktop_index(path, std::nullopt);

◆ setSourceIndex()

void display_device::win_utils::setSourceIndex ( DISPLAYCONFIG_PATH_INFO & path,
const std::optional< UINT32 > & index )

Set the source mode index in the path.

Parameters
pathPath to modify.
indexIndex value to set or empty optional to mark the index as invalid.
See also
query_display_config on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
set_source_index(path, 5);
set_source_index(path, std::nullopt);

◆ setTargetIndex()

void display_device::win_utils::setTargetIndex ( DISPLAYCONFIG_PATH_INFO & path,
const std::optional< UINT32 > & index )

Set the target mode index in the path.

Parameters
pathPath to modify.
indexIndex value to set or empty optional to mark the index as invalid.
See also
query_display_config on how to get paths and modes from the system.

*Examples**

DISPLAYCONFIG_PATH_INFO path;
set_target_index(path, 5);
set_target_index(path, std::nullopt);

◆ stripInitialState()

std::optional< SingleDisplayConfigState::Initial > display_device::win_utils::stripInitialState ( const SingleDisplayConfigState::Initial & initial_state,
const EnumeratedDeviceList & devices )

Strip the initial state of non-existing devices.

Parameters
initial_stateState to be stripped.
devicesCurrently available device list.
Returns
Stripped initial state.

◆ topologyGuardFn()

DdGuardFn display_device::win_utils::topologyGuardFn ( WinDisplayDeviceInterface & win_dd,
const ActiveTopology & topology )

Make guard function for the topology.

Parameters
win_ddInterface for interacting with the OS.
topologyTopology to be used when making a guard.
Returns
Function that once called will try to revert topology to the provided one.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
boost::scope::scope_exit guard { topologyGuardFn(*iface, iface->getCurrentTopology()) };
DdGuardFn topologyGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology)
Make guard function for the topology.
Definition settings_utils.cpp:392