1
1
/* *
2
2
* @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.
4
4
*/
5
5
// class header include
6
6
#include " display_device/windows/settings_manager.h"
@@ -23,25 +23,25 @@ namespace display_device {
23
23
}
24
24
} // namespace
25
25
26
- bool
26
+ SettingsManager::RevertResult
27
27
SettingsManager::revertSettings () {
28
28
const auto &cached_state { m_persistence_state->getState () };
29
29
if (!cached_state) {
30
- return true ;
30
+ return RevertResult::Ok ;
31
31
}
32
32
33
33
const auto api_access { m_dd_api->isApiAccessAvailable () };
34
34
DD_LOG (info) << " Trying to revert applied display device settings. API is available: " << toJson (api_access);
35
35
36
36
if (!api_access) {
37
- return false ;
37
+ return RevertResult::ApiTemporarilyUnavailable ;
38
38
}
39
39
40
40
const auto current_topology { m_dd_api->getCurrentTopology () };
41
41
if (!m_dd_api->isTopologyValid (current_topology)) {
42
42
DD_LOG (error) << " Retrieved current topology is invalid:\n "
43
43
<< toJson (current_topology);
44
- return false ;
44
+ return RevertResult::TopologyIsInvalid ;
45
45
}
46
46
47
47
bool system_settings_touched { false };
@@ -50,8 +50,8 @@ namespace display_device {
50
50
win_utils::blankHdrStates (*m_dd_api, m_workarounds.m_hdr_blank_delay );
51
51
}
52
52
} };
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) };
55
55
if (!m_dd_api->isTopologyValid (topology_to_restore)) {
56
56
topology_to_restore = current_topology;
57
57
}
@@ -66,15 +66,15 @@ namespace display_device {
66
66
67
67
// We can revert the modified setting independently before playing around with initial topology.
68
68
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 ) {
70
70
// Error already logged
71
- return false ;
71
+ return result ;
72
72
}
73
73
74
74
if (!m_dd_api->isTopologyValid (cached_state->m_initial .m_topology )) {
75
75
DD_LOG (error) << " Trying to revert to an invalid initial topology:\n "
76
76
<< toJson (cached_state->m_initial .m_topology );
77
- return false ;
77
+ return RevertResult::TopologyIsInvalid ;
78
78
}
79
79
80
80
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 {
83
83
if (need_to_switch_topology && !m_dd_api->setTopology (cached_state->m_initial .m_topology )) {
84
84
DD_LOG (error) << " Failed to change topology to:\n "
85
85
<< toJson (cached_state->m_initial .m_topology );
86
- return false ;
86
+ return RevertResult::SwitchingTopologyFailed ;
87
87
}
88
88
89
89
if (!m_persistence_state->persistState (std::nullopt)) {
90
90
DD_LOG (error) << " Failed to save reverted settings! Undoing initial topology changes..." ;
91
- return false ;
91
+ return RevertResult::PersistenceSaveFailed ;
92
92
}
93
93
94
94
if (m_audio_context_api->isCaptured ()) {
@@ -97,28 +97,28 @@ namespace display_device {
97
97
98
98
// Disable guards
99
99
topology_prep_guard.set_active (false );
100
- return true ;
100
+ return RevertResult::Ok ;
101
101
}
102
102
103
- bool
103
+ SettingsManager::RevertResult
104
104
SettingsManager::revertModifiedSettings (const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology) {
105
105
const auto &cached_state { m_persistence_state->getState () };
106
106
if (!cached_state || !cached_state->m_modified .hasModifications ()) {
107
- return true ;
107
+ return RevertResult::Ok ;
108
108
}
109
109
110
110
if (!m_dd_api->isTopologyValid (cached_state->m_modified .m_topology )) {
111
111
DD_LOG (error) << " Trying to revert modified settings using invalid topology:\n "
112
112
<< toJson (cached_state->m_modified .m_topology );
113
- return false ;
113
+ return RevertResult::TopologyIsInvalid ;
114
114
}
115
115
116
116
const bool is_topology_the_same { m_dd_api->isTopologyTheSame (current_topology, cached_state->m_modified .m_topology ) };
117
117
system_settings_touched = !is_topology_the_same;
118
118
if (!is_topology_the_same && !m_dd_api->setTopology (cached_state->m_modified .m_topology )) {
119
119
DD_LOG (error) << " Failed to change topology to:\n "
120
120
<< toJson (cached_state->m_modified .m_topology );
121
- return false ;
121
+ return RevertResult::SwitchingTopologyFailed ;
122
122
}
123
123
if (switched_topology) {
124
124
*switched_topology = !is_topology_the_same;
@@ -135,7 +135,7 @@ namespace display_device {
135
135
<< toJson (cached_state->m_modified .m_original_hdr_states );
136
136
if (!m_dd_api->setHdrStates (cached_state->m_modified .m_original_hdr_states )) {
137
137
// Error already logged
138
- return false ;
138
+ return RevertResult::RevertingHdrStatesFailed ;
139
139
}
140
140
141
141
hdr_guard_fn = win_utils::hdrStateGuardFn (*m_dd_api, current_states);
@@ -152,7 +152,7 @@ namespace display_device {
152
152
if (!m_dd_api->setDisplayModes (cached_state->m_modified .m_original_modes )) {
153
153
system_settings_touched = true ;
154
154
// Error already logged
155
- return false ;
155
+ return RevertResult::RevertingDisplayModesFailed ;
156
156
}
157
157
158
158
// 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 {
175
175
DD_LOG (info) << " Trying to change back the original primary device to: " << toJson (cached_state->m_modified .m_original_primary_device );
176
176
if (!m_dd_api->setAsPrimary (cached_state->m_modified .m_original_primary_device )) {
177
177
// Error already logged
178
- return false ;
178
+ return RevertResult::RevertingPrimaryDeviceFailed ;
179
179
}
180
180
181
181
primary_guard_fn = win_utils::primaryGuardFn (*m_dd_api, current_primary_device);
@@ -186,13 +186,13 @@ namespace display_device {
186
186
cleared_data.m_modified = { cleared_data.m_modified .m_topology };
187
187
if (!m_persistence_state->persistState (cleared_data)) {
188
188
DD_LOG (error) << " Failed to save reverted settings! Undoing changes to modified topology..." ;
189
- return false ;
189
+ return RevertResult::PersistenceSaveFailed ;
190
190
}
191
191
192
192
// Disable guards
193
193
hdr_guard.set_active (false );
194
194
mode_guard.set_active (false );
195
195
primary_guard.set_active (false );
196
- return true ;
196
+ return RevertResult::Ok ;
197
197
}
198
198
} // namespace display_device
0 commit comments