This commit is contained in:
Frank Skare
2019-07-12 06:23:53 +02:00
parent e308bbf928
commit e0111b6f12
4 changed files with 44 additions and 5 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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" }]
{ 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" }]

View File

@@ -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");