Skip to content

Commit a09aa61

Browse files
authored
Feature: Screenshot mode (#3711)
1 parent b420427 commit a09aa61

7 files changed

Lines changed: 187 additions & 3 deletions

File tree

‎Source/GlobalAssemblyInfo.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[assembly: AssemblyTrademark("")]
77
[assembly: AssemblyCulture("")]
88

9-
[assembly: AssemblyVersion("2026.11.11.0")]
10-
[assembly: AssemblyFileVersion("2026.11.11.0")]
9+
[assembly: AssemblyVersion("2026.11.14.0")]
10+
[assembly: AssemblyFileVersion("2026.11.14.0")]

‎Source/NETworkManager.Settings/CommandLineInfo.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public class CommandLineInfo
3232
/// </summary>
3333
public ApplicationName Application { get; set; } = ApplicationName.None;
3434

35+
/// <summary>
36+
/// Indicates if the application should start in screenshot mode (fixed window size, centered, not resizable,
37+
/// window position not loaded or saved) to take consistent screenshots for the documentation
38+
/// </summary>
39+
public bool Screenshot { get; set; }
40+
41+
/// <summary>
42+
/// Width of the window in screenshot mode (device-independent pixels, scaled with the Windows display scaling)
43+
/// </summary>
44+
public int ScreenshotWidth { get; set; } = CommandLineManager.ScreenshotDefaultWidth;
45+
46+
/// <summary>
47+
/// Height of the window in screenshot mode (device-independent pixels, scaled with the Windows display scaling)
48+
/// </summary>
49+
public int ScreenshotHeight { get; set; } = CommandLineManager.ScreenshotDefaultHeight;
50+
3551
/// <summary>
3652
/// Wrong parameter(s) detected in the command line to display in the help dialog
3753
/// </summary>

‎Source/NETworkManager.Settings/CommandLineManager.cs‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ static CommandLineManager()
5656
WrongParameterDetected(parameters);
5757
return;
5858
}
59+
} // Screenshot mode (optional size, e.g. --screenshot:1280x800)
60+
else if (param[0].Equals(ParameterScreenshot, StringComparison.InvariantCultureIgnoreCase))
61+
{
62+
Current.Screenshot = true;
63+
64+
if (param.Length > 1)
65+
{
66+
if (TryParseScreenshotSize(param[1], out var width, out var height))
67+
{
68+
Current.ScreenshotWidth = width;
69+
Current.ScreenshotHeight = height;
70+
}
71+
else
72+
{
73+
WrongParameterDetected(parameters);
74+
return;
75+
}
76+
}
5977
}
6078
else
6179
{
@@ -84,13 +102,60 @@ static CommandLineManager()
84102
public static string ParameterAutostart => $"{ParameterIdentifier}autostart";
85103
public static string ParameterRestartPid => $"{ParameterIdentifier}restart-pid";
86104

105+
// Documentation (screenshots)
106+
public static string ParameterScreenshot => $"{ParameterIdentifier}screenshot";
107+
108+
/// <summary>
109+
/// Default window width in screenshot mode (16:10, readable when scaled to the width of the documentation).
110+
/// </summary>
111+
public const int ScreenshotDefaultWidth = 1280;
112+
113+
/// <summary>
114+
/// Default window height in screenshot mode.
115+
/// </summary>
116+
public const int ScreenshotDefaultHeight = 800;
117+
118+
// Minimum size of the main window (MinWidth / MinHeight in MainWindow.xaml)
119+
private const int ScreenshotMinWidth = 800;
120+
private const int ScreenshotMinHeight = 600;
121+
private const int ScreenshotMaxSize = 7680;
122+
87123
public static CommandLineInfo Current { get; set; }
88124

89125
public static string GetParameterWithSplitIdentifier(string parameter)
90126
{
91127
return $"{parameter}{ValueSplitIdentifier}";
92128
}
93129

130+
/// <summary>
131+
/// Parses the window size of the screenshot mode (<c>WIDTHxHEIGHT</c>, e.g. <c>1280x800</c>).
132+
/// </summary>
133+
/// <param name="value">Size to parse.</param>
134+
/// <param name="width">Parsed width.</param>
135+
/// <param name="height">Parsed height.</param>
136+
/// <returns><c>true</c> if the size is valid and not smaller than the minimum size of the main window.</returns>
137+
public static bool TryParseScreenshotSize(string value, out int width, out int height)
138+
{
139+
width = 0;
140+
height = 0;
141+
142+
var size = value.Split('x', 'X');
143+
144+
if (size.Length != 2 ||
145+
!int.TryParse(size[0], out var parsedWidth) ||
146+
!int.TryParse(size[1], out var parsedHeight))
147+
return false;
148+
149+
if (parsedWidth is < ScreenshotMinWidth or > ScreenshotMaxSize ||
150+
parsedHeight is < ScreenshotMinHeight or > ScreenshotMaxSize)
151+
return false;
152+
153+
width = parsedWidth;
154+
height = parsedHeight;
155+
156+
return true;
157+
}
158+
94159
private static void WrongParameterDetected(string[] parameters)
95160
{
96161
Current.WrongParameter = string.Join(" ", parameters);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using NETworkManager.Settings;
2+
using Xunit;
3+
4+
namespace NETworkManager.Tests.Settings;
5+
6+
public class CommandLineManagerTests
7+
{
8+
[Theory]
9+
[InlineData("1280x800", 1280, 800)]
10+
[InlineData("1200X800", 1200, 800)]
11+
[InlineData("800x600", 800, 600)]
12+
public void ParsesTheScreenshotSize(string value, int expectedWidth, int expectedHeight)
13+
{
14+
Assert.True(CommandLineManager.TryParseScreenshotSize(value, out var width, out var height));
15+
Assert.Equal(expectedWidth, width);
16+
Assert.Equal(expectedHeight, height);
17+
}
18+
19+
[Theory]
20+
[InlineData("")]
21+
[InlineData("1280")]
22+
[InlineData("1280x")]
23+
[InlineData("x800")]
24+
[InlineData("1280x800x600")]
25+
[InlineData("abcxdef")]
26+
[InlineData("799x600")]
27+
[InlineData("800x599")]
28+
[InlineData("-1280x800")]
29+
[InlineData("7681x800")]
30+
public void RejectsAnInvalidScreenshotSize(string value)
31+
{
32+
Assert.False(CommandLineManager.TryParseScreenshotSize(value, out _, out _));
33+
}
34+
}

‎Source/NETworkManager/MainWindow.xaml.cs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ public MainWindow()
406406
InitializeComponent();
407407
DataContext = this;
408408

409+
if (CommandLineManager.Current.Screenshot)
410+
ConfigureScreenshotMode();
411+
409412
// Language metadata
410413
LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
411414
new FrameworkPropertyMetadata(
@@ -433,6 +436,27 @@ public MainWindow()
433436
_isLoading = false;
434437
}
435438

439+
/// <summary>
440+
/// Screenshot mode (<c>--screenshot</c>): fixed window size (device-independent pixels, e.g. 1280 x 800 is
441+
/// 1920 x 1200 pixels with 150 % display scaling), centered on the screen, not resizable and not maximizable.
442+
/// The saved window position is neither loaded nor overwritten. The window always shows the glow of an active
443+
/// window, so a screenshot tool that takes the focus doesn't change the look.
444+
/// </summary>
445+
private void ConfigureScreenshotMode()
446+
{
447+
SaveWindowPosition = false;
448+
WindowStartupLocation = WindowStartupLocation.CenterScreen;
449+
WindowState = WindowState.Normal;
450+
451+
Width = MinWidth = MaxWidth = CommandLineManager.Current.ScreenshotWidth;
452+
Height = MinHeight = MaxHeight = CommandLineManager.Current.ScreenshotHeight;
453+
454+
SetResourceReference(BackgroundProperty, AppearanceManager.SurfaceWindowBrushKey);
455+
SetResourceReference(NonActiveWindowTitleBrushProperty, AppearanceManager.SurfaceWindowBrushKey);
456+
457+
Log.Info($"Screenshot mode: {Width} x {Height}");
458+
}
459+
436460
private void MetroMainWindow_ContentRendered(object sender, EventArgs e)
437461
{
438462
WelcomeThenLoadAsync();
@@ -1548,6 +1572,13 @@ private void NotifyIcon_Click(object sender, EventArgs e)
15481572

15491573
private void MetroWindowMain_StateChanged(object sender, EventArgs e)
15501574
{
1575+
// Keep the fixed size in screenshot mode (e.g. double-click on the title bar)
1576+
if (CommandLineManager.Current.Screenshot && WindowState == WindowState.Maximized)
1577+
{
1578+
WindowState = WindowState.Normal;
1579+
return;
1580+
}
1581+
15511582
if (WindowState != WindowState.Minimized)
15521583
return;
15531584

@@ -1659,12 +1690,24 @@ private void CloseApplication()
16591690
public void RestartApplication(bool asAdmin = false)
16601691
{
16611692
ExternalProcessStarter.RunProcess(ConfigurationManager.Current.ApplicationFullName,
1662-
$"{CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterRestartPid)}{Environment.ProcessId} {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterApplication)}{SelectedApplication.Name}",
1693+
$"{CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterRestartPid)}{Environment.ProcessId} {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterApplication)}{SelectedApplication.Name}{GetScreenshotParameter()}",
16631694
asAdmin);
16641695

16651696
CloseApplication();
16661697
}
16671698

1699+
/// <summary>
1700+
/// Keeps the screenshot mode after a restart (e.g. language changed, restart as administrator).
1701+
/// </summary>
1702+
private static string GetScreenshotParameter()
1703+
{
1704+
if (!CommandLineManager.Current.Screenshot)
1705+
return string.Empty;
1706+
1707+
return
1708+
$" {CommandLineManager.GetParameterWithSplitIdentifier(CommandLineManager.ParameterScreenshot)}{CommandLineManager.Current.ScreenshotWidth}x{CommandLineManager.Current.ScreenshotHeight}";
1709+
}
1710+
16681711
public ICommand ApplicationListMouseEnterCommand => new RelayCommand(_ => ApplicationListMouseEnterAction());
16691712

16701713
private void ApplicationListMouseEnterAction()

‎Website/docs/changelog/next-release.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Release date: **xx.xx.2026**
3939
- 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)
4040
- 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)
4141
- 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)
42+
- 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`.
4243
- ARM64 builds are now available. [#3538](https://github.com/BornToBeRoot/NETworkManager/issues/3538)
4344

4445
**Run command**

‎Website/docs/commandline-arguments.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ Start a specific application on startup.
7373
NETworkManager.exe --application:PingMonitor
7474
```
7575

76+
### `--screenshot`
77+
78+
Starts the application in screenshot mode to take consistent screenshots, e.g. for the documentation:
79+
80+
- The window has a fixed size (default `1280x800`) and is centered on the primary screen. It can't be resized or maximized.
81+
- 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.
82+
- The saved window position and size are not loaded and not overwritten.
83+
- The window always looks like an active window (accent glow), even if the screenshot tool takes the focus.
84+
85+
Optionally, the size can be set with `--screenshot:WIDTHxHEIGHT` (minimum `800x600`).
86+
87+
**Example:**
88+
89+
```powershell
90+
NETworkManager.exe --screenshot
91+
NETworkManager.exe --screenshot:1200x800
92+
NETworkManager.exe --screenshot --application:IPScanner
93+
```
94+
95+
:::note
96+
97+
If NETworkManager is already running (and multiple instances are not allowed), the running instance is shown instead. Close it first.
98+
99+
:::
100+
76101
## Internal
77102

78103
Internally used command line arguments.

0 commit comments

Comments
 (0)