Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / unx / saldisp.hxx
blobd28326e389bbe27d60c7835de5fd6f069ec79144
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 #ifndef INCLUDED_VCL_INC_UNX_SALDISP_HXX
21 #define INCLUDED_VCL_INC_UNX_SALDISP_HXX
23 class SalDisplay;
24 class SalColormap;
25 class SalVisual;
26 class SalXLib;
28 #include <X11/Xlib.h>
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>
41 #include <list>
42 #include <unordered_map>
43 #include <vector>
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;
55 class BitmapPalette;
56 class SalFrame;
57 class ColorMask;
59 namespace vcl_sal { class WMAdaptor; }
61 // server vendor
63 typedef enum {
64 vendor_none = 0,
65 vendor_sun,
66 vendor_unknown
67 } srv_vendor_t;
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,
74 GBR, GRB,
75 BGR, BRG,
76 RGBA, RBGA,
77 GBRA, GRBA,
78 BGRA, BRGA,
79 otherSalRGB };
81 class SalVisual : public XVisualInfo
83 SalRGB eRGBMode_;
84 int nRedShift_;
85 int nGreenShift_;
86 int nBlueShift_;
87 int nRedBits_;
88 int nGreenBits_;
89 int nBlueBits_;
90 public:
91 SalVisual();
92 ~SalVisual();
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;
104 class SalColormap
106 const SalDisplay* m_pDisplay;
107 Colormap m_hColormap;
108 std::vector<SalColor> m_aPalette; // Pseudocolor
109 SalVisual m_aVisual;
110 std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction
111 Pixel m_nWhitePixel;
112 Pixel m_nBlackPixel;
113 Pixel m_nUsed; // Pseudocolor
114 SalX11Screen m_nXScreen;
116 void GetPalette();
117 void GetLookupTable();
118 public:
119 SalColormap( const SalDisplay* pSalDisplay,
120 Colormap hColormap,
121 SalX11Screen nXScreen );
122 SalColormap( sal_uInt16 nDepth );
123 SalColormap();
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,
135 int r,
136 int g,
137 int b ) const;
138 inline bool GetXPixel( XColor &rColor,
139 int r,
140 int g,
141 int b ) const;
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
152 protected:
153 timeval m_aTimeout;
154 sal_uLong m_nTimeoutMS;
155 int m_pTimeoutFDS[2];
156 bool blockIdleTimeout;
158 int nFDs_;
159 fd_set aReadFDS_;
160 fd_set aExceptionFDS_;
162 Display *m_pDisplay;
163 SalI18N_InputMethod *m_pInputMethod;
165 public:
166 SalXLib();
167 virtual ~SalXLib();
168 virtual void Init();
170 virtual SalYieldResult Yield( bool bWait, bool bHandleAllCurrentEvents );
171 virtual void Wakeup();
172 virtual void PostUserEvent();
174 virtual void Insert( int fd, void* data,
175 YieldFunc pending,
176 YieldFunc queued,
177 YieldFunc handle );
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;
192 extern "C" {
193 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
196 class VCLPLUG_GEN_PUBLIC GLX11Window : public GLWindow
198 public:
199 Display* dpy;
200 int screen;
201 Window win;
202 XVisualInfo* vi;
203 GLXContext ctx;
204 OString GLXExtensions;
206 bool HasGLXExtension(const char* name) const;
208 GLX11Window();
209 virtual bool Synchronize(bool bOnoff) const override;
210 virtual ~GLX11Window() override;
213 class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay
215 public:
216 struct RenderEntry
218 Pixmap m_aPixmap;
219 Picture m_aPicture;
221 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
224 typedef std::unordered_map<int,RenderEntry> RenderEntryMap;
226 struct ScreenData
228 bool m_bInit;
230 ::Window m_aRoot;
231 ::Window m_aRefWindow;
232 Size m_aSize;
233 SalVisual m_aVisual;
234 SalColormap m_aColormap;
235 GC m_aMonoGC;
236 GC m_aCopyGC;
237 GC m_aAndInvertedGC;
238 GC m_aAndGC;
239 GC m_aOrGC;
240 GC m_aStippleGC;
241 Pixmap m_hInvert50;
242 mutable RenderEntryMap m_aRenderData;
244 ScreenData() :
245 m_bInit( false ),
246 m_aRoot( None ),
247 m_aRefWindow( None ),
248 m_aMonoGC( None ),
249 m_aCopyGC( None ),
250 m_aAndInvertedGC( None ),
251 m_aAndGC( None ),
252 m_aOrGC( None ),
253 m_aStippleGC( None ),
254 m_hInvert50( None ),
255 m_aRenderData( 1 )
259 protected:
260 SalXLib *pXLib_;
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;
275 // until x bytes
277 o3tl::enumarray<PointerStyle, Cursor> aPointerCache_;
279 // Keyboard
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;
289 bool m_bXinerama;
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;
299 void InitXinerama();
300 void InitRandR( ::Window aRoot ) const;
301 void DeInitRandR();
302 void processRandREvent( XEvent* );
304 void doDestruct();
305 void addXineramaScreenUnique( int i, long i_nX, long i_nY, long i_nWidth, long i_nHeight );
306 public:
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;
314 void Init();
316 #ifdef DBG_UTIL
317 void PrintInfo() const;
318 void DbgPrintDisplayEvent(const char *pComment, XEvent *pEvent) const;
319 #endif
321 void Beep() 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,
330 char *pPrintable,
331 int *pLen,
332 KeySym *pUnmodifiedKeySym,
333 Status *pStatus,
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
391 public:
392 SalX11Display( Display* pDisp );
393 virtual ~SalX11Display() override;
395 virtual bool Dispatch( XEvent *pEvent ) override;
396 virtual void Yield();
397 virtual void PostUserEvent() override;
399 bool IsEvent();
400 void SetupInput();
403 namespace vcl_sal {
404 // get foreign key names
405 OUString getKeysymReplacementName(
406 const OUString& pLang,
407 KeySym nSymbol );
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: */