@@ -38,6 +38,8 @@ public class FancyZonesEditorIO
3838 PropertyNamingPolicy = new DashCaseNamingPolicy ( ) ,
3939 } ;
4040
41+ private List < DeviceWrapper > _unusedDevices = new List < DeviceWrapper > ( ) ;
42+
4143 public string FancyZonesSettingsFile { get ; private set ; }
4244
4345 public string FancyZonesEditorParamsFile { get ; private set ; }
@@ -225,11 +227,11 @@ public static void ParseCommandLineArguments()
225227 // Span zones across monitors
226228 App . Overlay . SpanZonesAcrossMonitors = int . Parse ( argsParts [ ( int ) CmdArgs . SpanZones ] ) == 1 ;
227229
230+ // Target monitor id
231+ string targetMonitorName = argsParts [ ( int ) CmdArgs . TargetMonitorId ] ;
232+
228233 if ( ! App . Overlay . SpanZonesAcrossMonitors )
229234 {
230- // Target monitor id
231- string targetMonitorName = argsParts [ ( int ) CmdArgs . TargetMonitorId ] ;
232-
233235 // Test launch with custom monitors configuration
234236 bool isCustomMonitorConfigurationMode = targetMonitorName . StartsWith ( "Monitor#" ) ;
235237 if ( isCustomMonitorConfigurationMode )
@@ -336,6 +338,10 @@ public static void ParseCommandLineArguments()
336338 }
337339 }
338340 }
341+ else
342+ {
343+ App . Overlay . Monitors [ App . Overlay . CurrentDesktop ] . Device . Id = targetMonitorName ;
344+ }
339345 }
340346 catch ( Exception )
341347 {
@@ -435,6 +441,31 @@ public ParsingResult ParseParams()
435441 }
436442 }
437443 }
444+ else
445+ {
446+ // Update monitors data
447+ foreach ( Monitor monitor in App . Overlay . Monitors )
448+ {
449+ bool matchFound = false ;
450+ foreach ( NativeMonitorData nativeData in editorParams . Monitors )
451+ {
452+ // Can't do an exact match since the rounding algorithm used by the framework is different from ours
453+ if ( monitor . Device . UnscaledBounds . X >= ( nativeData . LeftCoordinate - 1 ) && monitor . Device . UnscaledBounds . X <= ( nativeData . LeftCoordinate + 1 ) &&
454+ monitor . Device . UnscaledBounds . Y >= ( nativeData . TopCoordinate - 1 ) && monitor . Device . UnscaledBounds . Y <= ( nativeData . TopCoordinate + 1 ) )
455+ {
456+ monitor . Device . Id = nativeData . MonitorId ;
457+ monitor . Device . Dpi = nativeData . Dpi ;
458+ matchFound = true ;
459+ break ;
460+ }
461+ }
462+
463+ if ( matchFound == false )
464+ {
465+ MessageBox . Show ( string . Format ( Properties . Resources . Error_Monitor_Match_Not_Found , monitor . Device . UnscaledBounds . ToString ( ) ) ) ;
466+ }
467+ }
468+ }
438469 }
439470 catch ( Exception ex )
440471 {
@@ -451,6 +482,8 @@ public ParsingResult ParseParams()
451482
452483 public ParsingResult ParseZoneSettings ( )
453484 {
485+ _unusedDevices . Clear ( ) ;
486+
454487 if ( _fileSystem . File . Exists ( FancyZonesSettingsFile ) )
455488 {
456489 ZoneSettingsWrapper zoneSettings ;
@@ -491,7 +524,7 @@ public void SerializeZoneSettings()
491524 zoneSettings . Devices = new List < DeviceWrapper > ( ) ;
492525 zoneSettings . CustomZoneSets = new List < CustomLayoutWrapper > ( ) ;
493526
494- // Serialize devices
527+ // Serialize used devices
495528 foreach ( var monitor in App . Overlay . Monitors )
496529 {
497530 LayoutSettings zoneset = monitor . Settings ;
@@ -515,6 +548,12 @@ public void SerializeZoneSettings()
515548 } ) ;
516549 }
517550
551+ // Serialize unused devices
552+ foreach ( var device in _unusedDevices )
553+ {
554+ zoneSettings . Devices . Add ( device ) ;
555+ }
556+
518557 // Serialize custom zonesets
519558 foreach ( LayoutModel layout in MainWindowSettingsModel . CustomModels )
520559 {
@@ -634,37 +673,30 @@ private bool SetDevices(List<DeviceWrapper> devices)
634673 continue ;
635674 }
636675
637- var settings = new LayoutSettings
638- {
639- ZonesetUuid = device . ActiveZoneset . Uuid ,
640- ShowSpacing = device . EditorShowSpacing ,
641- Spacing = device . EditorSpacing ,
642- Type = JsonTagToLayoutType ( device . ActiveZoneset . Type ) ,
643- ZoneCount = device . EditorZoneCount ,
644- SensitivityRadius = device . EditorSensitivityRadius ,
645- } ;
646-
647- if ( ! App . Overlay . SpanZonesAcrossMonitors )
676+ bool unused = true ;
677+ foreach ( Monitor monitor in monitors )
648678 {
649- foreach ( Monitor monitor in monitors )
679+ if ( monitor . Device . Id == device . DeviceId )
650680 {
651- if ( monitor . Device . Id == device . DeviceId )
681+ var settings = new LayoutSettings
652682 {
653- monitor . Settings = settings ;
654- break ;
655- }
683+ ZonesetUuid = device . ActiveZoneset . Uuid ,
684+ ShowSpacing = device . EditorShowSpacing ,
685+ Spacing = device . EditorSpacing ,
686+ Type = JsonTagToLayoutType ( device . ActiveZoneset . Type ) ,
687+ ZoneCount = device . EditorZoneCount ,
688+ SensitivityRadius = device . EditorSensitivityRadius ,
689+ } ;
690+
691+ monitor . Settings = settings ;
692+ unused = false ;
693+ break ;
656694 }
657695 }
658- else
696+
697+ if ( unused )
659698 {
660- bool isLayoutMultiMonitor = device . DeviceId . StartsWith ( MultiMonitorId ) ;
661- if ( isLayoutMultiMonitor )
662- {
663- // one zoneset for all desktops
664- App . Overlay . Monitors [ App . Overlay . CurrentDesktop ] . Settings = settings ;
665- App . Overlay . Monitors [ App . Overlay . CurrentDesktop ] . Device . Id = device . DeviceId ;
666- break ;
667- }
699+ _unusedDevices . Add ( device ) ;
668700 }
669701 }
670702
0 commit comments