diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-05-10 11:58:24 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2004-05-10 11:58:24 +0000 |
commit | 22795c8fad40ebf5f7fa34eef92068fdd4687c7a (patch) | |
tree | 728584174c130b53c97f17b93b6ca7618cb011b7 /vcl/unx/source/plugadapt | |
parent | ca6bef646041ca07284f1fca26c4541db0948f7f (diff) |
INTEGRATION: CWS defaultbrowser (1.4.36); FILE MERGED
2004/04/29 07:41:25 obr 1.4.36.2: #i27120# /usr/dt/lib no longer in LD_LIBRARY_PATH
2004/04/27 06:45:55 obr 1.4.36.1: #i27120# export a string interface identifying the desktop environment
Diffstat (limited to 'vcl/unx/source/plugadapt')
-rw-r--r-- | vcl/unx/source/plugadapt/salplug.cxx | 151 |
1 files changed, 109 insertions, 42 deletions
diff --git a/vcl/unx/source/plugadapt/salplug.cxx b/vcl/unx/source/plugadapt/salplug.cxx index 677c37f62a4a..f388c20830c8 100644 --- a/vcl/unx/source/plugadapt/salplug.cxx +++ b/vcl/unx/source/plugadapt/salplug.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salplug.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: obo $ $Date: 2004-03-15 14:53:17 $ + * last change: $Author: hr $ $Date: 2004-05-10 12:58:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -79,6 +79,7 @@ #include <cstdio> #include <unistd.h> +#include <dlfcn.h> using namespace rtl; @@ -86,6 +87,21 @@ typedef SalInstance*(*salFactoryProc)( oslModule pModule); static oslModule pCloseModule = NULL; +#define DESKTOP_NONE 0 +#define DESKTOP_UNKNOWN 1 +#define DESKTOP_GNOME 2 +#define DESKTOP_KDE 3 +#define DESKTOP_CDE 4 + +static const char * desktop_strings[5] = { "none", "unknown", "GNOME", "KDE", "CDE" }; + +// NETBSD has no RTLD_GLOBAL +#ifndef RTLD_GLOBAL +#define DLOPEN_MODE (RTLD_LAZY) +#else +#define DLOPEN_MODE (RTLD_GLOBAL | RTLD_LAZY) +#endif + static SalInstance* tryInstance( const OUString& rModuleBase ) { SalInstance* pInst = NULL; @@ -132,9 +148,9 @@ static SalInstance* tryInstance( const OUString& rModuleBase ) return pInst; } -static const char* autodetect_gnome( Display* pDisplay ) +static bool is_gnome_desktop( Display* pDisplay ) { - const char* pRet = NULL; + bool ret = false; // warning: this check is coincidental, GNOME does not // explicitly advertise itself @@ -150,12 +166,13 @@ static const char* autodetect_gnome( Display* pDisplay ) if( pProperties[ i ] == nAtom1 || pProperties[ i ] == nAtom2 ) { - pRet = "gtk"; + ret = true; } XFree( pProperties ); } } - return pRet; + + return ret; } static bool bWasXError = false; @@ -174,6 +191,8 @@ extern "C" bWasXError = true; return 0; } + + typedef int(* XErrorHandler)(Display*,XErrorEvent*); } static OUString getNetWMName( Display* pDisplay ) @@ -264,60 +283,102 @@ static OUString getNetWMName( Display* pDisplay ) return aRet; } -static const char* autodetect_kde( Display* pDisplay ) +static bool is_kde_desktop( Display* pDisplay ) { - const char* pRet = NULL; // check for kwin rtl::OUString aWM = getNetWMName( pDisplay ); if( aWM.equalsIgnoreAsciiCaseAscii( "KWin" ) ) - pRet = "kde"; + return true; - return pRet; + return false; } -static const char* autodetect_plugin() +static bool is_cde_desktop( Display* pDisplay ) { - // get display to connect to - static const char* pDisplayStr = getenv( "DISPLAY" ); - int nParams = osl_getCommandArgCount(); - OUString aParam; - OString aBParm; - for( int i = 0; i < nParams-1; i++ ) + void* pLibrary = NULL; + + Atom nDtAtom = XInternAtom( pDisplay, "_DT_WM_READY", True ); + if( nDtAtom && ( pLibrary = dlopen( "/usr/dt/lib/libDtSvc.so", DLOPEN_MODE ) ) ) { - osl_getCommandArg( i, &aParam.pData ); - if( aParam.equalsAscii( "-display" ) || aParam.equalsAscii( "--display" ) ) + dlclose( pLibrary ); + return true; + } + + return false; +} + + +static const char * get_desktop_environment() +{ + static const char *pRet = NULL; + + if ( NULL == pRet ) + { + // get display to connect to + const char* pDisplayStr = getenv( "DISPLAY" ); + int nParams = osl_getCommandArgCount(); + OUString aParam; + OString aBParm; + for( int i = 0; i < nParams-1; i++ ) { - osl_getCommandArg( i+1, &aParam.pData ); - aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() ); - pDisplayStr = aBParm.getStr(); - break; + osl_getCommandArg( i, &aParam.pData ); + if( aParam.equalsAscii( "-display" ) || aParam.equalsAscii( "--display" ) ) + { + osl_getCommandArg( i+1, &aParam.pData ); + aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() ); + pDisplayStr = aBParm.getStr(); + break; + } + } + + // no server at all + if( ! pDisplayStr || !*pDisplayStr ) + pRet = desktop_strings[DESKTOP_NONE]; + else + { + Display* pDisplay = XOpenDisplay( pDisplayStr ); + if( pDisplay ) + { + XErrorHandler pOldHdl = XSetErrorHandler( autodect_error_handler ); + + if ( is_gnome_desktop( pDisplay ) ) + pRet = desktop_strings[DESKTOP_GNOME]; + else if ( is_kde_desktop( pDisplay ) ) + pRet = desktop_strings[DESKTOP_KDE]; + else if ( is_cde_desktop( pDisplay ) ) + pRet = desktop_strings[DESKTOP_CDE]; + else + pRet = desktop_strings[DESKTOP_UNKNOWN]; + + // set the default handler again + XSetErrorHandler( pOldHdl ); + + XCloseDisplay( pDisplay ); + } } } - const char* pRet = NULL; + return pRet; +} + + +static const char* autodetect_plugin() +{ + const char * desktop = get_desktop_environment(); + const char * pRet = NULL; + // no server at all: dummy plugin - if( ! pDisplayStr || !*pDisplayStr ) + if ( desktop == desktop_strings[DESKTOP_NONE] ) pRet = "dummy"; - else - { - Display* pDisplay = XOpenDisplay( pDisplayStr ); - if( pDisplay ) - { - int(*pOldHdl)(Display*,XErrorEvent*) = XSetErrorHandler( autodect_error_handler ); #ifdef ENABLE_GTK_AUTODETECT - pRet = autodetect_gnome( pDisplay ); + else if ( desktop == desktop_strings[DESKTOP_GNOME] ) + pRet = "gtk"; #endif - if( ! pRet ) - pRet = autodetect_kde( pDisplay ); - if( ! pRet ) - pRet = "gen"; - - // set the default handler again - XSetErrorHandler( pOldHdl ); + else if( desktop == desktop_strings[DESKTOP_KDE] ) + pRet = "kde"; + else + pRet = "gen"; - XCloseDisplay( pDisplay ); - } - } #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "plugin autodetection: %s\n", pRet ); #endif @@ -395,3 +456,9 @@ void SalAbort( const XubString& rErrorText ) fprintf( stderr, ByteString( rErrorText, gsl_getSystemTextEncoding() ).GetBuffer() ); abort(); } + +const OUString& SalGetDesktopEnvironment() +{ + static OUString aRet = OStringToOUString(OString(get_desktop_environment()), RTL_TEXTENCODING_ASCII_US); + return aRet; +} |