added taskbar-progress implementation

This commit is contained in:
Frank Skare
2019-09-05 06:20:44 +02:00
parent b07901485e
commit 078e8046bd
10 changed files with 135 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
### ###
- added taskbar-progress implementation
- added new setting to start with maximized window - added new setting to start with maximized window
- long file names work now even if not enabled by the OS - long file names work now even if not enabled by the OS
- fixed history being written even when history file wasn't created prior - fixed history being written even when history file wasn't created prior

View File

@@ -27,6 +27,9 @@ namespace mpvnet
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); public static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int RegisterWindowMessage(string id);
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool AllowSetForegroundWindow(int dwProcessId); public static extern bool AllowSetForegroundWindow(int dwProcessId);

53
mpv.net/Native/Taskbar.cs Normal file
View File

@@ -0,0 +1,53 @@
using System;
using System.Runtime.InteropServices;
public class Taskbar
{
private ITaskbarList3 Instance = (ITaskbarList3)new TaskBarCommunication();
public IntPtr Handle { get; set; }
public Taskbar(IntPtr handle) => Handle = handle;
[ComImportAttribute]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
private interface ITaskbarList3
{
// ITaskbarList
[PreserveSig] void HrInit();
[PreserveSig] void AddTab(IntPtr hwnd);
[PreserveSig] void DeleteTab(IntPtr hwnd);
[PreserveSig] void ActivateTab(IntPtr hwnd);
[PreserveSig] void SetActiveAlt(IntPtr hwnd);
// ITaskbarList2
[PreserveSig] void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
// ITaskbarList3
[PreserveSig] void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
[PreserveSig] void SetProgressState(IntPtr hwnd, TaskbarStates state);
}
[ComImportAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
private class TaskBarCommunication { }
public void SetState(TaskbarStates taskbarState)
{
Instance.SetProgressState(Handle, taskbarState);
}
public void SetValue(double progressValue, double progressMax)
{
Instance.SetProgressValue(Handle, (UInt64)progressValue, (UInt64)progressMax);
}
}
public enum TaskbarStates
{
NoProgress = 0,
Indeterminate = 0x1,
Normal = 0x2,
Error = 0x4,
Paused = 0x8
}

View File

@@ -196,5 +196,4 @@
Ctrl+Wheel_Up no-osd seek 7 Ctrl+Wheel_Up no-osd seek 7
Ctrl+Wheel_Down no-osd seek -7 Ctrl+Wheel_Down no-osd seek -7
MBTN_Left_DBL cycle fullscreen MBTN_Left_DBL cycle fullscreen
KP_Enter cycle fullscreen KP_Enter cycle fullscreen
MBTN_Left ignore

View File

@@ -325,6 +325,14 @@ name = "screenshot-png-filter"
filter = "Screen" filter = "Screen"
help = "<0-5> Set the filter applied prior to PNG compression. 0 is none, 1 is 'sub', 2 is 'up', 3 is 'average', 4 is 'Paeth', and 5 is 'mixed'. This affects the level of compression that can be achieved. For most images, 'mixed' achieves the best compression ratio, hence it is the default." help = "<0-5> Set the filter applied prior to PNG compression. 0 is none, 1 is 'sub', 2 is 'up', 3 is 'average', 4 is 'Paeth', and 5 is 'mixed'. This affects the level of compression that can be achieved. For most images, 'mixed' achieves the best compression ratio, hence it is the default."
[[settings]]
name = "taskbar-progress"
default = "yes"
filter = "Playback"
help = "Show progress in taskbar."
options = [{ name = "yes" },
{ name = "no" }]
[[settings]] [[settings]]
name = "keep-open-pause" name = "keep-open-pause"
default = "yes" default = "yes"

View File

@@ -30,14 +30,19 @@
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.Timer = new System.Windows.Forms.Timer(this.components); this.CursorTimer = new System.Windows.Forms.Timer(this.components);
this.ProgressTimer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout(); this.SuspendLayout();
// //
// Timer // CursorTimer
// //
this.Timer.Enabled = true; this.CursorTimer.Enabled = true;
this.Timer.Interval = 1000; this.CursorTimer.Interval = 1000;
this.Timer.Tick += new System.EventHandler(this.Timer_Tick); this.CursorTimer.Tick += new System.EventHandler(this.CursorTimer_Tick);
//
// ProgressTimer
//
this.ProgressTimer.Tick += new System.EventHandler(this.ProgressTimer_Tick);
// //
// MainForm // MainForm
// //
@@ -57,6 +62,7 @@
#endregion #endregion
private System.Windows.Forms.Timer Timer; private System.Windows.Forms.Timer CursorTimer;
private System.Windows.Forms.Timer ProgressTimer;
} }
} }

