From ad43349a0393890b60ca62c447fa3b0bd2a22fb5 Mon Sep 17 00:00:00 2001 From: FootStark Date: Tue, 22 Mar 2016 01:15:54 +0100 Subject: [PATCH] Use SmallIconSize from SystemInformation in Win-Tray --- .../GUI/Duplicati.GUI.TrayIcon/ImageLoader.cs | 21 +++++++++++++++++-- .../Duplicati.GUI.TrayIcon/WinFormsRunner.cs | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/ImageLoader.cs b/Duplicati/GUI/Duplicati.GUI.TrayIcon/ImageLoader.cs index 175d4b9e7..43bd5beaa 100644 --- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/ImageLoader.cs +++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/ImageLoader.cs @@ -36,7 +36,19 @@ namespace Duplicati.GUI.TrayIcon private static readonly Dictionary BITMAPS = new Dictionary(); private static readonly Dictionary ICONS = new Dictionary(); private static readonly object LOCK = new object(); - + + private static Size m_trayIconSize = Size.Empty; + + /// Set size of icons to return. + public static void SetTrayIconSize(Size useTrayIconSize) + { + lock (LOCK) + { + ICONS.Clear(); + m_trayIconSize = useTrayIconSize; + } + } + private static Bitmap LoadImage(string filename) { Bitmap bmp; @@ -71,7 +83,12 @@ namespace Duplicati.GUI.TrayIcon lock(LOCK) if (!ICONS.TryGetValue(filename, out ico)) - return ICONS[filename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename)); + { + if (!m_trayIconSize.IsEmpty) + return ICONS[filename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename), m_trayIconSize); + else + return ICONS[filename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename)); + } return ICONS[filename]; } diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/WinFormsRunner.cs b/Duplicati/GUI/Duplicati.GUI.TrayIcon/WinFormsRunner.cs index 9dbf57856..8254005ac 100644 --- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/WinFormsRunner.cs +++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/WinFormsRunner.cs @@ -116,6 +116,8 @@ namespace Duplicati.GUI.TrayIcon.Windows WinFormsRunner.Instance = this; + ImageLoader.SetTrayIconSize(System.Windows.Forms.SystemInformation.SmallIconSize); + //We need this ugly hack to get a handle that we can call Invoke on, // and sadly the TrayIcon does not expose one, and forcing the context menu // to create one causes weird "lost clicks"