From 6bf73ad501e59c55a15592a4f422756bb9093302 Mon Sep 17 00:00:00 2001 From: Anton Kasyanov Date: Mon, 5 Feb 2018 01:32:30 +0200 Subject: [PATCH] Implementing internal message bus --- .../ApplicationBase/LightInjectContainer.cs | 26 +++++- .../Configuration/ConfigurationStorage.cs | 12 +-- ...ilConfig.cs => IThumbnailConfiguration.cs} | 5 +- ...ailConfig.cs => ThumbnailConfiguration.cs} | 16 ++-- Eve-O-Preview/Eve-O-Preview.csproj | 31 ++++--- Eve-O-Preview/Hotkeys/HotkeyHandler.cs | 2 +- .../Hotkeys/HotkeyHandlerNativeMethods.cs | 2 +- .../Mediator/Implementation/Mediator.cs | 90 +++++++++++++++++++ Eve-O-Preview/Mediator/Interface/IMediator.cs | 20 +++++ .../Mediator/Interface/INotification.cs | 10 +++ Eve-O-Preview/Presentation/MainPresenter.cs | 4 +- .../Presentation/ThumbnailManager.cs | 5 +- Eve-O-Preview/Program.cs | 75 +++++----------- .../UI/Implementation/ThumbnailOverlay.cs | 1 + .../UI/Implementation/ThumbnailView.cs | 6 +- .../Implementation/DwmThumbnail.cs | 3 +- .../Implementation/WindowManager.cs | 16 +++- .../Interface/IDwmThumbnail.cs | 2 +- .../Interface/IWindowManager.cs | 5 +- .../Interface/InteropConstants.cs | 2 +- .../Interop/DWM_BLURBEHIND.cs | 2 +- .../Interop/DWM_THUMBNAIL_PROPERTIES.cs | 2 +- .../Interop/DWM_TNP_CONSTANTS.cs | 2 +- .../Interop/DwmApiNativeMethods.cs | 2 +- .../Interop/MARGINS.cs | 2 +- .../{DwmAPI => WindowManager}/Interop/RECT.cs | 2 +- .../Interop/User32NativeMethods.cs | 9 +- 27 files changed, 245 insertions(+), 109 deletions(-) rename Eve-O-Preview/Configuration/{IThumbnailConfig.cs => IThumbnailConfiguration.cs} (90%) rename Eve-O-Preview/Configuration/{ThumbnailConfig.cs => ThumbnailConfiguration.cs} (83%) create mode 100644 Eve-O-Preview/Mediator/Implementation/Mediator.cs create mode 100644 Eve-O-Preview/Mediator/Interface/IMediator.cs create mode 100644 Eve-O-Preview/Mediator/Interface/INotification.cs rename Eve-O-Preview/{DwmAPI => WindowManager}/Implementation/DwmThumbnail.cs (92%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Implementation/WindowManager.cs (76%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interface/IDwmThumbnail.cs (80%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interface/IWindowManager.cs (70%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interface/InteropConstants.cs (96%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/DWM_BLURBEHIND.cs (86%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/DWM_THUMBNAIL_PROPERTIES.cs (83%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/DWM_TNP_CONSTANTS.cs (83%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/DwmApiNativeMethods.cs (93%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/MARGINS.cs (84%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/RECT.cs (82%) rename Eve-O-Preview/{DwmAPI => WindowManager}/Interop/User32NativeMethods.cs (75%) diff --git a/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs b/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs index 73567c9..31f9d6a 100644 --- a/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs +++ b/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs @@ -21,13 +21,35 @@ namespace EveOPreview public void Register() { - this._container.Register(); + if (!typeof(TService).IsInterface) + { + this._container.Register(new PerContainerLifetime()); + return; + } + + foreach (Type implementationType in typeof(TService).Assembly.DefinedTypes) + { + if (!implementationType.IsClass || implementationType.IsAbstract) + { + continue; + } + + if (!typeof(TService).IsAssignableFrom(implementationType)) + { + continue; + } + + this._container.Register(typeof(TService), implementationType, new PerContainerLifetime()); + break; + } + + } public void Register() where TImplementation : TService { - this._container.Register(); + this._container.Register(new PerContainerLifetime()); } public void Register(Expression> factory) diff --git a/Eve-O-Preview/Configuration/ConfigurationStorage.cs b/Eve-O-Preview/Configuration/ConfigurationStorage.cs index f6452db..78fce2f 100644 --- a/Eve-O-Preview/Configuration/ConfigurationStorage.cs +++ b/Eve-O-Preview/Configuration/ConfigurationStorage.cs @@ -8,12 +8,12 @@ namespace EveOPreview.Configuration private const string ConfigurationFileName = "EVE-O Preview.json"; private readonly IAppConfig _appConfig; - private readonly IThumbnailConfig _thumbnailConfig; + private readonly IThumbnailConfiguration _thumbnailConfiguration; - public ConfigurationStorage(IAppConfig appConfig, IThumbnailConfig thumbnailConfig) + public ConfigurationStorage(IAppConfig appConfig, IThumbnailConfiguration thumbnailConfiguration) { this._appConfig = appConfig; - this._thumbnailConfig = thumbnailConfig; + this._thumbnailConfiguration = thumbnailConfiguration; } public void Load() @@ -27,15 +27,15 @@ namespace EveOPreview.Configuration string rawData = File.ReadAllText(filename); - JsonConvert.PopulateObject(rawData, this._thumbnailConfig); + JsonConvert.PopulateObject(rawData, this._thumbnailConfiguration); // Validate data after loading it - this._thumbnailConfig.ApplyRestrictions(); + this._thumbnailConfiguration.ApplyRestrictions(); } public void Save() { - string rawData = JsonConvert.SerializeObject(this._thumbnailConfig, Formatting.Indented); + string rawData = JsonConvert.SerializeObject(this._thumbnailConfiguration, Formatting.Indented); File.WriteAllText(this.GetConfigFileName(), rawData); } diff --git a/Eve-O-Preview/Configuration/IThumbnailConfig.cs b/Eve-O-Preview/Configuration/IThumbnailConfiguration.cs similarity index 90% rename from Eve-O-Preview/Configuration/IThumbnailConfig.cs rename to Eve-O-Preview/Configuration/IThumbnailConfiguration.cs index f3571d7..f5308eb 100644 --- a/Eve-O-Preview/Configuration/IThumbnailConfig.cs +++ b/Eve-O-Preview/Configuration/IThumbnailConfiguration.cs @@ -3,10 +3,7 @@ using System.Windows.Forms; namespace EveOPreview.Configuration { - /// - /// Thumbnails Manager configuration - /// - public interface IThumbnailConfig + public interface IThumbnailConfiguration { bool MinimizeToTray { get; set; } int ThumbnailRefreshPeriod { get; set; } diff --git a/Eve-O-Preview/Configuration/ThumbnailConfig.cs b/Eve-O-Preview/Configuration/ThumbnailConfiguration.cs similarity index 83% rename from Eve-O-Preview/Configuration/ThumbnailConfig.cs rename to Eve-O-Preview/Configuration/ThumbnailConfiguration.cs index 24c71f2..9a268c7 100644 --- a/Eve-O-Preview/Configuration/ThumbnailConfig.cs +++ b/Eve-O-Preview/Configuration/ThumbnailConfiguration.cs @@ -5,9 +5,9 @@ using Newtonsoft.Json; namespace EveOPreview.Configuration { - class ThumbnailConfig : IThumbnailConfig + class ThumbnailConfiguration : IThumbnailConfiguration { - public ThumbnailConfig() + public ThumbnailConfiguration() { this.MinimizeToTray = false; this.ThumbnailRefreshPeriod = 500; @@ -173,12 +173,12 @@ namespace EveOPreview.Configuration /// public void ApplyRestrictions() { - this.ThumbnailRefreshPeriod = ThumbnailConfig.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000); - this.ThumbnailSize = new Size(ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width), - ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height)); - this.ThumbnailOpacity = ThumbnailConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00; - this.ThumbnailZoomFactor = ThumbnailConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10); - this.ActiveClientHighlightThickness = ThumbnailConfig.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 6); + this.ThumbnailRefreshPeriod = ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000); + this.ThumbnailSize = new Size(ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width), + ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height)); + this.ThumbnailOpacity = ThumbnailConfiguration.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00; + this.ThumbnailZoomFactor = ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10); + this.ActiveClientHighlightThickness = ThumbnailConfiguration.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 6); } private static int ApplyRestrictions(int value, int minimum, int maximum) diff --git a/Eve-O-Preview/Eve-O-Preview.csproj b/Eve-O-Preview/Eve-O-Preview.csproj index ffa7348..1532924 100644 --- a/Eve-O-Preview/Eve-O-Preview.csproj +++ b/Eve-O-Preview/Eve-O-Preview.csproj @@ -108,21 +108,24 @@ - + - - - - - - - - - + + + + + + + + + - - + + + + + @@ -135,7 +138,7 @@ - + @@ -183,7 +186,7 @@ ThumbnailView.cs - + diff --git a/Eve-O-Preview/Hotkeys/HotkeyHandler.cs b/Eve-O-Preview/Hotkeys/HotkeyHandler.cs index 8e12b54..86c705a 100644 --- a/Eve-O-Preview/Hotkeys/HotkeyHandler.cs +++ b/Eve-O-Preview/Hotkeys/HotkeyHandler.cs @@ -2,7 +2,7 @@ using System; using System.Windows.Forms; using System.ComponentModel; -namespace EveOPreview.UI +namespace EveOPreview.UI.Hotkeys { class HotkeyHandler : IMessageFilter, IDisposable { diff --git a/Eve-O-Preview/Hotkeys/HotkeyHandlerNativeMethods.cs b/Eve-O-Preview/Hotkeys/HotkeyHandlerNativeMethods.cs index 4d15506..f241316 100644 --- a/Eve-O-Preview/Hotkeys/HotkeyHandlerNativeMethods.cs +++ b/Eve-O-Preview/Hotkeys/HotkeyHandlerNativeMethods.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace EveOPreview.UI +namespace EveOPreview.UI.Hotkeys { static class HotkeyHandlerNativeMethods { diff --git a/Eve-O-Preview/Mediator/Implementation/Mediator.cs b/Eve-O-Preview/Mediator/Implementation/Mediator.cs new file mode 100644 index 0000000..fd841ea --- /dev/null +++ b/Eve-O-Preview/Mediator/Implementation/Mediator.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; + +namespace EveOPreview.Mediator.Implementation +{ + class Mediator : IMediator + { + #region Private fields + private readonly ReaderWriterLockSlim _lock; + private readonly IDictionary _handlers; + #endregion + + public Mediator() + { + this._lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); + this._handlers = new Dictionary(); + } + + public void Subscribe(Action handler) + where T : INotification + { + this._lock.EnterWriteLock(); + try + { + IList handlers; + if (!this._handlers.TryGetValue(typeof(T), out handlers)) + { + handlers = new List>(); + this._handlers.Add(typeof(T), handlers); + } + + handlers.Add(handler); + } + finally + { + this._lock.ExitWriteLock(); + } + } + + public void Unsubscribe(Action handler) + where T : INotification + { + this._lock.EnterWriteLock(); + try + { + this._handlers.TryGetValue(typeof(T), out var handlers); + handlers?.Remove(handler); + } + finally + { + this._lock.ExitWriteLock(); + } + } + + public void Publish(T notification) + where T : INotification + { + // Empty notifications are silently swallowed + if (notification.IsEmpty()) + { + return; + } + + IList> handlers; + this._lock.EnterReadLock(); + try + { + if (!this._handlers.TryGetValue(typeof(T), out var untypedHandlers)) + { + return; + } + + // Clone the list to minimize lock time + // and possible deadlock issues (f.e. one of subscribers could raise an event ar add/remove subsctibers etc) + handlers = new List>((IList>)untypedHandlers); + } + finally + { + this._lock.ExitReadLock(); + } + + foreach (var handler in handlers) + { + handler.Invoke(notification); + } + } + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Mediator/Interface/IMediator.cs b/Eve-O-Preview/Mediator/Interface/IMediator.cs new file mode 100644 index 0000000..bba6d3d --- /dev/null +++ b/Eve-O-Preview/Mediator/Interface/IMediator.cs @@ -0,0 +1,20 @@ +using System; + +namespace EveOPreview.Mediator +{ + /// + /// Message dispatcher. + /// Consider this as a very simple message bus + /// + public interface IMediator + { + void Subscribe(Action handler) + where T : INotification; + + void Unsubscribe(Action handler) + where T : INotification; + + void Publish(T notification) + where T : INotification; + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Mediator/Interface/INotification.cs b/Eve-O-Preview/Mediator/Interface/INotification.cs new file mode 100644 index 0000000..3f1f274 --- /dev/null +++ b/Eve-O-Preview/Mediator/Interface/INotification.cs @@ -0,0 +1,10 @@ +namespace EveOPreview.Mediator +{ + /// + /// Base class for all Mediator notifications + /// + public interface INotification + { + bool IsEmpty(); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Presentation/MainPresenter.cs b/Eve-O-Preview/Presentation/MainPresenter.cs index c83bb40..0d3a98b 100644 --- a/Eve-O-Preview/Presentation/MainPresenter.cs +++ b/Eve-O-Preview/Presentation/MainPresenter.cs @@ -13,7 +13,7 @@ namespace EveOPreview.UI #endregion #region Private fields - private readonly IThumbnailConfig _configuration; + private readonly IThumbnailConfiguration _configuration; private readonly IConfigurationStorage _configurationStorage; private readonly IThumbnailDescriptionViewFactory _thumbnailDescriptionViewFactory; private readonly IDictionary _thumbnailDescriptionViews; @@ -22,7 +22,7 @@ namespace EveOPreview.UI private bool _exitApplication; #endregion - public MainPresenter(IApplicationController controller, IMainView view, IThumbnailConfig configuration, IConfigurationStorage configurationStorage, + public MainPresenter(IApplicationController controller, IMainView view, IThumbnailConfiguration configuration, IConfigurationStorage configurationStorage, IThumbnailManager thumbnailManager, IThumbnailDescriptionViewFactory thumbnailDescriptionViewFactory) : base(controller, view) { diff --git a/Eve-O-Preview/Presentation/ThumbnailManager.cs b/Eve-O-Preview/Presentation/ThumbnailManager.cs index bebbc94..0f8cb9a 100644 --- a/Eve-O-Preview/Presentation/ThumbnailManager.cs +++ b/Eve-O-Preview/Presentation/ThumbnailManager.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Drawing; using System.Windows.Threading; using EveOPreview.Configuration; +using EveOPreview.WindowManager; namespace EveOPreview.UI { @@ -19,7 +20,7 @@ namespace EveOPreview.UI #region Private fields private readonly IWindowManager _windowManager; - private readonly IThumbnailConfig _configuration; + private readonly IThumbnailConfiguration _configuration; private readonly DispatcherTimer _thumbnailUpdateTimer; private readonly IThumbnailViewFactory _thumbnailViewFactory; private readonly Dictionary _thumbnailViews; @@ -31,7 +32,7 @@ namespace EveOPreview.UI private bool _isHoverEffectActive; #endregion - public ThumbnailManager(IWindowManager windowManager, IThumbnailConfig configuration, IThumbnailViewFactory factory) + public ThumbnailManager(IWindowManager windowManager, IThumbnailConfiguration configuration, IThumbnailViewFactory factory) { this._windowManager = windowManager; this._configuration = configuration; diff --git a/Eve-O-Preview/Program.cs b/Eve-O-Preview/Program.cs index d3ef4fd..1ab2408 100644 --- a/Eve-O-Preview/Program.cs +++ b/Eve-O-Preview/Program.cs @@ -2,18 +2,19 @@ using System; using System.Threading; using System.Windows.Forms; using EveOPreview.Configuration; +using EveOPreview.Mediator; using EveOPreview.UI; +using EveOPreview.WindowManager; namespace EveOPreview { static class Program { private static string MutexName = "EVE-O Preview Single Instance Mutex"; - private static string ConfigParameterName = "--config:"; /// The main entry point for the application. [STAThread] - static void Main(string[] args) + static void Main() { // The very usual Mutex-based single-instance screening // 'token' variable is used to store reference to the instance Mutex @@ -30,44 +31,12 @@ namespace EveOPreview ExceptionHandler handler = new ExceptionHandler(); handler.SetupExceptionHandlers(); - Program.InitializeWinFormsGui(); - IApplicationController controller = Program.InitializeApplicationController(); - Program.SetupApplicationConttroller(controller, Program.GetCustomConfigFile(args)); + Program.InitializeWinForms(); controller.Run(); } - private static string GetCustomConfigFile(string[] args) - { - // Parse startup parameters - // Simple approach is used because something like NParams would be an overkill here - string configFile = null; - foreach (string arg in args) - { - if ((arg.Length <= Program.ConfigParameterName.Length) || !arg.StartsWith(Program.ConfigParameterName, StringComparison.Ordinal)) - { - continue; - } - - configFile = arg.Substring(Program.ConfigParameterName.Length); - break; - } - - if (string.IsNullOrEmpty(configFile)) - { - return ""; - } - - // One more check to drop trailing " - if ((configFile.Length > 3) && (configFile[0] == '"') && (configFile[configFile.Length - 1] == '"')) - { - configFile = configFile.Substring(1, configFile.Length - 2); - } - - return configFile; - } - private static object GetInstanceToken() { // The code might look overcomplicated here for a single Mutex operation @@ -92,7 +61,7 @@ namespace EveOPreview } } - private static void InitializeWinFormsGui() + private static void InitializeWinForms() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -102,28 +71,30 @@ namespace EveOPreview { IIocContainer container = new LightInjectContainer(); + // Singleton registration is used for services + // Low-level services + container.Register(); + container.Register(); + + // Configuration services + container.Register(); + container.Register(); + container.Register(); + + // Application services + container.Register(); + container.Register(); + container.Register(); + + IApplicationController controller = new ApplicationController(container); + // UI classes - IApplicationController controller = new ApplicationController(container) - .RegisterView() + controller.RegisterView() .RegisterView() .RegisterView() .RegisterInstance(new ApplicationContext()); - // Application services - controller.RegisterService() - .RegisterService() - .RegisterService() - .RegisterService() - .RegisterService() - .RegisterInstance(new AppConfig()) - .RegisterInstance(new ThumbnailConfig()); - return controller; } - - private static void SetupApplicationConttroller(IApplicationController controller, string configFile) - { - controller.Create().ConfigFileName = configFile; - } } } \ No newline at end of file diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs b/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs index 71c0dfe..d0ac1f0 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using EveOPreview.WindowManager; namespace EveOPreview.UI { diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs index 33ef18d..cdc0e25 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs @@ -2,7 +2,8 @@ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; -using EveOPreview.DwmAPI; +using EveOPreview.UI.Hotkeys; +using EveOPreview.WindowManager; namespace EveOPreview.UI { @@ -475,8 +476,7 @@ namespace EveOPreview.UI #region Thumbnail management private void RegisterThumbnail() { - this._thumbnail = new DwmThumbnail(this._windowManager); - this._thumbnail.Register(this.Handle, this.Id); + this._thumbnail = this._windowManager.RegisterThumbnail(this.Handle, this.Id); } private void UpdateThumbnail() diff --git a/Eve-O-Preview/DwmAPI/Implementation/DwmThumbnail.cs b/Eve-O-Preview/WindowManager/Implementation/DwmThumbnail.cs similarity index 92% rename from Eve-O-Preview/DwmAPI/Implementation/DwmThumbnail.cs rename to Eve-O-Preview/WindowManager/Implementation/DwmThumbnail.cs index 4a52091..eff4bee 100644 --- a/Eve-O-Preview/DwmAPI/Implementation/DwmThumbnail.cs +++ b/Eve-O-Preview/WindowManager/Implementation/DwmThumbnail.cs @@ -1,7 +1,6 @@ using System; -using EveOPreview.DwmInterop; -namespace EveOPreview.DwmAPI +namespace EveOPreview.WindowManager.Implementation { class DwmThumbnail : IDwmThumbnail { diff --git a/Eve-O-Preview/DwmAPI/Implementation/WindowManager.cs b/Eve-O-Preview/WindowManager/Implementation/WindowManager.cs similarity index 76% rename from Eve-O-Preview/DwmAPI/Implementation/WindowManager.cs rename to Eve-O-Preview/WindowManager/Implementation/WindowManager.cs index a257299..c4dd22b 100644 --- a/Eve-O-Preview/DwmAPI/Implementation/WindowManager.cs +++ b/Eve-O-Preview/WindowManager/Implementation/WindowManager.cs @@ -1,7 +1,6 @@ using System; -using EveOPreview.DwmInterop; -namespace EveOPreview.DwmAPI +namespace EveOPreview.WindowManager.Implementation { class WindowManager : IWindowManager { @@ -48,5 +47,18 @@ namespace EveOPreview.DwmAPI right = windowRectangle.Right; bottom = windowRectangle.Bottom; } + + public bool IsWindowMinimized(IntPtr handle) + { + return User32NativeMethods.IsIconic(handle); + } + + public IDwmThumbnail RegisterThumbnail(IntPtr destination, IntPtr source) + { + IDwmThumbnail thumbnail = new DwmThumbnail(this); + thumbnail.Register(destination, source); + + return thumbnail; + } } } \ No newline at end of file diff --git a/Eve-O-Preview/DwmAPI/Interface/IDwmThumbnail.cs b/Eve-O-Preview/WindowManager/Interface/IDwmThumbnail.cs similarity index 80% rename from Eve-O-Preview/DwmAPI/Interface/IDwmThumbnail.cs rename to Eve-O-Preview/WindowManager/Interface/IDwmThumbnail.cs index 395e525..3840a7e 100644 --- a/Eve-O-Preview/DwmAPI/Interface/IDwmThumbnail.cs +++ b/Eve-O-Preview/WindowManager/Interface/IDwmThumbnail.cs @@ -1,6 +1,6 @@ using System; -namespace EveOPreview +namespace EveOPreview.WindowManager { public interface IDwmThumbnail { diff --git a/Eve-O-Preview/DwmAPI/Interface/IWindowManager.cs b/Eve-O-Preview/WindowManager/Interface/IWindowManager.cs similarity index 70% rename from Eve-O-Preview/DwmAPI/Interface/IWindowManager.cs rename to Eve-O-Preview/WindowManager/Interface/IWindowManager.cs index f78f013..522bf72 100644 --- a/Eve-O-Preview/DwmAPI/Interface/IWindowManager.cs +++ b/Eve-O-Preview/WindowManager/Interface/IWindowManager.cs @@ -1,6 +1,6 @@ using System; -namespace EveOPreview +namespace EveOPreview.WindowManager { public interface IWindowManager { @@ -13,5 +13,8 @@ namespace EveOPreview void MoveWindow(IntPtr handle, int left, int top, int width, int height); void GetWindowCoordinates(IntPtr handle, out int left, out int top, out int right, out int bottom); + bool IsWindowMinimized(IntPtr handle); + + IDwmThumbnail RegisterThumbnail(IntPtr destination, IntPtr source); } } \ No newline at end of file diff --git a/Eve-O-Preview/DwmAPI/Interface/InteropConstants.cs b/Eve-O-Preview/WindowManager/Interface/InteropConstants.cs similarity index 96% rename from Eve-O-Preview/DwmAPI/Interface/InteropConstants.cs rename to Eve-O-Preview/WindowManager/Interface/InteropConstants.cs index 218f8eb..814975c 100644 --- a/Eve-O-Preview/DwmAPI/Interface/InteropConstants.cs +++ b/Eve-O-Preview/WindowManager/Interface/InteropConstants.cs @@ -1,6 +1,6 @@ using System; -namespace EveOPreview +namespace EveOPreview.WindowManager { public static class InteropConstants { diff --git a/Eve-O-Preview/DwmAPI/Interop/DWM_BLURBEHIND.cs b/Eve-O-Preview/WindowManager/Interop/DWM_BLURBEHIND.cs similarity index 86% rename from Eve-O-Preview/DwmAPI/Interop/DWM_BLURBEHIND.cs rename to Eve-O-Preview/WindowManager/Interop/DWM_BLURBEHIND.cs index 31e2a75..ff2c717 100644 --- a/Eve-O-Preview/DwmAPI/Interop/DWM_BLURBEHIND.cs +++ b/Eve-O-Preview/WindowManager/Interop/DWM_BLURBEHIND.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { [StructLayout(LayoutKind.Sequential)] class DWM_BLURBEHIND diff --git a/Eve-O-Preview/DwmAPI/Interop/DWM_THUMBNAIL_PROPERTIES.cs b/Eve-O-Preview/WindowManager/Interop/DWM_THUMBNAIL_PROPERTIES.cs similarity index 83% rename from Eve-O-Preview/DwmAPI/Interop/DWM_THUMBNAIL_PROPERTIES.cs rename to Eve-O-Preview/WindowManager/Interop/DWM_THUMBNAIL_PROPERTIES.cs index cef7946..a181020 100644 --- a/Eve-O-Preview/DwmAPI/Interop/DWM_THUMBNAIL_PROPERTIES.cs +++ b/Eve-O-Preview/WindowManager/Interop/DWM_THUMBNAIL_PROPERTIES.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { [StructLayout(LayoutKind.Sequential)] class DWM_THUMBNAIL_PROPERTIES diff --git a/Eve-O-Preview/DwmAPI/Interop/DWM_TNP_CONSTANTS.cs b/Eve-O-Preview/WindowManager/Interop/DWM_TNP_CONSTANTS.cs similarity index 83% rename from Eve-O-Preview/DwmAPI/Interop/DWM_TNP_CONSTANTS.cs rename to Eve-O-Preview/WindowManager/Interop/DWM_TNP_CONSTANTS.cs index da19f2f..110744b 100644 --- a/Eve-O-Preview/DwmAPI/Interop/DWM_TNP_CONSTANTS.cs +++ b/Eve-O-Preview/WindowManager/Interop/DWM_TNP_CONSTANTS.cs @@ -1,4 +1,4 @@ -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { static class DWM_TNP_CONSTANTS { diff --git a/Eve-O-Preview/DwmAPI/Interop/DwmApiNativeMethods.cs b/Eve-O-Preview/WindowManager/Interop/DwmApiNativeMethods.cs similarity index 93% rename from Eve-O-Preview/DwmAPI/Interop/DwmApiNativeMethods.cs rename to Eve-O-Preview/WindowManager/Interop/DwmApiNativeMethods.cs index 639ce2a..2398f3c 100644 --- a/Eve-O-Preview/DwmAPI/Interop/DwmApiNativeMethods.cs +++ b/Eve-O-Preview/WindowManager/Interop/DwmApiNativeMethods.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using System.Drawing; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { static class DwmApiNativeMethods { diff --git a/Eve-O-Preview/DwmAPI/Interop/MARGINS.cs b/Eve-O-Preview/WindowManager/Interop/MARGINS.cs similarity index 84% rename from Eve-O-Preview/DwmAPI/Interop/MARGINS.cs rename to Eve-O-Preview/WindowManager/Interop/MARGINS.cs index e9fbb09..61b4b01 100644 --- a/Eve-O-Preview/DwmAPI/Interop/MARGINS.cs +++ b/Eve-O-Preview/WindowManager/Interop/MARGINS.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { [StructLayout(LayoutKind.Sequential)] class MARGINS diff --git a/Eve-O-Preview/DwmAPI/Interop/RECT.cs b/Eve-O-Preview/WindowManager/Interop/RECT.cs similarity index 82% rename from Eve-O-Preview/DwmAPI/Interop/RECT.cs rename to Eve-O-Preview/WindowManager/Interop/RECT.cs index 306c40e..a21a4e2 100644 --- a/Eve-O-Preview/DwmAPI/Interop/RECT.cs +++ b/Eve-O-Preview/WindowManager/Interop/RECT.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { [StructLayout(LayoutKind.Sequential)] struct RECT diff --git a/Eve-O-Preview/DwmAPI/Interop/User32NativeMethods.cs b/Eve-O-Preview/WindowManager/Interop/User32NativeMethods.cs similarity index 75% rename from Eve-O-Preview/DwmAPI/Interop/User32NativeMethods.cs rename to Eve-O-Preview/WindowManager/Interop/User32NativeMethods.cs index 8f0fd5a..03c3746 100644 --- a/Eve-O-Preview/DwmAPI/Interop/User32NativeMethods.cs +++ b/Eve-O-Preview/WindowManager/Interop/User32NativeMethods.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace EveOPreview.DwmInterop +namespace EveOPreview.WindowManager.Implementation { static class User32NativeMethods { @@ -28,5 +28,12 @@ namespace EveOPreview.DwmInterop [DllImport("user32.dll")] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsIconic(IntPtr hWnd); + + [DllImport("user32.dll")] + public static extern bool IsZoomed(IntPtr hWnd); } } \ No newline at end of file