1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3*4882a593Smuzhiyun *Copyright (C) 2009-2010 Jon TURNEY
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun *Permission is hereby granted, free of charge, to any person obtaining
6*4882a593Smuzhiyun *a copy of this software and associated documentation files (the
7*4882a593Smuzhiyun *"Software"), to deal in the Software without restriction, including
8*4882a593Smuzhiyun *without limitation the rights to use, copy, modify, merge, publish,
9*4882a593Smuzhiyun *distribute, sublicense, and/or sell copies of the Software, and to
10*4882a593Smuzhiyun *permit persons to whom the Software is furnished to do so, subject to
11*4882a593Smuzhiyun *the following conditions:
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun *The above copyright notice and this permission notice shall be
14*4882a593Smuzhiyun *included in all copies or substantial portions of the Software.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17*4882a593Smuzhiyun *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18*4882a593Smuzhiyun *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19*4882a593Smuzhiyun *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
20*4882a593Smuzhiyun *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21*4882a593Smuzhiyun *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22*4882a593Smuzhiyun *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun *Except as contained in this notice, the name of the author(s)
25*4882a593Smuzhiyun *shall not be used in advertising or otherwise to promote the sale, use
26*4882a593Smuzhiyun *or other dealings in this Software without prior written authorization
27*4882a593Smuzhiyun *from the author(s)
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * Authors: Harold L Hunt II
30*4882a593Smuzhiyun * Jon TURNEY
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
34*4882a593Smuzhiyun #include <xwin-config.h>
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun #include "win.h"
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun * Answer queries about the RandR features supported.
40*4882a593Smuzhiyun */
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun static Bool
winRandRGetInfo(ScreenPtr pScreen,Rotation * pRotations)43*4882a593Smuzhiyun winRandRGetInfo(ScreenPtr pScreen, Rotation * pRotations)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun rrScrPrivPtr pRRScrPriv;
46*4882a593Smuzhiyun RROutputPtr output;
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun pRRScrPriv = rrGetScrPriv(pScreen);
49*4882a593Smuzhiyun output = pRRScrPriv->outputs[0];
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun winDebug("winRandRGetInfo ()\n");
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* Don't support rotations */
54*4882a593Smuzhiyun *pRotations = RR_Rotate_0;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* Delete previous mode */
57*4882a593Smuzhiyun if (output->modes[0])
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun RRModeDestroy(output->modes[0]);
60*4882a593Smuzhiyun RRModeDestroy(output->crtc->mode);
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun /* Register current mode */
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun xRRModeInfo modeInfo;
66*4882a593Smuzhiyun RRModePtr mode;
67*4882a593Smuzhiyun char name[100];
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun memset(&modeInfo, '\0', sizeof(modeInfo));
70*4882a593Smuzhiyun snprintf(name, sizeof(name), "%dx%d", pScreen->width, pScreen->height);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun modeInfo.width = pScreen->width;
73*4882a593Smuzhiyun modeInfo.height = pScreen->height;
74*4882a593Smuzhiyun modeInfo.hTotal = pScreen->width;
75*4882a593Smuzhiyun modeInfo.vTotal = pScreen->height;
76*4882a593Smuzhiyun modeInfo.dotClock = 0;
77*4882a593Smuzhiyun modeInfo.nameLength = strlen(name);
78*4882a593Smuzhiyun mode = RRModeGet(&modeInfo, name);
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun output->modes[0] = mode;
81*4882a593Smuzhiyun output->numModes = 1;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun mode = RRModeGet(&modeInfo, name);
84*4882a593Smuzhiyun output->crtc->mode = mode;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun return TRUE;
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun void
winDoRandRScreenSetSize(ScreenPtr pScreen,CARD16 width,CARD16 height,CARD32 mmWidth,CARD32 mmHeight)94*4882a593Smuzhiyun winDoRandRScreenSetSize(ScreenPtr pScreen,
95*4882a593Smuzhiyun CARD16 width,
96*4882a593Smuzhiyun CARD16 height, CARD32 mmWidth, CARD32 mmHeight)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun winScreenPriv(pScreen);
99*4882a593Smuzhiyun winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
100*4882a593Smuzhiyun WindowPtr pRoot = pScreen->root;
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Ignore changes which do nothing */
103*4882a593Smuzhiyun if ((pScreen->width == width) && (pScreen->height == height) &&
104*4882a593Smuzhiyun (pScreen->mmWidth == mmWidth) && (pScreen->mmHeight == mmHeight))
105*4882a593Smuzhiyun return;
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun // Prevent screen updates while we change things around
108*4882a593Smuzhiyun SetRootClip(pScreen, ROOT_CLIP_NONE);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun /* Update the screen size as requested */
111*4882a593Smuzhiyun pScreenInfo->dwWidth = width;
112*4882a593Smuzhiyun pScreenInfo->dwHeight = height;
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /* Reallocate the framebuffer used by the drawing engine */
115*4882a593Smuzhiyun (*pScreenPriv->pwinFreeFB) (pScreen);
116*4882a593Smuzhiyun if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) {
117*4882a593Smuzhiyun ErrorF("winDoRandRScreenSetSize - Could not reallocate framebuffer\n");
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun pScreen->width = width;
121*4882a593Smuzhiyun pScreen->height = height;
122*4882a593Smuzhiyun pScreen->mmWidth = mmWidth;
123*4882a593Smuzhiyun pScreen->mmHeight = mmHeight;
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* Update the screen pixmap to point to the new framebuffer */
126*4882a593Smuzhiyun winUpdateFBPointer(pScreen, pScreenInfo->pfb);
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun // pScreen->devPrivate == pScreen->GetScreenPixmap(screen) ?
129*4882a593Smuzhiyun // resize the root window
130*4882a593Smuzhiyun //pScreen->ResizeWindow(pRoot, 0, 0, width, height, NULL);
131*4882a593Smuzhiyun // does this emit a ConfigureNotify??
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun // Restore the ability to update screen, now with new dimensions
134*4882a593Smuzhiyun SetRootClip(pScreen, ROOT_CLIP_FULL);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun // and arrange for it to be repainted
137*4882a593Smuzhiyun pScreen->PaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun /* Indicate that a screen size change took place */
140*4882a593Smuzhiyun RRScreenSizeNotify(pScreen);
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /*
144*4882a593Smuzhiyun * Respond to resize request
145*4882a593Smuzhiyun */
146*4882a593Smuzhiyun static
147*4882a593Smuzhiyun Bool
winRandRScreenSetSize(ScreenPtr pScreen,CARD16 width,CARD16 height,CARD32 mmWidth,CARD32 mmHeight)148*4882a593Smuzhiyun winRandRScreenSetSize(ScreenPtr pScreen,
149*4882a593Smuzhiyun CARD16 width,
150*4882a593Smuzhiyun CARD16 height, CARD32 mmWidth, CARD32 mmHeight)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun winScreenPriv(pScreen);
153*4882a593Smuzhiyun winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun winDebug("winRandRScreenSetSize ()\n");
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun /*
158*4882a593Smuzhiyun It doesn't currently make sense to allow resize in fullscreen mode
159*4882a593Smuzhiyun (we'd actually have to list the supported resolutions)
160*4882a593Smuzhiyun */
161*4882a593Smuzhiyun if (pScreenInfo->fFullScreen) {
162*4882a593Smuzhiyun ErrorF
163*4882a593Smuzhiyun ("winRandRScreenSetSize - resize not supported in fullscreen mode\n");
164*4882a593Smuzhiyun return FALSE;
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /*
168*4882a593Smuzhiyun Client resize requests aren't allowed in rootless modes, even if
169*4882a593Smuzhiyun the X screen is monitor or virtual desktop size, we'd need to
170*4882a593Smuzhiyun resize the native display size
171*4882a593Smuzhiyun */
172*4882a593Smuzhiyun if (FALSE
173*4882a593Smuzhiyun #ifdef XWIN_MULTIWINDOWEXTWM
174*4882a593Smuzhiyun || pScreenInfo->fMWExtWM
175*4882a593Smuzhiyun #endif
176*4882a593Smuzhiyun || pScreenInfo->fRootless
177*4882a593Smuzhiyun || pScreenInfo->fMultiWindow
178*4882a593Smuzhiyun ) {
179*4882a593Smuzhiyun ErrorF
180*4882a593Smuzhiyun ("winRandRScreenSetSize - resize not supported in rootless modes\n");
181*4882a593Smuzhiyun return FALSE;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun winDoRandRScreenSetSize(pScreen, width, height, mmWidth, mmHeight);
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun /* Cause the native window for the screen to resize itself */
187*4882a593Smuzhiyun {
188*4882a593Smuzhiyun DWORD dwStyle, dwExStyle;
189*4882a593Smuzhiyun RECT rcClient;
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun rcClient.left = 0;
192*4882a593Smuzhiyun rcClient.top = 0;
193*4882a593Smuzhiyun rcClient.right = width;
194*4882a593Smuzhiyun rcClient.bottom = height;
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun ErrorF("winRandRScreenSetSize new client area w: %d h: %d\n", width,
197*4882a593Smuzhiyun height);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun /* Get the Windows window style and extended style */
200*4882a593Smuzhiyun dwExStyle = GetWindowLongPtr(pScreenPriv->hwndScreen, GWL_EXSTYLE);
201*4882a593Smuzhiyun dwStyle = GetWindowLongPtr(pScreenPriv->hwndScreen, GWL_STYLE);
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /*
204*4882a593Smuzhiyun * Calculate the window size needed for the given client area
205*4882a593Smuzhiyun * adjusting for any decorations it will have
206*4882a593Smuzhiyun */
207*4882a593Smuzhiyun AdjustWindowRectEx(&rcClient, dwStyle, FALSE, dwExStyle);
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun ErrorF("winRandRScreenSetSize new window area w: %d h: %d\n",
210*4882a593Smuzhiyun (int)(rcClient.right - rcClient.left),
211*4882a593Smuzhiyun (int)(rcClient.bottom - rcClient.top));
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun SetWindowPos(pScreenPriv->hwndScreen, NULL,
214*4882a593Smuzhiyun 0, 0, rcClient.right - rcClient.left,
215*4882a593Smuzhiyun rcClient.bottom - rcClient.top, SWP_NOZORDER | SWP_NOMOVE);
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun return TRUE;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun * Initialize the RandR layer.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun Bool
winRandRInit(ScreenPtr pScreen)226*4882a593Smuzhiyun winRandRInit(ScreenPtr pScreen)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun rrScrPrivPtr pRRScrPriv;
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun winDebug("winRandRInit ()\n");
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun if (!RRScreenInit(pScreen)) {
233*4882a593Smuzhiyun ErrorF("winRandRInit () - RRScreenInit () failed\n");
234*4882a593Smuzhiyun return FALSE;
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun /* Set some RandR function pointers */
238*4882a593Smuzhiyun pRRScrPriv = rrGetScrPriv(pScreen);
239*4882a593Smuzhiyun pRRScrPriv->rrGetInfo = winRandRGetInfo;
240*4882a593Smuzhiyun pRRScrPriv->rrSetConfig = NULL;
241*4882a593Smuzhiyun pRRScrPriv->rrScreenSetSize = winRandRScreenSetSize;
242*4882a593Smuzhiyun pRRScrPriv->rrCrtcSet = NULL;
243*4882a593Smuzhiyun pRRScrPriv->rrCrtcSetGamma = NULL;
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun /* Create a CRTC and an output for the screen, and hook them together */
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun RRCrtcPtr crtc;
248*4882a593Smuzhiyun RROutputPtr output;
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun crtc = RRCrtcCreate(pScreen, NULL);
251*4882a593Smuzhiyun if (!crtc)
252*4882a593Smuzhiyun return FALSE;
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun crtc->rotations = RR_Rotate_0;
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun output = RROutputCreate(pScreen, "default", 7, NULL);
257*4882a593Smuzhiyun if (!output)
258*4882a593Smuzhiyun return FALSE;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun RROutputSetCrtcs(output, &crtc, 1);
261*4882a593Smuzhiyun RROutputSetConnection(output, RR_Connected);
262*4882a593Smuzhiyun RROutputSetSubpixelOrder(output, PictureGetSubpixelOrder(pScreen));
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun output->crtc = crtc;
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun /* Set crtc outputs (should use RRCrtcNotify?) */
267*4882a593Smuzhiyun crtc->outputs = malloc(sizeof(RROutputPtr));
268*4882a593Smuzhiyun crtc->outputs[0] = output;
269*4882a593Smuzhiyun crtc->numOutputs = 1;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun pRRScrPriv->primaryOutput = output;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun /* Ensure we have space for exactly one mode */
274*4882a593Smuzhiyun output->modes = malloc(sizeof(RRModePtr));
275*4882a593Smuzhiyun output->modes[0] = NULL;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun /*
279*4882a593Smuzhiyun The screen doesn't have to be limited to the actual
280*4882a593Smuzhiyun monitor size (we can have scrollbars :-), so set the
281*4882a593Smuzhiyun upper limit to the maximum coordinates X11 can use.
282*4882a593Smuzhiyun */
283*4882a593Smuzhiyun RRScreenSetSizeRange(pScreen, 0, 0, 32768, 32768);
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun return TRUE;
286*4882a593Smuzhiyun }
287