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/mutex.hxx>
40 #include "unx/kde/kdedata.hxx"
41 #include "unx/i18n_im.hxx"
42 #include "unx/i18n_xkb.hxx"
44 #include "vclpluginapi.h"
46 #include <config_vclplug.h>
48 /* #i59042# override KApplications method for session management
49 * since it will interfere badly with our own.
51 class VCLKDEApplication
: public KApplication
54 VCLKDEApplication() : KApplication() {}
56 virtual void commitData(QSessionManager
&sm
) SAL_OVERRIDE
;
59 void VCLKDEApplication::commitData(QSessionManager
&)
63 /***************************************************************************
64 * class SalKDEDisplay *
65 ***************************************************************************/
67 SalKDEDisplay::SalKDEDisplay( Display
* pDisp
)
68 : SalX11Display( pDisp
)
72 SalKDEDisplay::~SalKDEDisplay()
74 // in case never a frame opened
75 static_cast<KDEXLib
*>(GetXLib())->doStartup();
76 // clean up own members
78 // prevent SalDisplay from closing KApplication's display
82 /***************************************************************************
84 ***************************************************************************/
88 // on 64 bit linux using libXRandr.so.2 will crash in
89 // XCloseDisplay when freeing extension data
90 // no known work around, therefore currently leak. Hopefully
91 // this does not make problems since we're shutting down anyway
92 // should we ever get a real kde plugin that uses the KDE event loop
93 // we should use kde's method to signal screen changes similar
95 #if ! defined USE_RANDR || ! (defined LINUX && defined X86_64)
96 // properly deinitialize KApplication
97 delete static_cast<VCLKDEApplication
*>(m_pApplication
);
99 // free the faked cmdline arguments no longer needed by KApplication
100 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
101 free( m_pFreeCmdLineArgs
[i
] );
102 delete [] m_pFreeCmdLineArgs
;
103 delete [] m_pAppCmdLineArgs
;
108 SalI18N_InputMethod
* pInputMethod
= new SalI18N_InputMethod
;
109 pInputMethod
->SetLocale();
112 KAboutData
*kAboutData
= new KAboutData( "LibreOffice",
113 I18N_NOOP( "LibreOffice" ),
115 I18N_NOOP( "LibreOffice with KDE Native Widget Support." ),
116 KAboutData::License_File
,
117 I18N_NOOP( "Copyright (C) 2000, 2014 LibreOffice contributors" ),
118 I18N_NOOP( "LibreOffice is an office suite.\n" ),
119 "http://libreoffice.org",
120 "libreoffice@lists.freedesktop.org");
121 kAboutData
->addAuthor( "Jan Holesovsky",
122 I18N_NOOP( "Original author and maintainer of the KDE NWF." ),
123 "kendy@artax.karlin.mff.cuni.cz",
124 "http://artax.karlin.mff.cuni.cz/~kendy" );
126 m_nFakeCmdLineArgs
= 1;
128 int nParams
= osl_getCommandArgCount();
130 OUString aParam
, aBin
;
132 for ( nIdx
= 0; nIdx
< nParams
; ++nIdx
)
134 osl_getCommandArg( nIdx
, &aParam
.pData
);
135 if ( !m_pFreeCmdLineArgs
&& aParam
== "-display" && nIdx
+ 1 < nParams
)
137 osl_getCommandArg( nIdx
+ 1, &aParam
.pData
);
138 aDisplay
= OUStringToOString( aParam
, osl_getThreadTextEncoding() );
140 m_nFakeCmdLineArgs
= 3;
141 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
142 m_pFreeCmdLineArgs
[ 1 ] = strdup( "-display" );
143 m_pFreeCmdLineArgs
[ 2 ] = strdup( aDisplay
.getStr() );
146 if ( !m_pFreeCmdLineArgs
)
147 m_pFreeCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
149 osl_getExecutableFile( &aParam
.pData
);
150 osl_getSystemPathFromFileURL( aParam
.pData
, &aBin
.pData
);
151 OString aExec
= OUStringToOString( aBin
, osl_getThreadTextEncoding() );
152 m_pFreeCmdLineArgs
[0] = strdup( aExec
.getStr() );
154 // make a copy of the string list for freeing it since
155 // KApplication manipulates the pointers inside the argument vector
156 // note: KApplication bad !
157 m_pAppCmdLineArgs
= new char*[ m_nFakeCmdLineArgs
];
158 for( int i
= 0; i
< m_nFakeCmdLineArgs
; i
++ )
159 m_pAppCmdLineArgs
[i
] = m_pFreeCmdLineArgs
[i
];
161 KCmdLineArgs::init( m_nFakeCmdLineArgs
, m_pAppCmdLineArgs
, kAboutData
);
163 KApplication::disableAutoDcopRegistration();
164 m_pApplication
= new VCLKDEApplication();
165 kapp
->disableSessionManagement();
167 Display
* pDisp
= QPaintDevice::x11AppDisplay();
169 SalX11Display
*pSalDisplay
= new SalKDEDisplay( pDisp
);
171 pInputMethod
->CreateMethod( pDisp
);
172 pSalDisplay
->SetupInput( pInputMethod
);
175 void KDEXLib::doStartup()
177 if( ! m_bStartupDone
)
179 KStartupInfo::appStarted();
180 m_bStartupDone
= true;
181 SAL_INFO( "vcl.kde", "called KStartupInfo::appStarted()" );
185 /**********************************************************************
187 **********************************************************************/
195 pXLib_
= new KDEXLib();
199 /**********************************************************************
200 * plugin entry point *
201 **********************************************************************/
204 VCLPLUG_KDE_PUBLIC SalInstance
* create_SalInstance()
206 /* #i92121# workaround deadlocks in the X11 implementation
208 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
210 from now on we know that an X connection will be
211 established, so protect X against itself
213 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
216 OString
aVersion( qVersion() );
217 SAL_INFO( "vcl.kde", "qt version string is \"" << aVersion
<< "\"" );
219 sal_Int32 nIndex
= 0, nMajor
= 0, nMinor
= 0, nMicro
= 0;
220 nMajor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
222 nMinor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
224 nMicro
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
225 if( nMajor
!= 3 || nMinor
< 2 || (nMinor
== 2 && nMicro
< 2) )
227 SAL_INFO( "vcl.kde", "unsuitable qt version " << nMajor
<< "." << nMinor
<< "." << nMicro
);
231 KDESalInstance
* pInstance
= new KDESalInstance( new SalYieldMutex() );
232 SAL_INFO( "vcl.kde", "created KDESalInstance " << &pInstance
);
234 // initialize SalData
235 KDEData
*pSalData
= new KDEData( pInstance
);
237 pInstance
->SetLib( pSalData
->GetLib() );
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */