diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index db28b71..8450ad6 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -53,6 +53,7 @@ namespace mpvnet case "show-input-editor": ShowDialog(typeof(InputWindow)); break; case "show-keys": ShowStrings(Core.GetPropertyString("input-key-list").Split(',')); break; case "show-media-info": ShowMediaInfo(args); break; + case "show-menu": ShowMenu(); break; case "show-playlist": ShowPlaylist(); break; case "show-profiles": Msg.ShowInfo(mpvHelp.GetProfiles()); break; case "show-progress": ShowProgress(); break; @@ -661,5 +662,7 @@ namespace mpvnet MainForm.Instance.ShowCommandPalette(); CommandPalette.Instance.SelectFirst(); }); + + public static void ShowMenu() => Core.RaiseShowMenu(); } } diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index eaf026b..eb98d50 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -53,6 +53,7 @@ namespace mpvnet public event Action Initialized; public event Action InitializedAsync; + public event Action ShowMenu; public event Action ScaleWindow; public event Action WindowScale; public event Action PlaylistPosChanged; @@ -81,7 +82,7 @@ namespace mpvnet public string ConfPath { get => ConfigFolder + "mpv.conf"; } public string GPUAPI { get; set; } = "auto"; public string VO { get; set; } = "gpu"; - public string InputConfPath { get => ConfigFolder + "input.conf"; } + public string InputConfPath => ConfigFolder + "input.conf"; public string VID { get; set; } = ""; public string AID { get; set; } = ""; @@ -109,6 +110,8 @@ namespace mpvnet public void Init() { + ApplyShowMenuFix(); + Handle = mpv_create(); if (Handle == IntPtr.Zero) @@ -168,23 +171,40 @@ namespace mpvnet InvokeAsync(InitializedAsync); } - void ApplyCompatibilityFixes() + void ApplyShowMenuFix() { - if (!App.Settings.InputDefaultBindingsFixApplied) + if (App.Settings.ShowMenuFixApplied) + return; + + if (File.Exists(InputConfPath)) { - if (File.Exists(ConfPath)) - { - string content = File.ReadAllText(ConfPath); + string content = File.ReadAllText(InputConfPath); - if (content.Contains("input-default-bindings = no")) - File.WriteAllText(ConfPath, content.Replace("input-default-bindings = no", "")); - - if (content.Contains("input-default-bindings=no")) - File.WriteAllText(ConfPath, content.Replace("input-default-bindings=no", "")); - } - - App.Settings.InputDefaultBindingsFixApplied = true; + if (!content.Contains("script-message mpv.net show-menu")) + File.WriteAllText(InputConfPath, BR + content.Trim() + BR + + "MBTN_Right script-message mpv.net show-menu" + BR); } + + App.Settings.ShowMenuFixApplied = true; + } + + void ApplyInputDefaultBindingsFix() + { + if (App.Settings.InputDefaultBindingsFixApplied) + return; + + if (File.Exists(ConfPath)) + { + string content = File.ReadAllText(ConfPath); + + if (content.Contains("input-default-bindings = no")) + File.WriteAllText(ConfPath, content.Replace("input-default-bindings = no", "")); + + if (content.Contains("input-default-bindings=no")) + File.WriteAllText(ConfPath, content.Replace("input-default-bindings=no", "")); + } + + App.Settings.InputDefaultBindingsFixApplied = true; } public void ProcessProperty(string name, string value) @@ -264,7 +284,7 @@ namespace mpvnet get { if (_Conf == null) { - ApplyCompatibilityFixes(); + ApplyInputDefaultBindingsFix(); _Conf = new Dictionary(); @@ -1352,6 +1372,8 @@ KP1 script-binding delete_current_file/confirm public void RaiseScaleWindow(float value) => ScaleWindow(value); public void RaiseWindowScale(float value) => WindowScale(value); + + public void RaiseShowMenu() => ShowMenu(); void ReadMetaData() { diff --git a/src/Misc/MainForm.cs b/src/Misc/MainForm.cs index 5cfe15d..12d662b 100644 --- a/src/Misc/MainForm.cs +++ b/src/Misc/MainForm.cs @@ -48,6 +48,7 @@ namespace mpvnet Core.Init(); Core.Shutdown += Core_Shutdown; + Core.ShowMenu += Core_ShowMenu; Core.VideoSizeChanged += Core_VideoSizeChanged; Core.ScaleWindow += Core_ScaleWindow; Core.WindowScale += Core_WindowScale; @@ -135,6 +136,18 @@ namespace mpvnet } } + private void Core_ShowMenu() + { + BeginInvoke(new Action(() => { + if (IsMouseInOSC()) + return; + + CursorHelp.Show(); + UpdateMenu(); + ContextMenu.IsOpen = true; + })); + } + void Core_ScaleWindow(float scale) { BeginInvoke(new Action(() => { int w, h; @@ -791,30 +804,17 @@ namespace mpvnet case 0x105: // WM_SYSKEYUP case 0x201: // WM_LBUTTONDOWN case 0x202: // WM_LBUTTONUP + case 0x204: // WM_RBUTTONDOWN + case 0x205: // WM_RBUTTONUP case 0x207: // WM_MBUTTONDOWN case 0x208: // WM_MBUTTONUP case 0x20a: // WM_MOUSEWHEEL - case 0x20e: // WM_MOUSEHWHEEL case 0x20b: // WM_XBUTTONDOWN - case 0x20c: // WM_XBUTTONUP + case 0x20c: // WM_XBUTTONUP + case 0x20e: // WM_MOUSEHWHEEL if (Core.WindowHandle != IntPtr.Zero) m.Result = SendMessage(Core.WindowHandle, m.Msg, m.WParam, m.LParam); break; - case 0x0204: // WM_RBUTTONDOWN - if (IsMouseInOSC() && Core.WindowHandle != IntPtr.Zero) - m.Result = SendMessage(Core.WindowHandle, m.Msg, m.WParam, m.LParam); - break; - case 0x0205: // WM_RBUTTONUP - if (!IsMouseInOSC()) - { - CursorHelp.Show(); - UpdateMenu(); - ContextMenu.IsOpen = true; - } - else - if (Core.WindowHandle != IntPtr.Zero) - m.Result = SendMessage(Core.WindowHandle, m.Msg, m.WParam, m.LParam); - break; case 0x319: // WM_APPCOMMAND { string value = Input.WM_APPCOMMAND_to_mpv_key((int)(m.LParam.ToInt64() >> 16 & ~0xf000)); diff --git a/src/Misc/Settings.cs b/src/Misc/Settings.cs index 7a64d18..38d707b 100644 --- a/src/Misc/Settings.cs +++ b/src/Misc/Settings.cs @@ -15,7 +15,7 @@ namespace mpvnet public class AppSettings { public bool InputDefaultBindingsFixApplied; - public int LastUpdateCheck; + public bool ShowMenuFixApplied; public int Volume = 70; public List RecentFiles = new List(); public Point WindowLocation; diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index c7a7575..453eec1 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -166,10 +166,11 @@ F1 script-message mpv.net show-command-palette #menu: Command Palette _ ignore #menu: - Esc quit #menu: Exit +MBTN_Right script-message mpv.net show-menu 6 script-message mpv.net show-progress KP6 script-message mpv.net show-progress 7 script-message mpv.net cycle-audio -SHARP script-message mpv.net cycle-audio +Sharp script-message mpv.net cycle-audio 8 cycle sub j cycle sub q quit @@ -195,15 +196,15 @@ MBTN_Left ignore f cycle fullscreen MBTN_Left_DBL cycle fullscreen KP_Enter cycle fullscreen -Shift+RIGHT no-osd seek 1 exact -Shift+LEFT no-osd seek -1 exact -Shift+UP no-osd seek 5 exact -Shift+DOWN no-osd seek -5 exact +Shift+Right no-osd seek 1 exact +Shift+Left no-osd seek -1 exact +Shift+Up no-osd seek 5 exact +Shift+Down no-osd seek -5 exact Shift+BS revert-seek # undo the previous (or marked) seek Shift+Ctrl+BS revert-seek mark # mark the position for revert-seek Shift+g add sub-scale +0.1 # increase the subtitle font size Shift+f add sub-scale -0.1 # decrease the subtitle font size -Ctrl+Shift+LEFT no-osd sub-seek -1 # seek to the previous subtitle -Ctrl+Shift+RIGHT no-osd sub-seek 1 # seek to the next subtitle +Ctrl+Shift+Left no-osd sub-seek -1 # seek to the previous subtitle +Ctrl+Shift+Right no-osd sub-seek 1 # seek to the next subtitle Ctrl+Wheel_Up no-osd seek 7 Ctrl+Wheel_Down no-osd seek -7 diff --git a/src/Scripts/JavaScript/seek-show-position.js b/src/Scripts/JavaScript/seek-show-position.js deleted file mode 100644 index e3a0e96..0000000 --- a/src/Scripts/JavaScript/seek-show-position.js +++ /dev/null @@ -1,35 +0,0 @@ - -// When seeking displays position and duration like so: 70:00 / 80:00 -// Which is different from most players which use: 01:10:00 / 01:20:00 -// In input.conf set the input command prefix no-osd infront of the seek command. - -function add_zero(val) -{ - val = Math.round(val); - return val > 9 ? "" + val : "0" + val; -} - -function format(val) -{ - var sec = Math.round(val); - - if (sec < 0) - sec = 0; - - pos_min_floor = Math.floor(sec / 60); - sec_rest = sec - pos_min_floor * 60; - return add_zero(pos_min_floor) + ":" + add_zero(sec_rest); -} - -function on_seek(_) -{ - pos = mp.get_property_number("time-pos"); - dur = mp.get_property_number("duration"); - - if (pos > dur) - pos = dur; - - mp.commandv("show-text", format(pos) + " / " + format(dur)); -} - -mp.register_event("seek", on_seek); diff --git a/src/Scripts/JavaScript/show-playlist.js b/src/Scripts/JavaScript/show-playlist.js deleted file mode 100644 index c40078d..0000000 --- a/src/Scripts/JavaScript/show-playlist.js +++ /dev/null @@ -1,26 +0,0 @@ - -// This script shows the playlist. - -function showPlaylist() -{ - // set font size - mp.set_property_number("osd-font-size", 40); - - // show playlist for 5 seconds - mp.command("show-text ${playlist} 5000"); - - // restore original font size in 6 seconds - setTimeout(resetFontSize, 6000); -} - -// restore original font size -function resetFontSize() -{ - mp.set_property_number("osd-font-size", size); -} - -// save original font size -var size = mp.get_property_number("osd-font-size"); - -// input.conf: key script-binding show-playlist -mp.add_key_binding(null, "show-playlist", showPlaylist); diff --git a/src/Scripts/Lua/.vscode/launch.json b/src/Scripts/Lua/.vscode/launch.json deleted file mode 100644 index a156dcf..0000000 --- a/src/Scripts/Lua/.vscode/launch.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "lua", - "request": "launch", - "name": "launch", - "runtimeExecutable": "D:/Software/Development/MSYS2/mingw64/bin/mpv.exe", - "runtimeArgs": ["--script=${workspaceFolder}\\delete-current-file.lua", "D:\\Samples\\castele.m2v"], - "stopOnEntry": false, - "luaVersion": "5.1" - } - ] -} \ No newline at end of file diff --git a/src/Scripts/Lua/delete-current-file.lua b/src/Scripts/Lua/delete-current-file.lua deleted file mode 100644 index 2bea2a8..0000000 --- a/src/Scripts/Lua/delete-current-file.lua +++ /dev/null @@ -1,70 +0,0 @@ - --- Only supported on Windows. - --- This script deletes the file that is currently playing --- via keyboard shortcut, the file is moved to the recycle bin. - --- Usage: --- Configure input.conf as described below. --- Press 0 to initiate the delete operation. --- Press 1 to confirm and delete. - --- input.conf: - --- KP0 script-binding delete_current_file/delete --- 0 script-binding delete_current_file/delete - --- KP1 script-binding delete_current_file/confirm --- 1 script-binding delete_current_file/confirm - -function delete() - file_to_delete = mp.get_property("path") - delete_time = os.time() - mp.commandv("show-text", "Press 1 to delete file", "10000") -end - -function confirm() - local path = mp.get_property("path") - - if file_to_delete == path and (os.time() - delete_time) < 10 then - mp.commandv("show-text", "") - - local count = mp.get_property_number("playlist-count") - local pos = mp.get_property_number("playlist-pos") - local new_pos = 0 - - if pos == count - 1 then - new_pos = pos - 1 - else - new_pos = pos + 1 - end - - if new_pos > -1 then - mp.command("set pause no") - mp.set_property_number("playlist-pos", new_pos) - end - - mp.command("playlist-remove " .. pos) - - local ps_code = [[& { - Start-Sleep -Seconds 2 - Add-Type -AssemblyName Microsoft.VisualBasic - [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('file_to_delete', 'OnlyErrorDialogs', 'SendToRecycleBin') - }]] - - local escaped_file_to_delete = string.gsub(file_to_delete, "'", "''") - escaped_file_to_delete = string.gsub(escaped_file_to_delete, "’", "’’") - escaped_file_to_delete = string.gsub(escaped_file_to_delete, "%%", "%%%%") - ps_code = string.gsub(ps_code, "file_to_delete", escaped_file_to_delete) - - mp.command_native({ - name = "subprocess", - playback_only = false, - detach = true, - args = { 'powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps_code }, - }) - end -end - -mp.add_key_binding(nil, "delete", delete) -mp.add_key_binding(nil, "confirm", confirm) diff --git a/src/Scripts/Lua/pause-when-minimize.lua b/src/Scripts/Lua/pause-when-minimize.lua deleted file mode 100644 index 629d3fe..0000000 --- a/src/Scripts/Lua/pause-when-minimize.lua +++ /dev/null @@ -1,23 +0,0 @@ - --- https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/pause-when-minimize.lua - --- This script pauses playback when minimizing the window, and resumes playback --- if it's brought back again. If the player was already paused when minimizing, --- then try not to mess with the pause state. - -local did_minimize = false - -mp.observe_property("window-minimized", "bool", function(name, value) - local pause = mp.get_property_native("pause") - if value == true then - if pause == false then - mp.set_property_native("pause", true) - did_minimize = true - end - elseif value == false then - if did_minimize and (pause == true) then - mp.set_property_native("pause", false) - end - did_minimize = false - end -end)