156: Remove Compatibility-Mode thumbnails

This commit is contained in:
Anton Kasyanov
2020-03-29 21:46:26 +03:00
parent f659949d4b
commit de7edfa2c1
12 changed files with 5 additions and 197 deletions

View File

@@ -24,8 +24,6 @@ namespace EveOPreview.Configuration.Implementation
this.MinimizeToTray = false;
this.ThumbnailRefreshPeriod = 500;
this.EnableCompatibilityMode = false;
this.ThumbnailOpacity = 0.5;
this.EnableClientLayoutTracking = false;
@@ -56,9 +54,6 @@ namespace EveOPreview.Configuration.Implementation
public bool MinimizeToTray { get; set; }
public int ThumbnailRefreshPeriod { get; set; }
[JsonProperty("CompatibilityMode")]
public bool EnableCompatibilityMode { get; set; }
[JsonProperty("ThumbnailsOpacity")]
public double ThumbnailOpacity { get; set; }
@@ -150,8 +145,7 @@ namespace EveOPreview.Configuration.Implementation
// If there is no layout too then use the default one
if (this.EnablePerClientThumbnailLayouts && !string.IsNullOrEmpty(activeClient))
{
Dictionary<string, Point> layoutSource;
if (this.PerClientLayout.TryGetValue(activeClient, out layoutSource) && layoutSource.TryGetValue(currentClient, out location))
if (this.PerClientLayout.TryGetValue(activeClient, out Dictionary<string, Point> layoutSource) && layoutSource.TryGetValue(currentClient, out location))
{
return location;
}
@@ -187,8 +181,7 @@ namespace EveOPreview.Configuration.Implementation
public ClientLayout GetClientLayout(string currentClient)
{
ClientLayout layout;
this.ClientLayout.TryGetValue(currentClient, out layout);
this.ClientLayout.TryGetValue(currentClient, out ClientLayout layout);
return layout;
}
@@ -200,8 +193,7 @@ namespace EveOPreview.Configuration.Implementation
public Keys GetClientHotkey(string currentClient)
{
string hotkey;
if (this.ClientHotkey.TryGetValue(currentClient, out hotkey))
if (this.ClientHotkey.TryGetValue(currentClient, out string hotkey))
{
// Protect from incorrect values
object rawValue = (new KeysConverter()).ConvertFromInvariantString(hotkey);

View File

@@ -8,8 +8,6 @@ namespace EveOPreview.Configuration
bool MinimizeToTray { get; set; }
int ThumbnailRefreshPeriod { get; set; }
bool EnableCompatibilityMode { get; set; }
double ThumbnailOpacity { get; set; }
bool EnableClientLayoutTracking { get; set; }

View File

@@ -147,7 +147,6 @@
<Compile Include="Services\Interop\DWM_THUMBNAIL_PROPERTIES.cs" />
<Compile Include="Services\Interop\DWM_TNP_CONSTANTS.cs" />
<Compile Include="Services\Interface\IWindowManager.cs" />
<Compile Include="Services\Interop\Gdi32NativeMethods.cs" />
<Compile Include="Services\Interop\MARGINS.cs" />
<Compile Include="Services\Interop\RECT.cs" />
<Compile Include="Configuration\Interface\ClientLayout.cs" />
@@ -164,9 +163,6 @@
<Compile Include="View\Implementation\StaticThumbnailImage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="View\Implementation\StaticThumbnailView.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="View\Interface\IThumbnailViewFactory.cs" />
<Compile Include="Services\Interface\IThumbnailManager.cs" />
<Compile Include="View\Implementation\ThumbnailDescription.cs" />

View File

@@ -99,7 +99,6 @@ namespace EveOPreview
IApplicationController controller = new ApplicationController(container);
// UI classes
controller.RegisterView<StaticThumbnailView, StaticThumbnailView>();
controller.RegisterView<LiveThumbnailView, LiveThumbnailView>();
controller.RegisterView<IMainFormView, MainForm>();

View File

@@ -14,7 +14,7 @@ namespace EveOPreview.Services.Implementation
public WindowManager()
{
// Composition is always enabled for Windows 8+
this.IsCompositionEnabled =
this.IsCompositionEnabled =
((Environment.OSVersion.Version.Major == 6) && (Environment.OSVersion.Version.Minor >= 2)) // Win 8 and Win 8.1
|| (Environment.OSVersion.Version.Major >= 10) // Win 10
|| DwmNativeMethods.DwmIsCompositionEnabled(); // In case of Win 7 an API call is requiredWin 7
@@ -89,35 +89,5 @@ namespace EveOPreview.Services.Implementation
return thumbnail;
}
public Image GetStaticThumbnail(IntPtr source)
{
var sourceContext = User32NativeMethods.GetDC(source);
User32NativeMethods.GetClientRect(source, out RECT windowRect);
var width = windowRect.Right - windowRect.Left;
var height = windowRect.Bottom - windowRect.Top;
// Check if there is anything to make thumbnail of
if ((width < WINDOW_SIZE_THRESHOLD) || (height < WINDOW_SIZE_THRESHOLD))
{
return null;
}
var destContext = Gdi32NativeMethods.CreateCompatibleDC(sourceContext);
var bitmap = Gdi32NativeMethods.CreateCompatibleBitmap(sourceContext, width, height);
var oldBitmap = Gdi32NativeMethods.SelectObject(destContext, bitmap);
Gdi32NativeMethods.BitBlt(destContext, 0, 0, width, height, sourceContext, 0, 0, Gdi32NativeMethods.SRCCOPY);
Gdi32NativeMethods.SelectObject(destContext, oldBitmap);
Gdi32NativeMethods.DeleteDC(destContext);
User32NativeMethods.ReleaseDC(source, sourceContext);
Image image = Image.FromHbitmap(bitmap);
Gdi32NativeMethods.DeleteObject(bitmap);
return image;
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Drawing;
namespace EveOPreview.Services
{
@@ -16,6 +15,5 @@ namespace EveOPreview.Services
bool IsWindowMaximized(IntPtr handle);
bool IsWindowMinimized(IntPtr handle);
IDwmThumbnail GetLiveThumbnail(IntPtr destination, IntPtr source);
Image GetStaticThumbnail(IntPtr source);
}
}

View File

@@ -1,28 +1,12 @@
using System;
using System.Runtime.InteropServices;
using System.Drawing;
namespace EveOPreview.Services.Interop
{
static class DwmNativeMethods
{
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, MARGINS pMargins);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmGetColorizationColor(
out int pcrColorization,
[MarshalAs(UnmanagedType.Bool)]out bool pfOpaqueBlend);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableComposition(bool bEnable);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern IntPtr DwmRegisterThumbnail(IntPtr dest, IntPtr source);
@@ -31,8 +15,5 @@ namespace EveOPreview.Services.Interop
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmUpdateThumbnailProperties(IntPtr hThumbnail, DWM_THUMBNAIL_PROPERTIES props);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmQueryThumbnailSourceSize(IntPtr hThumbnail, out Size size);
}
}

View File

@@ -1,28 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace EveOPreview.Services.Interop
{
static class Gdi32NativeMethods
{
public const int SRCCOPY = 13369376;
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int width, int height);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop);
}
}

