PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[CmdPal] Added recenter window support.

Open shuaiyuanxx opened this issue 8 months ago • 11 comments

Summary of the Pull Request

Added a new setting option to Command Palette that allows users to choose whether the window should be recentered on every launch or remember its last position. This enhancement improves user experience by maintaining window positioning preferences across sessions.

PR Checklist

  • [x] Closes: #38310
  • [x] Communication: I've discussed this with core contributors already. If 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

This PR adds a "Recenter window on launch" setting to Command Palette with the following changes:

  1. Added a new RecenterWindow property to SettingsModel (default is true for backward compatibility)
  2. Added corresponding property to SettingsViewModel for binding
  3. Created a new WindowPosition class to track window position and size
  4. Modified MainWindow.xaml.cs to:
    • Track window position and size changes
    • Update position memory when window is modified or dismissed
    • Respect the recenter setting when showing the window
  5. Added UI controls in the settings page with proper localization strings image

This feature allows users who prefer to have the Command Palette appear in a specific screen location to maintain that preference, while others can continue using the centered window behavior.

Validation Steps Performed

  1. Manually verified that with the setting enabled (default), the window centers on launch
  2. Verified that with the setting disabled, the window appears at its last position

shuaiyuanxx avatar Apr 18 '25 02:04 shuaiyuanxx

Can we move the new setting nearby the monitor selection setting? Would make sense

htcfreek avatar Apr 18 '25 09:04 htcfreek

Can we move the new setting nearby the monitor selection setting? Would make sense

Done.

shuaiyuanxx avatar Apr 18 '25 09:04 shuaiyuanxx

Ok, fine. Let me summarize:

currently, we will always open cmdpal in the center right?

After this change, we can:

  1. Open cmdpal in the center.
  2. Open cmdpal in the last position.

I think the config text is wired. We have one behaviour as default (open in the center), so we need to add a settings for another behaviour, right?

I think "Always Open in the center" or "Open in the last position" is better. We don't need to mix the two behaviour in one description.

moooyo avatar Apr 21 '25 05:04 moooyo

Ok, fine. Let me summarize:

currently, we will always open cmdpal in the center right?

After this change, we can:

  1. Open cmdpal in the center.
  2. Open cmdpal in the last position.

I think the config text is wired. We have one behaviour as default (open in the center), so we need to add a settings for another behaviour, right?

I think "Always Open in the center" or "Open in the last position" is better. We don't need to mix the two behaviour in one description.

We do not have any setting to control the window open position. After adding this setting, user can control the window open position, and by default it will always be opened in center of screen, if user want to open the window at the place where it was closed last time, they can disable this setting.

shuaiyuanxx avatar Apr 23 '25 02:04 shuaiyuanxx

/azp run

shuaiyuanxx avatar Apr 24 '25 00:04 shuaiyuanxx

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

azure-pipelines[bot] avatar Apr 24 '25 00:04 azure-pipelines[bot]

/azp run

shuaiyuanxx avatar Apr 24 '25 06:04 shuaiyuanxx

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Apr 24 '25 06:04 azure-pipelines[bot]

Okay I just checked this branch out. My immediate thought is that if this setting overrides the setting from SummonOn, then it should just be another enum value of MonitorBehavior, it shouldn't be a separate boolean

zadjii-msft avatar May 05 '25 18:05 zadjii-msft

Okay I just checked this branch out. My immediate thought is that if this setting overrides the setting from SummonOn, then it should just be another enum value of MonitorBehavior, it shouldn't be a separate boolean

Looks like it need more thinking and time for this PR.

The PR current implementation doesn't persist the "position" to disk, i.e. there is still need a behavior on "new launch" Moreover, there will be still plug and unplug new monitor scenario which it need fallback setting.

The perfect case should be it remember my common monitors setting up to X, and remember the position per a given monitors setting even on relaunch.

yeelam-gordon avatar May 06 '25 06:05 yeelam-gordon

Yea I concur. Let's pull this one from 0.91 and get this early in 0.92

zadjii-msft avatar May 06 '25 09:05 zadjii-msft

Hiya @shuaiyuanxx, looks like we're still needing:

  • Persist location to disk
  • Set location on startup

Is that it?

michaeljolley avatar Aug 19 '25 20:08 michaeljolley

Hiya @shuaiyuanxx, looks like we're still needing:

  • Persist location to disk
  • Set location on startup

Is that it?

I think so.

shuaiyuanxx avatar Aug 20 '25 06:08 shuaiyuanxx