Use SMMainThread with LLW_Cocoa. This fixes just about every GUI issue. For some reason, mousing over the button does not highlight them. Other than that, everything seems to work.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#import "RageLog.h"
|
#import "RageLog.h"
|
||||||
#import "RageUtil.h"
|
#import "RageUtil.h"
|
||||||
#import "arch/ArchHooks/ArchHooks.h"
|
#import "arch/ArchHooks/ArchHooks.h"
|
||||||
|
#import "archutils/Darwin/SMMainThread.h"
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <OpenGl/OpenGl.h>
|
#import <OpenGl/OpenGl.h>
|
||||||
@@ -71,16 +72,22 @@ LowLevelWindow_Cocoa::LowLevelWindow_Cocoa() : mView(nil), mFullScreenContext(ni
|
|||||||
{
|
{
|
||||||
POOL;
|
POOL;
|
||||||
NSRect rect = { {0, 0}, {0, 0} };
|
NSRect rect = { {0, 0}, {0, 0} };
|
||||||
|
SMMainThread *mt = [[SMMainThread alloc] init];
|
||||||
|
|
||||||
mWindow = [[NSWindow alloc] initWithContentRect:rect
|
mWindow = [[NSWindow alloc] initWithContentRect:rect
|
||||||
styleMask:g_iStyleMask
|
styleMask:g_iStyleMask
|
||||||
backing:NSBackingStoreNonretained
|
backing:NSBackingStoreNonretained
|
||||||
defer:YES];
|
defer:YES];
|
||||||
ASSERT( mWindow != nil );
|
ASSERT( mWindow != nil );
|
||||||
[mWindow setExcludedFromWindowsMenu:YES];
|
|
||||||
[mWindow useOptimizedDrawing:YES];
|
ADD_ACTIONb( mt, mWindow, setExcludedFromWindowsMenu:, YES );
|
||||||
[mWindow setReleasedWhenClosed:NO];
|
ADD_ACTIONb( mt, mWindow, useOptimizedDrawing:, YES );
|
||||||
// setDelegate: does not retain the delegate; however, we didn't (auto)release it.
|
ADD_ACTIONb( mt, mWindow, setReleasedWhenClosed:, NO );
|
||||||
[mWindow setDelegate:[[SMWindowDelegate alloc] init]];
|
// setDelegate: does not retain the delegate; however, we don't (auto)release it.
|
||||||
|
ADD_ACTION1( mt, mWindow, setDelegate:, [[SMWindowDelegate alloc] init] );
|
||||||
|
|
||||||
|
[mt performOnMainThread];
|
||||||
|
[mt release];
|
||||||
mCurrentParams.windowed = true; // We are essentially windowed to begin with.
|
mCurrentParams.windowed = true; // We are essentially windowed to begin with.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +95,19 @@ LowLevelWindow_Cocoa::~LowLevelWindow_Cocoa()
|
|||||||
{
|
{
|
||||||
POOL;
|
POOL;
|
||||||
ShutDownFullScreen();
|
ShutDownFullScreen();
|
||||||
|
|
||||||
|
SMMainThread *mt = [[SMMainThread alloc] init];
|
||||||
|
|
||||||
// We need to release the window's delegate now.
|
// We need to release the window's delegate now.
|
||||||
// Autorelease to prevent a race condition.
|
id delegate = [mWindow delegate];
|
||||||
[[mWindow delegate] autorelease];
|
|
||||||
[mWindow setDelegate:nil];
|
ADD_ACTION1( mt, mWindow, setDelegate:, nil );
|
||||||
[mWindow orderOut:nil];
|
ADD_ACTION1( mt, mWindow, orderOut:, nil );
|
||||||
[mWindow release];
|
ADD_ACTION0( mt, mWindow, release );
|
||||||
|
|
||||||
|
[mt performOnMainThread];
|
||||||
|
[delegate release];
|
||||||
|
[mt release];
|
||||||
[mFullScreenContext release];
|
[mFullScreenContext release];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,10 +148,11 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD
|
|||||||
newDeviceOut = false;
|
newDeviceOut = false;
|
||||||
|
|
||||||
NSRect contentRect = { { 0, 0 }, { p.width, p.height } };
|
NSRect contentRect = { { 0, 0 }, { p.width, p.height } };
|
||||||
|
SMMainThread *mt = [[[SMMainThread alloc] init] autorelease];
|
||||||
|
|
||||||
// Change the window and the title
|
// Change the window and the title
|
||||||
[mWindow setContentSize:contentRect.size];
|
ADD_ACTIONn( mt, mWindow, setContentSize:, 1, &contentRect.size );
|
||||||
[mWindow setTitle:[NSString stringWithUTF8String:p.sWindowTitle.c_str()]];
|
ADD_ACTION1( mt, mWindow, setTitle:, [NSString stringWithUTF8String:p.sWindowTitle.c_str()] );
|
||||||
|
|
||||||
mCurrentParams.width = p.width;
|
mCurrentParams.width = p.width;
|
||||||
mCurrentParams.height = p.height;
|
mCurrentParams.height = p.height;
|
||||||
@@ -160,16 +175,21 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD
|
|||||||
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||||
|
|
||||||
if( pixelFormat == nil )
|
if( pixelFormat == nil )
|
||||||
|
{
|
||||||
|
[mt performOnMainThread];
|
||||||
return "Failed to set the windowed pixel format.";
|
return "Failed to set the windowed pixel format.";
|
||||||
nextView = [[NSOpenGLView alloc] initWithFrame:contentRect pixelFormat:pixelFormat];
|
}
|
||||||
|
nextView = [[[NSOpenGLView alloc] initWithFrame:contentRect pixelFormat:pixelFormat] autorelease];
|
||||||
[pixelFormat release];
|
[pixelFormat release];
|
||||||
if( nextView == nil )
|
if( nextView == nil )
|
||||||
|
{
|
||||||
|
[mt performOnMainThread];
|
||||||
return "Failed to create windowed OGL context.";
|
return "Failed to create windowed OGL context.";
|
||||||
|
}
|
||||||
SetOGLParameters( [mView openGLContext] );
|
SetOGLParameters( [mView openGLContext] );
|
||||||
newDeviceOut = true;
|
newDeviceOut = true;
|
||||||
mView = nextView;
|
mView = nextView;
|
||||||
[mWindow setContentView:mView];
|
ADD_ACTION1( mt, mWindow, setContentView:, mView );
|
||||||
[mView release];
|
|
||||||
|
|
||||||
// We need to recreate the full screen context as well.
|
// We need to recreate the full screen context as well.
|
||||||
[mFullScreenContext clearDrawable];
|
[mFullScreenContext clearDrawable];
|
||||||
@@ -182,9 +202,11 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD
|
|||||||
id context = [mView openGLContext];
|
id context = [mView openGLContext];
|
||||||
|
|
||||||
ShutDownFullScreen();
|
ShutDownFullScreen();
|
||||||
[mWindow center];
|
|
||||||
[mWindow makeKeyAndOrderFront:nil];
|
|
||||||
|
|
||||||
|
ADD_ACTION0( mt, mWindow, center );
|
||||||
|
ADD_ACTION1( mt, mWindow, makeKeyAndOrderFront:, nil );
|
||||||
|
|
||||||
|
[mt performOnMainThread];
|
||||||
[context update];
|
[context update];
|
||||||
[context makeCurrentContext];
|
[context makeCurrentContext];
|
||||||
mCurrentParams.windowed = true;
|
mCurrentParams.windowed = true;
|
||||||
@@ -193,6 +215,7 @@ CString LowLevelWindow_Cocoa::TryVideoMode( const VideoModeParams& p, bool& newD
|
|||||||
newDeviceOut = newDeviceOut || !mSharingContexts;
|
newDeviceOut = newDeviceOut || !mSharingContexts;
|
||||||
return CString();
|
return CString();
|
||||||
}
|
}
|
||||||
|
[mt performOnMainThread];
|
||||||
int result = ChangeDisplayMode( p );
|
int result = ChangeDisplayMode( p );
|
||||||
|
|
||||||
if( result )
|
if( result )
|
||||||
@@ -361,7 +384,5 @@ void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const
|
|||||||
|
|
||||||
void LowLevelWindow_Cocoa::SwapBuffers()
|
void LowLevelWindow_Cocoa::SwapBuffers()
|
||||||
{
|
{
|
||||||
// XXX I'm not sure if this is needed yet.
|
|
||||||
POOL;
|
|
||||||
[[NSOpenGLContext currentContext] flushBuffer];
|
[[NSOpenGLContext currentContext] flushBuffer];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user