From b5e84749a7c215a0c782f06cf8aaf22ee9a579cd Mon Sep 17 00:00:00 2001 From: Nguyen Duy Date: Thu, 14 May 2026 15:42:58 +0700 Subject: [PATCH] feat: update CLI mode to displays in reverse order --- app/CLI.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/CLI.cs b/app/CLI.cs index 8bcaecf..f95a371 100644 --- a/app/CLI.cs +++ b/app/CLI.cs @@ -132,7 +132,7 @@ namespace ParsecVDisplay if (Vdd.Core.AddDisplay(VddHandle, out int index)) { - Console.WriteLine($"Added a virtual display with index {0}.", index); + Console.WriteLine($"Added a virtual display with index {index}."); return index; } else @@ -159,10 +159,26 @@ namespace ParsecVDisplay else if (removeAll) { PrepareVdd(); - foreach (var di in displays) + + // Reverse order preserves the Windows 10 Connectivity + // registry config (see docs/issues/windows-10-display- + // configurations-bug.md). Best-effort per display so + // one failure doesn't strand the rest. + int failed = 0; + for (int i = displays.Count - 1; i >= 0; i--) { + var di = displays[i]; if (!Vdd.Core.RemoveDisplay(VddHandle, di.DisplayIndex)) - throw new Exception(string.Format("Failed to remove the display at index {0}.", index)); + { + failed++; + Console.WriteLine("Warning: failed to remove display at index {0}.", di.DisplayIndex); + } + } + + if (failed > 0) + { + Console.WriteLine("Removed {0}/{1} displays.", displays.Count - failed, displays.Count); + return 1; } Console.WriteLine("Removed all added displays.");