Skip to content
Merged
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. Newer
// Windows 11 shells (e.g. build 26300) return S_OK from a second
// ThumbBarAddButtons while leaving the existing toolbar untouched, so
// adding first on every sync silently drops later property changes.
// Update first when already initialized, and fall back to
// ThumbBarAddButtons if the shell recreated the taskbar item and returns
// E_INVALIDARG (ReplayAllOnWindowThread also resets thumbbar_initialized_
// 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
Loading