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.
- The navigation bar on the left side of the config editor was changed
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.
- Improved support for third party osc scripts like uosc.
- Support of the mpv property `focused`.

View File

@@ -24,7 +24,7 @@ Table of contents
* [Advanced Features](#advanced-features)
* [Hidden Features](#hidden-features)
* [Differences compared to mpv](#differences-compared-to-mpv)
* [Technical Overview](#technical-overview)
* [Environment Variables](#environment-variables)
* [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.
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
[Managed Extensibility Framework](https://docs.microsoft.com/en-us/dotnet/framework/mef/).
Directory where mpv.net looks for user settings.
The main window is WinForms based because WinForms allows better libmpv integration
compared to WPF, all other windows are WPF based.
### MPVNET_VERSION
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

View File

@@ -11,7 +11,6 @@ using MpvNet.Windows.WinForms;
using MpvNet.Windows.WPF.Views;
using MpvNet.Windows.WPF;
using MpvNet.Windows.WPF.MsgBox;
using MpvNet.Windows.UI;
namespace MpvNet;
@@ -45,16 +44,16 @@ public class GuiCommand
["move-window"] = args => MoveWindow?.Invoke(args[0]),
["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)),
["show-menu"] = args => ShowMenu?.Invoke(),
["show-command-palette"] = args => ShowCommandPalette(),
// deprecated
["show-info"] = args => ShowMediaInfo(new[] { "osd" }), // deprecated
["playlist-random"] = args => PlaylistRandom(), // deprecated
["quick-bookmark"] = args => QuickBookmark(), // deprecated
["show-commands"] = args => ShowCommands(), // deprecated
["show-history"] = args => ShowHistory(), // deprecated
["show-playlist"] = args => ShowPlaylist(), // deprecated
//["show-command-palette"] = args => ShowCommandPalette(),
};
public void ShowDialog(Type winType)
@@ -267,19 +266,14 @@ public class GuiCommand
ProcessHelp.ShellExecute(file);
}
public void ShowCommandPalette()
{
MainForm.Instance?.BeginInvoke(() => {
CommandPalette.Instance.SetItems(CommandPalette.GetItems());
MainForm.Instance.ShowCommandPalette();
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");
//public void ShowCommandPalette()
//{
// MainForm.Instance?.BeginInvoke(() => {
// CommandPalette.Instance.SetItems(CommandPalette.GetItems());
// MainForm.Instance.ShowCommandPalette();
// CommandPalette.Instance.SelectFirst();
// });
//}
// deprecated
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.Windows.Forms;
using System.Windows.Threading;
using System.Windows.Forms.Integration;
using MpvNet.Windows.WPF;
using MpvNet.Windows.UI;
@@ -17,7 +18,7 @@ using WpfControls = System.Windows.Controls;
using CommunityToolkit.Mvvm.Messaging;
using static MpvNet.Windows.Native.WinApi;
using System.Windows.Forms.Integration;
using MpvNet.Windows.Help;
namespace MpvNet.Windows.WinForms;
@@ -25,7 +26,7 @@ public partial class MainForm : Form
{
public SnapManager SnapManager = new SnapManager();
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 bool WasShown { get; set; }
public static MainForm? Instance { get; set; }
@@ -39,6 +40,7 @@ public partial class MainForm : Form
int _lastCycleFullscreen;
int _taskbarButtonCreatedMessage;
bool _contextMenuIsReady;
bool _wasMaximized;
public MainForm()
@@ -758,6 +760,8 @@ public partial class MainForm : Form
menuItem.InputGestureText = tempBinding.Input;
}
}
_contextMenuIsReady = true;
}
void Player_FileLoaded()
@@ -901,11 +905,26 @@ public partial class MainForm : Form
case 0x0290: // WM_IME_KEYDOWN
case 0x0291: // WM_IME_KEYUP
case 0x02a3: // WM_MOUSELEAVE
if (MpvWindowHandle == IntPtr.Zero)
MpvWindowHandle = FindWindowEx(Handle, IntPtr.Zero, "mpv", null);
{
bool ignore = false;
if (MpvWindowHandle != IntPtr.Zero)
m.Result = SendMessage(MpvWindowHandle, m.Msg, m.WParam, m.LParam);
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)
MpvWindowHandle = FindWindowEx(Handle, IntPtr.Zero, "mpv", null);
if (MpvWindowHandle != IntPtr.Zero && !ignore)
m.Result = SendMessage(MpvWindowHandle, m.Msg, m.WParam, m.LParam);
}
break;
case 0x51: // WM_INPUTLANGCHANGE
ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/);
@@ -1187,7 +1206,7 @@ public partial class MainForm : Form
InitAndBuildContextMenu();
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
GlobalHotkey.RegisterGlobalHotkeys(Handle);
TaskHelp.Run(Misc.CopyMpvnetCom);
TaskHelp.Run(WinMpvHelp.CopyMpvNetCom);
WasShown = true;
StrongReferenceMessenger.Default.Send(new MainWindowIsLoadedMessage());
//Player.Command("script-message-to mpvnet show-conf-editor");
@@ -1333,72 +1352,72 @@ public partial class MainForm : Form
[DllImport("DwmApi")]
static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
protected override void OnLayout(LayoutEventArgs args)
{
base.OnLayout(args);
AdjustCommandPaletteLeftAndWidth();
}
//protected override void OnLayout(LayoutEventArgs args)
//{
// base.OnLayout(args);
// AdjustCommandPaletteLeftAndWidth();
//}
class ElementHostEx : ElementHost
{
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
const int LWA_ColorKey = 1;
//class ElementHostEx : ElementHost
//{
// protected override void OnHandleCreated(EventArgs e)
// {
// base.OnHandleCreated(e);
// const int LWA_ColorKey = 1;
if (Environment.OSVersion.Version > new Version(10, 0))
SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey);
}
// if (Environment.OSVersion.Version > new Version(10, 0))
// SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey);
// }
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
// protected override CreateParams CreateParams
// {
// get
// {
// CreateParams cp = base.CreateParams;
if (Environment.OSVersion.Version > new Version(10, 0))
cp.ExStyle |= 0x00080000; // WS_EX_LAYERED
// if (Environment.OSVersion.Version > new Version(10, 0))
// 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 |= 0x02000000; //WS_CLIPCHILDREN
// cp.Style |= 0x04000000; //WS_CLIPSIBLINGS
// cp.Style |= 0x02000000; //WS_CLIPCHILDREN
return cp;
}
}
// return cp;
// }
// }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
try
{
return base.ProcessCmdKey(ref msg, keyData);
}
catch (Exception)
{
return true;
}
}
// protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
// {
// try
// {
// return base.ProcessCmdKey(ref msg, keyData);
// }
// catch (Exception)
// {
// return true;
// }
// }
[DllImport("user32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags);
}
// [DllImport("user32.dll")]
// public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags);
//}
public void ShowCommandPalette()
{
if (CommandPaletteHost == null)
{
CommandPaletteHost = new ElementHostEx();
CommandPaletteHost.Dock = DockStyle.Fill;
CommandPaletteHost.BackColor = Color.FromArgb(0x111111);
//public void ShowCommandPalette()
//{
// if (CommandPaletteHost == null)
// {
// CommandPaletteHost = new ElementHostEx();
// CommandPaletteHost.Dock = DockStyle.Fill;
// CommandPaletteHost.BackColor = Color.FromArgb(0x111111);
AdjustCommandPaletteLeftAndWidth();
CommandPaletteHost.Child = CommandPalette.Instance;
CommandPalette.Instance.AdjustHeight();
Controls.Add(CommandPaletteHost);
CommandPaletteHost.BringToFront();
}
}
// AdjustCommandPaletteLeftAndWidth();
// CommandPaletteHost.Child = CommandPalette.Instance;
// CommandPalette.Instance.AdjustHeight();
// Controls.Add(CommandPaletteHost);
// CommandPaletteHost.BringToFront();
// }
//}
public void HideCommandPalette()
{
@@ -1419,16 +1438,16 @@ public partial class MainForm : Form
}
}
void AdjustCommandPaletteLeftAndWidth()
{
if (CommandPaletteHost == null)
return;
//void AdjustCommandPaletteLeftAndWidth()
//{
// if (CommandPaletteHost == null)
// return;
CommandPaletteHost.Width = FontHeight * 26;
// CommandPaletteHost.Width = FontHeight * 26;
if (CommandPaletteHost.Width > ClientSize.Width)
CommandPaletteHost.Width = ClientSize.Width;
// if (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

@@ -25,7 +25,8 @@ public class Command
["cycle-audio"] = args => CycleAudio(), // deprecated
["cycle-subtitles"] = args => CycleSubtitles(), // 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");
@@ -175,4 +176,11 @@ public class Command
if (Player.PlaylistPos < 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 without subtitles"), "async screenshot video", "S"),
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 (_("Audio"), _("Cycle/Next"), "cycle audio", "KP7"),
new (_("Audio"), "-"),

View File

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

View File

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