environment variables and more

This commit is contained in:
stax76
2023-10-31 09:44:20 +01:00
parent ea8944c1cc
commit 4c4088b28a
10 changed files with 140 additions and 119 deletions

View File

@@ -22,7 +22,7 @@
- Dark mode title bar enabled on Windows 10.0.18985 or higher. - Dark mode title bar enabled on Windows 10.0.18985 or higher.
- The navigation bar on the left side of the config editor was changed - The navigation bar on the left side of the config editor was changed
from a simple list to a tree view. from a simple list to a tree view.
- Support of the MPV_HOME environment variable that allows - Support of the MPVNET_HOME environment variable that allows
customizing the conf directory location. customizing the conf directory location.
- Improved support for third party osc scripts like uosc. - Improved support for third party osc scripts like uosc.
- Support of the mpv property `focused`. - Support of the mpv property `focused`.

View File

@@ -24,7 +24,7 @@ Table of contents
* [Advanced Features](#advanced-features) * [Advanced Features](#advanced-features)
* [Hidden Features](#hidden-features) * [Hidden Features](#hidden-features)
* [Differences compared to mpv](#differences-compared-to-mpv) * [Differences compared to mpv](#differences-compared-to-mpv)
* [Technical Overview](#technical-overview) * [Environment Variables](#environment-variables)
* [Context Menu Commands](#context-menu) * [Context Menu Commands](#context-menu)
@@ -614,22 +614,20 @@ mpv.net specific options are saved in the file mpvnet.conf and are just
as mpv properties available on the command line. as mpv properties available on the command line.
Technical Overview Environment Variables
------------------ ---------------------
mpv.net is written in C# 7 and runs on the .NET Framework 4.8. ### MPVNET_HOME
The Extension implementation is based on the Directory where mpv.net looks for user settings.
[Managed Extensibility Framework](https://docs.microsoft.com/en-us/dotnet/framework/mef/).
The main window is WinForms based because WinForms allows better libmpv integration ### MPVNET_VERSION
compared to WPF, all other windows are WPF based.
Third party components are: Returns the version of mpv.net.
- [libmpv provides the core functionality](https://mpv.io/)
- [MediaInfo](https://mediaarea.net/en/MediaInfo)
Context Menu Commands
---------------------
### Open > Open Files ### Open > Open Files

View File

@@ -11,7 +11,6 @@ using MpvNet.Windows.WinForms;
using MpvNet.Windows.WPF.Views; using MpvNet.Windows.WPF.Views;
using MpvNet.Windows.WPF; using MpvNet.Windows.WPF;
using MpvNet.Windows.WPF.MsgBox; using MpvNet.Windows.WPF.MsgBox;
using MpvNet.Windows.UI;
namespace MpvNet; namespace MpvNet;
@@ -45,16 +44,16 @@ public class GuiCommand
["move-window"] = args => MoveWindow?.Invoke(args[0]), ["move-window"] = args => MoveWindow?.Invoke(args[0]),
["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)), ["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)),
["show-menu"] = args => ShowMenu?.Invoke(), ["show-menu"] = args => ShowMenu?.Invoke(),
["show-command-palette"] = args => ShowCommandPalette(),
// deprecated // deprecated
["show-info"] = args => ShowMediaInfo(new[] { "osd" }), // deprecated ["show-info"] = args => ShowMediaInfo(new[] { "osd" }), // deprecated
["playlist-random"] = args => PlaylistRandom(), // deprecated
["quick-bookmark"] = args => QuickBookmark(), // deprecated ["quick-bookmark"] = args => QuickBookmark(), // deprecated
["show-commands"] = args => ShowCommands(), // deprecated ["show-commands"] = args => ShowCommands(), // deprecated
["show-history"] = args => ShowHistory(), // deprecated ["show-history"] = args => ShowHistory(), // deprecated
["show-playlist"] = args => ShowPlaylist(), // deprecated ["show-playlist"] = args => ShowPlaylist(), // deprecated
//["show-command-palette"] = args => ShowCommandPalette(),
}; };
public void ShowDialog(Type winType) public void ShowDialog(Type winType)
@@ -267,19 +266,14 @@ public class GuiCommand
ProcessHelp.ShellExecute(file); ProcessHelp.ShellExecute(file);
} }
public void ShowCommandPalette() //public void ShowCommandPalette()
{ //{
MainForm.Instance?.BeginInvoke(() => { // MainForm.Instance?.BeginInvoke(() => {
CommandPalette.Instance.SetItems(CommandPalette.GetItems()); // CommandPalette.Instance.SetItems(CommandPalette.GetItems());
MainForm.Instance.ShowCommandPalette(); // MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst(); // CommandPalette.Instance.SelectFirst();
}); // });
} //}
// deprecated
public void PlaylistRandom() =>
Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" +
"https://github.com/stax76/mpv-scripts/blob/main/misc.lua");
// deprecated // deprecated
public void QuickBookmark() => public void QuickBookmark() =>

View File

@@ -0,0 +1,16 @@

using MpvNet.ExtensionMethod;
namespace MpvNet.Windows.Help;
public class WinMpvHelp
{
public static void CopyMpvNetCom()
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).AddSep() +
"Microsoft\\WindowsApps\\";
if (File.Exists(dir + "mpvnet.exe") && !File.Exists(dir + "mpvnet.com"))
File.Copy(Folder.Startup + "mpvnet.com", dir + "mpvnet.com");
}
}

