142: Add a mouse action to switch out to the last used external app

This commit is contained in:
Anton Kasyanov
2019-03-04 21:37:03 +02:00
parent cd74a3d29f
commit ea2445eeb2
3 changed files with 35 additions and 15 deletions

View File

@@ -32,6 +32,7 @@ namespace EveOPreview.Services
private readonly Dictionary<IntPtr, IThumbnailView> _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,7 +406,13 @@ namespace EveOPreview.Services
});
}
private void ThumbnailDeactivated(IntPtr id)
private void ThumbnailDeactivated(IntPtr id, bool switchOut)
{
if (switchOut)
{
this._windowManager.ActivateWindow(this._externalApplication);
}
else
{
if (!this._thumbnailViews.TryGetValue(id, out IThumbnailView view))
{
@@ -408,6 +422,7 @@ namespace EveOPreview.Services
this._windowManager.MinimizeWindow(view.Id, true);
this.RefreshThumbnails();
}
}
private async void ThumbnailViewResized(IntPtr id)
{

View File

@@ -104,7 +104,7 @@ namespace EveOPreview.View
public Action<IntPtr> ThumbnailActivated { get; set; }
public Action<IntPtr> ThumbnailDeactivated { get; set; }
public Action<IntPtr, bool> 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

View File

@@ -36,6 +36,6 @@ namespace EveOPreview.View
Action<IntPtr> ThumbnailLostFocus { get; set; }
Action<IntPtr> ThumbnailActivated { get; set; }
Action<IntPtr> ThumbnailDeactivated { get; set; }
Action<IntPtr, bool> ThumbnailDeactivated { get; set; }
}
}