mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
support pre-10.6 OSX
This commit is contained in:
parent
7299a150c3
commit
6a98f97c9b
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#import <Foundation/NSAutoreleasePool.h>
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
#import <AppKit/NSApplication.h>
|
#import <AppKit/NSApplication.h>
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
#import <AppKit/NSRunningApplication.h>
|
#import <AppKit/NSRunningApplication.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <mach-o/arch.h>
|
#include <mach-o/arch.h>
|
||||||
|
|
||||||
@ -32,7 +34,9 @@ static void init_app() {
|
|||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
#endif
|
||||||
[NSApp finishLaunching];
|
[NSApp finishLaunching];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
|
||||||
@ -143,7 +147,7 @@ load_display_information() {
|
|||||||
//_display_information->_device_id = CGDisplaySerialNumber(_display);
|
//_display_information->_device_id = CGDisplaySerialNumber(_display);
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL);
|
CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL);
|
||||||
size_t num_modes = CFArrayGetCount(modes);
|
size_t num_modes = CFArrayGetCount(modes);
|
||||||
_display_information->_total_display_modes = num_modes;
|
_display_information->_total_display_modes = num_modes;
|
||||||
|
@ -66,8 +66,13 @@ protected:
|
|||||||
virtual void close_window();
|
virtual void close_window();
|
||||||
virtual bool open_window();
|
virtual bool open_window();
|
||||||
|
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
CGDisplayModeRef find_display_mode(int width, int height);
|
CGDisplayModeRef find_display_mode(int width, int height);
|
||||||
bool do_switch_fullscreen(CGDisplayModeRef mode);
|
bool do_switch_fullscreen(CGDisplayModeRef mode);
|
||||||
|
#else
|
||||||
|
CFDictionaryRef find_display_mode(int width, int height);
|
||||||
|
bool do_switch_fullscreen(CFDictionaryRef mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void mouse_mode_absolute();
|
virtual void mouse_mode_absolute();
|
||||||
virtual void mouse_mode_relative();
|
virtual void mouse_mode_relative();
|
||||||
@ -82,11 +87,17 @@ private:
|
|||||||
NSView *_view;
|
NSView *_view;
|
||||||
NSUInteger _modifier_keys;
|
NSUInteger _modifier_keys;
|
||||||
CGDirectDisplayID _display;
|
CGDirectDisplayID _display;
|
||||||
CGDisplayModeRef _fullscreen_mode;
|
|
||||||
CGDisplayModeRef _windowed_mode;
|
|
||||||
bool _mouse_hidden;
|
bool _mouse_hidden;
|
||||||
bool _context_needs_update;
|
bool _context_needs_update;
|
||||||
|
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
CGDisplayModeRef _fullscreen_mode;
|
||||||
|
CGDisplayModeRef _windowed_mode;
|
||||||
|
#else
|
||||||
|
CFDictionaryRef _fullscreen_mode;
|
||||||
|
CFDictionaryRef _windowed_mode;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef pmap<Filename, NSImage*> IconImages;
|
typedef pmap<Filename, NSImage*> IconImages;
|
||||||
IconImages _images;
|
IconImages _images;
|
||||||
|
|
||||||
|
@ -565,8 +565,14 @@ open_window() {
|
|||||||
|
|
||||||
if (_properties.get_fullscreen()) {
|
if (_properties.get_fullscreen()) {
|
||||||
// Change the display mode.
|
// Change the display mode.
|
||||||
CGDisplayModeRef mode = find_display_mode(_properties.get_x_size(),
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
_properties.get_y_size());
|
CGDisplayModeRef mode;
|
||||||
|
#else
|
||||||
|
CFDictionaryRef mode;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mode = find_display_mode(_properties.get_x_size(),
|
||||||
|
_properties.get_y_size());
|
||||||
|
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
cocoadisplay_cat.error()
|
cocoadisplay_cat.error()
|
||||||
@ -725,7 +731,13 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
height = _properties.get_y_size();
|
height = _properties.get_y_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
CGDisplayModeRef mode = find_display_mode(width, height);
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
CGDisplayModeRef mode;
|
||||||
|
#else
|
||||||
|
CFDictionaryRef mode;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mode = find_display_mode(width, height);
|
||||||
|
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
cocoadisplay_cat.error()
|
cocoadisplay_cat.error()
|
||||||
@ -796,7 +808,11 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
properties.clear_size();
|
properties.clear_size();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
CGDisplayModeRef mode = find_display_mode(width, height);
|
CGDisplayModeRef mode = find_display_mode(width, height);
|
||||||
|
#else
|
||||||
|
CFDictionaryRef mode = find_display_mode(width, height);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
cocoadisplay_cat.error()
|
cocoadisplay_cat.error()
|
||||||
@ -1010,6 +1026,7 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
// Description: Returns an appropriate CGDisplayModeRef for the
|
// Description: Returns an appropriate CGDisplayModeRef for the
|
||||||
// given width and height, or NULL if none was found.
|
// given width and height, or NULL if none was found.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
CGDisplayModeRef CocoaGraphicsWindow::
|
CGDisplayModeRef CocoaGraphicsWindow::
|
||||||
find_display_mode(int width, int height) {
|
find_display_mode(int width, int height) {
|
||||||
CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL);
|
CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL);
|
||||||
@ -1053,6 +1070,60 @@ find_display_mode(int width, int height) {
|
|||||||
CFRelease(modes);
|
CFRelease(modes);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#else // Version for pre-10.6.
|
||||||
|
CFDictionaryRef CocoaGraphicsWindow::
|
||||||
|
find_display_mode(int width, int height) {
|
||||||
|
// Get the current mode and extract its properties.
|
||||||
|
CFDictionaryRef current_mode = CGDisplayCurrentMode(_display);
|
||||||
|
int current_width, current_height, current_bpp, current_refresh_rate;
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayWidth),
|
||||||
|
kCFNumberIntType, ¤t_width);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayHeight),
|
||||||
|
kCFNumberIntType, ¤t_height);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayBitsPerPixel),
|
||||||
|
kCFNumberIntType, ¤t_bpp);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayRefreshRate),
|
||||||
|
kCFNumberIntType, ¤t_refresh_rate);
|
||||||
|
|
||||||
|
// Check if it is suitable and if so, return it.
|
||||||
|
if (current_width == width && current_height == height) {
|
||||||
|
return current_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over the modes to find a suitable one.
|
||||||
|
CFArrayRef modes = CGDisplayAvailableModes(_display);
|
||||||
|
size_t num_modes = CFArrayGetCount(modes);
|
||||||
|
int mode_width, mode_height, mode_bpp, mode_refresh_rate;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < num_modes; ++i) {
|
||||||
|
CFDictionaryRef mode = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayWidth),
|
||||||
|
kCFNumberIntType, &mode_width);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayHeight),
|
||||||
|
kCFNumberIntType, &mode_height);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel),
|
||||||
|
kCFNumberIntType, &mode_bpp);
|
||||||
|
|
||||||
|
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayRefreshRate),
|
||||||
|
kCFNumberIntType, &mode_refresh_rate);
|
||||||
|
|
||||||
|
if (mode_width == width && mode_height == height &&
|
||||||
|
mode_refresh_rate == current_refresh_rate &&
|
||||||
|
mode_bpp == current_bpp) {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CocoaGraphicsWindow::do_switch_fullscreen
|
// Function: CocoaGraphicsWindow::do_switch_fullscreen
|
||||||
@ -1061,8 +1132,13 @@ find_display_mode(int width, int height) {
|
|||||||
// back to windowed if NULL was given. Returns true
|
// back to windowed if NULL was given. Returns true
|
||||||
// on success, false on failure.
|
// on success, false on failure.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
bool CocoaGraphicsWindow::
|
bool CocoaGraphicsWindow::
|
||||||
do_switch_fullscreen(CGDisplayModeRef mode) {
|
do_switch_fullscreen(CGDisplayModeRef mode) {
|
||||||
|
#else
|
||||||
|
bool CocoaGraphicsWindow::
|
||||||
|
do_switch_fullscreen(CFDictionaryRef mode) {
|
||||||
|
#endif
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
if (_windowed_mode == NULL) {
|
if (_windowed_mode == NULL) {
|
||||||
// Already windowed.
|
// Already windowed.
|
||||||
@ -1070,8 +1146,12 @@ do_switch_fullscreen(CGDisplayModeRef mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Switch back to the mode we were in when we were still windowed.
|
// Switch back to the mode we were in when we were still windowed.
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
CGDisplaySetDisplayMode(_display, _windowed_mode, NULL);
|
CGDisplaySetDisplayMode(_display, _windowed_mode, NULL);
|
||||||
CGDisplayModeRelease(_windowed_mode);
|
CGDisplayModeRelease(_windowed_mode);
|
||||||
|
#else
|
||||||
|
CGDisplaySwitchToMode(_display, _windowed_mode);
|
||||||
|
#endif
|
||||||
CGDisplayRelease(_display);
|
CGDisplayRelease(_display);
|
||||||
_windowed_mode = NULL;
|
_windowed_mode = NULL;
|
||||||
_context_needs_update = true;
|
_context_needs_update = true;
|
||||||
@ -1081,15 +1161,28 @@ do_switch_fullscreen(CGDisplayModeRef mode) {
|
|||||||
// Already fullscreen in that size.
|
// Already fullscreen in that size.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the existing mode under _windowed_mode.
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
_windowed_mode = CGDisplayCopyDisplayMode(_display);
|
_windowed_mode = CGDisplayCopyDisplayMode(_display);
|
||||||
|
#else
|
||||||
|
_windowed_mode = CGDisplayCurrentMode(_display);
|
||||||
|
#endif
|
||||||
_fullscreen_mode = mode;
|
_fullscreen_mode = mode;
|
||||||
_context_needs_update = true;
|
_context_needs_update = true;
|
||||||
|
|
||||||
if (CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL) != kCGErrorSuccess) {
|
CGError err;
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
err = CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL);
|
||||||
|
#else
|
||||||
|
err = CGDisplaySwitchToMode(_display, _fullscreen_mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (err != kCGErrorSuccess) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGDisplayCaptureWithOptions(_display, kCGCaptureNoFill);
|
CGDisplayCapture(_display);
|
||||||
|
|
||||||
NSRect frame = [[[_view window] screen] frame];
|
NSRect frame = [[[_view window] screen] frame];
|
||||||
if (cocoadisplay_cat.is_debug()) {
|
if (cocoadisplay_cat.is_debug()) {
|
||||||
|
@ -22,7 +22,9 @@
|
|||||||
self = [super initWithFrame: frameRect];
|
self = [super initWithFrame: frameRect];
|
||||||
|
|
||||||
_context = context;
|
_context = context;
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
[self setCanDrawConcurrently:YES];
|
[self setCanDrawConcurrently:YES];
|
||||||
|
#endif
|
||||||
|
|
||||||
cocoadisplay_cat.debug()
|
cocoadisplay_cat.debug()
|
||||||
<< "Created CocoaPandaView " << self << " for GraphicsWindow " << window << "\n";
|
<< "Created CocoaPandaView " << self << " for GraphicsWindow " << window << "\n";
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
[self setDelegate:delegate];
|
[self setDelegate:delegate];
|
||||||
[self setOpaque:YES];
|
[self setOpaque:YES];
|
||||||
[self setReleasedWhenClosed:YES];
|
[self setReleasedWhenClosed:YES];
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
[self setAllowsConcurrentViewDrawing:YES];
|
[self setAllowsConcurrentViewDrawing:YES];
|
||||||
|
#endif
|
||||||
|
|
||||||
// Necessary to be able to accept mouseMoved in the NSView
|
// Necessary to be able to accept mouseMoved in the NSView
|
||||||
[self setAcceptsMouseMovedEvents:YES];
|
[self setAcceptsMouseMovedEvents:YES];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user