bump product version to 7.2.5.1
[LibreOffice.git] / vcl / inc / unx / saldisp.hxx
blob591423df76834cd7c82fe97af035ef731bfbe9ba
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/render.h>
31 #include <epoxy/glx.h>
33 #include <rtl/string.hxx>
34 #include <unx/saltype.h>
35 #include <vcl/opengl/OpenGLContext.hxx>
36 #include <vcl/ptrstyle.hxx>
37 #include <sal/types.h>
38 #include <cassert>
39 #include <list>
40 #include <unordered_map>
41 #include <vector>
42 #include <tools/gen.hxx>
43 #include <salwtype.hxx>
44 #include <unx/gendata.hxx>
45 #include <unx/gendisp.hxx>
46 #include <o3tl/enumarray.hxx>
48 #include <vclpluginapi.h>
50 /* From <X11/Intrinsic.h> */
51 typedef unsigned long Pixel;
53 class BitmapPalette;
54 class SalFrame;
55 class ColorMask;
57 namespace vcl_sal { class WMAdaptor; }
59 // server vendor
61 typedef enum {
62 vendor_none = 0,
63 vendor_sun,
64 vendor_unknown
65 } srv_vendor_t;
67 extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
69 // MSB/Bigendian view (Color == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
71 enum class SalRGB { RGB, RBG,
72 GBR, GRB,
73 BGR, BRG,
74 otherSalRGB };
76 class SalVisual : public XVisualInfo
78 SalRGB eRGBMode_;
79 int nRedShift_;
80 int nGreenShift_;
81 int nBlueShift_;
82 int nRedBits_;
83 int nGreenBits_;
84 int nBlueBits_;
85 public:
86 SalVisual();
87 SalVisual( const XVisualInfo* pXVI );
89 VisualID GetVisualId() const { return visualid; }
90 Visual *GetVisual() const { return visual; }
91 int GetClass() const { return c_class; }
92 int GetDepth() const { return depth; }
94 Pixel GetTCPixel( Color nColor ) const;
95 Color GetTCColor( Pixel nPixel ) const;
98 // A move-only flag, used by SalColormap to track ownership of its m_aVisual.visual:
99 struct OwnershipFlag {
100 bool owner = false;
102 OwnershipFlag() = default;
104 OwnershipFlag(OwnershipFlag && other) noexcept: owner(other.owner) { other.owner = false; }
106 OwnershipFlag & operator =(OwnershipFlag && other) noexcept {
107 assert(&other != this);
108 owner = other.owner;
109 other.owner = false;
110 return *this;
114 class SalColormap
116 const SalDisplay* m_pDisplay;
117 Colormap m_hColormap;
118 std::vector<Color> m_aPalette; // Pseudocolor
119 SalVisual m_aVisual;
120 OwnershipFlag m_aVisualOwnership;
121 std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction
122 Pixel m_nWhitePixel;
123 Pixel m_nBlackPixel;
124 Pixel m_nUsed; // Pseudocolor
126 void GetPalette();
127 void GetLookupTable();
128 public:
129 SalColormap( const SalDisplay* pSalDisplay,
130 Colormap hColormap,
131 SalX11Screen nXScreen );
132 SalColormap( sal_uInt16 nDepth );
133 SalColormap();
135 ~SalColormap();
137 SalColormap(SalColormap &&) = default;
138 SalColormap & operator =(SalColormap &&) = default;
140 Colormap GetXColormap() const { return m_hColormap; }
141 const SalDisplay* GetDisplay() const { return m_pDisplay; }
142 inline Display* GetXDisplay() const;
143 const SalVisual& GetVisual() const { return m_aVisual; }
144 Visual* GetXVisual() const { return m_aVisual.GetVisual(); }
145 Pixel GetWhitePixel() const { return m_nWhitePixel; }
146 Pixel GetBlackPixel() const { return m_nBlackPixel; }
147 Pixel GetUsed() const { return m_nUsed; }
149 bool GetXPixels( XColor &rColor,
150 int r,
151 int g,
152 int b ) const;
153 inline bool GetXPixel( XColor &rColor,
154 int r,
155 int g,
156 int b ) const;
157 Pixel GetPixel( Color nColor ) const;
158 Color GetColor( Pixel nPixel ) const;
161 class SalI18N_InputMethod;
163 typedef int(*YieldFunc)(int fd, void* data);
165 class SalXLib
167 protected:
168 timeval m_aTimeout;
169 sal_uLong m_nTimeoutMS;
170 int m_pTimeoutFDS[2];
172 int nFDs_;
173 fd_set aReadFDS_;
174 fd_set aExceptionFDS_;
176 Display *m_pDisplay;
177 std::unique_ptr<SalI18N_InputMethod> m_pInputMethod;
179 public:
180 SalXLib();
181 virtual ~SalXLib();
182 virtual void Init();
184 virtual bool Yield( bool bWait, bool bHandleAllCurrentEvents );
185 virtual void Wakeup();
186 void TriggerUserEventProcessing();
188 virtual void Insert( int fd, void* data,
189 YieldFunc pending,
190 YieldFunc queued,
191 YieldFunc handle );
192 virtual void Remove( int fd );
194 virtual void StartTimer( sal_uInt64 nMS );
195 virtual void StopTimer();
197 virtual bool CheckTimeout( bool bExecuteTimers = true );
199 SalI18N_InputMethod* GetInputMethod() const { return m_pInputMethod.get(); }
200 Display* GetDisplay() const { return m_pDisplay; }
203 class SalI18N_KeyboardExtension;
204 class AttributeProvider;
206 extern "C" {
207 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
210 class GLX11Window final : public GLWindow
212 public:
213 Display* dpy;
214 int screen;
215 Window win;
216 XVisualInfo* vi;
217 GLXContext ctx;
218 OString GLXExtensions;
220 bool HasGLXExtension(const char* name) const;
222 GLX11Window();
223 virtual bool Synchronize(bool bOnoff) const override;
224 virtual ~GLX11Window() override;
227 class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay
229 public:
230 struct RenderEntry
232 Pixmap m_aPixmap;
233 Picture m_aPicture;
235 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
238 typedef std::unordered_map<int,RenderEntry> RenderEntryMap;
240 struct ScreenData
242 bool m_bInit;
244 ::Window m_aRoot;
245 ::Window m_aRefWindow;
246 Size m_aSize;
247 SalVisual m_aVisual;
248 SalColormap m_aColormap;
249 GC m_aMonoGC;
250 GC m_aCopyGC;
251 GC m_aAndInvertedGC;
252 GC m_aAndGC;
253 GC m_aOrGC;
254 GC m_aStippleGC;
255 Pixmap m_hInvert50;
256 mutable RenderEntryMap m_aRenderData;
258 ScreenData() :
259 m_bInit( false ),
260 m_aRoot( None ),
261 m_aRefWindow( None ),
262 m_aMonoGC( None ),
263 m_aCopyGC( None ),
264 m_aAndInvertedGC( None ),
265 m_aAndGC( None ),
266 m_aOrGC( None ),
267 m_aStippleGC( None ),
268 m_hInvert50( None ),
269 m_aRenderData( 1 )
273 protected:
274 SalXLib *pXLib_;
275 SalI18N_KeyboardExtension *mpKbdExtension;
277 Display *pDisp_; // X Display
279 SalX11Screen m_nXDefaultScreen;
280 std::vector< ScreenData > m_aScreens;
281 ScreenData m_aInvalidScreenData;
282 Pair aResolution_; // [dpi]
283 sal_uLong nMaxRequestSize_; // [byte]
285 srv_vendor_t meServerVendor;
287 // until x bytes
289 o3tl::enumarray<PointerStyle, Cursor> aPointerCache_;
291 // Keyboard
292 bool bNumLockFromXS_; // Num Lock handled by X Server
293 int nNumLockIndex_; // modifier index in modmap
294 KeySym nShiftKeySym_; // first shift modifier
295 KeySym nCtrlKeySym_; // first control modifier
296 KeySym nMod1KeySym_; // first mod1 modifier
298 std::unique_ptr<vcl_sal::WMAdaptor> m_pWMAdaptor;
300 bool m_bXinerama;
301 std::vector< tools::Rectangle > m_aXineramaScreens;
302 std::vector< int > m_aXineramaScreenIndexMap;
303 std::list<SalObject*> m_aSalObjects;
305 mutable Time m_nLastUserEventTime; // mutable because changed on first access
307 virtual void Dispatch( XEvent *pEvent ) = 0;
308 void InitXinerama();
309 void InitRandR( ::Window aRoot ) const;
310 static void DeInitRandR();
311 void processRandREvent( XEvent* );
313 void doDestruct();
314 void addXineramaScreenUnique( int i, tools::Long i_nX, tools::Long i_nY, tools::Long i_nWidth, tools::Long i_nHeight );
315 Time GetEventTimeImpl( bool bAlwaysReget = false ) const;
316 public:
317 static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI);
319 SalDisplay( Display* pDisp );
321 virtual ~SalDisplay() override;
323 void Init();
325 #ifdef DBG_UTIL
326 void PrintInfo() const;
327 void DbgPrintDisplayEvent(const char *pComment, const XEvent *pEvent) const;
328 #endif
330 void Beep() const;
332 void ModifierMapping();
333 void SimulateKeyPress( sal_uInt16 nKeyCode );
334 KeyIndicatorState GetIndicatorState() const;
335 OUString GetKeyNameFromKeySym( KeySym keysym ) const;
336 OUString GetKeyName( sal_uInt16 nKeyCode ) const;
337 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
338 KeySym GetKeySym( XKeyEvent *pEvent,
339 char *pPrintable,
340 int *pLen,
341 KeySym *pUnmodifiedKeySym,
342 Status *pStatus,
343 XIC = nullptr ) const;
345 Cursor GetPointer( PointerStyle ePointerStyle );
346 int CaptureMouse( SalFrame *pCapture );
348 ScreenData* initScreen( SalX11Screen nXScreen ) const;
349 const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
351 if( nXScreen.getXScreen() >= m_aScreens.size() )
352 return m_aInvalidScreenData;
353 if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
354 initScreen( nXScreen );
355 return m_aScreens[nXScreen.getXScreen()];
358 ::Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
359 Display *GetDisplay() const { return pDisp_; }
360 const SalX11Screen& GetDefaultXScreen() const { return m_nXDefaultScreen; }
361 const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
362 srv_vendor_t GetServerVendor() const { return meServerVendor; }
363 bool IsDisplay() const { return !!pXLib_; }
364 GC GetCopyGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aCopyGC; }
365 Pixmap GetInvert50( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_hInvert50; }
366 const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
367 const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
368 RenderEntryMap& GetRenderEntries( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aRenderData; }
369 const Pair &GetResolution() const { return aResolution_; }
370 sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; }
371 Time GetLastUserEventTime() const { return GetEventTimeImpl(); }
372 // this is an equivalent of gdk_x11_get_server_time()
373 Time GetX11ServerTime() const { return GetEventTimeImpl( true ); }
375 bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate ) const;
376 SalXLib* GetXLib() const { return pXLib_; }
378 SalI18N_InputMethod* GetInputMethod() const { return pXLib_->GetInputMethod(); }
379 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
380 void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
381 { mpKbdExtension = pKbdExtension; }
382 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor.get(); }
383 bool IsXinerama() const { return m_bXinerama; }
384 const std::vector< tools::Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
385 ::Window GetRootWindow( SalX11Screen nXScreen ) const
386 { return getDataForScreen( nXScreen ).m_aRoot; }
387 unsigned int GetXScreenCount() const { return m_aScreens.size(); }
389 const SalFrameSet& getFrames() const { return m_aFrames; }
391 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
394 inline Display *SalColormap::GetXDisplay() const
395 { return m_pDisplay->GetDisplay(); }
397 class SalX11Display final : public SalDisplay
399 public:
400 SalX11Display( Display* pDisp );
401 virtual ~SalX11Display() override;
403 virtual void Dispatch( XEvent *pEvent ) override;
404 virtual void Yield();
405 virtual void TriggerUserEventProcessing() override;
407 bool IsEvent();
408 void SetupInput();
411 namespace vcl_sal {
412 // get foreign key names
413 OUString getKeysymReplacementName(
414 const OUString& pLang,
415 KeySym nSymbol );
417 inline SalDisplay *getSalDisplay(GenericUnixSalData const * data)
419 assert(data != nullptr);
420 assert(data->GetType() != SAL_DATA_GTK3);
421 return static_cast<SalDisplay *>(data->GetDisplay());
425 #endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */