Allow to switch clients even if Aero is not enabled
This commit is contained in:
@@ -100,7 +100,7 @@ namespace EveOPreview.UI
|
|||||||
private void RefreshThumbnails()
|
private void RefreshThumbnails()
|
||||||
{
|
{
|
||||||
IntPtr foregroundWindowHandle = WindowManagerNativeMethods.GetForegroundWindow();
|
IntPtr foregroundWindowHandle = WindowManagerNativeMethods.GetForegroundWindow();
|
||||||
Boolean hideAllThumbnails = (this._configuration.HideThumbnailsOnLostFocus && this.IsNonClientWindowActive(foregroundWindowHandle)) || !WindowManagerNativeMethods.DwmIsCompositionEnabled();
|
Boolean hideAllThumbnails = this._configuration.HideThumbnailsOnLostFocus && this.IsNonClientWindowActive(foregroundWindowHandle);
|
||||||
|
|
||||||
this.DisableViewEvents();
|
this.DisableViewEvents();
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace EveOPreview.UI
|
|||||||
this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
|
this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.BackColor = System.Drawing.Color.Black;
|
||||||
this.ClientSize = new System.Drawing.Size(153, 89);
|
this.ClientSize = new System.Drawing.Size(153, 89);
|
||||||
this.ControlBox = false;
|
this.ControlBox = false;
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace EveOPreview.UI
|
|||||||
public partial class ThumbnailView : Form, IThumbnailView
|
public partial class ThumbnailView : Form, IThumbnailView
|
||||||
{
|
{
|
||||||
#region Private fields
|
#region Private fields
|
||||||
|
private readonly bool _isDwmCompositionEnabled;
|
||||||
private readonly ThumbnailOverlay _overlay;
|
private readonly ThumbnailOverlay _overlay;
|
||||||
|
|
||||||
// Part of the logic (namely current size / position management)
|
// Part of the logic (namely current size / position management)
|
||||||
@@ -52,6 +53,7 @@ namespace EveOPreview.UI
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this._overlay = new ThumbnailOverlay(this, this.MouseDown_Handler);
|
this._overlay = new ThumbnailOverlay(this, this.MouseDown_Handler);
|
||||||
|
this._isDwmCompositionEnabled = WindowManagerNativeMethods.DwmIsCompositionEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPtr Id { get; set; }
|
public IntPtr Id { get; set; }
|
||||||
@@ -321,37 +323,10 @@ namespace EveOPreview.UI
|
|||||||
|
|
||||||
if (sizeChanged)
|
if (sizeChanged)
|
||||||
{
|
{
|
||||||
// This approach would work only for square-shaped thumbnail window
|
this.RecalculateThumbnailSize();
|
||||||
// To get PROPER results we have to do some crazy math
|
|
||||||
//int delta = this._isHighlightEnabled ? this._highlightWidth : 0;
|
|
||||||
//this._thumbnail.rcDestination = new RECT(0 + delta, 0 + delta, this.ClientSize.Width - delta, this.ClientSize.Height - delta);
|
|
||||||
if (this._isHighlightEnabled)
|
|
||||||
{
|
|
||||||
int baseWidth = this.ClientSize.Width;
|
|
||||||
int baseHeight = this.ClientSize.Height;
|
|
||||||
double baseAspectRatio = ((double)baseWidth) / baseHeight;
|
|
||||||
|
|
||||||
int actualHeight = baseHeight - 2 * this._highlightWidth;
|
this.UpdateThumbnail();
|
||||||
double desiredWidth = actualHeight * baseAspectRatio;
|
|
||||||
int actualWidth = (int)Math.Round(desiredWidth, MidpointRounding.AwayFromZero);
|
|
||||||
int highlightWidthLeft = (baseWidth - actualWidth) / 2;
|
|
||||||
int highlightWidthRight = baseWidth - actualWidth - highlightWidthLeft;
|
|
||||||
|
|
||||||
this._thumbnail.rcDestination = new RECT(0 + highlightWidthLeft, 0 + this._highlightWidth, baseWidth - highlightWidthRight, baseHeight - this._highlightWidth);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//No highlighting enables, so no odd math required
|
|
||||||
this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
WindowManagerNativeMethods.DwmUpdateThumbnailProperties(this._thumbnailHandle, this._thumbnail);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
//This exception will be thrown if the EVE client disappears while this method is running
|
|
||||||
}
|
|
||||||
this._isSizeChanged = false;
|
this._isSizeChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,6 +366,32 @@ namespace EveOPreview.UI
|
|||||||
this._overlay.Refresh();
|
this._overlay.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RecalculateThumbnailSize()
|
||||||
|
{
|
||||||
|
// This approach would work only for square-shaped thumbnail window
|
||||||
|
// To get PROPER results we have to do some crazy math
|
||||||
|
//int delta = this._isHighlightEnabled ? this._highlightWidth : 0;
|
||||||
|
//this._thumbnail.rcDestination = new RECT(0 + delta, 0 + delta, this.ClientSize.Width - delta, this.ClientSize.Height - delta);
|
||||||
|
if (!this._isHighlightEnabled)
|
||||||
|
{
|
||||||
|
//No highlighting enables, so no odd math required
|
||||||
|
this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int baseWidth = this.ClientSize.Width;
|
||||||
|
int baseHeight = this.ClientSize.Height;
|
||||||
|
double baseAspectRatio = ((double)baseWidth) / baseHeight;
|
||||||
|
|
||||||
|
int actualHeight = baseHeight - 2 * this._highlightWidth;
|
||||||
|
double desiredWidth = actualHeight * baseAspectRatio;
|
||||||
|
int actualWidth = (int)Math.Round(desiredWidth, MidpointRounding.AwayFromZero);
|
||||||
|
int highlightWidthLeft = (baseWidth - actualWidth) / 2;
|
||||||
|
int highlightWidthRight = baseWidth - actualWidth - highlightWidthLeft;
|
||||||
|
|
||||||
|
this._thumbnail.rcDestination = new RECT(0 + highlightWidthLeft, 0 + this._highlightWidth, baseWidth - highlightWidthRight, baseHeight - this._highlightWidth);
|
||||||
|
}
|
||||||
|
|
||||||
#region GUI events
|
#region GUI events
|
||||||
protected override CreateParams CreateParams
|
protected override CreateParams CreateParams
|
||||||
{
|
{
|
||||||
@@ -480,22 +481,49 @@ namespace EveOPreview.UI
|
|||||||
#region Thumbnail management
|
#region Thumbnail management
|
||||||
private void RegisterThumbnail()
|
private void RegisterThumbnail()
|
||||||
{
|
{
|
||||||
this._thumbnailHandle = WindowManagerNativeMethods.DwmRegisterThumbnail(this.Handle, this.Id);
|
this._isThumbnailSetUp = true;
|
||||||
|
|
||||||
this._thumbnail = new DWM_THUMBNAIL_PROPERTIES();
|
this._thumbnail = new DWM_THUMBNAIL_PROPERTIES();
|
||||||
this._thumbnail.dwFlags = DWM_TNP_CONSTANTS.DWM_TNP_VISIBLE
|
this._thumbnail.dwFlags = DWM_TNP_CONSTANTS.DWM_TNP_VISIBLE
|
||||||
+ DWM_TNP_CONSTANTS.DWM_TNP_OPACITY
|
+ DWM_TNP_CONSTANTS.DWM_TNP_OPACITY
|
||||||
+ DWM_TNP_CONSTANTS.DWM_TNP_RECTDESTINATION
|
+ DWM_TNP_CONSTANTS.DWM_TNP_RECTDESTINATION
|
||||||
+ DWM_TNP_CONSTANTS.DWM_TNP_SOURCECLIENTAREAONLY;
|
+ DWM_TNP_CONSTANTS.DWM_TNP_SOURCECLIENTAREAONLY;
|
||||||
this._thumbnail.opacity = 255;
|
this._thumbnail.opacity = 255;
|
||||||
this._thumbnail.fVisible = true;
|
this._thumbnail.fVisible = true;
|
||||||
this._thumbnail.fSourceClientAreaOnly = true;
|
this._thumbnail.fSourceClientAreaOnly = true;
|
||||||
|
|
||||||
this._isThumbnailSetUp = true;
|
if (!this._isDwmCompositionEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._thumbnailHandle = WindowManagerNativeMethods.DwmRegisterThumbnail(this.Handle, this.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateThumbnail()
|
||||||
|
{
|
||||||
|
if (!this._isDwmCompositionEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WindowManagerNativeMethods.DwmUpdateThumbnailProperties(this._thumbnailHandle, this._thumbnail);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
//This exception will be thrown if the EVE client disappears while this method is running
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnregisterThumbnail(IntPtr thumbnailHandle)
|
private void UnregisterThumbnail(IntPtr thumbnailHandle)
|
||||||
{
|
{
|
||||||
|
if (!this._isDwmCompositionEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WindowManagerNativeMethods.DwmUnregisterThumbnail(thumbnailHandle);
|
WindowManagerNativeMethods.DwmUnregisterThumbnail(thumbnailHandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user