Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <Carbon/Carbon.h>
-#undef check // stupid, stupid carbon
-#undef YES // stupid, stupid gtkmm and/or NSObjC
-#undef NO // ditto
+#include <string>
+#include <ctype.h>
+#include <stdlib.h>
+#include <pbd/error.h>
+#include <gtkmm2ext/gtkapplication.h>
+#include <gdk/gdkquartz.h>
+#undef check
+#undef YES
+#undef NO
+#ifdef verify
+#undef verify
+#endif
#include "ardour_ui.h"
#include "actions.h"
#include "opts.h"
-#include <gtkmm2ext/sync-menu.h>
-#include <Appkit/Appkit.h>
+#include <CoreFoundation/CFLocale.h>
+#import <CoreFoundation/CFString.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSAutoreleasePool.h>
-sigc::signal<void,bool> ApplicationActivationChanged;
-static EventHandlerRef application_event_handler_ref;
+using namespace std;
+using namespace PBD;
-/* Called for clicks on the dock icon. Can be used to unminimize or
- * create a new window for example.
- */
-
-static OSErr
-handle_reopen_application (const AppleEvent *inAppleEvent,
- AppleEvent *outAppleEvent,
- long inHandlerRefcon)
+bool
+cocoa_open_url (const char* uri)
{
- cerr << "reopen app\n";
- return noErr;
-}
+ NSString* struri = [[NSString alloc] initWithUTF8String:uri];
+ NSURL* nsurl = [[NSURL alloc] initWithString:struri];
-static OSErr
-handle_quit_application (const AppleEvent *inAppleEvent,
- AppleEvent *outAppleEvent,
- long inHandlerRefcon)
-{
- cerr << "quit app\n";
- ARDOUR_UI::instance()->quit ();
+ bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
- return noErr;
-}
+ [struri release];
+ [nsurl release];
-static OSStatus
-application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData)
-{
- UInt32 eventKind = GetEventKind (event);
-
- switch (eventKind) {
- case kEventAppActivated:
- ApplicationActivationChanged (true); // EMIT SIGNAL
- return eventNotHandledErr;
-
- case kEventAppDeactivated:
- ApplicationActivationChanged (false); // EMIT SIGNAL
- return eventNotHandledErr;
-
- default:
- // pass-thru all kEventClassApplication events we're not interested in.
- break;
- }
- return eventNotHandledErr;
+ return ret;
}
void
-ARDOUR_UI::platform_specific ()
+set_language_preference ()
{
- AEInstallEventHandler (kCoreEventClass, kAEReopenApplication,
- handle_reopen_application, 0, true);
-
- AEInstallEventHandler (kCoreEventClass, kAEQuitApplication,
- handle_quit_application, 0, true);
-
- Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit");
- if (widget) {
- ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj());
+ gtk_disable_setlocale ();
+
+ /* the gettext manual is potentially misleading about the utility of
+ LANGUAGE. It notes that if LANGUAGE is set to include a dialect/region-free
+ language code, like "it", it will assume that you mean the main
+ dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for
+ locale dirs with the full name, only the short code (it doesn't
+ know any better).
+
+ Since Apple's preferred language list only consists of short language codes,
+ if we set LANGUAGE then gettext will not look for the relevant long-form
+ variants.
+ */
+
+ /* how to get language preferences with CoreFoundation
+ */
+
+ NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
+
+ /* push into LANGUAGE */
+
+ if (languages && [languages count] > 0) {
+
+ int i, count = [languages count];
+ for (i = 0; i < count; ++i) {
+ if ([[languages objectAtIndex:i]
+ isEqualToString:@"en"]) {
+ count = i+1;
+ break;
+ }
+ }
+ NSRange r = { 0, static_cast<NSUInteger> (count) };
+ setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0);
+ cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl;
}
- IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group ();
+ /* now get AppleLocale value and use that for LANG */
- widget = ActionManager::get_widget ("/ui/Main/Session/About");
- if (widget) {
- ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
- }
- widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor");
- if (widget) {
- ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
- }
+ CFLocaleRef cflocale = CFLocaleCopyCurrent();
+ NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
- EventTypeSpec applicationEventTypes[] = {
- {kEventClassApplication, kEventAppActivated },
- {kEventClassApplication, kEventAppDeactivated }
- };
-
- EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler);
-
- InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec),
- applicationEventTypes, 0, &application_event_handler_ref);
+ /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
+ */
+
+ cout << "LANG set to " << [nslocale UTF8String] << endl;
+ setenv ("LANG", [nslocale UTF8String], 0);
+ CFRelease (cflocale);
}
+ /* Prevent "App Nap" */
+
void
-ARDOUR_UI::platform_setup ()
+no_app_nap ()
{
- if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
-
- /* if invoked from the command line, make sure we're visible */
-
- [NSApp activateIgnoringOtherApps:1];
- }
+
+#ifndef NSActivityLatencyCritical
+#define NSActivityLatencyCritical 0xFF00000000ULL
+#endif
+
+ if ( [ [ NSProcessInfo processInfo ] respondsToSelector:@selector(beginActivityWithOptions:reason:) ] ) {
+ cout << "Disabling MacOS AppNap\n";
+ [ [ NSProcessInfo processInfo] beginActivityWithOptions:NSActivityLatencyCritical reason:@"realtime audio" ];
+ }
}