Skip to content

Commit 03f3d78

Browse files
committed
Deduplicate XAML override transitions and TAP activation
1 parent 3d9c8b1 commit 03f3d78

1 file changed

Lines changed: 39 additions & 86 deletions

File tree

‎Src/StartMenu/StartMenuHelper/Win11StartButtonTap.cpp‎

Lines changed: 39 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -821,83 +821,46 @@ class CWin11StartButtonTap: public IObjectWithSite, public IVisualTreeServiceCal
821821

822822
const bool allTaskbars = g_AllTaskbars;
823823

824+
// Both properties share the same set/restore behavior.
825+
auto applyOverride = [&](InstanceHandle handle, const wchar_t *property, const wchar_t *value,
826+
bool shouldOverride, bool hasOverride, bool visibility)
827+
{
828+
if (shouldOverride == hasOverride)
829+
return;
830+
HRESULT hr = shouldOverride ? SetPropertyText(handle, property, value) :
831+
ClearPropertyByName(handle, property);
832+
if (SUCCEEDED(hr))
833+
{
834+
bool updated = shouldOverride;
835+
if (visibility)
836+
SetOverrideFlags(handle, &updated, NULL);
837+
else
838+
SetOverrideFlags(handle, NULL, &updated);
839+
}
840+
else if (SUCCEEDED(firstError))
841+
firstError = hr;
842+
};
843+
824844
for (size_t i = 0; i < elements.size(); i++)
825845
{
826846
InstanceHandle handle = elements[i].first;
827847
StartElement record = elements[i].second;
828-
829848
if (record.isStartControl)
830849
{
831850
bool target = allTaskbars || !primaryStart || handle == primaryStart;
832-
if (enabled && target)
833-
{
834-
if (!record.hitTestOverride)
835-
{
836-
HRESULT hr = SetPropertyText(handle, L"IsHitTestVisible", L"False");
837-
if (SUCCEEDED(hr))
838-
{
839-
bool value = true;
840-
SetOverrideFlags(handle, NULL, &value);
841-
}
842-
else if (SUCCEEDED(firstError))
843-
{
844-
firstError = hr;
845-
}
846-
}
847-
}
848-
else if (record.hitTestOverride)
849-
{
850-
HRESULT hr = ClearPropertyByName(handle, L"IsHitTestVisible");
851-
if (SUCCEEDED(hr))
852-
{
853-
bool value = false;
854-
SetOverrideFlags(handle, NULL, &value);
855-
}
856-
else if (SUCCEEDED(firstError))
857-
{
858-
firstError = hr;
859-
}
860-
}
851+
applyOverride(handle, L"IsHitTestVisible", L"False",
852+
enabled && target, record.hitTestOverride, false);
861853
continue;
862854
}
863855

864856
if (!IsStartGlyph(record))
865857
continue;
866-
867858
InstanceHandle startAncestor = GetStartAncestor(handle);
868859
if (!startAncestor)
869860
continue;
870861
bool target = allTaskbars || !primaryStart || startAncestor == primaryStart;
871-
872-
if (enabled && target)
873-
{
874-
if (!record.visibilityOverride)
875-
{
876-
HRESULT hr = SetPropertyText(handle, L"Visibility", L"Collapsed");
877-
if (SUCCEEDED(hr))
878-
{
879-
bool value = true;
880-
SetOverrideFlags(handle, &value, NULL);
881-
}
882-
else if (SUCCEEDED(firstError))
883-
{
884-
firstError = hr;
885-
}
886-
}
887-
}
888-
else if (record.visibilityOverride)
889-
{
890-
HRESULT hr = ClearPropertyByName(handle, L"Visibility");
891-
if (SUCCEEDED(hr))
892-
{
893-
bool value = false;
894-
SetOverrideFlags(handle, &value, NULL);
895-
}
896-
else if (SUCCEEDED(firstError))
897-
{
898-
firstError = hr;
899-
}
900-
}
862+
applyOverride(handle, L"Visibility", L"Collapsed",
863+
enabled && target, record.visibilityOverride, true);
901864
}
902865

903866
return firstError;
@@ -1062,43 +1025,33 @@ static void EnsureConnection( void )
10621025
g_ConnectStarted = false;
10631026
}
10641027

1065-
extern "C" void StartWin11StartButtonTap( BOOL enabled, BOOL allTaskbars )
1028+
static void ActivateCurrentTap( void )
10661029
{
1067-
g_StartButtonEnabled = enabled != FALSE;
1068-
g_AllTaskbars = allTaskbars != FALSE;
1069-
g_StartButtonActive = true;
1070-
10711030
auto tap = GetTapRef();
1072-
if (tap)
1031+
if (!tap)
10731032
{
1074-
HRESULT hr = tap->Activate();
1075-
if (FAILED(hr))
1076-
LogToFile(STARTUP_LOG, L"Win11StartButtonTap: start activation failed 0x%08X", hr);
1033+
EnsureConnection();
10771034
return;
10781035
}
1036+
HRESULT hr = tap->Activate();
1037+
if (FAILED(hr))
1038+
LogToFile(STARTUP_LOG, L"Win11StartButtonTap: activation failed 0x%08X", hr);
1039+
}
10791040

1080-
EnsureConnection();
1041+
extern "C" void StartWin11StartButtonTap( BOOL enabled, BOOL allTaskbars )
1042+
{
1043+
g_StartButtonEnabled = enabled != FALSE;
1044+
g_AllTaskbars = allTaskbars != FALSE;
1045+
g_StartButtonActive = true;
1046+
ActivateCurrentTap();
10811047
}
10821048

10831049
extern "C" void UpdateWin11StartButtonTap( BOOL enabled, BOOL allTaskbars )
10841050
{
10851051
g_StartButtonEnabled = enabled != FALSE;
10861052
g_AllTaskbars = allTaskbars != FALSE;
1087-
1088-
if (!g_StartButtonActive)
1089-
return;
1090-
1091-
auto tap = GetTapRef();
1092-
if (tap)
1093-
{
1094-
HRESULT hr = tap->Activate();
1095-
if (FAILED(hr))
1096-
LogToFile(STARTUP_LOG, L"Win11StartButtonTap: update activation failed 0x%08X", hr);
1097-
}
1098-
else
1099-
{
1100-
EnsureConnection();
1101-
}
1053+
if (g_StartButtonActive)
1054+
ActivateCurrentTap();
11021055
}
11031056

11041057
extern "C" void StopWin11StartButtonTap( void )

0 commit comments

Comments
 (0)