mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-07 13:30:38 +00:00
Added several properties to get the default screen, default display, screen count and default root window. Updated XRRSizes to abstract away the memory marshaling.
This commit is contained in:
parent
d3c9517158
commit
a3ba77f35d
|
@ -45,8 +45,31 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
internal static class API
|
internal static class API
|
||||||
{
|
{
|
||||||
// Prevent BeforeFieldInit optimization.
|
#region --- Fields ---
|
||||||
static API() { }
|
|
||||||
|
static Display defaultDisplay = Functions.XOpenDisplay(IntPtr.Zero);
|
||||||
|
static int defaultScreen = Functions.XDefaultScreen(defaultDisplay);
|
||||||
|
static Window rootWindow = Functions.XRootWindow(defaultDisplay, defaultScreen);
|
||||||
|
static int screenCount = Functions.XScreenCount(defaultDisplay);
|
||||||
|
|
||||||
|
internal static Display DefaultDisplay { get { return defaultDisplay; } }
|
||||||
|
internal static int DefaultScreen { get { return defaultScreen; } }
|
||||||
|
internal static Window RootWindow { get { return rootWindow; } }
|
||||||
|
internal static int ScreenCount { get { return screenCount; } }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
static API()
|
||||||
|
{
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CurrentDomain_ProcessExit(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (defaultDisplay != IntPtr.Zero) { Functions.XCloseDisplay(defaultDisplay); defaultDisplay = IntPtr.Zero; }
|
||||||
|
if (defaultDisplay != IntPtr.Zero) { Functions.XCloseDisplay(defaultDisplay); defaultDisplay = IntPtr.Zero; }
|
||||||
|
if (defaultDisplay != IntPtr.Zero) { Functions.XCloseDisplay(defaultDisplay); defaultDisplay = IntPtr.Zero; }
|
||||||
|
}
|
||||||
|
|
||||||
private const string _dll_name = "libX11";
|
private const string _dll_name = "libX11";
|
||||||
private const string _dll_name_vid = "libXxf86vm";
|
private const string _dll_name_vid = "libXxf86vm";
|
||||||
|
@ -63,8 +86,6 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#region Window handling
|
#region Window handling
|
||||||
|
|
||||||
[DllImport(_dll_name, EntryPoint = "XRootWindow")]
|
|
||||||
public static extern Window RootWindow(Display display, int screen);
|
|
||||||
|
|
||||||
[Obsolete("Use XCreateWindow instead")]
|
[Obsolete("Use XCreateWindow instead")]
|
||||||
[DllImport(_dll_name, EntryPoint = "XCreateWindow")]
|
[DllImport(_dll_name, EntryPoint = "XCreateWindow")]
|
||||||
|
@ -109,9 +130,6 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[DllImport(_dll_name, EntryPoint = "XDefaultScreen")]
|
|
||||||
extern public static int DefaultScreen(Display display);
|
|
||||||
|
|
||||||
[DllImport(_dll_name, EntryPoint = "XDefaultVisual")]
|
[DllImport(_dll_name, EntryPoint = "XDefaultVisual")]
|
||||||
extern public static IntPtr DefaultVisual(Display display, int screen_number);
|
extern public static IntPtr DefaultVisual(Display display, int screen_number);
|
||||||
|
|
||||||
|
@ -1315,16 +1333,44 @@ XF86VidModeGetGammaRampSize(
|
||||||
public static extern Rotation XRRRotations(Display dpy, int screen, ref Rotation current_rotation);
|
public static extern Rotation XRRRotations(Display dpy, int screen, ref Rotation current_rotation);
|
||||||
|
|
||||||
[DllImport(XrandrLibrary)]
|
[DllImport(XrandrLibrary)]
|
||||||
[return: MarshalAs(UnmanagedType.LPStruct)]
|
unsafe static extern IntPtr XRRSizes(Display dpy, int screen, int* nsizes);
|
||||||
public static extern XRRScreenSize XRRSizes(Display dpy, int screen, int[] nsizes);
|
|
||||||
|
public static XRRScreenSize[] XRRSizes(Display dpy, int screen)
|
||||||
|
{
|
||||||
|
XRRScreenSize[] array;
|
||||||
|
IntPtr ptr;
|
||||||
|
int nsizes;
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
ptr = XRRSizes(dpy, screen, &nsizes);
|
||||||
|
|
||||||
|
byte* data = (byte*)ptr;
|
||||||
|
array = new XRRScreenSize[nsizes];
|
||||||
|
for (int i = 0; i < nsizes; i++)
|
||||||
|
{
|
||||||
|
array[i] = new XRRScreenSize();
|
||||||
|
Marshal.PtrToStructure((IntPtr)data, array[i]);
|
||||||
|
data += Marshal.SizeOf(typeof(XRRScreenSize));
|
||||||
|
}
|
||||||
|
XFree(ptr);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport(XrandrLibrary)]
|
[DllImport(XrandrLibrary)]
|
||||||
unsafe public static extern short* XRRRates(Display dpy, int screen, int size_index, int[] nrates);
|
unsafe public static extern short* XRRRates(Display dpy, int screen, int size_index, int* nrates);
|
||||||
|
|
||||||
[DllImport(XrandrLibrary)]
|
[DllImport(XrandrLibrary)]
|
||||||
public static extern Time XRRTimes(Display dpy, int screen, ref Time config_timestamp);
|
public static extern Time XRRTimes(Display dpy, int screen, ref Time config_timestamp);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Display, Screen and Window functions
|
||||||
|
|
||||||
|
[DllImport("libX11")]
|
||||||
|
public static extern int XScreenCount(Display display);
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|
Loading…
Reference in a new issue