2 * Wine X11drv Xrandr interface
4 * Copyright 2003 Alexander James Pasadyn
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <X11/extensions/Xrandr.h>
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(xrandr);
45 static int xrandr_event, xrandr_error, xrandr_major, xrandr_minor;
47 static LPDDHALMODEINFO dd_modes;
48 static unsigned int dd_mode_count;
49 static XRRScreenSize *real_xrandr_sizes;
50 static short **real_xrandr_rates;
51 static unsigned int real_xrandr_sizes_count;
52 static int *real_xrandr_rates_count;
53 static unsigned int real_xrandr_modes_count;
55 static int XRandRErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
60 static Bool in_desktop_mode;
62 /* create the mode structures */
63 static void make_modes(void)
66 for (i=0; i<real_xrandr_sizes_count; i++)
68 if (real_xrandr_rates_count[i])
70 for (j=0; j < real_xrandr_rates_count[i]; j++)
72 X11DRV_Settings_AddOneMode(real_xrandr_sizes[i].width,
73 real_xrandr_sizes[i].height,
74 0, real_xrandr_rates[i][j]);
79 X11DRV_Settings_AddOneMode(real_xrandr_sizes[i].width,
80 real_xrandr_sizes[i].height,
86 static int X11DRV_XRandR_GetCurrentMode(void)
91 XRRScreenConfiguration *sc;
97 root = RootWindow (gdi_display, DefaultScreen(gdi_display));
98 sc = XRRGetScreenInfo (gdi_display, root);
99 size = XRRConfigCurrentConfiguration (sc, &rot);
100 rate = XRRConfigCurrentRate (sc);
101 for (i = 0; i < real_xrandr_modes_count; i++)
103 if ( (dd_modes[i].dwWidth == real_xrandr_sizes[size].width ) &&
104 (dd_modes[i].dwHeight == real_xrandr_sizes[size].height) &&
105 (dd_modes[i].wRefreshRate == rate ) )
110 XRRFreeScreenConfigInfo(sc);
114 ERR("In unknown mode, returning default\n");
120 static void X11DRV_XRandR_SetCurrentMode(int mode)
125 XRRScreenConfiguration *sc;
126 Status stat = RRSetConfigSuccess;
129 DWORD dwBpp = screen_depth;
130 if (dwBpp == 24) dwBpp = 32;
133 root = RootWindow (gdi_display, DefaultScreen(gdi_display));
134 sc = XRRGetScreenInfo (gdi_display, root);
135 size = XRRConfigCurrentConfiguration (sc, &rot);
136 if (dwBpp != dd_modes[mode].dwBPP)
138 FIXME("Cannot change screen BPP from %ld to %ld\n", dwBpp, dd_modes[mode].dwBPP);
140 mode = mode%real_xrandr_modes_count;
141 for (i = 0; i < real_xrandr_sizes_count; i++)
143 if ( (dd_modes[mode].dwWidth == real_xrandr_sizes[i].width ) &&
144 (dd_modes[mode].dwHeight == real_xrandr_sizes[i].height) )
147 if (real_xrandr_rates_count[i])
149 for (j=0; j < real_xrandr_rates_count[i]; j++)
151 if (dd_modes[mode].wRefreshRate == real_xrandr_rates[i][j])
153 rate = real_xrandr_rates[i][j];
154 TRACE("Resizing X display to %ldx%ld @%d Hz\n",
155 dd_modes[mode].dwWidth, dd_modes[mode].dwHeight, rate);
156 stat = XRRSetScreenConfigAndRate (gdi_display, sc, root,
157 size, rot, rate, CurrentTime);
158 FIXME("Need to update SYSMETRICS after resizing display (now %ldx%ld)\n",
159 dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
165 TRACE("Resizing X display to %ldx%ld\n",
166 dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
167 stat = XRRSetScreenConfig (gdi_display, sc, root,
168 size, rot, CurrentTime);
169 FIXME("Need to update SYSMETRICS after resizing display (now %ldx%ld)\n",
170 dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
174 if (stat != RRSetConfigSuccess)
176 ERR("Resolution change not successful -- perhaps display has chaned?");
178 XRRFreeScreenConfigInfo(sc);
182 void X11DRV_XRandR_Init(void)
187 in_desktop_mode = (root_window != DefaultRootWindow(gdi_display));
189 if (xrandr_major) return; /* already initialized? */
190 if (!usexrandr) return; /* disabled in config */
191 if (in_desktop_mode) return; /* not compatible with desktop mode */
193 /* see if Xrandr is available */
195 ok = XRRQueryExtension(gdi_display, &xrandr_event, &xrandr_error);
198 X11DRV_expect_error(gdi_display, XRandRErrorHandler, NULL);
199 ok = XRRQueryVersion(gdi_display, &xrandr_major, &xrandr_minor);
200 if (X11DRV_check_error()) ok = FALSE;
204 TRACE("Found XRandR - major: %d, minor: %d\n", xrandr_major, xrandr_minor);
206 real_xrandr_sizes = XRRSizes(gdi_display, DefaultScreen(gdi_display), &real_xrandr_sizes_count);
207 ok = (real_xrandr_sizes_count>0);
211 real_xrandr_rates = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(short *) * real_xrandr_sizes_count);
212 real_xrandr_rates_count = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * real_xrandr_sizes_count);
213 for (i=0; i < real_xrandr_sizes_count; i++)
215 real_xrandr_rates[i] = XRRRates (gdi_display, DefaultScreen(gdi_display), i, &(real_xrandr_rates_count[i]));
216 if (real_xrandr_rates_count[i])
218 nmodes += real_xrandr_rates_count[i];
229 real_xrandr_modes_count = nmodes;
230 TRACE("XRandR modes: count=%d\n", nmodes);
232 dd_modes = X11DRV_Settings_SetHandlers("XRandR",
233 X11DRV_XRandR_GetCurrentMode,
234 X11DRV_XRandR_SetCurrentMode,
237 X11DRV_Settings_AddDepthModes();
238 dd_mode_count = X11DRV_Settings_GetModeCount();
239 X11DRV_Settings_SetDefaultMode(0);
241 TRACE("Available DD modes: count=%d\n", dd_mode_count);
242 TRACE("Enabling XRandR\n");
245 void X11DRV_XRandR_Cleanup(void)
247 if (real_xrandr_rates)
249 HeapFree(GetProcessHeap(), 0, real_xrandr_rates);
250 real_xrandr_rates = NULL;
252 if (real_xrandr_rates_count)
254 HeapFree(GetProcessHeap(), 0, real_xrandr_rates_count);
255 real_xrandr_rates_count = NULL;
259 #endif /* HAVE_LIBXRANDR */