Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Blur on 22621+ #957

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions Common/config/rapidjsonhelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ namespace rjh {
writer.Bool(value);
}

template<class Writer, std::same_as<uint32_t> T>
inline void Serialize(Writer& writer, T value, std::wstring_view key)
{
WriteKey(writer, key);
writer.Uint(value);
}

template<class Writer>
inline void Serialize(Writer &writer, std::wstring_view value, std::wstring_view key)
{
Expand Down Expand Up @@ -135,6 +142,13 @@ namespace rjh {
member = obj.GetBool();
}

inline void Deserialize(const value_t& obj, uint32_t& member, std::wstring_view key)
{
EnsureType(rj::Type::kNumberType, obj.GetType(), key);

member = obj.GetUint();
}

template<typename T, std::size_t size>
requires std::is_enum_v<T>
inline void Deserialize(const value_t &obj, T &member, std::wstring_view key, const std::array<std::wstring_view, size> &arr)
Expand Down
25 changes: 16 additions & 9 deletions Common/config/taskbarappearance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,24 @@ struct TaskbarAppearance {
return false;
}
}
else
{
// always works in Windows 10, but broken in Windows 11 besides RTM with KB5006746.
// since we check IsExactBuild above, using an inverted IsAtLeastBuild here
// makes sure we return false for future versions of Windows 11 as well.
return !win32::IsAtLeastBuild(22000);
}

return true;
}();

return isBlurSupported;
}

ACCENT_STATE Accent = ACCENT_NORMAL;
Util::Color Color = { 0, 0, 0, 0 };
uint32_t BlurRadius = 3;
bool ShowPeek = true;
bool ShowLine = true;

constexpr TaskbarAppearance() noexcept = default;
constexpr TaskbarAppearance(ACCENT_STATE accent, Util::Color color, bool showPeek, bool showLine) noexcept :
constexpr TaskbarAppearance(ACCENT_STATE accent, Util::Color color, bool showPeek, bool showLine, uint32_t blurRadius = 3) noexcept :
Accent(accent),
Color(color),
BlurRadius(blurRadius),
ShowPeek(showPeek),
ShowLine(showLine)
{ }
Expand All @@ -69,6 +66,7 @@ struct TaskbarAppearance {
{
rjh::Serialize(writer, Accent, ACCENT_KEY, ACCENT_MAP);
rjh::Serialize(writer, Color.ToString(), COLOR_KEY);
rjh::Serialize(writer, BlurRadius, RADIUS_KEY);
rjh::Serialize(writer, ShowPeek, SHOW_PEEK_KEY);
rjh::Serialize(writer, ShowLine, SHOW_LINE_KEY);
}
Expand Down Expand Up @@ -114,6 +112,13 @@ struct TaskbarAppearance {
};
}
}
else if (key == RADIUS_KEY)
{
rjh::Deserialize(val, BlurRadius, key);

if (BlurRadius > 250)
BlurRadius = 250;
}
else if (key == SHOW_PEEK_KEY)
{
rjh::Deserialize(val, ShowPeek, key);
Expand All @@ -139,6 +144,7 @@ struct TaskbarAppearance {

static constexpr std::wstring_view ACCENT_KEY = L"accent";
static constexpr std::wstring_view COLOR_KEY = L"color";
static constexpr std::wstring_view RADIUS_KEY = L"blur_radius";
static constexpr std::wstring_view SHOW_PEEK_KEY = L"show_peek";
static constexpr std::wstring_view SHOW_LINE_KEY = L"show_line";
#endif
Expand All @@ -148,13 +154,14 @@ struct TaskbarAppearance {
TaskbarAppearance(const txmp::TaskbarAppearance &winrtObj) noexcept :
Accent(static_cast<ACCENT_STATE>(winrtObj.Accent())),
Color(winrtObj.Color()),
BlurRadius(winrtObj.BlurRadius()),
ShowPeek(winrtObj.ShowPeek()),
ShowLine(winrtObj.ShowLine())
{ }

operator txmp::TaskbarAppearance() const
{
return { static_cast<txmp::AccentState>(Accent), Color, ShowPeek, ShowLine };
return { static_cast<txmp::AccentState>(Accent), Color, ShowPeek, ShowLine, BlurRadius };
}
#endif
};
2 changes: 2 additions & 0 deletions Common/winrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace winrt {
namespace Controls {}
namespace Hosting {}
}
namespace UI::Composition {}
}
}

