1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <X11/extensions/Xrandr.h>
25 #include <sal/log.hxx>
34 explicit RandRWrapper(Display
*);
36 static RandRWrapper
& get(Display
*);
37 static void releaseWrapper();
39 Bool
XRRQueryExtension(Display
* i_pDisp
, int* o_event_base
, int* o_error_base
)
43 bRet
= ::XRRQueryExtension( i_pDisp
, o_event_base
, o_error_base
);
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
)
53 ::XRRFreeScreenConfigInfo( i_pConfig
);
55 void XRRSelectInput( Display
* i_pDisp
, ::Window i_window
, int i_nMask
)
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
) :
81 int nEventBase
= 0, nErrorBase
= 0;
82 if( !XRRQueryExtension( pDisplay
, &nEventBase
, &nErrorBase
) )
86 RandRWrapper
* pWrapper
= nullptr;
88 RandRWrapper
& RandRWrapper::get( Display
* i_pDisplay
)
91 pWrapper
= new RandRWrapper( i_pDisplay
);
95 void RandRWrapper::releaseWrapper()
105 #include <unx/saldisp.hxx>
106 #if OSL_DEBUG_LEVEL > 1
110 void SalDisplay::InitRandR( ::Window aRoot
) const
113 RandRWrapper::get( GetDisplay() ).XRRSelectInput( GetDisplay(), aRoot
, RRScreenChangeNotifyMask
);
120 void SalDisplay::DeInitRandR()
123 RandRWrapper::releaseWrapper();
124 #if OSL_DEBUG_LEVEL > 1
125 SAL_INFO("vcl.app", "SalDisplay::DeInitRandR().");
130 void SalDisplay::processRandREvent( XEvent
* pEvent
)
133 XConfigureEvent
* pCnfEvent
=reinterpret_cast<XConfigureEvent
*>(pEvent
);
134 if( !pWrapper
|| pWrapper
->XRRRootToScreen(GetDisplay(),pCnfEvent
->window
) == -1 )
137 int nRet
= pWrapper
->XRRUpdateConfiguration( pEvent
);
138 if( nRet
!= 1 || pEvent
->type
== ConfigureNotify
) // this should then be a XRRScreenChangeNotifyEvent
142 bool bNotify
= false;
143 for(ScreenData
& rScreen
: m_aScreens
)
145 if( rScreen
.m_bInit
)
147 XRRScreenConfiguration
*pConfig
= nullptr;
148 XRRScreenSize
*pSizes
= nullptr;
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
;
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
);
174 emitDisplayChanged();
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */