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 #ifndef INCLUDED_VCL_INC_UNX_SALDISP_HXX
21 #define INCLUDED_VCL_INC_UNX_SALDISP_HXX
29 #include <X11/Xutil.h>
30 #include <X11/extensions/Xrender.h>
31 #include <epoxy/glx.h>
33 #include <rtl/string.hxx>
34 #include <unx/salunx.h>
35 #include <unx/saltype.h>
36 #include <vcl/opengl/OpenGLContext.hxx>
37 #include <vcl/salgtype.hxx>
38 #include <vcl/ptrstyle.hxx>
39 #include <sal/types.h>
40 #include <osl/mutex.h>
42 #include <unordered_map>
44 #include <tools/gen.hxx>
45 #include <salwtype.hxx>
46 #include <unx/gendata.hxx>
47 #include <unx/gendisp.hxx>
48 #include <o3tl/enumarray.hxx>
50 #include <vclpluginapi.h>
52 /* From <X11/Intrinsic.h> */
53 typedef unsigned long Pixel
;
59 namespace vcl_sal
{ class WMAdaptor
; }
69 extern "C" srv_vendor_t
sal_GetServerVendor( Display
*p_display
);
71 // MSB/Bigendian view (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
73 enum SalRGB
{ RGB
, RBG
,
81 class SalVisual
: public XVisualInfo
93 SalVisual( const XVisualInfo
* pXVI
);
95 VisualID
GetVisualId() const { return visualid
; }
96 Visual
*GetVisual() const { return visual
; }
97 int GetClass() const { return c_class
; }
98 int GetDepth() const { return depth
; }
100 Pixel
GetTCPixel( SalColor nColor
) const;
101 SalColor
GetTCColor( Pixel nPixel
) const;
106 const SalDisplay
* m_pDisplay
;
107 Colormap m_hColormap
;
108 std::vector
<SalColor
> m_aPalette
; // Pseudocolor
110 std::vector
<sal_uInt16
> m_aLookupTable
; // Pseudocolor: 12bit reduction
113 Pixel m_nUsed
; // Pseudocolor
114 SalX11Screen m_nXScreen
;
117 void GetLookupTable();
119 SalColormap( const SalDisplay
* pSalDisplay
,
121 SalX11Screen nXScreen
);
122 SalColormap( sal_uInt16 nDepth
);
125 Colormap
GetXColormap() const { return m_hColormap
; }
126 const SalDisplay
* GetDisplay() const { return m_pDisplay
; }
127 inline Display
* GetXDisplay() const;
128 const SalVisual
& GetVisual() const { return m_aVisual
; }
129 Visual
* GetXVisual() const { return m_aVisual
.GetVisual(); }
130 Pixel
GetWhitePixel() const { return m_nWhitePixel
; }
131 Pixel
GetBlackPixel() const { return m_nBlackPixel
; }
132 Pixel
GetUsed() const { return m_nUsed
; }
134 bool GetXPixels( XColor
&rColor
,
138 inline bool GetXPixel( XColor
&rColor
,
142 Pixel
GetPixel( SalColor nColor
) const;
143 SalColor
GetColor( Pixel nPixel
) const;
146 class SalI18N_InputMethod
;
148 typedef int(*YieldFunc
)(int fd
, void* data
);
150 class VCLPLUG_GEN_PUBLIC SalXLib
154 sal_uLong m_nTimeoutMS
;
155 int m_pTimeoutFDS
[2];
156 bool blockIdleTimeout
;
160 fd_set aExceptionFDS_
;
163 SalI18N_InputMethod
*m_pInputMethod
;
170 virtual SalYieldResult
Yield( bool bWait
, bool bHandleAllCurrentEvents
);
171 virtual void Wakeup();
172 virtual void PostUserEvent();
174 virtual void Insert( int fd
, void* data
,
178 virtual void Remove( int fd
);
180 virtual void StartTimer( sal_uLong nMS
);
181 virtual void StopTimer();
183 bool CheckTimeout( bool bExecuteTimers
= true );
185 SalI18N_InputMethod
* GetInputMethod() const { return m_pInputMethod
; }
186 Display
* GetDisplay() const { return m_pDisplay
; }
189 class SalI18N_KeyboardExtension
;
190 class AttributeProvider
;
193 typedef Bool(*X_if_predicate
)(Display
*,XEvent
*,XPointer
);
196 class VCLPLUG_GEN_PUBLIC GLX11Window
: public GLWindow
204 OString GLXExtensions
;
206 bool HasGLXExtension(const char* name
) const;
209 virtual bool Synchronize(bool bOnoff
) const override
;
210 virtual ~GLX11Window() override
;
213 class VCLPLUG_GEN_PUBLIC SalDisplay
: public SalGenericDisplay
221 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
224 typedef std::unordered_map
<int,RenderEntry
> RenderEntryMap
;
231 ::Window m_aRefWindow
;
234 SalColormap m_aColormap
;
242 mutable RenderEntryMap m_aRenderData
;
247 m_aRefWindow( None
),
250 m_aAndInvertedGC( None
),
253 m_aStippleGC( None
),
261 SalI18N_KeyboardExtension
*mpKbdExtension
;
263 AttributeProvider
*mpFactory
;
265 Display
*pDisp_
; // X Display
267 SalX11Screen m_nXDefaultScreen
;
268 std::vector
< ScreenData
> m_aScreens
;
269 ScreenData m_aInvalidScreenData
;
270 Pair aResolution_
; // [dpi]
271 sal_uLong nMaxRequestSize_
; // [byte]
273 srv_vendor_t meServerVendor
;
277 o3tl::enumarray
<PointerStyle
, Cursor
> aPointerCache_
;
280 bool bNumLockFromXS_
; // Num Lock handled by X Server
281 int nNumLockIndex_
; // modifier index in modmap
282 int nNumLockMask_
; // keyevent state mask for
283 KeySym nShiftKeySym_
; // first shift modifier
284 KeySym nCtrlKeySym_
; // first control modifier
285 KeySym nMod1KeySym_
; // first mod1 modifier
287 vcl_sal::WMAdaptor
* m_pWMAdaptor
;
290 std::vector
< tools::Rectangle
> m_aXineramaScreens
;
291 std::vector
< int > m_aXineramaScreenIndexMap
;
292 std::list
<SalObject
*> m_aSalObjects
;
294 bool m_bUseRandRWrapper
; // don't use randr on gtk, use gdk signals there
296 mutable Time m_nLastUserEventTime
; // mutable because changed on first access
298 virtual bool Dispatch( XEvent
*pEvent
) = 0;
300 void InitRandR( ::Window aRoot
) const;
302 void processRandREvent( XEvent
* );
305 void addXineramaScreenUnique( int i
, long i_nX
, long i_nY
, long i_nWidth
, long i_nHeight
);
307 static bool BestOpenGLVisual(Display
* pDisplay
, int nScreen
, XVisualInfo
& rVI
);
308 static bool BestVisual(Display
*pDisp
, int nScreen
, XVisualInfo
&rVI
);
310 SalDisplay( Display
* pDisp
);
312 virtual ~SalDisplay() override
;
317 void PrintInfo() const;
318 void DbgPrintDisplayEvent(const char *pComment
, XEvent
*pEvent
) const;
323 void ModifierMapping();
324 void SimulateKeyPress( sal_uInt16 nKeyCode
);
325 KeyIndicatorState
GetIndicatorState() const;
326 OUString
GetKeyNameFromKeySym( KeySym keysym
) const;
327 OUString
GetKeyName( sal_uInt16 nKeyCode
) const;
328 sal_uInt16
GetKeyCode( KeySym keysym
, char*pcPrintable
) const;
329 KeySym
GetKeySym( XKeyEvent
*pEvent
,
332 KeySym
*pUnmodifiedKeySym
,
334 XIC
= nullptr ) const;
336 Cursor
GetPointer( PointerStyle ePointerStyle
);
337 virtual int CaptureMouse( SalFrame
*pCapture
);
339 virtual ScreenData
*initScreen( SalX11Screen nXScreen
) const;
340 const ScreenData
& getDataForScreen( SalX11Screen nXScreen
) const
342 if( nXScreen
.getXScreen() >= m_aScreens
.size() )
343 return m_aInvalidScreenData
;
344 if( ! m_aScreens
[nXScreen
.getXScreen()].m_bInit
)
345 initScreen( nXScreen
);
346 return m_aScreens
[nXScreen
.getXScreen()];
349 ::Window
GetDrawable( SalX11Screen nXScreen
) const { return getDataForScreen( nXScreen
).m_aRefWindow
; }
350 Display
*GetDisplay() const { return pDisp_
; }
351 const SalX11Screen
& GetDefaultXScreen() const { return m_nXDefaultScreen
; }
352 const Size
& GetScreenSize( SalX11Screen nXScreen
) const { return getDataForScreen( nXScreen
).m_aSize
; }
353 srv_vendor_t
GetServerVendor() const { return meServerVendor
; }
354 bool IsDisplay() const { return !!pXLib_
; }
355 GC
GetCopyGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aCopyGC
; }
356 Pixmap
GetInvert50( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_hInvert50
; }
357 const SalColormap
& GetColormap( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aColormap
; }
358 const SalVisual
& GetVisual( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aVisual
; }
359 RenderEntryMap
& GetRenderEntries( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aRenderData
; }
360 const Pair
&GetResolution() const { return aResolution_
; }
361 sal_uLong
GetMaxRequestSize() const { return nMaxRequestSize_
; }
362 Time
GetLastUserEventTime( bool bAlwaysReget
= false ) const;
364 bool XIfEventWithTimeout( XEvent
*, XPointer
, X_if_predicate
) const;
365 SalXLib
* GetXLib() const { return pXLib_
; }
367 SalI18N_InputMethod
* GetInputMethod() const { return pXLib_
->GetInputMethod(); }
368 SalI18N_KeyboardExtension
* GetKbdExtension() const { return mpKbdExtension
; }
369 void SetKbdExtension(SalI18N_KeyboardExtension
*pKbdExtension
)
370 { mpKbdExtension
= pKbdExtension
; }
371 ::vcl_sal::WMAdaptor
* getWMAdaptor() const { return m_pWMAdaptor
; }
372 bool IsXinerama() const { return m_bXinerama
; }
373 const std::vector
< tools::Rectangle
>& GetXineramaScreens() const { return m_aXineramaScreens
; }
374 ::Window
GetRootWindow( SalX11Screen nXScreen
) const
375 { return getDataForScreen( nXScreen
).m_aRoot
; }
376 unsigned int GetXScreenCount() const { return m_aScreens
.size(); }
378 const std::list
< SalFrame
* >& getFrames() const { return m_aFrames
; }
379 bool IsNumLockFromXS() const { return bNumLockFromXS_
; }
381 std::list
< SalObject
* >& getSalObjects() { return m_aSalObjects
; }
383 virtual void PostUserEvent() override
= 0;
386 inline Display
*SalColormap::GetXDisplay() const
387 { return m_pDisplay
->GetDisplay(); }
389 class VCLPLUG_GEN_PUBLIC SalX11Display
: public SalDisplay
392 SalX11Display( Display
* pDisp
);
393 virtual ~SalX11Display() override
;
395 virtual bool Dispatch( XEvent
*pEvent
) override
;
396 virtual void Yield();
397 virtual void PostUserEvent() override
;
404 // get foreign key names
405 OUString
getKeysymReplacementName(
406 const OUString
& pLang
,
409 inline SalDisplay
*getSalDisplay(SalGenericData
const * data
)
411 assert(data
!= nullptr);
412 assert(data
->GetType() != SAL_DATA_GTK3
);
413 return static_cast<SalDisplay
*>(data
->GetDisplay());
417 #endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */