##// END OF EJS Templates
util: add Mac-specific check whether we're in a GUI session (issue2553)...
Dan Villiom Podlaski Christiansen -
r13734:16118b48 default
parent child Browse files
Show More
@@ -514,6 +514,22 b' bail:'
514 }
514 }
515 #endif
515 #endif
516
516
517 #ifdef __APPLE__
518 #import <ApplicationServices/ApplicationServices.h>
519
520 static PyObject *isgui(PyObject *self)
521 {
522 CFDictionaryRef dict = CGSessionCopyCurrentDictionary();
523
524 if (dict != NULL) {
525 CFRelease(dict);
526 return Py_True;
527 } else {
528 return Py_False;
529 }
530 }
531 #endif
532
517 static char osutil_doc[] = "Native operating system services.";
533 static char osutil_doc[] = "Native operating system services.";
518
534
519 static PyMethodDef methods[] = {
535 static PyMethodDef methods[] = {
@@ -524,6 +540,12 b' static PyMethodDef methods[] = {'
524 "Open a file with POSIX-like semantics.\n"
540 "Open a file with POSIX-like semantics.\n"
525 "On error, this function may raise either a WindowsError or an IOError."},
541 "On error, this function may raise either a WindowsError or an IOError."},
526 #endif
542 #endif
543 #ifdef __APPLE__
544 {
545 "isgui", (PyCFunction)isgui, METH_NOARGS,
546 "Is a CoreGraphics session available?"
547 },
548 #endif
527 {NULL, NULL}
549 {NULL, NULL}
528 };
550 };
529
551
@@ -769,7 +769,18 b' def splitpath(path):'
769
769
770 def gui():
770 def gui():
771 '''Are we running in a GUI?'''
771 '''Are we running in a GUI?'''
772 return os.name == "nt" or os.name == "mac" or os.environ.get("DISPLAY")
772 if sys.platform == 'darwin':
773 if 'SSH_CONNECTION' in os.environ:
774 # handle SSH access to a box where the user is logged in
775 return False
776 elif getattr(osutil, 'isgui', None):
777 # check if a CoreGraphics session is available
778 return osutil.isgui()
779 else:
780 # pure build; use a safe default
781 return True
782 else:
783 return os.name == "nt" or os.environ.get("DISPLAY")
773
784
774 def mktempcopy(name, emptyok=False, createmode=None):
785 def mktempcopy(name, emptyok=False, createmode=None):
775 """Create a temporary file with the same contents from name
786 """Create a temporary file with the same contents from name
@@ -314,11 +314,17 b' extmodules = ['
314 Extension('mercurial.parsers', ['mercurial/parsers.c']),
314 Extension('mercurial.parsers', ['mercurial/parsers.c']),
315 ]
315 ]
316
316
317 osutil_ldflags = []
318
319 if sys.platform == 'darwin':
320 osutil_ldflags += ['-framework', 'ApplicationServices']
321
317 # disable osutil.c under windows + python 2.4 (issue1364)
322 # disable osutil.c under windows + python 2.4 (issue1364)
318 if sys.platform == 'win32' and sys.version_info < (2, 5, 0, 'final'):
323 if sys.platform == 'win32' and sys.version_info < (2, 5, 0, 'final'):
319 pymodules.append('mercurial.pure.osutil')
324 pymodules.append('mercurial.pure.osutil')
320 else:
325 else:
321 extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
326 extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'],
327 extra_link_args=osutil_ldflags))
322
328
323 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
329 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
324 # The inotify extension is only usable with Linux 2.6 kernels.
330 # The inotify extension is only usable with Linux 2.6 kernels.
General Comments 0
You need to be logged in to leave comments. Login now