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
72class SalVisual : public XVisualInfo
73{
74public:
76 SalVisual( const XVisualInfo* pXVI );
77
78 VisualID GetVisualId() const { return visualid; }
79 Visual *GetVisual() const { return visual; }
80 int GetClass() const { return c_class; }
81 int GetDepth() const { return depth; }
82};
83
84// A move-only flag, used by SalColormap to track ownership of its m_aVisual.visual:
86 bool owner = false;
87
88 OwnershipFlag() = default;
89
90 OwnershipFlag(OwnershipFlag && other) noexcept: owner(other.owner) { other.owner = false; }
91
92 OwnershipFlag & operator =(OwnershipFlag && other) noexcept {
93 assert(&other != this);
94 owner = other.owner;
95 other.owner = false;
96 return *this;
97 }
98};
99
101{
103 Colormap m_hColormap;
104 std::vector<Color> m_aPalette; // Pseudocolor
109 Pixel m_nUsed; // Pseudocolor
110
111public:
112 SalColormap( const SalDisplay* pSalDisplay,
113 Colormap hColormap,
114 SalX11Screen nXScreen );
115 SalColormap( sal_uInt16 nDepth );
117
119
122
123 Colormap GetXColormap() const { return m_hColormap; }
124 const SalDisplay* GetDisplay() const { return m_pDisplay; }
125 inline Display* GetXDisplay() const;
126 const SalVisual& GetVisual() const { return m_aVisual; }
129
130 bool GetXPixels( XColor &rColor,
131 int r,
132 int g,
133 int b ) const;
134 inline bool GetXPixel( XColor &rColor,
135 int r,
136 int g,
137 int b ) const;
138};
139
141
142typedef int(*YieldFunc)(int fd, void* data);
143
145{
146 timeval m_aTimeout;
149
150 int nFDs_;
151 fd_set aReadFDS_;
153
155 std::unique_ptr<SalI18N_InputMethod> m_pInputMethod;
156
157public:
160 void Init();
161
162 bool Yield( bool bWait, bool bHandleAllCurrentEvents );
163 void Wakeup();
165
166 void Insert( int fd, void* data,
167 YieldFunc pending,
168 YieldFunc queued,
169 YieldFunc handle );
170 void Remove( int fd );
171
172 void StartTimer( sal_uInt64 nMS );
173 void StopTimer();
174
175 bool CheckTimeout( bool bExecuteTimers = true );
176
178 Display* GetDisplay() const { return m_pDisplay; }
179};
180
182class AttributeProvider;
183
184extern "C" {
185 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
186}
187
188class GLX11Window final : public GLWindow
189{
190public:
194 XVisualInfo* vi;
195 GLXContext ctx;
197
198 bool HasGLXExtension(const char* name) const;
199
200 GLX11Window();
201 virtual bool Synchronize(bool bOnoff) const override;
202 virtual ~GLX11Window() override;
203};
204
206{
207public:
208
210 {
212
213 ::Window m_aRoot;
214 ::Window m_aRefWindow;
225
227 m_bInit( false ),
228 m_aRoot( None ),
229 m_aRefWindow( None ),
230 m_aMonoGC( None ),
231 m_aCopyGC( None ),
232 m_aAndInvertedGC( None ),
233 m_aAndGC( None ),
234 m_aOrGC( None ),
235 m_aStippleGC( None ),
236 m_hInvert50( None )
237 {}
238 };
239
240protected:
243
244 Display *pDisp_; // X Display
245
247 std::vector< ScreenData > m_aScreens;
251
253
254 // until x bytes
255
257
258 // Keyboard
259 bool bNumLockFromXS_; // Num Lock handled by X Server
260 int nNumLockIndex_; // modifier index in modmap
261 KeySym nShiftKeySym_; // first shift modifier
262 KeySym nCtrlKeySym_; // first control modifier
263 KeySym nMod1KeySym_; // first mod1 modifier
264
265 std::unique_ptr<vcl_sal::WMAdaptor> m_pWMAdaptor;
266
268 std::vector< tools::Rectangle > m_aXineramaScreens;
269 std::vector< int > m_aXineramaScreenIndexMap;
270 std::list<SalObject*> m_aSalObjects;
271
272 mutable Time m_nLastUserEventTime; // mutable because changed on first access
273
274 virtual void Dispatch( XEvent *pEvent ) = 0;
276 void InitRandR( ::Window aRoot ) const;
277 static void DeInitRandR();
278 void processRandREvent( XEvent* );
279
281 void addXineramaScreenUnique( int i, tools::Long i_nX, tools::Long i_nY, tools::Long i_nWidth, tools::Long i_nHeight );
282 Time GetEventTimeImpl( bool bAlwaysReget = false ) const;
283public:
284 static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI);
285
287
288 virtual ~SalDisplay() override;
289
290 void Init();
291
292#ifdef DBG_UTIL
293 void PrintInfo() const;
294 void DbgPrintDisplayEvent(const char *pComment, const XEvent *pEvent) const;
295#endif
296
297 void Beep() const;
298
300 void SimulateKeyPress( sal_uInt16 nKeyCode );
302 OUString GetKeyNameFromKeySym( KeySym keysym ) const;
303 OUString GetKeyName( sal_uInt16 nKeyCode ) const;
304 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
305 KeySym GetKeySym( XKeyEvent *pEvent,
306 char *pPrintable,
307 int *pLen,
308 KeySym *pUnmodifiedKeySym,
309 Status *pStatus,
310 XIC = nullptr ) const;
311
313 int CaptureMouse( SalFrame *pCapture );
314
316 const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
317 {
318 if( nXScreen.getXScreen() >= m_aScreens.size() )
319 return m_aInvalidScreenData;
320 if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
321 initScreen( nXScreen );
322 return m_aScreens[nXScreen.getXScreen()];
323 }
324
325 ::Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
326 Display *GetDisplay() const { return pDisp_; }
327 const SalX11Screen& GetDefaultXScreen() const { return m_nXDefaultScreen; }
328 const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
329 srv_vendor_t GetServerVendor() const { return meServerVendor; }
330 bool IsDisplay() const { return !!pXLib_; }
331 const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
332 const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
333 const Pair &GetResolution() const { return aResolution_; }
334 Time GetLastUserEventTime() const { return GetEventTimeImpl(); }
335 // this is an equivalent of gdk_x11_get_server_time()
336 Time GetX11ServerTime() const { return GetEventTimeImpl( true ); }
337
338 SalI18N_InputMethod* GetInputMethod() const { return pXLib_->GetInputMethod(); }
339 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
341 { mpKbdExtension = pKbdExtension; }
342 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor.get(); }
343 bool IsXinerama() const { return m_bXinerama; }
344 const std::vector< tools::Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
345 ::Window GetRootWindow( SalX11Screen nXScreen ) const
346 { return getDataForScreen( nXScreen ).m_aRoot; }
347 unsigned int GetXScreenCount() const { return m_aScreens.size(); }
348
349 const SalFrameSet& getFrames() const { return m_aFrames; }
350
351 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
352};
353
355{ return m_pDisplay->GetDisplay(); }
356
357class SalX11Display final : public SalDisplay
358{
359public:
361 virtual ~SalX11Display() override;
362
363 virtual void Dispatch( XEvent *pEvent ) override;
364 virtual void Yield();
365 virtual void TriggerUserEventProcessing() override;
366
367 bool IsEvent();
369};
370
371namespace vcl_sal {
372 // get foreign key names
374 std::u16string_view pLang,
375 KeySym nSymbol );
376
378 {
379 assert(data != nullptr);
380 return static_cast<SalDisplay *>(data->GetDisplay());
381 }
382}
383
384#endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
385
386/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GLXContext ctx
Definition: saldisp.hxx:195
virtual bool Synchronize(bool bOnoff) const override
Display * dpy
Definition: saldisp.hxx:191
virtual ~GLX11Window() override
Window win
Definition: saldisp.hxx:193
bool HasGLXExtension(const char *name) const
XVisualInfo * vi
Definition: saldisp.hxx:194
OString GLXExtensions
Definition: saldisp.hxx:196
SalGenericDisplay * GetDisplay() const
Definition: gendata.hxx:76
Colormap m_hColormap
Definition: saldisp.hxx:103
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:104
Display * GetXDisplay() const
Definition: saldisp.hxx:354
Pixel GetBlackPixel() const
Definition: saldisp.hxx:128
const SalDisplay * GetDisplay() const
Definition: saldisp.hxx:124
const SalVisual & GetVisual() const
Definition: saldisp.hxx:126
Pixel GetWhitePixel() const
Definition: saldisp.hxx:127
const SalDisplay * m_pDisplay
Definition: saldisp.hxx:102
SalColormap(SalColormap &&)=default
Colormap GetXColormap() const
Definition: saldisp.hxx:123
OwnershipFlag m_aVisualOwnership
Definition: saldisp.hxx:106
Pixel m_nBlackPixel
Definition: saldisp.hxx:108
bool GetXPixel(XColor &rColor, int r, int g, int b) const
Pixel m_nUsed
Definition: saldisp.hxx:109
SalColormap(sal_uInt16 nDepth)
SalColormap & operator=(SalColormap &&)=default
SalVisual m_aVisual
Definition: saldisp.hxx:105
Pixel m_nWhitePixel
Definition: saldisp.hxx:107
void Init()
srv_vendor_t GetServerVendor() const
Definition: saldisp.hxx:329
SalX11Screen m_nXDefaultScreen
Definition: saldisp.hxx:246
Display * pDisp_
Definition: saldisp.hxx:244
unsigned int GetXScreenCount() const
Definition: saldisp.hxx:347
std::vector< ScreenData > m_aScreens
Definition: saldisp.hxx:247
ScreenData * initScreen(SalX11Screen nXScreen) const
Pair aResolution_
Definition: saldisp.hxx:249
const SalColormap & GetColormap(SalX11Screen nXScreen) const
Definition: saldisp.hxx:331
OUString GetKeyName(sal_uInt16 nKeyCode) const
void InitXinerama()
::Window GetRootWindow(SalX11Screen nXScreen) const
Definition: saldisp.hxx:345
KeySym nMod1KeySym_
Definition: saldisp.hxx:263
Time GetEventTimeImpl(bool bAlwaysReget=false) const
Cursor GetPointer(PointerStyle ePointerStyle)
const ScreenData & getDataForScreen(SalX11Screen nXScreen) const
Definition: saldisp.hxx:316
::vcl_sal::WMAdaptor * getWMAdaptor() const
Definition: saldisp.hxx:342
int CaptureMouse(SalFrame *pCapture)
std::vector< tools::Rectangle > m_aXineramaScreens
Definition: saldisp.hxx:268
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:272
const SalVisual & GetVisual(SalX11Screen nXScreen) const
Definition: saldisp.hxx:332
SalI18N_KeyboardExtension * mpKbdExtension
Definition: saldisp.hxx:242
void InitRandR(::Window aRoot) const
KeyIndicatorState GetIndicatorState() const
::Window GetDrawable(SalX11Screen nXScreen) const
Definition: saldisp.hxx:325
OUString GetKeyNameFromKeySym(KeySym keysym) const
KeySym nCtrlKeySym_
Definition: saldisp.hxx:262
SalI18N_KeyboardExtension * GetKbdExtension() const
Definition: saldisp.hxx:339
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:338
virtual ~SalDisplay() override
std::list< SalObject * > m_aSalObjects
Definition: saldisp.hxx:270
sal_uInt16 GetKeyCode(KeySym keysym, char *pcPrintable) const
o3tl::enumarray< PointerStyle, Cursor > aPointerCache_
Definition: saldisp.hxx:256
void SimulateKeyPress(sal_uInt16 nKeyCode)
const Size & GetScreenSize(SalX11Screen nXScreen) const
Definition: saldisp.hxx:328
static bool BestVisual(Display *pDisp, int nScreen, XVisualInfo &rVI)
std::vector< int > m_aXineramaScreenIndexMap
Definition: saldisp.hxx:269
SalDisplay(Display *pDisp)
ScreenData m_aInvalidScreenData
Definition: saldisp.hxx:248
Display * GetDisplay() const
Definition: saldisp.hxx:326
bool IsXinerama() const
Definition: saldisp.hxx:343
sal_uLong nMaxRequestSize_
Definition: saldisp.hxx:250
void processRandREvent(XEvent *)
const Pair & GetResolution() const
Definition: saldisp.hxx:333
void Beep() const
bool bNumLockFromXS_
Definition: saldisp.hxx:259
KeySym GetKeySym(XKeyEvent *pEvent, char *pPrintable, int *pLen, KeySym *pUnmodifiedKeySym, Status *pStatus, XIC=nullptr) const
int nNumLockIndex_
Definition: saldisp.hxx:260
SalXLib * pXLib_
Definition: saldisp.hxx:241
Time GetLastUserEventTime() const
Definition: saldisp.hxx:334
const SalX11Screen & GetDefaultXScreen() const
Definition: saldisp.hxx:327
const std::vector< tools::Rectangle > & GetXineramaScreens() const
Definition: saldisp.hxx:344
virtual void Dispatch(XEvent *pEvent)=0
void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
Definition: saldisp.hxx:340
bool IsDisplay() const
Definition: saldisp.hxx:330
srv_vendor_t meServerVendor
Definition: saldisp.hxx:252
const SalFrameSet & getFrames() const
Definition: saldisp.hxx:349
KeySym nShiftKeySym_
Definition: saldisp.hxx:261
std::unique_ptr< vcl_sal::WMAdaptor > m_pWMAdaptor
Definition: saldisp.hxx:265
bool m_bXinerama
Definition: saldisp.hxx:267
void doDestruct()
std::list< SalObject * > & getSalObjects()
Definition: saldisp.hxx:351
void DbgPrintDisplayEvent(const char *pComment, const XEvent *pEvent) const
Time GetX11ServerTime() const
Definition: saldisp.hxx:336
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
int GetDepth() const
Definition: saldisp.hxx:81
int GetClass() const
Definition: saldisp.hxx:80
SalVisual(const XVisualInfo *pXVI)
Visual * GetVisual() const
Definition: saldisp.hxx:79
VisualID GetVisualId() const
Definition: saldisp.hxx:78
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:151
int m_pTimeoutFDS[2]
Definition: saldisp.hxx:148
SalI18N_InputMethod * GetInputMethod() const
Definition: saldisp.hxx:177
sal_uLong m_nTimeoutMS
Definition: saldisp.hxx:147
void Wakeup()
void Init()
fd_set aExceptionFDS_
Definition: saldisp.hxx:152
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:155
bool CheckTimeout(bool bExecuteTimers=true)
void StartTimer(sal_uInt64 nMS)
void TriggerUserEventProcessing()
timeval m_aTimeout
Definition: saldisp.hxx:146
Display * GetDisplay() const
Definition: saldisp.hxx:178
int nFDs_
Definition: saldisp.hxx:150
void StopTimer()
Display * m_pDisplay
Definition: saldisp.hxx:154
KeyIndicatorState
Definition: keycodes.hxx:187
Status
None
Display
long Long
SalDisplay * getSalDisplay(GenericUnixSalData const *data)
Definition: saldisp.hxx:377
OUString getKeysymReplacementName(std::u16string_view pLang, KeySym nSymbol)
PointerStyle
Definition: ptrstyle.hxx:26
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
unsigned long Pixel
Definition: saldisp.hxx:48
srv_vendor_t sal_GetServerVendor(Display *p_display)
int(* YieldFunc)(int fd, void *data)
Definition: saldisp.hxx:142
Bool(* X_if_predicate)(Display *, XEvent *, XPointer)
Definition: saldisp.hxx:185
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:92
OwnershipFlag()=default
OwnershipFlag(OwnershipFlag &&other) noexcept
Definition: saldisp.hxx:90
SalColormap m_aColormap
Definition: saldisp.hxx:217
#define VCLPLUG_GEN_PUBLIC
Definition: vclpluginapi.h:29