View File

@@ -14,9 +14,6 @@ namespace EveOPreview.Services.Interop
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("User32.dll")]
public static extern bool ReleaseCapture();
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
@@ -26,9 +23,6 @@ namespace EveOPreview.Services.Interop
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hWnd, out RECT rect);
[DllImport("user32.dll")]
public static extern bool GetClientRect(IntPtr hWnd, out RECT rect);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
@@ -45,14 +39,5 @@ namespace EveOPreview.Services.Interop
[DllImport("user32.dll")]
public static extern bool IsZoomed(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hdc);
}
}

View File

@@ -1,70 +0,0 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using EveOPreview.Services;
namespace EveOPreview.View
{
sealed class StaticThumbnailView : ThumbnailView
{
#region Private fields
private readonly PictureBox _thumbnail;
#endregion
public StaticThumbnailView(IWindowManager windowManager)
: base(windowManager)
{
this._thumbnail = new StaticThumbnailImage
{
TabStop = false,
SizeMode = PictureBoxSizeMode.StretchImage,
Location = new Point(0, 0),
Size = new Size(this.ClientSize.Width, this.ClientSize.Height)
};
this.Controls.Add(this._thumbnail);
}
protected override void RefreshThumbnail(bool forceRefresh)
{
if (!forceRefresh)
{
return;
}
var thumbnail = this.WindowManager.GetStaticThumbnail(this.Id);
if (thumbnail != null)
{
var oldImage = this._thumbnail.Image;
this._thumbnail.Image = thumbnail;
oldImage?.Dispose();
}
}
protected override void ResizeThumbnail(int baseWidth, int baseHeight, int highlightWidthTop, int highlightWidthRight, int highlightWidthBottom, int highlightWidthLeft)
{
var left = 0 + highlightWidthLeft;
var top = 0 + highlightWidthTop;
if (this.IsLocationUpdateRequired(this._thumbnail.Location, left, top))
{
this._thumbnail.Location = new Point(left, top);
}
var width = baseWidth - highlightWidthLeft - highlightWidthRight;
var height = baseHeight - highlightWidthTop - highlightWidthBottom;
if (this.IsSizeUpdateRequired(this._thumbnail.Size, width, height))
{
this._thumbnail.Size = new Size(width, height);
}
}
private bool IsLocationUpdateRequired(Point currentLocation, int left, int top)
{
return (currentLocation.X != left) || (currentLocation.Y != top);
}
private bool IsSizeUpdateRequired(Size currentSize, int width, int height)
{
return (currentSize.Width != width) || (currentSize.Height != height);
}
}
}

