-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
565 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Windows; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary | ||
{ | ||
public static class BlurWindow | ||
{ | ||
private static readonly IWindowBlurController BlurController; | ||
|
||
static BlurWindow() | ||
{ | ||
BlurController = Helpers.GetWindowControllerForOs(OsHelper.GetOsType()); | ||
} | ||
|
||
/// <summary> | ||
/// Current blur state | ||
/// </summary> | ||
public static bool Enabled => BlurController.Enabled; | ||
|
||
/// <summary> | ||
/// Checks if blur can be enabled. | ||
/// </summary> | ||
public static bool CanBeEnabled => BlurController.CanBeEnabled; | ||
|
||
private static void EnableWindowBlur(IntPtr hwnd) | ||
{ | ||
if (!CanBeEnabled) | ||
return; | ||
|
||
BlurController.EnableBlur(hwnd); | ||
} | ||
|
||
/// <summary> | ||
/// Enable blur for window | ||
/// </summary> | ||
/// <param name="window">Window object</param> | ||
public static void EnableWindowBlur(Window window) | ||
{ | ||
EnableWindowBlur(Helpers.GetWindowHandle(window)); | ||
} | ||
|
||
private static void DisableWindowBlur(IntPtr hwnd) | ||
{ | ||
if (!CanBeEnabled) | ||
return; | ||
|
||
BlurController.DisableBlur(hwnd); | ||
} | ||
|
||
/// <summary> | ||
/// Disable blur for window | ||
/// </summary> | ||
/// <param name="window">Window object</param> | ||
public static void DisableWindowBlur(Window window) | ||
{ | ||
DisableWindowBlur(Helpers.GetWindowHandle(window)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Interop; | ||
using QuickLook.Helpers.BlurLibrary.PlatformsImpl; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary | ||
{ | ||
internal static class Helpers | ||
{ | ||
internal static IWindowBlurController GetWindowControllerForOs(OsType osType) | ||
{ | ||
switch (osType) | ||
{ | ||
case OsType.WindowsVista: | ||
return new WindowsVistaWindowBlurController(); | ||
case OsType.Windows7: | ||
return new Windows7WindowBlurController(); | ||
case OsType.Windows8: | ||
return new Windows8WindowBlurController(); | ||
case OsType.Windows81: | ||
return new Windows81WindowBlurController(); | ||
case OsType.Windows10: | ||
return new Windows10WindowBlurController(); | ||
case OsType.Other: | ||
return new OsNotSupportedWindowBlurController(); | ||
default: | ||
return new OsNotSupportedWindowBlurController(); | ||
} | ||
} | ||
|
||
internal static IntPtr GetWindowHandle(Window window) | ||
{ | ||
return new WindowInteropHelper(window).Handle; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary | ||
{ | ||
internal interface IWindowBlurController | ||
{ | ||
/// <summary> | ||
/// Current blur state | ||
/// </summary> | ||
bool Enabled { get; } | ||
|
||
/// <summary> | ||
/// Checks if blur can be enabled. | ||
/// </summary> | ||
bool CanBeEnabled { get; } | ||
|
||
/// <summary> | ||
/// Enable blur for window | ||
/// </summary> | ||
/// <param name="hwnd">Pointer to Window</param> | ||
/// <exception cref="NotImplementedException">Throws when blur is not supported.</exception> | ||
void EnableBlur(IntPtr hwnd); | ||
|
||
/// <summary> | ||
/// Disable blur for window | ||
/// </summary> | ||
/// <param name="hwnd">Pointer to Window</param> | ||
/// <exception cref="NotImplementedException">Throws when blur is not supported.</exception> | ||
void DisableBlur(IntPtr hwnd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Security; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings | ||
{ | ||
[SuppressUnmanagedCodeSecurity] | ||
internal static class NativeMethods | ||
{ | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
QuickLook/Helpers/BlurLibrary/NativeThings/Windows10/AccentPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10 | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct AccentPolicy | ||
{ | ||
public AccentState AccentState; | ||
public int AccentFlags; | ||
public int GradientColor; | ||
public int AnimationId; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
QuickLook/Helpers/BlurLibrary/NativeThings/Windows10/AccentState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ReSharper disable InconsistentNaming | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10 | ||
{ | ||
internal enum AccentState | ||
{ | ||
ACCENT_DISABLED = 0, | ||
ACCENT_ENABLE_GRADIENT = 1, | ||
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, | ||
ACCENT_ENABLE_BLURBEHIND = 3, | ||
ACCENT_INVALID_STATE = 4 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
QuickLook/Helpers/BlurLibrary/NativeThings/Windows10/NativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
// ReSharper disable once CheckNamespace | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10 | ||
{ | ||
internal static class NativeMethods | ||
{ | ||
[DllImport("user32.dll")] | ||
public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
QuickLook/Helpers/BlurLibrary/NativeThings/Windows10/WindowCompositionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10 | ||
{ | ||
internal enum WindowCompositionAttribute | ||
{ | ||
// ... | ||
WCA_ACCENT_POLICY = 19 | ||
// ... | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
QuickLook/Helpers/BlurLibrary/NativeThings/Windows10/WindowCompositionAttributeData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.Windows10 | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct WindowCompositionAttributeData | ||
{ | ||
public WindowCompositionAttribute Attribute; | ||
public IntPtr Data; | ||
public int SizeOfData; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
QuickLook/Helpers/BlurLibrary/NativeThings/WindowsVistaAnd7/NativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
// ReSharper disable FieldCanBeMadeReadOnly.Global | ||
// ReSharper disable MemberCanBePrivate.Global | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable UnusedMember.Global | ||
// ReSharper disable once CheckNamespace | ||
|
||
namespace QuickLook.Helpers.BlurLibrary.NativeThings.WindowsVistaAnd7 | ||
{ | ||
internal static class NativeMethods | ||
{ | ||
[Flags] | ||
public enum DWM_BB | ||
{ | ||
DWM_BB_ENABLE = 1, | ||
DWM_BB_BLURREGION = 2, | ||
DWM_BB_TRANSITIONONMAXIMIZED = 4 | ||
} | ||
|
||
public const int WM_DWMCOMPOSITIONCHANGED = 0x031E; | ||
|
||
[DllImport("dwmapi.dll", PreserveSig = false)] | ||
public static extern bool DwmIsCompositionEnabled(); | ||
|
||
[DllImport("dwmapi.dll", PreserveSig = false)] | ||
public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind); | ||
|
||
[DllImport("dwmapi.dll")] | ||
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins); | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct DWM_BLURBEHIND | ||
{ | ||
public DWM_BB dwFlags; | ||
public bool fEnable; | ||
public IntPtr hRgnBlur; | ||
public bool fTransitionOnMaximized; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct MARGINS | ||
{ | ||
public int cxLeftWidth; | ||
public int cxRightWidth; | ||
public int cyTopHeight; | ||
public int cyBottomHeight; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
|
||
namespace QuickLook.Helpers.BlurLibrary | ||
{ | ||
internal static class OsHelper | ||
{ | ||
public static OsType GetOsType() | ||
{ | ||
if (Environment.OSVersion.Version.Major != 6 && Environment.OSVersion.Version.Major != 10) | ||
return OsType.Other; | ||
|
||
if (Environment.OSVersion.Version.Major != 6) | ||
return Environment.OSVersion.Version.Major == 10 | ||
? OsType.Windows10 | ||
: OsType.Other; | ||
|
||
switch (Environment.OSVersion.Version.Minor) | ||
{ | ||
case 0: | ||
return OsType.WindowsVista; | ||
case 1: | ||
return OsType.Windows7; | ||
case 2: | ||
return OsType.Windows8; | ||
case 3: | ||
return OsType.Windows81; | ||
default: | ||
return OsType.Other; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace QuickLook.Helpers.BlurLibrary | ||
{ | ||
internal enum OsType | ||
{ | ||
WindowsVista, | ||
Windows7, | ||
Windows8, | ||
Windows81, | ||
Windows10, | ||
Other | ||
} | ||
} |
Oops, something went wrong.