private bool QueryXRandR(List <DisplayDevice> devices) { foreach (DisplayDevice key1 in devices) { int index1 = this.deviceToScreen[key1]; IntPtr config_timestamp; Functions.XRRTimes(API.DefaultDisplay, index1, out config_timestamp); this.lastConfigUpdate.Add(config_timestamp); List <DisplayResolution> list = new List <DisplayResolution>(); this.screenResolutionToIndex.Add(new Dictionary <DisplayResolution, int>()); int[] availableDepths = X11DisplayDevice.FindAvailableDepths(index1); int size_index = 0; foreach (XRRScreenSize xrrScreenSize in X11DisplayDevice.FindAvailableResolutions(index1)) { if (xrrScreenSize.Width != 0 && xrrScreenSize.Height != 0) { short[] numArray = Functions.XRRRates(API.DefaultDisplay, index1, size_index); foreach (short num in numArray) { if ((int)num != 0 || numArray.Length == 1) { foreach (int bitsPerPixel in availableDepths) { list.Add(new DisplayResolution(0, 0, xrrScreenSize.Width, xrrScreenSize.Height, bitsPerPixel, (float)num)); } } } foreach (int bitsPerPixel in availableDepths) { DisplayResolution key2 = new DisplayResolution(0, 0, xrrScreenSize.Width, xrrScreenSize.Height, bitsPerPixel, 0.0f); if (!this.screenResolutionToIndex[index1].ContainsKey(key2)) { this.screenResolutionToIndex[index1].Add(key2, size_index); } } ++size_index; } } float currentRefreshRate = X11DisplayDevice.FindCurrentRefreshRate(index1); int currentDepth = X11DisplayDevice.FindCurrentDepth(index1); ushort rotation; int index2 = (int)Functions.XRRConfigCurrentConfiguration(Functions.XRRGetScreenInfo(API.DefaultDisplay, Functions.XRootWindow(API.DefaultDisplay, index1)), out rotation); if (key1.Bounds == System.Drawing.Rectangle.Empty) { key1.Bounds = new System.Drawing.Rectangle(0, 0, list[index2].Width, list[index2].Height); } key1.BitsPerPixel = currentDepth; key1.RefreshRate = currentRefreshRate; key1.AvailableResolutions = (IList <DisplayResolution>)list; this.deviceToDefaultResolution.Add(key1, index2); } return(true); }
public override sealed bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) { if (this.xrandr_supported) { return(this.ChangeResolutionXRandR(device, resolution)); } if (this.xf86_supported) { return(X11DisplayDevice.ChangeResolutionXF86(device, resolution)); } else { return(false); } }
private void RefreshDisplayDevices() { using (new XLock(API.DefaultDisplay)) { List <DisplayDevice> devices = new List <DisplayDevice>(); this.xinerama_supported = false; try { this.xinerama_supported = this.QueryXinerama(devices); } catch { } if (!this.xinerama_supported) { for (int index = 0; index < API.ScreenCount; ++index) { DisplayDevice key = new DisplayDevice(); key.IsPrimary = index == Functions.XDefaultScreen(API.DefaultDisplay); devices.Add(key); this.deviceToScreen.Add(key, index); } } try { this.xrandr_supported = this.QueryXRandR(devices); } catch { } if (!this.xrandr_supported) { try { this.xf86_supported = this.QueryXF86(devices); } catch { } int num = this.xf86_supported ? 1 : 0; } this.AvailableDevices.Clear(); this.AvailableDevices.AddRange((IEnumerable <DisplayDevice>)devices); this.Primary = X11DisplayDevice.FindDefaultDevice((IEnumerable <DisplayDevice>)devices); } }
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); }
public void InitDisplayDeviceDriver() { X11DisplayDevice.Init(); }