Updates for full screen support in Mac OS X.

This commit is contained in:
kanato 2009-02-03 07:45:58 +00:00
parent 44f2ad77d0
commit 1a4a3238c2
4 changed files with 56 additions and 49 deletions

View file

@ -26,7 +26,6 @@ namespace OpenTK.Platform.MacOS
class AglContext : IGraphicsContext, IGraphicsContextInternal class AglContext : IGraphicsContext, IGraphicsContextInternal
{ {
IntPtr storedContextRef;
IntPtr contextRef; IntPtr contextRef;
bool mVSync = false; bool mVSync = false;
@ -99,7 +98,7 @@ namespace OpenTK.Platform.MacOS
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
} }
if (fullscreen) //if (fullscreen)
{ {
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN); AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
} }
@ -200,8 +199,6 @@ namespace OpenTK.Platform.MacOS
{ {
IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef); IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
Debug.Print("GetControlOwner: {0}", controlOwner);
windowPort = API.GetWindowPort(controlOwner); windowPort = API.GetWindowPort(controlOwner);
} }
else else
@ -235,40 +232,26 @@ namespace OpenTK.Platform.MacOS
{ {
return Agl.aglGetCurrentContext(); return Agl.aglGetCurrentContext();
} }
bool firstFullScreen = false;
internal void SetFullScreen() internal void SetFullScreen(CarbonWindowInfo info)
{ {
if (storedContextRef == IntPtr.Zero) Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0);
{
storedContextRef = contextRef;
}
else
{
Agl.aglDestroyContext(contextRef);
}
// TODO: this may be a problem if we are switching from one // This is a weird hack to workaround a bug where the first time a context
// full screen mode to another. // is made fullscreen, we just end up with a blank screen. So we undo it as fullscreen
try // and redo it as fullscreen.
if (firstFullScreen == false)
{ {
CreateContext(mode, carbonWindow, storedContextRef, true); firstFullScreen = true;
Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0); UnsetFullScreen(info);
} SetFullScreen(info);
catch (MacOSException e)
{
contextRef = storedContextRef;
storedContextRef = IntPtr.Zero;
throw;
} }
} }
internal void UnsetFullScreen() internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
{ {
if (storedContextRef == IntPtr.Zero) Agl.aglSetDrawable(contextRef, IntPtr.Zero);
return; SetDrawable(windowInfo);
Agl.aglDestroyContext(contextRef);
contextRef = storedContextRef;
} }

View file

