diff --git a/src/platform/windows/window_taskbar_windows.cpp b/src/platform/windows/window_taskbar_windows.cpp index 3dc9e8f..a411eb2 100644 --- a/src/platform/windows/window_taskbar_windows.cpp +++ b/src/platform/windows/window_taskbar_windows.cpp @@ -1089,20 +1089,29 @@ class TaskbarState : public std::enable_shared_from_this { } } - // 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(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(kMaxThumbnailButtons), native_buttons.data()); + if (hr == E_INVALIDARG) { + hr = list->ThumbBarAddButtons(hwnd_, static_cast(kMaxThumbnailButtons), + native_buttons.data()); + } + } else { + hr = list->ThumbBarAddButtons(hwnd_, static_cast(kMaxThumbnailButtons), + native_buttons.data()); } if (SUCCEEDED(hr)) { - thumbbar_initialized_ = !snapshots.empty(); + thumbbar_initialized_ = true; } std::array old_icons{};