Send WM_SIZING during resize for grid-snapping apps#723
Send WM_SIZING during resize for grid-snapping apps#723andrewachen wants to merge 2 commits intoRamonUnch:mainfrom
Conversation
The flag field was written to snwnds.it[snwnds.num] before ListAppend allocated the slot, causing a write past the end of the buffer when the list was full. Store the flag in a local variable and write it to new_wnd->flag after ListAppend, matching the safe pattern used in EnumStackedWindowsProc. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Sponsored-By: Netflix
Terminal emulators (mintty, PuTTY, etc.) and other apps that snap to a character-cell grid need WM_SIZING to adjust the proposed rect to their grid boundaries. AltSnap was calling SetWindowPos directly, bypassing this. There was already commented-out code attempting this. Send WM_SIZING via SendMessageTimeout (SMTO_ABORTIFHUNG, 32ms) before SetWindowPos when resizing. The app-adjusted rect is read back and used for the final SetWindowPos. A lookup table maps the current resize direction (state.resize.x/y) to the correct WMSZ_* edge constant. Respects the existing SSizeMove blacklist. Apps that don't handle WM_SIZING are unaffected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Sponsored-By: Netflix
|
??? You are sending with WM_SIZING message to another process with a pointer to your own memory? This is not possible because since we run in protected mode on Win32 every process has its own address space. I will have a look about the ListAppend problem Have you even tested the code? Also sending a WM_SIZING message is not a documented way of resizing a window,, the Win32 API gust guarenties that you will receive it while resizing. I would not rely on it even if it were to work. |
|
Thanks for the review and for taking the time to look at this! On the cross-process pointer concern: That's a reasonable worry, but it turns out
So the On WM_SIZING not being a documented resize API: That's a fair point — the docs do describe it as "sent to a window that the user is resizing," so it's a notification rather than a command. But since AltSnap already synthesizes I have been testing this locally and it fixes the grid-snapping issue for both Windows Terminal and wsltty. Apps that don't handle Happy to hear if you have other concerns or suggestions for a better approach! |
|
@RamonUnch -- would it be ok to reopen this PR given the above information? |
|
this is true for WM_ENTER/WM_EXITSIZEMOVE, they are optional and are a legacy of original AltDarg, also they require no marshaling. I thought the list of system message that were actually marshaled were very little. |
|
Sorr ignore the above I misred your changes |
|
I will try it myself and see what happens, then |
Summary
Fix buffer overrun in EnumSnappedWindows:
snwnds.it[snwnds.num].flagwas written beforeListAppendallocated the slot, causing a write past the buffer when full. Now stores the flag in a local and writes it afterListAppend, matching the safe pattern inEnumStackedWindowsProc.Send WM_SIZING before SetWindowPos during resize: Terminal emulators (mintty, PuTTY, etc.) and other apps that snap to a character-cell grid need
WM_SIZINGto adjust the proposed rect to their grid boundaries. AltSnap was callingSetWindowPosdirectly, bypassing this. There was already commented-out code attempting this.Sends
WM_SIZINGviaSendMessageTimeout(SMTO_ABORTIFHUNG, 32ms) beforeSetWindowPoswhen resizing. The app-adjusted rect is read back and used for the final positioning. A lookup table maps the current resize direction (state.resize.x/y) to the correctWMSZ_*edge constant. Respects the existingSSizeMoveblacklist. Apps that don't handleWM_SIZINGare unaffected.Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
Sponsored-By: Netflix