Sign in Join
Wiki copytemporary

Application disable resize over Dock

(macOS only)

On macOS it's often needed to disable app window's resize below OS Dock. But Lazarus forms always resize below it. How to disable this resize?

1) Create TForm.OnConstrainedResize handler for your form. Note, it was not "published" in LCL until LCL 1.7. Create it by hands:

pascal
  TfmMain = class(TForm)
    ... 
  private
    ...
    procedure FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight,
      MaxWidth, MaxHeight: TConstraintSize);
    ...
  end;

procedure TfmMain.FormCreate(Sender: TObject);
begin
  ..
  Self.OnConstrainedResize:= @FormConstrainedResize; 
  ..
end;

2) Write code in handler to change MaxHeight, value must be workarea height minus current form's Top.

pascal
procedure TfmMain.FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight,
  MaxWidth, MaxHeight: TConstraintSize);
const
  cMinHeight = 200;
var
  RWork: TRect;
begin
  {$ifndef darwin} exit; {$endif}
  RWork:= Screen.PrimaryMonitor.WorkareaRect;
  MaxHeight:= Max(cMinHeight, RWork.Bottom - RWork.Top - Top);
end;

3) Note: handler has side effect. On dragging window by its caption, handler is called too, so window will be resized on moving it too low, near the Dock.

See also


From the Free Pascal wiki, page "Application disable resize over Dock", as it stood on 2021-12-15 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.