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>
36 #include <osl/thread.h>
37 #include <osl/process.h>
38 #include <osl/module.h>
39 #include <osl/mutex.hxx>
41 #include "unx/kde/kdedata.hxx"
42 #include "unx/i18n_im.hxx"
43 #include "unx/i18n_xkb.hxx"
45 #include "vclpluginapi.h"
47 #include <config_vclplug.h>
49 /* #i59042# override KApplications method for session management
50 * since it will interfere badly with our own.
52 class VCLKDEApplication
: public KApplication
55 VCLKDEApplication() : KApplication() {}
57 virtual void commitData(QSessionManager
&sm
) SAL_OVERRIDE
;
60 void VCLKDEApplication::commitData(QSessionManager
&)
64 /***************************************************************************
65 * class SalKDEDisplay *
66 ***************************************************************************/
68 SalKDEDisplay::SalKDEDisplay( Display
* pDisp
)
69 : SalX11Display( pDisp
)
73 SalKDEDisplay::~SalKDEDisplay()
75 // in case never a frame opened
76 static_cast<KDEXLib
*>(GetXLib())->doStartup();
77 // clean up own members
79 // prevent SalDisplay from closing KApplication's display
83 /***************************************************************************
85 ***************************************************************************/
89 // on 64 bit linux using libXRandr.so.2 will crash in
90 // XCloseDisplay when freeing extension data
91 // no known work around, therefor currently leak. Hopefully
92 // this does not make problems since we're shutting down anyway
93 // should we ever get a real kde plugin that uses the KDE event loop
94 // we should use kde's method to signal screen changes similar
96 #if ! defined USE_RANDR || ! (defined LINUX && defined X86_64)
97 // properly deinitialize KApplication
98 delete (VCLKDEApplication
*)m_pApplication
;
100 // free the faked cmdline arguments no longer needed by KApplication
101 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
102 free( m_pFreeCmdLineArgs
[i
] );
103 delete [] m_pFreeCmdLineArgs
;
104 delete [] m_pAppCmdLineArgs
;
109 SalI18N_InputMethod
* pInputMethod
= new SalI18N_InputMethod
;
110 pInputMethod
->SetLocale();
113 KAboutData
*kAboutData
= new KAboutData( "LibreOffice",
114 I18N_NOOP( "LibreOffice" ),
116 I18N_NOOP( "LibreOffice with KDE Native Widget Support." ),
117 KAboutData::License_File
,
118 I18N_NOOP( "Copyright (C) 2000, 2014 LibreOffice contributors" ),
119 I18N_NOOP( "LibreOffice is an office suite.\n" ),
120 "http://libreoffice.org",
121 "libreoffice@lists.freedesktop.org");
122 kAboutData
->addAuthor( "Jan Holesovsky",
123 I18N_NOOP( "Original author and maintainer of the KDE NWF." ),
124 "kendy@artax.karlin.mff.cuni.cz",
125 "http://artax.karlin.mff.cuni.cz/~kendy" );
127 m_nFakeCmdLineArgs
= 1;
129 int nParams
= osl_getCommandArgCount();
131 OUString aParam
, aBin
;
133 for ( nIdx
= 0; nIdx
< nParams
; ++nIdx
)
135 osl_getCommandArg( nIdx
, &aParam
.pData
);
136 if ( !m_pFreeCmdLineArgs
&& aParam
== "-display" && nIdx
+ 1 < nParams
)
138 osl_getCommandArg( nIdx
+ 1, &aParam
.pData
);
139 aDisplay
= OUStringToOString( aParam
, osl_getThreadTextEncoding() );
141 m_nFakeCmdLineArgs
= 3;
142 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
143 m_pFreeCmdLineArgs
[ 1 ] = strdup( "-display" );
144 m_pFreeCmdLineArgs
[ 2 ] = strdup( aDisplay
.getStr() );
147 if ( !m_pFreeCmdLineArgs
)
148 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
150 osl_getExecutableFile( &aParam
.pData
);
151 osl_getSystemPathFromFileURL( aParam
.pData
, &aBin
.pData
);
152 OString aExec
= OUStringToOString( aBin
, osl_getThreadTextEncoding() );
153 m_pFreeCmdLineArgs
[0] = strdup( aExec
.getStr() );
155 // make a copy of the string list for freeing it since
156 // KApplication manipulates the pointers inside the argument vector
157 // note: KApplication bad !
158 m_pAppCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
159 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
160 m_pAppCmdLineArgs
[i
] = m_pFreeCmdLineArgs
[i
];
162 KCmdLineArgs::init( m_nFakeCmdLineArgs
, m_pAppCmdLineArgs
, kAboutData
);
164 KApplication::disableAutoDcopRegistration();
165 m_pApplication
= new VCLKDEApplication();
166 kapp
->disableSessionManagement();
168 Display
* pDisp
= QPaintDevice::x11AppDisplay();
170 SalX11Display
*pSalDisplay
= new SalKDEDisplay( pDisp
);
172 pInputMethod
->CreateMethod( pDisp
);
173 pSalDisplay
->SetupInput( pInputMethod
);
176 void KDEXLib::doStartup()
178 if( ! m_bStartupDone
)
180 KStartupInfo::appStarted();
181 m_bStartupDone
= true;
182 SAL_INFO( "vcl.kde", "called KStartupInfo::appStarted()" );
186 /**********************************************************************
188 **********************************************************************/
196 pXLib_
= new KDEXLib();
200 /**********************************************************************
201 * plugin entry point *
202 **********************************************************************/
205 VCLPLUG_KDE_PUBLIC SalInstance
* create_SalInstance( oslModule
)
207 /* #i92121# workaround deadlocks in the X11 implementation
209 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
211 from now on we know that an X connection will be
212 established, so protect X against itself
214 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
217 OString
aVersion( qVersion() );
218 SAL_INFO( "vcl.kde", "qt version string is \"" << aVersion
<< "\"" );
220 sal_Int32 nIndex
= 0, nMajor
= 0, nMinor
= 0, nMicro
= 0;
221 nMajor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
223 nMinor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
225 nMicro
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
226 if( nMajor
!= 3 || nMinor
< 2 || (nMinor
== 2 && nMicro
< 2) )
228 SAL_INFO( "vcl.kde", "unsuitable qt version " << nMajor
<< "." << nMinor
<< "." << nMicro
);
232 KDESalInstance
* pInstance
= new KDESalInstance( new SalYieldMutex() );
233 SAL_INFO( "vcl.kde", "created KDESalInstance " << &pInstance
);
235 // initialize SalData
236 KDEData
*pSalData
= new KDEData( pInstance
);
238 pInstance
->SetLib( pSalData
->GetLib() );
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */