Browse Source

BundlePath is always set in 10.4

David Rose 16 years ago
parent
commit
bfc0b2ea2b

+ 28 - 5
panda/src/osxdisplay/osxGraphicsWindow.mm

@@ -1059,11 +1059,34 @@ os_open_window(WindowProperties &req_properties) {
     // Determine if we're running from a bundle.
     // Determine if we're running from a bundle.
     CFDictionaryRef dref =
     CFDictionaryRef dref =
       ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
       ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
-    // If the dictionary doesn't have "BundlePath", then we're not
-    // running from a bundle, and we need to call TransformProcessType
-    // to make the process a "foreground" application, with its own
-    // icon in the dock and such.
-    if (!CFDictionaryContainsKey(dref, CFSTR("BundlePath"))) {
+    // If the dictionary doesn't have "BundlePath" (or the BundlePath
+    // is the same as the executable path), then we're not running
+    // from a bundle, and we need to call TransformProcessType to make
+    // the process a "foreground" application, with its own icon in
+    // the dock and such.
+
+    bool has_bundle = false;
+
+    CFStringRef bundle_path = (CFStringRef)CFDictionaryGetValue(dref, CFSTR("BundlePath"));
+    if (bundle_path != NULL) {
+      // OK, we have a bundle path.  We're probably running in a
+      // bundle . . .
+      has_bundle = true;
+
+      // . . . unless it turns out it's the same as the executable
+      // path.
+      CFStringRef exe_path = (CFStringRef)CFDictionaryGetValue(dref, kCFBundleExecutableKey);
+      if (exe_path != NULL) {
+        if (CFStringCompare(bundle_path, exe_path, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+          has_bundle = false;
+        }
+        CFRelease(exe_path);
+      }
+
+      CFRelease(bundle_path);
+    }
+
+    if (!has_bundle) {
       TransformProcessType(&psn, kProcessTransformToForegroundApplication);
       TransformProcessType(&psn, kProcessTransformToForegroundApplication);
     }
     }
     SetFrontProcess(&psn);
     SetFrontProcess(&psn);

+ 60 - 37
panda/src/tinydisplay/tinyOsxGraphicsWindow.mm

@@ -854,45 +854,68 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
   
   
 	static bool GlobalInits = false;
 	static bool GlobalInits = false;
 	if (!GlobalInits)
 	if (!GlobalInits)
-	{
-		//
-		// one time aplication inits.. to get a window open from a standalone aplication..
-
-		EventHandlerRef	application_event_ref_ref1;
-		EventTypeSpec	list1[] =
-		{ 
-			//{ kEventClassCommand,  kEventProcessCommand },
-			//{ kEventClassCommand,  kEventCommandUpdateStatus },
-			{ kEventClassMouse, kEventMouseDown },// handle trackball functionality globaly because there is only a single user
-			{ kEventClassMouse, kEventMouseUp }, 
-			{ kEventClassMouse, kEventMouseMoved },
-			{ kEventClassMouse, kEventMouseDragged },
-			{ kEventClassMouse, kEventMouseWheelMoved } ,
-			{ kEventClassKeyboard, kEventRawKeyDown },
-			{ kEventClassKeyboard, kEventRawKeyUp } ,
-			{ kEventClassKeyboard, kEventRawKeyRepeat },
-			{ kEventClassKeyboard, kEventRawKeyModifiersChanged }	,
-			{ kEventClassTextInput,	kEventTextInputUnicodeForKeyEvent},				   
-		};
-
-		EventHandlerUPP	gEvtHandler = NewEventHandlerUPP(appEvtHndlr);
-		err = InstallApplicationEventHandler (gEvtHandler, GetEventTypeCount (list1) , list1, this, &application_event_ref_ref1 );
-		GlobalInits = true;
-
-		ProcessSerialNumber psn = { 0, kCurrentProcess };
+          {
+            //
+            // one time aplication inits.. to get a window open from a standalone aplication..
+
+            EventHandlerRef	application_event_ref_ref1;
+            EventTypeSpec	list1[] =
+              { 
+                //{ kEventClassCommand,  kEventProcessCommand },
+                //{ kEventClassCommand,  kEventCommandUpdateStatus },
+                { kEventClassMouse, kEventMouseDown },// handle trackball functionality globaly because there is only a single user
+                { kEventClassMouse, kEventMouseUp }, 
+                { kEventClassMouse, kEventMouseMoved },
+                { kEventClassMouse, kEventMouseDragged },
+                { kEventClassMouse, kEventMouseWheelMoved } ,
+                { kEventClassKeyboard, kEventRawKeyDown },
+                { kEventClassKeyboard, kEventRawKeyUp } ,
+                { kEventClassKeyboard, kEventRawKeyRepeat },
+                { kEventClassKeyboard, kEventRawKeyModifiersChanged }	,
+                { kEventClassTextInput,	kEventTextInputUnicodeForKeyEvent},				   
+              };
+
+            EventHandlerUPP	gEvtHandler = NewEventHandlerUPP(appEvtHndlr);
+            err = InstallApplicationEventHandler (gEvtHandler, GetEventTypeCount (list1) , list1, this, &application_event_ref_ref1 );
+            GlobalInits = true;
+
+            ProcessSerialNumber psn = { 0, kCurrentProcess };
         
         
-                // Determine if we're running from a bundle.
-                CFDictionaryRef dref =
-                  ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
-                // If the dictionary doesn't have "BundlePath", then we're not
-                // running from a bundle, and we need to call TransformProcessType
-                // to make the process a "foreground" application, with its own
-                // icon in the dock and such.
-                if (!CFDictionaryContainsKey(dref, CFSTR("BundlePath"))) {
-                  TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+            // Determine if we're running from a bundle.
+            CFDictionaryRef dref =
+              ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
+            // If the dictionary doesn't have "BundlePath" (or the BundlePath
+            // is the same as the executable path), then we're not running
+            // from a bundle, and we need to call TransformProcessType to make
+            // the process a "foreground" application, with its own icon in
+            // the dock and such.
+
+            bool has_bundle = false;
+
+            CFStringRef bundle_path = (CFStringRef)CFDictionaryGetValue(dref, CFSTR("BundlePath"));
+            if (bundle_path != NULL) {
+              // OK, we have a bundle path.  We're probably running in a
+              // bundle . . .
+              has_bundle = true;
+
+              // . . . unless it turns out it's the same as the executable
+              // path.
+              CFStringRef exe_path = (CFStringRef)CFDictionaryGetValue(dref, kCFBundleExecutableKey);
+              if (exe_path != NULL) {
+                if (CFStringCompare(bundle_path, exe_path, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+                  has_bundle = false;
                 }
                 }
-                SetFrontProcess(&psn);
-	}
+                CFRelease(exe_path);
+              }
+
+              CFRelease(bundle_path);
+            }
+
+            if (!has_bundle) {
+              TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+            }
+            SetFrontProcess(&psn);
+          }
 
 
 	if (req_properties.has_fullscreen() && req_properties.get_fullscreen())
 	if (req_properties.has_fullscreen() && req_properties.get_fullscreen())
 	{
 	{