mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-23 13:11:09 +00:00
Updates for full screen support in Mac OS X.
This commit is contained in:
parent
44f2ad77d0
commit
1a4a3238c2
|
@ -26,7 +26,6 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
class AglContext : IGraphicsContext, IGraphicsContextInternal
|
||||
{
|
||||
IntPtr storedContextRef;
|
||||
IntPtr contextRef;
|
||||
|
||||
bool mVSync = false;
|
||||
|
@ -99,7 +98,7 @@ namespace OpenTK.Platform.MacOS
|
|||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
//if (fullscreen)
|
||||
{
|
||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
|
||||
}
|
||||
|
@ -200,8 +199,6 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
|
||||
|
||||
Debug.Print("GetControlOwner: {0}", controlOwner);
|
||||
|
||||
windowPort = API.GetWindowPort(controlOwner);
|
||||
}
|
||||
else
|
||||
|
@ -235,40 +232,26 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
return Agl.aglGetCurrentContext();
|
||||
}
|
||||
bool firstFullScreen = false;
|
||||
|
||||
internal void SetFullScreen()
|
||||
internal void SetFullScreen(CarbonWindowInfo info)
|
||||
{
|
||||
if (storedContextRef == IntPtr.Zero)
|
||||
{
|
||||
storedContextRef = contextRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
Agl.aglDestroyContext(contextRef);
|
||||
}
|
||||
Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0);
|
||||
|
||||
// TODO: this may be a problem if we are switching from one
|
||||
// full screen mode to another.
|
||||
try
|
||||
// This is a weird hack to workaround a bug where the first time a context
|
||||
// is made fullscreen, we just end up with a blank screen. So we undo it as fullscreen
|
||||
// and redo it as fullscreen.
|
||||
if (firstFullScreen == false)
|
||||
{
|
||||
CreateContext(mode, carbonWindow, storedContextRef, true);
|
||||
Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0);
|
||||
}
|
||||
catch (MacOSException e)
|
||||
{
|
||||
contextRef = storedContextRef;
|
||||
storedContextRef = IntPtr.Zero;
|
||||
|
||||
throw;
|
||||
firstFullScreen = true;
|
||||
UnsetFullScreen(info);
|
||||
SetFullScreen(info);
|
||||
}
|
||||
}
|
||||
internal void UnsetFullScreen()
|
||||
internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
|
||||
{
|
||||
if (storedContextRef == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
Agl.aglDestroyContext(contextRef);
|
||||
contextRef = storedContextRef;
|
||||
Agl.aglSetDrawable(contextRef, IntPtr.Zero);
|
||||
SetDrawable(windowInfo);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -599,24 +599,24 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
|
||||
return (MouseButton)button;
|
||||
}
|
||||
static internal HIPoint GetEventWindowMouseLocation(IntPtr inEvent)
|
||||
static internal OSStatus GetEventWindowMouseLocation(IntPtr inEvent, out HIPoint pt)
|
||||
{
|
||||
HIPoint pt;
|
||||
HIPoint point;
|
||||
|
||||
unsafe
|
||||
{
|
||||
HIPoint* parm = &pt;
|
||||
HIPoint* parm = &point;
|
||||
|
||||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
||||
(uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero,
|
||||
(IntPtr)parm);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
pt = point;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return pt;
|
||||
}
|
||||
static internal MacOSKeyModifiers GetEventKeyModifiers(IntPtr inEvent)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace OpenTK.Platform.MacOS
|
|||
IntPtr uppHandler;
|
||||
string title = "OpenTK Window";
|
||||
short mWidth, mHeight;
|
||||
short mWindowedWidth, mWindowedHeight;
|
||||
bool mIsDisposed = false;
|
||||
|
||||
WindowAttributes mWindowAttrib;
|
||||
|
@ -262,8 +263,6 @@ namespace OpenTK.Platform.MacOS
|
|||
MacOSKeyCode code;
|
||||
char charCode;
|
||||
|
||||
//Debug.Print(" {0}, '{1}'", (int)charCode, charCode);
|
||||
|
||||
switch (evt.KeyboardEventKind)
|
||||
{
|
||||
case KeyboardEventKind.RawKeyRepeat:
|
||||
|
@ -273,7 +272,6 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
case KeyboardEventKind.RawKeyDown:
|
||||
GetCharCodes(inEvent, out code, out charCode);
|
||||
Debug.Print(" {0}, '{1}'", code, charCode);
|
||||
InputDriver.Keyboard[0][Keymap[code]] = true;
|
||||
return OSStatus.EventNotHandled;
|
||||
|
||||
|
@ -329,7 +327,18 @@ namespace OpenTK.Platform.MacOS
|
|||
MouseButton button = MouseButton.Primary;
|
||||
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
|
||||
if (pt.Y < mTitlebarHeight)
|
||||
|
@ -454,6 +463,9 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
public void SetSize(int width, int height)
|
||||
{
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
return;
|
||||
|
||||
mWidth = (short)width;
|
||||
mHeight = (short)height;
|
||||
|
||||
|
@ -472,22 +484,26 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
contentBounds = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
||||
Debug.Print("New content region size: {0}", contentBounds);
|
||||
|
||||
}
|
||||
|
||||
protected void OnResize()
|
||||
{
|
||||
LoadSize();
|
||||
|
||||
if (context != null)
|
||||
if (context != null && this.windowState != WindowState.Fullscreen)
|
||||
context.Update(window);
|
||||
|
||||
if (Resize != null)
|
||||
{
|
||||
Resize(this, new ResizeEventArgs(Width, Height));
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSize()
|
||||
{
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
return;
|
||||
|
||||
Rect region = GetRegion();
|
||||
|
||||
mWidth = (short)(region.Width);
|
||||
|
@ -619,7 +635,7 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
{
|
||||
((AglContext)context.Implementation).UnsetFullScreen();
|
||||
((AglContext)context.Implementation).UnsetFullScreen(window);
|
||||
}
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
|
@ -630,8 +646,17 @@ namespace OpenTK.Platform.MacOS
|
|||
switch (value)
|
||||
{
|
||||
case WindowState.Fullscreen:
|
||||
((AglContext)context.Implementation).SetFullScreen();
|
||||
context.Update(WindowInfo);
|
||||
((AglContext)context.Implementation).SetFullScreen(window);
|
||||
|
||||
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;
|
||||
|
||||
|
@ -657,10 +682,9 @@ namespace OpenTK.Platform.MacOS
|
|||
break;
|
||||
}
|
||||
|
||||
OnResize();
|
||||
|
||||
windowState = value;
|
||||
|
||||
OnResize();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
if (storedModes.ContainsKey(display))
|
||||
{
|
||||
//CG.DisplaySwitchToMode(display, storedModes[display]);
|
||||
CG.DisplaySwitchToMode(display, storedModes[display]);
|
||||
CG.DisplayRelease(display);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue