2003-10-16 02:21:42 +02:00
|
|
|
/*
|
|
|
|
* Wine X11drv Xrandr interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Alexander James Pasadyn
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-10-16 02:21:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2004-04-07 05:57:35 +02:00
|
|
|
#include "wine/port.h"
|
2003-10-16 02:21:42 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-07-04 12:45:03 +02:00
|
|
|
#ifdef SONAME_LIBXRANDR
|
2003-10-16 02:21:42 +02:00
|
|
|
|
2003-11-21 22:50:59 +01:00
|
|
|
#include <X11/Xlib.h>
|
2003-10-16 02:21:42 +02:00
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include "x11drv.h"
|
|
|
|
|
|
|
|
#include "xrandr.h"
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "ddrawi.h"
|
2004-04-07 05:57:35 +02:00
|
|
|
#include "wine/library.h"
|
2003-10-16 02:21:42 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(xrandr);
|
|
|
|
|
2004-04-07 05:57:35 +02:00
|
|
|
static void *xrandr_handle;
|
|
|
|
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f;
|
|
|
|
MAKE_FUNCPTR(XRRConfigCurrentConfiguration)
|
|
|
|
MAKE_FUNCPTR(XRRConfigCurrentRate)
|
|
|
|
MAKE_FUNCPTR(XRRFreeScreenConfigInfo)
|
|
|
|
MAKE_FUNCPTR(XRRGetScreenInfo)
|
|
|
|
MAKE_FUNCPTR(XRRQueryExtension)
|
|
|
|
MAKE_FUNCPTR(XRRQueryVersion)
|
|
|
|
MAKE_FUNCPTR(XRRRates)
|
|
|
|
MAKE_FUNCPTR(XRRSetScreenConfig)
|
|
|
|
MAKE_FUNCPTR(XRRSetScreenConfigAndRate)
|
|
|
|
MAKE_FUNCPTR(XRRSizes)
|
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
extern int usexrandr;
|
|
|
|
|
|
|
|
static int xrandr_event, xrandr_error, xrandr_major, xrandr_minor;
|
|
|
|
|
|
|
|
static LPDDHALMODEINFO dd_modes;
|
|
|
|
static unsigned int dd_mode_count;
|
|
|
|
static XRRScreenSize *real_xrandr_sizes;
|
|
|
|
static short **real_xrandr_rates;
|
2005-08-12 12:35:46 +02:00
|
|
|
static int real_xrandr_sizes_count;
|
2003-10-16 02:21:42 +02:00
|
|
|
static int *real_xrandr_rates_count;
|
|
|
|
static unsigned int real_xrandr_modes_count;
|
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static int load_xrandr(void)
|
2004-04-07 05:57:35 +02:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
if (wine_dlopen(SONAME_LIBX11, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
|
|
|
|
wine_dlopen(SONAME_LIBXEXT, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
|
|
|
|
wine_dlopen(SONAME_LIBXRENDER, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
|
|
|
|
(xrandr_handle = wine_dlopen(SONAME_LIBXRANDR, RTLD_NOW, NULL, 0)))
|
|
|
|
{
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(xrandr_handle, #f, NULL, 0)) == NULL) \
|
|
|
|
goto sym_not_found;
|
|
|
|
|
|
|
|
LOAD_FUNCPTR(XRRConfigCurrentConfiguration)
|
|
|
|
LOAD_FUNCPTR(XRRConfigCurrentRate)
|
|
|
|
LOAD_FUNCPTR(XRRFreeScreenConfigInfo)
|
|
|
|
LOAD_FUNCPTR(XRRGetScreenInfo)
|
|
|
|
LOAD_FUNCPTR(XRRQueryExtension)
|
|
|
|
LOAD_FUNCPTR(XRRQueryVersion)
|
|
|
|
LOAD_FUNCPTR(XRRRates)
|
|
|
|
LOAD_FUNCPTR(XRRSetScreenConfig)
|
|
|
|
LOAD_FUNCPTR(XRRSetScreenConfigAndRate)
|
|
|
|
LOAD_FUNCPTR(XRRSizes)
|
|
|
|
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
r = 1; /* success */
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
if (!r) TRACE("Unable to load function ptrs from XRandR library\n");
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
static int XRandRErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create the mode structures */
|
|
|
|
static void make_modes(void)
|
|
|
|
{
|
2008-12-06 14:18:43 +01:00
|
|
|
int i, j;
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
for (i=0; i<real_xrandr_sizes_count; i++)
|
|
|
|
{
|
|
|
|
if (real_xrandr_rates_count[i])
|
|
|
|
{
|
|
|
|
for (j=0; j < real_xrandr_rates_count[i]; j++)
|
|
|
|
{
|
|
|
|
X11DRV_Settings_AddOneMode(real_xrandr_sizes[i].width,
|
|
|
|
real_xrandr_sizes[i].height,
|
|
|
|
0, real_xrandr_rates[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
X11DRV_Settings_AddOneMode(real_xrandr_sizes[i].width,
|
|
|
|
real_xrandr_sizes[i].height,
|
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int X11DRV_XRandR_GetCurrentMode(void)
|
|
|
|
{
|
|
|
|
SizeID size;
|
|
|
|
Rotation rot;
|
|
|
|
Window root;
|
|
|
|
XRRScreenConfiguration *sc;
|
|
|
|
short rate;
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int i;
|
2003-10-16 02:21:42 +02:00
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
root = RootWindow (gdi_display, DefaultScreen(gdi_display));
|
2004-04-07 05:57:35 +02:00
|
|
|
sc = pXRRGetScreenInfo (gdi_display, root);
|
|
|
|
size = pXRRConfigCurrentConfiguration (sc, &rot);
|
|
|
|
rate = pXRRConfigCurrentRate (sc);
|
2007-01-11 15:47:06 +01:00
|
|
|
pXRRFreeScreenConfigInfo(sc);
|
|
|
|
wine_tsx11_unlock();
|
2003-10-16 02:21:42 +02:00
|
|
|
for (i = 0; i < real_xrandr_modes_count; i++)
|
|
|
|
{
|
|
|
|
if ( (dd_modes[i].dwWidth == real_xrandr_sizes[size].width ) &&
|
|
|
|
(dd_modes[i].dwHeight == real_xrandr_sizes[size].height) &&
|
|
|
|
(dd_modes[i].wRefreshRate == rate ) )
|
|
|
|
{
|
|
|
|
res = i;
|
2007-01-11 15:47:06 +01:00
|
|
|
break;
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
ERR("In unknown mode, returning default\n");
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-02-22 12:42:20 +01:00
|
|
|
static LONG X11DRV_XRandR_SetCurrentMode(int mode)
|
2003-10-16 02:21:42 +02:00
|
|
|
{
|
|
|
|
SizeID size;
|
|
|
|
Rotation rot;
|
|
|
|
Window root;
|
|
|
|
XRRScreenConfiguration *sc;
|
|
|
|
Status stat = RRSetConfigSuccess;
|
|
|
|
short rate;
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int i;
|
|
|
|
int j;
|
2007-12-16 14:00:45 +01:00
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
wine_tsx11_lock();
|
|
|
|
root = RootWindow (gdi_display, DefaultScreen(gdi_display));
|
2004-04-07 05:57:35 +02:00
|
|
|
sc = pXRRGetScreenInfo (gdi_display, root);
|
|
|
|
size = pXRRConfigCurrentConfiguration (sc, &rot);
|
2003-10-16 02:21:42 +02:00
|
|
|
mode = mode%real_xrandr_modes_count;
|
2005-04-28 20:29:12 +02:00
|
|
|
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("Changing Resolution to %dx%d @%d Hz\n",
|
2005-04-28 20:29:12 +02:00
|
|
|
dd_modes[mode].dwWidth,
|
|
|
|
dd_modes[mode].dwHeight,
|
|
|
|
dd_modes[mode].wRefreshRate);
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
for (i = 0; i < real_xrandr_sizes_count; i++)
|
|
|
|
{
|
|
|
|
if ( (dd_modes[mode].dwWidth == real_xrandr_sizes[i].width ) &&
|
|
|
|
(dd_modes[mode].dwHeight == real_xrandr_sizes[i].height) )
|
|
|
|
{
|
|
|
|
size = i;
|
|
|
|
if (real_xrandr_rates_count[i])
|
|
|
|
{
|
|
|
|
for (j=0; j < real_xrandr_rates_count[i]; j++)
|
|
|
|
{
|
|
|
|
if (dd_modes[mode].wRefreshRate == real_xrandr_rates[i][j])
|
|
|
|
{
|
|
|
|
rate = real_xrandr_rates[i][j];
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("Resizing X display to %dx%d @%d Hz\n",
|
2003-10-16 02:21:42 +02:00
|
|
|
dd_modes[mode].dwWidth, dd_modes[mode].dwHeight, rate);
|
2004-04-07 05:57:35 +02:00
|
|
|
stat = pXRRSetScreenConfigAndRate (gdi_display, sc, root,
|
2003-10-16 02:21:42 +02:00
|
|
|
size, rot, rate, CurrentTime);
|
2007-01-11 15:47:06 +01:00
|
|
|
break;
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("Resizing X display to %dx%d <default Hz>\n",
|
2005-04-28 20:29:12 +02:00
|
|
|
dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
|
|
|
|
stat = pXRRSetScreenConfig (gdi_display, sc, root, size, rot, CurrentTime);
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
2007-01-11 15:47:06 +01:00
|
|
|
break;
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-07 05:57:35 +02:00
|
|
|
pXRRFreeScreenConfigInfo(sc);
|
2003-10-16 02:21:42 +02:00
|
|
|
wine_tsx11_unlock();
|
2004-02-13 04:58:21 +01:00
|
|
|
if (stat == RRSetConfigSuccess)
|
2007-02-22 12:42:20 +01:00
|
|
|
{
|
2008-01-17 19:53:59 +01:00
|
|
|
X11DRV_resize_desktop( dd_modes[mode].dwWidth, dd_modes[mode].dwHeight );
|
2007-02-22 12:42:20 +01:00
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Resolution change not successful -- perhaps display has changed?\n");
|
|
|
|
return DISP_CHANGE_FAILED;
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11DRV_XRandR_Init(void)
|
|
|
|
{
|
|
|
|
Bool ok;
|
2008-12-06 14:18:43 +01:00
|
|
|
int i, nmodes = 0;
|
2003-10-16 02:21:42 +02:00
|
|
|
|
|
|
|
if (xrandr_major) return; /* already initialized? */
|
|
|
|
if (!usexrandr) return; /* disabled in config */
|
2006-03-27 15:33:43 +02:00
|
|
|
if (root_window != DefaultRootWindow( gdi_display )) return;
|
2004-04-07 05:57:35 +02:00
|
|
|
if (!load_xrandr()) return; /* can't load the Xrandr library */
|
2003-10-16 02:21:42 +02:00
|
|
|
|
|
|
|
/* see if Xrandr is available */
|
|
|
|
wine_tsx11_lock();
|
2004-04-07 05:57:35 +02:00
|
|
|
ok = pXRRQueryExtension(gdi_display, &xrandr_event, &xrandr_error);
|
2003-10-16 02:21:42 +02:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
X11DRV_expect_error(gdi_display, XRandRErrorHandler, NULL);
|
2004-04-07 05:57:35 +02:00
|
|
|
ok = pXRRQueryVersion(gdi_display, &xrandr_major, &xrandr_minor);
|
2003-10-16 02:21:42 +02:00
|
|
|
if (X11DRV_check_error()) ok = FALSE;
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
TRACE("Found XRandR - major: %d, minor: %d\n", xrandr_major, xrandr_minor);
|
|
|
|
/* retrieve modes */
|
2004-04-07 05:57:35 +02:00
|
|
|
real_xrandr_sizes = pXRRSizes(gdi_display, DefaultScreen(gdi_display), &real_xrandr_sizes_count);
|
2003-10-16 02:21:42 +02:00
|
|
|
ok = (real_xrandr_sizes_count>0);
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
{
|
2005-04-28 20:29:12 +02:00
|
|
|
TRACE("XRandR: found %u resolutions sizes\n", real_xrandr_sizes_count);
|
2003-10-16 02:21:42 +02:00
|
|
|
real_xrandr_rates = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(short *) * real_xrandr_sizes_count);
|
|
|
|
real_xrandr_rates_count = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * real_xrandr_sizes_count);
|
|
|
|
for (i=0; i < real_xrandr_sizes_count; i++)
|
|
|
|
{
|
2004-04-07 05:57:35 +02:00
|
|
|
real_xrandr_rates[i] = pXRRRates (gdi_display, DefaultScreen(gdi_display), i, &(real_xrandr_rates_count[i]));
|
2008-12-06 14:18:43 +01:00
|
|
|
TRACE("- at %d: %dx%d (%d rates):", i, real_xrandr_sizes[i].width, real_xrandr_sizes[i].height, real_xrandr_rates_count[i]);
|
2003-10-16 02:21:42 +02:00
|
|
|
if (real_xrandr_rates_count[i])
|
|
|
|
{
|
2005-04-28 20:29:12 +02:00
|
|
|
int j;
|
2003-10-16 02:21:42 +02:00
|
|
|
nmodes += real_xrandr_rates_count[i];
|
2005-04-28 20:29:12 +02:00
|
|
|
for (j = 0; j < real_xrandr_rates_count[i]; ++j) {
|
|
|
|
if (j > 0) TRACE(",");
|
|
|
|
TRACE(" %d", real_xrandr_rates[i][j]);
|
|
|
|
}
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nmodes++;
|
2005-04-28 20:29:12 +02:00
|
|
|
TRACE(" <default>");
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE(" Hz\n");
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (!ok) return;
|
|
|
|
|
|
|
|
real_xrandr_modes_count = nmodes;
|
|
|
|
TRACE("XRandR modes: count=%d\n", nmodes);
|
|
|
|
|
|
|
|
dd_modes = X11DRV_Settings_SetHandlers("XRandR",
|
|
|
|
X11DRV_XRandR_GetCurrentMode,
|
|
|
|
X11DRV_XRandR_SetCurrentMode,
|
|
|
|
nmodes, 1);
|
|
|
|
make_modes();
|
|
|
|
X11DRV_Settings_AddDepthModes();
|
|
|
|
dd_mode_count = X11DRV_Settings_GetModeCount();
|
|
|
|
|
|
|
|
TRACE("Available DD modes: count=%d\n", dd_mode_count);
|
|
|
|
TRACE("Enabling XRandR\n");
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:45:03 +02:00
|
|
|
#endif /* SONAME_LIBXRANDR */
|