Merge pull request #632 from UnknownShadow200/develop

X11DisplayDevice - Use XRRSizes array directly if dev.Bounds is empty
This commit is contained in:
Fraser Waters 2017-08-08 17:53:41 +01:00 committed by GitHub
commit b4dc24cfcf

View file

@ -171,7 +171,8 @@ namespace OpenTK.Platform.X11
int[] depths = FindAvailableDepths(screen); int[] depths = FindAvailableDepths(screen);
int resolution_count = 0; int resolution_count = 0;
foreach (XRRScreenSize size in FindAvailableResolutions(screen)) XRRScreenSize[] sizes = FindAvailableResolutions(screen);
foreach (XRRScreenSize size in sizes)
{ {
if (size.Width == 0 || size.Height == 0) if (size.Width == 0 || size.Height == 0)
{ {
@ -221,28 +222,17 @@ namespace OpenTK.Platform.X11
int current_depth = FindCurrentDepth(screen); int current_depth = FindCurrentDepth(screen);
IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, screen)); IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, screen));
ushort current_rotation; // Not needed. ushort current_rotation; // Not needed.
int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation); int current_sizes_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);
if (dev.Bounds == Rectangle.Empty) if (dev.Bounds == Rectangle.Empty)
{ {
// We have added depths.Length copies of each resolution dev.Bounds = new Rectangle(0, 0, sizes[current_sizes_index].Width, sizes[current_sizes_index].Height);
// Adjust the return value of XRRGetScreenInfo to retrieve the correct resolution
int index = current_resolution_index * depths.Length;
// Make sure we are within the bounds of the available_res array
if (index >= available_res.Count)
{
// If not, use the return value of XRRGetScreenInfo directly
index = current_resolution_index;
}
DisplayResolution current_resolution = available_res[index];
dev.Bounds = new Rectangle(0, 0, current_resolution.Width, current_resolution.Height);
} }
dev.BitsPerPixel = current_depth; dev.BitsPerPixel = current_depth;
dev.RefreshRate = current_refresh_rate; dev.RefreshRate = current_refresh_rate;
dev.AvailableResolutions = available_res; dev.AvailableResolutions = available_res;
deviceToDefaultResolution.Add(dev, current_resolution_index); deviceToDefaultResolution.Add(dev, current_sizes_index);
} }
return true; return true;