Hi all, I’m trying to add some final embellishments to a Mac app - and make it as ‘Mac’ like as possible.
Is it therefore possible to detect which screen the app was launched on, like Apple’s own apps do? i.e. if you open an app from either a dock or a finder window other than screen(0), it will open on that window… I can’t figure this out, maybe there’s a Declare?
Add this function to your window, or somewhere it is accessible globally:
Public Function ScreenIndexGet(w As DesktopWindow) As Int32
Var index As Int32 = 0
If DesktopDisplay.DisplayCount > 1 Then
Var b As Rect = w.Bounds
Var x As Int32 = b.Left + b.Width / 2
Var y As Int32 = b.top + b.Height / 2
Var iLast As Int32 = DesktopDisplay.LastDisplayIndex
Var s As DesktopDisplay
For i As Int32 = 0 To iLast
s = DesktopDisplay.DisplayAt(i)
If x >= s.Left And y >= s.top And x <= s.Left + s.Width And y <= s.top + s.Height Then
index = i
Exit For i
End If
Next i
End If
Return index
End Function
Then call it like so:
Var currentScreen As Int32 = Self.ScreenIndexGet(Self)
The screen index is based on how Xojo manages them in the DesktopDisplay class.
Basically the logic takes the current Window’s Top and Left positions (adjusted in case one screen is much smaller than another), then loops through all the displays of your machine to see if the Top & Left position is within one of those screens - then returns the screen index it was found in.
Ideally what I need to know is which screen the app was launched from, before any windows are placed anywhere - that way, like other Mac (Apple) apps, I can then choose where to place the windows…
In the IDE, Design Mode, Window Editor, near the bottom → Default Location.
Changing this value - in the popup menu - will change the location that window will be opened. That is what Tim was talking about some entries ago.
Of course, yu may have tested that and this is not what you’re searching. In that case, your only solution is to set yourself the window left location at Opening time.