environment variables and more
This commit is contained in:
@@ -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() =>
|
||||
|
||||
16
src/MpvNet.Windows/Help/WinMpvHelp.cs
Normal file
16
src/MpvNet.Windows/Help/WinMpvHelp.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user