Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/include/display_device/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>)
DD_JSON_DECLARE_CONVERTER(StringSet)
DD_JSON_DECLARE_CONVERTER(std::string)
DD_JSON_DECLARE_CONVERTER(bool)
} // namespace display_device
40 changes: 40 additions & 0 deletions src/common/include/display_device/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,53 @@
#pragma once

// system includes
#include <cstddef>
#include <cstdint>
#include <functional>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>

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<std::string_view> {}(value);
}
};

/**
* @brief Ordered set keyed by strings with transparent comparisons.
*/
using StringSet = std::set<std::string, std::less<>>;

/**
* @brief Ordered map keyed by strings with transparent comparisons.
*/
template<typename T>
using StringMap = std::map<std::string, T, std::less<>>;

/**
* @brief Unordered map keyed by strings with transparent comparisons.
*/
template<typename T>
using StringUnorderedMap = std::unordered_map<std::string, T, StringHash, std::equal_to<>>;

/**
* @brief Unordered set keyed by strings with transparent comparisons.
*/
using StringUnorderedSet = std::unordered_set<std::string, StringHash, std::equal_to<>>;

/**
* @brief The device's HDR state in the operating system.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/common/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>)
DD_JSON_DEFINE_CONVERTER(StringSet)
DD_JSON_DEFINE_CONVERTER(std::string)
DD_JSON_DEFINE_CONVERTER(bool)
} // namespace display_device
6 changes: 3 additions & 3 deletions src/windows/include/display_device/windows/settings_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<SingleDisplayConfigState, std::string, std::set<std::string>>> prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched);
[[nodiscard]] std::optional<std::tuple<SingleDisplayConfigState, std::string, StringSet>> 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.
Expand All @@ -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<std::string> &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.
Expand All @@ -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<std::string> &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.
Expand Down
10 changes: 5 additions & 5 deletions src/windows/include/display_device/windows/settings_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace display_device::win_utils {
* const auto device_ids { flattenTopology(topology) };
* @examples_end
*/
std::set<std::string> flattenTopology(const ActiveTopology &topology);
StringSet flattenTopology(const ActiveTopology &topology);

/**
* @brief Create extended topology from all the available devices.
Expand Down Expand Up @@ -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<std::string> &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.
Expand All @@ -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<ActiveTopology, std::string, std::set<std::string>> computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state);
std::tuple<ActiveTopology, std::string, StringSet> computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state);

/**
* @brief Compute new display modes from arbitrary data.
Expand All @@ -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> &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);
DeviceDisplayModeMap 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 DeviceDisplayModeMap &original_modes);

/**
* @brief Compute new HDR states from arbitrary data.
Expand All @@ -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<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);
HdrStateMap computeNewHdrStates(const std::optional<HdrState> &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.
Expand Down
8 changes: 4 additions & 4 deletions src/windows/include/display_device/windows/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace display_device {
* @brief Ordered map of [DEVICE_ID -> PathSourceIndexData].
* @see PathSourceIndexData
*/
using PathSourceIndexDataMap = std::map<std::string, PathSourceIndexData>;
using PathSourceIndexDataMap = StringMap<PathSourceIndexData>;

/**
* @brief A LIST[LIST[DEVICE_ID]] structure which represents an active topology.
Expand Down Expand Up @@ -101,12 +101,12 @@ namespace display_device {
/**
* @brief Ordered map of [DEVICE_ID -> DisplayMode].
*/
using DeviceDisplayModeMap = std::map<std::string, DisplayMode>;
using DeviceDisplayModeMap = StringMap<DisplayMode>;

/**
* @brief Ordered map of [DEVICE_ID -> std::optional<HdrState>].
*/
using HdrStateMap = std::map<std::string, std::optional<HdrState>>;
using HdrStateMap = StringMap<std::optional<HdrState>>;

/**
* @brief Arbitrary data for making and undoing changes.
Expand All @@ -118,7 +118,7 @@ namespace display_device {
*/
struct Initial {
ActiveTopology m_topology {};
std::set<std::string> m_primary_devices {};
StringSet m_primary_devices {};

/**
* @brief Comparator for strict equality.
Expand Down
2 changes: 1 addition & 1 deletion src/windows/include/display_device/windows/win_api_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace display_device::win_utils {
* const auto device_ids_with_duplicates = getAllDeviceIdsAndMatchingDuplicates(*iface, { "MY_ID1" });
* @examples_end
*/
[[nodiscard]] std::set<std::string> getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set<std::string> &device_ids);
[[nodiscard]] StringSet getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const StringSet &device_ids);

/**
* @brief Check if the refresh rates are almost equal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &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;
Expand All @@ -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<std::string> &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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> &device_ids) const = 0;
[[nodiscard]] virtual DeviceDisplayModeMap getCurrentDisplayModes(const StringSet &device_ids) const = 0;

/**
* @brief Set new display modes for the devices.
Expand Down Expand Up @@ -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<std::string> 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<std::string> &device_ids) const = 0;
[[nodiscard]] virtual HdrStateMap getCurrentHdrStates(const StringSet &device_ids) const = 0;

/**
* @brief Set HDR states for the devices.
Expand Down
6 changes: 3 additions & 3 deletions src/windows/settings_manager_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace display_device {
return ApplyResult::Ok;
}

std::optional<std::tuple<SingleDisplayConfigState, std::string, std::set<std::string>>> SettingsManager::prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched) {
std::optional<std::tuple<SingleDisplayConfigState, std::string, StringSet>> 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!";
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace display_device {
return true;
}

bool SettingsManager::prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set<std::string> &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};
Expand Down Expand Up @@ -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<std::string> &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};
Expand Down
Loading
Loading