# Popmenu opens at wrong display - multiscreen setup

**URL:** <https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335>\
**Category:** General JUCE discussion\
**Created:** [November 24, 2007, 4:01pm UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335 "2007-11-24T16:01:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [November 24, 2007, 4:01pm UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335/1 "2007-11-24T16:01:34Z")

</div>

Hi Jules,

i’m using the latest version from SVN. I opening a popup menu in my plugin ( with show and showAt ). When i click on the first monitor, it appears on the second.

That was not the case with an earlier version.

With the old version of Desktop::getMonitorAreaContaining (changed on 15.Nov) the problem does not happen.

[code]/\* !new version

const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()  
{  
Rectangle best (getMainMonitorArea (clippedToWorkArea));  
double bestDistance = 1.0e10;

```
for (int i = getNumDisplayMonitors(); --i > 0;)
{
    const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
    const double distance = juce_hypot ((double) (rect.getCentreX() - cx), 
                                        (double) (rect.getCentreY() - cy));

    if (distance < bestDistance)
    {
        bestDistance = distance;
        best = rect;
    }
}

return best;

```

}\*/

const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()  
{

```
for (int i = getNumDisplayMonitors(); --i > 0;)
{
    const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));

    if (rect.contains (cx, cy))
        return rect;

}

return getMainMonitorArea (clippedToWorkArea);

```

}[/code]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 24, 2007, 5:17pm UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335/2 "2007-11-24T17:17:11Z")

</div>

Oh sorry, I was trying something out there… What I meant was this:

[code] for (int i = getNumDisplayMonitors(); --i \> 0;)  
{  
const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));

```
    if (rect.contains (cx, cy))
        return rect;

    const double distance = juce_hypot ((double) (rect.getCentreX() - cx), 
                                        (double) (rect.getCentreY() - cy));

    if (distance < bestDistance)
    {
        bestDistance = distance;
        best = rect;
    }
}[/code]

```

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [November 27, 2007, 12:30pm UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335/3 "2007-11-27T12:30:42Z")

</div>

mmmh, does not work

did you mean:

```auto

```

instead of

```auto

```

😉

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 27, 2007, 12:41pm UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335/4 "2007-11-27T12:41:52Z")

</div>

well done, you spotted my deliberate mistake there…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:05am UTC](https://forum.juce.com/t/popmenu-opens-at-wrong-display-multiscreen-setup/2335/5 "2017-05-12T10:05:45Z")

</div>

Closed on May 12, 2017, 10:05am UTC


