libdisplaydevice master
C++ library to modify display devices.
display_device::mac_utils Namespace Reference

Shared utility-level code for macOS API wrappers. More...

Functions

std::optional< MacSingleDisplayConfigState::InitialcomputeInitialState (const std::optional< MacSingleDisplayConfigState::Initial > &prev_state, const MacActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices)
 Compute the initial state that should be used for future reverts.
 
MacDeviceDisplayModeMap computeNewDisplayModes (const std::optional< Resolution > &resolution, const std::optional< FloatingPoint > &refresh_rate, bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const MacDeviceDisplayModeMap &original_modes)
 Compute display modes requested by a single-display configuration.
 
StringSet flattenTopology (const MacActiveTopology &topology)
 Get all the device ids in the topology.
 
bool fuzzyCompareModes (const MacDisplayMode &lhs, const MacDisplayMode &rhs)
 Check if two macOS display modes are close enough to be treated as equal.
 
bool fuzzyCompareRefreshRates (const Rational &lhs, const Rational &rhs)
 Check if two refresh rates are close enough to be treated as equal.
 
std::string getPrimaryDevice (const MacDisplayDeviceInterface &mac_dd, const MacActiveTopology &topology)
 Get one primary device from the provided topology.
 
bool isSuccess (MacApiError error_code)
 Check if a macOS API error represents success.
 
MacDdGuardFn modeGuardFn (MacDisplayDeviceInterface &mac_dd, const MacDeviceDisplayModeMap &modes)
 Make a guard function for display modes.
 
void noopGuard ()
 Function that does nothing.
 
std::optional< MacSingleDisplayConfigState::InitialstripInitialState (const MacSingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices)
 Remove unavailable devices from a stored initial state.
 

Detailed Description

Shared utility-level code for macOS API wrappers.

Shared utility-level code for macOS settings.

Function Documentation

◆ computeInitialState()

std::optional< MacSingleDisplayConfigState::Initial > display_device::mac_utils::computeInitialState ( const std::optional< MacSingleDisplayConfigState::Initial > & prev_state,
const MacActiveTopology & topology_before_changes,
const EnumeratedDeviceList & devices )
nodiscard

Compute the initial state that should be used for future reverts.

Parameters
prev_statePrevious initial state if one was persisted.
topology_before_changesCurrent topology before applying a new configuration.
devicesCurrently available devices.
Returns
Initial state, or empty optional if the state cannot be computed.

◆ computeNewDisplayModes()

MacDeviceDisplayModeMap display_device::mac_utils::computeNewDisplayModes ( const std::optional< Resolution > & resolution,
const std::optional< FloatingPoint > & refresh_rate,
bool configuring_primary_devices,
const std::string & device_to_configure,
const StringSet & additional_devices_to_configure,
const MacDeviceDisplayModeMap & original_modes )
nodiscard

Compute display modes requested by a single-display configuration.

Parameters
resolutionOptional resolution override.
refresh_rateOptional refresh-rate override.
configuring_primary_devicesTrue when an empty device id selected primary devices.
device_to_configureMain device being configured.
additional_devices_to_configureAdditional devices mirrored with the main device.
original_modesCurrent or persisted display modes used as the base.
Returns
New mode map with requested changes applied.

◆ flattenTopology()

StringSet display_device::mac_utils::flattenTopology ( const MacActiveTopology & topology)
nodiscard

Get all the device ids in the topology.

Parameters
topologyTopology to flatten.
Returns
Device ids found in the topology.

◆ fuzzyCompareModes()

bool display_device::mac_utils::fuzzyCompareModes ( const MacDisplayMode & lhs,
const MacDisplayMode & rhs )
nodiscard

Check if two macOS display modes are close enough to be treated as equal.

Parameters
lhsFirst mode to compare.
rhsSecond mode to compare.
Returns
True if resolution matches exactly and refresh rate is close enough.

◆ fuzzyCompareRefreshRates()

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

Check if two refresh rates are close enough to be treated as equal.

Parameters
lhsFirst refresh rate to compare.
rhsSecond refresh rate to compare.
Returns
True if the refresh rates are close enough, false otherwise.

◆ getPrimaryDevice()

std::string display_device::mac_utils::getPrimaryDevice ( const MacDisplayDeviceInterface & mac_dd,
const MacActiveTopology & topology )
nodiscard

Get one primary device from the provided topology.

Parameters
mac_ddInterface for interacting with the OS.
topologyTopology to search.
Returns
Primary device id, or an empty string if none can be found.

◆ isSuccess()

bool display_device::mac_utils::isSuccess ( MacApiError error_code)
nodiscard

Check if a macOS API error represents success.

Parameters
error_codeError code to check.
Returns
True if the error code represents success, false otherwise.

◆ modeGuardFn()

MacDdGuardFn display_device::mac_utils::modeGuardFn ( MacDisplayDeviceInterface & mac_dd,
const MacDeviceDisplayModeMap & modes )
nodiscard

Make a guard function for display modes.

Parameters
mac_ddInterface for interacting with the OS.
modesDisplay modes to restore when the guard runs.
Returns
Function that tries to restore the provided modes.

◆ stripInitialState()

std::optional< MacSingleDisplayConfigState::Initial > display_device::mac_utils::stripInitialState ( const MacSingleDisplayConfigState::Initial & initial_state,
const EnumeratedDeviceList & devices )
nodiscard

Remove unavailable devices from a stored initial state.

Parameters
initial_stateState to strip.
devicesCurrently available devices.
Returns
Stripped state, or empty optional if no usable state remains.