11/* *
22 * @file src/windows/settings_manager_revert.cpp
3- * @brief Definitions for the methods for reverting settings in SettingsManager..
3+ * @brief Definitions for the methods for reverting settings in SettingsManager.
44 */
55// class header include
66#include " display_device/windows/settings_manager.h"
@@ -23,25 +23,25 @@ namespace display_device {
2323 }
2424 } // namespace
2525
26- bool
26+ SettingsManager::RevertResult
2727 SettingsManager::revertSettings () {
2828 const auto &cached_state { m_persistence_state->getState () };
2929 if (!cached_state) {
30- return true ;
30+ return RevertResult::Ok ;
3131 }
3232
3333 const auto api_access { m_dd_api->isApiAccessAvailable () };
3434 DD_LOG (info) << " Trying to revert applied display device settings. API is available: " << toJson (api_access);
3535
3636 if (!api_access) {
37- return false ;
37+ return RevertResult::ApiTemporarilyUnavailable ;
3838 }
3939
4040 const auto current_topology { m_dd_api->getCurrentTopology () };
4141 if (!m_dd_api->isTopologyValid (current_topology)) {
4242 DD_LOG (error) << " Retrieved current topology is invalid:\n "
4343 << toJson (current_topology);
44- return false ;
44+ return RevertResult::TopologyIsInvalid ;
4545 }
4646
4747 bool system_settings_touched { false };
@@ -50,8 +50,8 @@ namespace display_device {
5050 win_utils::blankHdrStates (*m_dd_api, m_workarounds.m_hdr_blank_delay );
5151 }
5252 } };
53- boost::scope::scope_exit topology_prep_guard { [this , &cached_state, & current_topology, &system_settings_touched]() {
54- auto topology_to_restore { win_utils::stripTopologyOfUnavailableDevices (*m_dd_api, cached_state-> m_initial . m_topology ) };
53+ boost::scope::scope_exit topology_prep_guard { [this , ¤t_topology, &system_settings_touched]() {
54+ auto topology_to_restore { win_utils::createFullExtendedTopology (*m_dd_api) };
5555 if (!m_dd_api->isTopologyValid (topology_to_restore)) {
5656 topology_to_restore = current_topology;
5757 }
@@ -66,15 +66,15 @@ namespace display_device {
6666
6767 // We can revert the modified setting independently before playing around with initial topology.
6868 bool switched_to_modified_topology { false };
69- if (! revertModifiedSettings (current_topology, system_settings_touched, &switched_to_modified_topology)) {
69+ if (const auto result = revertModifiedSettings (current_topology, system_settings_touched, &switched_to_modified_topology); result != RevertResult::Ok ) {
7070 // Error already logged
71- return false ;
71+ return result ;
7272 }
7373
7474 if (!m_dd_api->isTopologyValid (cached_state->m_initial .m_topology )) {
7575 DD_LOG (error) << " Trying to revert to an invalid initial topology:\n "
7676 << toJson (cached_state->m_initial .m_topology );
77- return false ;
77+ return RevertResult::TopologyIsInvalid ;
7878 }
7979
8080 const bool is_topology_the_same { m_dd_api->isTopologyTheSame (current_topology, cached_state->m_initial .m_topology ) };
@@ -83,12 +83,12 @@ namespace display_device {
8383 if (need_to_switch_topology && !m_dd_api->setTopology (cached_state->m_initial .m_topology )) {
8484 DD_LOG (error) << " Failed to change topology to:\n "
8585 << toJson (cached_state->m_initial .m_topology );
86- return false ;
86+ return RevertResult::SwitchingTopologyFailed ;
8787 }
8888
8989 if (!m_persistence_state->persistState (std::nullopt )) {
9090 DD_LOG (error) << " Failed to save reverted settings! Undoing initial topology changes..." ;
91- return false ;
91+ return RevertResult::PersistenceSaveFailed ;
9292 }
9393
9494 if (m_audio_context_api->isCaptured ()) {
@@ -97,28 +97,28 @@ namespace display_device {
9797
9898 // Disable guards
9999 topology_prep_guard.set_active (false );
100- return true ;
100+ return RevertResult::Ok ;
101101 }
102102
103- bool
103+ SettingsManager::RevertResult
104104 SettingsManager::revertModifiedSettings (const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology) {
105105 const auto &cached_state { m_persistence_state->getState () };
106106 if (!cached_state || !cached_state->m_modified .hasModifications ()) {
107- return true ;
107+ return RevertResult::Ok ;
108108 }
109109
110110 if (!m_dd_api->isTopologyValid (cached_state->m_modified .m_topology )) {
111111 DD_LOG (error) << " Trying to revert modified settings using invalid topology:\n "
112112 << toJson (cached_state->m_modified .m_topology );
113- return false ;
113+ return RevertResult::TopologyIsInvalid ;
114114 }
115115
116116 const bool is_topology_the_same { m_dd_api->isTopologyTheSame (current_topology, cached_state->m_modified .m_topology ) };
117117 system_settings_touched = !is_topology_the_same;
118118 if (!is_topology_the_same && !m_dd_api->setTopology (cached_state->m_modified .m_topology )) {
119119 DD_LOG (error) << " Failed to change topology to:\n "
120120 << toJson (cached_state->m_modified .m_topology );
121- return false ;
121+ return RevertResult::SwitchingTopologyFailed ;
122122 }
123123 if (switched_topology) {
124124 *switched_topology = !is_topology_the_same;
@@ -135,7 +135,7 @@ namespace display_device {
135135 << toJson (cached_state->m_modified .m_original_hdr_states );
136136 if (!m_dd_api->setHdrStates (cached_state->m_modified .m_original_hdr_states )) {
137137 // Error already logged
138- return false ;
138+ return RevertResult::RevertingHdrStatesFailed ;
139139 }
140140
141141 hdr_guard_fn = win_utils::hdrStateGuardFn (*m_dd_api, current_states);
@@ -152,7 +152,7 @@ namespace display_device {
152152 if (!m_dd_api->setDisplayModes (cached_state->m_modified .m_original_modes )) {
153153 system_settings_touched = true ;
154154 // Error already logged
155- return false ;
155+ return RevertResult::RevertingDisplayModesFailed ;
156156 }
157157
158158 // It is possible that the display modes will not actually change even though the "current != new" condition is true.
@@ -175,7 +175,7 @@ namespace display_device {
175175 DD_LOG (info) << " Trying to change back the original primary device to: " << toJson (cached_state->m_modified .m_original_primary_device );
176176 if (!m_dd_api->setAsPrimary (cached_state->m_modified .m_original_primary_device )) {
177177 // Error already logged
178- return false ;
178+ return RevertResult::RevertingPrimaryDeviceFailed ;
179179 }
180180
181181 primary_guard_fn = win_utils::primaryGuardFn (*m_dd_api, current_primary_device);
@@ -186,13 +186,13 @@ namespace display_device {
186186 cleared_data.m_modified = { cleared_data.m_modified .m_topology };
187187 if (!m_persistence_state->persistState (cleared_data)) {
188188 DD_LOG (error) << " Failed to save reverted settings! Undoing changes to modified topology..." ;
189- return false ;
189+ return RevertResult::PersistenceSaveFailed ;
190190 }
191191
192192 // Disable guards
193193 hdr_guard.set_active (false );
194194 mode_guard.set_active (false );
195195 primary_guard.set_active (false );
196- return true ;
196+ return RevertResult::Ok ;
197197 }
198198} // namespace display_device
0 commit comments