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 <config_features.h>
23 #include <vcl/skia/SkiaHelper.hxx>
24 #include <config_skia.h>
26 #include <skia/x11/gdiimpl.hxx>
27 #include <skia/salbmp.hxx>
30 #include <headless/svpbmp.hxx>
31 #include <unx/saldata.hxx>
32 #include <unx/saldisp.hxx>
33 #include <unx/salinst.h>
34 #include <unx/geninst.h>
35 #include <unx/genpspgraphics.h>
36 #include <unx/salframe.h>
38 #include <unx/i18n_im.hxx>
40 #include <vcl/inputtypes.hxx>
42 #include <salwtype.hxx>
44 // plugin factory function
47 VCLPLUG_GEN_PUBLIC SalInstance
* create_SalInstance()
49 /* #i92121# workaround deadlocks in the X11 implementation
51 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
53 from now on we know that an X connection will be
54 established, so protect X against itself
56 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
59 X11SalInstance
* pInstance
= new X11SalInstance( std::make_unique
<SalYieldMutex
>() );
62 X11SalData
*pSalData
= new X11SalData();
65 pInstance
->SetLib( pSalData
->GetLib() );
71 X11SalInstance::X11SalInstance(std::unique_ptr
<SalYieldMutex
> pMutex
)
72 : SalGenericInstance(std::move(pMutex
))
75 ImplSVData
* pSVData
= ImplGetSVData();
76 // [-loplugin:ostr] if we use a literal here, we get use-after-free on shutdown
77 pSVData
->maAppData
.mxToolkitName
= OUString("x11");
78 m_bSupportsOpenGL
= true;
80 X11SkiaSalGraphicsImpl::prepareSkia();
82 if (SkiaHelper::isVCLSkiaEnabled())
83 m_bSupportsBitmap32
= true;
88 X11SalInstance::~X11SalInstance()
90 // close session management
91 SessionManagerClient::close();
93 // dispose SalDisplay list from SalData
94 // would be done in a static destructor else which is
96 GetGenericUnixSalData()->Dispose();
99 SkiaHelper::cleanup();
103 SalX11Display
* X11SalInstance::CreateDisplay() const
105 return new SalX11Display( mpXLib
->GetDisplay() );
108 // AnyInput from sv/mow/source/app/svapp.cxx
112 struct PredicateReturn
121 static Bool
ImplPredicateEvent( Display
*, XEvent
*pEvent
, char *pData
)
123 PredicateReturn
*pPre
= reinterpret_cast<PredicateReturn
*>(pData
);
130 switch( pEvent
->type
)
137 nType
= VclInputFlags::MOUSE
;
142 nType
= VclInputFlags::KEYBOARD
;
147 nType
= VclInputFlags::PAINT
;
150 nType
= VclInputFlags::NONE
;
153 if ( (nType
& pPre
->nType
) || ( nType
== VclInputFlags::NONE
&& (pPre
->nType
& VclInputFlags::OTHER
) ) )
160 bool X11SalInstance::AnyInput(VclInputFlags nType
)
162 GenericUnixSalData
*pData
= GetGenericUnixSalData();
163 Display
*pDisplay
= vcl_sal::getSalDisplay(pData
)->GetDisplay();
166 if( (nType
& VclInputFlags::TIMER
) && (mpXLib
&& mpXLib
->CheckTimeout(false)) )
169 if( !bRet
&& XPending(pDisplay
) )
171 PredicateReturn aInput
;
175 aInput
.nType
= nType
;
177 XCheckIfEvent(pDisplay
, &aEvent
, ImplPredicateEvent
,
178 reinterpret_cast<char *>(&aInput
) );
182 #if OSL_DEBUG_LEVEL > 1
183 SAL_INFO("vcl.app", "AnyInput "
184 << std::showbase
<< std::hex
185 << static_cast<unsigned int>(nType
)
186 << " = " << (bRet
? "true" : "false"));
191 bool X11SalInstance::DoYield(bool bWait
, bool bHandleAllCurrentEvents
)
193 return mpXLib
->Yield( bWait
, bHandleAllCurrentEvents
);
196 OUString
X11SalInstance::GetConnectionIdentifier()
198 static const char* pDisplay
= getenv( "DISPLAY" );
199 return pDisplay
? OUString::createFromAscii(pDisplay
) : OUString();
202 SalFrame
*X11SalInstance::CreateFrame( SalFrame
*pParent
, SalFrameStyleFlags nSalFrameStyle
)
204 SalFrame
*pFrame
= new X11SalFrame( pParent
, nSalFrameStyle
);
209 SalFrame
* X11SalInstance::CreateChildFrame( SystemParentData
* pParentData
, SalFrameStyleFlags nStyle
)
211 SalFrame
* pFrame
= new X11SalFrame( nullptr, nStyle
, pParentData
);
216 void X11SalInstance::DestroyFrame( SalFrame
* pFrame
)
221 void X11SalInstance::AfterAppInit()
223 assert( mpXLib
->GetDisplay() );
224 assert( mpXLib
->GetInputMethod() );
226 SalX11Display
*pSalDisplay
= CreateDisplay();
227 mpXLib
->GetInputMethod()->CreateMethod( mpXLib
->GetDisplay() );
228 pSalDisplay
->SetupInput();
231 void X11SalInstance::AddToRecentDocumentList(const OUString
&, const OUString
&, const OUString
&) {}
233 void X11SalInstance::PostPrintersChanged()
235 SalDisplay
* pDisp
= vcl_sal::getSalDisplay(GetGenericUnixSalData());
236 for (auto pSalFrame
: pDisp
->getFrames() )
237 pDisp
->PostEvent( pSalFrame
, nullptr, SalEvent::PrinterChanged
);
240 std::unique_ptr
<GenPspGraphics
> X11SalInstance::CreatePrintGraphics()
242 return std::make_unique
<GenPspGraphics
>();
245 std::shared_ptr
<SalBitmap
> X11SalInstance::CreateSalBitmap()
247 #if HAVE_FEATURE_SKIA
248 if (SkiaHelper::isVCLSkiaEnabled())
249 return std::make_shared
<SkiaSalBitmap
>();
251 return std::make_shared
<SvpSalBitmap
>();
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */