diff --git a/src/CoreGraphics/CGSession.cs b/src/CoreGraphics/CGSession.cs
new file mode 100644
index 000000000000..f4fdfe29ae6a
--- /dev/null
+++ b/src/CoreGraphics/CGSession.cs
@@ -0,0 +1,58 @@
+#if NET
+#if __MACOS__ || __MACCATALYST__
+
+using System.Runtime.InteropServices;
+
+using Foundation;
+using ObjCRuntime;
+
+namespace CoreGraphics {
+
+ [SupportedOSPlatform ("maccatalyst")]
+ [SupportedOSPlatform ("macos")]
+ [UnsupportedOSPlatform ("ios")]
+ [UnsupportedOSPlatform ("tvos")]
+ public static class CGSession {
+ [DllImport (Constants.CoreGraphicsLibrary)]
+ extern static /* CFDictionaryRef __nullable */ IntPtr CGSessionCopyCurrentDictionary ();
+
+ /// Get the properties for the current window server session.
+ /// The properties for the current window server session.
+ /// Returns null if the caller is not running in a Quartz GUI session or the window server is disabled.
+ public static CGSessionProperties? GetProperties ()
+ {
+ var handle = CGSessionCopyCurrentDictionary ();
+ if (handle == IntPtr.Zero)
+ return null;
+ var dict = Runtime.GetNSObject (handle, owns: true);
+ return new CGSessionProperties (dict);
+ }
+ }
+
+ // This looks like it should be in an api definition bound using [Field] attributes,
+ // but these aren't actual native fields, in the headers they're declared as constants:
+ // #define kCGSession*Key @"SomeStringValue"
+ [SupportedOSPlatform ("maccatalyst")]
+ [SupportedOSPlatform ("macos")]
+ [UnsupportedOSPlatform ("ios")]
+ [UnsupportedOSPlatform ("tvos")]
+ public static class CGSessionKeys {
+ /// A key for the user ID for the session's current user.
+ public static NSString UserIdKey { get => (NSString) "kCGSSessionUserIDKey"; }
+
+ /// A key for the short user name for the session's current user.
+ public static NSString UserNameKey { get => (NSString) "kCGSSessionUserNameKey"; }
+
+ /// A key for the set of hardware composing a console for the session's current user.
+ public static NSString ConsoleSetKey { get => (NSString) "kCGSSessionConsoleSetKey"; }
+
+ /// A key for indicating whether the session's on a console.
+ public static NSString OnConsoleKey { get => (NSString) "kCGSSessionOnConsoleKey"; }
+
+ /// A key for indicating whether the session's login operation has been don
+ public static NSString LoginDoneKey { get => (NSString) "kCGSessionLoginDoneKey"; }
+ }
+}
+
+#endif // __MACOS__ || __MACCATALYST__
+#endif // NET
diff --git a/src/coregraphics.cs b/src/coregraphics.cs
index 2c643830b8ad..cb6db64df0b4 100644
--- a/src/coregraphics.cs
+++ b/src/coregraphics.cs
@@ -504,4 +504,16 @@ interface CGDisplayStreamYCbCrMatrixOptionKeys {
[Field ("kCGDisplayStreamYCbCrMatrix_SMPTE_240M_1995")]
NSString Smpte_240M_1995 { get; }
}
+
+#if NET
+ [NoiOS, NoTV, NoWatch, MacCatalyst (13, 1)]
+ [StrongDictionary ("CGSessionKeys")]
+ interface CGSessionProperties {
+ uint UserId { get; }
+ string UserName { get; }
+ uint ConsoleSet { get; }
+ bool OnConsole { get; }
+ bool LoginDone { get; }
+ }
+#endif
}
diff --git a/src/frameworks.sources b/src/frameworks.sources
index b9561a58abb1..a6e2309c3452 100644
--- a/src/frameworks.sources
+++ b/src/frameworks.sources
@@ -546,6 +546,7 @@ COREGRAPHICS_SOURCES = \
CoreGraphics/CGPDFStream.cs \
CoreGraphics/CGPDFString.cs \
CoreGraphics/CGPdfTagType.cs \
+ CoreGraphics/CGSession.cs \
CoreGraphics/CGShading.cs \
CoreGraphics/NativeDrawingMethods.cs \
diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt
index 72f9e2975083..e0f98bc2b7b2 100644
--- a/tests/cecil-tests/Documentation.KnownFailures.txt
+++ b/tests/cecil-tests/Documentation.KnownFailures.txt
@@ -30269,6 +30269,8 @@ M:CoreGraphics.CGRectExtensions.IsInfinite(CoreGraphics.CGRect)
M:CoreGraphics.CGRectExtensions.IsNull(CoreGraphics.CGRect)
M:CoreGraphics.CGRectExtensions.Standardize(CoreGraphics.CGRect)
M:CoreGraphics.CGRectExtensions.UnionWith(CoreGraphics.CGRect,CoreGraphics.CGRect)
+M:CoreGraphics.CGSessionProperties.#ctor
+M:CoreGraphics.CGSessionProperties.#ctor(Foundation.NSDictionary)
M:CoreGraphics.CGShading.CreateAxial(CoreGraphics.CGColorSpace,CoreGraphics.CGPoint,CoreGraphics.CGPoint,CoreGraphics.CGFunction,System.Boolean,System.Boolean)
M:CoreGraphics.CGShading.CreateRadial(CoreGraphics.CGColorSpace,CoreGraphics.CGPoint,System.Runtime.InteropServices.NFloat,CoreGraphics.CGPoint,System.Runtime.InteropServices.NFloat,CoreGraphics.CGFunction,System.Boolean,System.Boolean)
M:CoreGraphics.CGShading.Release
@@ -59868,6 +59870,11 @@ P:CoreGraphics.CGRect.Top
P:CoreGraphics.CGRect.Width
P:CoreGraphics.CGRect.X
P:CoreGraphics.CGRect.Y
+P:CoreGraphics.CGSessionProperties.ConsoleSet
+P:CoreGraphics.CGSessionProperties.LoginDone
+P:CoreGraphics.CGSessionProperties.OnConsole
+P:CoreGraphics.CGSessionProperties.UserId
+P:CoreGraphics.CGSessionProperties.UserName
P:CoreGraphics.CGSize.Height
P:CoreGraphics.CGSize.IsEmpty
P:CoreGraphics.CGSize.Width
@@ -78125,6 +78132,9 @@ T:CoreGraphics.CGRect
T:CoreGraphics.CGRectEdge
T:CoreGraphics.CGRectExtensions
T:CoreGraphics.CGScrollEventUnit
+T:CoreGraphics.CGSession
+T:CoreGraphics.CGSessionKeys
+T:CoreGraphics.CGSessionProperties
T:CoreGraphics.CGShading
T:CoreGraphics.CGSize
T:CoreGraphics.CGVector
diff --git a/tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs b/tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs
index 2a4046d47c6a..02cd13d7882e 100644
--- a/tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs
+++ b/tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs
@@ -13,6 +13,17 @@ namespace MonoTouchFixtures.CoreVideo {
[Preserve (AllMembers = true)]
public class CVDisplayLinkTest {
+ void IgnoreIfLockedScreen ()
+ {
+#if NET
+ var props = CGSession.GetProperties ();
+ var value = props.Dictionary [(NSString) "CGSSessionScreenIsLocked"]; // This key isn't documented, so no binding for it.
+ var isLocked = (value as NSNumber)?.BoolValue;
+ if (isLocked == true)
+ Assert.Ignore ("The screen is locked.");
+#endif
+ }
+
[Test]
public void CreateFromDisplayIdValidIdTest ()
{
@@ -61,6 +72,7 @@ public void CreateFromOpenGLMaskTest ()
public void DefaultConstructorTest ()
{
TestRuntime.AssertNotVSTS ();
+ IgnoreIfLockedScreen ();
Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
});
@@ -70,6 +82,7 @@ public void DefaultConstructorTest ()
public void SetCurrentDisplayOpenGLTest ()
{
TestRuntime.AssertNotVSTS ();
+ IgnoreIfLockedScreen ();
Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
displayLink.SetCurrentDisplay (CGDisplay.MainDisplayID);
@@ -80,6 +93,7 @@ public void SetCurrentDisplayOpenGLTest ()
public void GetCurrentDisplayTest ()
{
TestRuntime.AssertNotVSTS ();
+ IgnoreIfLockedScreen ();
Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
Assert.AreEqual (CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay ());
@@ -100,6 +114,7 @@ public void TryTranslateTimeValidTest ()
{
TestRuntime.AssertNotVSTS ();
TestRuntime.AssertSystemVersion (ApplePlatform.MacOSX, 12, 0);
+ IgnoreIfLockedScreen ();
var outTime = new CVTimeStamp {
Version = 0,
Flags = (1L << 0) | (1L << 1), // kCVTimeStampVideoTimeValid | kCVTimeStampHostTimeValid
diff --git a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore
index e0198271018d..00fa76c91b80 100644
--- a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore
+++ b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore
@@ -90,7 +90,6 @@
!missing-pinvoke! CGReleaseDisplayFadeReservation is not bound
!missing-pinvoke! CGRequestScreenCaptureAccess is not bound
!missing-pinvoke! CGRestorePermanentDisplayConfiguration is not bound
-!missing-pinvoke! CGSessionCopyCurrentDictionary is not bound
!missing-pinvoke! CGSetDisplayTransferByByteTable is not bound
!missing-pinvoke! CGSetDisplayTransferByTable is not bound
!missing-pinvoke! CGWarpMouseCursorPosition is not bound
diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore
index 12d3eabcc157..e73b7d078547 100644
--- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore
+++ b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore
@@ -87,7 +87,6 @@
!missing-pinvoke! CGPSConverterIsConverting is not bound
!missing-pinvoke! CGReleaseDisplayFadeReservation is not bound
!missing-pinvoke! CGRestorePermanentDisplayConfiguration is not bound
-!missing-pinvoke! CGSessionCopyCurrentDictionary is not bound
!missing-pinvoke! CGSetDisplayTransferByByteTable is not bound
!missing-pinvoke! CGSetDisplayTransferByTable is not bound
!missing-pinvoke! CGWarpMouseCursorPosition is not bound