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 <unx/saldata.hxx>
31 #include <unx/saldisp.hxx>
32 #include <unx/salinst.h>
33 #include <unx/geninst.h>
34 #include <unx/genpspgraphics.h>
35 #include <unx/salframe.h>
37 #include <unx/i18n_im.hxx>
38 #include <unx/salbmp.h>
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 pSVData
->maAppData
.mxToolkitName
= OUString("x11");
77 m_bSupportsOpenGL
= true;
79 X11SkiaSalGraphicsImpl::prepareSkia();
81 if (SkiaHelper::isVCLSkiaEnabled())
82 m_bSupportsBitmap32
= true;
87 X11SalInstance::~X11SalInstance()
89 // close session management
90 SessionManagerClient::close();
92 // dispose SalDisplay list from SalData
93 // would be done in a static destructor else which is
95 GetGenericUnixSalData()->Dispose();
98 SkiaHelper::cleanup();
102 SalX11Display
* X11SalInstance::CreateDisplay() const
104 return new SalX11Display( mpXLib
->GetDisplay() );
107 // AnyInput from sv/mow/source/app/svapp.cxx
111 struct PredicateReturn
120 static Bool
ImplPredicateEvent( Display
*, XEvent
*pEvent
, char *pData
)
122 PredicateReturn
*pPre
= reinterpret_cast<PredicateReturn
*>(pData
);
129 switch( pEvent
->type
)
136 nType
= VclInputFlags::MOUSE
;
141 nType
= VclInputFlags::KEYBOARD
;
146 nType
= VclInputFlags::PAINT
;
149 nType
= VclInputFlags::NONE
;
152 if ( (nType
& pPre
->nType
) || ( nType
== VclInputFlags::NONE
&& (pPre
->nType
& VclInputFlags::OTHER
) ) )
159 bool X11SalInstance::AnyInput(VclInputFlags nType
)
161 GenericUnixSalData
*pData
= GetGenericUnixSalData();
162 Display
*pDisplay
= vcl_sal::getSalDisplay(pData
)->GetDisplay();
165 if( (nType
& VclInputFlags::TIMER
) && (mpXLib
&& mpXLib
->CheckTimeout(false)) )
168 if( !bRet
&& XPending(pDisplay
) )
170 PredicateReturn aInput
;
174 aInput
.nType
= nType
;
176 XCheckIfEvent(pDisplay
, &aEvent
, ImplPredicateEvent
,
177 reinterpret_cast<char *>(&aInput
) );
181 #if OSL_DEBUG_LEVEL > 1
182 SAL_INFO("vcl.app", "AnyInput "
183 << std::showbase
<< std::hex
184 << static_cast<unsigned int>(nType
)
185 << " = " << (bRet
? "true" : "false"));
190 bool X11SalInstance::DoYield(bool bWait
, bool bHandleAllCurrentEvents
)
192 return mpXLib
->Yield( bWait
, bHandleAllCurrentEvents
);
195 OUString
X11SalInstance::GetConnectionIdentifier()
197 static const char* pDisplay
= getenv( "DISPLAY" );
198 return pDisplay
? OUString::createFromAscii(pDisplay
) : OUString();
201 SalFrame
*X11SalInstance::CreateFrame( SalFrame
*pParent
, SalFrameStyleFlags nSalFrameStyle
)
203 SalFrame
*pFrame
= new X11SalFrame( pParent
, nSalFrameStyle
);
208 SalFrame
* X11SalInstance::CreateChildFrame( SystemParentData
* pParentData
, SalFrameStyleFlags nStyle
)
210 SalFrame
* pFrame
= new X11SalFrame( nullptr, nStyle
, pParentData
);
215 void X11SalInstance::DestroyFrame( SalFrame
* pFrame
)
220 void X11SalInstance::AfterAppInit()
222 assert( mpXLib
->GetDisplay() );
223 assert( mpXLib
->GetInputMethod() );
225 SalX11Display
*pSalDisplay
= CreateDisplay();
226 mpXLib
->GetInputMethod()->CreateMethod( mpXLib
->GetDisplay() );
227 pSalDisplay
->SetupInput();
230 void X11SalInstance::AddToRecentDocumentList(const OUString
&, const OUString
&, const OUString
&) {}
232 void X11SalInstance::PostPrintersChanged()
234 SalDisplay
* pDisp
= vcl_sal::getSalDisplay(GetGenericUnixSalData());
235 for (auto pSalFrame
: pDisp
->getFrames() )
236 pDisp
->PostEvent( pSalFrame
, nullptr, SalEvent::PrinterChanged
);
239 std::unique_ptr
<GenPspGraphics
> X11SalInstance::CreatePrintGraphics()
241 return std::make_unique
<GenPspGraphics
>();
244 std::shared_ptr
<SalBitmap
> X11SalInstance::CreateSalBitmap()
246 #if HAVE_FEATURE_SKIA
247 if (SkiaHelper::isVCLSkiaEnabled())
248 return std::make_shared
<SkiaSalBitmap
>();
251 return std::make_shared
<X11SalBitmap
>();
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */