nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / app / randrwrapper.cxx
blob431c70ae37afcafcc54f2531db8c1199dd0408e2
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 #ifdef USE_RANDR
22 #include <X11/Xlib.h>
23 #include <X11/extensions/Xrandr.h>
25 #include <sal/log.hxx>
27 namespace
30 class RandRWrapper
32 bool m_bValid;
34 explicit RandRWrapper(Display*);
35 public:
36 static RandRWrapper& get(Display*);
37 static void releaseWrapper();
39 Bool XRRQueryExtension(Display* i_pDisp, int* o_event_base, int* o_error_base )
41 Bool bRet = False;
42 if( m_bValid )
43 bRet = ::XRRQueryExtension( i_pDisp, o_event_base, o_error_base );
44 return bRet;
46 XRRScreenConfiguration* XRRGetScreenInfo( Display* i_pDisp, Drawable i_aDrawable )
48 return m_bValid ? ::XRRGetScreenInfo( i_pDisp, i_aDrawable ) : nullptr;
50 void XRRFreeScreenConfigInfo( XRRScreenConfiguration* i_pConfig )
52 if( m_bValid )
53 ::XRRFreeScreenConfigInfo( i_pConfig );
55 void XRRSelectInput( Display* i_pDisp, ::Window i_window, int i_nMask )
57 if( m_bValid )
58 ::XRRSelectInput( i_pDisp, i_window, i_nMask );
60 int XRRUpdateConfiguration( XEvent* i_pEvent )
62 return m_bValid ? ::XRRUpdateConfiguration( i_pEvent ) : 0;
64 XRRScreenSize* XRRConfigSizes( XRRScreenConfiguration* i_pConfig, int* o_nSizes )
66 return m_bValid ? ::XRRConfigSizes( i_pConfig, o_nSizes ) : nullptr;
68 SizeID XRRConfigCurrentConfiguration( XRRScreenConfiguration* i_pConfig, Rotation* o_pRot )
70 return m_bValid ? ::XRRConfigCurrentConfiguration( i_pConfig, o_pRot ) : 0;
72 int XRRRootToScreen( Display *dpy, ::Window root )
74 return m_bValid ? ::XRRRootToScreen( dpy, root ) : -1;
78 RandRWrapper::RandRWrapper( Display* pDisplay ) :
79 m_bValid( true )
81 int nEventBase = 0, nErrorBase = 0;
82 if( !XRRQueryExtension( pDisplay, &nEventBase, &nErrorBase ) )
83 m_bValid = false;
86 RandRWrapper* pWrapper = nullptr;
88 RandRWrapper& RandRWrapper::get( Display* i_pDisplay )
90 if( ! pWrapper )
91 pWrapper = new RandRWrapper( i_pDisplay );
92 return *pWrapper;
95 void RandRWrapper::releaseWrapper()
97 delete pWrapper;
98 pWrapper = nullptr;
101 } // namespace
103 #endif
105 #include <unx/saldisp.hxx>
106 #if OSL_DEBUG_LEVEL > 1
107 #include <cstdio>
108 #endif
110 void SalDisplay::InitRandR( ::Window aRoot ) const
112 #ifdef USE_RANDR
113 RandRWrapper::get( GetDisplay() ).XRRSelectInput( GetDisplay(), aRoot, RRScreenChangeNotifyMask );
114 #else
115 (void)this;
116 (void)aRoot;
117 #endif
120 void SalDisplay::DeInitRandR()
122 #ifdef USE_RANDR
123 RandRWrapper::releaseWrapper();
124 #if OSL_DEBUG_LEVEL > 1
125 SAL_INFO("vcl.app", "SalDisplay::DeInitRandR().");
126 #endif
127 #endif
130 void SalDisplay::processRandREvent( XEvent* pEvent )
132 #ifdef USE_RANDR
133 XConfigureEvent* pCnfEvent=reinterpret_cast<XConfigureEvent*>(pEvent);
134 if( !pWrapper || pWrapper->XRRRootToScreen(GetDisplay(),pCnfEvent->window) == -1 )
135 return;
137 int nRet = pWrapper->XRRUpdateConfiguration( pEvent );
138 if( nRet != 1 || pEvent->type == ConfigureNotify) // this should then be a XRRScreenChangeNotifyEvent
139 return;
141 // update screens
142 bool bNotify = false;
143 for(ScreenData & rScreen : m_aScreens)
145 if( rScreen.m_bInit )
147 XRRScreenConfiguration *pConfig = nullptr;
148 XRRScreenSize *pSizes = nullptr;
149 int nSizes = 0;
150 Rotation nRot = 0;
151 SizeID nId = 0;
153 pConfig = pWrapper->XRRGetScreenInfo( GetDisplay(), rScreen.m_aRoot );
154 nId = pWrapper->XRRConfigCurrentConfiguration( pConfig, &nRot );
155 pSizes = pWrapper->XRRConfigSizes( pConfig, &nSizes );
156 XRRScreenSize *pTargetSize = pSizes + nId;
158 bNotify = bNotify ||
159 rScreen.m_aSize.Width() != pTargetSize->width ||
160 rScreen.m_aSize.Height() != pTargetSize->height;
162 rScreen.m_aSize = Size( pTargetSize->width, pTargetSize->height );
164 pWrapper->XRRFreeScreenConfigInfo( pConfig );
166 #if OSL_DEBUG_LEVEL > 1
167 SAL_INFO("vcl.app", "screen " << nId
168 << " changed to size " << (int)pTargetSize->width
169 << "x" << (int)pTargetSize->height);
170 #endif
173 if( bNotify )
174 emitDisplayChanged();
175 #else
176 (void)this;
177 (void)pEvent;
178 #endif
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */