44using CodectoryCore . UI . Wpf ;
55using System ;
66using System . Collections . Generic ;
7+ using System . Collections . ObjectModel ;
78using System . Drawing ;
89using System . Linq ;
910using System . Management ;
@@ -53,6 +54,7 @@ public struct DISPLAY_DEVICE
5354 }
5455
5556
57+
5658 public class MonitorManager : BaseViewModel
5759 {
5860 [ DllImport ( "user32.dll" ) ]
@@ -77,9 +79,8 @@ public class MonitorManager : BaseViewModel
7779
7880 public event EventHandler AutoHDRChanged ;
7981
80- //private List<Monitor> _monitors = new List<Monitor>();
8182
82- // public List <Monitor> Monitors { get => _monitors; set { _monitors = value; OnPropertyChanged(); } }
83+ public ObservableCollection < Monitor > Monitors => Settings . Monitors ;
8384
8485 public MonitorManager ( HDRProfileSettings settings )
8586 {
@@ -118,17 +119,21 @@ private void HDRMonitorLoop()
118119 {
119120 while ( ! _monitorCancelRequested )
120121 {
121- foreach ( Monitor monitor in Settings . Monitors )
122- monitor . HDRState = HDRController . GetHDRState ( monitor . UID ) ;
122+ bool currentValue = false ;
123123
124- bool currentValue = HDRController . GetGlobalHDRState ( ) ;
124+ foreach ( Monitor monitor in Monitors )
125+ {
126+ monitor . UpdateHDRState ( ) ;
127+ if ( monitor . AutoHDR )
128+ currentValue = currentValue || monitor . HDRState ;
129+ }
125130 bool changed = GlobalHDRIsActive != currentValue ;
126131 GlobalHDRIsActive = currentValue ;
127132 if ( changed )
128133 {
129134 try { HDRIsActiveChanged ? . Invoke ( null , EventArgs . Empty ) ; } catch { }
130135 }
131- System . Threading . Thread . Sleep ( 50 ) ;
136+ System . Threading . Thread . Sleep ( 100 ) ;
132137 }
133138 }
134139
@@ -209,27 +214,27 @@ private void MergeMonitors(List<Monitor> monitors)
209214 {
210215
211216 List < Monitor > toRemove = new List < Monitor > ( ) ;
212- foreach ( Monitor monitor in Settings . Monitors )
217+ foreach ( Monitor monitor in Monitors )
213218 {
214219 if ( ! monitors . Any ( m => m . UID . Equals ( monitor . UID ) ) )
215220 toRemove . Add ( monitor ) ;
216221 }
217222 foreach ( Monitor monitor in toRemove )
218- Settings . Monitors . Remove ( monitor ) ;
223+ Monitors . Remove ( monitor ) ;
219224 foreach ( Monitor monitor in monitors )
220225 {
221226 if ( ! Settings . Monitors . Any ( m => m . UID . Equals ( monitor . UID ) ) )
222227 Settings . Monitors . Add ( monitor ) ;
223228 else
224229 {
225- Monitor existingMonitor = Settings . Monitors . First ( m => m . UID . Equals ( monitor . UID ) ) ;
230+ Monitor existingMonitor = Monitors . First ( m => m . UID . Equals ( monitor . UID ) ) ;
226231 existingMonitor . Name = monitor . Name ;
227232 existingMonitor . RefreshRate = monitor . RefreshRate ;
228233 existingMonitor . Resolution = monitor . Resolution ;
229234 }
230235 }
231236
232- foreach ( Monitor monitor in Settings . Monitors )
237+ foreach ( Monitor monitor in Monitors )
233238 {
234239 monitor . PropertyChanged += Monitor_PropertyChanged ;
235240 }
0 commit comments