diff --git a/src/Localization/Locals.Designer.cs b/src/Localization/Locals.Designer.cs
index 81a5e18..aa7504c 100644
--- a/src/Localization/Locals.Designer.cs
+++ b/src/Localization/Locals.Designer.cs
@@ -1246,7 +1246,25 @@ internal static string MinimizeToTrayIconToolTip {
return ResourceManager.GetString("MinimizeToTrayIconToolTip", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Запускать в полноэкранном режиме:.
+ ///
+ internal static string StartMaximized {
+ get {
+ return ResourceManager.GetString("StartMaximized", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Если выключено, приложение запускается в обычном окне, а не развёрнутым на весь экран.
+ ///
+ internal static string StartMaximizedToolTip {
+ get {
+ return ResourceManager.GetString("StartMaximizedToolTip", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Название.
///
diff --git a/src/Localization/Locals.en.resx b/src/Localization/Locals.en.resx
index fedd51e..ba2f174 100644
--- a/src/Localization/Locals.en.resx
+++ b/src/Localization/Locals.en.resx
@@ -261,6 +261,12 @@
Show a tray icon when Log Viewer is minimized.
+
+ Start in fullscreen mode:
+
+
+ When off, the application starts in a normal window instead of maximized.
+
Only one application instance:
diff --git a/src/Localization/Locals.resx b/src/Localization/Locals.resx
index c1bb89e..8cc80f0 100644
--- a/src/Localization/Locals.resx
+++ b/src/Localization/Locals.resx
@@ -346,6 +346,12 @@
Показывать иконку в трее при сворачивании приложения
+
+ Запускать в полноэкранном режиме:
+
+
+ Если выключено, приложение запускается в обычном окне, а не развёрнутым на весь экран
+
Не добавлено ни одного сетевого приёмника.
Добавьте хотя бы один сетевой приёмник в настройках.
diff --git a/src/MVVM/Models/Settings.cs b/src/MVVM/Models/Settings.cs
index 739ef1c..8ffe803 100644
--- a/src/MVVM/Models/Settings.cs
+++ b/src/MVVM/Models/Settings.cs
@@ -28,6 +28,12 @@ public sealed class Settings : ISerializable
public bool AutoStartInStartup { get; set; } = false;
public bool MinimizeToTray { get; set; } = false;
+
+ ///
+ /// Start the main window maximized. Missing value in old settings.xml keeps the default (true),
+ /// matching the behavior before this setting existed.
+ ///
+ public bool StartMaximized { get; set; } = true;
public bool OnlyOneAppInstance { get; set; } = false;
public bool IsEnabledMaxMessageBufferSize { get; set; } = false;
public int MaxMessageBufferSize { get; set; } = 1000000;
@@ -193,6 +199,7 @@ public void Load()
{
Instance.AutoStartInStartup = settings.AutoStartInStartup;
Instance.MinimizeToTray = settings.MinimizeToTray;
+ Instance.StartMaximized = settings.StartMaximized;
Instance.CurrentTheme = settings.CurrentTheme;
Instance.DataFormat = settings.DataFormat;
Instance.IgnoredIPs = settings.IgnoredIPs;
diff --git a/src/MVVM/ViewModels/SettingsViewModel.cs b/src/MVVM/ViewModels/SettingsViewModel.cs
index 0f18626..2097a95 100644
--- a/src/MVVM/ViewModels/SettingsViewModel.cs
+++ b/src/MVVM/ViewModels/SettingsViewModel.cs
@@ -26,6 +26,7 @@ public class SettingsViewModel : BaseViewModel
private bool isConfigurationVisible = false;
private bool isAutoStartReadAtStartup = true;
private bool minimizeToTray = false;
+ private bool startMaximized = true;
private bool isEnableMaxMessageBufferSize = false;
private bool onlyOneAppInstance = true;
private Receiver selectedReceiver;
@@ -107,6 +108,19 @@ public bool MinimizeToTray
}
+ ///
+ /// Start the main window maximized.
+ ///
+ public bool StartMaximized
+ {
+ get => startMaximized;
+ set
+ {
+ startMaximized = value;
+ OnPropertyChanged();
+ }
+ }
+
///
/// Honor the maximum message buffer size.
///
@@ -566,6 +580,7 @@ public SettingsViewModel()
IgnoredIpAdresses = new ObservableCollection(Settings.Instance.IgnoredIPs);
IsAutoStartReadAtStartup = Settings.Instance.AutoStartInStartup;
MinimizeToTray = Settings.Instance.MinimizeToTray;
+ StartMaximized = Settings.Instance.StartMaximized;
OnlyOneAppInstance = Settings.Instance.OnlyOneAppInstance;
CheckForUpdatesOnStartup = Settings.Instance.CheckForUpdatesOnStartup;
SelectedDataFormat = Settings.Instance.DataFormat;
@@ -701,6 +716,7 @@ private void Save(object obj)
Settings.Instance.MinimizeToTray = MinimizeToTray;
Settings.Instance.AutoStartInStartup = IsAutoStartReadAtStartup;
+ Settings.Instance.StartMaximized = StartMaximized;
Settings.Instance.IsShowSourceColumn = IsShowSourceColumn;
Settings.Instance.IsShowThreadColumn = IsShowThreadColumn;
Settings.Instance.IsShowTaskbarProgress = IsShowTaskbarProgress;
diff --git a/src/MVVM/Views/MainWindow.xaml b/src/MVVM/Views/MainWindow.xaml
index ae074f5..f8592fc 100644
--- a/src/MVVM/Views/MainWindow.xaml
+++ b/src/MVVM/Views/MainWindow.xaml
@@ -10,7 +10,7 @@
xmlns:viewModels="clr-namespace:LogViewer.MVVM.ViewModels"
xmlns:localization="clr-namespace:LogViewer.Localization"
mc:Ignorable="d"
- Title="Log Viewer" Height="1080" Width="1920" WindowState="Maximized" Loaded="MainWindow_OnLoaded"
+ Title="Log Viewer" Height="1080" Width="1920" WindowStartupLocation="CenterScreen" Loaded="MainWindow_OnLoaded"
AllowDrop="True" DragOver="Window_OnDragOver" Drop="Window_OnDrop">
diff --git a/src/MVVM/Views/MainWindow.xaml.cs b/src/MVVM/Views/MainWindow.xaml.cs
index ad2e029..3168fe8 100644
--- a/src/MVVM/Views/MainWindow.xaml.cs
+++ b/src/MVVM/Views/MainWindow.xaml.cs
@@ -49,6 +49,12 @@ public partial class MainWindow : Window, IDisposable
public MainWindow()
{
InitializeComponent();
+ if (!Settings.Instance.StartMaximized)
+ {
+ WindowStartupLocation = WindowStartupLocation.Manual;
+ CenterNormalWindow(Screen.FromPoint(System.Windows.Forms.Cursor.Position));
+ }
+ WindowState = Settings.Instance.StartMaximized ? WindowState.Maximized : WindowState.Normal;
UpdateAutoScrollChrome();
logsViewKeeper = new ListViewViewKeeper(LogsListView, () => AutoScrollEnabled);
TranslationSource.Instance.LanguageChanged += (_, __) => UpdateAutoScrollChrome();
@@ -99,6 +105,9 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
///
protected override void OnStateChanged(EventArgs e)
{
+ if (WindowState == WindowState.Normal && IsLoaded)
+ CenterNormalWindow();
+
if (WindowState == WindowState.Minimized && Settings.Instance.MinimizeToTray)
{
if (trayIcon == null)
@@ -128,6 +137,34 @@ protected override void OnStateChanged(EventArgs e)
base.OnStateChanged(e);
}
+ private void CenterNormalWindow(Screen screen = null)
+ {
+ var workArea = GetWorkArea(screen ?? Screen.FromHandle(new WindowInteropHelper(this).Handle));
+
+ Width = Math.Min(Width, workArea.Width);
+ Height = Math.Min(Height, workArea.Height);
+ Left = workArea.Left + (workArea.Width - Width) / 2;
+ Top = workArea.Top + (workArea.Height - Height) / 2;
+ }
+
+ private Rect GetWorkArea(Screen screen)
+ {
+ var source = PresentationSource.FromVisual(this);
+ // Screen coordinates are physical pixels; WPF window bounds use device-independent units.
+ var transform = source?.CompositionTarget?.TransformFromDevice;
+ if (!transform.HasValue)
+ {
+ // Before HWND creation, use the system DPI used by this WPF application.
+ using (var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
+ transform = new System.Windows.Media.Matrix(96.0 / graphics.DpiX, 0, 0, 96.0 / graphics.DpiY, 0, 0);
+ }
+
+ var workArea = screen.WorkingArea;
+ var topLeft = transform.Value.Transform(new Point(workArea.Left, workArea.Top));
+ var bottomRight = transform.Value.Transform(new Point(workArea.Right, workArea.Bottom));
+ return new Rect(topLeft, bottomRight);
+ }
+
private void TrayIconContextMenuClick(object sender, ToolStripItemClickedEventArgs e)
{
switch (e.ClickedItem.Text)
@@ -555,4 +592,4 @@ public void Dispose()
trayIcon?.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/MVVM/Views/SettingsWindow.xaml b/src/MVVM/Views/SettingsWindow.xaml
index f455292..186ee61 100644
--- a/src/MVVM/Views/SettingsWindow.xaml
+++ b/src/MVVM/Views/SettingsWindow.xaml
@@ -10,7 +10,7 @@
xmlns:dropDownCustomColorPicker="clr-namespace:DropDownCustomColorPicker;assembly=CustomColorPicker"
xmlns:localization="clr-namespace:LogViewer.Localization"
mc:Ignorable="d"
- Title="{localization:LocBinding Settings}" Height="770" Width="760" MinWidth="720" MinHeight="610">
+ Title="{localization:LocBinding Settings}" Height="790" Width="760" MinWidth="720" MinHeight="610">
@@ -40,104 +40,110 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
+