View File

@@ -16,12 +16,12 @@ namespace mpvnet
{ {
public static MainForm Instance { get; set; } public static MainForm Instance { get; set; }
public static IntPtr Hwnd { get; set; } public static IntPtr Hwnd { get; set; }
public new ContextMenuStripEx ContextMenu { get; set; } public new ContextMenuStripEx ContextMenu { get; set; }
Point LastCursorPosChanged; Point LastCursorPosChanged;
int LastCursorChangedTickCount; int LastCursorChangedTickCount;
int TaskbarButtonCreatedMessage;
bool WasShown; bool WasShown;
Taskbar Taskbar;
List<string> RecentFiles; List<string> RecentFiles;
public MainForm() public MainForm()
@@ -38,7 +38,9 @@ namespace mpvnet
mp.VideoSizeChanged += VideoSizeChanged; mp.VideoSizeChanged += VideoSizeChanged;
mp.FileLoaded += FileLoaded; mp.FileLoaded += FileLoaded;
mp.Idle += Idle; mp.Idle += Idle;
mp.Seek += () => UpdateProgressBar();
mp.observe_property_bool("pause", PropChangePause);
mp.observe_property_bool("fullscreen", PropChangeFullscreen); mp.observe_property_bool("fullscreen", PropChangeFullscreen);
mp.observe_property_bool("ontop", PropChangeOnTop); mp.observe_property_bool("ontop", PropChangeOnTop);
mp.observe_property_bool("border", PropChangeBorder); mp.observe_property_bool("border", PropChangeBorder);
@@ -46,14 +48,15 @@ namespace mpvnet
mp.observe_property_string("aid", PropChangeAid); mp.observe_property_string("aid", PropChangeAid);
mp.observe_property_string("vid", PropChangeVid); mp.observe_property_string("vid", PropChangeVid);
mp.observe_property_int("edition", PropChangeEdition); mp.observe_property_int("edition", PropChangeEdition);
if (mp.GPUAPI != "vulkan") mp.ProcessCommandLine(false); if (mp.GPUAPI != "vulkan") mp.ProcessCommandLine(false);
AppDomain.CurrentDomain.UnhandledException += (sender, e) => Msg.ShowError(e.ExceptionObject.ToString()); AppDomain.CurrentDomain.UnhandledException += (sender, e) => Msg.ShowError(e.ExceptionObject.ToString());
Application.ThreadException += (sender, e) => Msg.ShowException(e.Exception); Application.ThreadException += (sender, e) => Msg.ShowException(e.Exception);
Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
Text = "mpv.net " + Application.ProductVersion; Text = "mpv.net " + Application.ProductVersion;
TaskbarButtonCreatedMessage = Native.RegisterWindowMessage("TaskbarButtonCreated");
object recent = RegHelp.GetObject(App.RegPath, "Recent"); object recent = RegHelp.GetObject(App.RegPath, "Recent");
if (recent is string[] r) if (recent is string[] r)
@@ -94,14 +97,17 @@ namespace mpvnet
public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items); public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items);
void Idle() => BeginInvoke(new Action(() => Text = "mpv.net " + Application.ProductVersion)); void Shutdown() => BeginInvoke(new Action(() => Close()));
void Idle()
{
BeginInvoke(new Action(() => Text = "mpv.net " + Application.ProductVersion));
}
void CM_Popup(object sender, EventArgs e) => CursorHelp.Show(); void CM_Popup(object sender, EventArgs e) => CursorHelp.Show();
void VideoSizeChanged() => BeginInvoke(new Action(() => SetFormPosAndSize())); void VideoSizeChanged() => BeginInvoke(new Action(() => SetFormPosAndSize()));
void Shutdown() => BeginInvoke(new Action(() => Close()));
void PropChangeFullscreen(bool value) => BeginInvoke(new Action(() => CycleFullscreen(value))); void PropChangeFullscreen(bool value) => BeginInvoke(new Action(() => CycleFullscreen(value)));
void ContextMenu_Opened(object sender, EventArgs e) => CursorHelp.Show(); void ContextMenu_Opened(object sender, EventArgs e) => CursorHelp.Show();
@@ -372,6 +378,7 @@ namespace mpvnet
private void FileLoaded() private void FileLoaded()
{ {
string path = mp.get_property_string("path"); string path = mp.get_property_string("path");
BeginInvoke(new Action(() => { BeginInvoke(new Action(() => {
if (path.Contains("://")) if (path.Contains("://"))
Text = path + " - mpv.net " + Application.ProductVersion; Text = path + " - mpv.net " + Application.ProductVersion;
@@ -379,7 +386,13 @@ namespace mpvnet
Text = path.FileName() + " - mpv.net " + Application.ProductVersion; Text = path.FileName() + " - mpv.net " + Application.ProductVersion;
else else
Text = "mpv.net " + Application.ProductVersion; Text = "mpv.net " + Application.ProductVersion;
double duration = mp.get_property_number("duration");
ProgressTimer.Interval = (int)(mp.Duration.TotalMilliseconds / 99);
if (ProgressTimer.Interval < 100) ProgressTimer.Interval = 100;
if (ProgressTimer.Interval > 999) ProgressTimer.Interval = 999;
})); }));
if (RecentFiles.Contains(path)) RecentFiles.Remove(path); if (RecentFiles.Contains(path)) RecentFiles.Remove(path);
RecentFiles.Insert(0, path); RecentFiles.Insert(0, path);
while (RecentFiles.Count > App.RecentCount) RecentFiles.RemoveAt(App.RecentCount); while (RecentFiles.Count > App.RecentCount) RecentFiles.RemoveAt(App.RecentCount);
@@ -473,10 +486,16 @@ namespace mpvnet
return; return;
} }
if (m.Msg == TaskbarButtonCreatedMessage)
{
Taskbar = new Taskbar(Handle);
ProgressTimer.Start();
}
base.WndProc(ref m); base.WndProc(ref m);
} }
void Timer_Tick(object sender, EventArgs e) void CursorTimer_Tick(object sender, EventArgs e)
{ {
if (CursorHelp.IsPosDifferent(LastCursorPosChanged)) if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
{ {
@@ -490,6 +509,14 @@ namespace mpvnet
CursorHelp.Hide(); CursorHelp.Hide();
} }
private void ProgressTimer_Tick(object sender, EventArgs e) => UpdateProgressBar();
void UpdateProgressBar()
{
if (mp.TaskbarProgress)
Taskbar.SetValue(mp.get_property_number("time-pos"), mp.Duration.TotalSeconds);
}
void PropChangeOnTop(bool value) => BeginInvoke(new Action(() => TopMost = value)); void PropChangeOnTop(bool value) => BeginInvoke(new Action(() => TopMost = value));
void PropChangeAid(string value) => mp.Aid = value; void PropChangeAid(string value) => mp.Aid = value;
@@ -514,6 +541,17 @@ namespace mpvnet
})); }));
} }
void PropChangePause(bool enabled)
{
if (Taskbar != null)
{
if (enabled)
Taskbar.SetState(TaskbarStates.Paused);
else
Taskbar.SetState(TaskbarStates.Normal);
}
}
protected override void OnLoad(EventArgs e) protected override void OnLoad(EventArgs e)
{ {
base.OnLoad(e); base.OnLoad(e);

View File

@@ -117,9 +117,12 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="Timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="CursorTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>30, 12</value> <value>30, 12</value>
</metadata> </metadata>
<metadata name="ProgressTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>321, 12</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>

View File

@@ -153,6 +153,7 @@
<Compile Include="DynamicGUI\Tommy.cs" /> <Compile Include="DynamicGUI\Tommy.cs" />
<Compile Include="Misc\ExtensionMethods.cs" /> <Compile Include="Misc\ExtensionMethods.cs" />
<Compile Include="Native\MediaInfo.cs" /> <Compile Include="Native\MediaInfo.cs" />
<Compile Include="Native\Taskbar.cs" />
<Compile Include="WinForms\Menu.cs"> <Compile Include="WinForms\Menu.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>

View File

@@ -61,12 +61,12 @@ namespace mpvnet
public static List<KeyValuePair<string, Action<string>>> StringPropChangeActions { get; set; } = new List<KeyValuePair<string, Action<string>>>(); public static List<KeyValuePair<string, Action<string>>> StringPropChangeActions { get; set; } = new List<KeyValuePair<string, Action<string>>>();
public static List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>(); public static List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
public static List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>(); public static List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>();
public static IntPtr Handle { get; set; } public static IntPtr Handle { get; set; }
public static IntPtr WindowHandle { get; set; } public static IntPtr WindowHandle { get; set; }
public static Extension Extension { get; set; } public static Extension Extension { get; set; }
public static List<PythonScript> PythonScripts { get; set; } = new List<PythonScript>(); public static List<PythonScript> PythonScripts { get; set; } = new List<PythonScript>();
public static Size VideoSize { get; set; } public static Size VideoSize { get; set; }
public static TimeSpan Duration;
public static AutoResetEvent ShutdownAutoResetEvent { get; set; } = new AutoResetEvent(false); public static AutoResetEvent ShutdownAutoResetEvent { get; set; } = new AutoResetEvent(false);
public static AutoResetEvent VideoSizeAutoResetEvent { get; set; } = new AutoResetEvent(false); public static AutoResetEvent VideoSizeAutoResetEvent { get; set; } = new AutoResetEvent(false);
@@ -81,7 +81,8 @@ namespace mpvnet
public static bool IsQuitNeeded { set; get; } = true; public static bool IsQuitNeeded { set; get; } = true;
public static bool Fullscreen { get; set; } public static bool Fullscreen { get; set; }
public static bool Border { get; set; } = true; public static bool Border { get; set; } = true;
public static bool TaskbarProgress { get; set; } = true;
public static int Screen { get; set; } = -1; public static int Screen { get; set; } = -1;
public static int Edition { get; set; } public static int Edition { get; set; }
@@ -136,6 +137,7 @@ namespace mpvnet
case "fs": case "fs":
case "fullscreen": Fullscreen = value == "yes"; break; case "fullscreen": Fullscreen = value == "yes"; break;
case "border": Border = value == "yes"; break; case "border": Border = value == "yes"; break;
case "taskbar-progress": TaskbarProgress = value == "yes"; break;
case "screen": Screen = Convert.ToInt32(value); break; case "screen": Screen = Convert.ToInt32(value); break;
case "gpu-api": GPUAPI = value; break; case "gpu-api": GPUAPI = value; break;
} }
@@ -317,7 +319,7 @@ namespace mpvnet
break; break;
case mpv_event_id.MPV_EVENT_FILE_LOADED: case mpv_event_id.MPV_EVENT_FILE_LOADED:
HideLogo(); HideLogo();
FileLoaded?.Invoke(); Duration = TimeSpan.FromSeconds(get_property_number("duration"));
Size vidSize = new Size(get_property_int("width"), get_property_int("height")); Size vidSize = new Size(get_property_int("width"), get_property_int("height"));
if (vidSize.Width == 0 || vidSize.Height == 0) if (vidSize.Width == 0 || vidSize.Height == 0)
vidSize = new Size(1, 1); vidSize = new Size(1, 1);
@@ -329,6 +331,7 @@ namespace mpvnet
VideoSizeAutoResetEvent.Set(); VideoSizeAutoResetEvent.Set();
Task.Run(new Action(() => ReadMetaData())); Task.Run(new Action(() => ReadMetaData()));
WriteHistory(get_property_string("path")); WriteHistory(get_property_string("path"));
FileLoaded?.Invoke();
break; break;
case mpv_event_id.MPV_EVENT_TRACKS_CHANGED: case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
TracksChanged?.Invoke(); TracksChanged?.Invoke();