31#include <config_features.h>
32#include <config_vclplug.h>
36#include <rtl/bootstrap.hxx>
37#include <rtl/process.h>
45#define UNIX_DESKTOP_DETECT 1
48#define UNIX_DESKTOP_DETECT 0
52#if defined(DISABLE_DYNLOADING) || !HAVE_FEATURE_UI
53#define STATIC_SAL_INSTANCE 1
56#define STATIC_SAL_INSTANCE 0
57#include <osl/module.hxx>
62#include <UIKit/UIKit.h>
95#if !STATIC_SAL_INSTANCE
96oslModule pCloseModule =
nullptr;
100SalInstance* tryInstance(
const OUString& rModuleBase,
bool bForce =
false )
103 if (rModuleBase ==
"svp")
104 return svp_create_SalInstance();
108 OUString aUsedModuleBase(rModuleBase);
109 if (aUsedModuleBase ==
"kde5")
110 aUsedModuleBase =
"kf5";
115 "vclplug_" + aUsedModuleBase +
"lo" SAL_DLLEXTENSION );
118 if (aMod.loadRelative(
reinterpret_cast<oslGenericFunction
>(&tryInstance), aModule, SAL_LOADMODULE_GLOBAL))
120 salFactoryProc aProc =
reinterpret_cast<salFactoryProc
>(aMod.getFunctionSymbol(
"create_SalInstance"));
126 "sal plugin " << aModule <<
" produced instance " << pInst);
129 pCloseModule =
static_cast<oslModule
>(aMod);
138 if (aUsedModuleBase ==
"gtk4" || aUsedModuleBase ==
"gtk3" ||
139 aUsedModuleBase ==
"gtk3_kde5" || aUsedModuleBase ==
"kf5" ||
140 aUsedModuleBase ==
"qt5" || aUsedModuleBase ==
"qt6" ||
141 aUsedModuleBase ==
"win")
143 pCloseModule =
nullptr;
151 "could not load symbol create_SalInstance from shared object "
157 SAL_WARN(
"vcl.plugadapt",
"could not load shared object " << aModule);
161 SAL_INFO(
"vcl.plugadapt",
"could not load shared object " << aModule);
169#if UNIX_DESKTOP_DETECT
170#ifndef DISABLE_DYNLOADING
171extern "C" typedef DesktopType Fn_get_desktop_environment();
179#ifdef DISABLE_DYNLOADING
180 ret = get_desktop_environment();
182 OUString aModule(DESKTOP_DETECTOR_DLL_NAME);
183 oslModule aMod = osl_loadModuleRelative(
184 reinterpret_cast< oslGenericFunction
>( &tryInstance ), aModule.pData,
185 SAL_LOADMODULE_DEFAULT );
188 Fn_get_desktop_environment * pSym
189 =
reinterpret_cast<Fn_get_desktop_environment *
>(
190 osl_getAsciiFunctionSymbol(aMod,
"get_desktop_environment"));
194 osl_unloadModule( aMod );
199#if !STATIC_SAL_INSTANCE
200const char*
const* autodetect_plugin_list()
202 static const char*
const pKDEFallbackList[] =
219 static const char*
const pStandardFallbackList[] =
231 static const char*
const pHeadlessFallbackList[] =
239 const char *
const * pList = pStandardFallbackList;
244 pList = pHeadlessFallbackList;
251 pList = pStandardFallbackList;
253 pList = pKDEFallbackList;
264bool IsHeadlessModeRequested()
269 sal_uInt32
n = rtl_getAppCommandArgCount();
270 for (sal_uInt32 i = 0;
i <
n; ++
i) {
272 rtl_getAppCommandArg(i, &arg.pData);
273 if ( arg ==
"--headless" || arg ==
"-headless" ) {
285 rtl::Bootstrap::get(
"SAL_USE_VCLPLUGIN", aUsePlugin);
286 SAL_INFO_IF(!aUsePlugin.isEmpty(),
"vcl.plugadapt",
"Requested VCL plugin: " << aUsePlugin);
291 if (aUsePlugin ==
"svp")
295 return svp_create_SalInstance();
301#if STATIC_SAL_INSTANCE
307 if( !aUsePlugin.isEmpty() )
308 pInst = tryInstance( aUsePlugin,
true );
310#if UNIX_DESKTOP_DETECT
311 const char*
const* pPluginList = pInst ? nullptr : autodetect_plugin_list();
312 for (
int i = 0; !pInst && pPluginList[
i]; ++
i)
314 pInst = tryInstance(OUString::createFromAscii(pPluginList[
i]));
315 SAL_INFO_IF(pInst,
"vcl.plugadapt",
"plugin autodetection: " << pPluginList[
i]);
320 static const char*
const pPlugin[] = {
348 for (
int i = 0; !pInst && pPlugin[
i]; ++
i)
349 pInst = tryInstance( OUString::createFromAscii( pPlugin[
i ] ) );
353 std::fprintf( stderr,
"no suitable windowing system found, exiting.\n" );
364#if !STATIC_SAL_INSTANCE
366 osl_unloadModule( pCloseModule );
370void SalAbort(
const OUString& rErrorText,
bool bDumpCore )
376 if( rErrorText.isEmpty() )
379 RaiseException( 0, EXCEPTION_NONCONTINUABLE, 0,
nullptr );
380 FatalAppExitW( 0, L
"Application Error" );
386 RaiseException( 0, EXCEPTION_NONCONTINUABLE, 0,
nullptr );
387 FatalAppExitW( 0, o3tl::toW(rErrorText.getStr()) );
391 OUString aError(rErrorText.isEmpty() ?
"Unspecified application error" : rErrorText);
394 NSLog(
@"SalAbort: %s",
OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr());
396 if( rErrorText.isEmpty() )
397 std::fprintf( stderr,
"Unspecified Application Error\n" );
401 std::fprintf( stderr,
"%s\n",
OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
414 static OUString aDesktopEnvironment(
"headless");
416 static OUString aDesktopEnvironment(
"Windows" );
418 static OUString aDesktopEnvironment(
"MacOSX" );
419#elif defined(EMSCRIPTEN)
420 static OUString aDesktopEnvironment(
"WASM");
421#elif defined(ANDROID)
422 static OUString aDesktopEnvironment(
"android");
424 static OUString aDesktopEnvironment(
"iOS");
425#elif UNIX_DESKTOP_DETECT
427 static const char *
const desktop_strings[] = {
428 "none",
"unknown",
"GNOME",
"UNITY",
429 "XFCE",
"MATE",
"PLASMA5",
"LXQT" };
430 static OUString aDesktopEnvironment;
431 if( aDesktopEnvironment.isEmpty())
433 aDesktopEnvironment = OUString::createFromAscii(
434 desktop_strings[lcl_get_desktop_environment()]);
437 static OUString aDesktopEnvironment(
"unknown");
439 return aDesktopEnvironment;
447 return SystemParametersInfoW(SPI_GETSCREENREADER, 0, &bIsRunning, 0)
static bool IsBitmapRendering()
Determines if bitmap rendering is enabled.
static void EnableBitmapRendering()
Enable software-only bitmap rendering.
static bool IsHeadlessModeEnabled()
Determines if headless mode is enabled.
static void addKeyValue(SAL_UNUSED_PARAMETER const OUString &, SAL_UNUSED_PARAMETER const OUString &, SAL_UNUSED_PARAMETER tAddKeyHandling)
virtual void BeforeAbort(const OUString &, bool)
enum SAL_DLLPUBLIC_RTTI DesktopType
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const wchar_t *typedef BOOL
void SalAbort(const OUString &rErrorText, bool bDumpCore)
SalInstance * create_SalInstance()
const OUString & SalGetDesktopEnvironment()
void DestroySalInstance(SalInstance *pInst)
SalInstance * CreateSalInstance()
SalInstance * GetSalInstance()