try to fix #413
This commit is contained in:
@@ -71,7 +71,6 @@ namespace mpvnet
|
|||||||
public List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>();
|
public List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>();
|
||||||
public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
|
public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
|
||||||
public IntPtr Handle { get; set; }
|
public IntPtr Handle { get; set; }
|
||||||
public IntPtr WindowHandle { get; set; }
|
|
||||||
|
|
||||||
public Size VideoSize { get; set; }
|
public Size VideoSize { get; set; }
|
||||||
public TimeSpan Duration;
|
public TimeSpan Duration;
|
||||||
@@ -108,7 +107,7 @@ namespace mpvnet
|
|||||||
public float AutofitSmaller { get; set; } = 0.3f;
|
public float AutofitSmaller { get; set; } = 0.3f;
|
||||||
public float AutofitLarger { get; set; } = 0.8f;
|
public float AutofitLarger { get; set; } = 0.8f;
|
||||||
|
|
||||||
public void Init()
|
public void Init(IntPtr handle)
|
||||||
{
|
{
|
||||||
ApplyShowMenuFix();
|
ApplyShowMenuFix();
|
||||||
|
|
||||||
@@ -117,6 +116,8 @@ namespace mpvnet
|
|||||||
if (Handle == IntPtr.Zero)
|
if (Handle == IntPtr.Zero)
|
||||||
throw new Exception("error mpv_create");
|
throw new Exception("error mpv_create");
|
||||||
|
|
||||||
|
SetPropertyLong("wid", handle.ToInt64());
|
||||||
|
|
||||||
mpv_request_log_messages(Handle, "terminal-default");
|
mpv_request_log_messages(Handle, "terminal-default");
|
||||||
|
|
||||||
App.RunTask(() => EventLoop());
|
App.RunTask(() => EventLoop());
|
||||||
@@ -127,21 +128,20 @@ namespace mpvnet
|
|||||||
SetPropertyString("input-terminal", "yes");
|
SetPropertyString("input-terminal", "yes");
|
||||||
SetPropertyString("msg-level", "osd/libass=fatal");
|
SetPropertyString("msg-level", "osd/libass=fatal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPropertyString("watch-later-options", "mute");
|
|
||||||
SetPropertyString("screenshot-directory", "~~desktop/");
|
|
||||||
SetPropertyString("osd-playing-msg", "${filename}");
|
|
||||||
SetPropertyString("wid", MainForm.Hwnd.ToString());
|
|
||||||
SetPropertyString("osc", "yes");
|
|
||||||
SetPropertyString("force-window", "yes");
|
|
||||||
SetPropertyString("config-dir", ConfigFolder);
|
|
||||||
SetPropertyString("config", "yes");
|
|
||||||
|
|
||||||
SetPropertyInt("osd-duration", 2000);
|
SetPropertyInt("osd-duration", 2000);
|
||||||
|
|
||||||
SetPropertyBool("input-default-bindings", true);
|
SetPropertyBool("input-default-bindings", true);
|
||||||
SetPropertyBool("input-builtin-bindings", false);
|
SetPropertyBool("input-builtin-bindings", false);
|
||||||
|
|
||||||
|
SetPropertyString("watch-later-options", "mute");
|
||||||
|
SetPropertyString("screenshot-directory", "~~desktop/");
|
||||||
|
SetPropertyString("osd-playing-msg", "${filename}");
|
||||||
|
SetPropertyString("osc", "yes");
|
||||||
|
SetPropertyString("force-window", "yes");
|
||||||
|
SetPropertyString("config-dir", ConfigFolder);
|
||||||
|
SetPropertyString("config", "yes");
|
||||||
|
|
||||||
ProcessCommandLine(true);
|
ProcessCommandLine(true);
|
||||||
mpv_error err = mpv_initialize(Handle);
|
mpv_error err = mpv_initialize(Handle);
|
||||||
|
|
||||||
@@ -388,9 +388,6 @@ namespace mpvnet
|
|||||||
IntPtr ptr = mpv_wait_event(Handle, -1);
|
IntPtr ptr = mpv_wait_event(Handle, -1);
|
||||||
mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
|
mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
|
||||||
|
|
||||||
if (WindowHandle == IntPtr.Zero)
|
|
||||||
WindowHandle = Native.FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (evt.event_id)
|
switch (evt.event_id)
|
||||||
@@ -761,6 +758,14 @@ namespace mpvnet
|
|||||||
HandleError(err, throwException, $"error setting property: {name} = {value}");
|
HandleError(err, throwException, $"error setting property: {name} = {value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetPropertyLong(string name, long value, bool throwException = false)
|
||||||
|
{
|
||||||
|
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref value);
|
||||||
|
|
||||||
|
if (err < 0)
|
||||||
|
HandleError(err, throwException, $"error setting property: {name} = {value}");
|
||||||
|
}
|
||||||
|
|
||||||
public long GetPropertyLong(string name, bool throwException = false)
|
public long GetPropertyLong(string name, bool throwException = false)
|
||||||
{
|
{
|
||||||
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
|
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
|
||||||
@@ -772,15 +777,6 @@ namespace mpvnet
|
|||||||
return lpBuffer.ToInt64();
|
return lpBuffer.ToInt64();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPropertyLong(string name, long value, bool throwException = false)
|
|
||||||
{
|
|
||||||
long val = value;
|
|
||||||
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
|
||||||
|
|
||||||
if (err < 0)
|
|
||||||
HandleError(err, throwException, $"error setting property: {name} = {value}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public double GetPropertyDouble(string name, bool throwException = false)
|
public double GetPropertyDouble(string name, bool throwException = false)
|
||||||
{
|
{
|
||||||
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
|
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ namespace mpvnet
|
|||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
public ElementHost CommandPaletteHost { get; set; }
|
public ElementHost CommandPaletteHost { get; set; }
|
||||||
|
public IntPtr mpvWindowHandle { get; set; }
|
||||||
public static MainForm Instance { get; set; }
|
public static MainForm Instance { get; set; }
|
||||||
public static IntPtr Hwnd { get; set; }
|
|
||||||
|
|
||||||
new WpfControls.ContextMenu ContextMenu { get; set; }
|
new WpfControls.ContextMenu ContextMenu { get; set; }
|
||||||
AutoResetEvent MenuAutoResetEvent { get; } = new AutoResetEvent(false);
|
AutoResetEvent MenuAutoResetEvent { get; } = new AutoResetEvent(false);
|
||||||
Point LastCursorPosition;
|
Point LastCursorPosition;
|
||||||
@@ -44,8 +44,7 @@ namespace mpvnet
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
Hwnd = Handle;
|
Core.Init(Handle);
|
||||||
Core.Init();
|
|
||||||
|
|
||||||
Core.Shutdown += Core_Shutdown;
|
Core.Shutdown += Core_Shutdown;
|
||||||
Core.ShowMenu += Core_ShowMenu;
|
Core.ShowMenu += Core_ShowMenu;
|
||||||
@@ -812,8 +811,11 @@ namespace mpvnet
|
|||||||
case 0x20b: // WM_XBUTTONDOWN
|
case 0x20b: // WM_XBUTTONDOWN
|
||||||
case 0x20c: // WM_XBUTTONUP
|
case 0x20c: // WM_XBUTTONUP
|
||||||
case 0x20e: // WM_MOUSEHWHEEL
|
case 0x20e: // WM_MOUSEHWHEEL
|
||||||
if (Core.WindowHandle != IntPtr.Zero)
|
if (mpvWindowHandle == IntPtr.Zero)
|
||||||
m.Result = SendMessage(Core.WindowHandle, m.Msg, m.WParam, m.LParam);
|
mpvWindowHandle = FindWindowEx(Handle, IntPtr.Zero, "mpv", null);
|
||||||
|
|
||||||
|
if (mpvWindowHandle != IntPtr.Zero)
|
||||||
|
m.Result = SendMessage(mpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
||||||
break;
|
break;
|
||||||
case 0x051: // WM_INPUTLANGCHANGE
|
case 0x051: // WM_INPUTLANGCHANGE
|
||||||
ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/);
|
ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/);
|
||||||
|
|||||||
Reference in New Issue
Block a user