Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xwin / winrandr.c
CommitLineData
a09e091a
JB
1/*
2 *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3 *Copyright (C) 2009-2010 Jon TURNEY
4 *
5 *Permission is hereby granted, free of charge, to any person obtaining
6 *a copy of this software and associated documentation files (the
7 *"Software"), to deal in the Software without restriction, including
8 *without limitation the rights to use, copy, modify, merge, publish,
9 *distribute, sublicense, and/or sell copies of the Software, and to
10 *permit persons to whom the Software is furnished to do so, subject to
11 *the following conditions:
12 *
13 *The above copyright notice and this permission notice shall be
14 *included in all copies or substantial portions of the Software.
15 *
16 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
20 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 *Except as contained in this notice, the name of the author(s)
25 *shall not be used in advertising or otherwise to promote the sale, use
26 *or other dealings in this Software without prior written authorization
27 *from the author(s)
28 *
29 * Authors: Harold L Hunt II
30 * Jon TURNEY
31 */
32
33#ifdef HAVE_XWIN_CONFIG_H
34#include <xwin-config.h>
35#endif
36#include "win.h"
37#include "mivalidate.h" // for union _Validate used by windowstr.h
38
39#ifndef RANDR_12_INTERFACE
40#error X server must have RandR 1.2 interface
41#endif
42
43/*
44 * Answer queries about the RandR features supported.
45 */
46
47static Bool
48winRandRGetInfo(ScreenPtr pScreen, Rotation * pRotations)
49{
50 winDebug("winRandRGetInfo ()\n");
51
52 /* Don't support rotations */
53 *pRotations = RR_Rotate_0;
54
55 /*
56 The screen doesn't have to be limited to the actual
57 monitor size (we can have scrollbars :-), so what is
58 the upper limit?
59 */
60 RRScreenSetSizeRange(pScreen, 0, 0, 4096, 4096);
61
62 return TRUE;
63}
64
65/*
66
67*/
68void
69winDoRandRScreenSetSize(ScreenPtr pScreen,
70 CARD16 width,
71 CARD16 height, CARD32 mmWidth, CARD32 mmHeight)
72{
73 winScreenPriv(pScreen);
74 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
75 WindowPtr pRoot = pScreen->root;
76
77 // Prevent screen updates while we change things around
78 SetRootClip(pScreen, FALSE);
79
80 /* Update the screen size as requested */
81 pScreenInfo->dwWidth = width;
82 pScreenInfo->dwHeight = height;
83
84 /* Reallocate the framebuffer used by the drawing engine */
85 (*pScreenPriv->pwinFreeFB) (pScreen);
86 if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) {
87 ErrorF("winDoRandRScreenSetSize - Could not reallocate framebuffer\n");
88 }
89
90 pScreen->width = width;
91 pScreen->height = height;
92 pScreen->mmWidth = mmWidth;
93 pScreen->mmHeight = mmHeight;
94
95 /* Update the screen pixmap to point to the new framebuffer */
96 winUpdateFBPointer(pScreen, pScreenInfo->pfb);
97
98 // pScreen->devPrivate == pScreen->GetScreenPixmap(screen) ?
99 // resize the root window
100 //pScreen->ResizeWindow(pRoot, 0, 0, width, height, NULL);
101 // does this emit a ConfigureNotify??
102
103 // Restore the ability to update screen, now with new dimensions
104 SetRootClip(pScreen, TRUE);
105
106 // and arrange for it to be repainted
107 miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
108
109 /* Indicate that a screen size change took place */
110 RRScreenSizeNotify(pScreen);
111}
112
113/*
114 * Respond to resize request
115 */
116static
117 Bool
118winRandRScreenSetSize(ScreenPtr pScreen,
119 CARD16 width,
120 CARD16 height, CARD32 mmWidth, CARD32 mmHeight)
121{
122 winScreenPriv(pScreen);
123 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
124
125 winDebug("winRandRScreenSetSize ()\n");
126
127 /*
128 It doesn't currently make sense to allow resize in fullscreen mode
129 (we'd actually have to list the supported resolutions)
130 */
131 if (pScreenInfo->fFullScreen) {
132 ErrorF
133 ("winRandRScreenSetSize - resize not supported in fullscreen mode\n");
134 return FALSE;
135 }
136
137 /*
138 Client resize requests aren't allowed in rootless modes, even if
139 the X screen is monitor or virtual desktop size, we'd need to
140 resize the native display size
141 */
142 if (FALSE
143#ifdef XWIN_MULTIWINDOWEXTWM
144 || pScreenInfo->fMWExtWM
145#endif
146 || pScreenInfo->fRootless
147#ifdef XWIN_MULTIWINDOW
148 || pScreenInfo->fMultiWindow
149#endif
150 ) {
151 ErrorF
152 ("winRandRScreenSetSize - resize not supported in rootless modes\n");
153 return FALSE;
154 }
155
156 winDoRandRScreenSetSize(pScreen, width, height, mmWidth, mmHeight);
157
158 /* Cause the native window for the screen to resize itself */
159 {
160 DWORD dwStyle, dwExStyle;
161 RECT rcClient;
162
163 rcClient.left = 0;
164 rcClient.top = 0;
165 rcClient.right = width;
166 rcClient.bottom = height;
167
168 ErrorF("winRandRScreenSetSize new client area w: %d h: %d\n", width,
169 height);
170
171 /* Get the Windows window style and extended style */
172 dwExStyle = GetWindowLongPtr(pScreenPriv->hwndScreen, GWL_EXSTYLE);
173 dwStyle = GetWindowLongPtr(pScreenPriv->hwndScreen, GWL_STYLE);
174
175 /*
176 * Calculate the window size needed for the given client area
177 * adjusting for any decorations it will have
178 */
179 AdjustWindowRectEx(&rcClient, dwStyle, FALSE, dwExStyle);
180
181 ErrorF("winRandRScreenSetSize new window area w: %ld h: %ld\n",
182 rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
183
184 SetWindowPos(pScreenPriv->hwndScreen, NULL,
185 0, 0, rcClient.right - rcClient.left,
186 rcClient.bottom - rcClient.top, SWP_NOZORDER | SWP_NOMOVE);
187 }
188
189 return TRUE;
190}
191
192/*
193 * Initialize the RandR layer.
194 */
195
196Bool
197winRandRInit(ScreenPtr pScreen)
198{
199 rrScrPrivPtr pRRScrPriv;
200
201 winDebug("winRandRInit ()\n");
202
203 if (!RRScreenInit(pScreen)) {
204 ErrorF("winRandRInit () - RRScreenInit () failed\n");
205 return FALSE;
206 }
207
208 /* Set some RandR function pointers */
209 pRRScrPriv = rrGetScrPriv(pScreen);
210 pRRScrPriv->rrGetInfo = winRandRGetInfo;
211 pRRScrPriv->rrSetConfig = NULL;
212 pRRScrPriv->rrScreenSetSize = winRandRScreenSetSize;
213 pRRScrPriv->rrCrtcSet = NULL;
214 pRRScrPriv->rrCrtcSetGamma = NULL;
215
216 return TRUE;
217}