XF86VidModeQueryVersion() private method

private XF86VidModeQueryVersion ( Display display, int &major_version_return, int &minor_version_return ) : bool
display Display
major_version_return int
minor_version_return int
return bool
        private bool QueryXF86(List <DisplayDevice> devices)
        {
            int major;
            int minor;

            try
            {
                if (!API.XF86VidModeQueryVersion(API.DefaultDisplay, out major, out minor))
                {
                    return(false);
                }
            }
            catch (DllNotFoundException)
            {
                return(false);
            }

            var currentScreen = 0;

            Debug.Print("Using XF86 v" + major + "." + minor);

            foreach (var dev in devices)
            {
                int count;

                IntPtr srcArray;
                API.XF86VidModeGetAllModeLines(API.DefaultDisplay, currentScreen, out count, out srcArray);
                Debug.Print(count + " modes detected on screen " + currentScreen);
                var array = new IntPtr[count];
                Marshal.Copy(srcArray, array, 0, count);
                var Mode = new API.XF86VidModeModeInfo();

                int x;
                int y;
                API.XF86VidModeGetViewPort(API.DefaultDisplay, currentScreen, out x, out y);
                var resolutions = new List <DisplayResolution>();
                for (var 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);
        }
Esempio n. 2
0
        private bool QueryXF86(List <DisplayDevice> devices)
        {
            try
            {
                int major_version_return;
                int minor_version_return;
                if (!API.XF86VidModeQueryVersion(API.DefaultDisplay, out major_version_return, out minor_version_return))
                {
                    return(false);
                }
            }
            catch (DllNotFoundException ex)
            {
                return(false);
            }
            int screen = 0;

            foreach (DisplayDevice displayDevice in devices)
            {
                int    modecount_return;
                IntPtr modesinfo;
                API.XF86VidModeGetAllModeLines(API.DefaultDisplay, screen, out modecount_return, out modesinfo);
                IntPtr[] destination = new IntPtr[modecount_return];
                Marshal.Copy(modesinfo, destination, 0, modecount_return);
                API.XF86VidModeModeInfo xf86VidModeModeInfo = new API.XF86VidModeModeInfo();
                int x_return;
                int y_return;
                API.XF86VidModeGetViewPort(API.DefaultDisplay, screen, out x_return, out y_return);
                List <DisplayResolution> list = new List <DisplayResolution>();
                for (int index = 0; index < modecount_return; ++index)
                {
                    xf86VidModeModeInfo = (API.XF86VidModeModeInfo)Marshal.PtrToStructure(destination[index], typeof(API.XF86VidModeModeInfo));
                    list.Add(new DisplayResolution(x_return, y_return, (int)xf86VidModeModeInfo.hdisplay, (int)xf86VidModeModeInfo.vdisplay, 24, (float)xf86VidModeModeInfo.dotclock * 1000f / (float)((int)xf86VidModeModeInfo.vtotal * (int)xf86VidModeModeInfo.htotal)));
                }
                displayDevice.AvailableResolutions = (IList <DisplayResolution>)list;
                int dotclock_return;
                API.XF86VidModeModeLine modeline;
                API.XF86VidModeGetModeLine(API.DefaultDisplay, screen, out dotclock_return, out modeline);
                displayDevice.Bounds       = new System.Drawing.Rectangle(x_return, y_return, (int)modeline.hdisplay, (int)modeline.vdisplay == 0 ? (int)modeline.vsyncstart : (int)modeline.vdisplay);
                displayDevice.BitsPerPixel = X11DisplayDevice.FindCurrentDepth(screen);
                displayDevice.RefreshRate  = (float)dotclock_return * 1000f / (float)((int)modeline.vtotal * (int)modeline.htotal);
                ++screen;
            }
            return(true);
        }