Skip to content

Fix AlwaysOnTop sound playing when pin/unpin fails#46910

Merged
niels9001 merged 2 commits intomainfrom
copilot/fix-sound-on-pin-unpin-failure
Apr 13, 2026
Merged

Fix AlwaysOnTop sound playing when pin/unpin fails#46910
niels9001 merged 2 commits intomainfrom
copilot/fix-sound-on-pin-unpin-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

Summary of the Pull Request

ProcessCommand played the pin/unpin sound unconditionally, regardless of whether SetWindowPos succeeded. This caused spurious audio feedback when targeting desktop, taskbar, task view, start menu, or elevated windows from a non-elevated process.

Gate sound playback on actual state change:

bool stateChanged = false;
// ...
if (UnpinTopmostWindow(window)) { stateChanged = true; /* ... */ }
// ...
if (PinTopmostWindow(window))   { stateChanged = true; /* ... */ }
// ...
if (stateChanged && AlwaysOnTopSettings::settings()->enableSound)
    m_sound.Play(soundType);

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

PinTopmostWindow and UnpinTopmostWindow already return bool indicating success, and the existing code already branches on those return values for bookkeeping and telemetry — but the sound playback at the end of ProcessCommand ignored the result. Added a stateChanged flag set only inside the success branches, then checked before calling m_sound.Play().

Validation Steps Performed

  • Verified that the soundType / stateChanged logic covers all four paths: pin success, pin failure, unpin success, unpin failure.
  • Code review passed with no comments.

Copilot AI linked an issue Apr 11, 2026 that may be closed by this pull request
1 task
Only play sound when PinTopmostWindow or UnpinTopmostWindow
succeeds. Previously, sound played regardless of the operation
result, causing incorrect audio feedback when attempting to
pin/unpin desktop, taskbar, or elevated windows.

Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/2b34eb87-b088-4fa7-8973-25b86b249adb

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sound played when pin/unpin fail in Always On Top Fix AlwaysOnTop sound playing when pin/unpin fails Apr 11, 2026
Copilot AI requested a review from niels9001 April 11, 2026 23:47
@niels9001
Copy link
Copy Markdown
Collaborator

@vanzue Can you verify if the changes make sense?

@niels9001 niels9001 requested a review from vanzue April 12, 2026 09:18
@niels9001 niels9001 marked this pull request as ready for review April 12, 2026 09:18
@vanzue
Copy link
Copy Markdown
Contributor

vanzue commented Apr 12, 2026

The code looks straight forward, and I'm just hesitating about the behavior, imagine I'm trying to hit shortcut, nothing changed, and nothing happen(sound), I will then wonder whether if I'm hitting the wrong hotkey for it, so currently user know something is happening, but he pin/unpin failed, I'm not sure which one is prefered

@niels9001
Copy link
Copy Markdown
Collaborator

The code looks straight forward, and I'm just hesitating about the behavior, imagine I'm trying to hit shortcut, nothing changed, and nothing happen(sound), I will then wonder whether if I'm hitting the wrong hotkey for it, so currently user know something is happening, but he pin/unpin failed, I'm not sure which one is prefered

  1. Do we know why this fails sometimes?
  2. Users might turn off the sounds (I do), I still don't get any feedback if it doesn't work. So yeah, this 'bug' kinda addresses it but not always.
  3. I think we should fix this bug, and then figure out what a good way is to let users know it didn't work.

Thoughts?

@vanzue
Copy link
Copy Markdown
Contributor

vanzue commented Apr 12, 2026

OK, agree, some window can't be pinned, I think this pr is safe and helps, although some distance from absolute fix.
For 1, I can't get a full picture yet, but I think I'm good with this pr

@niels9001 niels9001 merged commit f8cadbf into main Apr 13, 2026
15 checks passed
@LegendaryBlair LegendaryBlair added this to the PowerToys 0.99 milestone Apr 16, 2026
@LegendaryBlair LegendaryBlair added the Product-Always On Top Refers to the idea of a Always on Top Powertoy label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.99 Product-Always On Top Refers to the idea of a Always on Top Powertoy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AlwaysOnTop] Sound played when pin/unpin fail

4 participants