This commit is contained in:
Frank Skare
2019-03-23 04:07:47 +01:00
parent 1d16861b0b
commit aeb5958be6
10 changed files with 162 additions and 69 deletions

View File

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

View File

@@ -55,6 +55,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />

View File

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

View File

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

View File

@@ -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<Native.RECT>(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<Native.RECT>(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)

View File

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

View File

@@ -35,4 +35,4 @@ namespace mpvnet
Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false);
}
}
}
}

View File

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

View File

@@ -25,7 +25,9 @@
</compatibility>
<application>
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
<dependency>

View File

@@ -64,20 +64,20 @@ namespace mpvnet
public static List<PythonScript> PythonScripts { get; } = new List<PythonScript>();
public static AutoResetEvent AutoResetEvent = new AutoResetEvent(false);
private static Dictionary<string, string> _mpvConv;
private static Dictionary<string, string> _mpvConf;
public static Dictionary<string, string> mpvConv {
public static Dictionary<string, string> mpvConf {
get {
if (_mpvConv == null)
if (_mpvConf == null)
{
_mpvConv = new Dictionary<string, string>();
_mpvConf = new Dictionary<string, string>();
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;
}
}