libdisplaydevice master
C++ library to modify display devices.
display_device::WinDisplayDevice Class Reference

Default implementation for the WinDisplayDeviceInterface. More...

#include <src/windows/include/display_device/windows/win_display_device.h>

Inheritance diagram for display_device::WinDisplayDevice:
[legend]
Collaboration diagram for display_device::WinDisplayDevice:
[legend]

Public Member Functions

EnumeratedDeviceList enumAvailableDevices () const override
 Enumerate the available (active and inactive) devices.
 
DeviceDisplayModeMap getCurrentDisplayModes (const StringSet &device_ids) const override
 Get current display modes for the devices.
 
HdrStateMap getCurrentHdrStates (const StringSet &device_ids) const override
 Get HDR state for the devices.
 
ActiveTopology getCurrentTopology () const override
 Get the active (current) topology.
 
std::string getDisplayName (const std::string &device_id) const override
 Get display name associated with the device.
 
bool isApiAccessAvailable () const override
 Check if the API for changing display settings is accessible.
 
bool isPrimary (const std::string &device_id) const override
 Check whether the specified device is primary.
 
bool isTopologyTheSame (const ActiveTopology &lhs, const ActiveTopology &rhs) const override
 Check if the topologies are close enough to be considered the same by the OS.
 
bool isTopologyValid (const ActiveTopology &topology) const override
 Verify if the active topology is valid.
 
bool setAsPrimary (const std::string &device_id) override
 Set the device as a primary display.
 
bool setDisplayModes (const DeviceDisplayModeMap &modes) override
 Set new display modes for the devices.
 
bool setHdrStates (const HdrStateMap &states) override
 Set HDR states for the devices.
 
bool setTopology (const ActiveTopology &new_topology) override
 Set a new active topology for the OS.
 
 WinDisplayDevice (std::shared_ptr< WinApiLayerInterface > w_api)
 
- Public Member Functions inherited from display_device::WinDisplayDeviceInterface
virtual ~WinDisplayDeviceInterface ()=default
 Default virtual destructor.
 

Detailed Description

Default implementation for the WinDisplayDeviceInterface.

Constructor & Destructor Documentation

◆ WinDisplayDevice()

display_device::WinDisplayDevice::WinDisplayDevice ( std::shared_ptr< WinApiLayerInterface > w_api)
explicit

Default constructor for the class.

Parameters
w_apiA pointer to the Windows API layer. Will throw on nullptr!

Member Function Documentation

◆ enumAvailableDevices()

EnumeratedDeviceList display_device::WinDisplayDevice::enumAvailableDevices ( ) const
nodiscardoverridevirtual

Enumerate the available (active and inactive) devices.

Returns
A list of available devices. Empty list can also be returned if an error has occurred.

*Examples**

const auto devices { enumAvailableDevices() };
EnumeratedDeviceList enumAvailableDevices() const override
Enumerate the available (active and inactive) devices.
Definition win_display_device_general.cpp:33

Implements display_device::WinDisplayDeviceInterface.

◆ getCurrentDisplayModes()

DeviceDisplayModeMap display_device::WinDisplayDevice::getCurrentDisplayModes ( const StringSet & device_ids) const
nodiscardoverridevirtual

Get current display modes for the devices.

Parameters
device_idsA list of devices to get the modes for.
Returns
A map of device modes per a device or an empty map if a mode could not be found (e.g. device is inactive). Empty map can also be returned if an error has occurred.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const StringSet device_ids { "DEVICE_ID_1", "DEVICE_ID_2" };
const auto current_modes = iface->getCurrentDisplayModes(device_ids);
Higher level abstracted API for interacting Windows' display device(s).
Definition win_display_device_interface.h:17
virtual DeviceDisplayModeMap getCurrentDisplayModes(const StringSet &device_ids) const =0
Get current display modes for the devices.
std::set< std::string, std::less<> > StringSet
Ordered set keyed by strings with transparent comparisons.
Definition types.h:46

Implements display_device::WinDisplayDeviceInterface.

◆ getCurrentHdrStates()

HdrStateMap display_device::WinDisplayDevice::getCurrentHdrStates ( const StringSet & device_ids) const
nodiscardoverridevirtual

Get HDR state for the devices.

Parameters
device_idsA list of devices to get the HDR states for.
Returns
A map of HDR states per a device or an empty map if an error has occurred.
Note
On Windows the state cannot be retrieved until the device is active even if it supports it.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const StringSet device_ids { "DEVICE_ID_1", "DEVICE_ID_2" };
const auto current_hdr_states = iface->getCurrentHdrStates(device_ids);
virtual HdrStateMap getCurrentHdrStates(const StringSet &device_ids) const =0
Get HDR state for the devices.

Implements display_device::WinDisplayDeviceInterface.

◆ getCurrentTopology()

ActiveTopology display_device::WinDisplayDevice::getCurrentTopology ( ) const
nodiscardoverridevirtual

Get the active (current) topology.

Returns
A list representing the current topology. Empty list can also be returned if an error has occurred.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const auto current_topology { iface->getCurrentTopology() };
virtual ActiveTopology getCurrentTopology() const =0
Get the active (current) topology.

Implements display_device::WinDisplayDeviceInterface.

◆ getDisplayName()

std::string display_device::WinDisplayDevice::getDisplayName ( const std::string & device_id) const
nodiscardoverridevirtual

Get display name associated with the device.

Parameters
device_idA device to get display name for.
Returns
A display name for the device, or an empty string if the device is inactive or not found. Empty string can also be returned if an error has occurred.

*Examples**

