1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <shell/kde_headers.h>
32 #include <sys/types.h>
37 #include <osl/thread.h>
38 #include <osl/process.h>
39 #include <osl/module.h>
40 #include <osl/mutex.hxx>
42 #include "unx/kde/kdedata.hxx"
43 #include "unx/i18n_im.hxx"
44 #include "unx/i18n_xkb.hxx"
46 #include "vclpluginapi.h"
49 #define THIS_DESKENV_NAME_CAP "TDE"
50 #define THIS_DESKENV_NAME_LOW "tde"
52 #define THIS_DESKENV_NAME_CAP "KDE"
53 #define THIS_DESKENV_NAME_LOW "kde"
56 /* #i59042# override KApplications method for session management
57 * since it will interfere badly with our own.
59 class VCLKDEApplication
: public KApplication
62 VCLKDEApplication() : KApplication() {}
64 virtual void commitData(QSessionManager
&sm
);
67 void VCLKDEApplication::commitData(QSessionManager
&)
71 /***************************************************************************
72 * class SalKDEDisplay *
73 ***************************************************************************/
75 SalKDEDisplay::SalKDEDisplay( Display
* pDisp
)
76 : SalX11Display( pDisp
)
80 SalKDEDisplay::~SalKDEDisplay()
82 // in case never a frame opened
83 static_cast<KDEXLib
*>(GetXLib())->doStartup();
84 // clean up own members
86 // prevent SalDisplay from closing KApplication's display
90 /***************************************************************************
92 ***************************************************************************/
96 // on 64 bit linux using libXRandr.so.2 will crash in
97 // XCloseDisplay when freeing extension data
98 // no known work around, therefor currently leak. Hopefully
99 // this does not make problems since we're shutting down anyway
100 // should we ever get a real kde plugin that uses the KDE event loop
101 // we should use kde's method to signal screen changes similar
103 #if ! defined USE_RANDR || ! (defined LINUX && defined X86_64)
104 // properly deinitialize KApplication
105 delete (VCLKDEApplication
*)m_pApplication
;
107 // free the faked cmdline arguments no longer needed by KApplication
108 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
109 free( m_pFreeCmdLineArgs
[i
] );
110 delete [] m_pFreeCmdLineArgs
;
111 delete [] m_pAppCmdLineArgs
;
116 SalI18N_InputMethod
* pInputMethod
= new SalI18N_InputMethod
;
117 pInputMethod
->SetLocale();
120 KAboutData
*kAboutData
= new KAboutData( "LibreOffice",
121 I18N_NOOP( "LibreOffice" ),
123 I18N_NOOP( "LibreOffice with KDE Native Widget Support." ),
124 KAboutData::License_File
,
125 I18N_NOOP( "Copyright (C) 2000 - 2012 LibreOffice contributors and/or their affiliates" ),
126 I18N_NOOP( "LibreOffice is an office suite.\n" ),
127 "http://libreoffice.org",
128 "libreoffice@lists.freedesktop.org");
129 kAboutData
->addAuthor( "Jan Holesovsky",
130 I18N_NOOP( "Original author and maintainer of the KDE NWF." ),
131 "kendy@artax.karlin.mff.cuni.cz",
132 "http://artax.karlin.mff.cuni.cz/~kendy" );
134 m_nFakeCmdLineArgs
= 1;
136 int nParams
= osl_getCommandArgCount();
137 rtl::OString aDisplay
;
138 rtl::OUString aParam
, aBin
;
140 for ( nIdx
= 0; nIdx
< nParams
; ++nIdx
)
142 osl_getCommandArg( nIdx
, &aParam
.pData
);
143 if ( !m_pFreeCmdLineArgs
&& aParam
== "-display" && nIdx
+ 1 < nParams
)
145 osl_getCommandArg( nIdx
+ 1, &aParam
.pData
);
146 aDisplay
= rtl::OUStringToOString( aParam
, osl_getThreadTextEncoding() );
148 m_nFakeCmdLineArgs
= 3;
149 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
150 m_pFreeCmdLineArgs
[ 1 ] = strdup( "-display" );
151 m_pFreeCmdLineArgs
[ 2 ] = strdup( aDisplay
.getStr() );
154 if ( !m_pFreeCmdLineArgs
)
155 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
157 osl_getExecutableFile( &aParam
.pData
);
158 osl_getSystemPathFromFileURL( aParam
.pData
, &aBin
.pData
);
159 rtl::OString aExec
= rtl::OUStringToOString( aBin
, osl_getThreadTextEncoding() );
160 m_pFreeCmdLineArgs
[0] = strdup( aExec
.getStr() );
162 // make a copy of the string list for freeing it since
163 // KApplication manipulates the pointers inside the argument vector
164 // note: KApplication bad !
165 m_pAppCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
166 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
167 m_pAppCmdLineArgs
[i
] = m_pFreeCmdLineArgs
[i
];
169 KCmdLineArgs::init( m_nFakeCmdLineArgs
, m_pAppCmdLineArgs
, kAboutData
);
171 KApplication::disableAutoDcopRegistration();
172 m_pApplication
= new VCLKDEApplication();
173 kapp
->disableSessionManagement();
175 Display
* pDisp
= QPaintDevice::x11AppDisplay();
177 SalX11Display
*pSalDisplay
= new SalKDEDisplay( pDisp
);
179 pInputMethod
->CreateMethod( pDisp
);
180 pSalDisplay
->SetupInput( pInputMethod
);
183 void KDEXLib::doStartup()
185 if( ! m_bStartupDone
)
187 KStartupInfo::appStarted();
188 m_bStartupDone
= true;
189 #if OSL_DEBUG_LEVEL > 1
190 fprintf( stderr
, "called KStartupInfo::appStarted()\n" );
195 /**********************************************************************
197 **********************************************************************/
205 pXLib_
= new KDEXLib();
209 /**********************************************************************
210 * plugin entry point *
211 **********************************************************************/
214 VCLPLUG_KDE_PUBLIC SalInstance
* create_SalInstance( oslModule
)
216 /* #i92121# workaround deadlocks in the X11 implementation
218 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
220 from now on we know that an X connection will be
221 established, so protect X against itself
223 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
226 rtl::OString
aVersion( qVersion() );
227 #if OSL_DEBUG_LEVEL > 1
228 fprintf( stderr
, "qt version string is \"%s\"\n", aVersion
.getStr() );
230 sal_Int32 nIndex
= 0, nMajor
= 0, nMinor
= 0, nMicro
= 0;
231 nMajor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
233 nMinor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
235 nMicro
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
236 if( nMajor
!= 3 || nMinor
< 2 || (nMinor
== 2 && nMicro
< 2) )
238 #if OSL_DEBUG_LEVEL > 1
239 fprintf( stderr
, "unsuitable qt version %d.%d.%d\n", (int)nMajor
, (int)nMinor
, (int)nMicro
);
244 KDESalInstance
* pInstance
= new KDESalInstance( new SalYieldMutex() );
245 #if OSL_DEBUG_LEVEL > 1
246 fprintf( stderr
, "created KDESalInstance 0x%p\n", pInstance
);
249 // initialize SalData
250 KDEData
*pSalData
= new KDEData( pInstance
);
252 pInstance
->SetLib( pSalData
->GetLib() );
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */