[PR #22] [MERGED] Add window size and position persistence #26

Closed
opened 2026-03-03 12:01:48 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ForLoopCodes/legacy-notepad/pull/22
Author: @Copilot
Created: 2/5/2026
Status: Merged
Merged: 3/4/2026
Merged by: @ForLoopCodes

Base: mainHead: copilot/remember-window-size-position


📝 Commits (5)

  • eba9630 Initial plan
  • 893af16 Add window size and position persistence to registry
  • 05c85f3 Improve window position handling for multi-monitor and off-screen scenarios
  • f32786f Fix signed/unsigned conversion for window coordinates using reinterpret_cast
  • c7f73ed Use static_cast for DWORD to int conversion with explanatory comments

📊 Changes

4 files changed (+113 additions, -2 deletions)

View changed files

📝 src/core/types.h (+4 -0)
📝 src/main.cpp (+17 -1)
📝 src/modules/settings.cpp (+90 -1)
📝 src/modules/settings.h (+2 -0)

📄 Description

Implements window geometry persistence to registry, matching native Notepad behavior.

Implementation

  • State: Added windowX, windowY, windowWidth, windowHeight to AppState with 640×480 default
  • Storage: New LoadWindowSettings() / SaveWindowSettings() functions write to HKEY_CURRENT_USER\Software\LegacyNotepad
  • Lifecycle: Load on startup before CreateWindowExW(), save on WM_DESTROY using GetWindowPlacement().rcNormalPosition

Edge Cases

  • Multi-monitor: Negative coordinates preserved via static_cast<int>(DWORD) round-trip
  • Off-screen: MonitorFromRect() validation resets to CW_USEDEFAULT if no monitor intersection
  • Maximized state: Uses rcNormalPosition so window doesn't reopen maximized unintentionally

Registry keys: WindowX, WindowY, WindowWidth, WindowHeight (REG_DWORD)

Original prompt

This section details on the original issue you should resolve

<issue_title>Remember window size and maybe position</issue_title>
<issue_description>Hello again!

Not really a bug or an issue but the og notepad remembers the window size and position of the last session. Since you already put font and always on top settings in the registry I guess this can be put there too?

Have a nice day and thanks!</issue_description>

Comments on the Issue (you are @copilot in this section)


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ForLoopCodes/legacy-notepad/pull/22 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 2/5/2026 **Status:** ✅ Merged **Merged:** 3/4/2026 **Merged by:** [@ForLoopCodes](https://github.com/ForLoopCodes) **Base:** `main` ← **Head:** `copilot/remember-window-size-position` --- ### 📝 Commits (5) - [`eba9630`](https://github.com/ForLoopCodes/legacy-notepad/commit/eba963074aa5107168237a765b275ffec47ad461) Initial plan - [`893af16`](https://github.com/ForLoopCodes/legacy-notepad/commit/893af16bcf416c8878118cd41c36671efeab1aa9) Add window size and position persistence to registry - [`05c85f3`](https://github.com/ForLoopCodes/legacy-notepad/commit/05c85f323588ab44d3cc2a007271ec2f799a0041) Improve window position handling for multi-monitor and off-screen scenarios - [`f32786f`](https://github.com/ForLoopCodes/legacy-notepad/commit/f32786f3b654e91184675c99fdf95e18d279a1f3) Fix signed/unsigned conversion for window coordinates using reinterpret_cast - [`c7f73ed`](https://github.com/ForLoopCodes/legacy-notepad/commit/c7f73ed1d80f425a934c394a73318b3eaa9e960d) Use static_cast for DWORD to int conversion with explanatory comments ### 📊 Changes **4 files changed** (+113 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/core/types.h` (+4 -0) 📝 `src/main.cpp` (+17 -1) 📝 `src/modules/settings.cpp` (+90 -1) 📝 `src/modules/settings.h` (+2 -0) </details> ### 📄 Description Implements window geometry persistence to registry, matching native Notepad behavior. ### Implementation - **State**: Added `windowX`, `windowY`, `windowWidth`, `windowHeight` to `AppState` with 640×480 default - **Storage**: New `LoadWindowSettings()` / `SaveWindowSettings()` functions write to `HKEY_CURRENT_USER\Software\LegacyNotepad` - **Lifecycle**: Load on startup before `CreateWindowExW()`, save on `WM_DESTROY` using `GetWindowPlacement().rcNormalPosition` ### Edge Cases - **Multi-monitor**: Negative coordinates preserved via `static_cast<int>(DWORD)` round-trip - **Off-screen**: `MonitorFromRect()` validation resets to `CW_USEDEFAULT` if no monitor intersection - **Maximized state**: Uses `rcNormalPosition` so window doesn't reopen maximized unintentionally Registry keys: `WindowX`, `WindowY`, `WindowWidth`, `WindowHeight` (REG_DWORD) <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Remember window size and maybe position</issue_title> > <issue_description>Hello again! > > Not really a bug or an issue but the og notepad remembers the window size and position of the last session. Since you already put font and always on top settings in the registry I guess this can be put there too? > > Have a nice day and thanks!</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes ForLoopCodes/legacy-notepad#20 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/ForLoopCodes/legacy-notepad/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem changed title from [PR #22] Add window size and position persistence to [PR #22] [MERGED] Add window size and position persistence 2026-03-15 16:02:12 +03:00
kerem closed this issue 2026-03-15 16:02:23 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/legacy-notepad#26
No description provided.