tl;dr alert!
Just to try and sum up the changes to handle multiple screens with multiple monitors arrangement correctly as well as the just single virtual screen X setup, @ed95, I would suggest that apart from my further modification suggested above to the push you made, I would remove the loop with the call
GetXProperty prop(display, RootWindow(display, i), hints, 0, 4, false, XA_CARDINAL);
And let it drop through and use the logic following that. This prevents it failing on the second screen.
There are still some inconsistencies: if xrandr or xinerama is used then the single virtual screen over 2 monitors is considered 2 JUCE displays, if they are not used its a single display with geometry of the whole virtual screen.
e.g. to hopefully clarify, this is what I get with a 1920x1080 and a 2560x1440 monitor for the different screen set-ups and the different methods for creating the JUCE displays:
(switching to preformatted text to keep idents):
App calling Displays::findDisplays with both monitors on same screen, default X configuration when DISPLAY=:1.0
xrandr - if enabled
0. 0,0 1920 x 1080
1. 1920,0 2560 x 1440
xinerama - if enabled
0. 0,0 1920 x 1080
1. 1920,0 2560 x 1440
loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 4480 x 1440
loop following loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 4480 x 1440
N.B. xrandr and xinerama returns the 2 physical displays, the others return the virtual screen geometries.
App calling Displays::findDisplays with one monitors on one screen, one on the other, on screen 0, when DISPLAY=:1.0
xrandr - if enabled
0. 0,0 1920 x 1080**
xinerama - if enabled
Call to XineramaQueryDisplays doesn’t return anything
loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 1920 x 1080
loop following loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 1920 x 1080
App calling Displays::findDisplays with one monitors on one screen, one on the other, on screen 1 when DISPLAY=:1.1
xrandr - if enabled
0. 0,0 2560 x 1440*
xinerama - if enabled
Call to XineramaQueryDisplays doesn’t return anything
loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 1920 x 1080***
loop following loop with GetXProperty prop(display, RootWindow(display, i).... call
0. 0,0 2560 x 1440
* before any changes this was returning 2 displays each 0,0 1920 x 1080. Correct result should be a single display 0,0 1920 x 1080
** before any changes this was returning 2 displays each 0,0 1920 x 1080. After the initial change this was return 0,0 1920 x 1080. Correct result should be a single display 0,0 2560 x 1440
*** this is wrong, hence suggestion this loop should be removed.