FancyZones: apply edited custom layout spacing/sensitivity/zone count to active work areas immediately - #49433
Open
MuyuanMS wants to merge 1 commit into
Conversation
…to active work areas immediately When a custom layout is edited in the FancyZones editor, active work areas already using that layout only refreshed the grid shape/edges. Scalar properties (spacing, sensitivity radius, and zone count) were read from a stale applied-layouts snapshot, so edits to them did not take effect on existing windows until PowerToys/FancyZones was restarted. WorkArea::CalculateZoneSet now re-derives the scalar properties from the live CustomLayouts store (CustomLayouts::instance().GetLayout(uuid)) for Custom-type layouts, matching the values used on the apply path. Scoped to Custom layouts only; at apply-time the values equal the snapshot, so only genuine edits change behavior. Adds a regression test (EditedCustomLayoutSpacingRefreshesExistingWorkArea) that creates a work area, edits the custom layout spacing, re-inits the layout, and asserts the new spacing gap is applied to existing zones. Co-authored-by: Copilot <[email protected]> Copilot-Session: 19f7171d-0ca4-48dc-95ef-e50f505a9097
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a FancyZones refresh gap where editing an already-applied custom layout would update zone geometry but leave scalar properties (spacing / sensitivity radius / canvas zone count) stale until restart or re-apply. It updates the runtime refresh path so active work areas rehydrate these values from the live custom-layouts.json store and ensures the module triggers a layout refresh when that store changes.
Changes:
- In
WorkArea::CalculateZoneSet, for Custom layouts, refreshLayoutDatafromCustomLayouts::GetLayout(uuid)before constructing theLayout, so scalar properties reflect the edited layout immediately. - In
FancyZonesmessage handling, refresh active layouts whencustom-layouts.jsonchanges (WM_PRIV_CUSTOM_LAYOUTS_FILE_UPDATE). - Add a regression unit test that edits custom grid spacing and verifies an existing
WorkAreareflects the new spacing afterInitLayout().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/modules/fancyzones/FancyZonesTests/UnitTests/WorkArea.Spec.cpp | Adds a regression test that validates edited custom-layout spacing is applied to an already-created work area after refresh. |
| src/modules/fancyzones/FancyZonesLib/WorkArea.cpp | Refreshes LayoutData for custom layouts from the live CustomLayouts store during zone set calculation. |
| src/modules/fancyzones/FancyZonesLib/FancyZones.cpp | Calls RefreshLayouts() on WM_PRIV_CUSTOM_LAYOUTS_FILE_UPDATE so active work areas re-init after custom layouts reload. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
When a custom layout is edited in the FancyZones editor while windows are already snapped to it, changes to the layout's scalar properties — spacing between zones, highlight/activation sensitivity radius, and zone count (for canvas layouts) — were not applied to already-active work areas until PowerToys (or FancyZones) was restarted. Only the grid shape/edges refreshed live.
This PR makes those scalar edits take effect immediately on existing work areas, resolving the remaining gap in issue 44058.
PR Checklist
EditedCustomLayoutSpacingRefreshesExistingWorkArearegression test; existing FancyZones unit tests pass.Detailed Description of the Pull Request / Additional comments
Root cause
For a Custom-type layout,
WorkArea::CalculateZoneSetbuilds itsLayoutfromAppliedLayouts::GetDeviceLayout(), which returns a snapshot fromapplied-layouts.json. The zone shape is read live from theCustomLayoutsstore, but the scalar properties (spacing,sensitivityRadius, andzoneCount) were taken from that stale applied-layouts snapshot. So when the editor updated the custom layout and firedWM_PRIV_CUSTOM_LAYOUTS_FILE_UPDATE, the existing work areas re-laid-out their grid geometry but kept the old spacing/sensitivity/zone count.The fix
In
WorkArea::CalculateZoneSet, for Custom-type layouts, re-derive the scalar properties from the liveCustomLayoutsstore instead of the stale snapshot:CustomLayouts::GetLayoutreturns the canonicalLayoutDataused by the apply path (it derives grid zone count fromzoneCount()and canvas zone count fromzones.size()), so the refreshed values exactly match what a fresh apply would produce.Why this is low-risk:
This complements the editor-side
RefreshLayouts()call (which refreshes zone shape) so that all properties of an edited custom layout now apply live.Validation Steps Performed
Automated: Added
EditedCustomLayoutSpacingRefreshesExistingWorkAreainFancyZonesTests/UnitTests/WorkArea.Spec.cpp. It creates a work area on a grid custom layout, asserts adjacent zones are flush, then edits the custom layout's spacing, re-initializes the layout viaInitLayout(), and asserts the new spacing gap is present on the existing zones. Built the FancyZones unit tests and ran theWorkAreasuite — all pass.Manual (end-to-end):