Commit 92e04256 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

winex11: Simplify the XRandR mode matching code a bit.

parent e5bb2e7d
...@@ -50,12 +50,8 @@ MAKE_FUNCPTR(XRRSizes) ...@@ -50,12 +50,8 @@ MAKE_FUNCPTR(XRRSizes)
extern int usexrandr; extern int usexrandr;
static struct x11drv_mode_info *dd_modes; static struct x11drv_mode_info *dd_modes;
static unsigned int dd_mode_count; static SizeID *xrandr_modes;
static XRRScreenSize *real_xrandr_sizes; static unsigned int xrandr_mode_count;
static short **real_xrandr_rates;
static int real_xrandr_sizes_count;
static int *real_xrandr_rates_count;
static unsigned int real_xrandr_modes_count;
static int load_xrandr(void) static int load_xrandr(void)
{ {
...@@ -112,15 +108,13 @@ static int X11DRV_XRandR_GetCurrentMode(void) ...@@ -112,15 +108,13 @@ static int X11DRV_XRandR_GetCurrentMode(void)
rate = pXRRConfigCurrentRate (sc); rate = pXRRConfigCurrentRate (sc);
pXRRFreeScreenConfigInfo(sc); pXRRFreeScreenConfigInfo(sc);
wine_tsx11_unlock(); wine_tsx11_unlock();
for (i = 0; i < real_xrandr_modes_count; i++) for (i = 0; i < xrandr_mode_count; ++i)
{ {
if ( (dd_modes[i].width == real_xrandr_sizes[size].width ) && if (xrandr_modes[i] == size && dd_modes[i].refresh_rate == rate)
(dd_modes[i].height == real_xrandr_sizes[size].height) && {
(dd_modes[i].refresh_rate == rate ) ) res = i;
{ break;
res = i; }
break;
}
} }
if (res == -1) if (res == -1)
{ {
...@@ -136,52 +130,28 @@ static LONG X11DRV_XRandR_SetCurrentMode(int mode) ...@@ -136,52 +130,28 @@ static LONG X11DRV_XRandR_SetCurrentMode(int mode)
Rotation rot; Rotation rot;
Window root; Window root;
XRRScreenConfiguration *sc; XRRScreenConfiguration *sc;
Status stat = RRSetConfigSuccess; Status stat;
short rate; short rate;
unsigned int i;
int j;
wine_tsx11_lock(); wine_tsx11_lock();
root = RootWindow (gdi_display, DefaultScreen(gdi_display)); root = RootWindow (gdi_display, DefaultScreen(gdi_display));
sc = pXRRGetScreenInfo (gdi_display, root); sc = pXRRGetScreenInfo (gdi_display, root);
size = pXRRConfigCurrentConfiguration (sc, &rot); size = pXRRConfigCurrentConfiguration (sc, &rot);
mode = mode%real_xrandr_modes_count; mode = mode % xrandr_mode_count;
TRACE("Changing Resolution to %dx%d @%d Hz\n", TRACE("Changing Resolution to %dx%d @%d Hz\n",
dd_modes[mode].width, dd_modes[mode].width,
dd_modes[mode].height, dd_modes[mode].height,
dd_modes[mode].refresh_rate); dd_modes[mode].refresh_rate);
for (i = 0; i < real_xrandr_sizes_count; i++) size = xrandr_modes[mode];
{ rate = dd_modes[mode].refresh_rate;
if ( (dd_modes[mode].width == real_xrandr_sizes[i].width ) &&
(dd_modes[mode].height == real_xrandr_sizes[i].height) ) if (rate)
{ stat = pXRRSetScreenConfigAndRate( gdi_display, sc, root, size, rot, rate, CurrentTime );
size = i; else
if (real_xrandr_rates_count[i]) stat = pXRRSetScreenConfig( gdi_display, sc, root, size, rot, CurrentTime );
{
for (j=0; j < real_xrandr_rates_count[i]; j++)
{
if (dd_modes[mode].refresh_rate == real_xrandr_rates[i][j])
{
rate = real_xrandr_rates[i][j];
TRACE("Resizing X display to %dx%d @%d Hz\n",
dd_modes[mode].width, dd_modes[mode].height, rate);
stat = pXRRSetScreenConfigAndRate (gdi_display, sc, root,
size, rot, rate, CurrentTime);
break;
}
}
}
else
{
TRACE("Resizing X display to %dx%d <default Hz>\n",
dd_modes[mode].width, dd_modes[mode].height);
stat = pXRRSetScreenConfig (gdi_display, sc, root, size, rot, CurrentTime);
}
break;
}
}
pXRRFreeScreenConfigInfo(sc); pXRRFreeScreenConfigInfo(sc);
wine_tsx11_unlock(); wine_tsx11_unlock();
if (stat == RRSetConfigSuccess) if (stat == RRSetConfigSuccess)
...@@ -196,30 +166,29 @@ static LONG X11DRV_XRandR_SetCurrentMode(int mode) ...@@ -196,30 +166,29 @@ static LONG X11DRV_XRandR_SetCurrentMode(int mode)
static void xrandr_init_modes(void) static void xrandr_init_modes(void)
{ {
XRRScreenSize *sizes;
int sizes_count;
int i, j, nmodes = 0; int i, j, nmodes = 0;
real_xrandr_sizes = pXRRSizes( gdi_display, DefaultScreen(gdi_display), &real_xrandr_sizes_count); sizes = pXRRSizes( gdi_display, DefaultScreen(gdi_display), &sizes_count );
if (real_xrandr_sizes_count <= 0) return; if (sizes_count <= 0) return;
TRACE("XRandR: found %u sizes.\n", real_xrandr_sizes_count); TRACE("XRandR: found %d sizes.\n", sizes_count);
real_xrandr_rates = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, for (i = 0; i < sizes_count; ++i)
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)
{ {
real_xrandr_rates[i] = pXRRRates( gdi_display, DefaultScreen(gdi_display), int rates_count;
i, &real_xrandr_rates_count[i] ); short *rates;
TRACE("- at %d: %dx%d (%d rates):", i, real_xrandr_sizes[i].width,
real_xrandr_sizes[i].height, real_xrandr_rates_count[i]); rates = pXRRRates( gdi_display, DefaultScreen(gdi_display), i, &rates_count );
if (real_xrandr_rates_count[i]) TRACE("- at %d: %dx%d (%d rates):", i, sizes[i].width, sizes[i].height, rates_count);
if (rates_count)
{ {
nmodes += real_xrandr_rates_count[i]; nmodes += rates_count;
for (j = 0; j < real_xrandr_rates_count[i]; ++j) for (j = 0; j < rates_count; ++j)
{ {
if (j > 0) if (j > 0)
TRACE(","); TRACE(",");
TRACE(" %d", real_xrandr_rates[i][j]); TRACE(" %d", rates[j]);
} }
} }
else else
...@@ -230,37 +199,46 @@ static void xrandr_init_modes(void) ...@@ -230,37 +199,46 @@ static void xrandr_init_modes(void)
TRACE(" Hz\n"); TRACE(" Hz\n");
} }
real_xrandr_modes_count = nmodes;
TRACE("XRandR modes: count=%d\n", nmodes); TRACE("XRandR modes: count=%d\n", nmodes);
if (!(xrandr_modes = HeapAlloc( GetProcessHeap(), 0, sizeof(*xrandr_modes) * nmodes )))
{
ERR("Failed to allocate xrandr mode info array.\n");
return;
}
dd_modes = X11DRV_Settings_SetHandlers( "XRandR", dd_modes = X11DRV_Settings_SetHandlers( "XRandR",
X11DRV_XRandR_GetCurrentMode, X11DRV_XRandR_GetCurrentMode,
X11DRV_XRandR_SetCurrentMode, X11DRV_XRandR_SetCurrentMode,
nmodes, 1 ); nmodes, 1 );
for (i = 0; i < real_xrandr_sizes_count; ++i) xrandr_mode_count = 0;
for (i = 0; i < sizes_count; ++i)
{ {
if (real_xrandr_rates_count[i]) int rates_count;
short *rates;
rates = pXRRRates( gdi_display, DefaultScreen(gdi_display), i, &rates_count );
if (rates_count)
{ {
for (j = 0; j < real_xrandr_rates_count[i]; ++j) for (j = 0; j < rates_count; ++j)
{ {
X11DRV_Settings_AddOneMode( real_xrandr_sizes[i].width, X11DRV_Settings_AddOneMode( sizes[i].width, sizes[i].height, 0, rates[j] );
real_xrandr_sizes[i].height, xrandr_modes[xrandr_mode_count++] = i;
0, real_xrandr_rates[i][j] );
} }
} }
else else
{ {
X11DRV_Settings_AddOneMode( real_xrandr_sizes[i].width, X11DRV_Settings_AddOneMode( sizes[i].width, sizes[i].height, 0, 0 );
real_xrandr_sizes[i].height, xrandr_modes[xrandr_mode_count++] = i;
0, 0 );
} }
} }
X11DRV_Settings_AddDepthModes(); X11DRV_Settings_AddDepthModes();
dd_mode_count = X11DRV_Settings_GetModeCount(); nmodes = X11DRV_Settings_GetModeCount();
TRACE("Available DD modes: count=%d\n", dd_mode_count); TRACE("Available DD modes: count=%d\n", nmodes);
TRACE("Enabling XRandR\n"); TRACE("Enabling XRandR\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment