diff mercurial/osutil.c @ 13734:16118b4859a1

util: add Mac-specific check whether we're in a GUI session (issue2553) The previous test assumed that 'os.name' was "mac" on Mac OS X. This is not the case; 'mac' was classic Mac OS, whereas Mac OS X has 'os.name' be 'posix'. Please note that this change will break Mercurial on hypothetical non-Mac OS X deployments of Darwin. Credit to Brodie Rao for thinking of CGSessionCopyCurrentDictionary() and Kevin Bullock for testing.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Wed, 23 Mar 2011 09:43:34 +0100
parents a4e0908ce35b
children f3c4421e121c
line wrap: on
line diff
--- 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}
 };