diff options
Diffstat (limited to 'vcl/unx/generic/app/saldisp.cxx')
-rw-r--r-- | vcl/unx/generic/app/saldisp.cxx | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index 90cfe61b65af..52690656beeb 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -241,6 +241,13 @@ sal_Bool SalDisplay::BestVisual( Display *pDisplay, XVisualInfo &rVI ) { VisualID nDefVID = XVisualIDFromVisual( DefaultVisual( pDisplay, nScreen ) ); + VisualID nVID = 0; + char *pVID = getenv( "SAL_VISUAL" ); + if( pVID ) + sscanf( pVID, "%li", &nVID ); + + if( nVID && sal_GetVisualInfo( pDisplay, nVID, rVI ) ) + return rVI.visualid == nDefVID; XVisualInfo aVI; aVI.screen = nScreen; @@ -248,9 +255,49 @@ sal_Bool SalDisplay::BestVisual( Display *pDisplay, int nVisuals; XVisualInfo* pVInfos = XGetVisualInfo( pDisplay, VisualScreenMask, &aVI, &nVisuals ); + // pVInfos should contain at least one visual, otherwise + // we're in trouble + int* pWeight = (int*)alloca( sizeof(int)*nVisuals ); + int i; + for( i = 0; i < nVisuals; i++ ) + { + sal_Bool bUsable = sal_False; + int nTrueColor = 1; + + if ( pVInfos[i].screen != nScreen ) + { + bUsable = sal_False; + } + else + if( pVInfos[i].c_class == TrueColor ) + { + nTrueColor = 2048; + if( pVInfos[i].depth == 24 ) + bUsable = sal_True; + } + else if( pVInfos[i].c_class == PseudoColor ) + { + if( pVInfos[i].depth <= 8 ) + bUsable = sal_True; + else if( pVInfos[i].depth == 12 ) + bUsable = sal_True; + } + pWeight[ i ] = bUsable ? nTrueColor*pVInfos[i].depth : -1024; + pWeight[ i ] -= pVInfos[ i ].visualid; + } + + int nBestVisual = 0; + int nBestWeight = -1024; + for( i = 0; i < nVisuals; i++ ) + { + if( pWeight[ i ] > nBestWeight ) + { + nBestWeight = pWeight[ i ]; + nBestVisual = i; + } + } - // HACK - rVI = pVInfos[ 0 ]; + rVI = pVInfos[ nBestVisual ]; XFree( pVInfos ); return rVI.visualid == nDefVID; |