Restore window position and size in macOS 12

I use this declare to save and restore a window position and size.

Restore Window Position and Size

#if TargetCocoa then
Declare function setFrameAutosaveName lib “cocoa” selector “setFrameAutosaveName:” ( NSWindowHandle as Integer, AutosaveName as CFStringRef ) as boolean
call setFrameAutosaveName( me.Handle, self.Title )
#endif

This works for macOS until release 11 like this:

With macOS 12.x the objects are no longer at the top on position 0, and there is an unwanted space.

If I resize the window interactive or per code, then the objects are place at the right position and there is no unwanted space.

Any ideas to solve this problem?

Perhaps you just have to refresh the window?
(I’ve not tested your declare, so I don’t know whether it’s just a graphical glitch or the controls’ bounds are really offset).

When the bug shows up starting in BS it’s 100% a toolbar problem. As far as I remember this fixes the problem:

'fix window height
Self.Height = Self.Height
1 Like

No, this will not help. If I use this, the problem still exists.

Self.Height = Self.Height

Only this will help: In the Open event:

Self.Height = Self.Height + 1
SleepMBS 0.5
Self.Height = Self.Height - 1

Or this will help to fix the problem.

In the OpenEven of each window:

ToolbarMain.Visible = False
ToolbarMain.Visible = true

call setFrameAutosaveName( me.Handle, self.Title )

Horst, how does one deal if/when a window changes its title when localized?
Should one use the constant of the title?
Fot instance kTitle (= “My Title” for “en” local., “Mio titolo” for “it” local. etc.)
I remember years years ago I’d not dare use it (from MacOSLibrary) for this particular reason.

Thanks.

Thank you for this hint. It is a problem with the window title. If the title has a constant value and multiple language definitions, then the problem occurs with macOS 12.2.

Now i add this in the open event, after “setFrameAutosaveName”.

self.title = langMyAppName

This problem is fixed in macOS 12.3 Beta 1

1 Like