LibreOffice Module vcl (master)  1
saldisp.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_INC_UNX_SALDISP_HXX
21 #define INCLUDED_VCL_INC_UNX_SALDISP_HXX
22 
23 class SalDisplay;
24 class SalColormap;
25 class SalVisual;
26 class SalXLib;
27 
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #include <X11/extensions/render.h>
31 #include <epoxy/glx.h>
32 
33 #include <rtl/string.hxx>
34 #include <unx/saltype.h>
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>
47 
48 #include <vclpluginapi.h>
49 
50 /* From <X11/Intrinsic.h> */
51 typedef unsigned long Pixel;
52 
53 class BitmapPalette;
54 class SalFrame;
55 class ColorMask;
56 
57 namespace vcl_sal { class WMAdaptor; }
58 
59 // server vendor
60 
61 typedef enum {
65 } srv_vendor_t;
66 
67 extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
68 
69 // MSB/Bigendian view (Color == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
70 
71 enum class SalRGB { RGB, RBG,
72  GBR, GRB,
73  BGR, BRG,
74  otherSalRGB };
75 
76 class SalVisual : public XVisualInfo
77 {
82  int nRedBits_;
85 public:
86  SalVisual();
87  SalVisual( const XVisualInfo* pXVI );
88 
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; }
93 
94  Pixel GetTCPixel( Color nColor ) const;
95  Color GetTCColor( Pixel nPixel ) const;
96 };
97 
98 // A move-only flag, used by SalColormap to track ownership of its m_aVisual.visual:
99 struct OwnershipFlag {
100  bool owner = false;
101 
102  OwnershipFlag() = default;
103 
104  OwnershipFlag(OwnershipFlag && other) noexcept: owner(other.owner) { other.owner = false; }
105 
106  OwnershipFlag & operator =(OwnershipFlag && other) noexcept {
107  assert(&other != this);
108  owner = other.owner;
109  other.owner = false;
110  return *this;
111  }
112 };
113 
115 {
117  Colormap m_hColormap;
118  std::vector<Color> m_aPalette; // Pseudocolor
121  std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction
124  Pixel m_nUsed; // Pseudocolor
125 
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();
134 
135  ~SalColormap();
136 
137  SalColormap(SalColormap &&) = default;
138  SalColormap & operator =(SalColormap &&) = default;
139 
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; }
148 
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;
159 };
160 
161 class SalI18N_InputMethod;
162 
163 typedef int(*YieldFunc)(int fd, void* data);
164 
165 class SalXLib
166 {
167 protected:
168  timeval m_aTimeout;
171 
172  int nFDs_;
173  fd_set aReadFDS_;
175 
177  std::unique_ptr<SalI18N_InputMethod> m_pInputMethod;
178 
179 public:
180  SalXLib();
181  virtual ~SalXLib();
182  virtual void Init();
183 
184  virtual bool Yield( bool bWait, bool bHandleAllCurrentEvents );
185  virtual void Wakeup();
187 
188  virtual void Insert( int fd, void* data,
189  YieldFunc pending,
190  YieldFunc queued,
191  YieldFunc handle );
192  virtual void Remove( int fd );
193 
194  virtual void StartTimer( sal_uInt64 nMS );
195  virtual void StopTimer();
196 
197  virtual bool CheckTimeout( bool bExecuteTimers = true );
198 
199  SalI18N_InputMethod* GetInputMethod() const { return m_pInputMethod.get(); }
200  Display* GetDisplay() const { return m_pDisplay; }
201 };
202 
204 class AttributeProvider;
205 
206 extern "C" {
207  typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
208 }
209 
210 class GLX11Window final : public GLWindow
211 {
212 public:
214  int screen;
216  XVisualInfo* vi;
217  GLXContext ctx;
218  OString GLXExtensions;
219 
220  bool HasGLXExtension(const char* name) const;
221 
222  GLX11Window();
223  virtual bool Synchronize(bool bOnoff) const override;
224  virtual ~GLX11Window() override;
225 };
226 
228 {
229 public:
230  struct RenderEntry
231  {
232  Pixmap m_aPixmap;
234 
235  RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
236  };
237 
238  typedef std::unordered_map<int,RenderEntry> RenderEntryMap;
239 
240  struct ScreenData
241  {
242  bool m_bInit;
243 
244  ::Window m_aRoot;
245  ::Window m_aRefWindow;
255  Pixmap m_hInvert50;
256  mutable RenderEntryMap m_aRenderData;
257 
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 )
270  {}
271  };
272 
273 protected:
276 
277  Display *pDisp_; // X Display
278 
280  std::vector< ScreenData > m_aScreens;
282  Pair aResolution_; // [dpi]
284 
286 
287  // until x bytes
288 
290 
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
297 
298  std::unique_ptr<vcl_sal::WMAdaptor> m_pWMAdaptor;
299 
301  std::vector< tools::Rectangle > m_aXineramaScreens;
302  std::vector< int > m_aXineramaScreenIndexMap;
303  std::list<SalObject*> m_aSalObjects;
304 
305  mutable Time m_nLastUserEventTime; // mutable because changed on first access
306 
307  virtual bool Dispatch( XEvent *pEvent ) = 0;
308  void InitXinerama();
309  void InitRandR( ::Window aRoot ) const;
310  static void DeInitRandR();
311  void processRandREvent( XEvent* );
312 
313  void doDestruct();
314  void addXineramaScreenUnique( int i, long i_nX, long i_nY, long i_nWidth, long i_nHeight );
315  Time GetEventTimeImpl( bool bAlwaysReget = false ) const;
316 public:
317  static bool BestOpenGLVisual(Display* pDisplay, int nScreen, XVisualInfo& rVI);
318  static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI);
319 
320  SalDisplay( Display* pDisp );
321 
322  virtual ~SalDisplay() override;
323 
324  void Init();
325 
326 #ifdef DBG_UTIL
327  void PrintInfo() const;
328  void DbgPrintDisplayEvent(const char *pComment, XEvent *pEvent) const;
329 #endif
330 
331  void Beep() const;
332 
333  void ModifierMapping();
334  void SimulateKeyPress( sal_uInt16 nKeyCode );
335  KeyIndicatorState GetIndicatorState() const;
336  OUString GetKeyNameFromKeySym( KeySym keysym ) const;
337  OUString GetKeyName( sal_uInt16 nKeyCode ) const;
338  sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
339  KeySym GetKeySym( XKeyEvent *pEvent,
340  char *pPrintable,
341  int *pLen,
342  KeySym *pUnmodifiedKeySym,
343  Status *pStatus,
344  XIC = nullptr ) const;
345 
346  Cursor GetPointer( PointerStyle ePointerStyle );
347  int CaptureMouse( SalFrame *pCapture );
348 
349  ScreenData* initScreen( SalX11Screen nXScreen ) const;
350  const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
351  {
352  if( nXScreen.getXScreen() >= m_aScreens.size() )
353  return m_aInvalidScreenData;
354  if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
355  initScreen( nXScreen );
356  return m_aScreens[nXScreen.getXScreen()];
357  }
358 
359  ::Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
360  Display *GetDisplay() const { return pDisp_; }
361  const SalX11Screen& GetDefaultXScreen() const { return m_nXDefaultScreen; }
362  const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
363  srv_vendor_t GetServerVendor() const { return meServerVendor; }
364  bool IsDisplay() const { return !!pXLib_; }
365  GC GetCopyGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aCopyGC; }
366  Pixmap GetInvert50( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_hInvert50; }
367  const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
368  const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
369  RenderEntryMap& GetRenderEntries( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aRenderData; }
370  const Pair &GetResolution() const { return aResolution_; }
371  sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; }
372  Time GetLastUserEventTime() const { return GetEventTimeImpl(); }
373  // this is an equivalent of gdk_x11_get_server_time()
374  Time GetX11ServerTime() const { return GetEventTimeImpl( true ); }
375 
376  bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate ) const;
377  SalXLib* GetXLib() const { return pXLib_; }
378 
379  SalI18N_InputMethod* GetInputMethod() const { return pXLib_->GetInputMethod(); }
380  SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
382  { mpKbdExtension = pKbdExtension; }
383  ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor.get(); }
384  bool IsXinerama() const { return m_bXinerama; }
385  const std::vector< tools::Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
386  ::Window GetRootWindow( SalX11Screen nXScreen ) const
387  { return getDataForScreen( nXScreen ).m_aRoot; }
388  unsigned int GetXScreenCount() const { return m_aScreens.size(); }
389 
390  const SalFrameSet& getFrames() const { return m_aFrames; }
391 
392  std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
393 };
394 
396 { return m_pDisplay->GetDisplay(); }
397 
398 class SalX11Display final : public SalDisplay
399 {
400 public:
401  SalX11Display( Display* pDisp );
402  virtual ~SalX11Display() override;
403 
404  virtual bool Dispatch( XEvent *pEvent ) override;
405  virtual void Yield();
406  virtual void TriggerUserEventProcessing() override;
407 
408  bool IsEvent();
409  void SetupInput();
410 };
411 
412 namespace vcl_sal {
413  // get foreign key names
414  OUString getKeysymReplacementName(
415  const OUString& pLang,
416  KeySym nSymbol );
417 
419  {
420  assert(data != nullptr);
421  assert(data->GetType() != SAL_DATA_GTK3);
422  return static_cast<SalDisplay *>(data->GetDisplay());
423  }
424 }
425 
426 #endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
427 
428 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Bool(* X_if_predicate)(Display *, XEvent *, XPointer)
Definition: saldisp.hxx:207
bool IsXinerama() const
Definition: saldisp.hxx:384
GenericUnixSalDataType GetType() const
Definition: gendata.hxx:72
std::list< SalObject * > m_aSalObjects
Definition: saldisp.hxx:303
virtual bool Dispatch(XEvent *pEvent) override
SalX11Screen m_nXDefaultScreen
Definition: saldisp.hxx:279
std::unique_ptr< SalI18N_InputMethod > m_pInputMethod
Definition: saldisp.hxx:177
virtual void Init()
OString GLXExtensions
Definition: saldisp.hxx:218
bool IsDisplay() const
Definition: saldisp.hxx:364
virtual ~SalXLib()
Time GetLastUserEventTime() const
Definition: saldisp.hxx:372
unsigned int GetXScreenCount() const
Definition: saldisp.hxx:388
::vcl_sal::WMAdaptor * getWMAdaptor() const
Definition: saldisp.hxx:383
void Init()
virtual void Wakeup()
int m_pTimeoutFDS[2]
Definition: saldisp.hxx:170
o3tl::enumarray< PointerStyle, Cursor > aPointerCache_
Definition: saldisp.hxx:289
SalXLib * GetXLib() const
Definition: saldisp.hxx:377
Time m_nLastUserEventTime
Definition: saldisp.hxx:305
virtual void Remove(int fd)
sal_uIntPtr sal_uLong
void GetPalette()
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
KeySym nCtrlKeySym_
Definition: saldisp.hxx:295
std::vector< int > m_aXineramaScreenIndexMap
Definition: saldisp.hxx:302
const ScreenData & getDataForScreen(SalX11Screen nXScreen) const
Definition: saldisp.hxx:350
Pair aResolution_
Definition: saldisp.hxx:282
int GetDepth() const
Definition: saldisp.hxx:92
const SalDisplay * m_pDisplay
Definition: saldisp.hxx:116
void SetupInput()
Pixel m_nBlackPixel
Definition: saldisp.hxx:123
bool bNumLockFromXS_
Definition: saldisp.hxx:292
None
SalGenericDisplay * GetDisplay() const
Definition: gendata.hxx:60
SalColormap m_aColormap
Definition: saldisp.hxx:248
SalVisual m_aVisual
Definition: saldisp.hxx:119
Color GetTCColor(Pixel nPixel) const
GC GetCopyGC(SalX11Screen nXScreen) const
Definition: saldisp.hxx:365
RenderEntryMap m_aRenderData
Definition: saldisp.hxx:256
bool HasGLXExtension(const char *name) const
Status
SalColormap & operator=(SalColormap &&)=default
virtual void TriggerUserEventProcessing() override
Display * GetDisplay() const
Definition: saldisp.hxx:200
virtual bool Synchronize(bool bOnoff) const override
SalRGB eRGBMode_
Definition: saldisp.hxx:78
Display * m_pDisplay
Definition: saldisp.hxx:176
Pixel GetUsed() const
Definition: saldisp.hxx:147
srv_vendor_t meServerVendor
Definition: saldisp.hxx:285
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
fd_set aReadFDS_
Definition: saldisp.hxx:173
Pixel m_nUsed
Definition: saldisp.hxx:124
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:199
virtual bool CheckTimeout(bool bExecuteTimers=true)
const Size & GetScreenSize(SalX11Screen nXScreen) const
Definition: saldisp.hxx:362
VisualID GetVisualId() const
Definition: saldisp.hxx:89
Pixel GetWhitePixel() const
Definition: saldisp.hxx:145
void TriggerUserEventProcessing()
::Window GetDrawable(SalX11Screen nXScreen) const
Definition: saldisp.hxx:359
::Window GetRootWindow(SalX11Screen nXScreen) const
Definition: saldisp.hxx:386
int nGreenShift_
Definition: saldisp.hxx:80
int nBlueBits_
Definition: saldisp.hxx:84
SalI18N_KeyboardExtension * GetKbdExtension() const
Definition: saldisp.hxx:380
#define VCLPLUG_GEN_PUBLIC
Definition: vclpluginapi.h:29
Display * GetDisplay() const
Definition: saldisp.hxx:360
std::list< SalObject * > & getSalObjects()
Definition: saldisp.hxx:392
Holds the information of our new child window.
unsigned int getXScreen() const
Definition: saltype.h:20
sal_uLong m_nTimeoutMS
Definition: saldisp.hxx:169
const SalVisual & GetVisual(SalX11Screen nXScreen) const
Definition: saldisp.hxx:368
Display * GetXDisplay() const
Definition: saldisp.hxx:395
RenderEntryMap & GetRenderEntries(SalX11Screen nXScreen) const
Definition: saldisp.hxx:369
std::vector< sal_uInt16 > m_aLookupTable
Definition: saldisp.hxx:121
KeyIndicatorState
Definition: keycodes.hxx:180
Time GetX11ServerTime() const
Definition: saldisp.hxx:374
bool GetXPixels(XColor &rColor, int r, int g, int b) const
int GetClass() const
Definition: saldisp.hxx:91
SalXLib * pXLib_
Definition: saldisp.hxx:274
Display
ScreenData m_aInvalidScreenData
Definition: saldisp.hxx:281
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:379
srv_vendor_t
Definition: saldisp.hxx:61
SalRGB
Definition: saldisp.hxx:71
virtual void StopTimer()
SalI18N_KeyboardExtension * mpKbdExtension
Definition: saldisp.hxx:275
Pixmap GetInvert50(SalX11Screen nXScreen) const
Definition: saldisp.hxx:366
virtual bool Yield(bool bWait, bool bHandleAllCurrentEvents)
exports com.sun.star.chart2. data
std::unordered_map< int, RenderEntry > RenderEntryMap
Definition: saldisp.hxx:238
sal_uLong GetMaxRequestSize() const
Definition: saldisp.hxx:371
OwnershipFlag(OwnershipFlag &&other) noexcept
Definition: saldisp.hxx:104
int(* YieldFunc)(int fd, void *data)
Definition: saldisp.hxx:163
int nNumLockIndex_
Definition: saldisp.hxx:293
std::vector< tools::Rectangle > m_aXineramaScreens
Definition: saldisp.hxx:301
GLXContext ctx
Definition: saldisp.hxx:217
Colormap m_hColormap
Definition: saldisp.hxx:117
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
int nFDs_
Definition: saldisp.hxx:172
virtual void Yield()
SalX11Display(Display *pDisp)
fd_set aExceptionFDS_
Definition: saldisp.hxx:174
unsigned long Pixel
Definition: saldisp.hxx:26
const SalDisplay * GetDisplay() const
Definition: saldisp.hxx:141
int nRedBits_
Definition: saldisp.hxx:82
Colormap GetXColormap() const
Definition: saldisp.hxx:140
const std::vector< tools::Rectangle > & GetXineramaScreens() const
Definition: saldisp.hxx:385
OwnershipFlag()=default
std::vector< ScreenData > m_aScreens
Definition: saldisp.hxx:280
void GetLookupTable()
int nBlueShift_
Definition: saldisp.hxx:81
OwnershipFlag m_aVisualOwnership
Definition: saldisp.hxx:120
srv_vendor_t sal_GetServerVendor(Display *p_display)
const SalColormap & GetColormap(SalX11Screen nXScreen) const
Definition: saldisp.hxx:367
virtual ~GLX11Window() override
OwnershipFlag & operator=(OwnershipFlag &&other) noexcept
Definition: saldisp.hxx:106
Pixel GetBlackPixel() const
Definition: saldisp.hxx:146
KeySym nShiftKeySym_
Definition: saldisp.hxx:294
PointerStyle
Definition: ptrstyle.hxx:25
Visual * GetVisual() const
Definition: saldisp.hxx:90
Pixel GetPixel(Color nColor) const
std::vector< Color > m_aPalette
Definition: saldisp.hxx:118
timeval m_aTimeout
Definition: saldisp.hxx:168
virtual void Insert(int fd, void *data, YieldFunc pending, YieldFunc queued, YieldFunc handle)
Visual * GetXVisual() const
Definition: saldisp.hxx:144
Pixel m_nWhitePixel
Definition: saldisp.hxx:122
SalDisplay * getSalDisplay(GenericUnixSalData const *data)
Definition: saldisp.hxx:418
std::unique_ptr< vcl_sal::WMAdaptor > m_pWMAdaptor
Definition: saldisp.hxx:298
Color GetColor(Pixel nPixel) const
srv_vendor_t GetServerVendor() const
Definition: saldisp.hxx:363
Pixel GetTCPixel(Color nColor) const
bool m_bXinerama
Definition: saldisp.hxx:300
bool GetXPixel(XColor &rColor, int r, int g, int b) const
const SalVisual & GetVisual() const
Definition: saldisp.hxx:143
sal_uLong nMaxRequestSize_
Definition: saldisp.hxx:283
const SalFrameSet & getFrames() const
Definition: saldisp.hxx:390
void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
Definition: saldisp.hxx:381
const Pair & GetResolution() const
Definition: saldisp.hxx:370
virtual void StartTimer(sal_uInt64 nMS)
Display * dpy
Definition: saldisp.hxx:213
int nRedShift_
Definition: saldisp.hxx:79
OUString getKeysymReplacementName(const OUString &pLang, KeySym nSymbol)
virtual ~SalX11Display() override
const SalX11Screen & GetDefaultXScreen() const
Definition: saldisp.hxx:361
XVisualInfo * vi
Definition: saldisp.hxx:216
KeySym nMod1KeySym_
Definition: saldisp.hxx:296
int nGreenBits_
Definition: saldisp.hxx:83
Window win
Definition: saldisp.hxx:215
Display * pDisp_
Definition: saldisp.hxx:277