const std::string device_id { "MY_DEVICE_ID" };
const WinDisplayDeviceInterface* iface = getIface(...);
const std::string display_name = iface->getDisplayName(device_id);
virtual std::string getDisplayName(const std::string &device_id) const =0
Get display name associated with the device.

Implements display_device::WinDisplayDeviceInterface.

◆ isApiAccessAvailable()

bool display_device::WinDisplayDevice::isApiAccessAvailable ( ) const
nodiscardoverridevirtual

Check if the API for changing display settings is accessible.

Returns
True if display settings can be changed, false otherwise.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const bool have_access { iface->isApiAccessAvailable() };
virtual bool isApiAccessAvailable() const =0
Check if the API for changing display settings is accessible.

Implements display_device::WinDisplayDeviceInterface.

◆ isPrimary()

bool display_device::WinDisplayDevice::isPrimary ( const std::string & device_id) const
nodiscardoverridevirtual

Check whether the specified device is primary.

Parameters
device_idA device to perform the check for.
Returns
True if the device is primary, false otherwise.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
const std::string device_id { "MY_DEVICE_ID" };
const bool is_primary = iface->isPrimary(device_id);
virtual bool isPrimary(const std::string &device_id) const =0
Check whether the specified device is primary.

Implements display_device::WinDisplayDeviceInterface.

◆ isTopologyTheSame()

bool display_device::WinDisplayDevice::isTopologyTheSame ( const ActiveTopology & lhs,
const ActiveTopology & rhs ) const
nodiscardoverridevirtual

Check if the topologies are close enough to be considered the same by the OS.

Parameters
lhsFirst topology to compare.
rhsSecond topology to compare.
Returns
True if topologies are close enough, false otherwise.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
auto current_topology { iface->getCurrentTopology() };
auto new_topology { current_topology };
// Modify the new_topology
const bool is_the_same = iface->isTopologyTheSame(current_topology, new_topology);
virtual bool isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const =0
Check if the topologies are close enough to be considered the same by the OS.

Implements display_device::WinDisplayDeviceInterface.

◆ isTopologyValid()

bool display_device::WinDisplayDevice::isTopologyValid ( const ActiveTopology & topology) const
nodiscardoverridevirtual

Verify if the active topology is valid.

This is mostly meant as a sanity check or to verify that it is still valid after a manual modification to an existing topology.

Parameters
topologyTopology to validate.
Returns
True if it is valid, false otherwise.

*Examples**

const WinDisplayDeviceInterface* iface = getIface(...);
auto current_topology { iface->getCurrentTopology() };
// Modify the current_topology
const bool is_valid = iface->isTopologyValid(current_topology);
virtual bool isTopologyValid(const ActiveTopology &topology) const =0
Verify if the active topology is valid.

Implements display_device::WinDisplayDeviceInterface.

◆ setAsPrimary()

bool display_device::WinDisplayDevice::setAsPrimary ( const std::string & device_id)
nodiscardoverridevirtual

Set the device as a primary display.

Parameters
device_idA device to set as primary.
Returns
True if the device is or was set as primary, false otherwise.
Note
On Windows if the device is duplicated, the other duplicated device(-s) will also become a primary device.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const std::string device_id { "MY_DEVICE_ID" };
const bool success = iface->set_as_primary_device(device_id);

Implements display_device::WinDisplayDeviceInterface.

◆ setDisplayModes()

bool display_device::WinDisplayDevice::setDisplayModes ( const DeviceDisplayModeMap & modes)
nodiscardoverridevirtual

Set new display modes for the devices.

Parameters
modesA map of modes to set.
Returns
True if modes were set, false otherwise.
Warning
if any of the specified devices are duplicated, modes be provided for duplicates too!

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const std::string display_a { "MY_ID_1" };
const std::string display_b { "MY_ID_2" };
const auto success = iface->setDisplayModes({ { display_a, { { 1920, 1080 }, { 60, 1 } } },
{ display_b, { { 1920, 1080 }, { 120, 1 } } } });
virtual bool setDisplayModes(const DeviceDisplayModeMap &modes)=0
Set new display modes for the devices.

Implements display_device::WinDisplayDeviceInterface.

◆ setHdrStates()

bool display_device::WinDisplayDevice::setHdrStates ( const HdrStateMap & states)
nodiscardoverridevirtual

Set HDR states for the devices.

Parameters
statesA map of HDR states to set.
Returns
True if HDR states were set, false otherwise.
Note
If unknown states are provided, they will be silently ignored and current state will not be changed.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
const std::string display_a { "MY_ID_1" };
const std::string display_b { "MY_ID_2" };
const auto success = iface->setHdrStates({ { display_a, HdrState::Enabled },
{ display_b, HdrState::Disabled } });
virtual bool setHdrStates(const HdrStateMap &states)=0
Set HDR states for the devices.

Implements display_device::WinDisplayDeviceInterface.

◆ setTopology()

bool display_device::WinDisplayDevice::setTopology ( const ActiveTopology & new_topology)
nodiscardoverridevirtual

Set a new active topology for the OS.

Parameters
new_topologyNew device topology to set.
Returns
True if the new topology has been set, false otherwise.

*Examples**

WinDisplayDeviceInterface* iface = getIface(...);
auto current_topology { iface->getCurrentTopology() };
// Modify the current_topology
const bool success = iface->setTopology(current_topology);
virtual bool setTopology(const ActiveTopology &new_topology)=0
Set a new active topology for the OS.

Implements display_device::WinDisplayDeviceInterface.


The documentation for this class was generated from the following files: