From 2af84941ca6992275dd2e59628dbbd93535cbda0 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Wed, 17 Jul 2019 18:18:33 +0200 Subject: [PATCH] color theme related improvements --- Changelog.md | 8 +++- README.md | 2 +- addons/RatingAddon/RatingAddon.cs | 23 +++++---- mpv.net/DynamicGUI/StringSettingControl.xaml | 2 +- .../DynamicGUI/StringSettingControl.xaml.cs | 12 +++-- mpv.net/Misc/Misc.cs | 13 +++-- mpv.net/Properties/AssemblyInfo.cs | 4 +- mpv.net/Resources/mpvNetConfToml.txt | 16 ++++++- mpv.net/WPF/AboutWindow.xaml.cs | 2 +- mpv.net/WPF/LearnWindow.xaml.cs | 7 ++- mpv.net/WPF/WPF.cs | 44 +++++++++++++++-- mpv.net/WinForms/MainForm.cs | 14 ++++-- mpv.net/WinForms/Menu.cs | 20 ++------ mpv.net/mpv/mp.cs | 5 +- setup.ps1 | 48 ------------------- 15 files changed, 121 insertions(+), 99 deletions(-) delete mode 100644 setup.ps1 diff --git a/Changelog.md b/Changelog.md index 1f0580c..19c9657 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,12 @@ -### 4.7.4 +### 4.7.6.1 - fix for mouse button back/forward causing freeze +- fix for WM_APPCOMMAND not working but crashing in input editor learn window +- on Win 7 the theme color was hardcoded to DarkSlateGrey because + WPF was returning a bad color on Win 7, this was fixed by reading + the theme color from the Registry on Win 7 +- new option color-dark was added to overwrite the OS theme color used in dark mode +- new option color-light was added to overwrite the OS theme color used in non dark mode ### 4.7.3 diff --git a/README.md b/README.md index 6221225..6daa3ee 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Table of contents - Very high degree of mpv compatibility, almost all mpv features are available - Great usability due to everything in the application being searchable -- Open source built with modern tools and applications +- Open source built with modern tools - Customizable context menu defined in the same file as the key bindings ([Screenshot](#context-menu-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt)) - Searchable config dialog ([Screenshot](#config-editor-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt)) - Searchable input (key/mouse) binding editor ([Screenshot](#input-editor-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt)) diff --git a/addons/RatingAddon/RatingAddon.cs b/addons/RatingAddon/RatingAddon.cs index 27ebfc1..87b6a55 100644 --- a/addons/RatingAddon/RatingAddon.cs +++ b/addons/RatingAddon/RatingAddon.cs @@ -1,5 +1,5 @@ -// this addon writes a rating to the filename of the current video, -// the input.conf defaults contain key bindings for this addon +// this addon writes a rating to the filename of rated videos when mpv.net +// shuts down. The input.conf defaults contain key bindings for this addon. using System; using System.ComponentModel.Composition; @@ -7,30 +7,36 @@ using System.Collections.Generic; using System.IO; using mpvnet; +using System.Diagnostics; +// the assembly name must end with 'Addon' namespace RatingAddon { [Export(typeof(IAddon))] public class RatingAddon : IAddon { + // dictionory to store the filename and the rating Dictionary Dic = new Dictionary(); - public RatingAddon() + public RatingAddon() // plugin initialization { mp.ClientMessage += ClientMessage; //handles keys defined in input.conf - mp.Shutdown += Shutdown; + mp.Shutdown += Shutdown; // handles MPV_EVENT_SHUTDOWN } + // handles MPV_EVENT_SHUTDOWN void Shutdown() { + if (App.DebugMode) Trace.WriteLine("aaa"); + foreach (var i in Dic) { string filepath = i.Key; int rating = i.Value; - + if (App.DebugMode) Trace.WriteLine("bbb"); if (String.IsNullOrEmpty(filepath) || ! File.Exists(filepath)) return; - + if (App.DebugMode) Trace.WriteLine("ccc"); string basename = Path.GetFileNameWithoutExtension(filepath); for (int x = 0; x < 6; x++) @@ -39,11 +45,12 @@ namespace RatingAddon basename += $" ({rating}stars)"; string newPath = Path.Combine(Path.GetDirectoryName(filepath), basename + Path.GetExtension(filepath)); - + if (App.DebugMode) Trace.WriteLine("ddd"); if (filepath.ToLower() != newPath.ToLower()) File.Move(filepath, newPath); - + if (App.DebugMode) Trace.WriteLine("eee"); File.SetLastWriteTime(newPath, DateTime.Now); + if (App.DebugMode) Trace.WriteLine("fff"); } } diff --git a/mpv.net/DynamicGUI/StringSettingControl.xaml b/mpv.net/DynamicGUI/StringSettingControl.xaml index 2f122bc..9b43069 100644 --- a/mpv.net/DynamicGUI/StringSettingControl.xaml +++ b/mpv.net/DynamicGUI/StringSettingControl.xaml @@ -15,7 +15,7 @@ - + diff --git a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs index 00b4c86..24cbe4a 100644 --- a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs +++ b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Globalization; using System.Windows; using System.Windows.Controls; @@ -64,11 +65,14 @@ namespace DynamicGUI { d.FullOpen = true; try { - Color col = GetColor(ValueTextBox.Text); - d.Color = System.Drawing.Color.FromArgb(col.A, col.R, col.G, col.B); - } catch { } + if (!string.IsNullOrEmpty(ValueTextBox.Text)) + { + Color col = GetColor(ValueTextBox.Text); + d.Color = System.Drawing.Color.FromArgb(col.A, col.R, col.G, col.B); + } + } catch {} if (d.ShowDialog() == WinForms.DialogResult.OK) - ValueTextBox.Text = System.Drawing.ColorTranslator.ToHtml(d.Color); + ValueTextBox.Text = "#" + d.Color.ToArgb().ToString("X8"); } break; } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 5d8685d..2d624a7 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -22,6 +22,8 @@ namespace mpvnet public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; public static string DarkMode { get; set; } = "always"; public static string ProcessInstance { get; set; } = "single"; + public static string DarkColor { get; set; } + public static string LightColor { get; set; } public static string[] VideoTypes { get; } = "mkv mp4 mpg avi mov webm vob wmv flv avs 264 h264 asf webm mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts m4v".Split(' '); public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' '); @@ -31,9 +33,9 @@ namespace mpvnet public static bool RememberHeight { get; set; } = true; public static bool RememberPosition { get; set; } - public static bool DebugMode { get; set; } = false; + public static bool DebugMode { get; set; } - public static bool IsDarkMode { + public static bool IsDarkMode { get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always"; } @@ -49,12 +51,11 @@ namespace mpvnet { try { - string filePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\mpvnet-debug.log"; + string filePath = mp.ConfFolder + "\\mpvnet-debug.log"; if (File.Exists(filePath)) File.Delete(filePath); Trace.Listeners.Clear(); Trace.Listeners.Add(new TextWriterTraceListener(filePath)); - foreach (Screen screen in Screen.AllScreens) - Trace.WriteLine(screen); + Trace.AutoFlush = true; } catch (Exception e) { @@ -94,6 +95,8 @@ namespace mpvnet case "process-instance": ProcessInstance = value; break; case "dark-mode": DarkMode = value; break; case "debug-mode": DebugMode = value == "yes"; break; + case "dark-color": DarkColor = value.Trim('\'', '"'); break; + case "light-color": LightColor = value.Trim('\'', '"'); break; case "url-whitelist": UrlWhitelist = value.Split(' ', ',', ';'); break; diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs index bed567b..1dac3cf 100644 --- a/mpv.net/Properties/AssemblyInfo.cs +++ b/mpv.net/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.7.4.0")] -[assembly: AssemblyFileVersion("4.7.4.0")] +[assembly: AssemblyVersion("4.7.6.1")] +[assembly: AssemblyFileVersion("4.7.6.1")] diff --git a/mpv.net/Resources/mpvNetConfToml.txt b/mpv.net/Resources/mpvNetConfToml.txt index f79cc4c..503230e 100644 --- a/mpv.net/Resources/mpvNetConfToml.txt +++ b/mpv.net/Resources/mpvNetConfToml.txt @@ -7,6 +7,18 @@ options = [{ name = "always" }, { name = "system" , help = "Available on Windows 10 or higher" }, { name = "never" }] +[[settings]] +name = "dark-color" +type = "color" +filter = "General" +help = "Theme color used in dark-mode. Leave empty to use OS theme." + +[[settings]] +name = "light-color" +type = "color" +filter = "General" +help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme" + [[settings]] name = "url-whitelist" filter = "General" @@ -17,7 +29,7 @@ help = "mpv.net specific whitelist setting to monitor the clipboard for URLs to name = "process-instance" default = "single" filter = "General" -help = "mpv.net specific setting that defines if more then one mpv.net process is allowed.\n\nTip: 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." +help = "mpv.net specific setting that defines if more then one mpv.net process is allowed.\n\nTip: 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 not only works on process startup but in all mpv.net features that open files." options = [{ name = "multi", help = "Create a new process everytime the shell starts mpv.net" }, { name = "single", help = "Force a single process everytime the shell starts mpv.net" }, { name = "queue", help = "Force a single process and add files to playlist" }] @@ -26,7 +38,7 @@ options = [{ name = "multi", help = "Create a new process everytime the shell s name = "debug-mode" default = "no" filter = "General" -help = "mpv.net specific setting that writes debug info to a file located on the desktop." +help = "mpv.net specific debugging setting, enable this only when a developer asks for it." options = [{ name = "yes" }, { name = "no" }] diff --git a/mpv.net/WPF/AboutWindow.xaml.cs b/mpv.net/WPF/AboutWindow.xaml.cs index acc416d..b79c910 100644 --- a/mpv.net/WPF/AboutWindow.xaml.cs +++ b/mpv.net/WPF/AboutWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Input; +using System.Windows.Media; namespace mpvnet { @@ -9,7 +10,6 @@ namespace mpvnet { InitializeComponent(); Version.Text = $"Version {System.Windows.Forms.Application.ProductVersion}"; - Foreground = WPF.WPF.ThemeBrush; } protected override void OnPreviewKeyDown(KeyEventArgs e) => Close(); diff --git a/mpv.net/WPF/LearnWindow.xaml.cs b/mpv.net/WPF/LearnWindow.xaml.cs index a518fc4..dbd72cd 100644 --- a/mpv.net/WPF/LearnWindow.xaml.cs +++ b/mpv.net/WPF/LearnWindow.xaml.cs @@ -187,7 +187,9 @@ namespace mpvnet OnKeyUp(new WF.KeyEventArgs((WF.Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys)); else if (m.Msg == WM_APPCOMMAND) { - switch ((AppCommand)(m.LParam.ToInt32() >> 16)) + var value = (AppCommand)(m.LParam.ToInt64() >> 16 & ~0xf000); + + switch (value) { case AppCommand.MEDIA_CHANNEL_DOWN: SetKey("Channel_Down"); @@ -231,6 +233,9 @@ namespace mpvnet case AppCommand.VolumeMute: SetKey("Mute"); break; + default: + Msg.ShowError($"AppCommand {value} not supported,\nplease contact support."); + break; } } } diff --git a/mpv.net/WPF/WPF.cs b/mpv.net/WPF/WPF.cs index e27677a..6002ca8 100644 --- a/mpv.net/WPF/WPF.cs +++ b/mpv.net/WPF/WPF.cs @@ -1,7 +1,11 @@ using System; +using System.Globalization; using System.Windows; using System.Windows.Media; +using Microsoft.Win32; +using mpvnet; + namespace WPF { public class WPF @@ -22,12 +26,42 @@ namespace WPF } } - public static Brush ThemeBrush { + public static Brush ThemeBrush { get; } = new SolidColorBrush(ThemeColor); + + static bool WasThemeColorSet; + + static Color _ThemeColor; + + public static Color ThemeColor { get { - if (Environment.OSVersion.Version.Major < 10) - return new SolidColorBrush(Colors.DarkSlateGray); - else - return SystemParameters.WindowGlassBrush; + if (!WasThemeColorSet) + { + Color? color = null; + + try { + if (App.IsDarkMode && !string.IsNullOrEmpty(App.DarkColor)) + color = (Color)ColorConverter.ConvertFromString(App.DarkColor); + else if (!App.IsDarkMode && !string.IsNullOrEmpty(App.LightColor)) + color = (Color)ColorConverter.ConvertFromString(App.LightColor); + } catch { } + + if (!color.HasValue) + { + if (Environment.OSVersion.Version.Major < 10) + { + int argb = Convert.ToInt32(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0)); + if (argb == 0) System.Drawing.Color.Blue.ToArgb(); + var c = System.Drawing.Color.FromArgb(argb); + color = Color.FromArgb(c.A, c.R, c.G, c.B); + } + else + color = SystemParameters.WindowGlassColor; + } + + _ThemeColor = color.Value; + WasThemeColorSet = true; + } + return _ThemeColor; } } } diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 0463b7f..cfd3ff0 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; -using System.Threading.Tasks; namespace mpvnet { @@ -47,7 +46,10 @@ namespace mpvnet else RecentFiles = new List(); - if (App.IsDarkMode) ToolStripRendererEx.ColorTheme = Color.Black; + var wpfColor = WPF.WPF.ThemeColor; + Color color = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B); + ToolStripRendererEx.InitColors(color, App.IsDarkMode); + ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; @@ -403,8 +405,6 @@ namespace mpvnet mp.command_string("mouse 1 1"); // osc won't always auto hide break; case 0x319: // WM_APPCOMMAND - case 0x020C: // WM_XBUTTONUP - case 0x020B: // WM_XBUTTONDOWN if (mp.WindowHandle != IntPtr.Zero) Native.PostMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam); break; @@ -567,6 +567,12 @@ namespace mpvnet Native.PostMessage(Handle, 0xA1 /* WM_NCLBUTTONDOWN */, HTCAPTION, IntPtr.Zero); } + if (e.Button == MouseButtons.XButton1) + mp.command_string($"mouse {e.Location.X} {e.Location.Y} 7 single"); + + if (e.Button == MouseButtons.XButton2) + mp.command_string($"mouse {e.Location.X} {e.Location.Y} 8 single"); + if (Width - e.Location.X < 10 && e.Location.Y < 10) mp.commandv("quit"); } diff --git a/mpv.net/WinForms/Menu.cs b/mpv.net/WinForms/Menu.cs index 8fdecbc..c0a34c9 100644 --- a/mpv.net/WinForms/Menu.cs +++ b/mpv.net/WinForms/Menu.cs @@ -131,8 +131,10 @@ public class MenuItem : ToolStripMenuItem public class ToolStripRendererEx : ToolStripSystemRenderer { + public static bool IsDarkMode { get; set; } + public static Color ColorForeground { get; set; } = Color.Black; - public static Color ColorTheme { get; set; } = Color.Empty; + public static Color ColorTheme { get; set; } public static Color ColorChecked { get; set; } public static Color ColorBorder { get; set; } public static Color ColorTop { get; set; } @@ -146,19 +148,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer int TextOffset; - public ToolStripRendererEx() - { - var argb = Convert.ToInt32(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0)); - - if (argb == 0) - argb = Color.LightBlue.ToArgb(); - if (ColorTheme == Color.Empty) - InitColors(Color.FromArgb(argb)); - else - InitColors(ColorTheme); - } - - public static void InitColors(Color c) + public static void InitColors(Color c, bool darkMode) { ColorBorder = HSLColor.Convert(c).ToColorSetLuminosity(100); ColorChecked = HSLColor.Convert(c).ToColorSetLuminosity(160); @@ -166,7 +156,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer ColorBackground = HSLColor.Convert(c).ToColorSetLuminosity(210); ColorTop = HSLColor.Convert(c).ToColorSetLuminosity(240); - if (ColorTheme == Color.Black) + if (darkMode) { ColorBorder = Color.White; ColorBackground = Color.FromArgb(50, 50, 50); diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 3720fee..6cbd2c5 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -213,14 +214,16 @@ namespace mpvnet if (WindowHandle == IntPtr.Zero) WindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null); - // System.Diagnostics.Debug.WriteLine(evt.event_id.ToString()); + // Debug.WriteLine(evt.event_id.ToString()); try { switch (evt.event_id) { case mpv_event_id.MPV_EVENT_SHUTDOWN: + if (App.DebugMode) Trace.WriteLine("before Shutdown.Invoke"); Shutdown?.Invoke(); + if (App.DebugMode) Trace.WriteLine("after Shutdown.Invoke"); WriteHistory(null); ShutdownAutoResetEvent.Set(); return; diff --git a/setup.ps1 b/setup.ps1 deleted file mode 100644 index 898c720..0000000 --- a/setup.ps1 +++ /dev/null @@ -1,48 +0,0 @@ -# exit the script if the exit code is greater than 0 -function CheckExitCode { - if ($LastExitCode -gt 0) { - Write-Host "`nExit code $LastExitCode was returned.`n" -ForegroundColor Red - exit - } -} - -# exit the script if the file don't exist -function CheckFileExist($path) { - if (![IO.File]::Exists($path)) { - Write-Host "`nFile is missing:`n`n$path`n" -ForegroundColor Red - exit - } -} - -$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" -$innoSetup = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" -$sevenZip = "C:\Program Files\7-Zip\7z.exe" - -# exit the script if one of the executables don't exist -CheckFileExist($msbuild); CheckFileExist($innoSetup); CheckFileExist($sevenZip); - -# build the projects using msbuild -& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x64; CheckExitCode -& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x86; CheckExitCode - -# build the setups using inno setup -& $innoSetup /Darch="x64" setup.iss; CheckExitCode -& $innoSetup /Darch="x86" setup.iss; CheckExitCode - -# create the x64 portable archives using 7zip -$scriptDir = Split-Path -Path $PSCommandPath -Parent -$desktopDir = [Environment]::GetFolderPath("Desktop") -$exePath = $scriptDir + "\mpv.net\bin\x64\mpvnet.exe" -$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion -$targetDir = $desktopDir + "\mpv.net-portable-x64-" + $version -Copy-Item $scriptDir\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Management.Automation.xml -Force -& $sevenZip a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"; CheckExitCode -& $sevenZip a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"; CheckExitCode - -# create the x86 portable archives using 7zip -$exePath = $scriptDir + "\mpv.net\bin\x86\mpvnet.exe" -$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion -$targetDir = $desktopDir + "\mpv.net-portable-x86-" + $version -Copy-Item $scriptDir\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml -Force -& $sevenZip a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"; CheckExitCode -& $sevenZip a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"; CheckExitCode \ No newline at end of file