diff --git a/CSScriptAddon/CSScriptAddon.vb b/CSScriptAddon/CSScriptAddon.vb
index ab52bd7..306c25b 100644
--- a/CSScriptAddon/CSScriptAddon.vb
+++ b/CSScriptAddon/CSScriptAddon.vb
@@ -1,5 +1,6 @@
Imports System.ComponentModel.Composition
Imports System.IO
+Imports System.Windows.Forms
Imports mpvnet
Imports mpvnet.StaticUsing
@@ -13,7 +14,8 @@ Public Class CSScriptAddon
Sub New()
Dim scriptDir = mp.mpvConfFolderPath + "scripts"
If Not Directory.Exists(scriptDir) Then Return
- Dim csFiles = Directory.GetFiles(scriptDir, "*.cs")
+ Dim csFiles = Directory.GetFiles(scriptDir, "*.cs").ToList
+ csFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\Scripts", "*.cs"))
If csFiles.Count = 0 Then Return
CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom
diff --git a/CSScriptAddon/CSScriptAddon.vbproj b/CSScriptAddon/CSScriptAddon.vbproj
index f418ddb..3aaf90f 100644
--- a/CSScriptAddon/CSScriptAddon.vbproj
+++ b/CSScriptAddon/CSScriptAddon.vbproj
@@ -55,6 +55,7 @@
+
diff --git a/README.md b/README.md
index cc53245..bd77340 100644
--- a/README.md
+++ b/README.md
@@ -19,22 +19,32 @@ mpv manual: https://mpv.io/manual/master/
The context menu can be customized via input.conf file located at:
-C:\Users\Frank\AppData\Roaming\mpv\input.conf
+C:\Users\username\AppData\Roaming\mpv\input.conf
if it's missing mpv.net generates it with the following defaults:
-
+```
https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
+```
+### Settings
+mpv.net shares the settings with mpv, settings have to be edited in a config file called mpv.conf located at:
+```
+C:\Users\username\AppData\Roaming\mpv\mpv.conf
+```
+if it's missing mpv.net generates it with the following defaults:
+```
+https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpv.conf.txt
+```
### C# Scripting
A simple C# script located at:
-
-C:\Users\Frank\AppData\Roaming\mpv\scripts\test.cs
-
+```
+C:\Users\username\AppData\Roaming\mpv\scripts\test.cs
+```
or
-
+```
startup\scripts\test.cs
-
+```
```
using mpvnet;
@@ -42,14 +52,14 @@ class Script
{
public Script()
{
- var fs = mpv.GetStringProp("fullscreen");
- mpv.Command("show-text", "fullscreen: " + fs);
- mpv.ObserveBoolProp("fullscreen", FullscreenChange);
+ var fs = mp.get_property_string("fullscreen");
+ mp.commandv("show-text", "fullscreen: " + fs);
+ mp.observe_property_bool("fullscreen", FullscreenChange);
}
void FullscreenChange(bool val)
{
- mpv.Command("show-text", "fullscreen: " + val.ToString());
+ mp.commandv("show-text", "fullscreen: " + val.ToString());
}
}
```
@@ -57,13 +67,13 @@ class Script
### Python Scripting
A simple Python script located at:
-
+```
C:\Users\user\AppData\Roaming\mpv\scripts
-
+```
or
-
+```
startup\scripts
-
+```
```
# when seeking displays position and
# duration like so: 70:00 / 80:00
@@ -96,14 +106,14 @@ mp.register_event("seek", seek) # or use: mp.Seek += seek
### PowerShell Scripting
A simple PowerShell script located at:
-
+```
C:\Users\user\AppData\Roaming\mpv\scripts
-
+```
or
-
+```
startup\scripts
-
-Please note that PowerShell don't allow assigning to events and mpv.net uses as workaround the script filename.
+```
+Please note that PowerShell don't allow assigning to events and mpv.net uses as workaround a matching script filename.
```
$position = [mp]::get_property_number("time-pos");
@@ -114,6 +124,12 @@ $position = [mp]::get_property_number("time-pos");
### not yet released
+### 1.6
+
+- a crash caused by WM_APPCOMMAND (multimedia keyboards) commands was fixed
+- support for the 'screen' property was added, it should work both from mpv.conf (screen = 1) and from command line (--screen=1)
+- per monitor DPI awareness and better multi monitor support was added
+
### 1.5
- the info command supports now info for music files instead of showing an exception on music files
diff --git a/mpv.net/MainForm.Designer.cs b/mpv.net/MainForm.Designer.cs
index 3133685..9df65ec 100644
--- a/mpv.net/MainForm.Designer.cs
+++ b/mpv.net/MainForm.Designer.cs
@@ -42,7 +42,8 @@
// MainForm
//
this.AllowDrop = true;
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
+ this.AutoScaleDimensions = new System.Drawing.SizeF(288F, 288F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(1012, 615);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs
index bf77109..2c908b5 100644
--- a/mpv.net/MainForm.cs
+++ b/mpv.net/MainForm.cs
@@ -6,6 +6,8 @@ using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using static mpvnet.StaticUsing;
+using System.Linq;
+using System.Collections.Generic;
namespace mpvnet
{
@@ -16,6 +18,7 @@ namespace mpvnet
private Point LastCursorPosChanged;
private int LastCursorChangedTickCount;
+ private bool IgnoreDpiChanged = true;
public ContextMenuStripEx CMS;
@@ -26,15 +29,86 @@ namespace mpvnet
try
{
Application.ThreadException += Application_ThreadException;
- SetFormPositionAndSize();
Instance = this;
Hwnd = Handle;
Text += " " + Application.ProductVersion;
- ChangeFullscreen((mp.mpvConv.ContainsKey("fullscreen") && mp.mpvConv["fullscreen"] == "yes") || (mp.mpvConv.ContainsKey("fs") && mp.mpvConv["fs"] == "yes"));
+
+ if (mp.mpvConf.ContainsKey("screen"))
+ SetScreen(Convert.ToInt32(mp.mpvConf["screen"]));
+ else
+ SetScreen(Screen.PrimaryScreen);
+
+ ChangeFullscreen((mp.mpvConf.ContainsKey("fullscreen") && mp.mpvConf["fullscreen"] == "yes") ||
+ (mp.mpvConf.ContainsKey("fs") && mp.mpvConf["fs"] == "yes"));
+
+ ProcessCommandLineEarly();
}
- catch (Exception ex)
+ catch (Exception e)
{
- HandleException(ex);
+ MsgError(e.ToString());
+ }
+ }
+
+ protected void SetScreen(int targetIndex)
+ {
+ Screen[] screens = Screen.AllScreens;
+ if (targetIndex < 0 || targetIndex > screens.Length - 1) return;
+ SetScreen(screens[Array.IndexOf(screens, screens[targetIndex])]);
+ }
+
+ protected void SetScreen(Screen screen)
+ {
+ Rectangle target = screen.Bounds;
+ Left = target.X + Convert.ToInt32((target.Width - Width) / 2.0);
+ Top = target.Y + Convert.ToInt32((target.Height - Height) / 2.0);
+ SetFormPositionAndSize();
+ }
+
+ void SetFormPositionAndSize()
+ {
+ if (IsFullscreen || mp.VideoSize.Width == 0) return;
+ Screen screen = Screen.FromControl(this);
+ int height = Convert.ToInt32(screen.Bounds.Height * 0.6);
+ int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height);
+ Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
+ var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));
+ NativeHelp.AddWindowBorders(Handle, ref rect);
+ int left = middlePos.X - rect.Width / 2;
+ int top = middlePos.Y - rect.Height / 2;
+ Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
+ }
+
+ protected void ProcessCommandLineEarly()
+ {
+ var args = Environment.GetCommandLineArgs().Skip(1);
+
+ foreach (string i in args)
+ {
+ if (i.StartsWith("--"))
+ {
+ if (i.Contains("="))
+ {
+ string left = i.Substring(2, i.IndexOf("=") - 2);
+ string right = i.Substring(left.Length + 3);
+
+ if (left == "screen")
+ SetScreen(Convert.ToInt32(right));
+
+ ChangeFullscreen((left == "fs" || left == "fullscreen") && right == "yes");
+ }
+ else
+ {
+ string switchName = i.Substring(2);
+
+ switch (switchName)
+ {
+ case "fs":
+ case "fullscreen":
+ ChangeFullscreen(true);
+ break;
+ }
+ }
+ }
}
}
@@ -107,12 +181,7 @@ namespace mpvnet
private void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
- HandleException(e.Exception);
- }
-
- void HandleException(Exception e)
- {
- MsgError(e.ToString());
+ MsgError(e.Exception.ToString());
}
private void mp_VideoSizeChanged()
@@ -125,7 +194,7 @@ namespace mpvnet
BeginInvoke(new Action(() => Close()));
}
- public bool IsFullscreen
+ public bool IsFullscreen
{
get => WindowState == FormWindowState.Maximized;
}
@@ -139,8 +208,11 @@ namespace mpvnet
{
if (value)
{
- FormBorderStyle = FormBorderStyle.None;
- WindowState = FormWindowState.Maximized;
+ if (FormBorderStyle != FormBorderStyle.None)
+ {
+ FormBorderStyle = FormBorderStyle.None;
+ WindowState = FormWindowState.Maximized;
+ }
}
else
{
@@ -164,7 +236,7 @@ namespace mpvnet
break;
case 0x319: // WM_APPCOMMAND
if (mp.MpvWindowHandle != IntPtr.Zero)
- Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
+ Native.PostMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
break;
case 0x0104: // WM_SYSKEYDOWN:
if (mp.MpvWindowHandle != IntPtr.Zero)
@@ -178,14 +250,19 @@ namespace mpvnet
if (!IsMouseInOSC())
mp.command_string("cycle fullscreen");
break;
+ case 0x02E0: // WM_DPICHANGED
+ if (IgnoreDpiChanged) break;
+ var r2 = Marshal.PtrToStructure(m.LParam);
+ Native.SetWindowPos(Handle, IntPtr.Zero, r2.Left, r2.Top, r2.Width, r2.Height, 0);
+ break;
case 0x0214: // WM_SIZING
var rc = Marshal.PtrToStructure(m.LParam);
var r = rc;
NativeHelp.SubtractWindowBorders(Handle, ref r);
int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top;
float aspect = mp.VideoSize.Width / (float)mp.VideoSize.Height;
- int d_w = (int)(c_h * aspect - c_w);
- int d_h = (int)(c_w / aspect - c_h);
+ int d_w = Convert.ToInt32(c_h * aspect - c_w);
+ int d_h = Convert.ToInt32(c_w / aspect - c_h);
int[] d_corners = { d_w, d_h, -d_w, -d_h };
int[] corners = { rc.Left, rc.Top, rc.Right, rc.Bottom };
int corner = NativeHelp.GetResizeBorder(m.WParam.ToInt32());
@@ -201,24 +278,6 @@ namespace mpvnet
base.WndProc(ref m);
}
- void SetFormPositionAndSize()
- {
- if (IsFullscreen || mp.VideoSize.Width == 0) return;
- var wa = Screen.GetWorkingArea(this);
- int h = (int)(wa.Height * 0.6);
- int w = (int)(h * mp.VideoSize.Width / (float)mp.VideoSize.Height);
- Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
- var r = new Native.RECT(new Rectangle(0, 0, w, h));
- NativeHelp.AddWindowBorders(Handle, ref r);
- int l = middlePos.X - r.Width / 2;
- int t = middlePos.Y - r.Height / 2;
- if (l < 0) l = 0;
- if (t < 0) t = 0;
- if (l + r.Width > wa.Width ) l = wa.Width - r.Width;
- if (t + r.Height > wa.Height ) t = wa.Height - r.Height;
- Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, l, t, r.Width, r.Height, 4 /* SWP_NOZORDER */);
- }
-
protected override void OnDragEnter(DragEventArgs e)
{
base.OnDragEnter(e);
@@ -239,7 +298,6 @@ namespace mpvnet
{
base.OnMouseDown(e);
- // window-dragging
if (WindowState == FormWindowState.Normal &&
e.Button == MouseButtons.Left &&
e.Y < ClientSize.Height * 0.9)
@@ -260,8 +318,6 @@ namespace mpvnet
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
-
- // send mouse command to make OSC show
mp.command_string($"mouse {e.X} {e.Y}");
if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
@@ -306,6 +362,7 @@ namespace mpvnet
CMS.Opened += CMS_Opened;
ContextMenuStrip = CMS;
BuildMenu();
+ IgnoreDpiChanged = false;
}
protected override void OnFormClosed(FormClosedEventArgs e)
diff --git a/mpv.net/Misc.cs b/mpv.net/Misc.cs
index 95e950f..1aae737 100644
--- a/mpv.net/Misc.cs
+++ b/mpv.net/Misc.cs
@@ -1,4 +1,5 @@
-using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@@ -43,4 +44,17 @@ namespace mpvnet
return MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
}
+
+ //public class OSVersion
+ //{
+ // public static float Windows7 { get; set; } = 6.1f;
+ // public static float Windows8 { get; set; } = 6.2f;
+ // public static float Windows81 { get; set; } = 6.3f;
+ // public static float Windows10 { get; set; } = 10f;
+
+ // public static float Current
+ // {
+ // get => Environment.OSVersion.Version.Major + Environment.OSVersion.Version.Minor / 10f;
+ // }
+ //}
}
\ No newline at end of file
diff --git a/mpv.net/NativeHelp.cs b/mpv.net/NativeHelp.cs
index de36ae6..caea177 100644
--- a/mpv.net/NativeHelp.cs
+++ b/mpv.net/NativeHelp.cs
@@ -35,4 +35,4 @@ namespace mpvnet
Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false);
}
}
-}
+}
\ No newline at end of file
diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs
index f0522fb..9582c2a 100644
--- a/mpv.net/Properties/AssemblyInfo.cs
+++ b/mpv.net/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.5.0.0")]
-[assembly: AssemblyFileVersion("1.5.0.0")]
+[assembly: AssemblyVersion("1.6.0.0")]
+[assembly: AssemblyFileVersion("1.6.0.0")]
diff --git a/mpv.net/app.manifest b/mpv.net/app.manifest
index e93d2f5..898dc0d 100644
--- a/mpv.net/app.manifest
+++ b/mpv.net/app.manifest
@@ -25,7 +25,9 @@
+ true
true
+ PerMonitorV2
diff --git a/mpv.net/mp.cs b/mpv.net/mp.cs
index 8e4b451..d9aef5b 100644
--- a/mpv.net/mp.cs
+++ b/mpv.net/mp.cs
@@ -64,20 +64,20 @@ namespace mpvnet
public static List PythonScripts { get; } = new List();
public static AutoResetEvent AutoResetEvent = new AutoResetEvent(false);
- private static Dictionary _mpvConv;
+ private static Dictionary _mpvConf;
- public static Dictionary mpvConv {
+ public static Dictionary mpvConf {
get {
- if (_mpvConv == null)
+ if (_mpvConf == null)
{
- _mpvConv = new Dictionary();
+ _mpvConf = new Dictionary();
if (File.Exists(mpvConfPath))
foreach (var i in File.ReadAllLines(mpvConfPath))
if (i.Contains("=") && ! i.StartsWith("#"))
- _mpvConv[i.Left("=").Trim()] = i.Right("=").Trim();
+ _mpvConf[i.Left("=").Trim()] = i.Right("=").Trim();
}
- return _mpvConv;
+ return _mpvConf;
}
}