Skip to content

Patch: Options to snap windows to screen and other form boundaries

This PR implements "magnetic" drag behavior for forms. You may rememeber this from Winamp, but in my experience many programs that don't want to do docked windows can use some way to easily align windows with the screen and with each other even if the window manager doesn't provide it.

Features

Add the ability to snap forms during move and resize to monitor edges and to other TCustomForm descendents. The behavior can be configured using TCustomForm.SnapOptions property. "Glueing" forms (snapping once, then moving together as a union) is not currently supported but could be implemented. The reason this is done in the LCL instead of a component is that intercepting the message from the outside is not easily possible from outside the class.

Compatibility

For Delphi compatibility, the ScreenSnap and and SnapBuffer properties are provided as shorthands to the new SnapOptions property, with the same default values.

This is developed on Win32, but uses only LCLIntf methods. I don't have access to any other test platform, but it looks like only the win32 interface dispatches the "while it happens" message LM_WINDOWPOSCHANGING... in that case, this would be a platform (or maybe window manager) specific feature.

Licensing

While I'm aware of the (very limited) implementation in Delphi 7 as well as JEDI's TJvFormMagnet, this is quite obviously a clean room implementation that shares nothing with these two.

If this is too limited to be useful feel free to reject, but at least this way it is somewhat searchable and maybe useful for someone.

Edited by Sebastian Hütter

Merge request reports