View File

@@ -7,19 +7,15 @@ namespace EveOPreview.View
sealed class ThumbnailViewFactory : IThumbnailViewFactory
{
private readonly IApplicationController _controller;
private readonly bool _isCompatibilityModeEnabled;
public ThumbnailViewFactory(IApplicationController controller, IThumbnailConfiguration configuration)
{
this._controller = controller;
this._isCompatibilityModeEnabled = configuration.EnableCompatibilityMode;
}
public IThumbnailView Create(IntPtr id, string title, Size size)
{
IThumbnailView view = this._isCompatibilityModeEnabled
? (IThumbnailView)this._controller.Create<StaticThumbnailView>()
: (IThumbnailView)this._controller.Create<LiveThumbnailView>();
IThumbnailView view = this._controller.Create<LiveThumbnailView>();
view.Id = id;
view.Title = title;

View File

@@ -91,7 +91,6 @@ Some of the application options are not exposed in the GUI. They can be adjusted
| Option | Description |
| --- | --- |
| **ActiveClientHighlightThickness** | Thickness of the border used to highlight the active client's thumbnail.<br />Allowed values are **1**...**6**.<br />The default value is **3**<br />For example: **"ActiveClientHighlightThickness": 3** |
| **CompatibilityMode** | Enables the alternative render mode (see below)<br />The default value is **false**<br />For example: **"CompatibilityMode": true** |
| **EnableThumbnailSnap** | Allows to disable thumbnails snap feature by setting its value to **false**<br />The default value is **true**<br />For example: **"EnableThumbnailSnap": true** |
| **PriorityClients** | Allows to set a list of clients that are not auto-minimized on inactivity even if the **Minimize inactive EVE clients** option is enabled. Listed clients still can be minimized using Windows hotkeys or via _Ctrl+Click_ on the corresponding thumbnail<br />The default value is empty list **[]**<br />For example: **"PriorityClients": [ "EVE - Phrynohyas Tig-Rah", "EVE - Ondatra Patrouette" ]** |
| **ThumbnailMinimumSize** | Minimum thumbnail size that can be set either via GUI or by resizing a thumbnail window. Value is written in the form "width, height"<br />The default value is **"100, 80"**.<br />For example: **"ThumbnailMinimumSize": "100, 80"** |
@@ -125,14 +124,6 @@ The following hotkey is described as `modifier+key` where `modifier` can be **Co
**Note:** Do not set hotkeys to use the key combinations already used by EVE. It won't work as "_I set hotkey for my DPS char to F1 and when I'll press F1 it will automatically open the DPS char's window and activate guns_". Key combination will be swallowed by EVE-O Preview and NOT retranslated to EVE window. So it will be only "_it will automatically open the DPS char's window_".
## Compatibility Mode
This setting allows to enable an alternate thumbnail render. This render doesn't use advanced DWM API to create live previews. Instead it is a screenshot-based render with the following pros and cons:
* `+` Should work even in remote desktop environments
* `-` Consumes significantly more memory. In the testing environment EVE-O Preview did consume around 180 MB to manage 3 thumbnails using this render. At the same time the primary render did consume around 50 MB when run in the same environment.
* `-` Thumbnail images are refreshed at 1 FPS rate
* `-` Possible short mouse cursor freezes
---
# Credits