Expand All @@ -27,3 +28,4 @@ namespace wfc = wf::Collections;
namespace wux = winrt::Windows::UI::Xaml;
namespace wuxc = wux::Controls;
namespace wuxh = wux::Hosting;
namespace wuc = winrt::Windows::UI::Composition;
6 changes: 5 additions & 1 deletion ExplorerTAP/ExplorerTAP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PreprocessorDefinitions>EXPLORERTAP_EXPORTS;WINRT_NO_MODULE_LOCK;RPCPROXY_ENABLE_CPP_NO_CINTERFACE;PROXY_CLSID_IS={ 0xe8721a60, 0x3798, 0x448f, { 0xa0, 0x1b, 0xdc, 0x4a, 0xf6, 0x5a, 0x78, 0xb } };ENTRY_PREFIX=PSFactory_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>Ole32.lib;OleAut32.lib;rpcrt4.lib;runtimeobject.lib;user32.lib</AdditionalDependencies>
<AdditionalDependencies>dxguid.lib;Ole32.lib;OleAut32.lib;rpcrt4.lib;runtimeobject.lib;user32.lib</AdditionalDependencies>
<ModuleDefinitionFile>ExplorerTAP.def</ModuleDefinitionFile>
<SubSystem>Windows</SubSystem>
</Link>
Expand Down Expand Up @@ -46,6 +46,7 @@
<ItemGroup>
<ClCompile Include="api.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="GaussianBlurEffect.cpp" />
<ClCompile Include="Generated Files\$(Platform)\dlldata.c" />
<ClCompile Include="Generated Files\$(Platform)\ExplorerTAP_i.c" />
<ClCompile Include="Generated Files\$(Platform)\ITaskbarAppearanceService_i.c" />
Expand All @@ -56,6 +57,7 @@
<ClCompile Include="tapsite.cpp" />
<ClCompile Include="taskbarappearanceservice.cpp" />
<ClCompile Include="visualtreewatcher.cpp" />
<ClCompile Include="XamlCompositionBrush.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="ExplorerTAP.def" />
Expand All @@ -64,13 +66,15 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="api.hpp" />
<ClInclude Include="GaussianBlurEffect.h" />
<ClInclude Include="Generated Files\$(Platform)\ExplorerTAP.h" />
<ClInclude Include="Generated Files\$(Platform)\ITaskbarAppearanceService.h" />
<ClInclude Include="Generated Files\$(Platform)\IVersionedApi.h" />
<ClInclude Include="Generated Files\$(Platform)\TaskbarBrush.h" />
<ClInclude Include="tapsite.hpp" />
<ClInclude Include="taskbarappearanceservice.hpp" />
<ClInclude Include="visualtreewatcher.hpp" />
<ClInclude Include="XamlCompositionBrush.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="ExplorerTAP.idl" />
Expand Down
12 changes: 12 additions & 0 deletions ExplorerTAP/ExplorerTAP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<ClCompile Include="Generated Files\$(Platform)\IVersionedApi_p.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XamlCompositionBrush.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GaussianBlurEffect.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="api.hpp">
Expand All @@ -80,6 +86,12 @@
<ClInclude Include="Generated Files\$(Platform)\TaskbarBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="XamlCompositionBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GaussianBlurEffect.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ExplorerTAP.def">
Expand Down
105 changes: 105 additions & 0 deletions ExplorerTAP/GaussianBlurEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma warning ( disable: 4100 26447 26490 26429 26818 )
#include "GaussianBlurEffect.h"

HRESULT __stdcall GaussianBlurEffect::GetEffectId(GUID* id) noexcept
{
if (id == nullptr)
return E_INVALIDARG;

*id = CLSID_D2D1GaussianBlur;
return S_OK;
}

HRESULT __stdcall GaussianBlurEffect::GetNamedPropertyMapping(LPCWSTR name, UINT* index, awge::GRAPHICS_EFFECT_PROPERTY_MAPPING* mapping) noexcept
{
if (index == nullptr || mapping == nullptr)
return E_INVALIDARG;

if (_wcsicmp(name, L"BlurAmount") == 0)
{
*index = D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION;
*mapping = awge::GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;

return S_OK;
}
else if (_wcsicmp(name, L"Optimization") == 0)
{
*index = D2D1_GAUSSIANBLUR_PROP_OPTIMIZATION;
*mapping = awge::GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;

return S_OK;
}
else if (_wcsicmp(name, L"BorderMode") == 0)
{
*index = D2D1_GAUSSIANBLUR_PROP_BORDER_MODE;
*mapping = awge::GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;

return S_OK;
}

return E_INVALIDARG;
}

HRESULT __stdcall GaussianBlurEffect::GetPropertyCount(UINT* count) noexcept
{
if (count == nullptr)
return E_INVALIDARG;

*count = 3;
return S_OK;
}

