Fix for Xinerama


#1

Hi,

On the new debian system, the xinerama library is “libXinerama.so.1” (and no more “libXinerama.so”).
I propose to update the code to:

void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
{
    if (display == 0)
        return;

#if JUCE_USE_XINERAMA
    int major_opcode, first_event, first_error;

    ScopedXLock xlock;
    if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
    {
        typedef Bool (*tXineramaIsActive) (Display*);
        typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);

        static tXineramaIsActive xXineramaIsActive = 0;
        static tXineramaQueryScreens xXineramaQueryScreens = 0;

        if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
        {
            void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
+            if (h == 0) h = dlopen ("libXinerama.so.1", RTLD_GLOBAL | RTLD_NOW);
            if (h != 0)

The basic idea in linux generally is that dlopen checks either full path or soname. The xinerama library has soname of “libXinerama.so.1” (meaning version 1 of the API of xinerama).
When they change the API, the soname increase so it doesn’t break code using old API.

So I don’t know on other Linux system, but at least on gentoo, ubuntu, and debian, the dlopen code should load the “.so.API” version (for xinerama, API == 1).
In a perfect world, we should find out the soname (the command readelf -a /path/to/libXinerama.so | grep “SONAME” returns it) before writing the dlopen call.

Please notice that /usr/lib/libXinerama.so is in the xinerama-dev package (because you need it when you link) but it’s not in the default xinerama package.


#2

Thanks, that sounds like a good suggestion!