From 1f6025a10f28d489397cf497103697eb09f0baca Mon Sep 17 00:00:00 2001 From: stax76 Date: Thu, 18 Aug 2022 09:31:23 +0200 Subject: [PATCH] New command to move the Window to the screen edge --- docs/Changelog.md | 13 +++++++++++++ docs/Manual.md | 3 +++ src/Misc/Commands.cs | 3 +++ src/Misc/Player.cs | 3 +++ src/Resources/input.conf.txt | 6 ++++++ src/WinForms/MainForm.cs | 31 ++++++++++++++++++++++++++++++- 6 files changed, 58 insertions(+), 1 deletion(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 2cf2a13..8676eee 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,7 +4,20 @@ - Support multiple folders input (regression fix). - Relative file input paths are converted to absolute paths. - New history-filter option added to define paths to be excluded from the history log feature. +- New command to move the Window to the screen edge (Alt+Arrow) or center (Alt+BS). +- libmpv shinchiro 2022-08-11 +input.conf changes: + +New: + +``` +Alt+Left script-message-to mpvnet move-window left #menu: View > Move > Left +Alt+Right script-message-to mpvnet move-window right #menu: View > Move > Right +Alt+Up script-message-to mpvnet move-window top #menu: View > Move > Top +Alt+Down script-message-to mpvnet move-window bottom #menu: View > Move > Bottom +Alt+BS script-message-to mpvnet move-window center #menu: View > Move > Center +``` # 6.0.3.1 (2022-07-30) diff --git a/docs/Manual.md b/docs/Manual.md index 9615137..f6aaf74 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -241,6 +241,9 @@ Shows a file browser dialog to open external audio files. ### load-sub Shows a file browser dialog to open external subtitle files. +### move-window [left|top|right|bottom|center] +Moves the Window to the screen edge (Alt+Arrow) or center (Alt+BS). + ### open-conf-folder Opens the config folder with Windows File Explorer. diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 9006ccb..178b31c 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -28,6 +28,7 @@ namespace mpvnet case "cycle-subtitles": CycleSubtitles(); break; case "load-audio": LoadAudio(); break; case "load-sub": LoadSubtitle(); break; + case "move-window": MoveWindow(args[0]); break; case "open-clipboard": OpenFromClipboard(); break; case "open-conf-folder": ProcessHelp.ShellExecute(Core.ConfigFolder); break; case "open-files": OpenFiles(args); break; @@ -759,5 +760,7 @@ namespace mpvnet App.QuickBookmark = 0; } } + + public static void MoveWindow(string direction) => Core.RaiseMoveWindow(direction); } } diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index e1b7269..7c9af1d 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -63,6 +63,7 @@ namespace mpvnet public event Action PlaylistPosChangedAsync; public event Action VideoSizeChanged; public event Action VideoSizeChangedAsync; + public event Action MoveWindow; public Dictionary> PropChangeActions { get; set; } = new Dictionary>(); public Dictionary>> IntPropChangeActions { get; set; } = new Dictionary>>(); @@ -1465,6 +1466,8 @@ namespace mpvnet } public void RaiseScaleWindow(float value) => ScaleWindow(value); + + public void RaiseMoveWindow(string value) => MoveWindow(value); public void RaiseWindowScaleNET(float value) => WindowScaleNET(value); diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index aafacc5..e769cf9 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -117,6 +117,12 @@ Alt+1 script-message-to mpvnet window-scale 1.0 #menu: View > Zoom > 100 % Alt+2 script-message-to mpvnet window-scale 2.0 #menu: View > Zoom > 200 % Alt+3 script-message-to mpvnet window-scale 3.0 #menu: View > Zoom > 300 % +Alt+Left script-message-to mpvnet move-window left #menu: View > Move > Left +Alt+Right script-message-to mpvnet move-window right #menu: View > Move > Right +Alt+Up script-message-to mpvnet move-window top #menu: View > Move > Top +Alt+Down script-message-to mpvnet move-window bottom #menu: View > Move > Bottom +Alt+BS script-message-to mpvnet move-window center #menu: View > Move > Center + F8 script-message-to mpvnet show-playlist #menu: View > Show Playlist Ctrl+p script-message-to mpvnet select-profile #menu: View > Show Profile Selection Ctrl+P script-message-to mpvnet show-profiles #menu: View > Show Profiles diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 2a39b8d..7d68171 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -46,6 +46,7 @@ namespace mpvnet Instance = this; Core.FileLoaded += Core_FileLoaded; + Core.MoveWindow += Core_MoveWindow; Core.Pause += Core_Pause; Core.PlaylistPosChanged += Core_PlaylistPosChanged; Core.ScaleWindow += Core_ScaleWindow; @@ -117,7 +118,35 @@ namespace mpvnet } } - private void Core_PlaylistPosChanged(int pos) + void Core_MoveWindow(string direction) + { + BeginInvoke(new Action(() => { + Screen screen = Screen.FromControl(this); + Rectangle workingArea = GetWorkingArea(Handle, screen.WorkingArea); + + switch (direction) + { + case "left": + Left = workingArea.Left; + break; + case "top": + Top = 0; + break; + case "right": + Left = workingArea.Width - Width + workingArea.Left; + break; + case "bottom": + Top = workingArea.Height - Height; + break; + case "center": + Left = (screen.Bounds.Width - Width) / 2; + Top = (screen.Bounds.Height - Height) / 2; + break; + } + })); + } + + void Core_PlaylistPosChanged(int pos) { if (pos == -1) SetTitle();