Fix AlwaysOnTop sound playing when pin/unpin fails#46910
Conversation
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>
|
@vanzue Can you verify if the changes make sense? |
|
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 |
Thoughts? |
|
OK, agree, some window can't be pinned, I think this pr is safe and helps, although some distance from absolute fix. |
Summary of the Pull Request
ProcessCommandplayed the pin/unpin sound unconditionally, regardless of whetherSetWindowPossucceeded. 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:
PR Checklist
Detailed Description of the Pull Request / Additional comments
PinTopmostWindowandUnpinTopmostWindowalready returnboolindicating success, and the existing code already branches on those return values for bookkeeping and telemetry — but the sound playback at the end ofProcessCommandignored the result. Added astateChangedflag set only inside the success branches, then checked before callingm_sound.Play().Validation Steps Performed
soundType/stateChangedlogic covers all four paths: pin success, pin failure, unpin success, unpin failure.