2 * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2008 David Robillard <d@drobilla.net>
4 * Copyright (C) 2014-2016 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <pbd/error.h>
25 #include <gtkmm2ext/gtkapplication.h>
26 #include <gdk/gdkquartz.h>
34 #include "ardour_ui.h"
38 #include <CoreFoundation/CFLocale.h>
39 #import <CoreFoundation/CFString.h>
40 #import <Foundation/NSString.h>
41 #import <Foundation/NSAutoreleasePool.h>
47 cocoa_open_url (const char* uri)
49 NSString* struri = [[NSString alloc] initWithUTF8String:uri];
50 NSURL* nsurl = [[NSURL alloc] initWithString:struri];
52 bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
61 set_language_preference ()
63 gtk_disable_setlocale ();
65 /* the gettext manual is potentially misleading about the utility of
66 LANGUAGE. It notes that if LANGUAGE is set to include a dialect/region-free
67 language code, like "it", it will assume that you mean the main
68 dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for
69 locale dirs with the full name, only the short code (it doesn't
72 Since Apple's preferred language list only consists of short language codes,
73 if we set LANGUAGE then gettext will not look for the relevant long-form
77 /* how to get language preferences with CoreFoundation
80 NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
82 /* push into LANGUAGE */
84 if (languages && [languages count] > 0) {
86 int i, count = [languages count];
87 for (i = 0; i < count; ++i) {
88 if ([[languages objectAtIndex:i]
89 isEqualToString:@"en"]) {
94 NSRange r = { 0, static_cast<NSUInteger> (count) };
95 setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0);
96 cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl;
99 /* now get AppleLocale value and use that for LANG */
101 CFLocaleRef cflocale = CFLocaleCopyCurrent();
102 NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
104 /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
107 cout << "LANG set to " << [nslocale UTF8String] << endl;
108 setenv ("LANG", [nslocale UTF8String], 0);
109 CFRelease (cflocale);
112 /* Prevent "App Nap" */
118 #ifndef NSActivityLatencyCritical
119 #define NSActivityLatencyCritical 0xFF00000000ULL
122 if ( [ [ NSProcessInfo processInfo ] respondsToSelector:@selector(beginActivityWithOptions:reason:) ] ) {
123 cout << "Disabling MacOS AppNap\n";
124 [ [ NSProcessInfo processInfo] beginActivityWithOptions:NSActivityLatencyCritical reason:@"realtime audio" ];