From ea2445eeb25f519d77dd0101478a3866ffae9151 Mon Sep 17 00:00:00 2001 From: Anton Kasyanov Date: Mon, 4 Mar 2019 21:37:03 +0200 Subject: [PATCH] 142: Add a mouse action to switch out to the last used external app --- .../Implementation/ThumbnailManager.cs | 33 ++++++++++++++----- .../View/Implementation/ThumbnailView.cs | 15 ++++++--- .../View/Interface/IThumbnailView.cs | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs b/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs index 58a562f..241e91b 100644 --- a/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs +++ b/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs @@ -32,6 +32,7 @@ namespace EveOPreview.Services private readonly Dictionary _thumbnailViews; private (IntPtr Handle, string Title) _activeClient; + private IntPtr _externalApplication; private readonly object _locationChangeNotificationSyncRoot; private (IntPtr Handle, string Title, string ActiveClient, Point Location, int Delay) _enqueuedLocationChangeNotification; @@ -181,6 +182,9 @@ namespace EveOPreview.Services IntPtr foregroundWindowHandle = this._windowManager.GetForegroundWindowHandle(); string foregroundWindowTitle = null; + // Check if the foreground window handle is one of the known handles for client windows or their thumbnails + bool isClientWindow = this.IsClientWindowActive(foregroundWindowHandle); + if (foregroundWindowHandle == this._activeClient.Handle) { foregroundWindowTitle = this._activeClient.Title; @@ -190,6 +194,10 @@ namespace EveOPreview.Services // This code will work only on Alt+Tab switch between clients foregroundWindowTitle = foregroundView.Title; } + else if (!isClientWindow) + { + this._externalApplication = foregroundWindowHandle; + } // No need to minimize EVE clients when switching out to non-EVE window (like thumbnail) if (!string.IsNullOrEmpty(foregroundWindowTitle)) @@ -197,7 +205,7 @@ namespace EveOPreview.Services this.SwitchActiveClient(foregroundWindowHandle, foregroundWindowTitle); } - bool hideAllThumbnails = this._configuration.HideThumbnailsOnLostFocus && !this.IsClientWindowActive(foregroundWindowHandle); + bool hideAllThumbnails = this._configuration.HideThumbnailsOnLostFocus && !isClientWindow; this._refreshCycleCount++; @@ -324,10 +332,10 @@ namespace EveOPreview.Services this._ignoreViewEvents = true; } - private void SwitchActiveClient(IntPtr foregroungClientHandle, string foregroundClientTitle) + private void SwitchActiveClient(IntPtr foregroundClientHandle, string foregroundClientTitle) { // Check if any actions are needed - if (this._activeClient.Handle == foregroungClientHandle) + if (this._activeClient.Handle == foregroundClientHandle) { return; } @@ -338,7 +346,7 @@ namespace EveOPreview.Services this._windowManager.MinimizeWindow(this._activeClient.Handle, false); } - this._activeClient = (foregroungClientHandle, foregroundClientTitle); + this._activeClient = (foregroundClientHandle, foregroundClientTitle); } private void ThumbnailViewFocused(IntPtr id) @@ -398,15 +406,22 @@ namespace EveOPreview.Services }); } - private void ThumbnailDeactivated(IntPtr id) + private void ThumbnailDeactivated(IntPtr id, bool switchOut) { - if (!this._thumbnailViews.TryGetValue(id, out IThumbnailView view)) + if (switchOut) { - return; + this._windowManager.ActivateWindow(this._externalApplication); } + else + { + if (!this._thumbnailViews.TryGetValue(id, out IThumbnailView view)) + { + return; + } - this._windowManager.MinimizeWindow(view.Id, true); - this.RefreshThumbnails(); + this._windowManager.MinimizeWindow(view.Id, true); + this.RefreshThumbnails(); + } } private async void ThumbnailViewResized(IntPtr id) diff --git a/Eve-O-Preview/View/Implementation/ThumbnailView.cs b/Eve-O-Preview/View/Implementation/ThumbnailView.cs index 94b1f72..bc5cf0f 100644 --- a/Eve-O-Preview/View/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/View/Implementation/ThumbnailView.cs @@ -104,7 +104,7 @@ namespace EveOPreview.View public Action ThumbnailActivated { get; set; } - public Action ThumbnailDeactivated { get; set; } + public Action ThumbnailDeactivated { get; set; } public new void Show() { @@ -159,7 +159,7 @@ namespace EveOPreview.View // Overlay opacity settings // Of the thumbnail's opacity is almost full then set the overlay's one to - // full. Otherwise set it to half of the thumnail opacity + // full. Otherwise set it to half of the thumbnail opacity // Opacity value is stored even if the overlay is not displayed atm this._overlay.Opacity = this.Opacity > 0.9 ? 1.0 : 1.0 - (1.0 - this.Opacity) / 2; } @@ -231,7 +231,7 @@ namespace EveOPreview.View // First change size, THEN move the window // Otherwise there is a chance to fail in a loop - // Zoom requied -> Moved the windows 1st -> Focus is lost -> Window is moved back -> Focus is back on -> Zoom required -> ... + // Zoom required -> Moved the windows 1st -> Focus is lost -> Window is moved back -> Focus is back on -> Zoom required -> ... this.MaximumSize = new Size(0, 0); this.Size = new Size(newWidth, newHeight); @@ -439,7 +439,12 @@ namespace EveOPreview.View { if (Control.ModifierKeys == Keys.Control) { - this.ThumbnailDeactivated?.Invoke(this.Id); + this.ThumbnailDeactivated?.Invoke(this.Id, false); + } + else + if (Control.ModifierKeys == (Keys.Control | Keys.Shift)) + { + this.ThumbnailDeactivated?.Invoke(this.Id, true); } else { @@ -490,7 +495,7 @@ namespace EveOPreview.View #endregion #region Custom Mouse mode - // This pair of methods saves/restores certain window propeties + // This pair of methods saves/restores certain window properties // Methods are used to remove the 'Zoom' effect (if any) when the // custom resize/move mode is activated // Methods are kept on this level because moving to the presenter diff --git a/Eve-O-Preview/View/Interface/IThumbnailView.cs b/Eve-O-Preview/View/Interface/IThumbnailView.cs index 3d7e593..00cac7d 100644 --- a/Eve-O-Preview/View/Interface/IThumbnailView.cs +++ b/Eve-O-Preview/View/Interface/IThumbnailView.cs @@ -36,6 +36,6 @@ namespace EveOPreview.View Action ThumbnailLostFocus { get; set; } Action ThumbnailActivated { get; set; } - Action ThumbnailDeactivated { get; set; } + Action ThumbnailDeactivated { get; set; } } } \ No newline at end of file