fix geometry

This commit is contained in:
stax76
2024-01-06 12:03:28 +01:00
parent ad94042a2c
commit 85e4e3f9df
4 changed files with 20 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
# v7.0.0.7 Beta (2023-??-??) # v7.0.0.7 Beta (2023-??-??)
- Fix geometry not working when used from mpv.conf and the conf editor.
- GitHub Auto/Action/Workflow builds use a newer libmpv build. - GitHub Auto/Action/Workflow builds use a newer libmpv build.
- German and Chinese translation updated. Thanks to our translation team! - German and Chinese translation updated. Thanks to our translation team!
- New PowerShell script Tools/update-mpv-and-libmpv.ps1 to update mpv and libmpv. - New PowerShell script Tools/update-mpv-and-libmpv.ps1 to update mpv and libmpv.

View File

@@ -675,6 +675,8 @@ https://mpv.io/manual/master/#window
Initial window location in percent. Default: 50:50 (centered) Initial window location in percent. Default: 50:50 (centered)
Requires Windows 11, on Windows 10 it works slightly incorrect due to invisible borders.
x=0 docks the window to the left side. x=0 docks the window to the left side.
x=100 docks the window to the right side. x=100 docks the window to the right side.

View File

@@ -971,9 +971,9 @@ directory = Window
help = <int> Initial window height in percent for audio files. Default: 70 help = <int> Initial window height in percent for audio files. Default: 70
name = geometry name = geometry
file = mpvnet file = mpv
directory = Window directory = Window
help = <x:y> Initial window location in percent. Default: 50:50 (centered)\n\nx=0 docks the window to the left side.\nx=100 docks the window to the right side.\ny=0 docks the window to the top side.\ny=100 docks the window to the bottom side. help = <x:y> Initial window location in percent. Default: 50:50 (centered)\n\nRequires Windows 11, on Windows 10 it works slightly incorrect due to invisible borders.\n\nx=0 docks the window to the left side.\nx=100 docks the window to the right side.\n\ny=0 docks the window to the top side.\ny=100 docks the window to the bottom side.
name = start-size name = start-size
file = mpvnet file = mpvnet

View File

@@ -688,18 +688,20 @@ public partial class MainForm : Form
int minTop = screens.Select(val => GetWorkingArea(Handle, val.WorkingArea).Y).Min(); int minTop = screens.Select(val => GetWorkingArea(Handle, val.WorkingArea).Y).Min();
int maxBottom = screens.Select(val => GetWorkingArea(Handle, val.WorkingArea).Bottom).Max(); int maxBottom = screens.Select(val => GetWorkingArea(Handle, val.WorkingArea).Bottom).Max();
if (load && CommandLine.Contains("geometry")) if (load)
{ {
string geometryString = CommandLine.GetValue("geometry"); string geometryString = Player.GetPropertyString("geometry");
var geometry = ParseGeometry(geometryString, GetWorkingArea( if (!string.IsNullOrEmpty(geometryString))
Handle, Screen.FromHandle(Handle).WorkingArea), width, height); {
var pos = ParseGeometry(geometryString, width, height);
if (geometry.x != int.MaxValue) if (pos.X != int.MaxValue)
left = geometry.x; left = pos.X;
if (geometry.y != int.MaxValue) if (pos.Y != int.MaxValue)
top = geometry.y; top = pos.Y;
}
} }
if (left < minLeft) if (left < minLeft)
@@ -718,15 +720,17 @@ public partial class MainForm : Form
SetWindowPos(Handle, IntPtr.Zero, left, top, width, height, SWP_NOACTIVATE); SetWindowPos(Handle, IntPtr.Zero, left, top, width, height, SWP_NOACTIVATE);
} }
(int x, int y) ParseGeometry(string input, Rectangle workingArea, int width, int height) Point ParseGeometry(string input, int width, int height)
{ {
int x = int.MaxValue; int x = int.MaxValue;
int y = int.MaxValue; int y = int.MaxValue;
Match match = Regex.Match(input, @"^(\d+)%?:(\d+)%?$"); Match match = Regex.Match(input, @"^\+(\d+)%?\+(\d+)%?$");
if (match.Success) if (match.Success)
{ {
Rectangle workingArea = GetWorkingArea(Handle, Screen.FromHandle(Handle).WorkingArea);
x = int.Parse(match.Groups[1].Value); x = int.Parse(match.Groups[1].Value);
y = int.Parse(match.Groups[2].Value); y = int.Parse(match.Groups[2].Value);
@@ -734,7 +738,7 @@ public partial class MainForm : Form
y = workingArea.Top + Convert.ToInt32((workingArea.Height - height) / 100.0 * y); y = workingArea.Top + Convert.ToInt32((workingArea.Height - height) / 100.0 * y);
} }
return (x, y); return new Point(x, y);
} }
public void CycleFullscreen(bool enabled) public void CycleFullscreen(bool enabled)