From 9ec7e8af8ff81db0ea351486d8691865f48a3894 Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:03:52 +0100 Subject: [PATCH] Feature: Screenshot mode --- Source/GlobalAssemblyInfo.cs | 4 +- .../CommandLineInfo.cs | 16 +++++ .../CommandLineManager.cs | 65 +++++++++++++++++++ .../Settings/CommandLineManagerTests.cs | 34 ++++++++++ Source/NETworkManager/MainWindow.xaml.cs | 45 ++++++++++++- Website/docs/changelog/next-release.md | 1 + Website/docs/commandline-arguments.md | 25 +++++++ 7 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 Source/NETworkManager.Tests/Settings/CommandLineManagerTests.cs diff --git a/Source/GlobalAssemblyInfo.cs b/Source/GlobalAssemblyInfo.cs index 193da9dd26..f3fd20736a 100644 --- a/Source/GlobalAssemblyInfo.cs +++ b/Source/GlobalAssemblyInfo.cs @@ -6,5 +6,5 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("2026.11.11.0")] -[assembly: AssemblyFileVersion("2026.11.11.0")] +[assembly: AssemblyVersion("2026.11.14.0")] +[assembly: AssemblyFileVersion("2026.11.14.0")] diff --git a/Source/NETworkManager.Settings/CommandLineInfo.cs b/Source/NETworkManager.Settings/CommandLineInfo.cs index c844843611..d5213987df 100644 --- a/Source/NETworkManager.Settings/CommandLineInfo.cs +++ b/Source/NETworkManager.Settings/CommandLineInfo.cs @@ -32,6 +32,22 @@ public class CommandLineInfo /// public ApplicationName Application { get; set; } = ApplicationName.None; + /// + /// Indicates if the application should start in screenshot mode (fixed window size, centered, not resizable, + /// window position not loaded or saved) to take consistent screenshots for the documentation + /// + public bool Screenshot { get; set; } + + /// + /// Width of the window in screenshot mode (device-independent pixels, scaled with the Windows display scaling) + /// + public int ScreenshotWidth { get; set; } = CommandLineManager.ScreenshotDefaultWidth; + + /// + /// Height of the window in screenshot mode (device-independent pixels, scaled with the Windows display scaling) + /// + public int ScreenshotHeight { get; set; } = CommandLineManager.ScreenshotDefaultHeight; + /// /// Wrong parameter(s) detected in the command line to display in the help dialog /// diff --git a/Source/NETworkManager.Settings/CommandLineManager.cs b/Source/NETworkManager.Settings/CommandLineManager.cs index f8cb40b26e..4de53f8630 100644 --- a/Source/NETworkManager.Settings/CommandLineManager.cs +++ b/Source/NETworkManager.Settings/CommandLineManager.cs @@ -56,6 +56,24 @@ static CommandLineManager() WrongParameterDetected(parameters); return; } + } // Screenshot mode (optional size, e.g. --screenshot:1280x800) + else if (param[0].Equals(ParameterScreenshot, StringComparison.InvariantCultureIgnoreCase)) + { + Current.Screenshot = true; + + if (param.Length > 1) + { + if (TryParseScreenshotSize(param[1], out var width, out var height)) + { + Current.ScreenshotWidth = width; + Current.ScreenshotHeight = height; + } + else + { + WrongParameterDetected(parameters); + return; + } + } } else { @@ -84,6 +102,24 @@ static CommandLineManager() public static string ParameterAutostart => $"{ParameterIdentifier}autostart"; public static string ParameterRestartPid => $"{ParameterIdentifier}restart-pid"; + // Documentation (screenshots) + public static string ParameterScreenshot => $"{ParameterIdentifier}screenshot"; + + /// + /// Default window width in screenshot mode (16:10, readable when scaled to the width of the documentation). + /// + public const int ScreenshotDefaultWidth = 1280; + + /// + /// Default window height in screenshot mode. + /// + public const int ScreenshotDefaultHeight = 800; + + // Minimum size of the main window (MinWidth / MinHeight in MainWindow.xaml) + private const int ScreenshotMinWidth = 800; + private const int ScreenshotMinHeight = 600; + private const int ScreenshotMaxSize = 7680; + public static CommandLineInfo Current { get; set; } public static string GetParameterWithSplitIdentifier(string parameter) @@ -91,6 +127,35 @@ public static string GetParameterWithSplitIdentifier(string parameter) return $"{parameter}{ValueSplitIdentifier}"; } + /// + /// Parses the window size of the screenshot mode (WIDTHxHEIGHT, e.g. 1280x800). + /// + /// Size to parse. + /// Parsed width. + /// Parsed height. + /// true if the size is valid and not smaller than the minimum size of the main window. + public static bool TryParseScreenshotSize(string value, out int width, out int height) + { + width = 0; + height = 0; + + var size = value.Split('x', 'X'); + + if (size.Length != 2 || + !int.TryParse(size[0], out var parsedWidth) || + !int.TryParse(size[1], out var parsedHeight)) + return false; + + if (parsedWidth is < ScreenshotMinWidth or > ScreenshotMaxSize || + parsedHeight is < ScreenshotMinHeight or > ScreenshotMaxSize) + return false; + + width = parsedWidth; + height = parsedHeight; + + return true; + } + private static void WrongParameterDetected(string[] parameters) { Current.WrongParameter = string.Join(" ", parameters); diff --git a/Source/NETworkManager.Tests/Settings/CommandLineManagerTests.cs b/Source/NETworkManager.Tests/Settings/CommandLineManagerTests.cs new file mode 100644 index 0000000000..bcd3676f66 --- /dev/null +++ b/Source/NETworkManager.Tests/Settings/CommandLineManagerTests.cs @@ -0,0 +1,34 @@ +using NETworkManager.Settings; +using Xunit; + +namespace NETworkManager.Tests.Settings; + +public class CommandLineManagerTests +{ + [Theory] + [InlineData("1280x800", 1280, 800)] + [InlineData("1200X800", 1200, 800)] + [InlineData("800x600", 800, 600)] + public void ParsesTheScreenshotSize(string value, int expectedWidth, int expectedHeight) + { + Assert.True(CommandLineManager.TryParseScreenshotSize(value, out var width, out var height)); + Assert.Equal(expectedWidth, width); + Assert.Equal(expectedHeight, height); + } + + [Theory] + [InlineData("")] + [InlineData("1280")] + [InlineData("1280x")] + [InlineData("x800")] + [InlineData("1280x800x600")] + [InlineData("abcxdef")] + [InlineData("799x600")] + [InlineData("800x599")] + [InlineData("-1280x800")] + [InlineData("7681x800")] + public void RejectsAnInvalidScreenshotSize(string value) + { + Assert.False(CommandLineManager.TryParseScreenshotSize(value, out _, out _)); + } +} diff --git a/Source/NETworkManager/MainWindow.xaml.cs b/Source/NETworkManager/MainWindow.xaml.cs index be5c4b8928..9af828e8a3 100644 --- a/Source/NETworkManager/MainWindow.xaml.cs +++ b/Source/NETworkManager/MainWindow.xaml.cs @@ -406,6 +406,9 @@ public MainWindow() InitializeComponent(); DataContext = this; + if (CommandLineManager.Current.Screenshot) + ConfigureScreenshotMode(); + // Language metadata LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata( @@ -433,6 +436,27 @@ public MainWindow() _isLoading = false; } + /// + /// Screenshot mode (--screenshot): fixed window size (device-independent pixels, e.g. 1280 x 800 is + /// 1920 x 1200 pixels with 150 % display scaling), centered on the screen, not resizable and not maximizable. + /// The saved window position is neither loaded nor overwritten. The window always shows the glow of an active + /// window, so a screenshot tool that takes the focus doesn't change the look. + /// + private void ConfigureScreenshotMode() + { + SaveWindowPosition = false; + WindowStartupLocation = WindowStartupLocation.CenterScreen; + WindowState = WindowState.Normal; + + Width = MinWidth = MaxWidth = CommandLineManager.Current.ScreenshotWidth; + Height = MinHeight = MaxHeight = CommandLineManager.Current.ScreenshotHeight; + + SetResourceReference(BackgroundProperty, AppearanceManager.SurfaceWindowBrushKey); + SetResourceReference(NonActiveWindowTitleBrushProperty, AppearanceManager.SurfaceWindowBrushKey); + + Log.Info($"Screenshot mode: {Width} x {Height}"); + } + private void MetroMainWindow_ContentRendered(object sender, EventArgs e) { WelcomeThenLoadAsync(); @@ -1548,6 +1572,13 @@ private void NotifyIcon_Click(object sender, EventArgs e) private void MetroWindowMain_StateChanged(object sender, EventArgs e) { + // Keep the fixed size in screenshot mode (e.g. double-click on the title bar) + if (CommandLineManager.Current.Screenshot && WindowState == WindowState.Maximized) + { + WindowState = WindowState.Normal; + return; + } + if (WindowState != WindowState.Minimized) return; @@ -1659,12 +1690,24 @@ private void CloseApplication() public void RestartApplication(bool asAdmin = false) { ExternalProcessStarter.RunProcess(ConfigurationManager.Current.ApplicationFullName, - $"{CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterRestartPid)}{Environment.ProcessId} {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterApplication)}{SelectedApplication.Name}", + $"{CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterRestartPid)}{Environment.ProcessId} {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterApplication)}{SelectedApplication.Name}{GetScreenshotParameter()}", asAdmin); CloseApplication(); } + /// + /// Keeps the screenshot mode after a restart (e.g. language changed, restart as administrator). + /// + private static string GetScreenshotParameter() + { + if (!CommandLineManager.Current.Screenshot) + return string.Empty; + + return + $" {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterScreenshot)}{CommandLineManager.Current.ScreenshotWidth}x{CommandLineManager.Current.ScreenshotHeight}"; + } + public ICommand ApplicationListMouseEnterCommand => new RelayCommand(_ => ApplicationListMouseEnterAction()); private void ApplicationListMouseEnterAction() diff --git a/Website/docs/changelog/next-release.md b/Website/docs/changelog/next-release.md index 190c9e4325..5584a7c4d0 100644 --- a/Website/docs/changelog/next-release.md +++ b/Website/docs/changelog/next-release.md @@ -39,6 +39,7 @@ Release date: **xx.xx.2026** - A dragged-out tab (e.g. **Remote Desktop**, **PuTTY**) can be dropped anywhere on the tab bar of another window of the same tool, not only over the existing tabs. While dragging, a highlighted slot shows where it can be dropped. [#3702](https://github.com/BornToBeRoot/NETworkManager/pull/3702) - New setting **Accent glow** in [Settings > Appearance](../settings/appearance.md#accent-glow): a subtle glow of the accent color in the top left corner of the windows (`Off`, `Subtle`, `Medium` (default), `Strong`). [#3702](https://github.com/BornToBeRoot/NETworkManager/pull/3702) - New themes **Black**, **Midnight**, **Steel**, **Indigo**, **Mist**, **Soft** and **Paper** and new accent colors **Sky**, **Ocean**, **Mint**, **Rose**, **Coral**, **Gold**, **Lavender**, **Slate** and **Graphite** in [Settings > Appearance](../settings/appearance.md#theme). All accents work with every theme. [#3702](https://github.com/BornToBeRoot/NETworkManager/pull/3702) +- New [command line argument](../commandline-arguments.md#--screenshot) `--screenshot` to start the application with a fixed window size (default `1280x800`, centered, not resizable) for consistent screenshots, e.g. `NETworkManager.exe --screenshot:1200x800`. - ARM64 builds are now available. [#3538](https://github.com/BornToBeRoot/NETworkManager/issues/3538) **Run command** diff --git a/Website/docs/commandline-arguments.md b/Website/docs/commandline-arguments.md index fb9d4a400c..09761bb651 100644 --- a/Website/docs/commandline-arguments.md +++ b/Website/docs/commandline-arguments.md @@ -73,6 +73,31 @@ Start a specific application on startup. NETworkManager.exe --application:PingMonitor ``` +### `--screenshot` + +Starts the application in screenshot mode to take consistent screenshots, e.g. for the documentation: + +- The window has a fixed size (default `1280x800`) and is centered on the primary screen. It can't be resized or maximized. +- The size is in device-independent pixels and is scaled with the Windows display scaling. For example, `1280x800` is `1920x1200` pixels with `150 %` scaling, which looks sharp on high-resolution screens. +- The saved window position and size are not loaded and not overwritten. +- The window always looks like an active window (accent glow), even if the screenshot tool takes the focus. + +Optionally, the size can be set with `--screenshot:WIDTHxHEIGHT` (minimum `800x600`). + +**Example:** + +```powershell +NETworkManager.exe --screenshot +NETworkManager.exe --screenshot:1200x800 +NETworkManager.exe --screenshot --application:IPScanner +``` + +:::note + +If NETworkManager is already running (and multiple instances are not allowed), the running instance is shown instead. Close it first. + +::: + ## Internal Internally used command line arguments.