View File

@@ -1,15 +0,0 @@
using MpvNet.ExtensionMethod;
namespace MpvNet.Windows;
public class Misc
{
public static void CopyMpvnetCom()
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).AddSep() +
"Microsoft\\WindowsApps\\";
if (File.Exists(dir + "MpvNet.exe") && !File.Exists(dir + "MpvNet.com"))
File.Copy(Folder.Startup + "MpvNet.com", dir + "MpvNet.com");
}
}

View File

@@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Threading; using System.Windows.Threading;
using System.Windows.Forms.Integration;
using MpvNet.Windows.WPF; using MpvNet.Windows.WPF;
using MpvNet.Windows.UI; using MpvNet.Windows.UI;
@@ -17,7 +18,7 @@ using WpfControls = System.Windows.Controls;
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
using static MpvNet.Windows.Native.WinApi; using static MpvNet.Windows.Native.WinApi;
using System.Windows.Forms.Integration; using MpvNet.Windows.Help;
namespace MpvNet.Windows.WinForms; namespace MpvNet.Windows.WinForms;
@@ -25,7 +26,7 @@ public partial class MainForm : Form
{ {
public SnapManager SnapManager = new SnapManager(); public SnapManager SnapManager = new SnapManager();
public IntPtr MpvWindowHandle { get; set; } public IntPtr MpvWindowHandle { get; set; }
public ElementHost CommandPaletteHost { get; set; } public ElementHost? CommandPaletteHost { get; set; }
public Dictionary<string, WpfControls.MenuItem> MenuItemDuplicate = new Dictionary<string, WpfControls.MenuItem>(); public Dictionary<string, WpfControls.MenuItem> MenuItemDuplicate = new Dictionary<string, WpfControls.MenuItem>();
public bool WasShown { get; set; } public bool WasShown { get; set; }
public static MainForm? Instance { get; set; } public static MainForm? Instance { get; set; }
@@ -39,6 +40,7 @@ public partial class MainForm : Form
int _lastCycleFullscreen; int _lastCycleFullscreen;
int _taskbarButtonCreatedMessage; int _taskbarButtonCreatedMessage;
bool _contextMenuIsReady;
bool _wasMaximized; bool _wasMaximized;
public MainForm() public MainForm()
@@ -758,6 +760,8 @@ public partial class MainForm : Form
menuItem.InputGestureText = tempBinding.Input; menuItem.InputGestureText = tempBinding.Input;
} }
} }
_contextMenuIsReady = true;
} }
void Player_FileLoaded() void Player_FileLoaded()
@@ -901,11 +905,26 @@ public partial class MainForm : Form
case 0x0290: // WM_IME_KEYDOWN case 0x0290: // WM_IME_KEYDOWN
case 0x0291: // WM_IME_KEYUP case 0x0291: // WM_IME_KEYUP
case 0x02a3: // WM_MOUSELEAVE case 0x02a3: // WM_MOUSELEAVE
{
bool ignore = false;
if (m.Msg == 0x0100) // WM_KEYDOWN
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if (keyCode == Keys.Escape && _contextMenuIsReady && ContextMenu!.IsOpen)
{
ignore = true;
ContextMenu!.IsOpen = false;
}
}
if (MpvWindowHandle == IntPtr.Zero) if (MpvWindowHandle == IntPtr.Zero)
MpvWindowHandle = FindWindowEx(Handle, IntPtr.Zero, "mpv", null); MpvWindowHandle = FindWindowEx(Handle, IntPtr.Zero, "mpv", null);
if (MpvWindowHandle != IntPtr.Zero) if (MpvWindowHandle != IntPtr.Zero && !ignore)
m.Result = SendMessage(MpvWindowHandle, m.Msg, m.WParam, m.LParam); m.Result = SendMessage(MpvWindowHandle, m.Msg, m.WParam, m.LParam);
}
break; break;
case 0x51: // WM_INPUTLANGCHANGE case 0x51: // WM_INPUTLANGCHANGE
ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/); ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/);
@@ -1187,7 +1206,7 @@ public partial class MainForm : Form
InitAndBuildContextMenu(); InitAndBuildContextMenu();
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
GlobalHotkey.RegisterGlobalHotkeys(Handle); GlobalHotkey.RegisterGlobalHotkeys(Handle);
TaskHelp.Run(Misc.CopyMpvnetCom); TaskHelp.Run(WinMpvHelp.CopyMpvNetCom);
WasShown = true; WasShown = true;
StrongReferenceMessenger.Default.Send(new MainWindowIsLoadedMessage()); StrongReferenceMessenger.Default.Send(new MainWindowIsLoadedMessage());
//Player.Command("script-message-to mpvnet show-conf-editor"); //Player.Command("script-message-to mpvnet show-conf-editor");
@@ -1333,72 +1352,72 @@ public partial class MainForm : Form
[DllImport("DwmApi")] [DllImport("DwmApi")]
static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize); static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
protected override void OnLayout(LayoutEventArgs args) //protected override void OnLayout(LayoutEventArgs args)
{ //{
base.OnLayout(args); // base.OnLayout(args);
AdjustCommandPaletteLeftAndWidth(); // AdjustCommandPaletteLeftAndWidth();
} //}
class ElementHostEx : ElementHost //class ElementHostEx : ElementHost
{ //{
protected override void OnHandleCreated(EventArgs e) // protected override void OnHandleCreated(EventArgs e)
{ // {
base.OnHandleCreated(e); // base.OnHandleCreated(e);
const int LWA_ColorKey = 1; // const int LWA_ColorKey = 1;
if (Environment.OSVersion.Version > new Version(10, 0)) // if (Environment.OSVersion.Version > new Version(10, 0))
SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey); // SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey);
} // }
protected override CreateParams CreateParams // protected override CreateParams CreateParams
{ // {
get // get
{ // {
CreateParams cp = base.CreateParams; // CreateParams cp = base.CreateParams;
if (Environment.OSVersion.Version > new Version(10, 0)) // if (Environment.OSVersion.Version > new Version(10, 0))
cp.ExStyle |= 0x00080000; // WS_EX_LAYERED // cp.ExStyle |= 0x00080000; // WS_EX_LAYERED
cp.ExStyle |= 0x00000008; // WS_EX_TOPMOST // cp.ExStyle |= 0x00000008; // WS_EX_TOPMOST
cp.Style |= 0x04000000; //WS_CLIPSIBLINGS // cp.Style |= 0x04000000; //WS_CLIPSIBLINGS
cp.Style |= 0x02000000; //WS_CLIPCHILDREN // cp.Style |= 0x02000000; //WS_CLIPCHILDREN
return cp; // return cp;
} // }
} // }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) // protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ // {
try // try
{ // {
return base.ProcessCmdKey(ref msg, keyData); // return base.ProcessCmdKey(ref msg, keyData);
} // }
catch (Exception) // catch (Exception)
{ // {
return true; // return true;
} // }
} // }
[DllImport("user32.dll")] // [DllImport("user32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags); // public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags);
} //}
public void ShowCommandPalette() //public void ShowCommandPalette()
{ //{
if (CommandPaletteHost == null) // if (CommandPaletteHost == null)
{ // {
CommandPaletteHost = new ElementHostEx(); // CommandPaletteHost = new ElementHostEx();
CommandPaletteHost.Dock = DockStyle.Fill; // CommandPaletteHost.Dock = DockStyle.Fill;
CommandPaletteHost.BackColor = Color.FromArgb(0x111111); // CommandPaletteHost.BackColor = Color.FromArgb(0x111111);
AdjustCommandPaletteLeftAndWidth(); // AdjustCommandPaletteLeftAndWidth();
CommandPaletteHost.Child = CommandPalette.Instance; // CommandPaletteHost.Child = CommandPalette.Instance;
CommandPalette.Instance.AdjustHeight(); // CommandPalette.Instance.AdjustHeight();
Controls.Add(CommandPaletteHost); // Controls.Add(CommandPaletteHost);
CommandPaletteHost.BringToFront(); // CommandPaletteHost.BringToFront();
} // }
} //}
public void HideCommandPalette() public void HideCommandPalette()
{ {
@@ -1419,16 +1438,16 @@ public partial class MainForm : Form
} }
} }
void AdjustCommandPaletteLeftAndWidth() //void AdjustCommandPaletteLeftAndWidth()
{ //{
if (CommandPaletteHost == null) // if (CommandPaletteHost == null)
return; // return;
CommandPaletteHost.Width = FontHeight * 26; // CommandPaletteHost.Width = FontHeight * 26;
if (CommandPaletteHost.Width > ClientSize.Width) // if (CommandPaletteHost.Width > ClientSize.Width)
CommandPaletteHost.Width = ClientSize.Width; // CommandPaletteHost.Width = ClientSize.Width;
CommandPaletteHost.Left = (ClientSize.Width - CommandPaletteHost.Size.Width) / 2; // CommandPaletteHost.Left = (ClientSize.Width - CommandPaletteHost.Size.Width) / 2;
} //}
} }

