diff --git a/src/common/include/display_device/json.h b/src/common/include/display_device/json.h index de9a7a61..208b7034 100644 --- a/src/common/include/display_device/json.h +++ b/src/common/include/display_device/json.h @@ -29,7 +29,7 @@ namespace display_device { DD_JSON_DECLARE_CONVERTER(EnumeratedDevice) DD_JSON_DECLARE_CONVERTER(EnumeratedDeviceList) DD_JSON_DECLARE_CONVERTER(SingleDisplayConfiguration) - DD_JSON_DECLARE_CONVERTER(std::set) + DD_JSON_DECLARE_CONVERTER(StringSet) DD_JSON_DECLARE_CONVERTER(std::string) DD_JSON_DECLARE_CONVERTER(bool) } // namespace display_device diff --git a/src/common/include/display_device/types.h b/src/common/include/display_device/types.h index 0c62b79e..7c42bf82 100644 --- a/src/common/include/display_device/types.h +++ b/src/common/include/display_device/types.h @@ -5,13 +5,53 @@ #pragma once // system includes +#include #include +#include +#include #include +#include #include +#include +#include +#include #include #include namespace display_device { + /** + * @brief Transparent hash for string-keyed unordered containers. + */ + struct StringHash { + using is_transparent = void; + + [[nodiscard]] std::size_t operator()(const std::string_view value) const noexcept { + return std::hash {}(value); + } + }; + + /** + * @brief Ordered set keyed by strings with transparent comparisons. + */ + using StringSet = std::set>; + + /** + * @brief Ordered map keyed by strings with transparent comparisons. + */ + template + using StringMap = std::map>; + + /** + * @brief Unordered map keyed by strings with transparent comparisons. + */ + template + using StringUnorderedMap = std::unordered_map>; + + /** + * @brief Unordered set keyed by strings with transparent comparisons. + */ + using StringUnorderedSet = std::unordered_set>; + /** * @brief The device's HDR state in the operating system. */ diff --git a/src/common/json.cpp b/src/common/json.cpp index de7abef9..0e6be174 100644 --- a/src/common/json.cpp +++ b/src/common/json.cpp @@ -17,7 +17,7 @@ namespace display_device { DD_JSON_DEFINE_CONVERTER(EnumeratedDevice) DD_JSON_DEFINE_CONVERTER(EnumeratedDeviceList) DD_JSON_DEFINE_CONVERTER(SingleDisplayConfiguration) - DD_JSON_DEFINE_CONVERTER(std::set) + DD_JSON_DEFINE_CONVERTER(StringSet) DD_JSON_DEFINE_CONVERTER(std::string) DD_JSON_DEFINE_CONVERTER(bool) } // namespace display_device diff --git a/src/windows/include/display_device/windows/settings_manager.h b/src/windows/include/display_device/windows/settings_manager.h index b80d9657..e4ea55b7 100644 --- a/src/windows/include/display_device/windows/settings_manager.h +++ b/src/windows/include/display_device/windows/settings_manager.h @@ -57,7 +57,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return A tuple of (new_state that is to be updated/persisted, device_to_configure, additional_devices_to_configure). */ - [[nodiscard]] std::optional>> prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched); + [[nodiscard]] std::optional> prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched); /** * @brief Changes or restores the primary device based on the cached state, new state and configuration. @@ -80,7 +80,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return True if no errors have occured, false otherwise. */ - [[nodiscard]] bool prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); + [[nodiscard]] bool prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); /** * @brief Changes or restores the HDR states based on the cached state, new state and configuration. @@ -92,7 +92,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return True if no errors have occured, false otherwise. */ - [[nodiscard]] bool prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); + [[nodiscard]] bool prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); /** * @brief Try to revert the modified settings. diff --git a/src/windows/include/display_device/windows/settings_utils.h b/src/windows/include/display_device/windows/settings_utils.h index 66e14787..d6be1898 100644 --- a/src/windows/include/display_device/windows/settings_utils.h +++ b/src/windows/include/display_device/windows/settings_utils.h @@ -25,7 +25,7 @@ namespace display_device::win_utils { * const auto device_ids { flattenTopology(topology) }; * @examples_end */ - std::set flattenTopology(const ActiveTopology &topology); + StringSet flattenTopology(const ActiveTopology &topology); /** * @brief Create extended topology from all the available devices. @@ -84,7 +84,7 @@ namespace display_device::win_utils { * @param initial_topology The initial topology from `computeInitialState(...)`. * @return New topology that should be set. */ - ActiveTopology computeNewTopology(SingleDisplayConfiguration::DevicePreparation device_prep, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const ActiveTopology &initial_topology); + ActiveTopology computeNewTopology(SingleDisplayConfiguration::DevicePreparation device_prep, bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const ActiveTopology &initial_topology); /** * @brief Compute new topology + metadata from config settings and initial state. @@ -93,7 +93,7 @@ namespace display_device::win_utils { * @param initial_state The initial topology from `computeInitialState(...)` or `stripInitialState(...)` (or both). * @return A tuple of (new_topology, device_to_configure, addotional_devices_to_configure). */ - std::tuple> computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state); + std::tuple computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state); /** * @brief Compute new display modes from arbitrary data. @@ -105,7 +105,7 @@ namespace display_device::win_utils { * @param original_modes Display modes to be used as a base onto which changes are made. * @return New display modes that should be set. */ - DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes); + DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes); /** * @brief Compute new HDR states from arbitrary data. @@ -116,7 +116,7 @@ namespace display_device::win_utils { * @param original_states HDR states to be used as a base onto which changes are made. * @return New HDR states that should be set. */ - HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const HdrStateMap &original_states); + HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const HdrStateMap &original_states); /** * @brief Toggle enabled HDR states off and on again if quick succession. diff --git a/src/windows/include/display_device/windows/types.h b/src/windows/include/display_device/windows/types.h index b8af9c26..045762fe 100644 --- a/src/windows/include/display_device/windows/types.h +++ b/src/windows/include/display_device/windows/types.h @@ -67,7 +67,7 @@ namespace display_device { * @brief Ordered map of [DEVICE_ID -> PathSourceIndexData]. * @see PathSourceIndexData */ - using PathSourceIndexDataMap = std::map; + using PathSourceIndexDataMap = StringMap; /** * @brief A LIST[LIST[DEVICE_ID]] structure which represents an active topology. @@ -101,12 +101,12 @@ namespace display_device { /** * @brief Ordered map of [DEVICE_ID -> DisplayMode]. */ - using DeviceDisplayModeMap = std::map; + using DeviceDisplayModeMap = StringMap; /** * @brief Ordered map of [DEVICE_ID -> std::optional]. */ - using HdrStateMap = std::map>; + using HdrStateMap = StringMap>; /** * @brief Arbitrary data for making and undoing changes. @@ -118,7 +118,7 @@ namespace display_device { */ struct Initial { ActiveTopology m_topology {}; - std::set m_primary_devices {}; + StringSet m_primary_devices {}; /** * @brief Comparator for strict equality. diff --git a/src/windows/include/display_device/windows/win_api_utils.h b/src/windows/include/display_device/windows/win_api_utils.h index 41c6171f..6273c3db 100644 --- a/src/windows/include/display_device/windows/win_api_utils.h +++ b/src/windows/include/display_device/windows/win_api_utils.h @@ -259,7 +259,7 @@ namespace display_device::win_utils { * const auto device_ids_with_duplicates = getAllDeviceIdsAndMatchingDuplicates(*iface, { "MY_ID1" }); * @examples_end */ - [[nodiscard]] std::set getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids); + [[nodiscard]] StringSet getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const StringSet &device_ids); /** * @brief Check if the refresh rates are almost equal. diff --git a/src/windows/include/display_device/windows/win_display_device.h b/src/windows/include/display_device/windows/win_display_device.h index c2fdfd11..cf3cc864 100644 --- a/src/windows/include/display_device/windows/win_display_device.h +++ b/src/windows/include/display_device/windows/win_display_device.h @@ -45,7 +45,7 @@ namespace display_device { [[nodiscard]] bool setTopology(const ActiveTopology &new_topology) override; /** For details @see WinDisplayDeviceInterface::getCurrentDisplayModes */ - [[nodiscard]] DeviceDisplayModeMap getCurrentDisplayModes(const std::set &device_ids) const override; + [[nodiscard]] DeviceDisplayModeMap getCurrentDisplayModes(const StringSet &device_ids) const override; /** For details @see WinDisplayDeviceInterface::setDisplayModes */ [[nodiscard]] bool setDisplayModes(const DeviceDisplayModeMap &modes) override; @@ -57,7 +57,7 @@ namespace display_device { [[nodiscard]] bool setAsPrimary(const std::string &device_id) override; /** For details @see WinDisplayDeviceInterface::getCurrentHdrStates */ - [[nodiscard]] HdrStateMap getCurrentHdrStates(const std::set &device_ids) const override; + [[nodiscard]] HdrStateMap getCurrentHdrStates(const StringSet &device_ids) const override; /** For details @see WinDisplayDeviceInterface::setHdrStates */ [[nodiscard]] bool setHdrStates(const HdrStateMap &states) override; diff --git a/src/windows/include/display_device/windows/win_display_device_interface.h b/src/windows/include/display_device/windows/win_display_device_interface.h index ebd82b60..a567cd7c 100644 --- a/src/windows/include/display_device/windows/win_display_device_interface.h +++ b/src/windows/include/display_device/windows/win_display_device_interface.h @@ -117,11 +117,11 @@ namespace display_device { * Empty map can also be returned if an error has occurred. * @examples * const WinDisplayDeviceInterface* iface = getIface(...); - * const std::set device_ids { "DEVICE_ID_1", "DEVICE_ID_2" }; + * const StringSet device_ids { "DEVICE_ID_1", "DEVICE_ID_2" }; * const auto current_modes = iface->getCurrentDisplayModes(device_ids); * @examples_end */ - [[nodiscard]] virtual DeviceDisplayModeMap getCurrentDisplayModes(const std::set &device_ids) const = 0; + [[nodiscard]] virtual DeviceDisplayModeMap getCurrentDisplayModes(const StringSet &device_ids) const = 0; /** * @brief Set new display modes for the devices. @@ -171,11 +171,11 @@ namespace display_device { * @note On Windows the state cannot be retrieved until the device is active even if it supports it. * @examples * const WinDisplayDeviceInterface* iface = getIface(...); - * const std::unordered_set device_ids { "DEVICE_ID_1", "DEVICE_ID_2" }; + * const StringSet device_ids { "DEVICE_ID_1", "DEVICE_ID_2" }; * const auto current_hdr_states = iface->getCurrentHdrStates(device_ids); * @examples_end */ - [[nodiscard]] virtual HdrStateMap getCurrentHdrStates(const std::set &device_ids) const = 0; + [[nodiscard]] virtual HdrStateMap getCurrentHdrStates(const StringSet &device_ids) const = 0; /** * @brief Set HDR states for the devices. diff --git a/src/windows/settings_manager_apply.cpp b/src/windows/settings_manager_apply.cpp index 1f6c5050..989e85ed 100644 --- a/src/windows/settings_manager_apply.cpp +++ b/src/windows/settings_manager_apply.cpp @@ -118,7 +118,7 @@ namespace display_device { return ApplyResult::Ok; } - std::optional>> SettingsManager::prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched) { + std::optional> SettingsManager::prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched) { const EnumeratedDeviceList devices {m_dd_api->enumAvailableDevices()}; if (devices.empty()) { DD_LOG(error) << "Failed to enumerate display devices!"; @@ -262,7 +262,7 @@ namespace display_device { return true; } - bool SettingsManager::prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { + bool SettingsManager::prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { const auto &cached_state {m_persistence_state->getState()}; const auto cached_display_modes {cached_state ? cached_state->m_modified.m_original_modes : DeviceDisplayModeMap {}}; const bool change_required {config.m_resolution || config.m_refresh_rate}; @@ -323,7 +323,7 @@ namespace display_device { return true; } - [[nodiscard]] bool SettingsManager::prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { + [[nodiscard]] bool SettingsManager::prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { const auto &cached_state {m_persistence_state->getState()}; const auto cached_hdr_states {cached_state ? cached_state->m_modified.m_original_hdr_states : HdrStateMap {}}; const bool change_required {config.m_hdr_state}; diff --git a/src/windows/settings_utils.cpp b/src/windows/settings_utils.cpp index 6da336d9..5dd0d46f 100644 --- a/src/windows/settings_utils.cpp +++ b/src/windows/settings_utils.cpp @@ -42,8 +42,8 @@ namespace display_device::win_utils { * const auto primary_only_ids { getDeviceIds(devices, primaryOnlyDevices) }; * @examples_end */ - std::set getDeviceIds(const EnumeratedDeviceList &devices, std::add_lvalue_reference_t &predicate) { - std::set device_ids; + StringSet getDeviceIds(const EnumeratedDeviceList &devices, std::add_lvalue_reference_t &predicate) { + StringSet device_ids; for (const auto &device : devices) { if (predicate(device)) { device_ids.insert(device.m_device_id); @@ -60,7 +60,7 @@ namespace display_device::win_utils { * @return Topology without missing device ids. */ ActiveTopology stripTopology(const ActiveTopology &topology, const EnumeratedDeviceList &devices) { - const std::set available_device_ids {getDeviceIds(devices, anyDevice)}; + const StringSet available_device_ids {getDeviceIds(devices, anyDevice)}; ActiveTopology stripped_topology; for (const auto &group : topology) { @@ -85,10 +85,10 @@ namespace display_device::win_utils { * @param devices List of devices. * @return List without missing device ids. */ - std::set stripDevices(const std::set &device_ids, const EnumeratedDeviceList &devices) { - std::set available_device_ids {getDeviceIds(devices, anyDevice)}; + StringSet stripDevices(const StringSet &device_ids, const EnumeratedDeviceList &devices) { + StringSet available_device_ids {getDeviceIds(devices, anyDevice)}; - std::set available_devices; + StringSet available_devices; std::ranges::set_intersection(device_ids, available_device_ids, std::inserter(available_devices, std::begin(available_devices))); return available_devices; } @@ -99,8 +99,8 @@ namespace display_device::win_utils { * @param target_device_id Device id whose group to search for. * @return Other ids in the group without (excluding the provided one). */ - std::set tryGetOtherDevicesInTheSameGroup(const ActiveTopology &topology, const std::string &target_device_id) { - std::set device_ids; + StringSet tryGetOtherDevicesInTheSameGroup(const ActiveTopology &topology, const std::string &target_device_id) { + StringSet device_ids; for (const auto &group : topology) { for (const auto &group_device_id : group) { @@ -119,15 +119,15 @@ namespace display_device::win_utils { /** * @brief Merge the configurable devices into a vector. */ - std::vector joinConfigurableDevices(const std::string &device_to_configure, const std::set &additional_devices_to_configure) { + std::vector joinConfigurableDevices(const std::string &device_to_configure, const StringSet &additional_devices_to_configure) { std::vector devices {device_to_configure}; devices.insert(std::end(devices), std::begin(additional_devices_to_configure), std::end(additional_devices_to_configure)); return devices; } } // namespace - std::set flattenTopology(const ActiveTopology &topology) { - std::set flattened_topology; + StringSet flattenTopology(const ActiveTopology &topology) { + StringSet flattened_topology; for (const auto &group : topology) { for (const auto &device_id : group) { flattened_topology.insert(device_id); @@ -191,7 +191,7 @@ namespace display_device::win_utils { }; } - ActiveTopology computeNewTopology(const SingleDisplayConfiguration::DevicePreparation device_prep, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const ActiveTopology &initial_topology) { + ActiveTopology computeNewTopology(const SingleDisplayConfiguration::DevicePreparation device_prep, const bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const ActiveTopology &initial_topology) { using DevicePrep = SingleDisplayConfiguration::DevicePreparation; if (device_prep != DevicePrep::VerifyOnly) { @@ -249,10 +249,10 @@ namespace display_device::win_utils { }; } - std::tuple> computeNewTopologyAndMetadata(const SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state) { + std::tuple computeNewTopologyAndMetadata(const SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state) { const bool configuring_unspecified_devices {device_id.empty()}; const auto device_to_configure {configuring_unspecified_devices ? *std::begin(initial_state.m_primary_devices) : device_id}; - auto additional_devices_to_configure {configuring_unspecified_devices ? std::set {std::next(std::begin(initial_state.m_primary_devices)), std::end(initial_state.m_primary_devices)} : tryGetOtherDevicesInTheSameGroup(initial_state.m_topology, device_to_configure)}; + auto additional_devices_to_configure {configuring_unspecified_devices ? StringSet {std::next(std::begin(initial_state.m_primary_devices)), std::end(initial_state.m_primary_devices)} : tryGetOtherDevicesInTheSameGroup(initial_state.m_topology, device_to_configure)}; DD_LOG(info) << "Will compute new display device topology from the following input:\n" << " - initial topology: " << toJson(initial_state.m_topology, JSON_COMPACT) << "\n" << " - initial primary devices: " << toJson(initial_state.m_primary_devices, JSON_COMPACT) << "\n" @@ -265,7 +265,7 @@ namespace display_device::win_utils { return std::make_tuple(new_topology, device_to_configure, additional_devices_to_configure); } - DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes) { + DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, const bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes) { DeviceDisplayModeMap new_modes {original_modes}; if (resolution) { @@ -310,7 +310,7 @@ namespace display_device::win_utils { return new_modes; } - HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const HdrStateMap &original_states) { + HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const StringSet &additional_devices_to_configure, const HdrStateMap &original_states) { HdrStateMap new_states {original_states}; if (hdr_state) { @@ -359,7 +359,7 @@ namespace display_device::win_utils { return; } - std::set device_ids; + StringSet device_ids; HdrStateMap original_states; HdrStateMap inverse_states; for (const auto &[device_id, state] : current_states) { diff --git a/src/windows/win_api_utils.cpp b/src/windows/win_api_utils.cpp index d3cef768..66082419 100644 --- a/src/windows/win_api_utils.cpp +++ b/src/windows/win_api_utils.cpp @@ -229,7 +229,7 @@ namespace display_device::win_utils { PathSourceIndexDataMap collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector &paths) { PathSourceIndexDataMap path_data; - std::unordered_map paths_to_ids; + StringUnorderedMap paths_to_ids; for (std::size_t index = 0; index < paths.size(); ++index) { const auto &path {paths[index]}; @@ -295,7 +295,7 @@ namespace display_device::win_utils { std::vector new_paths; UINT32 group_id {0}; - std::unordered_map> used_source_ids_per_adapter; + StringUnorderedMap> used_source_ids_per_adapter; const auto is_source_id_already_used = [&used_source_ids_per_adapter](const LUID &adapter_id, UINT32 source_id) { auto entry_it {used_source_ids_per_adapter.find(toString(adapter_id))}; if (entry_it != std::end(used_source_ids_per_adapter)) { @@ -306,7 +306,7 @@ namespace display_device::win_utils { }; for (const auto &group : new_topology) { - std::unordered_map used_source_ids_per_adapter_per_group; + StringUnorderedMap used_source_ids_per_adapter_per_group; const auto get_already_used_source_id_in_group = [&used_source_ids_per_adapter_per_group](const LUID &adapter_id) -> std::optional { auto entry_it {used_source_ids_per_adapter_per_group.find(toString(adapter_id))}; if (entry_it != std::end(used_source_ids_per_adapter_per_group)) { @@ -397,14 +397,14 @@ namespace display_device::win_utils { return new_paths; } - std::set getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids) { + StringSet getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const StringSet &device_ids) { const auto display_data {w_api.queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; } - std::set all_device_ids; + StringSet all_device_ids; for (const auto &device_id : device_ids) { if (device_id.empty()) { DD_LOG(error) << "Device it is empty!"; diff --git a/src/windows/win_display_device_hdr.cpp b/src/windows/win_display_device_hdr.cpp index 8be4dced..2ea09b4b 100644 --- a/src/windows/win_display_device_hdr.cpp +++ b/src/windows/win_display_device_hdr.cpp @@ -15,7 +15,7 @@ namespace display_device { namespace { /** @brief HDR state map without optional values. */ - using HdrStateMapNoOpt = std::map; + using HdrStateMapNoOpt = StringMap; /** * @see setHdrStates for a description as this was split off to reduce cognitive complexity. @@ -66,7 +66,7 @@ namespace display_device { } // namespace - HdrStateMap WinDisplayDevice::getCurrentHdrStates(const std::set &device_ids) const { + HdrStateMap WinDisplayDevice::getCurrentHdrStates(const StringSet &device_ids) const { if (device_ids.empty()) { DD_LOG(error) << "Device id set is empty!"; return {}; diff --git a/src/windows/win_display_device_modes.cpp b/src/windows/win_display_device_modes.cpp index c89b8f26..9b3656b8 100644 --- a/src/windows/win_display_device_modes.cpp +++ b/src/windows/win_display_device_modes.cpp @@ -102,7 +102,7 @@ namespace display_device { } } // namespace - DeviceDisplayModeMap WinDisplayDevice::getCurrentDisplayModes(const std::set &device_ids) const { + DeviceDisplayModeMap WinDisplayDevice::getCurrentDisplayModes(const StringSet &device_ids) const { if (device_ids.empty()) { DD_LOG(error) << "Device id set is empty!"; return {}; @@ -164,7 +164,7 @@ namespace display_device { // devices were provided instead of guessing modes automatically. This also resolve the problem of // having to choose refresh rate for duplicate display - leave it to the end-user of this function... const auto keys_view {std::ranges::views::keys(modes)}; - const std::set device_ids {std::begin(keys_view), std::end(keys_view)}; + const StringSet device_ids {std::begin(keys_view), std::end(keys_view)}; const auto all_device_ids {win_utils::getAllDeviceIdsAndMatchingDuplicates(*m_w_api, device_ids)}; if (all_device_ids.empty()) { DD_LOG(error) << "Failed to get all duplicated devices!"; diff --git a/src/windows/win_display_device_topology.cpp b/src/windows/win_display_device_topology.cpp index 55c73545..72bbdee1 100644 --- a/src/windows/win_display_device_topology.cpp +++ b/src/windows/win_display_device_topology.cpp @@ -62,7 +62,7 @@ namespace display_device { // Duplicate displays can be identified by having the same x/y position. Here we have a // "position to index" map for a simple and lazy lookup in case we have to add a device to the // topology group. - std::unordered_map position_to_topology_index; + StringUnorderedMap position_to_topology_index; ActiveTopology topology; for (const auto &path : display_data->m_paths) { const auto device_info {win_utils::getDeviceInfoForValidPath(*m_w_api, path, display_device::ValidatedPathType::Active)}; @@ -96,7 +96,7 @@ namespace display_device { return false; } - std::unordered_set device_ids; + StringUnorderedSet device_ids; for (const auto &group : topology) { // Size 2 is a Windows' limitation. // You CAN set the group to be more than 2, but then diff --git a/tests/unit/general/test_json_converter.cpp b/tests/unit/general/test_json_converter.cpp index ef53304b..514aaa15 100644 --- a/tests/unit/general/test_json_converter.cpp +++ b/tests/unit/general/test_json_converter.cpp @@ -103,9 +103,9 @@ TEST_F_S(SingleDisplayConfiguration) { } TEST_F_S(StringSet) { - executeTestCase(std::set {}, R"([])"); - executeTestCase(std::set {"ABC", "DEF"}, R"(["ABC","DEF"])"); - executeTestCase(std::set {"DEF", "ABC"}, R"(["ABC","DEF"])"); + executeTestCase(display_device::StringSet {}, R"([])"); + executeTestCase(display_device::StringSet {"ABC", "DEF"}, R"(["ABC","DEF"])"); + executeTestCase(display_device::StringSet {"DEF", "ABC"}, R"(["ABC","DEF"])"); } TEST_F_S(String) { diff --git a/tests/unit/windows/test_settings_manager_apply.cpp b/tests/unit/windows/test_settings_manager_apply.cpp index 0395a361..d37ba0b3 100644 --- a/tests/unit/windows/test_settings_manager_apply.cpp +++ b/tests/unit/windows/test_settings_manager_apply.cpp @@ -169,7 +169,7 @@ namespace { .RetiresOnSaturation(); } - void expectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::DeviceDisplayModeMap &modes) const { + void expectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::StringSet &devices, const display_device::DeviceDisplayModeMap &modes) const { EXPECT_CALL(*m_dd_api, getCurrentDisplayModes(devices)) .Times(1) .WillOnce(Return(modes)) @@ -190,7 +190,7 @@ namespace { .RetiresOnSaturation(); } - void expectedGetCurrentHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::HdrStateMap &states) const { + void expectedGetCurrentHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::StringSet &devices, const display_device::HdrStateMap &states) const { EXPECT_CALL(*m_dd_api, getCurrentHdrStates(devices)) .Times(1) .WillOnce(Return(states)) diff --git a/tests/unit/windows/test_settings_utils.cpp b/tests/unit/windows/test_settings_utils.cpp index 055acab0..7fcc1be2 100644 --- a/tests/unit/windows/test_settings_utils.cpp +++ b/tests/unit/windows/test_settings_utils.cpp @@ -35,9 +35,9 @@ namespace { } // namespace TEST_F_S_MOCKED(FlattenTopology) { - EXPECT_EQ(display_device::win_utils::flattenTopology({{"DeviceId1"}, {"DeviceId2", "DeviceId3"}, {}, {"DeviceId2"}}), (std::set {"DeviceId1", "DeviceId2", "DeviceId3"})); - EXPECT_EQ(display_device::win_utils::flattenTopology({{}, {}, {}}), std::set {}); - EXPECT_EQ(display_device::win_utils::flattenTopology({}), std::set {}); + EXPECT_EQ(display_device::win_utils::flattenTopology({{"DeviceId1"}, {"DeviceId2", "DeviceId3"}, {}, {"DeviceId2"}}), (display_device::StringSet {"DeviceId1", "DeviceId2", "DeviceId3"})); + EXPECT_EQ(display_device::win_utils::flattenTopology({{}, {}, {}}), display_device::StringSet {}); + EXPECT_EQ(display_device::win_utils::flattenTopology({}), display_device::StringSet {}); } TEST_F_S_MOCKED(CreateFullExtendedTopology, NoDevicesAreAvailable) { @@ -225,7 +225,7 @@ TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesN display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); EXPECT_EQ(new_topology, DEFAULT_INITIAL_TOPOLOGY); EXPECT_EQ(device_to_configure, "DeviceId1"); - EXPECT_EQ(additional_devices_to_configure, std::set {"DeviceId2"}); + EXPECT_EQ(additional_devices_to_configure, display_device::StringSet {"DeviceId2"}); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesStripped) { @@ -237,7 +237,7 @@ TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesS display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); EXPECT_EQ(new_topology, DEFAULT_INITIAL_TOPOLOGY); EXPECT_EQ(device_to_configure, "DeviceId3"); - EXPECT_EQ(additional_devices_to_configure, std::set {}); + EXPECT_EQ(additional_devices_to_configure, display_device::StringSet {}); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, WithAdditionalDevices) { @@ -249,7 +249,7 @@ TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, WithAdditionalDevi display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); EXPECT_EQ(new_topology, DEFAULT_INITIAL_TOPOLOGY); EXPECT_EQ(device_to_configure, device_id); - EXPECT_EQ(additional_devices_to_configure, std::set {"DeviceId2"}); + EXPECT_EQ(additional_devices_to_configure, display_device::StringSet {"DeviceId2"}); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, NoAdditionalDevices) { @@ -261,7 +261,7 @@ TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, NoAdditionalDevice display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureOnlyDisplay, device_id, initial_state); EXPECT_EQ(new_topology, display_device::ActiveTopology {{"DeviceId1"}}); EXPECT_EQ(device_to_configure, device_id); - EXPECT_EQ(additional_devices_to_configure, std::set {}); + EXPECT_EQ(additional_devices_to_configure, display_device::StringSet {}); } TEST_F_S_MOCKED(TopologyGuardFn, Success) { @@ -380,7 +380,7 @@ TEST_F_S_MOCKED(TopologyGuardFn, Failure) { } TEST_F_S_MOCKED(ModeGuardFn, Success) { - EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set {"DeviceId1"})) + EXPECT_CALL(m_dd_api, getCurrentDisplayModes(display_device::StringSet {"DeviceId1"})) .Times(1) .WillOnce(Return(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); @@ -394,7 +394,7 @@ TEST_F_S_MOCKED(ModeGuardFn, Success) { } TEST_F_S_MOCKED(ModeGuardFn, Failure) { - EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set {"DeviceId1"})) + EXPECT_CALL(m_dd_api, getCurrentDisplayModes(display_device::StringSet {"DeviceId1"})) .Times(1) .WillOnce(Return(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); @@ -436,7 +436,7 @@ TEST_F_S_MOCKED(PrimaryGuardFn, Failure) { } TEST_F_S_MOCKED(HdrStateGuardFn, Success) { - EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set {"DeviceId1"})) + EXPECT_CALL(m_dd_api, getCurrentHdrStates(display_device::StringSet {"DeviceId1"})) .Times(1) .WillOnce(Return(display_device::HdrStateMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); @@ -450,7 +450,7 @@ TEST_F_S_MOCKED(HdrStateGuardFn, Success) { } TEST_F_S_MOCKED(HdrStateGuardFn, Failure) { - EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set {"DeviceId1"})) + EXPECT_CALL(m_dd_api, getCurrentHdrStates(display_device::StringSet {"DeviceId1"})) .Times(1) .WillOnce(Return(display_device::HdrStateMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); diff --git a/tests/unit/windows/test_win_api_layer.cpp b/tests/unit/windows/test_win_api_layer.cpp index acafff5a..3e31da1c 100644 --- a/tests/unit/windows/test_win_api_layer.cpp +++ b/tests/unit/windows/test_win_api_layer.cpp @@ -104,7 +104,7 @@ TEST_F_S(GetDeviceId) { const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); - std::map device_id_per_device_path; + display_device::StringMap device_id_per_device_path; for (const auto &path : all_devices->m_paths) { const auto device_id {m_layer.getDeviceId(path)}; const auto device_id_2 {m_layer.getDeviceId(path)}; @@ -135,7 +135,7 @@ TEST_F_S(GetMonitorDevicePath) { const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); - std::set current_device_paths; + display_device::StringSet current_device_paths; for (const auto &path : all_devices->m_paths) { const auto device_path {m_layer.getMonitorDevicePath(path)}; const auto device_path_2 {m_layer.getMonitorDevicePath(path)}; diff --git a/tests/unit/windows/test_win_api_utils.cpp b/tests/unit/windows/test_win_api_utils.cpp index 3f4d6a47..edfcedd2 100644 --- a/tests/unit/windows/test_win_api_utils.cpp +++ b/tests/unit/windows/test_win_api_utils.cpp @@ -815,7 +815,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates) { setupExpectCallForValidPaths(4, sequence); } - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1", "DeviceId2"}), (std::set {"DeviceId1", "DeviceId2", "DeviceId3"})); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1", "DeviceId2"}), (display_device::StringSet {"DeviceId1", "DeviceId2", "DeviceId3"})); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToQueryDevices) { @@ -823,7 +823,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToQueryDevices) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), display_device::StringSet {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, EmptyDeviceIdInProvidedList) { @@ -833,7 +833,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, EmptyDeviceIdInProvidedLis .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {""}), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {""}), display_device::StringSet {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToFindActivePath) { @@ -844,7 +844,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToFindActivePath) { .Times(4) .WillOnce(Return("")); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), display_device::StringSet {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, NoSourceModeFound) { @@ -857,7 +857,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, NoSourceModeFound) { .WillOnce(Return(pam_no_modes)); setupExpectCallForValidPaths(2, sequence); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), display_device::StringSet {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, IncompleteListOfSources) { @@ -875,7 +875,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, IncompleteListOfSources) { .RetiresOnSaturation(); setupExpectCallForValidPaths(1, sequence); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1"}), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1"}), display_device::StringSet {}); } TEST_F_S_MOCKED(FuzzyCompareRefreshRates) { diff --git a/tests/unit/windows/test_win_display_device_modes.cpp b/tests/unit/windows/test_win_display_device_modes.cpp index 30d4a4c9..38362e4a 100644 --- a/tests/unit/windows/test_win_display_device_modes.cpp +++ b/tests/unit/windows/test_win_display_device_modes.cpp @@ -113,7 +113,7 @@ namespace { const UINT32 UNDO_FLAGS {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; // Helper functions - std::optional applyExpectedModesOntoInput(std::optional input, const display_device::DeviceDisplayModeMap &modes, const std::set &excluded_ids = {}) { + std::optional applyExpectedModesOntoInput(std::optional input, const display_device::DeviceDisplayModeMap &modes, const display_device::StringSet &excluded_ids = {}) { if (!input) { return std::nullopt; } @@ -150,7 +150,7 @@ TEST_F_S(GetCurrentDisplayModes) { // Can't really compare anything else without knowing system specs const auto mode_keys_view {std::ranges::views::keys(current_modes)}; - const std::set mode_keys {std::begin(mode_keys_view), std::end(mode_keys_view)}; + const display_device::StringSet mode_keys {std::begin(mode_keys_view), std::end(mode_keys_view)}; EXPECT_EQ(flattened_topology, mode_keys); } diff --git a/tests/unit/windows/test_win_display_device_topology.cpp b/tests/unit/windows/test_win_display_device_topology.cpp index 9cb9d1c1..8ce529fc 100644 --- a/tests/unit/windows/test_win_display_device_topology.cpp +++ b/tests/unit/windows/test_win_display_device_topology.cpp @@ -83,7 +83,7 @@ TEST_F_S(GetCurrentTopology) { GTEST_SKIP_("No active devices are available in the system."); } - std::set expected_devices; + display_device::StringSet expected_devices; for (const auto &path : active_devices->m_paths) { const auto device_id {m_layer->getDeviceId(path)}; EXPECT_FALSE(device_id.empty()); diff --git a/tests/unit/windows/utils/helpers.cpp b/tests/unit/windows/utils/helpers.cpp index 26addf39..0e6e55c5 100644 --- a/tests/unit/windows/utils/helpers.cpp +++ b/tests/unit/windows/utils/helpers.cpp @@ -10,7 +10,7 @@ std::optional> getAvailableDevices(display_device::WinA return std::nullopt; } - std::set device_ids; + display_device::StringSet device_ids; for (const auto &path : all_devices->m_paths) { if (only_valid_output && path.targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER) { continue; diff --git a/tests/unit/windows/utils/mock_win_display_device.h b/tests/unit/windows/utils/mock_win_display_device.h index 0fc92fa2..b7164d45 100644 --- a/tests/unit/windows/utils/mock_win_display_device.h +++ b/tests/unit/windows/utils/mock_win_display_device.h @@ -16,11 +16,11 @@ namespace display_device { MOCK_METHOD(bool, isTopologyValid, (const ActiveTopology &), (const, override)); MOCK_METHOD(bool, isTopologyTheSame, (const ActiveTopology &, const ActiveTopology &), (const, override)); MOCK_METHOD(bool, setTopology, (const ActiveTopology &), (override)); - MOCK_METHOD(DeviceDisplayModeMap, getCurrentDisplayModes, (const std::set &), (const, override)); + MOCK_METHOD(DeviceDisplayModeMap, getCurrentDisplayModes, (const StringSet &), (const, override)); MOCK_METHOD(bool, setDisplayModes, (const DeviceDisplayModeMap &), (override)); MOCK_METHOD(bool, isPrimary, (const std::string &), (const, override)); MOCK_METHOD(bool, setAsPrimary, (const std::string &), (override)); - MOCK_METHOD(HdrStateMap, getCurrentHdrStates, (const std::set &), (const, override)); + MOCK_METHOD(HdrStateMap, getCurrentHdrStates, (const StringSet &), (const, override)); MOCK_METHOD(bool, setHdrStates, (const HdrStateMap &), (override)); }; } // namespace display_device