@ -599,24 +599,24 @@ namespace OpenTK.Platform.MacOS.Carbon
return (MouseButton)button; return (MouseButton)button;
} }
static internal HIPoint GetEventWindowMouseLocation(IntPtr inEvent) static internal OSStatus GetEventWindowMouseLocation(IntPtr inEvent, out HIPoint pt)
{ {
HIPoint pt; HIPoint point;
unsafe unsafe
{ {
HIPoint* parm = &pt; HIPoint* parm = &point;
OSStatus result = API.GetEventParameter(inEvent, OSStatus result = API.GetEventParameter(inEvent,
EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero, EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
(uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero,
(IntPtr)parm); (IntPtr)parm);
if (result != OSStatus.NoError) pt = point;
throw new MacOSException(result);
return result;
} }
return pt;
} }
static internal MacOSKeyModifiers GetEventKeyModifiers(IntPtr inEvent) static internal MacOSKeyModifiers GetEventKeyModifiers(IntPtr inEvent)
{ {

View file

@ -29,6 +29,7 @@ namespace OpenTK.Platform.MacOS
IntPtr uppHandler; IntPtr uppHandler;
string title = "OpenTK Window"; string title = "OpenTK Window";
short mWidth, mHeight; short mWidth, mHeight;
short mWindowedWidth, mWindowedHeight;
bool mIsDisposed = false; bool mIsDisposed = false;
WindowAttributes mWindowAttrib; WindowAttributes mWindowAttrib;
@ -262,8 +263,6 @@ namespace OpenTK.Platform.MacOS
MacOSKeyCode code; MacOSKeyCode code;
char charCode; char charCode;
//Debug.Print(" {0}, '{1}'", (int)charCode, charCode);
switch (evt.KeyboardEventKind) switch (evt.KeyboardEventKind)
{ {
case KeyboardEventKind.RawKeyRepeat: case KeyboardEventKind.RawKeyRepeat:
@ -273,7 +272,6 @@ namespace OpenTK.Platform.MacOS
case KeyboardEventKind.RawKeyDown: case KeyboardEventKind.RawKeyDown:
GetCharCodes(inEvent, out code, out charCode); GetCharCodes(inEvent, out code, out charCode);
Debug.Print(" {0}, '{1}'", code, charCode);
InputDriver.Keyboard[0][Keymap[code]] = true; InputDriver.Keyboard[0][Keymap[code]] = true;
return OSStatus.EventNotHandled; return OSStatus.EventNotHandled;
@ -329,7 +327,18 @@ namespace OpenTK.Platform.MacOS
MouseButton button = MouseButton.Primary; MouseButton button = MouseButton.Primary;
HIPoint pt = new HIPoint(); HIPoint pt = new HIPoint();
pt = API.GetEventWindowMouseLocation(inEvent); OSStatus err = API.GetEventWindowMouseLocation(inEvent, out pt);
if (err != OSStatus.NoError)
{
// this error comes up if there is a mouse move event
// while switching from fullscreen to windowed. just
// ignore it.
if (err != OSStatus.EventParameterNotFound)
{
throw new MacOSException(err);
}
}
// ignore clicks in the title bar // ignore clicks in the title bar
if (pt.Y < mTitlebarHeight) if (pt.Y < mTitlebarHeight)
@ -454,6 +463,9 @@ namespace OpenTK.Platform.MacOS
} }
public void SetSize(int width, int height) public void SetSize(int width, int height)
{ {
if (WindowState == WindowState.Fullscreen)
return;
mWidth = (short)width; mWidth = (short)width;
mHeight = (short)height; mHeight = (short)height;
@ -472,22 +484,26 @@ namespace OpenTK.Platform.MacOS
contentBounds = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion); contentBounds = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
Debug.Print("New content region size: {0}", contentBounds); Debug.Print("New content region size: {0}", contentBounds);
} }
protected void OnResize() protected void OnResize()
{ {
LoadSize(); LoadSize();
if (context != null) if (context != null && this.windowState != WindowState.Fullscreen)
context.Update(window); context.Update(window);
if (Resize != null) if (Resize != null)
{
Resize(this, new ResizeEventArgs(Width, Height)); Resize(this, new ResizeEventArgs(Width, Height));
}
} }
private void LoadSize() private void LoadSize()
{ {
if (WindowState == WindowState.Fullscreen)
return;
Rect region = GetRegion(); Rect region = GetRegion();
mWidth = (short)(region.Width); mWidth = (short)(region.Width);
@ -619,7 +635,7 @@ namespace OpenTK.Platform.MacOS
if (WindowState == WindowState.Fullscreen) if (WindowState == WindowState.Fullscreen)
{ {
((AglContext)context.Implementation).UnsetFullScreen(); ((AglContext)context.Implementation).UnsetFullScreen(window);
} }
if (WindowState == WindowState.Minimized) if (WindowState == WindowState.Minimized)
{ {
@ -630,8 +646,17 @@ namespace OpenTK.Platform.MacOS
switch (value) switch (value)
{ {
case WindowState.Fullscreen: case WindowState.Fullscreen:
((AglContext)context.Implementation).SetFullScreen(); ((AglContext)context.Implementation).SetFullScreen(window);
context.Update(WindowInfo);
mWindowedWidth = mWidth;
mWindowedHeight = mHeight;
Debug.Print("Prev Size: {0}, {1}", Width, Height);
mWidth = (short) DisplayDevice.Default.Width;
mHeight = (short) DisplayDevice.Default.Height;
Debug.Print("New Size: {0}, {1}", Width, Height);
break; break;
@ -657,10 +682,9 @@ namespace OpenTK.Platform.MacOS
break; break;
} }
OnResize();
windowState = value; windowState = value;
OnResize();
} }
} }

View file

@ -150,7 +150,7 @@ namespace OpenTK.Platform.MacOS
if (storedModes.ContainsKey(display)) if (storedModes.ContainsKey(display))
{ {
//CG.DisplaySwitchToMode(display, storedModes[display]); CG.DisplaySwitchToMode(display, storedModes[display]);
CG.DisplayRelease(display); CG.DisplayRelease(display);
return true; return true;
} }