From 4a202245b540a5d384562480152e4af26b1a1cae Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Mon, 14 Oct 2019 15:50:20 +0200 Subject: [PATCH] window-size mpv property support added --- Changelog.md | 1 + Manual.md | 4 +- README.md | 1 + mpv.net/Resources/inputConf.txt | 2 + mpv.net/WinForms/MainForm.cs | 71 ++++++++++++++++++++++++--------- mpv.net/mpv/mp.cs | 31 ++++++++++++-- 6 files changed, 86 insertions(+), 24 deletions(-) diff --git a/Changelog.md b/Changelog.md index b046a6f..dad6bec 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ context menu item in explorer with multi selection support use my [Open with++](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist) shell extension, as far as I know multi selection can not be done using the Registry +- window-size mpv property support added ### 5.4.2 diff --git a/Manual.md b/Manual.md index c0aa472..07b02aa 100644 --- a/Manual.md +++ b/Manual.md @@ -103,7 +103,7 @@ mpv.net is meant to be a small single person project, it's designed to be mpv co The target audience of mpv.net are programmers, nerds and software enthusiasts that need something more advanced than typical media players. -Furthermore mpv.net is well suited for users who are interested to learn mpv, Linux, portable apps and the command line. +Furthermore mpv.net is well suited for people who are interested to learn mpv and the command line. ## Requirements @@ -155,6 +155,8 @@ A third way is to drag and drop files on the main window. Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This works in all mpv.net features that open files or URLs. +Pressing the shift key while opening a single file will suppress loading all files in the folder. + ### Open > Open URL The Open URL menu entry can be used to open URLs for example from YouTube. diff --git a/README.md b/README.md index 249dab4..1613e60 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Table of contents - File history feature to log time and filename - A-B loop feature - Watch later feature to save the position +- Files can be added to the playlist from explorer using --queue with [Open with++](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist) - [Manual](#manual) ### Screenshots diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index e3b59b9..69f74a1 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -134,6 +134,8 @@ Ctrl+t set ontop yes #menu: View > On Top > Enable Ctrl+T set ontop no #menu: View > On Top > Disable + Alt++ no-osd set window-scale 1.2 #menu: View > Window Size > Enlarge + Alt+- no-osd set window-scale 0.8 #menu: View > Window Size > Shrink b cycle border #menu: View > Toggle Border i script-message mpv.net show-info #menu: View > File/Stream Info t script-binding stats/display-stats #menu: View > Show Statistics diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 3c2fd87..3fd6bdd 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -30,6 +30,13 @@ namespace mpvnet try { + object recent = RegHelp.GetObject(App.RegPath, "Recent"); + + if (recent is string[] r) + RecentFiles = new List(r); + else + RecentFiles = new List(); + Instance = this; Hwnd = Handle; mp.Init(); @@ -48,6 +55,7 @@ namespace mpvnet mp.observe_property_string("aid", PropChangeAid); mp.observe_property_string("vid", PropChangeVid); mp.observe_property_int("edition", PropChangeEdition); + mp.observe_property_double("window-scale", PropChangeWindowScale); if (mp.GPUAPI != "vulkan") mp.ProcessCommandLine(false); @@ -58,13 +66,6 @@ namespace mpvnet Text = "mpv.net " + Application.ProductVersion; TaskbarButtonCreatedMessage = Native.RegisterWindowMessage("TaskbarButtonCreated"); - object recent = RegHelp.GetObject(App.RegPath, "Recent"); - - if (recent is string[] r) - RecentFiles = new List(r); - else - RecentFiles = new List(); - ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; @@ -233,6 +234,7 @@ namespace mpvnet { if (mi.Text.StartsWith(text) && mi.Text.Trim() == text) return mi; + if (mi.DropDownItems.Count > 0) { MenuItem val = FindMenuItem(text, mi.DropDownItems); @@ -245,7 +247,7 @@ namespace mpvnet bool WasInitialSizeSet; - void SetFormPosAndSize() + void SetFormPosAndSize(double scale = 1) { if (WindowState == FormWindowState.Maximized) return; @@ -265,7 +267,6 @@ namespace mpvnet mp.VideoSize = new Size((int)(autoFitHeight * (16 / 9.0)), autoFitHeight); Size size = mp.VideoSize; - int height = size.Height; if (App.RememberHeight) @@ -279,6 +280,7 @@ namespace mpvnet } } + height = Convert.ToInt32(height * scale); int width = Convert.ToInt32(height * size.Width / (double)size.Height); if (height > screen.WorkingArea.Height * 0.9) @@ -317,10 +319,17 @@ namespace mpvnet int minTop = screens.Select(val => val.WorkingArea.Y).Min(); int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max(); - if (left < minLeft) left = minLeft; - if (left + rect.Width > maxRight) left = maxRight - rect.Width; - if (top < minTop) top = minTop; - if (top + rect.Height > maxBottom) top = maxBottom - rect.Height; + if (left < minLeft) + left = minLeft; + + if (left + rect.Width > maxRight) + left = maxRight - rect.Width; + + if (top < minTop) + top = minTop; + + if (top + rect.Height > maxBottom) + top = maxBottom - rect.Height; Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); } @@ -373,7 +382,8 @@ namespace mpvnet foreach (CommandItem item in items) { - if (string.IsNullOrEmpty(item.Path)) continue; + if (string.IsNullOrEmpty(item.Path)) + continue; string path = item.Path.Replace("&", "&&"); MenuItem menuItem = ContextMenu.Add(path, () => { try { @@ -382,7 +392,8 @@ namespace mpvnet Msg.ShowException(ex); } }); - if (menuItem != null) menuItem.ShortcutKeyDisplayString = item.Input + " "; + if (menuItem != null) + menuItem.ShortcutKeyDisplayString = item.Input + " "; } } @@ -405,9 +416,13 @@ namespace mpvnet UpdateProgressBar(); })); - if (RecentFiles.Contains(path)) RecentFiles.Remove(path); + if (RecentFiles.Contains(path)) + RecentFiles.Remove(path); + RecentFiles.Insert(0, path); - while (RecentFiles.Count > App.RecentCount) RecentFiles.RemoveAt(App.RecentCount); + + while (RecentFiles.Count > App.RecentCount) + RecentFiles.RemoveAt(App.RecentCount); } protected override CreateParams CreateParams { @@ -420,7 +435,7 @@ namespace mpvnet protected override void WndProc(ref Message m) { - Debug.WriteLine(m); + //Debug.WriteLine(m); switch (m.Msg) { @@ -463,7 +478,10 @@ namespace mpvnet break; case 0x112: // WM_SYSCOMMAND if (m.WParam.ToInt32() == 0xf120) // SC_RESTORE - SetFormPosAndSize(); + { + CycleFullscreen(true); + CycleFullscreen(false); + } break; case 0x0214: // WM_SIZING var rc = Marshal.PtrToStructure(m.LParam); @@ -545,6 +563,15 @@ namespace mpvnet void PropChangeVid(string value) => mp.Vid = value; void PropChangeEdition(int value) => mp.Edition = value; + + void PropChangeWindowScale(double value) + { + if (value != 1) + { + BeginInvoke(new Action(() => SetFormPosAndSize(value))); + mp.command("no-osd set window-scale 1"); + } + } void PropChangeBorder(bool enabled) { mp.Border = enabled; @@ -660,5 +687,11 @@ namespace mpvnet base.OnLostFocus(e); CursorHelp.Show(); } + + protected override void OnKeyDown(KeyEventArgs e) + { + e.SuppressKeyPress = true; // prevent beep using alt key + base.OnKeyDown(e); + } } } \ No newline at end of file diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index a67485c..837d685 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -58,6 +58,7 @@ namespace mpvnet public static List>> BoolPropChangeActions { get; set; } = new List>>(); public static List>> IntPropChangeActions { get; set; } = new List>>(); + public static List>> DoublePropChangeActions { get; set; } = new List>>(); public static List>> StringPropChangeActions { get; set; } = new List>>(); public static List MediaTracks { get; set; } = new List(); public static List> Chapters { get; set; } = new List>(); @@ -382,22 +383,33 @@ namespace mpvnet var propData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property)); if (propData.format == mpv_format.MPV_FORMAT_FLAG) + { lock (BoolPropChangeActions) foreach (var i in BoolPropChangeActions) if (i.Key== propData.name) i.Value.Invoke(Marshal.PtrToStructure(propData.data) == 1); - - if (propData.format == mpv_format.MPV_FORMAT_STRING) + } + else if (propData.format == mpv_format.MPV_FORMAT_STRING) + { lock (StringPropChangeActions) foreach (var i in StringPropChangeActions) if (i.Key == propData.name) i.Value.Invoke(StringFromNativeUtf8(Marshal.PtrToStructure(propData.data))); - - if (propData.format == mpv_format.MPV_FORMAT_INT64) + } + else if(propData.format == mpv_format.MPV_FORMAT_INT64) + { lock (IntPropChangeActions) foreach (var i in IntPropChangeActions) if (i.Key == propData.name) i.Value.Invoke(Marshal.PtrToStructure(propData.data)); + } + else if (propData.format == mpv_format.MPV_FORMAT_DOUBLE) + { + lock (DoublePropChangeActions) + foreach (var i in DoublePropChangeActions) + if (i.Key == propData.name) + i.Value.Invoke(Marshal.PtrToStructure(propData.data)); + } break; case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART: PlaybackRestart?.Invoke(); @@ -557,6 +569,17 @@ namespace mpvnet IntPropChangeActions.Add(new KeyValuePair>(name, action)); } + public static void observe_property_double(string name, Action action) + { + int err = mpv_observe_property(Handle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_DOUBLE); + + if (err < 0) + throw new Exception($"{name}: {(mpv_error)err}"); + else + lock (DoublePropChangeActions) + DoublePropChangeActions.Add(new KeyValuePair>(name, action)); + } + public static void observe_property_bool(string name, Action action) { int err = mpv_observe_property(Handle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_FLAG);