Added XF86VM fallback when XRandR is missing (many thanks to jdomnitz!)

This commit is contained in:
the_fiddler 2010-10-09 19:10:39 +00:00
parent 42fdd873ff
commit dd41ed9610
2 changed files with 72 additions and 26 deletions

View file

@ -311,17 +311,17 @@ namespace OpenTK.Platform.X11
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct XF86VidModeModeLine internal struct XF86VidModeModeLine
{ {
short hdisplay; /* Number of display pixels horizontally */ public short hdisplay; /* Number of display pixels horizontally */
short hsyncstart; /* Horizontal sync start */ public short hsyncstart; /* Horizontal sync start */
short hsyncend; /* Horizontal sync end */ public short hsyncend; /* Horizontal sync end */
short htotal; /* Total horizontal pixels */ public short htotal; /* Total horizontal pixels */
short vdisplay; /* Number of display pixels vertically */ public short vdisplay; /* Number of display pixels vertically */
short vsyncstart; /* Vertical sync start */ public short vsyncstart; /* Vertical sync start */
short vsyncend; /* Vertical sync start */ public short vsyncend; /* Vertical sync start */
short vtotal; /* Total vertical pixels */ public short vtotal; /* Total vertical pixels */
int flags; /* Mode flags */ public int flags; /* Mode flags */
int privsize; /* Size of private */ public int privsize; /* Size of private */
IntPtr _private; /* Server privates */ public IntPtr _private; /* Server privates */
} }
/// <summary> /// <summary>
@ -471,6 +471,13 @@ namespace OpenTK.Platform.X11
out int major_version_return, out int major_version_return,
out int minor_version_return); out int minor_version_return);
[DllImport(_dll_name_vid)]
extern public static bool XF86VidModeGetModeLine(
Display display,
int screen,
out int dotclock_return,
out XF86VidModeModeLine modeline);
[DllImport(_dll_name_vid)] [DllImport(_dll_name_vid)]
extern public static bool XF86VidModeGetAllModeLines( extern public static bool XF86VidModeGetAllModeLines(
Display display, Display display,
@ -479,6 +486,13 @@ namespace OpenTK.Platform.X11
/*XF86VidModeModeInfo*** <-- yes, that's three *'s. */ /*XF86VidModeModeInfo*** <-- yes, that's three *'s. */
out IntPtr modesinfo); out IntPtr modesinfo);
[DllImport(_dll_name_vid)]
extern public static bool XF86VidModeGetViewPort(
Display display,
int screen,
out int x_return,
out int y_return);
[DllImport(_dll_name_vid)] [DllImport(_dll_name_vid)]
extern public static bool XF86VidModeSetViewPort( extern public static bool XF86VidModeSetViewPort(
Display display, Display display,
@ -490,12 +504,6 @@ namespace OpenTK.Platform.X11
Bool XF86VidModeSetClientVersion( Bool XF86VidModeSetClientVersion(
Display *display); Display *display);
Bool XF86VidModeGetModeLine(
Display *display,
int screen,
int *dotclock_return,
XF86VidModeModeLine *modeline);
Bool XF86VidModeDeleteModeLine( Bool XF86VidModeDeleteModeLine(
Display *display, Display *display,
int screen, int screen,
@ -511,7 +519,6 @@ Status XF86VidModeValidateModeLine(
int screen, int screen,
XF86VidModeModeLine *modeline); XF86VidModeModeLine *modeline);
Bool XF86VidModeLockModeSwitch( Bool XF86VidModeLockModeSwitch(
Display *display, Display *display,
int screen, int screen,
@ -522,13 +529,6 @@ Bool XF86VidModeGetMonitor(
int screen, int screen,
XF86VidModeMonitor *monitor); XF86VidModeMonitor *monitor);
Bool XF86VidModeGetViewPort(
Display *display,
int screen,
int *x_return,
int *y_return);
XF86VidModeGetDotClocks( XF86VidModeGetDotClocks(
Display *display, Display *display,
int screen, int screen,

View file

@ -198,7 +198,53 @@ namespace OpenTK.Platform.X11
static bool QueryXF86(List<DisplayDevice> devices) static bool QueryXF86(List<DisplayDevice> devices)
{ {
return false; int major;
int minor;
try
{
if (!API.XF86VidModeQueryVersion(API.DefaultDisplay, out major, out minor))
return false;
}
catch (DllNotFoundException)
{
return false;
}
int currentScreen = 0;
Debug.Print("Using XF86 v" + major.ToString() + "." + minor.ToString());
foreach (DisplayDevice dev in devices)
{
int count;
IntPtr srcArray;
API.XF86VidModeGetAllModeLines(API.DefaultDisplay, currentScreen, out count, out srcArray);
Debug.Print(count.ToString() + " modes detected on screen " + currentScreen.ToString());
IntPtr[] array = new IntPtr[count];
Marshal.Copy(srcArray, array, 0, count);
API.XF86VidModeModeInfo Mode = new API.XF86VidModeModeInfo();
int x;
int y;
API.XF86VidModeGetViewPort(API.DefaultDisplay, currentScreen, out x, out y);
List<DisplayResolution> resolutions = new List<DisplayResolution>();
for (int i = 0; i < count; i++)
{
Mode = (API.XF86VidModeModeInfo)Marshal.PtrToStructure(array[i], typeof(API.XF86VidModeModeInfo));
resolutions.Add(new DisplayResolution(x, y, Mode.hdisplay, Mode.vdisplay, 24, (Mode.dotclock * 1000F) / (Mode.vtotal * Mode.htotal)));
}
dev.AvailableResolutions = resolutions;
int pixelClock;
API.XF86VidModeModeLine currentMode;
API.XF86VidModeGetModeLine(API.DefaultDisplay, currentScreen, out pixelClock, out currentMode);
dev.Bounds = new Rectangle(x, y, currentMode.hdisplay, (currentMode.vdisplay == 0) ? currentMode.vsyncstart : currentMode.vdisplay);
dev.BitsPerPixel = FindCurrentDepth(currentScreen);
dev.RefreshRate = (pixelClock * 1000F) / (currentMode.vtotal * currentMode.htotal);
currentScreen++;
}
return true;
} }
#region static int[] FindAvailableDepths(int screen) #region static int[] FindAvailableDepths(int screen)