View File

@@ -26,6 +26,7 @@ public class Command
["cycle-subtitles"] = args => CycleSubtitles(), // deprecated ["cycle-subtitles"] = args => CycleSubtitles(), // deprecated
["playlist-first"] = args => PlaylistFirst(), // deprecated ["playlist-first"] = args => PlaylistFirst(), // deprecated
["playlist-last"] = args => PlaylistLast(), // deprecated ["playlist-last"] = args => PlaylistLast(), // deprecated
["playlist-random"] = args => PlaylistRandom(), // deprecated
}; };
public string FormatTime(double value) => ((int)value).ToString("00"); public string FormatTime(double value) => ((int)value).ToString("00");
@@ -175,4 +176,11 @@ public class Command
if (Player.PlaylistPos < count - 1) if (Player.PlaylistPos < count - 1)
Player.SetPropertyInt("playlist-pos", count - 1); Player.SetPropertyInt("playlist-pos", count - 1);
} }
// deprecated
public static void PlaylistRandom()
{
int count = Player.GetPropertyInt("playlist-count");
Player.SetPropertyInt("playlist-pos", new Random().Next(count));
}
} }

View File

@@ -69,7 +69,7 @@ public static class InputHelp
new (_("Video"), _("Take Screenshot"), "async screenshot", "s"), new (_("Video"), _("Take Screenshot"), "async screenshot", "s"),
new (_("Video"), _("Take Screenshot without subtitles"), "async screenshot video", "S"), new (_("Video"), _("Take Screenshot without subtitles"), "async screenshot video", "S"),
new (_("Video"), _("Toggle Deinterlace"), "cycle deinterlace", "d"), new (_("Video"), _("Toggle Deinterlace"), "cycle deinterlace", "d"),
new (_("Video"), _("Cycle Aspect Ratio"), "cycle-values video-aspect 16:9 4:3 2.35:1 -1", "a"), new (_("Video"), _("Cycle Aspect Ratio"), "cycle-values video-aspect-override 16:9 4:3 2.35:1 -1", "a"),
new (_("Video"), _("Rotate Video"), "cycle-values video-rotate 90 180 270 0", "Ctrl+r"), new (_("Video"), _("Rotate Video"), "cycle-values video-rotate 90 180 270 0", "Ctrl+r"),
new (_("Audio"), _("Cycle/Next"), "cycle audio", "KP7"), new (_("Audio"), _("Cycle/Next"), "cycle audio", "KP7"),
new (_("Audio"), "-"), new (_("Audio"), "-"),

View File

@@ -6,6 +6,7 @@
<Product>mpv.net</Product> <Product>mpv.net</Product>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>MpvNet</RootNamespace> <RootNamespace>MpvNet</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -208,10 +208,10 @@ public class MainPlayer : MpvClient
get { get {
if (_configFolder == null) if (_configFolder == null)
{ {
string? mpv_home = Environment.GetEnvironmentVariable("MPV_HOME"); string? mpvnet_home = Environment.GetEnvironmentVariable("MPVNET_HOME");
if (Directory.Exists(mpv_home)) if (Directory.Exists(mpvnet_home))
return _configFolder = mpv_home.AddSep(); return _configFolder = mpvnet_home.AddSep();
_configFolder = Folder.Startup + "portable_config"; _configFolder = Folder.Startup + "portable_config";