# Detect launch screen

**URL:** <https://forum.xojo.com/t/detect-launch-screen/83447>\
**Category:** macOS\
**Created:** [December 3, 2024, 6:04pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447 "2024-12-03T18:04:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Yeaman](https://forum.xojo.com/user_avatar/forum.xojo.com/david_yeaman/32/1674_2.png) [@David\_Yeaman](https://forum.xojo.com/u/David_Yeaman)\
**Post date:** [December 3, 2024, 6:04pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/1 "2024-12-03T18:04:51Z")

</div>

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?

Tia

Dave.

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [December 3, 2024, 6:16pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/2 "2024-12-03T18:16:44Z")

</div>

What is your Window’s `DefaultLocation` property set to?  
I find I get better Mac-like behavior by using “Parent Window Screen”.

---

<div class="post-metadata">

**Author:** ![Scott\_C](https://forum.xojo.com/user_avatar/forum.xojo.com/scott_c/32/19612_2.png) [@Scott\_C](https://forum.xojo.com/u/Scott_C)\
**Post date:** [December 3, 2024, 7:24pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/3 "2024-12-03T19:24:36Z")

</div>

> [@David\_Yeaman](#):
>
> Is it therefore possible to detect which screen the app was launched on

This is what I use.

Add this function to your window, or somewhere it is accessible globally:

```auto
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:

```auto
Var currentScreen As Int32 = Self.ScreenIndexGet(Self)

```

The screen index is based on how Xojo manages them in the [DesktopDisplay](https://documentation.xojo.com/api/user_interface/desktop/desktopdisplay.html#desktopdisplay-displayat) 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.

---

<div class="post-metadata">

**Author:** ![David\_Yeaman](https://forum.xojo.com/user_avatar/forum.xojo.com/david_yeaman/32/1674_2.png) [@David\_Yeaman](https://forum.xojo.com/u/David_Yeaman)\
**Post date:** [December 4, 2024, 11:28am UTC](https://forum.xojo.com/t/detect-launch-screen/83447/4 "2024-12-04T11:28:03Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [December 4, 2024, 1:10pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/5 "2024-12-04T13:10:24Z")

</div>

You may explore what is the use of:

 ![image](https://forum.xojo.com/uploads/default/original/3X/1/5/1595f7c966f3c9fa87d94077b93b7cd290abdde9.png)

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.

---

<div class="post-metadata">

**Author:** ![David\_Yeaman](https://forum.xojo.com/user_avatar/forum.xojo.com/david_yeaman/32/1674_2.png) [@David\_Yeaman](https://forum.xojo.com/u/David_Yeaman)\
**Post date:** [December 4, 2024, 1:15pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/6 "2024-12-04T13:15:14Z")

</div>

It’s OK, I think this is a case of me not explaining my query in the correct terms.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [January 5, 2025, 11:53pm UTC](https://forum.xojo.com/t/detect-launch-screen/83447/7 "2025-01-05T23:53:48Z")

</div>

In the opening even of the main window you could store and set an integer holding it’s startingatscreen index. Whenever a next window is opened, you check and relocate the screen on demand.

You can use the code that scot has posted to do this.

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [January 6, 2025, 8:49am UTC](https://forum.xojo.com/t/detect-launch-screen/83447/8 "2025-01-06T08:49:01Z")

</div>

DesktopDisplay(0) returns the default screen. IIRC, this is the screen where windows that have no previous stored locations should open at.

`Var MainScreen As DesktopDisplay=DesktopDisplay.DisplayAt(0)`
