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
28 #include <unx/salunx.h>
29 #include <unx/saltype.h>
30 #include <vcl/salgtype.hxx>
31 #include <vcl/ptrstyle.hxx>
32 #include <sal/types.h>
33 #include <osl/mutex.h>
35 #include <unordered_map>
37 #include <tools/gen.hxx>
38 #include <salwtype.hxx>
39 #include <generic/gendata.hxx>
40 #include <generic/gendisp.hxx>
41 #include <o3tl/enumarray.hxx>
43 #include <vclpluginapi.h>
49 namespace vcl_sal
{ class WMAdaptor
; }
59 extern "C" srv_vendor_t
sal_GetServerVendor( Display
*p_display
);
61 // MSB/Bigendian view (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
63 enum SalRGB
{ RGB
, RBG
,
71 class SalVisual
: public XVisualInfo
83 SalVisual( const XVisualInfo
* pXVI
);
85 inline VisualID
GetVisualId() const { return visualid
; }
86 inline Visual
*GetVisual() const { return visual
; }
87 inline int GetClass() const { return c_class
; }
88 inline int GetDepth() const { return depth
; }
89 inline SalRGB
GetMode() const { return eRGBMode_
; }
91 Pixel
GetTCPixel( SalColor nColor
) const;
92 SalColor
GetTCColor( Pixel nPixel
) const;
97 const SalDisplay
* m_pDisplay
;
99 std::vector
<SalColor
> m_aPalette
; // Pseudocolor
101 std::vector
<sal_uInt16
> m_aLookupTable
; // Pseudocolor: 12bit reduction
104 Pixel m_nUsed
; // Pseudocolor
105 SalX11Screen m_nXScreen
;
108 void GetLookupTable();
110 SalColormap( const SalDisplay
* pSalDisplay
,
112 SalX11Screen nXScreen
);
113 SalColormap( sal_uInt16 nDepth
);
117 inline Colormap
GetXColormap() const { return m_hColormap
; }
118 inline const SalDisplay
* GetDisplay() const { return m_pDisplay
; }
119 inline Display
* GetXDisplay() const;
120 inline const SalVisual
& GetVisual() const { return m_aVisual
; }
121 inline Visual
* GetXVisual() const { return m_aVisual
.GetVisual(); }
122 inline Pixel
GetWhitePixel() const { return m_nWhitePixel
; }
123 inline Pixel
GetBlackPixel() const { return m_nBlackPixel
; }
124 inline Pixel
GetUsed() const { return m_nUsed
; }
125 inline int GetClass() const { return m_aVisual
.GetClass(); }
127 bool GetXPixels( XColor
&rColor
,
131 inline bool GetXPixel( XColor
&rColor
,
135 Pixel
GetPixel( SalColor nColor
) const;
136 SalColor
GetColor( Pixel nPixel
) const;
139 typedef int(*YieldFunc
)(int fd
, void* data
);
141 class VCLPLUG_GEN_PUBLIC SalXLib
145 sal_uLong m_nTimeoutMS
;
146 int m_pTimeoutFDS
[2];
147 bool blockIdleTimeout
;
151 fd_set aExceptionFDS_
;
158 virtual void Yield( bool bWait
, bool bHandleAllCurrentEvents
);
159 virtual void Wakeup();
160 virtual void PostUserEvent();
162 virtual void Insert( int fd
, void* data
,
166 virtual void Remove( int fd
);
168 virtual void StartTimer( sal_uLong nMS
);
169 virtual void StopTimer();
171 bool CheckTimeout( bool bExecuteTimers
= true );
174 class SalI18N_InputMethod
;
175 class SalI18N_KeyboardExtension
;
176 class AttributeProvider
;
179 typedef Bool(*X_if_predicate
)(Display
*,XEvent
*,XPointer
);
182 class VCLPLUG_GEN_PUBLIC SalDisplay
: public SalGenericDisplay
190 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
193 typedef std::unordered_map
<int,RenderEntry
> RenderEntryMap
;
200 ::Window m_aRefWindow
;
203 SalColormap m_aColormap
;
211 mutable RenderEntryMap m_aRenderData
;
216 m_aRefWindow( None
),
219 m_aAndInvertedGC( None
),
222 m_aStippleGC( None
),
230 SalI18N_InputMethod
*mpInputMethod
;
231 SalI18N_KeyboardExtension
*mpKbdExtension
;
233 AttributeProvider
*mpFactory
;
235 Display
*pDisp_
; // X Display
237 SalX11Screen m_nXDefaultScreen
;
238 std::vector
< ScreenData
> m_aScreens
;
239 ScreenData m_aInvalidScreenData
;
240 Pair aResolution_
; // [dpi]
241 sal_uLong nMaxRequestSize_
; // [byte]
243 srv_vendor_t meServerVendor
;
247 o3tl::enumarray
<PointerStyle
, Cursor
> aPointerCache_
;
250 bool bNumLockFromXS_
; // Num Lock handled by X Server
251 int nNumLockIndex_
; // modifier index in modmap
252 int nNumLockMask_
; // keyevent state mask for
253 KeySym nShiftKeySym_
; // first shift modifier
254 KeySym nCtrlKeySym_
; // first control modifier
255 KeySym nMod1KeySym_
; // first mod1 modifier
257 vcl_sal::WMAdaptor
* m_pWMAdaptor
;
260 std::vector
< Rectangle
> m_aXineramaScreens
;
261 std::vector
< int > m_aXineramaScreenIndexMap
;
262 std::list
<SalObject
*> m_aSalObjects
;
264 bool m_bUseRandRWrapper
; // don't use randr on gtk, use gdk signals there
266 mutable Time m_nLastUserEventTime
; // mutable because changed on first access
268 virtual bool Dispatch( XEvent
*pEvent
) = 0;
270 void InitRandR( ::Window aRoot
) const;
272 int processRandREvent( XEvent
* );
275 void addXineramaScreenUnique( int i
, long i_nX
, long i_nY
, long i_nWidth
, long i_nHeight
);
277 static bool BestVisual( Display
*pDisp
,
281 SalDisplay( Display
* pDisp
);
283 virtual ~SalDisplay();
288 void PrintInfo() const;
289 void DbgPrintDisplayEvent(const char *pComment
, XEvent
*pEvent
) const;
294 void ModifierMapping();
295 void SimulateKeyPress( sal_uInt16 nKeyCode
);
296 KeyIndicatorState
GetIndicatorState() const;
297 OUString
GetKeyNameFromKeySym( KeySym keysym
) const;
298 OUString
GetKeyName( sal_uInt16 nKeyCode
) const;
299 sal_uInt16
GetKeyCode( KeySym keysym
, char*pcPrintable
) const;
300 KeySym
GetKeySym( XKeyEvent
*pEvent
,
301 unsigned char *pPrintable
,
303 KeySym
*pUnmodifiedKeySym
,
307 Cursor
GetPointer( PointerStyle ePointerStyle
);
308 virtual int CaptureMouse( SalFrame
*pCapture
);
310 void Remove( XEvent
*pEvent
);
311 virtual ScreenData
*initScreen( SalX11Screen nXScreen
) const;
312 const ScreenData
& getDataForScreen( SalX11Screen nXScreen
) const
314 if( nXScreen
.getXScreen() >= m_aScreens
.size() )
315 return m_aInvalidScreenData
;
316 if( ! m_aScreens
[nXScreen
.getXScreen()].m_bInit
)
317 initScreen( nXScreen
);
318 return m_aScreens
[nXScreen
.getXScreen()];
321 ::Window
GetDrawable( SalX11Screen nXScreen
) const { return getDataForScreen( nXScreen
).m_aRefWindow
; }
322 Display
*GetDisplay() const { return pDisp_
; }
323 SalX11Screen
GetDefaultXScreen() const { return m_nXDefaultScreen
; }
324 const Size
& GetScreenSize( SalX11Screen nXScreen
) const { return getDataForScreen( nXScreen
).m_aSize
; }
325 srv_vendor_t
GetServerVendor() const { return meServerVendor
; }
326 void SetServerVendor() { meServerVendor
= sal_GetServerVendor(pDisp_
); }
327 bool IsDisplay() const { return !!pXLib_
; }
328 GC
GetMonoGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aMonoGC
; }
329 GC
GetCopyGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aCopyGC
; }
330 GC
GetAndInvertedGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aAndInvertedGC
; }
331 GC
GetAndGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aAndGC
; }
332 GC
GetOrGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aOrGC
; }
333 GC
GetStippleGC( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aStippleGC
; }
334 GC
GetGC( sal_uInt16 nDepth
, SalX11Screen nXScreen
) const;
335 Pixmap
GetInvert50( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_hInvert50
; }
336 const SalColormap
& GetColormap( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aColormap
; }
337 const SalVisual
& GetVisual( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aVisual
; }
338 RenderEntryMap
& GetRenderEntries( SalX11Screen nXScreen
) const { return getDataForScreen(nXScreen
).m_aRenderData
; }
339 const Pair
&GetResolution() const { return aResolution_
; }
340 sal_uLong
GetMaxRequestSize() const { return nMaxRequestSize_
; }
341 Time
GetLastUserEventTime( bool bAlwaysReget
= false ) const;
343 bool XIfEventWithTimeout( XEvent
*, XPointer
, X_if_predicate
, long i_nTimeout
= 1000 ) const;
344 SalXLib
* GetXLib() const { return pXLib_
; }
346 SalI18N_InputMethod
* GetInputMethod() const { return mpInputMethod
; }
347 SalI18N_KeyboardExtension
* GetKbdExtension() const { return mpKbdExtension
; }
348 void SetInputMethod( SalI18N_InputMethod
*pInputMethod
)
349 { mpInputMethod
= pInputMethod
; }
350 void SetKbdExtension(SalI18N_KeyboardExtension
*pKbdExtension
)
351 { mpKbdExtension
= pKbdExtension
; }
352 ::vcl_sal::WMAdaptor
* getWMAdaptor() const { return m_pWMAdaptor
; }
353 bool IsXinerama() const { return m_bXinerama
; }
354 const std::vector
< Rectangle
>& GetXineramaScreens() const { return m_aXineramaScreens
; }
355 ::Window
GetRootWindow( SalX11Screen nXScreen
) const
356 { return getDataForScreen( nXScreen
).m_aRoot
; }
357 const std::vector
< ScreenData
>& GetScreenData() { return m_aScreens
; }
358 unsigned int GetXScreenCount() const { return m_aScreens
.size(); }
360 const std::list
< SalFrame
* >& getFrames() const { return m_aFrames
; }
361 bool IsNumLockFromXS() const { return bNumLockFromXS_
; }
363 std::list
< SalObject
* >& getSalObjects() { return m_aSalObjects
; }
365 virtual void PostUserEvent() SAL_OVERRIDE
= 0;
368 inline GC
SalDisplay::GetGC( sal_uInt16 nDepth
, SalX11Screen nXScreen
) const
370 ? GetMonoGC( nXScreen
)
371 : getDataForScreen(nXScreen
).m_aVisual
.GetDepth() == nDepth
372 ? GetCopyGC( nXScreen
)
375 inline Display
*SalColormap::GetXDisplay() const
376 { return m_pDisplay
->GetDisplay(); }
378 class VCLPLUG_GEN_PUBLIC SalX11Display
: public SalDisplay
381 SalX11Display( Display
* pDisp
);
382 virtual ~SalX11Display();
384 virtual bool Dispatch( XEvent
*pEvent
) SAL_OVERRIDE
;
385 virtual void Yield();
386 virtual void PostUserEvent() SAL_OVERRIDE
;
389 void SetupInput( SalI18N_InputMethod
*pInputMethod
);
393 // get foreign key names
394 OUString
getKeysymReplacementName(
395 const OUString
& pLang
,
398 inline SalDisplay
*getSalDisplay(SalGenericData
const * data
)
400 assert(data
!= nullptr);
401 assert(data
->GetType() != SAL_DATA_GTK3
);
402 return static_cast<SalDisplay
*>(data
->GetDisplay());
406 #endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */