Sign in Join
Wiki copytemporary

Application disable resize over Dock: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Application disable resize over Dock

OldNewLine
1+*(macOS only)*
2+
3+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?
4+
5+1\) Create TForm.OnConstrainedResize handler for your form. Note, it was not "published" in LCL until LCL 1.7. Create it by hands:
6+
7+``` pascal
8+ TfmMain = class(TForm)
9+ ...
10+ private
11+ ...
12+ procedure FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight,
13+ MaxWidth, MaxHeight: TConstraintSize);
14+ ...
15+ end;
16+
17+procedure TfmMain.FormCreate(Sender: TObject);
18+begin
19+ ..
20+ Self.OnConstrainedResize:= @FormConstrainedResize;
21+ ..
22+end;
23+```
24+
25+2\) Write code in handler to change MaxHeight, value must be workarea height minus current form's Top.
26+
27+``` pascal
28+procedure TfmMain.FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight,
29+ MaxWidth, MaxHeight: TConstraintSize);
30+const
31+ cMinHeight = 200;
32+var
33+ RWork: TRect;
34+begin
35+ {$ifndef darwin} exit; {$endif}
36+ RWork:= Screen.PrimaryMonitor.WorkareaRect;
37+ MaxHeight:= Max(cMinHeight, RWork.Bottom - RWork.Top - Top);
38+end;
39+```
40+
41+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.
42+
43+## See also
44+
45+- [[Bounce Application Icon in Dock]]
46+- [[Hiding a macOS app from the Dock]]
47+- [[macOS Application Dock Menu]]
48+- [[Show Badge on Application Icon in Dock]]
49+
50+---
51+*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](/wiki-contact).*
52+Category: Code Snippets
53+Category: macOS

Back to history