Remove Carbon API usage.

The new API has been available since 10.6 or 10.7 and the debugger
indicates it simply calls through to TransformProcessType.

Change-Id: Ia8f82d7426cb409aca8fd5feb8e43e1b0e79f8f6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Jake Petroules 2015-11-27 02:18:23 -08:00
parent 105fc117b7
commit 32eeb46f3c

View File

@ -443,50 +443,47 @@ Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions)
// Misc // Misc
// //
// Changes the process type for this process to kProcessTransformToForegroundApplication, // Sets the activation policy for this process to NSApplicationActivationPolicyRegular,
// unless either LSUIElement or LSBackgroundOnly is set in the Info.plist. // unless either LSUIElement or LSBackgroundOnly is set in the Info.plist.
void qt_mac_transformProccessToForegroundApplication() void qt_mac_transformProccessToForegroundApplication()
{ {
ProcessSerialNumber psn; bool forceTransform = true;
if (GetCurrentProcess(&psn) == noErr) { CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
bool forceTransform = true; CFSTR("LSUIElement"));
CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), if (value) {
CFSTR("LSUIElement")); CFTypeID valueType = CFGetTypeID(value);
// Officially it's supposed to be a string, a boolean makes sense, so we'll check.
// A number less so, but OK.
if (valueType == CFStringGetTypeID())
forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
else if (valueType == CFBooleanGetTypeID())
forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value));
else if (valueType == CFNumberGetTypeID()) {
int valueAsInt;
CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
forceTransform = !valueAsInt;
}
}
if (forceTransform) {
value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
CFSTR("LSBackgroundOnly"));
if (value) { if (value) {
CFTypeID valueType = CFGetTypeID(value); CFTypeID valueType = CFGetTypeID(value);
// Officially it's supposed to be a string, a boolean makes sense, so we'll check. if (valueType == CFBooleanGetTypeID())
// A number less so, but OK.
if (valueType == CFStringGetTypeID())
forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
else if (valueType == CFBooleanGetTypeID())
forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value)); forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value));
else if (valueType == CFStringGetTypeID())
forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
else if (valueType == CFNumberGetTypeID()) { else if (valueType == CFNumberGetTypeID()) {
int valueAsInt; int valueAsInt;
CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt); CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
forceTransform = !valueAsInt; forceTransform = !valueAsInt;
} }
} }
}
if (forceTransform) { if (forceTransform) {
value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), [[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
CFSTR("LSBackgroundOnly"));
if (value) {
CFTypeID valueType = CFGetTypeID(value);
if (valueType == CFBooleanGetTypeID())
forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value));
else if (valueType == CFStringGetTypeID())
forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
else if (valueType == CFNumberGetTypeID()) {
int valueAsInt;
CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
forceTransform = !valueAsInt;
}
}
}
if (forceTransform) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
} }
} }
static CGColorSpaceRef m_genericColorSpace = 0; static CGColorSpaceRef m_genericColorSpace = 0;