I’m using the following which seems to work fine on my Desktop iMac but not on my MacBook Pro. On the Desktop I get a centred screen for my app but on the MacBook I get a window pushed off to the right. What have I missed?

MainWindow.Width = screen(0).AvailableWidth *.65
MainWindow.Height = screen(0).AvailableHeight *.8

//Centre Window
Dim tScreen as screen = screen( 0)
Dim newFrame as new Rect( 0, 0,mainwindow.width, mainwindow.height)
newFrame.left = ( ( tScreen.availableWidth - newFrame.width ) * 0.5 ) + tScreen.availableLeft = min( ( ( tScreen.availableHeight - newFrame.height+tScreen.availableTop ) * 0.5 ) + tScreen.availableTop, tScreen.availableTop*2 )
me.bounds = newFrame

newFrame.left = ( ( tScreen.availableWidth - newFrame.width ) * 0.5 ) + tScreen.availableLeft

this basically calculates the left offset twice and adds it.

Here’s the debug for your code on my M1 MBP:

MainWindow sees centered horizontally, but not vertically.

MainWindow was added to a current project and displayed at run time. Your code is in MainWindow.Open.
MainWindow size is Xojo default size.

Thanks for the pickup Christian. Even with that change the when run on the MacBook it still displays off centre and off screen slightly.
I thought if I moved that code to the App open event it might make a difference but it is still the same??

Thanks Emile

Ok, some more info. The code does behave and centre horizontally if I set the MacBook display to the maximum scaled display size but not on any other setting.

Oh ! That is why it worked here…

1 Like    !=
window.height != window.bounds.height is the top point of the content area (top + window chrome height). is the top point of the window.
window.height is the height of the content area of the window.
window.bounds.height is the height of the content area + window chrome height.

The top and height behave as expected (even though I have things a little muddled).
The horizontal adjustment is what is not consistent between iMac and MacBook.
Does the .availablewidth take screen scale into consideration or does it just look at maximum availability?

My bad, sorry.

Well, you’ve got gold here as you have a machine that can reproduce the problem. I would suggest using system.debuglog to make sure that the values are what you think they should be.
Write out the screen dimensions, then the available dimensions, then the window dimensions.

1 Like

Have you checked, on your machine, how much equals Screen(0).Width-Screen(0).AvailableWidth, just to be sure the difference is what you expect?

Macbook Pros give a message that on the lowest resolution Apps may not appear correct so I think I will stop chasing this one.