HRESULT __stdcall GaussianBlurEffect::GetProperty(UINT index, ABI::Windows::Foundation::IPropertyValue** value) noexcept
{
if (value == nullptr)
return E_INVALIDARG;

switch (index)
{
case D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION:
{
reinterpret_cast<wf::IPropertyValue&>(*value) = wf::PropertyValue::CreateSingle(BlurAmount).as<wf::IPropertyValue>();
break;
}
case D2D1_GAUSSIANBLUR_PROP_OPTIMIZATION:
{
reinterpret_cast<wf::IPropertyValue&>(*value) = wf::PropertyValue::CreateUInt32((UINT32)Optimization).as<wf::IPropertyValue>();
break;
}
case D2D1_GAUSSIANBLUR_PROP_BORDER_MODE:
{
reinterpret_cast<wf::IPropertyValue&>(*value) = wf::PropertyValue::CreateUInt32((UINT32)BorderMode).as<wf::IPropertyValue>();
break;
}
}

return S_OK;
}

HRESULT __stdcall GaussianBlurEffect::GetSource(UINT index, awge::IGraphicsEffectSource** source) noexcept
{
if (source == nullptr)
return E_INVALIDARG;

reinterpret_cast<wge::IGraphicsEffectSource&>(*source) = Source;
return S_OK;
}

HRESULT __stdcall GaussianBlurEffect::GetSourceCount(UINT* count) noexcept
{
if (count == nullptr)
return E_INVALIDARG;

*count = 1;
return S_OK;
}

winrt::hstring GaussianBlurEffect::Name()
{
return m_name;
}

void GaussianBlurEffect::Name(winrt::hstring name)
{
m_name = name;
}
33 changes: 33 additions & 0 deletions ExplorerTAP/GaussianBlurEffect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include "winrt.hpp"
#include "d2d1effects.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Graphics.Effects.h>
#include <windows.graphics.effects.interop.h>

namespace wge = winrt::Windows::Graphics::Effects;
namespace awge = ABI::Windows::Graphics::Effects;

struct GaussianBlurEffect : winrt::implements<GaussianBlurEffect, wge::IGraphicsEffect, wge::IGraphicsEffectSource, awge::IGraphicsEffectD2D1Interop>
{
public:
// IGraphicsEffectD2D1Interop
HRESULT STDMETHODCALLTYPE GetEffectId(GUID* id) noexcept override;
HRESULT STDMETHODCALLTYPE GetNamedPropertyMapping(LPCWSTR name, UINT* index, awge::GRAPHICS_EFFECT_PROPERTY_MAPPING* mapping) noexcept override;
HRESULT STDMETHODCALLTYPE GetPropertyCount(UINT* count) noexcept override;
HRESULT STDMETHODCALLTYPE GetProperty(UINT index, ABI::Windows::Foundation::IPropertyValue** value) noexcept override;
HRESULT STDMETHODCALLTYPE GetSource(UINT index, awge::IGraphicsEffectSource** source) noexcept override;
HRESULT STDMETHODCALLTYPE GetSourceCount(UINT* count) noexcept override;

// IGraphicsEffect
winrt::hstring Name();
void Name(winrt::hstring name);

wge::IGraphicsEffectSource Source;

float BlurAmount = 3.0f;
D2D1_GAUSSIANBLUR_OPTIMIZATION Optimization = D2D1_GAUSSIANBLUR_OPTIMIZATION_BALANCED;
D2D1_BORDER_MODE BorderMode = D2D1_BORDER_MODE_SOFT;
private:
winrt::hstring m_name = L"GaussianBlurEffect";
};
3 changes: 2 additions & 1 deletion ExplorerTAP/TaskbarBrush.idl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enum TaskbarBrush
{
Acrylic,
SolidColor
SolidColor,
Blur
};
34 changes: 34 additions & 0 deletions ExplorerTAP/XamlCompositionBrush.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "XamlCompositionBrush.h"

std::atomic_int XamlCompositionBrush::m_connectionCounter = 0;

XamlCompositionBrush::XamlCompositionBrush(wuc::CompositionBrush brush, bool disposeBrush) : m_brush(brush), m_disposeBrush(disposeBrush) { }

void XamlCompositionBrush::OnConnected()
{
CompositionBrush(m_brush);

if (m_disposeBrush)
{
++m_connectionCounter;
OnConnectionChanged();
}
}

void XamlCompositionBrush::OnDisconnected()
{
if (m_disposeBrush)
{
--m_connectionCounter;
OnConnectionChanged();
}
}

void XamlCompositionBrush::OnConnectionChanged()
{
if (!m_connectionCounter)
{
CompositionBrush(nullptr);
m_brush.Close();
}
}
23 changes: 23 additions & 0 deletions ExplorerTAP/XamlCompositionBrush.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <atomic>
#include "winrt.hpp"
#include "undefgetcurrenttime.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Composition.h>

class XamlCompositionBrush : public wux::Media::XamlCompositionBrushBaseT<XamlCompositionBrush>
{
public:
XamlCompositionBrush(wuc::CompositionBrush brush, bool disposeBrush = true);

void OnConnected();
void OnDisconnected();
private:
wuc::CompositionBrush m_brush;

bool m_disposeBrush;
static std::atomic_int m_connectionCounter;

void OnConnectionChanged();
};