mercurial/osutil.c
changeset 13734 16118b4859a1
parent 13302 a4e0908ce35b
child 13736 f3c4421e121c
--- a/mercurial/osutil.c	Wed Mar 23 01:14:43 2011 +0100
+++ b/mercurial/osutil.c	Wed Mar 23 09:43:34 2011 +0100
@@ -514,6 +514,22 @@
 }
 #endif
 
+#ifdef __APPLE__
+#import <ApplicationServices/ApplicationServices.h>
+
+static PyObject *isgui(PyObject *self)
+{
+    CFDictionaryRef dict = CGSessionCopyCurrentDictionary();
+
+    if (dict != NULL) {
+        CFRelease(dict);
+        return Py_True;
+    } else {
+        return Py_False;
+    }
+}
+#endif
+
 static char osutil_doc[] = "Native operating system services.";
 
 static PyMethodDef methods[] = {
@@ -524,6 +540,12 @@
 	 "Open a file with POSIX-like semantics.\n"
 "On error, this function may raise either a WindowsError or an IOError."},
 #endif
+#ifdef __APPLE__
+    {
+        "isgui", (PyCFunction)isgui, METH_NOARGS,
+        "Is a CoreGraphics session available?"
+    },
+#endif
 	{NULL, NULL}
 };