2010-11-23 12:42:19 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-10 01:25:52 +01:00
|
|
|
Copyright 2010-2011, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2010-2012, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
2010-11-23 12:42:19 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-04-27 20:44:19 +02:00
|
|
|
#import <AppKit/NSApplication.h>
|
2011-05-30 12:09:34 +02:00
|
|
|
#import <AppKit/NSEvent.h>
|
|
|
|
#import <AppKit/NSGraphics.h>
|
|
|
|
#import <AppKit/NSNibDeclarations.h>
|
|
|
|
#import <AppKit/NSViewController.h>
|
2010-04-27 20:44:19 +02:00
|
|
|
|
2010-04-15 17:23:12 +02:00
|
|
|
#import <Foundation/NSBundle.h>
|
2010-12-09 13:34:08 +01:00
|
|
|
#import <Foundation/NSError.h>
|
|
|
|
#import <Foundation/NSFileManager.h>
|
2010-12-06 18:06:02 +01:00
|
|
|
#import <Foundation/NSPathUtilities.h>
|
2010-12-09 13:34:08 +01:00
|
|
|
#import <Foundation/NSThread.h>
|
2010-04-15 17:23:12 +02:00
|
|
|
#import <Foundation/NSTimer.h>
|
|
|
|
#import <Foundation/NSURL.h>
|
2011-05-30 12:09:34 +02:00
|
|
|
|
|
|
|
#import <IOKit/hidsystem/ev_keymap.h>
|
2010-04-15 17:23:12 +02:00
|
|
|
|
2010-06-17 22:31:34 +02:00
|
|
|
#import <Kernel/AvailabilityMacros.h>
|
|
|
|
|
2011-05-30 12:09:34 +02:00
|
|
|
#import <QuartzCore/CALayer.h>
|
|
|
|
|
2011-11-10 20:56:49 +01:00
|
|
|
#import "3rdparty/SPMediaKeyTap/SPMediaKeyTap.h"
|
2011-05-30 12:09:34 +02:00
|
|
|
|
2010-06-18 13:41:16 +02:00
|
|
|
#include "config.h"
|
2010-05-11 14:51:31 +02:00
|
|
|
#include "globalshortcuts.h"
|
2011-02-04 16:25:05 +01:00
|
|
|
#include "mac_delegate.h"
|
2010-04-13 15:55:54 +02:00
|
|
|
#include "mac_startup.h"
|
2011-09-01 15:10:30 +02:00
|
|
|
#include "mac_utilities.h"
|
2010-06-17 22:31:34 +02:00
|
|
|
#include "macglobalshortcutbackend.h"
|
2010-12-09 13:34:08 +01:00
|
|
|
#include "utilities.h"
|
2011-04-22 18:50:29 +02:00
|
|
|
#include "core/logging.h"
|
2012-01-21 00:46:33 +01:00
|
|
|
#include "core/scoped_cftyperef.h"
|
2012-01-31 13:54:03 +01:00
|
|
|
#include "core/scoped_nsautorelease_pool.h"
|
2010-04-13 15:55:54 +02:00
|
|
|
|
2010-12-14 19:20:14 +01:00
|
|
|
#ifdef HAVE_SPARKLE
|
|
|
|
#import <Sparkle/SUUpdater.h>
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 14:56:17 +02:00
|
|
|
#include <QApplication>
|
2010-04-14 23:27:27 +02:00
|
|
|
#include <QCoreApplication>
|
2010-12-09 13:34:08 +01:00
|
|
|
#include <QDir>
|
2010-04-14 23:27:27 +02:00
|
|
|
#include <QEvent>
|
2010-12-09 13:34:08 +01:00
|
|
|
#include <QFile>
|
2011-02-16 14:43:01 +01:00
|
|
|
#include <QSettings>
|
2012-10-09 14:56:17 +02:00
|
|
|
#include <QWidget>
|
2010-06-14 15:22:45 +02:00
|
|
|
|
|
|
|
#include <QtDebug>
|
2010-04-14 23:27:27 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
QDebug operator<<(QDebug dbg, NSObject* object) {
|
|
|
|
QString ns_format = [[NSString stringWithFormat:@"%@", object] UTF8String];
|
2012-03-12 17:09:22 +01:00
|
|
|
dbg.nospace() << ns_format;
|
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
|
2010-04-13 15:55:54 +02:00
|
|
|
// Capture global media keys on Mac (Cocoa only!)
|
2014-01-30 14:48:49 +01:00
|
|
|
// See:
|
|
|
|
// http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/
|
2010-04-13 15:55:54 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
@interface MacApplication : NSApplication {
|
2010-06-14 15:22:45 +02:00
|
|
|
PlatformInterface* application_handler_;
|
2011-05-30 12:09:34 +02:00
|
|
|
AppDelegate* delegate_;
|
|
|
|
// shortcut_handler_ only used to temporarily save it
|
|
|
|
// AppDelegate does all the heavy-shortcut-lifting
|
|
|
|
MacGlobalShortcutBackend* shortcut_handler_;
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (MacGlobalShortcutBackend*)shortcut_handler;
|
|
|
|
- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler;
|
2010-04-14 23:27:27 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (PlatformInterface*)application_handler;
|
|
|
|
- (void)SetApplicationHandler:(PlatformInterface*)handler;
|
2010-04-13 15:55:54 +02:00
|
|
|
|
2010-04-27 20:44:19 +02:00
|
|
|
@end
|
2010-04-14 23:27:27 +02:00
|
|
|
|
2011-03-26 18:36:13 +01:00
|
|
|
#ifdef HAVE_BREAKPAD
|
2014-01-30 14:48:49 +01:00
|
|
|
static bool BreakpadCallback(int, int, mach_port_t, void*) { return true; }
|
2011-03-25 12:38:03 +01:00
|
|
|
|
|
|
|
static BreakpadRef InitBreakpad() {
|
2012-01-31 13:54:03 +01:00
|
|
|
ScopedNSAutoreleasePool pool;
|
2011-03-25 12:38:03 +01:00
|
|
|
BreakpadRef breakpad = nil;
|
|
|
|
NSDictionary* plist = [[NSBundle mainBundle] infoDictionary];
|
|
|
|
if (plist) {
|
|
|
|
breakpad = BreakpadCreate(plist);
|
2014-02-21 17:24:49 +01:00
|
|
|
BreakpadSetFilterCallback(breakpad, &BreakpadCallback, nullptr);
|
2011-03-25 12:38:03 +01:00
|
|
|
}
|
|
|
|
[pool release];
|
|
|
|
return breakpad;
|
|
|
|
}
|
2014-01-30 14:48:49 +01:00
|
|
|
#endif // HAVE_BREAKPAD
|
2011-03-25 12:38:03 +01:00
|
|
|
|
2010-04-27 20:44:19 +02:00
|
|
|
@implementation AppDelegate
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (id)init {
|
2010-04-27 20:44:19 +02:00
|
|
|
if ((self = [super init])) {
|
|
|
|
application_handler_ = nil;
|
2011-05-30 12:09:34 +02:00
|
|
|
shortcut_handler_ = nil;
|
2010-06-22 16:09:13 +02:00
|
|
|
dock_menu_ = nil;
|
2010-04-27 20:44:19 +02:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (id)initWithHandler:(PlatformInterface*)handler {
|
2010-04-27 20:44:19 +02:00
|
|
|
application_handler_ = handler;
|
2011-03-26 18:36:13 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_BREAKPAD
|
2011-03-25 12:38:03 +01:00
|
|
|
breakpad_ = InitBreakpad();
|
2011-03-26 18:36:13 +01:00
|
|
|
#endif
|
|
|
|
|
2011-05-30 12:09:34 +02:00
|
|
|
// Register defaults for the whitelist of apps that want to use media keys
|
2014-01-30 14:48:49 +01:00
|
|
|
[[NSUserDefaults standardUserDefaults]
|
|
|
|
registerDefaults:
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:
|
|
|
|
[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers],
|
|
|
|
kMediaKeyUsingBundleIdentifiersDefaultsKey, nil]];
|
2010-04-27 20:44:19 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication*)app
|
|
|
|
hasVisibleWindows:(BOOL)flag {
|
2010-04-27 20:44:19 +02:00
|
|
|
if (application_handler_) {
|
2010-06-14 15:22:45 +02:00
|
|
|
application_handler_->Activate();
|
2010-04-27 20:44:19 +02:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
2010-06-14 15:22:45 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)setDockMenu:(NSMenu*)menu {
|
2010-06-22 16:09:13 +02:00
|
|
|
dock_menu_ = menu;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
2010-06-22 16:09:13 +02:00
|
|
|
return dock_menu_;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)setShortcutHandler:(MacGlobalShortcutBackend*)backend {
|
2011-05-30 12:09:34 +02:00
|
|
|
shortcut_handler_ = backend;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (MacGlobalShortcutBackend*)shortcut_handler {
|
2011-05-30 12:09:34 +02:00
|
|
|
return shortcut_handler_;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
|
2011-05-30 12:09:34 +02:00
|
|
|
key_tap_ = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
2014-01-30 14:48:49 +01:00
|
|
|
if ([SPMediaKeyTap usesGlobalMediaKeyTap])
|
2011-05-30 12:09:34 +02:00
|
|
|
[key_tap_ startWatchingMediaKeys];
|
|
|
|
else
|
2014-01-30 14:48:49 +01:00
|
|
|
qLog(Warning) << "Media key monitoring disabled";
|
2011-05-30 12:09:34 +02:00
|
|
|
}
|
2012-03-12 16:49:19 +01:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (BOOL)application:(NSApplication*)app openFile:(NSString*)filename {
|
2012-03-12 17:11:07 +01:00
|
|
|
qLog(Debug) << "Wants to open:" << [filename UTF8String];
|
2010-06-14 15:22:45 +02:00
|
|
|
|
|
|
|
if (application_handler_->LoadUrl(QString::fromUtf8([filename UTF8String]))) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2011-03-25 12:38:03 +01:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)application:(NSApplication*)app openFiles:(NSArray*)filenames {
|
2012-03-12 17:09:22 +01:00
|
|
|
qLog(Debug) << "Wants to open:" << filenames;
|
2014-01-30 14:48:49 +01:00
|
|
|
[filenames
|
|
|
|
enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL* stop) {
|
|
|
|
[self application:app openFile:(NSString*)object];
|
|
|
|
}];
|
2012-03-12 16:49:19 +01:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)mediaKeyTap:(SPMediaKeyTap*)keyTap
|
|
|
|
receivedMediaKeyEvent:(NSEvent*)event {
|
|
|
|
NSAssert([event type] == NSSystemDefined &&
|
|
|
|
[event subtype] == SPSystemDefinedEventMediaKeys,
|
|
|
|
@"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:");
|
2011-05-30 12:09:34 +02:00
|
|
|
|
|
|
|
int key_code = (([event data1] & 0xFFFF0000) >> 16);
|
|
|
|
int key_flags = ([event data1] & 0x0000FFFF);
|
2011-06-13 12:20:37 +02:00
|
|
|
BOOL key_is_released = (((key_flags & 0xFF00) >> 8)) == 0xB;
|
2011-05-30 12:09:34 +02:00
|
|
|
// not used. keep just in case
|
|
|
|
// int key_repeat = (key_flags & 0x1);
|
|
|
|
|
|
|
|
if (!shortcut_handler_) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-13 12:20:37 +02:00
|
|
|
if (key_is_released) {
|
2011-05-30 12:09:34 +02:00
|
|
|
shortcut_handler_->MacMediaKeyPressed(key_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:
|
|
|
|
(NSApplication*)sender {
|
2011-03-26 18:36:13 +01:00
|
|
|
#ifdef HAVE_BREAKPAD
|
2011-03-25 12:38:03 +01:00
|
|
|
BreakpadRelease(breakpad_);
|
2011-03-26 18:36:13 +01:00
|
|
|
#endif
|
2011-03-25 12:38:03 +01:00
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
2012-09-13 16:15:28 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (BOOL)userNotificationCenter:(id)center
|
|
|
|
shouldPresentNotification:(id)notification {
|
2012-09-13 16:15:28 +02:00
|
|
|
// Always show notifications, even if Clementine is in the foreground.
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-04-27 20:44:19 +02:00
|
|
|
@end
|
|
|
|
|
2010-04-13 15:55:54 +02:00
|
|
|
@implementation MacApplication
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (id)init {
|
2010-04-13 15:55:54 +02:00
|
|
|
if ((self = [super init])) {
|
2010-04-14 23:27:27 +02:00
|
|
|
[self SetShortcutHandler:nil];
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (MacGlobalShortcutBackend*)shortcut_handler {
|
2011-05-30 12:09:34 +02:00
|
|
|
// should be the same as delegate_'s shortcut handler
|
2010-04-14 23:27:27 +02:00
|
|
|
return shortcut_handler_;
|
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler {
|
2010-04-14 23:27:27 +02:00
|
|
|
shortcut_handler_ = handler;
|
2014-01-30 14:48:49 +01:00
|
|
|
if (delegate_) [delegate_ setShortcutHandler:handler];
|
2010-04-14 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (PlatformInterface*)application_handler {
|
2010-04-14 23:27:27 +02:00
|
|
|
return application_handler_;
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)SetApplicationHandler:(PlatformInterface*)handler {
|
2011-05-30 12:09:34 +02:00
|
|
|
delegate_ = [[AppDelegate alloc] initWithHandler:handler];
|
|
|
|
// App-shortcut-handler set before delegate is set.
|
|
|
|
// this makes sure the delegate's shortcut_handler is set
|
|
|
|
[delegate_ setShortcutHandler:shortcut_handler_];
|
|
|
|
[self setDelegate:delegate_];
|
2012-09-13 16:15:28 +02:00
|
|
|
|
2015-02-18 18:03:05 +01:00
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
|
|
|
setDelegate:delegate_];
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
- (void)sendEvent:(NSEvent*)event {
|
2011-05-30 12:09:34 +02:00
|
|
|
// If event tap is not installed, handle events that reach the app instead
|
2014-01-30 14:48:49 +01:00
|
|
|
BOOL shouldHandleMediaKeyEventLocally =
|
|
|
|
![SPMediaKeyTap usesGlobalMediaKeyTap];
|
2012-09-13 16:15:28 +02:00
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
if (shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined &&
|
|
|
|
[event subtype] == SPSystemDefinedEventMediaKeys) {
|
|
|
|
[(id)[self delegate] mediaKeyTap:nil receivedMediaKeyEvent:event];
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 14:48:49 +01:00
|
|
|
[super sendEvent:event];
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace mac {
|
|
|
|
|
|
|
|
void MacMain() {
|
2012-01-31 13:54:03 +01:00
|
|
|
ScopedNSAutoreleasePool pool;
|
2010-04-13 15:55:54 +02:00
|
|
|
// Creates and sets the magic global variable so QApplication will find it.
|
|
|
|
[MacApplication sharedApplication];
|
2014-01-30 14:48:49 +01:00
|
|
|
#ifdef HAVE_SPARKLE
|
|
|
|
// Creates and sets the magic global variable for Sparkle.
|
|
|
|
[[SUUpdater sharedUpdater] setDelegate:NSApp];
|
|
|
|
#endif
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2010-06-17 22:31:34 +02:00
|
|
|
void SetShortcutHandler(MacGlobalShortcutBackend* handler) {
|
2014-01-30 14:48:49 +01:00
|
|
|
[NSApp SetShortcutHandler:handler];
|
2010-04-14 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-14 15:22:45 +02:00
|
|
|
void SetApplicationHandler(PlatformInterface* handler) {
|
2014-01-30 14:48:49 +01:00
|
|
|
[NSApp SetApplicationHandler:handler];
|
2010-04-13 15:55:54 +02:00
|
|
|
}
|
|
|
|
|
2010-04-15 17:23:12 +02:00
|
|
|
void CheckForUpdates() {
|
2014-01-30 14:48:49 +01:00
|
|
|
#ifdef HAVE_SPARKLE
|
|
|
|
[[SUUpdater sharedUpdater] checkForUpdates:NSApp];
|
|
|
|
#endif
|
2010-04-15 17:23:12 +02:00
|
|
|
}
|
|
|
|
|
2010-06-07 11:49:20 +02:00
|
|
|
QString GetBundlePath() {
|
2014-01-30 14:48:49 +01:00
|
|
|
ScopedCFTypeRef<CFURLRef> app_url(
|
|
|
|
CFBundleCopyBundleURL(CFBundleGetMainBundle()));
|
|
|
|
ScopedCFTypeRef<CFStringRef> mac_path(
|
|
|
|
CFURLCopyFileSystemPath(app_url.get(), kCFURLPOSIXPathStyle));
|
|
|
|
const char* path =
|
|
|
|
CFStringGetCStringPtr(mac_path.get(), CFStringGetSystemEncoding());
|
2010-06-07 11:49:20 +02:00
|
|
|
QString bundle_path = QString::fromUtf8(path);
|
|
|
|
return bundle_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GetResourcesPath() {
|
|
|
|
QString bundle_path = GetBundlePath();
|
|
|
|
return bundle_path + "/Contents/Resources";
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:06:02 +01:00
|
|
|
QString GetApplicationSupportPath() {
|
2012-01-31 13:54:03 +01:00
|
|
|
ScopedNSAutoreleasePool pool;
|
2010-12-06 18:06:02 +01:00
|
|
|
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
2014-01-30 14:48:49 +01:00
|
|
|
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
2010-12-09 13:34:08 +01:00
|
|
|
QString ret;
|
2010-12-06 18:06:02 +01:00
|
|
|
if ([paths count] > 0) {
|
|
|
|
NSString* user_path = [paths objectAtIndex:0];
|
2010-12-09 13:34:08 +01:00
|
|
|
ret = QString::fromUtf8([user_path UTF8String]);
|
|
|
|
} else {
|
|
|
|
ret = "~/Library/Application Support";
|
2010-12-06 18:06:02 +01:00
|
|
|
}
|
2010-12-09 13:34:08 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-14 16:00:46 +01:00
|
|
|
QString GetMusicDirectory() {
|
2012-01-31 13:54:03 +01:00
|
|
|
ScopedNSAutoreleasePool pool;
|
2014-01-30 14:48:49 +01:00
|
|
|
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSMusicDirectory,
|
|
|
|
NSUserDomainMask, YES);
|
2010-12-14 16:00:46 +01:00
|
|
|
QString ret;
|
|
|
|
if ([paths count] > 0) {
|
|
|
|
NSString* user_path = [paths objectAtIndex:0];
|
|
|
|
ret = QString::fromUtf8([user_path UTF8String]);
|
|
|
|
} else {
|
|
|
|
ret = "~/Music";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-01 15:10:30 +02:00
|
|
|
static int MapFunctionKey(int keycode) {
|
|
|
|
switch (keycode) {
|
|
|
|
// Function keys
|
2014-01-30 14:48:49 +01:00
|
|
|
case NSInsertFunctionKey:
|
|
|
|
return Qt::Key_Insert;
|
|
|
|
case NSDeleteFunctionKey:
|
|
|
|
return Qt::Key_Delete;
|
|
|
|
case NSPauseFunctionKey:
|
|
|
|
return Qt::Key_Pause;
|
|
|
|
case NSPrintFunctionKey:
|
|
|
|
return Qt::Key_Print;
|
|
|
|
case NSSysReqFunctionKey:
|
|
|
|
return Qt::Key_SysReq;
|
|
|
|
case NSHomeFunctionKey:
|
|
|
|
return Qt::Key_Home;
|
|
|
|
case NSEndFunctionKey:
|
|
|
|
return Qt::Key_End;
|
|
|
|
case NSLeftArrowFunctionKey:
|
|
|
|
return Qt::Key_Left;
|
|
|
|
case NSUpArrowFunctionKey:
|
|
|
|
return Qt::Key_Up;
|
|
|
|
case NSRightArrowFunctionKey:
|
|
|
|
return Qt::Key_Right;
|
|
|
|
case NSDownArrowFunctionKey:
|
|
|
|
return Qt::Key_Down;
|
|
|
|
case NSPageUpFunctionKey:
|
|
|
|
return Qt::Key_PageUp;
|
|
|
|
case NSPageDownFunctionKey:
|
|
|
|
return Qt::Key_PageDown;
|
|
|
|
case NSScrollLockFunctionKey:
|
|
|
|
return Qt::Key_ScrollLock;
|
|
|
|
case NSF1FunctionKey:
|
|
|
|
return Qt::Key_F1;
|
|
|
|
case NSF2FunctionKey:
|
|
|
|
return Qt::Key_F2;
|
|
|
|
case NSF3FunctionKey:
|
|
|
|
return Qt::Key_F3;
|
|
|
|
case NSF4FunctionKey:
|
|
|
|
return Qt::Key_F4;
|
|
|
|
case NSF5FunctionKey:
|
|
|
|
return Qt::Key_F5;
|
|
|
|
case NSF6FunctionKey:
|
|
|
|
return Qt::Key_F6;
|
|
|
|
case NSF7FunctionKey:
|
|
|
|
return Qt::Key_F7;
|
|
|
|
case NSF8FunctionKey:
|
|
|
|
return Qt::Key_F8;
|
|
|
|
case NSF9FunctionKey:
|
|
|
|
return Qt::Key_F9;
|
|
|
|
case NSF10FunctionKey:
|
|
|
|
return Qt::Key_F10;
|
|
|
|
case NSF11FunctionKey:
|
|
|
|
return Qt::Key_F11;
|
|
|
|
case NSF12FunctionKey:
|
|
|
|
return Qt::Key_F12;
|
|
|
|
case NSF13FunctionKey:
|
|
|
|
return Qt::Key_F13;
|
|
|
|
case NSF14FunctionKey:
|
|
|
|
return Qt::Key_F14;
|
|
|
|
case NSF15FunctionKey:
|
|
|
|
return Qt::Key_F15;
|
|
|
|
case NSF16FunctionKey:
|
|
|
|
return Qt::Key_F16;
|
|
|
|
case NSF17FunctionKey:
|
|
|
|
return Qt::Key_F17;
|
|
|
|
case NSF18FunctionKey:
|
|
|
|
return Qt::Key_F18;
|
|
|
|
case NSF19FunctionKey:
|
|
|
|
return Qt::Key_F19;
|
|
|
|
case NSF20FunctionKey:
|
|
|
|
return Qt::Key_F20;
|
|
|
|
case NSF21FunctionKey:
|
|
|
|
return Qt::Key_F21;
|
|
|
|
case NSF22FunctionKey:
|
|
|
|
return Qt::Key_F22;
|
|
|
|
case NSF23FunctionKey:
|
|
|
|
return Qt::Key_F23;
|
|
|
|
case NSF24FunctionKey:
|
|
|
|
return Qt::Key_F24;
|
|
|
|
case NSF25FunctionKey:
|
|
|
|
return Qt::Key_F25;
|
|
|
|
case NSF26FunctionKey:
|
|
|
|
return Qt::Key_F26;
|
|
|
|
case NSF27FunctionKey:
|
|
|
|
return Qt::Key_F27;
|
|
|
|
case NSF28FunctionKey:
|
|
|
|
return Qt::Key_F28;
|
|
|
|
case NSF29FunctionKey:
|
|
|
|
return Qt::Key_F29;
|
|
|
|
case NSF30FunctionKey:
|
|
|
|
return Qt::Key_F30;
|
|
|
|
case NSF31FunctionKey:
|
|
|
|
return Qt::Key_F31;
|
|
|
|
case NSF32FunctionKey:
|
|
|
|
return Qt::Key_F32;
|
|
|
|
case NSF33FunctionKey:
|
|
|
|
return Qt::Key_F33;
|
|
|
|
case NSF34FunctionKey:
|
|
|
|
return Qt::Key_F34;
|
|
|
|
case NSF35FunctionKey:
|
|
|
|
return Qt::Key_F35;
|
|
|
|
case NSMenuFunctionKey:
|
|
|
|
return Qt::Key_Menu;
|
|
|
|
case NSHelpFunctionKey:
|
|
|
|
return Qt::Key_Help;
|
2011-09-01 15:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence KeySequenceFromNSEvent(NSEvent* event) {
|
|
|
|
NSString* str = [event charactersIgnoringModifiers];
|
|
|
|
NSString* upper = [str uppercaseString];
|
|
|
|
const char* chars = [upper UTF8String];
|
|
|
|
NSUInteger modifiers = [event modifierFlags];
|
|
|
|
int key = 0;
|
|
|
|
unsigned char c = chars[0];
|
|
|
|
switch (c) {
|
2014-01-30 14:48:49 +01:00
|
|
|
case 0x1b:
|
|
|
|
key = Qt::Key_Escape;
|
|
|
|
break;
|
|
|
|
case 0x09:
|
|
|
|
key = Qt::Key_Tab;
|
|
|
|
break;
|
|
|
|
case 0x0d:
|
|
|
|
key = Qt::Key_Return;
|
|
|
|
break;
|
|
|
|
case 0x08:
|
|
|
|
key = Qt::Key_Backspace;
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
key = Qt::Key_Enter;
|
|
|
|
break;
|
2011-09-01 15:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key == 0) {
|
|
|
|
if (c >= 0x20 && c <= 0x7e) { // ASCII from space to ~
|
|
|
|
key = c;
|
|
|
|
} else {
|
|
|
|
key = MapFunctionKey([event keyCode]);
|
|
|
|
if (key == 0) {
|
|
|
|
return QKeySequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers & NSShiftKeyMask) {
|
|
|
|
key += Qt::SHIFT;
|
|
|
|
}
|
|
|
|
if (modifiers & NSControlKeyMask) {
|
|
|
|
key += Qt::META;
|
|
|
|
}
|
|
|
|
if (modifiers & NSAlternateKeyMask) {
|
|
|
|
key += Qt::ALT;
|
|
|
|
}
|
|
|
|
if (modifiers & NSCommandKeyMask) {
|
|
|
|
key += Qt::CTRL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QKeySequence(key);
|
|
|
|
}
|
|
|
|
|
2012-03-09 17:29:55 +01:00
|
|
|
void DumpDictionary(CFDictionaryRef dict) {
|
|
|
|
NSDictionary* d = (NSDictionary*)dict;
|
|
|
|
NSLog(@"%@", d);
|
|
|
|
}
|
|
|
|
|
2012-10-09 14:56:17 +02:00
|
|
|
// NSWindowCollectionBehaviorFullScreenPrimary
|
|
|
|
static const NSUInteger kFullScreenPrimary = 1 << 7;
|
|
|
|
|
|
|
|
void EnableFullScreen(const QWidget& main_window) {
|
|
|
|
NSView* view = reinterpret_cast<NSView*>(main_window.winId());
|
|
|
|
NSWindow* window = [view window];
|
2014-01-30 14:48:49 +01:00
|
|
|
[window setCollectionBehavior:kFullScreenPrimary];
|
2012-10-09 14:56:17 +02:00
|
|
|
}
|
|
|
|
|
2014-01-10 16:57:32 +01:00
|
|
|
float GetDevicePixelRatio(QWidget* widget) {
|
|
|
|
NSView* view = reinterpret_cast<NSView*>(widget->winId());
|
2015-02-18 18:03:05 +01:00
|
|
|
return [[view window] backingScaleFactor];
|
2014-01-10 16:57:32 +01:00
|
|
|
}
|
|
|
|
|
2010-04-13 15:55:54 +02:00
|
|
|
} // namespace mac
|