nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / app / salinst.cxx
blob21d878cfa6122242707918561411264d72119565
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <stdlib.h>
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>
28 #include <unx/sm.hxx>
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>
38 #if HAVE_FEATURE_SKIA
39 #include <skia/x11/gdiimpl.hxx>
40 #endif
42 // plugin factory function
43 extern "C"
45 VCLPLUG_GEN_PUBLIC SalInstance* create_SalInstance()
47 /* #i92121# workaround deadlocks in the X11 implementation
49 static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
50 /* #i90094#
51 from now on we know that an X connection will be
52 established, so protect X against itself
54 if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
55 XInitThreads();
57 X11SalInstance* pInstance = new X11SalInstance( std::make_unique<SalYieldMutex>() );
59 // initialize SalData
60 X11SalData *pSalData = new X11SalData( SAL_DATA_UNX, pInstance );
62 pSalData->Init();
63 pInstance->SetLib( pSalData->GetLib() );
65 return pInstance;
69 X11SalInstance::X11SalInstance(std::unique_ptr<SalYieldMutex> pMutex)
70 : SalGenericInstance(std::move(pMutex))
71 , mpXLib(nullptr)
73 ImplSVData* pSVData = ImplGetSVData();
74 pSVData->maAppData.mxToolkitName = OUString("x11");
75 #if HAVE_FEATURE_SKIA
76 X11SkiaSalGraphicsImpl::prepareSkia();
77 #endif
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
87 // a little late
88 GetGenericUnixSalData()->Dispose();
90 #if HAVE_FEATURE_SKIA
91 SkiaHelper::cleanup();
92 #endif
95 SalX11Display* X11SalInstance::CreateDisplay() const
97 return new SalX11Display( mpXLib->GetDisplay() );
100 // AnyInput from sv/mow/source/app/svapp.cxx
102 namespace {
104 struct PredicateReturn
106 VclInputFlags nType;
107 bool bRet;
112 extern "C" {
113 static Bool ImplPredicateEvent( Display *, XEvent *pEvent, char *pData )
115 PredicateReturn *pPre = reinterpret_cast<PredicateReturn *>(pData);
117 if ( pPre->bRet )
118 return False;
120 VclInputFlags nType;
122 switch( pEvent->type )
124 case ButtonPress:
125 case ButtonRelease:
126 case MotionNotify:
127 case EnterNotify:
128 case LeaveNotify:
129 nType = VclInputFlags::MOUSE;
130 break;
132 case KeyPress:
133 //case KeyRelease:
134 nType = VclInputFlags::KEYBOARD;
135 break;
136 case Expose:
137 case GraphicsExpose:
138 case NoExpose:
139 nType = VclInputFlags::PAINT;
140 break;
141 default:
142 nType = VclInputFlags::NONE;
145 if ( (nType & pPre->nType) || ( nType == VclInputFlags::NONE && (pPre->nType & VclInputFlags::OTHER) ) )
146 pPre->bRet = true;
148 return False;
152 bool X11SalInstance::AnyInput(VclInputFlags nType)
154 GenericUnixSalData *pData = GetGenericUnixSalData();
155 Display *pDisplay = vcl_sal::getSalDisplay(pData)->GetDisplay();
156 bool bRet = false;
158 if( (nType & VclInputFlags::TIMER) && (mpXLib && mpXLib->CheckTimeout(false)) )
159 bRet = true;
161 if( !bRet && XPending(pDisplay) )
163 PredicateReturn aInput;
164 XEvent aEvent;
166 aInput.bRet = false;
167 aInput.nType = nType;
169 XCheckIfEvent(pDisplay, &aEvent, ImplPredicateEvent,
170 reinterpret_cast<char *>(&aInput) );
172 bRet = aInput.bRet;
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"));
179 #endif
180 return bRet;
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 );
198 return pFrame;
201 SalFrame* X11SalInstance::CreateChildFrame( SystemParentData* pParentData, SalFrameStyleFlags nStyle )
203 SalFrame* pFrame = new X11SalFrame( nullptr, nStyle, pParentData );
205 return pFrame;
208 void X11SalInstance::DestroyFrame( SalFrame* pFrame )
210 delete 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;
244 #endif
245 #endif
246 return pBackendCapabilities;
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */