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 .
22 #include <unx/saldata.hxx>
23 #include <unx/saldisp.hxx>
24 #include <unx/salinst.h>
25 #include <unx/geninst.h>
26 #include <unx/genpspgraphics.h>
27 #include <unx/salframe.h>
29 #include <unx/i18n_im.hxx>
31 #include <vcl/inputtypes.hxx>
33 #include <salwtype.hxx>
35 #include <config_features.h>
36 #include <vcl/skia/SkiaHelper.hxx>
37 #include <config_skia.h>
39 #include <skia/x11/gdiimpl.hxx>
42 // plugin factory function
45 VCLPLUG_GEN_PUBLIC SalInstance
* create_SalInstance()
47 /* #i92121# workaround deadlocks in the X11 implementation
49 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
51 from now on we know that an X connection will be
52 established, so protect X against itself
54 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
57 X11SalInstance
* pInstance
= new X11SalInstance( std::make_unique
<SalYieldMutex
>() );
60 X11SalData
*pSalData
= new X11SalData( SAL_DATA_UNX
, pInstance
);
63 pInstance
->SetLib( pSalData
->GetLib() );
69 X11SalInstance::X11SalInstance(std::unique_ptr
<SalYieldMutex
> pMutex
)
70 : SalGenericInstance(std::move(pMutex
))
73 ImplSVData
* pSVData
= ImplGetSVData();
74 pSVData
->maAppData
.mxToolkitName
= OUString("x11");
76 X11SkiaSalGraphicsImpl::prepareSkia();
80 X11SalInstance::~X11SalInstance()
82 // close session management
83 SessionManagerClient::close();
85 // dispose SalDisplay list from SalData
86 // would be done in a static destructor else which is
88 GetGenericUnixSalData()->Dispose();
91 SkiaHelper::cleanup();
95 SalX11Display
* X11SalInstance::CreateDisplay() const
97 return new SalX11Display( mpXLib
->GetDisplay() );
100 // AnyInput from sv/mow/source/app/svapp.cxx
104 struct PredicateReturn
113 static Bool
ImplPredicateEvent( Display
*, XEvent
*pEvent
, char *pData
)
115 PredicateReturn
*pPre
= reinterpret_cast<PredicateReturn
*>(pData
);
122 switch( pEvent
->type
)
129 nType
= VclInputFlags::MOUSE
;
134 nType
= VclInputFlags::KEYBOARD
;
139 nType
= VclInputFlags::PAINT
;
142 nType
= VclInputFlags::NONE
;
145 if ( (nType
& pPre
->nType
) || ( nType
== VclInputFlags::NONE
&& (pPre
->nType
& VclInputFlags::OTHER
) ) )
152 bool X11SalInstance::AnyInput(VclInputFlags nType
)
154 GenericUnixSalData
*pData
= GetGenericUnixSalData();
155 Display
*pDisplay
= vcl_sal::getSalDisplay(pData
)->GetDisplay();
158 if( (nType
& VclInputFlags::TIMER
) && (mpXLib
&& mpXLib
->CheckTimeout(false)) )
161 if( !bRet
&& XPending(pDisplay
) )
163 PredicateReturn aInput
;
167 aInput
.nType
= nType
;
169 XCheckIfEvent(pDisplay
, &aEvent
, ImplPredicateEvent
,
170 reinterpret_cast<char *>(&aInput
) );
174 #if OSL_DEBUG_LEVEL > 1
175 SAL_INFO("vcl.app", "AnyInput "
176 << std::showbase
<< std::hex
177 << static_cast<unsigned int>(nType
)
178 << " = " << (bRet
? "true" : "false"));
183 bool X11SalInstance::DoYield(bool bWait
, bool bHandleAllCurrentEvents
)
185 return mpXLib
->Yield( bWait
, bHandleAllCurrentEvents
);
188 OUString
X11SalInstance::GetConnectionIdentifier()
190 static const char* pDisplay
= getenv( "DISPLAY" );
191 return pDisplay
? OUString::createFromAscii(pDisplay
) : OUString();
194 SalFrame
*X11SalInstance::CreateFrame( SalFrame
*pParent
, SalFrameStyleFlags nSalFrameStyle
)
196 SalFrame
*pFrame
= new X11SalFrame( pParent
, nSalFrameStyle
);
201 SalFrame
* X11SalInstance::CreateChildFrame( SystemParentData
* pParentData
, SalFrameStyleFlags nStyle
)
203 SalFrame
* pFrame
= new X11SalFrame( nullptr, nStyle
, pParentData
);
208 void X11SalInstance::DestroyFrame( SalFrame
* pFrame
)
213 void X11SalInstance::AfterAppInit()
215 assert( mpXLib
->GetDisplay() );
216 assert( mpXLib
->GetInputMethod() );
218 SalX11Display
*pSalDisplay
= CreateDisplay();
219 mpXLib
->GetInputMethod()->CreateMethod( mpXLib
->GetDisplay() );
220 pSalDisplay
->SetupInput();
223 void X11SalInstance::AddToRecentDocumentList(const OUString
&, const OUString
&, const OUString
&) {}
225 void X11SalInstance::PostPrintersChanged()
227 SalDisplay
* pDisp
= vcl_sal::getSalDisplay(GetGenericUnixSalData());
228 for (auto pSalFrame
: pDisp
->getFrames() )
229 pDisp
->PostEvent( pSalFrame
, nullptr, SalEvent::PrinterChanged
);
232 std::unique_ptr
<GenPspGraphics
> X11SalInstance::CreatePrintGraphics()
234 return std::make_unique
<GenPspGraphics
>();
237 std::shared_ptr
<vcl::BackendCapabilities
> X11SalInstance::GetBackendCapabilities()
239 auto pBackendCapabilities
= SalInstance::GetBackendCapabilities();
240 #if HAVE_FEATURE_SKIA
241 #if SKIA_USE_BITMAP32
242 if( SkiaHelper::isVCLSkiaEnabled())
243 pBackendCapabilities
->mbSupportsBitmap32
= true;
246 return pBackendCapabilities
;
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */