diff --git a/Eve-O-Preview/Presentation/ThumbnailManager.cs b/Eve-O-Preview/Presentation/ThumbnailManager.cs index 08bb055..b57b91c 100644 --- a/Eve-O-Preview/Presentation/ThumbnailManager.cs +++ b/Eve-O-Preview/Presentation/ThumbnailManager.cs @@ -85,7 +85,7 @@ namespace EveOPreview.UI foreach (KeyValuePair entry in this._thumbnailViews) { entry.Value.Size = size; - entry.Value.Refresh(); + entry.Value.Refresh(false); } this.ThumbnailSizeChanged?.Invoke(size); @@ -139,7 +139,7 @@ namespace EveOPreview.UI } else { - view.Refresh(); + view.Refresh(false); } } @@ -322,9 +322,15 @@ namespace EveOPreview.UI DwmApiNativeMethods.SetForegroundWindow(id); int style = DwmApiNativeMethods.GetWindowLong(id, DwmApiNativeMethods.GWL_STYLE); + // If the window was minimized then its thumbnail should be reset if ((style & DwmApiNativeMethods.WS_MINIMIZE) == DwmApiNativeMethods.WS_MINIMIZE) { DwmApiNativeMethods.ShowWindowAsync(id, DwmApiNativeMethods.SW_SHOWNORMAL); + IThumbnailView view; + if (this._thumbnailViews.TryGetValue(id, out view)) + { + view.Refresh(true); + } } if (this._configuration.EnableClientLayoutTracking) @@ -348,7 +354,7 @@ namespace EveOPreview.UI this.SetThumbnailsSize(view.Size); - view.Refresh(); + view.Refresh(false); } private void ThumbnailViewMoved(IntPtr id) @@ -362,7 +368,7 @@ namespace EveOPreview.UI this._configuration.SetThumbnailLocation(view.Title, this._activeClientTitle, view.Location); - view.Refresh(); + view.Refresh(false); } private bool IsNonClientWindowActive(IntPtr windowHandle) @@ -391,7 +397,7 @@ namespace EveOPreview.UI this.DisableViewEvents(); view.ZoomIn(ViewZoomAnchorConverter.Convert(this._configuration.ThumbnailZoomAnchor), this._configuration.ThumbnailZoomFactor); - view.Refresh(); + view.Refresh(false); this.EnableViewEvents(); } @@ -401,7 +407,7 @@ namespace EveOPreview.UI this.DisableViewEvents(); view.ZoomOut(); - view.Refresh(); + view.Refresh(false); this.EnableViewEvents(); } diff --git a/Eve-O-Preview/Program.cs b/Eve-O-Preview/Program.cs index c36b116..cf7d7e8 100644 --- a/Eve-O-Preview/Program.cs +++ b/Eve-O-Preview/Program.cs @@ -12,7 +12,7 @@ namespace EveOPreview static void Main() { Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(true); + Application.SetCompatibleTextRenderingDefault(false); // TODO Switch to another container that provides signed assemblies IIocContainer container = new LightInjectContainer(); @@ -31,7 +31,7 @@ namespace EveOPreview .RegisterService() .RegisterInstance(new ApplicationConfiguration()); - controller.Run(); + controller.Run(); } } } \ No newline at end of file diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs index f5d0be1..94d32f3 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs @@ -114,7 +114,7 @@ namespace EveOPreview.UI { this.IsActive = false; - this.UnregisterThumbnail(); + this.UnregisterThumbnail(this._thumbnailHandle); this._overlay.Close(); base.Close(); @@ -215,15 +215,18 @@ namespace EveOPreview.UI this.Location = this._baseLocation; } - public new void Refresh() + public void Refresh(bool forceRefresh) { - if (this._isThumbnailSetUp == false) + // To prevent flickering the old broken thumbnail is removed AFTER the new shiny one is created + IntPtr obsoleteThumbnailHanlde = forceRefresh ? this._thumbnailHandle : IntPtr.Zero; + + if ((this._isThumbnailSetUp == false) || forceRefresh) { this.RegisterThumbnail(); } - bool sizeChanged = this._isSizeChanged; - bool locationChanged = this._isPositionChanged; + bool sizeChanged = this._isSizeChanged || forceRefresh; + bool locationChanged = this._isPositionChanged || forceRefresh; if (sizeChanged) { @@ -239,6 +242,11 @@ namespace EveOPreview.UI this._isSizeChanged = false; } + if (obsoleteThumbnailHanlde != IntPtr.Zero) + { + this.UnregisterThumbnail(obsoleteThumbnailHanlde); + } + if (!this.IsOverlayEnabled) { if (this._isOverlayVisible) @@ -320,10 +328,12 @@ namespace EveOPreview.UI // // do smth cool? //} - //if (e.Button == MouseButtons.Middle) - //{ - // // do smth cool? - //} + if (e.Button == MouseButtons.Middle) + { + //// Trigger full thumbnail refresh + //this.UnregisterThumbnail(); + //this.Refresh(); + } } #endregion @@ -343,11 +353,14 @@ namespace EveOPreview.UI this._isThumbnailSetUp = true; } - private void UnregisterThumbnail() + private void UnregisterThumbnail(IntPtr thumbnailHandle) { - if (this._thumbnailHandle != IntPtr.Zero) + try + { + DwmApiNativeMethods.DwmUnregisterThumbnail(thumbnailHandle); + } + catch (ArgumentException) { - DwmApiNativeMethods.DwmUnregisterThumbnail(this._thumbnailHandle); } } diff --git a/Eve-O-Preview/UI/Interface/IThumbnailView.cs b/Eve-O-Preview/UI/Interface/IThumbnailView.cs index 8ce7129..35ae31c 100644 --- a/Eve-O-Preview/UI/Interface/IThumbnailView.cs +++ b/Eve-O-Preview/UI/Interface/IThumbnailView.cs @@ -24,7 +24,7 @@ namespace EveOPreview.UI void ZoomIn(ViewZoomAnchor anchor, int zoomFactor); void ZoomOut(); - void Refresh(); + void Refresh(bool forceRefresh); Action ThumbnailResized { get; set; } Action ThumbnailMoved { get; set; }