Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/platform/windows/window_taskbar_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,20 +1089,29 @@ class TaskbarState : public std::enable_shared_from_this<TaskbarState> {
}
}

// Attempt ThumbBarAddButtons first on every sync: hiding a window destroys
// its shell taskbar item, so on restore a cached boolean would call
// ThumbBarUpdateButtons (which silently returns S_OK without recreating the
// buttons). When buttons already exist on the active taskbar item,
// ThumbBarAddButtons returns E_INVALIDARG and we fall back to
// ThumbBarUpdateButtons.
HRESULT hr = list->ThumbBarAddButtons(hwnd_, static_cast<UINT>(kMaxThumbnailButtons),
native_buttons.data());
if (hr == E_INVALIDARG) {
// The toolbar is created once per shell taskbar item; afterwards its
// buttons can only be changed through ThumbBarUpdateButtons. Current
// Windows 11 shells return S_OK from a second ThumbBarAddButtons while
// leaving the existing toolbar untouched, so adding first on every sync
// silently drops every later state change (icons / enabled flags).
// Update first and fall back to ThumbBarAddButtons only when the toolbar
// is gone, reported as E_INVALIDARG after the shell recreates the taskbar
// item (restore from hide, Explorer restart); ReplayAllOnWindowThread
// also resets the flag on TaskbarButtonCreated.
HRESULT hr = S_OK;
if (thumbbar_initialized_) {
hr = list->ThumbBarUpdateButtons(hwnd_, static_cast<UINT>(kMaxThumbnailButtons),
native_buttons.data());
if (hr == E_INVALIDARG) {
hr = list->ThumbBarAddButtons(hwnd_, static_cast<UINT>(kMaxThumbnailButtons),
native_buttons.data());
}
} else {
hr = list->ThumbBarAddButtons(hwnd_, static_cast<UINT>(kMaxThumbnailButtons),
native_buttons.data());
}
if (SUCCEEDED(hr)) {
thumbbar_initialized_ = !snapshots.empty();
thumbbar_initialized_ = true;
}

std::array<HICON, kMaxThumbnailButtons> old_icons{};
Expand Down