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#include <X11/Xlib.h>
24#include <X11/Xutil.h>
25#include <X11/extensions/render.h>
26#include <epoxy/glx.h>
27
28#include <rtl/string.hxx>
29#include <unx/saltype.h>
31#include <vcl/ptrstyle.hxx>
32#include <sal/types.h>
33#include <cassert>
34#include <list>
35#include <unordered_map>
36#include <vector>
37#include <tools/gen.hxx>
38#include <salwtype.hxx>
39#include <unx/gendata.hxx>
40#include <unx/gendisp.hxx>
41#include <o3tl/enumarray.hxx>
42
43#include <vclpluginapi.h>
44
45class SalDisplay;
46class SalColormap;
47class SalVisual;
48class SalXLib;
49
50
51/* From <X11/Intrinsic.h> */
52typedef unsigned long Pixel;
53
54class BitmapPalette;
55class SalFrame;
56class ColorMask;
57
58namespace vcl_sal { class WMAdaptor; }
59
60// server vendor
61
62typedef enum {
67
68extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
69
70// MSB/Bigendian view (Color == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
71
72enum class SalRGB { RGB, RBG,
73 GBR, GRB,
74 BGR, BRG,
76
77class SalVisual : public XVisualInfo
78{
86public:
88 SalVisual( const XVisualInfo* pXVI );
89
90 VisualID GetVisualId() const { return visualid; }
91 Visual *GetVisual() const { return visual; }
92 int GetClass() const { return c_class; }
93 int GetDepth() const { return depth; }
94
95 Pixel GetTCPixel( Color nColor ) const;
96};
97
98// A move-only flag, used by SalColormap to track ownership of its m_aVisual.visual:
100 bool owner = false;
101
102 OwnershipFlag() = default;
103
104 OwnershipFlag(OwnershipFlag && other) noexcept: owner(other.owner) { other.owner = false; }
105
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
128public:
129 SalColormap( const SalDisplay* pSalDisplay,
130 Colormap hColormap,
131 SalX11Screen nXScreen );
132 SalColormap( sal_uInt16 nDepth );
134
136
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; }
146
147 bool GetXPixels( XColor &rColor,
148 int r,
149 int g,
150 int b ) const;
151 inline bool GetXPixel( XColor &rColor,
152 int r,
153 int g,
154 int b ) const;
155 Pixel GetPixel( std::optional<Color> nColor ) const;
156};
157
159
160typedef int(*YieldFunc)(int fd, void* data);
161
163{
164 timeval m_aTimeout;
167
168 int nFDs_;
169 fd_set aReadFDS_;
171
173 std::unique_ptr<SalI18N_InputMethod> m_pInputMethod;
174
175public:
178 void Init();
179
180 bool Yield( bool bWait, bool bHandleAllCurrentEvents );
181 void Wakeup();
183
184 void Insert( int fd, void* data,
185 YieldFunc pending,
186 YieldFunc queued,
187 YieldFunc handle );
188 void Remove( int fd );
189
190 void StartTimer( sal_uInt64 nMS );
191 void StopTimer();
192
193 bool CheckTimeout( bool bExecuteTimers = true );
194
196 Display* GetDisplay() const { return m_pDisplay; }
197};
198
200class AttributeProvider;
201
202extern "C" {
203 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
204}
205
206class GLX11Window final : public GLWindow
207{
208public:
212 XVisualInfo* vi;
213 GLXContext ctx;
215
216 bool HasGLXExtension(const char* name) const;
217
218 GLX11Window();
219 virtual bool Synchronize(bool bOnoff) const override;
220 virtual ~GLX11Window() override;
221};
222
224{
225public:
226
228 {
230
231 ::Window m_aRoot;
232 ::Window m_aRefWindow;
243
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 {}
256 };
257
258protected:
261
262 Display *pDisp_; // X Display
263
265 std::vector< ScreenData > m_aScreens;
269
271
272 // until x bytes
273
275
276 // Keyboard
277 bool bNumLockFromXS_; // Num Lock handled by X Server
278 int nNumLockIndex_; // modifier index in modmap
279 KeySym nShiftKeySym_; // first shift modifier
280 KeySym nCtrlKeySym_; // first control modifier
281 KeySym nMod1KeySym_; // first mod1 modifier
282
283 std::unique_ptr<vcl_sal::WMAdaptor> m_pWMAdaptor;
284
286 std::vector< tools::Rectangle > m_aXineramaScreens;
287 std::vector< int > m_aXineramaScreenIndexMap;
288 std::list<SalObject*> m_aSalObjects;
289
290 mutable Time m_nLastUserEventTime; // mutable because changed on first access
291
292 virtual void Dispatch( XEvent *pEvent ) = 0;
294 void InitRandR( ::Window aRoot ) const;
295 static void DeInitRandR();
296 void processRandREvent( XEvent* );
297
299 void addXineramaScreenUnique( int i, tools::Long i_nX, tools::Long i_nY, tools::Long i_nWidth, tools::Long i_nHeight );
300 Time GetEventTimeImpl( bool bAlwaysReget = false ) const;
301public:
302 static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI);
303
305
306 virtual ~SalDisplay() override;
307
308 void Init();
309
310#ifdef DBG_UTIL
311 void PrintInfo() const;
312 void DbgPrintDisplayEvent(const char *pComment, const XEvent *pEvent) const;
313#endif
314
315 void Beep() const;
316
318 void SimulateKeyPress( sal_uInt16 nKeyCode );
320 OUString GetKeyNameFromKeySym( KeySym keysym ) const;
321 OUString GetKeyName( sal_uInt16 nKeyCode ) const;
322 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
323 KeySym GetKeySym( XKeyEvent *pEvent,
324 char *pPrintable,
325 int *pLen,
326 KeySym *pUnmodifiedKeySym,
327 Status *pStatus,
328 XIC = nullptr ) const;
329
331 int CaptureMouse( SalFrame *pCapture );
332
334 const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
335 {
336 if( nXScreen.getXScreen() >= m_aScreens.size() )
337 return m_aInvalidScreenData;
338 if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
339 initScreen( nXScreen );
340 return m_aScreens[nXScreen.getXScreen()];
341 }
342
343 ::Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
344 Display *GetDisplay() const { return pDisp_; }
345 const SalX11Screen& GetDefaultXScreen() const { return m_nXDefaultScreen; }
346 const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
347 srv_vendor_t GetServerVendor() const { return meServerVendor; }
348 bool IsDisplay() const { return !!pXLib_; }
349 const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
350 const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
351 const Pair &GetResolution() const { return aResolution_; }
352 Time GetLastUserEventTime() const { return GetEventTimeImpl(); }
353 // this is an equivalent of gdk_x11_get_server_time()
354 Time GetX11ServerTime() const { return GetEventTimeImpl( true ); }
355
356 SalI18N_InputMethod* GetInputMethod() const { return pXLib_->GetInputMethod(); }
357 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
359 { mpKbdExtension = pKbdExtension; }
360 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor.get(); }
361 bool IsXinerama() const { return m_bXinerama; }
362 const std::vector< tools::Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
363 ::Window GetRootWindow( SalX11Screen nXScreen ) const
364 { return getDataForScreen( nXScreen ).m_aRoot; }
365 unsigned int GetXScreenCount() const { return m_aScreens.size(); }
366
367 const SalFrameSet& getFrames() const { return m_aFrames; }
368
369 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
370};
371
373{ return m_pDisplay->GetDisplay(); }
374
375class SalX11Display final : public SalDisplay
376{
377public:
379 virtual ~SalX11Display() override;
380
381 virtual void Dispatch( XEvent *pEvent ) override;
382 virtual void Yield();
383 virtual void TriggerUserEventProcessing() override;
384
385 bool IsEvent();
387};
388
389namespace vcl_sal {
390 // get foreign key names
392 std::u16string_view pLang,
393 KeySym nSymbol );
394
396 {
397 assert(data != nullptr);
398 return static_cast<SalDisplay *>(data->GetDisplay());
399 }
400}
401
402#endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
403
404/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GLXContext ctx
Definition: saldisp.hxx:213
virtual bool Synchronize(bool bOnoff) const override
Display * dpy
Definition: saldisp.hxx:209
virtual ~GLX11Window() override
Window win
Definition: saldisp.hxx:211
bool HasGLXExtension(const char *name) const
XVisualInfo * vi
Definition: saldisp.hxx:212
OString GLXExtensions
Definition: saldisp.hxx:214
SalGenericDisplay * GetDisplay() const
Definition: gendata.hxx:76
Colormap m_hColormap
Definition: saldisp.hxx:117
SalColormap(const SalDisplay *pSalDisplay, Colormap hColormap, SalX11Screen nXScreen)
bool GetXPixels(XColor &rColor, int r, int g, int b) const
std::vector< Color > m_aPalette
Definition: saldisp.hxx:118
Display * GetXDisplay() const
Definition: saldisp.hxx:372
Pixel GetBlackPixel() const
Definition: saldisp.hxx:145
std::vector< sal_uInt16 > m_aLookupTable
Definition: saldisp.hxx:121
const SalDisplay * GetDisplay() const
Definition: saldisp.hxx:141
const SalVisual & GetVisual() const
Definition: saldisp.hxx:143
Pixel GetPixel(std::optional< Color > nColor) const
Pixel GetWhitePixel() const
Definition: saldisp.hxx:144
const SalDisplay * m_pDisplay
Definition: saldisp.hxx:116
SalColormap(SalColormap &&)=default
Colormap GetXColormap() const
Definition: saldisp.hxx:140
OwnershipFlag m_aVisualOwnership
Definition: saldisp.hxx:120
Pixel m_nBlackPixel
Definition: saldisp.hxx:123
bool GetXPixel(XColor &rColor, int r, int g, int b) const
void GetLookupTable()
void GetPalette()
Pixel m_nUsed
Definition: saldisp.hxx:124
SalColormap(sal_uInt16 nDepth)
SalColormap & operator=(SalColormap &&)=default
SalVisual m_aVisual
Definition: saldisp.hxx:119
Pixel m_nWhitePixel
Definition: saldisp.hxx:122
void Init()
srv_vendor_t GetServerVendor() const
Definition: saldisp.hxx:347
SalX11Screen m_nXDefaultScreen
Definition: saldisp.hxx:264
Display * pDisp_
Definition: saldisp.hxx:262
unsigned int GetXScreenCount() const
Definition: saldisp.hxx:365
std::vector< ScreenData > m_aScreens
Definition: saldisp.hxx:265
ScreenData * initScreen(SalX11Screen nXScreen) const
Pair aResolution_
Definition: saldisp.hxx:267
const SalColormap & GetColormap(SalX11Screen nXScreen) const
Definition: saldisp.hxx:349
OUString GetKeyName(sal_uInt16 nKeyCode) const
void InitXinerama()
::Window GetRootWindow(SalX11Screen nXScreen) const
Definition: saldisp.hxx:363
KeySym nMod1KeySym_
Definition: saldisp.hxx:281
Time GetEventTimeImpl(bool bAlwaysReget=false) const
Cursor GetPointer(PointerStyle ePointerStyle)
const ScreenData & getDataForScreen(SalX11Screen nXScreen) const
Definition: saldisp.hxx:334
::vcl_sal::WMAdaptor * getWMAdaptor() const
Definition: saldisp.hxx:360
int CaptureMouse(SalFrame *pCapture)
std::vector< tools::Rectangle > m_aXineramaScreens
Definition: saldisp.hxx:286
void addXineramaScreenUnique(int i, tools::Long i_nX, tools::Long i_nY, tools::Long i_nWidth, tools::Long i_nHeight)
void ModifierMapping()
void PrintInfo() const
static void DeInitRandR()
Time m_nLastUserEventTime
Definition: saldisp.hxx:290
const SalVisual & GetVisual(SalX11Screen nXScreen) const
Definition: saldisp.hxx:350
SalI18N_KeyboardExtension * mpKbdExtension
Definition: saldisp.hxx:260
void InitRandR(::Window aRoot) const
KeyIndicatorState GetIndicatorState() const
::Window GetDrawable(SalX11Screen nXScreen) const
Definition: saldisp.hxx:343
OUString GetKeyNameFromKeySym(KeySym keysym) const
KeySym nCtrlKeySym_
Definition: saldisp.hxx:280
SalI18N_KeyboardExtension * GetKbdExtension() const
Definition: saldisp.hxx:357
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:356
virtual ~SalDisplay() override
std::list< SalObject * > m_aSalObjects
Definition: saldisp.hxx:288
sal_uInt16 GetKeyCode(KeySym keysym, char *pcPrintable) const
o3tl::enumarray< PointerStyle, Cursor > aPointerCache_
Definition: saldisp.hxx:274
void SimulateKeyPress(sal_uInt16 nKeyCode)
const Size & GetScreenSize(SalX11Screen nXScreen) const
Definition: saldisp.hxx:346
static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI)
std::vector< int > m_aXineramaScreenIndexMap
Definition: saldisp.hxx:287
SalDisplay(Display *pDisp)
ScreenData m_aInvalidScreenData
Definition: saldisp.hxx:266
Display * GetDisplay() const
Definition: saldisp.hxx:344
bool IsXinerama() const
Definition: saldisp.hxx:361
sal_uLong nMaxRequestSize_
Definition: saldisp.hxx:268
void processRandREvent(XEvent *)
const Pair & GetResolution() const
Definition: saldisp.hxx:351
void Beep() const
bool bNumLockFromXS_
Definition: saldisp.hxx:277
KeySym GetKeySym(XKeyEvent *pEvent, char *pPrintable, int *pLen, KeySym *pUnmodifiedKeySym, Status *pStatus, XIC=nullptr) const
int nNumLockIndex_
Definition: saldisp.hxx:278
SalXLib * pXLib_
Definition: saldisp.hxx:259
Time GetLastUserEventTime() const
Definition: saldisp.hxx:352
const SalX11Screen & GetDefaultXScreen() const
Definition: saldisp.hxx:345
const std::vector< tools::Rectangle > & GetXineramaScreens() const
Definition: saldisp.hxx:362
virtual void Dispatch(XEvent *pEvent)=0
void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
Definition: saldisp.hxx:358
bool IsDisplay() const
Definition: saldisp.hxx:348
srv_vendor_t meServerVendor
Definition: saldisp.hxx:270
const SalFrameSet & getFrames() const
Definition: saldisp.hxx:367
KeySym nShiftKeySym_
Definition: saldisp.hxx:279
std::unique_ptr< vcl_sal::WMAdaptor > m_pWMAdaptor
Definition: saldisp.hxx:283
bool m_bXinerama
Definition: saldisp.hxx:285
void doDestruct()
std::list< SalObject * > & getSalObjects()
Definition: saldisp.hxx:369
void DbgPrintDisplayEvent(const char *pComment, const XEvent *pEvent) const
Time GetX11ServerTime() const
Definition: saldisp.hxx:354
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
SalRGB eRGBMode_
Definition: saldisp.hxx:79
int nGreenShift_
Definition: saldisp.hxx:81
int nBlueShift_
Definition: saldisp.hxx:82
int nRedBits_
Definition: saldisp.hxx:83
int nRedShift_
Definition: saldisp.hxx:80
int GetDepth() const
Definition: saldisp.hxx:93
int GetClass() const
Definition: saldisp.hxx:92
SalVisual(const XVisualInfo *pXVI)
Visual * GetVisual() const
Definition: saldisp.hxx:91
int nGreenBits_
Definition: saldisp.hxx:84
VisualID GetVisualId() const
Definition: saldisp.hxx:90
Pixel GetTCPixel(Color nColor) const
int nBlueBits_
Definition: saldisp.hxx:85
virtual void TriggerUserEventProcessing() override
virtual ~SalX11Display() override
virtual void Dispatch(XEvent *pEvent) override
void SetupInput()
SalX11Display(Display *pDisp)
virtual void Yield()
unsigned int getXScreen() const
Definition: saltype.h:20
fd_set aReadFDS_
Definition: saldisp.hxx:169
int m_pTimeoutFDS[2]
Definition: saldisp.hxx:166
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:195
sal_uLong m_nTimeoutMS
Definition: saldisp.hxx:165
void Wakeup()
void Init()
fd_set aExceptionFDS_
Definition: saldisp.hxx:170
void Insert(int fd, void *data, YieldFunc pending, YieldFunc queued, YieldFunc handle)
bool Yield(bool bWait, bool bHandleAllCurrentEvents)
void Remove(int fd)
std::unique_ptr< SalI18N_InputMethod > m_pInputMethod
Definition: saldisp.hxx:173
bool CheckTimeout(bool bExecuteTimers=true)
void StartTimer(sal_uInt64 nMS)
void TriggerUserEventProcessing()
timeval m_aTimeout
Definition: saldisp.hxx:164
Display * GetDisplay() const
Definition: saldisp.hxx:196
int nFDs_
Definition: saldisp.hxx:168
void StopTimer()
Display * m_pDisplay
Definition: saldisp.hxx:172
KeyIndicatorState
Definition: keycodes.hxx:187
Status
None
Display
long Long
SalDisplay * getSalDisplay(GenericUnixSalData const *data)
Definition: saldisp.hxx:395
OUString getKeysymReplacementName(std::u16string_view pLang, KeySym nSymbol)
PointerStyle
Definition: ptrstyle.hxx:26
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
SalRGB
Definition: saldisp.hxx:72
@ otherSalRGB
unsigned long Pixel
Definition: saldisp.hxx:48
srv_vendor_t sal_GetServerVendor(Display *p_display)
int(* YieldFunc)(int fd, void *data)
Definition: saldisp.hxx:160
Bool(* X_if_predicate)(Display *, XEvent *, XPointer)
Definition: saldisp.hxx:203
srv_vendor_t
Definition: saldisp.hxx:62
@ vendor_none
Definition: saldisp.hxx:63
@ vendor_unknown
Definition: saldisp.hxx:65
@ vendor_sun
Definition: saldisp.hxx:64
sal_uIntPtr sal_uLong
Holds the information of our new child window.
OwnershipFlag & operator=(OwnershipFlag &&other) noexcept
Definition: saldisp.hxx:106
OwnershipFlag()=default
OwnershipFlag(OwnershipFlag &&other) noexcept
Definition: saldisp.hxx:104
SalColormap m_aColormap
Definition: saldisp.hxx:235
#define VCLPLUG_GEN_PUBLIC
Definition: vclpluginapi.h:29