VirtualBox

Ignore:
Timestamp:
Mar 6, 2020 5:48:36 PM (5 years ago)
Author:
vboxsync
Message:

bugref:9637. optional dlopen'ing libXrandr instead of linking. part-2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp

    r83217 r83224  
    5454#include <X11/extensions/panoramiXproto.h>
    5555
    56 #define OLD_JUNK
    57 
    58 //#define DL_OPEN_RANDR
    59 
    6056/** Maximum number of supported screens.  DRM and X11 both limit this to 32. */
    6157/** @todo if this ever changes, dynamically allocate resizeable arrays in the
     
    121117    Bool (*pXRRQueryExtension) (Display *, int *, int *);
    122118    Status (*pXRRQueryVersion) (Display *, int *, int*);
     119    XRRMonitorInfo* (*pXRRGetMonitors)(Display *, Window, Bool, int *);
     120    void (*pXRRFreeMonitors)(XRRMonitorInfo *);
    123121};
    124122
     
    181179}
    182180
    183 #ifndef OLD_JUNK
    184181/** This function assumes monitors are named as from Virtual1 to VirtualX. */
    185182static int getMonitorIdFromName(const char *sMonitorName)
     
    222219    }
    223220
    224     XRRScreenResources *pScreenResources = XRRGetScreenResources (x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay));
    225     AssertReturnVoid(pScreenResources);
    226     XRRFreeScreenResources (pScreenResources);
     221    // XRRScreenResources *pScreenResources = XRRGetScreenResources(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay));
     222    // AssertReturnVoid(pScreenResources);
     223    // XRRFreeScreenResources(pScreenResources);
    227224
    228225    int iMonitorCount = 0;
    229     XRRMonitorInfo *pMonitorInfo = XRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
     226    XRRMonitorInfo *pMonitorInfo = NULL;
     227#ifdef WITH_DISTRO_XRAND_XINERAMA
     228    pMonitorInfo = XRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
     229#else
     230    if (x11Context.pXRRGetMonitors)
     231        x11Context.pXRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
     232#endif
     233    if (!pMonitorInfo)
     234        return;
    230235    if (iMonitorCount == -1)
    231236        VBClLogError("Could not get monitor info\n");
     
    254259            sendMonitorPositions(mpMonitorPositions, x11Context.hOutputCount);
    255260    }
     261#ifdef WITH_DISTRO_XRAND_XINERAMA
    256262    XRRFreeMonitors(pMonitorInfo);
    257 }
     263#else
     264    if (x11Context.pXRRFreeMonitors)
     265        x11Context.pXRRFreeMonitors(pMonitorInfo);
    258266#endif
     267}
    259268
    260269static void monitorRandREvents()
    261270{
    262 #ifndef OLD_JUNK
    263271    XEvent event;
    264272    XNextEvent(x11Context.pDisplay, &event);
     
    277285            break;
    278286    }
    279 #endif
    280287}
    281288
     
    333340static bool callVMWCTRL()
    334341{
    335 #ifndef OLD_JUNK
    336342    const int hHeight = 600;
    337343    const int hWidth = 800;
     
    352358                                 DefaultScreen(x11Context.pDisplay),
    353359                                 extents, x11Context.hOutputCount);
    354 #else
    355     return true;
    356 #endif
    357360}
    358361
     
    365368    if (RT_FAILURE(startX11MonitorThread()))
    366369        return false;
    367 #ifdef DL_OPEN_RANDR
     370#ifdef WITH_DISTRO_XRAND_XINERAMA
     371    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
     372#else
    368373    if (x11Context.pXRRSelectInput)
    369374        x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
    370 #else
    371     XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
    372375#endif
    373376    return true;
     
    387390        x11Context.pRandLibraryHandle = NULL;
    388391    }
    389 #ifdef DL_OPEN_RANDR
     392#ifdef WITH_DISTRO_XRAND_XINERAMA
     393    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
     394#else
    390395    if (x11Context.pXRRSelectInput)
    391396        x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
    392 #else
    393     XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
    394397#endif
    395398    XCloseDisplay(x11Context.pDisplay);
    396399}
    397400
    398 #ifdef DL_OPEN_RANDR
     401#ifndef WITH_DISTRO_XRAND_XINERAMA
    399402static int openLibRandR()
    400403{
     
    434437        return VERR_NOT_FOUND;
    435438    }
     439
     440    x11Context.pXRRGetMonitors = (XRRMonitorInfo* (*)(Display *, Window, Bool, int *))
     441        dlsym(x11Context.pRandLibraryHandle, "XRRGetMonitors");
     442    if (!x11Context.pXRRGetMonitors)
     443    {
     444        VBClLogFatalError("Could not find address for the symbol XRRGetMonitors\n");
     445        dlclose(x11Context.pRandLibraryHandle);
     446        x11Context.pRandLibraryHandle = NULL;
     447        return VERR_NOT_FOUND;
     448    }
     449
     450    x11Context.pXRRFreeMonitors = (void (*)(XRRMonitorInfo *))
     451        dlsym(x11Context.pRandLibraryHandle, "XRRFreeMonitors");
     452    if (!x11Context.pXRRFreeMonitors)
     453    {
     454        VBClLogFatalError("Could not find address for the symbol XRRFreeMonitors\n");
     455        dlclose(x11Context.pRandLibraryHandle);
     456        x11Context.pRandLibraryHandle = NULL;
     457        return VERR_NOT_FOUND;
     458    }
     459
    436460    return VINF_SUCCESS;
    437461}
     
    454478    }
    455479    bool fSuccess = false;
    456 #ifdef DL_OPEN_RANDR
     480#ifdef WITH_DISTRO_XRAND_XINERAMA
     481    fSuccess = XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
     482#else
    457483    if (x11Context.pXRRQueryExtension)
    458484        fSuccess = x11Context.pXRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
    459 #else
    460     fSuccess = XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
    461485#endif
    462486    if (fSuccess)
    463487    {
    464488        fSuccess = false;
    465 #ifdef DL_OPEN_RANDR
     489#ifdef WITH_DISTRO_XRAND_XINERAMA
     490        fSuccess = XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
     491#else
    466492    if (x11Context.pXRRQueryVersion)
    467493        fSuccess = x11Context.pXRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
    468 #else
    469         fSuccess = XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
    470494#endif
    471495        if (!fSuccess)
     
    477501    }
    478502    x11Context.hEventMask = 0;
    479 #ifndef OLD_JUNK
    480503    x11Context.hEventMask = RRScreenChangeNotifyMask;
    481504    if (x11Context.hRandRMinor >= 2)
     
    483506                               | RROutputChangeNotifyMask
    484507                               | RROutputPropertyNotifyMask;
    485 #endif
    486508    x11Context.rootWindow = DefaultRootWindow(x11Context.pDisplay);
    487509    x11Context.hOutputCount = determineOutputCount();
     
    490512    x11Context.pXRRQueryExtension = NULL;
    491513    x11Context.pXRRQueryVersion = NULL;
    492 #ifdef DL_OPEN_RANDR
     514    x11Context.pXRRGetMonitors = NULL;
     515    x11Context.pXRRFreeMonitors = NULL;
     516#ifndef WITH_DISTRO_XRAND_XINERAMA
    493517    if (openLibRandR() != VINF_SUCCESS)
    494518    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette