From e0111b6f125517f4449ec43bd018b47d34bda0ea Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Fri, 12 Jul 2019 06:23:53 +0200 Subject: [PATCH] - --- Changelog.md | 1 + mpv.net/Misc/Misc.cs | 2 ++ mpv.net/Resources/mpvNetConfToml.txt | 10 +++++++- mpv.net/WinForms/MainForm.cs | 36 ++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index 41cf9de..9894589 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ to video the main video starts directly with the native video size, before it was starting with the autofit size first and was only afterwards resized to the native video size +- on exit the window location can be saved with remember-position ### 4.6 diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index a52bc9b..c4d49bf 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -29,6 +29,7 @@ namespace mpvnet public static string[] UrlWhitelist { get; set; } = { "tube", "vimeo", "ard", "zdf" }; public static bool RememberHeight { get; set; } = true; + public static bool RememberPosition { get; set; } public static bool DebugMode { get; set; } = false; public static bool IsDarkMode { @@ -87,6 +88,7 @@ namespace mpvnet { switch (name) { + case "remember-position": RememberPosition = value == "yes"; break; case "start-size": RememberHeight = value == "previous"; break; case "process-instance": ProcessInstance = value; break; case "dark-mode": DarkMode = value; break; diff --git a/mpv.net/Resources/mpvNetConfToml.txt b/mpv.net/Resources/mpvNetConfToml.txt index a22b264..f79cc4c 100644 --- a/mpv.net/Resources/mpvNetConfToml.txt +++ b/mpv.net/Resources/mpvNetConfToml.txt @@ -36,4 +36,12 @@ default = "previous" filter = "Screen" help = "mpv.net specific setting to remember the window height in the current session, otherwise the video's native resolution is used." options = [{ name = "video", help = "Window size is set to native video resolution" }, - { name = "previous", help = "Window size is remembered but only from the current session" }] \ No newline at end of file + { name = "previous", help = "Window size is remembered but only from the current session" }] + +[[settings]] +name = "remember-position" +default = "no" +filter = "Screen" +help = "mpv.net specific setting to save the window position on exit." +options = [{ name = "yes" }, + { name = "no" }] \ No newline at end of file diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 9adf141..bb647c6 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -55,8 +55,17 @@ namespace mpvnet if (targetIndex > screens.Length - 1) targetIndex = screens.Length - 1; Screen screen = screens[Array.IndexOf(screens, screens[targetIndex])]; Rectangle target = screen.Bounds; - Left = target.X + Convert.ToInt32((target.Width - Width) / 2.0); - Top = target.Y + Convert.ToInt32((target.Height - Height) / 2.0); + Left = target.X + (target.Width - Width) / 2; + Top = target.Y + (target.Height - Height) / 2; + + int posX = RegHelp.GetInt(App.RegPath, "PosX"); + int posY = RegHelp.GetInt(App.RegPath, "PosY"); + + if (posX != 0 && posY != 0) + { + Left = posX - Width / 2; + Top = posY - Height / 2; + } mp.Shutdown += Shutdown; mp.VideoSizeChanged += VideoSizeChanged; @@ -244,6 +253,18 @@ namespace mpvnet NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; + + Screen[] screens = Screen.AllScreens; + int minLeft = screens.Select(val => val.WorkingArea.X).Min(); + int maxRight = screens.Select(val => val.WorkingArea.Right).Max(); + int minTop = screens.Select(val => val.WorkingArea.Y).Min(); + int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max(); + + if (left < minLeft) left = minLeft; + if (left + rect.Width > maxRight) left = maxRight - rect.Width; + if (top < minTop) top = minTop; + if (top + rect.Height > maxBottom) top = maxBottom - rect.Height; + Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); } @@ -492,9 +513,16 @@ namespace mpvnet if (mp.IsLogoVisible) mp.ShowLogo(); } - protected override void OnFormClosed(FormClosedEventArgs e) + protected override void OnFormClosing(FormClosingEventArgs e) { - base.OnFormClosed(e); + base.OnFormClosing(e); + + if (WindowState == FormWindowState.Normal) + { + RegHelp.SetObject(App.RegPath, "PosX", Left + Width / 2); + RegHelp.SetObject(App.RegPath, "PosY", Top + Height / 2); + } + RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray()); App.Exit(); mp.commandv("quit");