This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisualManager.hpp
185 lines (166 loc) · 5.61 KB
/
VisualManager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#include "udwmPrivates.hpp"
#include "CompositedBackdrop.hpp"
namespace AcrylicEverywhere
{
class CVisualManager
{
public:
winrt::com_ptr<CCompositedBackdrop> GetOrCreateBackdrop(uDwmPrivates::CTopLevelWindow* target, bool createIfNecessary = false)
{
auto it{ m_backdropMap.find(target) };
if (createIfNecessary)
{
if (it == m_backdropMap.end())
{
auto result{ m_backdropMap.emplace(target, winrt::make_self<CCompositedBackdrop>(target)) };
if (result.second == true)
{
it = result.first;
it->second->UpdateBackdropType(BackdropType::Aero);
it->second->UpdateGlassReflectionState(true);
}
}
}
return it == m_backdropMap.end() ? nullptr : it->second;
}
winrt::com_ptr<CCompositedAccentBackdrop> GetOrCreateAccentBackdrop(uDwmPrivates::CTopLevelWindow* target, bool createIfNecessary = false)
{
auto it{ m_accentBackdropMap.find(target) };
if (createIfNecessary)
{
if (it == m_accentBackdropMap.end())
{
auto result{ m_accentBackdropMap.emplace(target, winrt::make_self<CCompositedAccentBackdrop>(target)) };
if (result.second == true)
{
it = result.first;
it->second->UpdateBackdropType(BackdropType::Aero);
it->second->UpdateGlassReflectionState(true);
}
}
}
return it == m_accentBackdropMap.end() ? nullptr : it->second;
}
winrt::com_ptr<CCompositedBackdrop> TryCloneBackdropForWindow(uDwmPrivates::CTopLevelWindow* src, uDwmPrivates::CTopLevelWindow* dest)
{
if (auto backdrop{ GetOrCreateBackdrop(src) }; backdrop)
{
auto it{ m_backdropMap.find(dest) };
auto clonedBackdrop{ winrt::make_self<CCompositedBackdrop>(backdrop.get(), dest)};
if (it == m_backdropMap.end())
{
auto result{ m_backdropMap.emplace(dest, clonedBackdrop) };
if (result.second == true) { it = result.first; }
}
else
{
std::swap(
clonedBackdrop,
it->second
);
}
return it == m_backdropMap.end() ? nullptr : it->second;
}
return nullptr;
}
winrt::com_ptr<CCompositedBackdrop> TryCloneAnimatedBackdropForWindow(uDwmPrivates::CTopLevelWindow* src, uDwmPrivates::CSecondaryWindowRepresentation* dest)
{
if (auto backdrop{ GetOrCreateBackdrop(src) }; backdrop)
{
auto it{ m_animatedBackdropMap.find(dest) };
if (it != m_animatedBackdropMap.end())
{
m_animatedBackdropMap.erase(it);
}
auto clonedBackdrop{ winrt::make_self<CCompositedBackdrop>(backdrop.get()) };
auto result{ m_animatedBackdropMap.emplace(dest, clonedBackdrop) };
if (result.second == true) { it = result.first; }
return it == m_animatedBackdropMap.end() ? nullptr : it->second;
}
return nullptr;
}
winrt::com_ptr<CCompositedAccentBackdrop> TryCloneAnimatedAccentBackdropForWindow(uDwmPrivates::CTopLevelWindow* src, uDwmPrivates::CSecondaryWindowRepresentation* dest)
{
if (auto backdrop{ GetOrCreateAccentBackdrop(src) }; backdrop)
{
auto it{ m_animatedAccentBackdropMap.find(dest) };
if (it != m_animatedAccentBackdropMap.end())
{
m_animatedAccentBackdropMap.erase(it);
}
auto clonedBackdrop{ winrt::make_self<CCompositedAccentBackdrop>(backdrop.get()) };
auto result{ m_animatedAccentBackdropMap.emplace(dest, clonedBackdrop) };
if (result.second == true) { it = result.first; }
return it == m_animatedAccentBackdropMap.end() ? nullptr : it->second;
}
return nullptr;
}
winrt::com_ptr<CCompositedAccentBackdrop> TryCloneAccentBackdropForWindow(uDwmPrivates::CTopLevelWindow* src, uDwmPrivates::CTopLevelWindow* dest)
{
if (auto backdrop{ GetOrCreateAccentBackdrop(src) }; backdrop)
{
auto it{ m_accentBackdropMap.find(dest) };
auto clonedBackdrop{ winrt::make_self<CCompositedAccentBackdrop>(backdrop.get(), dest) };
if (it == m_accentBackdropMap.end())
{
auto result{ m_accentBackdropMap.emplace(dest, clonedBackdrop) };
if (result.second == true) { it = result.first; }
}
else
{
std::swap(
clonedBackdrop,
it->second
);
}
return it == m_accentBackdropMap.end() ? nullptr : it->second;
}
return nullptr;
}
void Remove(uDwmPrivates::CTopLevelWindow* target)
{
auto it{ m_backdropMap.find(target) };
if (it != m_backdropMap.end())
{
m_backdropMap.erase(it);
}
}
void RemoveAnimatedBackdrop(uDwmPrivates::CSecondaryWindowRepresentation* target)
{
auto it{ m_animatedBackdropMap.find(target) };
if (it != m_animatedBackdropMap.end())
{
m_animatedBackdropMap.erase(it);
}
}
void RemoveAnimatedAccentBackdrop(uDwmPrivates::CSecondaryWindowRepresentation* target)
{
auto it{ m_animatedAccentBackdropMap.find(target) };
if (it != m_animatedAccentBackdropMap.end())
{
m_animatedAccentBackdropMap.erase(it);
}
}
void RemoveAccent(uDwmPrivates::CTopLevelWindow* target)
{
auto it{ m_accentBackdropMap.find(target) };
if (it != m_accentBackdropMap.end())
{
m_accentBackdropMap.erase(it);
}
}
void Shutdown()
{
m_backdropMap.clear();
m_accentBackdropMap.clear();
m_animatedBackdropMap.clear();
m_animatedAccentBackdropMap.clear();
}
private:
std::unordered_map<uDwmPrivates::CTopLevelWindow*, winrt::com_ptr<CCompositedBackdrop>> m_backdropMap{};
std::unordered_map<uDwmPrivates::CTopLevelWindow*, winrt::com_ptr<CCompositedAccentBackdrop>> m_accentBackdropMap{};
std::unordered_map<uDwmPrivates::CSecondaryWindowRepresentation*, winrt::com_ptr<CCompositedBackdrop>> m_animatedBackdropMap{};
std::unordered_map<uDwmPrivates::CSecondaryWindowRepresentation*, winrt::com_ptr<CCompositedAccentBackdrop>> m_animatedAccentBackdropMap{};
};
}