2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
2019-04-16 08:43:29 -04:00
|
|
|
// GLFW 3.4 macOS - www.glfw.org
|
2010-09-07 11:34:51 -04:00
|
|
|
//------------------------------------------------------------------------
|
2019-04-15 14:50:00 -04:00
|
|
|
// Copyright (c) 2009-2019 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 11:34:51 -04:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
2019-05-20 09:24:14 -04:00
|
|
|
// It is fine to use C99 in this file because it will not be built with VS
|
|
|
|
//========================================================================
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2016-03-16 10:05:50 -04:00
|
|
|
#include <float.h>
|
2014-09-09 10:26:57 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
// Returns the style mask corresponding to the window settings
|
|
|
|
//
|
|
|
|
static NSUInteger getStyleMask(_GLFWwindow* window)
|
|
|
|
{
|
2019-11-12 12:23:04 -05:00
|
|
|
NSUInteger styleMask = NSWindowStyleMaskMiniaturizable;
|
2016-02-23 06:26:42 -05:00
|
|
|
|
|
|
|
if (window->monitor || !window->decorated)
|
2016-10-08 19:39:31 -04:00
|
|
|
styleMask |= NSWindowStyleMaskBorderless;
|
2016-02-23 06:26:42 -05:00
|
|
|
else
|
|
|
|
{
|
2016-10-08 19:39:31 -04:00
|
|
|
styleMask |= NSWindowStyleMaskTitled |
|
2019-11-12 12:23:04 -05:00
|
|
|
NSWindowStyleMaskClosable;
|
2016-02-23 06:26:42 -05:00
|
|
|
|
|
|
|
if (window->resizable)
|
2016-10-08 19:39:31 -04:00
|
|
|
styleMask |= NSWindowStyleMaskResizable;
|
2016-02-23 06:26:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return styleMask;
|
|
|
|
}
|
|
|
|
|
2019-01-22 14:54:16 -05:00
|
|
|
// Returns whether the cursor is in the content area of the specified window
|
2016-05-25 08:06:02 -04:00
|
|
|
//
|
2019-01-22 14:54:16 -05:00
|
|
|
static GLFWbool cursorInContentArea(_GLFWwindow* window)
|
2016-05-25 08:06:02 -04:00
|
|
|
{
|
2016-05-30 15:21:09 -04:00
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
return [window->ns.view mouse:pos inRect:[window->ns.view frame]];
|
|
|
|
}
|
|
|
|
|
2017-08-22 14:40:07 -04:00
|
|
|
// Hides the cursor if not already hidden
|
2017-06-04 17:26:55 -04:00
|
|
|
//
|
2017-08-22 14:40:07 -04:00
|
|
|
static void hideCursor(_GLFWwindow* window)
|
2017-06-04 17:26:55 -04:00
|
|
|
{
|
2017-08-22 14:40:07 -04:00
|
|
|
if (!_glfw.ns.cursorHidden)
|
|
|
|
{
|
2017-06-04 17:26:55 -04:00
|
|
|
[NSCursor hide];
|
2017-08-22 14:40:07 -04:00
|
|
|
_glfw.ns.cursorHidden = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2017-06-04 17:26:55 -04:00
|
|
|
|
2017-08-22 14:40:07 -04:00
|
|
|
// Shows the cursor if not already shown
|
|
|
|
//
|
|
|
|
static void showCursor(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (_glfw.ns.cursorHidden)
|
|
|
|
{
|
|
|
|
[NSCursor unhide];
|
|
|
|
_glfw.ns.cursorHidden = GLFW_FALSE;
|
|
|
|
}
|
2017-06-04 17:26:55 -04:00
|
|
|
}
|
|
|
|
|
2016-05-30 15:21:09 -04:00
|
|
|
// Updates the cursor image according to its cursor mode
|
|
|
|
//
|
|
|
|
static void updateCursorImage(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
2016-05-25 08:06:02 -04:00
|
|
|
{
|
2017-08-22 14:40:07 -04:00
|
|
|
showCursor(window);
|
2017-06-04 17:26:55 -04:00
|
|
|
|
2016-05-25 08:06:02 -04:00
|
|
|
if (window->cursor)
|
|
|
|
[(NSCursor*) window->cursor->ns.object set];
|
|
|
|
else
|
|
|
|
[[NSCursor arrowCursor] set];
|
|
|
|
}
|
|
|
|
else
|
2017-08-22 14:40:07 -04:00
|
|
|
hideCursor(window);
|
2016-05-25 08:06:02 -04:00
|
|
|
}
|
|
|
|
|
2018-04-17 13:54:36 -04:00
|
|
|
// Apply chosen cursor mode to a focused window
|
|
|
|
//
|
|
|
|
static void updateCursorMode(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
{
|
|
|
|
_glfw.ns.disabledCursorWindow = window;
|
|
|
|
_glfwPlatformGetCursorPos(window,
|
|
|
|
&_glfw.ns.restoreCursorPosX,
|
|
|
|
&_glfw.ns.restoreCursorPosY);
|
2019-01-22 14:54:16 -05:00
|
|
|
_glfwCenterCursorInContentArea(window);
|
2018-04-17 13:54:36 -04:00
|
|
|
CGAssociateMouseAndMouseCursorPosition(false);
|
|
|
|
}
|
|
|
|
else if (_glfw.ns.disabledCursorWindow == window)
|
|
|
|
{
|
|
|
|
_glfw.ns.disabledCursorWindow = NULL;
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
|
|
|
_glfwPlatformSetCursorPos(window,
|
|
|
|
_glfw.ns.restoreCursorPosX,
|
|
|
|
_glfw.ns.restoreCursorPosY);
|
|
|
|
}
|
|
|
|
|
2019-01-22 14:54:16 -05:00
|
|
|
if (cursorInContentArea(window))
|
2018-04-17 13:54:36 -04:00
|
|
|
updateCursorImage(window);
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:34:35 -05:00
|
|
|
// Make the specified window and its video mode active on its monitor
|
2013-05-02 12:16:23 -04:00
|
|
|
//
|
2018-02-05 11:11:04 -05:00
|
|
|
static void acquireMonitor(_GLFWwindow* window)
|
2013-05-02 12:16:23 -04:00
|
|
|
{
|
2018-02-05 11:11:04 -05:00
|
|
|
_glfwSetVideoModeNS(window->monitor, &window->videoMode);
|
2015-12-07 15:03:24 -05:00
|
|
|
const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID);
|
|
|
|
const NSRect frame = NSMakeRect(bounds.origin.x,
|
2019-04-10 15:19:40 -04:00
|
|
|
_glfwTransformYNS(bounds.origin.y + bounds.size.height - 1),
|
2015-12-07 15:03:24 -05:00
|
|
|
bounds.size.width,
|
|
|
|
bounds.size.height);
|
|
|
|
|
|
|
|
[window->ns.object setFrame:frame display:YES];
|
2016-02-23 06:34:35 -05:00
|
|
|
|
2017-01-10 09:46:00 -05:00
|
|
|
_glfwInputMonitorWindow(window->monitor, window);
|
2013-05-02 12:16:23 -04:00
|
|
|
}
|
|
|
|
|
2016-02-23 06:34:35 -05:00
|
|
|
// Remove the window and restore the original video mode
|
2013-05-02 12:16:23 -04:00
|
|
|
//
|
2016-02-23 06:34:35 -05:00
|
|
|
static void releaseMonitor(_GLFWwindow* window)
|
2013-05-02 12:16:23 -04:00
|
|
|
{
|
2016-02-23 06:34:35 -05:00
|
|
|
if (window->monitor->window != window)
|
|
|
|
return;
|
|
|
|
|
2017-01-10 09:46:00 -05:00
|
|
|
_glfwInputMonitorWindow(window->monitor, NULL);
|
2015-12-03 12:16:46 -05:00
|
|
|
_glfwRestoreVideoModeNS(window->monitor);
|
2013-05-02 12:16:23 -04:00
|
|
|
}
|
|
|
|
|
2016-10-19 18:50:54 -04:00
|
|
|
// Translates macOS key modifiers into GLFW ones
|
2015-05-15 12:05:20 -04:00
|
|
|
//
|
|
|
|
static int translateFlags(NSUInteger flags)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
2016-10-08 19:39:31 -04:00
|
|
|
if (flags & NSEventModifierFlagShift)
|
2015-05-15 12:05:20 -04:00
|
|
|
mods |= GLFW_MOD_SHIFT;
|
2016-10-08 19:39:31 -04:00
|
|
|
if (flags & NSEventModifierFlagControl)
|
2015-05-15 12:05:20 -04:00
|
|
|
mods |= GLFW_MOD_CONTROL;
|
2016-10-08 19:39:31 -04:00
|
|
|
if (flags & NSEventModifierFlagOption)
|
2015-05-15 12:05:20 -04:00
|
|
|
mods |= GLFW_MOD_ALT;
|
2016-10-08 19:39:31 -04:00
|
|
|
if (flags & NSEventModifierFlagCommand)
|
2015-05-15 12:05:20 -04:00
|
|
|
mods |= GLFW_MOD_SUPER;
|
2017-11-29 14:42:37 -05:00
|
|
|
if (flags & NSEventModifierFlagCapsLock)
|
|
|
|
mods |= GLFW_MOD_CAPS_LOCK;
|
2015-05-15 12:05:20 -04:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
2016-10-19 18:50:54 -04:00
|
|
|
// Translates a macOS keycode to a GLFW keycode
|
2015-05-15 12:05:20 -04:00
|
|
|
//
|
|
|
|
static int translateKey(unsigned int key)
|
|
|
|
{
|
2016-09-07 09:43:39 -04:00
|
|
|
if (key >= sizeof(_glfw.ns.keycodes) / sizeof(_glfw.ns.keycodes[0]))
|
2015-05-15 12:05:20 -04:00
|
|
|
return GLFW_KEY_UNKNOWN;
|
|
|
|
|
2016-09-07 09:43:39 -04:00
|
|
|
return _glfw.ns.keycodes[key];
|
2015-05-15 12:05:20 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 21:40:54 -04:00
|
|
|
// Translate a GLFW keycode to a Cocoa modifier flag
|
|
|
|
//
|
|
|
|
static NSUInteger translateKeyToModifierFlag(int key)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case GLFW_KEY_LEFT_SHIFT:
|
|
|
|
case GLFW_KEY_RIGHT_SHIFT:
|
2016-10-08 19:39:31 -04:00
|
|
|
return NSEventModifierFlagShift;
|
2015-07-26 21:40:54 -04:00
|
|
|
case GLFW_KEY_LEFT_CONTROL:
|
|
|
|
case GLFW_KEY_RIGHT_CONTROL:
|
2016-10-08 19:39:31 -04:00
|
|
|
return NSEventModifierFlagControl;
|
2015-07-26 21:40:54 -04:00
|
|
|
case GLFW_KEY_LEFT_ALT:
|
|
|
|
case GLFW_KEY_RIGHT_ALT:
|
2016-10-08 19:39:31 -04:00
|
|
|
return NSEventModifierFlagOption;
|
2015-07-26 21:40:54 -04:00
|
|
|
case GLFW_KEY_LEFT_SUPER:
|
|
|
|
case GLFW_KEY_RIGHT_SUPER:
|
2016-10-08 19:39:31 -04:00
|
|
|
return NSEventModifierFlagCommand;
|
2018-11-03 20:12:28 -04:00
|
|
|
case GLFW_KEY_CAPS_LOCK:
|
|
|
|
return NSEventModifierFlagCapsLock;
|
2015-07-26 21:40:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:19:20 -05:00
|
|
|
// Defines a constant for empty ranges in NSTextInputClient
|
|
|
|
//
|
2016-02-26 04:34:23 -05:00
|
|
|
static const NSRange kEmptyRange = { NSNotFound, 0 };
|
2015-11-13 11:19:20 -05:00
|
|
|
|
2013-05-02 12:16:23 -04:00
|
|
|
|
2013-02-04 07:22:10 -05:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 11:34:51 -04:00
|
|
|
// Delegate for window related notifications
|
2013-02-04 07:22:10 -05:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
@interface GLFWWindowDelegate : NSObject
|
2010-09-15 12:57:25 -04:00
|
|
|
{
|
|
|
|
_GLFWwindow* window;
|
|
|
|
}
|
|
|
|
|
2017-09-27 17:01:14 -04:00
|
|
|
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow;
|
2010-09-15 12:57:25 -04:00
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWWindowDelegate
|
|
|
|
|
2017-09-27 17:01:14 -04:00
|
|
|
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
2010-09-15 12:57:25 -04:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
window = initWindow;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-08-10 07:31:15 -04:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)notification
|
|
|
|
{
|
2016-03-28 07:19:31 -04:00
|
|
|
if (window->context.client != GLFW_NO_API)
|
2015-11-09 10:48:55 -05:00
|
|
|
[window->context.nsgl.object update];
|
2015-05-15 09:28:27 -04:00
|
|
|
|
2016-05-30 15:21:09 -04:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2019-01-22 14:54:16 -05:00
|
|
|
_glfwCenterCursorInContentArea(window);
|
2014-02-11 12:24:01 -05:00
|
|
|
|
2016-06-16 07:09:28 -04:00
|
|
|
const int maximized = [window->ns.object isZoomed];
|
|
|
|
if (window->ns.maximized != maximized)
|
|
|
|
{
|
|
|
|
window->ns.maximized = maximized;
|
|
|
|
_glfwInputWindowMaximize(window, maximized);
|
|
|
|
}
|
|
|
|
|
2013-06-03 06:51:57 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 13:15:36 -04:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-03 06:51:57 -04:00
|
|
|
|
2017-11-16 05:34:42 -05:00
|
|
|
if (fbRect.size.width != window->ns.fbWidth ||
|
|
|
|
fbRect.size.height != window->ns.fbHeight)
|
|
|
|
{
|
|
|
|
window->ns.fbWidth = fbRect.size.width;
|
|
|
|
window->ns.fbHeight = fbRect.size.height;
|
|
|
|
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contentRect.size.width != window->ns.width ||
|
|
|
|
contentRect.size.height != window->ns.height)
|
|
|
|
{
|
|
|
|
window->ns.width = contentRect.size.width;
|
|
|
|
window->ns.height = contentRect.size.height;
|
|
|
|
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
|
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:25:09 -04:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification
|
|
|
|
{
|
2016-03-28 07:19:31 -04:00
|
|
|
if (window->context.client != GLFW_NO_API)
|
2015-11-09 10:48:55 -05:00
|
|
|
[window->context.nsgl.object update];
|
2015-05-15 09:28:27 -04:00
|
|
|
|
2016-05-30 15:21:09 -04:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2019-01-22 14:54:16 -05:00
|
|
|
_glfwCenterCursorInContentArea(window);
|
2014-02-11 12:24:01 -05:00
|
|
|
|
2013-01-24 13:30:31 -05:00
|
|
|
int x, y;
|
|
|
|
_glfwPlatformGetWindowPos(window, &x, &y);
|
|
|
|
_glfwInputWindowPos(window, x, y);
|
2010-09-16 18:25:09 -04:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:39:35 -04:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notification
|
2010-09-15 21:05:55 -04:00
|
|
|
{
|
2015-08-28 06:00:06 -04:00
|
|
|
if (window->monitor)
|
2016-02-23 06:34:35 -05:00
|
|
|
releaseMonitor(window);
|
2015-08-28 06:00:06 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowIconify(window, GLFW_TRUE);
|
2010-09-15 21:05:55 -04:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:39:35 -04:00
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
2010-09-15 21:05:55 -04:00
|
|
|
{
|
2015-08-28 06:00:06 -04:00
|
|
|
if (window->monitor)
|
2016-02-23 06:34:35 -05:00
|
|
|
acquireMonitor(window);
|
2015-08-28 06:00:06 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowIconify(window, GLFW_FALSE);
|
2010-09-15 21:05:55 -04:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:39:35 -04:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
2010-09-15 21:05:55 -04:00
|
|
|
{
|
2016-05-30 15:21:09 -04:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
2019-01-22 14:54:16 -05:00
|
|
|
_glfwCenterCursorInContentArea(window);
|
2014-02-11 12:24:01 -05:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowFocus(window, GLFW_TRUE);
|
2018-04-17 13:54:36 -04:00
|
|
|
updateCursorMode(window);
|
2010-09-15 21:05:55 -04:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:39:35 -04:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification
|
2010-09-15 21:05:55 -04:00
|
|
|
{
|
2015-05-06 17:52:39 -04:00
|
|
|
if (window->monitor && window->autoIconify)
|
2015-08-28 06:00:06 -04:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2014-12-29 13:21:31 -05:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowFocus(window, GLFW_FALSE);
|
2010-09-15 21:05:55 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 16:12:21 -04:00
|
|
|
- (void)windowDidChangeOcclusionState:(NSNotification* )notification
|
|
|
|
{
|
|
|
|
if ([window->ns.object occlusionState] & NSWindowOcclusionStateVisible)
|
|
|
|
window->ns.occluded = GLFW_FALSE;
|
|
|
|
else
|
|
|
|
window->ns.occluded = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-15 21:05:55 -04:00
|
|
|
@end
|
|
|
|
|
2012-03-07 09:04:14 -05:00
|
|
|
|
2013-02-04 07:22:10 -05:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 11:34:51 -04:00
|
|
|
// Content view class for the GLFW window
|
2013-02-04 07:22:10 -05:00
|
|
|
//------------------------------------------------------------------------
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-11-13 11:19:20 -05:00
|
|
|
@interface GLFWContentView : NSView <NSTextInputClient>
|
2010-09-15 12:57:25 -04:00
|
|
|
{
|
|
|
|
_GLFWwindow* window;
|
2012-03-26 08:46:42 -04:00
|
|
|
NSTrackingArea* trackingArea;
|
2015-11-13 11:19:20 -05:00
|
|
|
NSMutableAttributedString* markedText;
|
2010-09-15 12:57:25 -04:00
|
|
|
}
|
|
|
|
|
2017-09-27 17:01:14 -04:00
|
|
|
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow;
|
2010-09-15 12:57:25 -04:00
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWContentView
|
|
|
|
|
2017-09-27 17:01:14 -04:00
|
|
|
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
2010-09-15 12:57:25 -04:00
|
|
|
{
|
2015-05-15 09:28:27 -04:00
|
|
|
self = [super init];
|
2010-09-15 12:57:25 -04:00
|
|
|
if (self != nil)
|
2012-03-26 08:46:42 -04:00
|
|
|
{
|
2010-09-15 12:57:25 -04:00
|
|
|
window = initWindow;
|
2012-03-26 08:46:42 -04:00
|
|
|
trackingArea = nil;
|
2015-11-13 11:19:20 -05:00
|
|
|
markedText = [[NSMutableAttributedString alloc] init];
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2012-03-26 08:46:42 -04:00
|
|
|
[self updateTrackingAreas];
|
2018-11-19 16:27:51 -05:00
|
|
|
// NOTE: kUTTypeURL corresponds to NSPasteboardTypeURL but is available
|
|
|
|
// on 10.7 without having been deprecated yet
|
|
|
|
[self registerForDraggedTypes:@[(__bridge NSString*) kUTTypeURL]];
|
2012-03-26 08:46:42 -04:00
|
|
|
}
|
2010-09-15 12:57:25 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:19:20 -05:00
|
|
|
- (void)dealloc
|
2012-03-26 08:46:42 -04:00
|
|
|
{
|
|
|
|
[trackingArea release];
|
2015-11-13 11:19:20 -05:00
|
|
|
[markedText release];
|
2012-03-26 08:46:42 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
2017-09-18 12:10:57 -04:00
|
|
|
return [window->ns.object isOpaque];
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyView
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2016-10-13 19:46:56 -04:00
|
|
|
- (BOOL)wantsUpdateLayer
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2018-10-26 07:21:14 -04:00
|
|
|
- (void)updateLayer
|
|
|
|
{
|
|
|
|
if (window->context.client != GLFW_NO_API)
|
|
|
|
[window->context.nsgl.object update];
|
|
|
|
|
|
|
|
_glfwInputWindowDamage(window);
|
|
|
|
}
|
|
|
|
|
2013-09-18 19:05:51 -04:00
|
|
|
- (void)cursorUpdate:(NSEvent *)event
|
|
|
|
{
|
2016-05-30 15:21:09 -04:00
|
|
|
updateCursorImage(window);
|
2013-09-18 19:05:51 -04:00
|
|
|
}
|
|
|
|
|
2018-11-24 09:38:07 -05:00
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent *)event
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
- (void)mouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_PRESS,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_LEFT,
|
|
|
|
GLFW_RELEASE,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event
|
|
|
|
{
|
2013-04-26 11:20:31 -04:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2014-02-11 12:24:01 -05:00
|
|
|
{
|
2016-05-25 08:06:02 -04:00
|
|
|
const double dx = [event deltaX] - window->ns.cursorWarpDeltaX;
|
|
|
|
const double dy = [event deltaY] - window->ns.cursorWarpDeltaY;
|
|
|
|
|
|
|
|
_glfwInputCursorPos(window,
|
|
|
|
window->virtualCursorPosX + dx,
|
|
|
|
window->virtualCursorPosY + dy);
|
2014-02-11 12:24:01 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
else
|
|
|
|
{
|
2013-06-03 19:51:40 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2019-04-10 15:19:40 -04:00
|
|
|
// NOTE: The returned location uses base 0,1 not 0,0
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSPoint pos = [event locationInWindow];
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2016-05-25 08:06:02 -04:00
|
|
|
_glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y);
|
2011-05-21 16:50:25 -04:00
|
|
|
}
|
2014-02-11 12:24:01 -05:00
|
|
|
|
2016-05-24 06:23:58 -04:00
|
|
|
window->ns.cursorWarpDeltaX = 0;
|
|
|
|
window->ns.cursorWarpDeltaY = 0;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_PRESS,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
|
|
|
GLFW_MOUSE_BUTTON_RIGHT,
|
|
|
|
GLFW_RELEASE,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
2013-10-08 10:42:17 -04:00
|
|
|
(int) [event buttonNumber],
|
2012-12-09 13:19:00 -05:00
|
|
|
GLFW_PRESS,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)event
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window,
|
2013-10-08 10:42:17 -04:00
|
|
|
(int) [event buttonNumber],
|
2012-12-09 13:19:00 -05:00
|
|
|
GLFW_RELEASE,
|
2013-05-30 11:19:12 -04:00
|
|
|
translateFlags([event modifierFlags]));
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-03-26 08:46:42 -04:00
|
|
|
- (void)mouseExited:(NSEvent *)event
|
|
|
|
{
|
2017-06-04 17:26:55 -04:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
2017-08-22 14:40:07 -04:00
|
|
|
showCursor(window);
|
2017-06-04 17:26:55 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputCursorEnter(window, GLFW_FALSE);
|
2012-03-26 08:46:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent *)event
|
|
|
|
{
|
2017-06-04 17:26:55 -04:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
2017-08-22 14:40:07 -04:00
|
|
|
hideCursor(window);
|
2017-06-04 17:26:55 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputCursorEnter(window, GLFW_TRUE);
|
2012-03-26 08:46:42 -04:00
|
|
|
}
|
|
|
|
|
2013-06-03 06:51:57 -04:00
|
|
|
- (void)viewDidChangeBackingProperties
|
|
|
|
{
|
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 13:15:36 -04:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-03 06:51:57 -04:00
|
|
|
|
2017-11-16 05:34:42 -05:00
|
|
|
if (fbRect.size.width != window->ns.fbWidth ||
|
|
|
|
fbRect.size.height != window->ns.fbHeight)
|
|
|
|
{
|
|
|
|
window->ns.fbWidth = fbRect.size.width;
|
|
|
|
window->ns.fbHeight = fbRect.size.height;
|
|
|
|
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
|
|
|
|
}
|
2017-12-11 15:26:40 -05:00
|
|
|
|
|
|
|
const float xscale = fbRect.size.width / contentRect.size.width;
|
|
|
|
const float yscale = fbRect.size.height / contentRect.size.height;
|
|
|
|
|
|
|
|
if (xscale != window->ns.xscale || yscale != window->ns.yscale)
|
|
|
|
{
|
|
|
|
window->ns.xscale = xscale;
|
|
|
|
window->ns.yscale = yscale;
|
|
|
|
_glfwInputWindowContentScale(window, xscale, yscale);
|
2018-03-20 13:33:35 -04:00
|
|
|
|
2019-03-27 12:07:44 -04:00
|
|
|
if (window->ns.retina && window->ns.layer)
|
2018-03-20 13:33:35 -04:00
|
|
|
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
|
2017-12-11 15:26:40 -05:00
|
|
|
}
|
2015-08-31 16:22:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)rect
|
|
|
|
{
|
2015-01-05 16:33:02 -05:00
|
|
|
_glfwInputWindowDamage(window);
|
2013-06-03 06:51:57 -04:00
|
|
|
}
|
|
|
|
|
2012-03-26 08:46:42 -04:00
|
|
|
- (void)updateTrackingAreas
|
|
|
|
{
|
|
|
|
if (trackingArea != nil)
|
|
|
|
{
|
|
|
|
[self removeTrackingArea:trackingArea];
|
|
|
|
[trackingArea release];
|
|
|
|
}
|
|
|
|
|
2014-12-29 13:00:53 -05:00
|
|
|
const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
|
|
|
|
NSTrackingActiveInKeyWindow |
|
2014-12-31 16:23:35 -05:00
|
|
|
NSTrackingEnabledDuringMouseDrag |
|
2014-12-29 13:00:53 -05:00
|
|
|
NSTrackingCursorUpdate |
|
|
|
|
NSTrackingInVisibleRect |
|
|
|
|
NSTrackingAssumeInside;
|
2012-03-26 08:46:42 -04:00
|
|
|
|
|
|
|
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
|
|
|
options:options
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
|
|
|
|
[self addTrackingArea:trackingArea];
|
2013-07-17 22:36:43 -04:00
|
|
|
[super updateTrackingAreas];
|
2012-03-26 08:46:42 -04:00
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
- (void)keyDown:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 11:19:12 -04:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
2014-06-12 17:04:20 -04:00
|
|
|
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
|
2012-12-09 13:19:00 -05:00
|
|
|
|
2018-12-24 17:41:29 -05:00
|
|
|
[self interpretKeyEvents:@[event]];
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)flagsChanged:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 11:19:12 -04:00
|
|
|
int action;
|
2014-06-17 05:29:34 -04:00
|
|
|
const unsigned int modifierFlags =
|
2016-10-08 19:39:31 -04:00
|
|
|
[event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask;
|
2014-06-17 05:29:34 -04:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags(modifierFlags);
|
2015-07-26 21:40:54 -04:00
|
|
|
const NSUInteger keyFlag = translateKeyToModifierFlag(key);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-07-26 21:40:54 -04:00
|
|
|
if (keyFlag & modifierFlags)
|
2014-06-17 05:29:34 -04:00
|
|
|
{
|
2014-06-18 15:07:54 -04:00
|
|
|
if (window->keys[key] == GLFW_PRESS)
|
2014-06-17 05:29:34 -04:00
|
|
|
action = GLFW_RELEASE;
|
|
|
|
else
|
|
|
|
action = GLFW_PRESS;
|
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
else
|
2013-04-21 15:54:33 -04:00
|
|
|
action = GLFW_RELEASE;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, key, [event keyCode], action, mods);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)event
|
|
|
|
{
|
2013-05-30 11:19:12 -04:00
|
|
|
const int key = translateKey([event keyCode]);
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
|
|
|
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)event
|
|
|
|
{
|
2019-06-04 10:51:31 -04:00
|
|
|
double deltaX = [event scrollingDeltaX];
|
|
|
|
double deltaY = [event scrollingDeltaY];
|
2013-07-17 22:36:43 -04:00
|
|
|
|
2015-10-18 13:15:36 -04:00
|
|
|
if ([event hasPreciseScrollingDeltas])
|
2013-07-17 22:36:43 -04:00
|
|
|
{
|
2015-10-18 13:15:36 -04:00
|
|
|
deltaX *= 0.1;
|
|
|
|
deltaY *= 0.1;
|
2013-07-17 22:36:43 -04:00
|
|
|
}
|
2012-03-28 16:39:48 -04:00
|
|
|
|
|
|
|
if (fabs(deltaX) > 0.0 || fabs(deltaY) > 0.0)
|
2014-10-26 08:53:45 -04:00
|
|
|
_glfwInputScroll(window, deltaX, deltaY);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2013-07-10 05:42:14 -04:00
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2018-11-19 16:27:51 -05:00
|
|
|
// HACK: We don't know what to say here because we don't know what the
|
|
|
|
// application wants to do with the paths
|
|
|
|
return NSDragOperationGeneric;
|
2013-07-10 05:42:14 -04:00
|
|
|
}
|
|
|
|
|
2013-12-22 10:38:56 -05:00
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2019-04-10 15:19:40 -04:00
|
|
|
// NOTE: The returned location uses base 0,1 not 0,0
|
|
|
|
const NSPoint pos = [sender draggingLocation];
|
|
|
|
_glfwInputCursorPos(window, pos.x, contentRect.size.height - pos.y);
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2018-11-19 16:27:51 -05:00
|
|
|
NSPasteboard* pasteboard = [sender draggingPasteboard];
|
|
|
|
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
|
|
|
|
NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
|
|
|
options:options];
|
|
|
|
const NSUInteger count = [urls count];
|
2013-12-22 13:28:46 -05:00
|
|
|
if (count)
|
2013-12-22 10:38:56 -05:00
|
|
|
{
|
2015-01-27 17:04:22 -05:00
|
|
|
char** paths = calloc(count, sizeof(char*));
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2018-11-19 16:27:51 -05:00
|
|
|
for (NSUInteger i = 0; i < count; i++)
|
2019-01-03 13:32:45 -05:00
|
|
|
paths[i] = _glfw_strdup([urls[i] fileSystemRepresentation]);
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2017-11-16 14:10:51 -05:00
|
|
|
_glfwInputDrop(window, (int) count, (const char**) paths);
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2018-11-19 16:27:51 -05:00
|
|
|
for (NSUInteger i = 0; i < count; i++)
|
2015-01-27 17:04:22 -05:00
|
|
|
free(paths[i]);
|
|
|
|
free(paths);
|
2013-12-22 10:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2013-07-10 05:42:14 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:19:20 -05:00
|
|
|
- (BOOL)hasMarkedText
|
|
|
|
{
|
2016-02-26 04:34:23 -05:00
|
|
|
return [markedText length] > 0;
|
2015-11-13 11:19:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)markedRange
|
|
|
|
{
|
2016-02-26 04:34:23 -05:00
|
|
|
if ([markedText length] > 0)
|
|
|
|
return NSMakeRange(0, [markedText length] - 1);
|
|
|
|
else
|
|
|
|
return kEmptyRange;
|
2015-11-13 11:19:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)selectedRange
|
|
|
|
{
|
|
|
|
return kEmptyRange;
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
- (void)setMarkedText:(id)string
|
2015-11-13 11:19:20 -05:00
|
|
|
selectedRange:(NSRange)selectedRange
|
|
|
|
replacementRange:(NSRange)replacementRange
|
|
|
|
{
|
2017-08-06 17:04:19 -04:00
|
|
|
[markedText release];
|
2016-02-26 04:34:23 -05:00
|
|
|
if ([string isKindOfClass:[NSAttributedString class]])
|
2017-08-06 17:04:19 -04:00
|
|
|
markedText = [[NSMutableAttributedString alloc] initWithAttributedString:string];
|
2015-11-13 11:19:20 -05:00
|
|
|
else
|
2017-08-06 17:04:19 -04:00
|
|
|
markedText = [[NSMutableAttributedString alloc] initWithString:string];
|
2015-11-13 11:19:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unmarkText
|
|
|
|
{
|
|
|
|
[[markedText mutableString] setString:@""];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)validAttributesForMarkedText
|
|
|
|
{
|
|
|
|
return [NSArray array];
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
|
2015-11-13 11:19:20 -05:00
|
|
|
actualRange:(NSRangePointer)actualRange
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point
|
2015-11-13 11:19:20 -05:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)range
|
2015-11-13 11:19:20 -05:00
|
|
|
actualRange:(NSRangePointer)actualRange
|
|
|
|
{
|
2019-04-10 15:19:40 -04:00
|
|
|
const NSRect frame = [window->ns.view frame];
|
|
|
|
return NSMakeRect(frame.origin.x, frame.origin.y, 0.0, 0.0);
|
2015-11-13 11:19:20 -05:00
|
|
|
}
|
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange
|
2015-11-13 11:19:20 -05:00
|
|
|
{
|
2016-02-26 04:34:23 -05:00
|
|
|
NSString* characters;
|
2015-11-13 11:19:20 -05:00
|
|
|
NSEvent* event = [NSApp currentEvent];
|
|
|
|
const int mods = translateFlags([event modifierFlags]);
|
2016-02-26 04:34:23 -05:00
|
|
|
const int plain = !(mods & GLFW_MOD_SUPER);
|
2015-11-13 11:19:20 -05:00
|
|
|
|
2016-02-26 04:34:23 -05:00
|
|
|
if ([string isKindOfClass:[NSAttributedString class]])
|
|
|
|
characters = [string string];
|
|
|
|
else
|
|
|
|
characters = (NSString*) string;
|
2015-11-13 11:19:20 -05:00
|
|
|
|
2019-06-04 10:51:31 -04:00
|
|
|
const NSUInteger length = [characters length];
|
|
|
|
for (NSUInteger i = 0; i < length; i++)
|
2015-11-13 11:19:20 -05:00
|
|
|
{
|
|
|
|
const unichar codepoint = [characters characterAtIndex:i];
|
|
|
|
if ((codepoint & 0xff00) == 0xf700)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_glfwInputChar(window, codepoint, mods, plain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 04:53:48 -05:00
|
|
|
- (void)doCommandBySelector:(SEL)selector
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
@end
|
|
|
|
|
2012-03-07 09:04:14 -05:00
|
|
|
|
2013-04-08 09:16:32 -04:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// GLFW window class
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@interface GLFWWindow : NSWindow {}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLFWWindow
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
2016-10-08 19:39:31 -04:00
|
|
|
// Required for NSWindowStyleMaskBorderless windows
|
2013-04-08 09:16:32 -04:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:23:59 -04:00
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-04-08 09:16:32 -04:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
2012-01-31 11:53:19 -05:00
|
|
|
// Create the Cocoa window
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2016-07-25 13:36:25 -04:00
|
|
|
static GLFWbool createNativeWindow(_GLFWwindow* window,
|
2017-09-18 12:10:57 -04:00
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-01-31 11:53:19 -05:00
|
|
|
{
|
2014-04-06 07:46:16 -04:00
|
|
|
window->ns.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
|
|
|
if (window->ns.delegate == nil)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to create window delegate");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2014-04-06 07:46:16 -04:00
|
|
|
}
|
|
|
|
|
2014-10-28 17:10:39 -04:00
|
|
|
NSRect contentRect;
|
|
|
|
|
2016-03-14 10:17:28 -04:00
|
|
|
if (window->monitor)
|
2015-09-01 12:33:34 -04:00
|
|
|
{
|
|
|
|
GLFWvidmode mode;
|
|
|
|
int xpos, ypos;
|
|
|
|
|
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
|
|
|
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
|
|
|
|
|
|
|
|
contentRect = NSMakeRect(xpos, ypos, mode.width, mode.height);
|
|
|
|
}
|
2014-10-28 17:10:39 -04:00
|
|
|
else
|
|
|
|
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
|
|
|
|
|
2013-04-07 21:07:52 -04:00
|
|
|
window->ns.object = [[GLFWWindow alloc]
|
2014-10-28 17:10:39 -04:00
|
|
|
initWithContentRect:contentRect
|
2016-02-23 06:26:42 -05:00
|
|
|
styleMask:getStyleMask(window)
|
2012-01-31 11:53:19 -05:00
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
if (window->ns.object == nil)
|
2012-01-31 11:53:19 -05:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-01-31 11:53:19 -05:00
|
|
|
}
|
|
|
|
|
2016-03-14 10:17:28 -04:00
|
|
|
if (window->monitor)
|
2014-10-28 17:10:39 -04:00
|
|
|
[window->ns.object setLevel:NSMainMenuWindowLevel + 1];
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:46:05 -05:00
|
|
|
[(NSWindow*) window->ns.object center];
|
2017-05-27 02:00:05 -04:00
|
|
|
_glfw.ns.cascadePoint =
|
|
|
|
NSPointToCGPoint([window->ns.object cascadeTopLeftFromPoint:
|
|
|
|
NSPointFromCGPoint(_glfw.ns.cascadePoint)]);
|
2014-10-28 17:10:39 -04:00
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
if (wndconfig->resizable)
|
2017-03-14 20:19:54 -04:00
|
|
|
{
|
|
|
|
const NSWindowCollectionBehavior behavior =
|
|
|
|
NSWindowCollectionBehaviorFullScreenPrimary |
|
|
|
|
NSWindowCollectionBehaviorManaged;
|
|
|
|
[window->ns.object setCollectionBehavior:behavior];
|
|
|
|
}
|
2016-02-23 06:26:42 -05:00
|
|
|
|
2014-10-28 17:10:39 -04:00
|
|
|
if (wndconfig->floating)
|
|
|
|
[window->ns.object setLevel:NSFloatingWindowLevel];
|
2015-10-13 06:50:59 -04:00
|
|
|
|
|
|
|
if (wndconfig->maximized)
|
|
|
|
[window->ns.object zoom:nil];
|
2014-10-28 17:10:39 -04:00
|
|
|
}
|
2014-05-23 08:01:02 -04:00
|
|
|
|
2017-12-12 10:45:38 -05:00
|
|
|
if (strlen(wndconfig->ns.frameName))
|
2019-01-03 13:32:45 -05:00
|
|
|
[window->ns.object setFrameAutosaveName:@(wndconfig->ns.frameName)];
|
2017-01-01 13:41:50 -05:00
|
|
|
|
2015-05-15 09:28:27 -04:00
|
|
|
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
|
2019-03-27 12:07:44 -04:00
|
|
|
window->ns.retina = wndconfig->ns.retina;
|
2015-05-15 09:28:27 -04:00
|
|
|
|
2017-09-18 12:10:57 -04:00
|
|
|
if (fbconfig->transparent)
|
2015-12-16 16:28:20 -05:00
|
|
|
{
|
|
|
|
[window->ns.object setOpaque:NO];
|
2019-03-05 13:25:21 -05:00
|
|
|
[window->ns.object setHasShadow:NO];
|
2015-12-16 16:28:20 -05:00
|
|
|
[window->ns.object setBackgroundColor:[NSColor clearColor]];
|
|
|
|
}
|
|
|
|
|
2016-10-15 08:25:42 -04:00
|
|
|
[window->ns.object setContentView:window->ns.view];
|
2016-03-16 09:48:53 -04:00
|
|
|
[window->ns.object makeFirstResponder:window->ns.view];
|
2019-01-03 13:32:45 -05:00
|
|
|
[window->ns.object setTitle:@(wndconfig->title)];
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object setDelegate:window->ns.delegate];
|
|
|
|
[window->ns.object setAcceptsMouseMovedEvents:YES];
|
2015-10-18 13:15:36 -04:00
|
|
|
[window->ns.object setRestorable:NO];
|
2019-03-27 15:04:43 -04:00
|
|
|
|
2019-01-17 18:41:47 -05:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
|
2019-03-27 15:04:43 -04:00
|
|
|
if ([window->ns.object respondsToSelector:@selector(setTabbingMode:)])
|
|
|
|
[window->ns.object setTabbingMode:NSWindowTabbingModeDisallowed];
|
2019-01-17 18:41:47 -05:00
|
|
|
#endif
|
2012-07-02 09:24:02 -04:00
|
|
|
|
2017-11-16 05:34:42 -05:00
|
|
|
_glfwPlatformGetWindowSize(window, &window->ns.width, &window->ns.height);
|
|
|
|
_glfwPlatformGetFramebufferSize(window, &window->ns.fbWidth, &window->ns.fbHeight);
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2012-01-31 11:53:19 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-03-07 09:04:14 -05:00
|
|
|
|
2019-03-05 11:41:32 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Transforms a y-coordinate between the CG display and NS screen spaces
|
|
|
|
//
|
|
|
|
float _glfwTransformYNS(float y)
|
|
|
|
{
|
2019-04-10 15:19:40 -04:00
|
|
|
return CGDisplayBounds(CGMainDisplayID()).size.height - y - 1;
|
2019-03-05 11:41:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-31 11:53:19 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-06 11:56:41 -04:00
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2014-03-06 14:05:32 -05:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2012-08-06 11:56:41 -04:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-01-31 11:53:19 -05:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2017-09-18 12:10:57 -04:00
|
|
|
if (!createNativeWindow(window, wndconfig, fbconfig))
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-01-31 11:53:19 -05:00
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
if (ctxconfig->client != GLFW_NO_API)
|
2015-06-18 08:03:02 -04:00
|
|
|
{
|
2016-03-28 07:19:31 -04:00
|
|
|
if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
|
|
|
|
{
|
2016-07-20 06:52:06 -04:00
|
|
|
if (!_glfwInitNSGL())
|
|
|
|
return GLFW_FALSE;
|
2016-03-28 07:19:31 -04:00
|
|
|
if (!_glfwCreateContextNSGL(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2017-02-28 13:23:25 -05:00
|
|
|
else if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
|
2016-03-28 07:19:31 -04:00
|
|
|
{
|
2020-04-19 08:10:52 -04:00
|
|
|
// EGL implementation on macOS use CALayer* EGLNativeWindowType so we
|
|
|
|
// need to get the layer for EGL window surface creation.
|
|
|
|
[window->ns.view setWantsLayer:YES];
|
|
|
|
window->ns.layer = [window->ns.view layer];
|
|
|
|
|
2017-01-02 09:32:55 -05:00
|
|
|
if (!_glfwInitEGL())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
2016-03-28 07:19:31 -04:00
|
|
|
}
|
2017-02-28 13:23:25 -05:00
|
|
|
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
|
|
|
|
{
|
|
|
|
if (!_glfwInitOSMesa())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2015-06-18 08:03:02 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2016-03-14 10:17:28 -04:00
|
|
|
if (window->monitor)
|
2014-10-28 17:10:39 -04:00
|
|
|
{
|
|
|
|
_glfwPlatformShowWindow(window);
|
2016-02-23 06:26:42 -05:00
|
|
|
_glfwPlatformFocusWindow(window);
|
2018-02-05 11:11:04 -05:00
|
|
|
acquireMonitor(window);
|
2014-10-28 17:10:39 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-08-06 11:56:41 -04:00
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-05-30 15:21:09 -04:00
|
|
|
if (_glfw.ns.disabledCursorWindow == window)
|
|
|
|
_glfw.ns.disabledCursorWindow = NULL;
|
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object orderOut:nil];
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2016-02-23 06:34:35 -05:00
|
|
|
releaseMonitor(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2016-08-05 05:22:55 -04:00
|
|
|
if (window->context.destroy)
|
2016-05-25 08:43:51 -04:00
|
|
|
window->context.destroy(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object setDelegate:nil];
|
|
|
|
[window->ns.delegate release];
|
|
|
|
window->ns.delegate = nil;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.view release];
|
|
|
|
window->ns.view = nil;
|
2012-03-26 09:29:01 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object close];
|
|
|
|
window->ns.object = nil;
|
2016-03-18 07:01:48 -04:00
|
|
|
|
2019-11-06 17:34:08 -05:00
|
|
|
// HACK: Allow Cocoa to catch up before returning
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2019-12-11 16:10:00 -05:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2019-12-10 07:47:19 -05:00
|
|
|
NSString* string = @(title);
|
|
|
|
[window->ns.object setTitle:string];
|
2017-09-28 12:44:04 -04:00
|
|
|
// HACK: Set the miniwindow title explicitly as setTitle: doesn't update it
|
|
|
|
// if the window lacks NSWindowStyleMaskTitled
|
2019-12-10 07:47:19 -05:00
|
|
|
[window->ns.object setMiniwindowTitle:string];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:55:30 -05:00
|
|
|
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
|
|
|
|
int count, const GLFWimage* images)
|
|
|
|
{
|
2020-05-20 12:02:58 -04:00
|
|
|
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
|
|
|
|
"Cocoa: Regular windows do not have icons on macOS");
|
2016-03-07 08:55:30 -05:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:30:31 -05:00
|
|
|
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2013-01-24 13:30:31 -05:00
|
|
|
const NSRect contentRect =
|
|
|
|
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = contentRect.origin.x;
|
|
|
|
if (ypos)
|
2019-04-10 15:19:40 -04:00
|
|
|
*ypos = _glfwTransformYNS(contentRect.origin.y + contentRect.size.height - 1);
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2013-01-24 13:30:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2013-07-09 11:08:26 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2019-04-10 15:19:40 -04:00
|
|
|
const NSRect dummyRect = NSMakeRect(x, _glfwTransformYNS(y + contentRect.size.height - 1), 0, 0);
|
2013-07-09 11:08:26 -04:00
|
|
|
const NSRect frameRect = [window->ns.object frameRectForContentRect:dummyRect];
|
2013-01-24 13:30:31 -05:00
|
|
|
[window->ns.object setFrameOrigin:frameRect.origin];
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2013-01-24 13:30:31 -05:00
|
|
|
}
|
|
|
|
|
2012-11-25 08:53:33 -05:00
|
|
|
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2013-06-03 19:51:40 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2012-11-25 08:53:33 -05:00
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = contentRect.size.width;
|
|
|
|
if (height)
|
|
|
|
*height = contentRect.size.height;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2012-11-25 08:53:33 -05:00
|
|
|
}
|
|
|
|
|
2010-09-15 12:57:25 -04:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2015-01-18 20:37:15 -05:00
|
|
|
if (window->monitor)
|
2016-02-23 06:26:42 -05:00
|
|
|
{
|
|
|
|
if (window->monitor->window == window)
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
2015-01-18 20:37:15 -05:00
|
|
|
else
|
2019-08-29 16:08:29 -04:00
|
|
|
{
|
|
|
|
NSRect contentRect =
|
|
|
|
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
|
|
|
contentRect.origin.y += contentRect.size.height - height;
|
|
|
|
contentRect.size = NSMakeSize(width, height);
|
|
|
|
[window->ns.object setFrame:[window->ns.object frameRectForContentRect:contentRect]
|
|
|
|
display:YES];
|
|
|
|
}
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2014-02-12 20:57:59 -05:00
|
|
|
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|
|
|
int minwidth, int minheight,
|
|
|
|
int maxwidth, int maxheight)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-02-12 20:57:59 -05:00
|
|
|
if (minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE)
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(0, 0)];
|
|
|
|
else
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(minwidth, minheight)];
|
|
|
|
|
|
|
|
if (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE)
|
2016-03-16 10:05:50 -04:00
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(DBL_MAX, DBL_MAX)];
|
2014-02-12 20:57:59 -05:00
|
|
|
else
|
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(maxwidth, maxheight)];
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-02-12 20:57:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-02-12 20:57:59 -05:00
|
|
|
if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE)
|
2016-08-31 19:23:22 -04:00
|
|
|
[window->ns.object setResizeIncrements:NSMakeSize(1.0, 1.0)];
|
2014-02-12 20:57:59 -05:00
|
|
|
else
|
|
|
|
[window->ns.object setContentAspectRatio:NSMakeSize(numer, denom)];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2014-02-12 20:57:59 -05:00
|
|
|
}
|
|
|
|
|
2013-06-03 06:51:57 -04:00
|
|
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2013-06-16 12:32:16 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2015-10-18 13:15:36 -04:00
|
|
|
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
|
2013-06-16 12:32:16 -04:00
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = (int) fbRect.size.width;
|
|
|
|
if (height)
|
|
|
|
*height = (int) fbRect.size.height;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2013-06-03 06:51:57 -04:00
|
|
|
}
|
|
|
|
|
2014-03-25 16:30:13 -04:00
|
|
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|
|
|
int* left, int* top,
|
|
|
|
int* right, int* bottom)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-03-25 16:30:13 -04:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
|
|
|
const NSRect frameRect = [window->ns.object frameRectForContentRect:contentRect];
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
*left = contentRect.origin.x - frameRect.origin.x;
|
|
|
|
if (top)
|
|
|
|
*top = frameRect.origin.y + frameRect.size.height -
|
|
|
|
contentRect.origin.y - contentRect.size.height;
|
|
|
|
if (right)
|
|
|
|
*right = frameRect.origin.x + frameRect.size.width -
|
|
|
|
contentRect.origin.x - contentRect.size.width;
|
|
|
|
if (bottom)
|
|
|
|
*bottom = contentRect.origin.y - frameRect.origin.y;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-03-25 16:30:13 -04:00
|
|
|
}
|
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
|
|
|
|
float* xscale, float* yscale)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
const NSRect points = [window->ns.view frame];
|
|
|
|
const NSRect pixels = [window->ns.view convertRectToBacking:points];
|
|
|
|
|
|
|
|
if (xscale)
|
|
|
|
*xscale = (float) (pixels.size.width / points.size.width);
|
|
|
|
if (yscale)
|
|
|
|
*yscale = (float) (pixels.size.height / points.size.height);
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2017-08-29 13:19:00 -04:00
|
|
|
}
|
|
|
|
|
2010-09-15 12:57:25 -04:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object miniaturize:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-15 12:57:25 -04:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2015-10-13 06:50:59 -04:00
|
|
|
if ([window->ns.object isMiniaturized])
|
|
|
|
[window->ns.object deminiaturize:nil];
|
|
|
|
else if ([window->ns.object isZoomed])
|
|
|
|
[window->ns.object zoom:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2015-10-13 06:50:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2015-10-13 06:50:59 -04:00
|
|
|
if (![window->ns.object isZoomed])
|
|
|
|
[window->ns.object zoom:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-08-21 14:01:57 -04:00
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
2016-02-21 09:42:49 -05:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2016-02-21 09:42:49 -05:00
|
|
|
[window->ns.object orderFront:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2016-02-21 09:42:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2016-02-21 09:42:49 -05:00
|
|
|
[window->ns.object orderOut:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2016-02-21 09:42:49 -05:00
|
|
|
}
|
|
|
|
|
2017-03-21 09:02:57 -04:00
|
|
|
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2017-03-21 09:02:57 -04:00
|
|
|
[NSApp requestUserAttention:NSInformationalRequest];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2017-03-21 09:02:57 -04:00
|
|
|
}
|
|
|
|
|
2016-02-21 09:42:49 -05:00
|
|
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
2012-08-21 14:01:57 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2013-11-07 12:07:46 -05:00
|
|
|
// Make us the active application
|
2019-01-10 19:05:00 -05:00
|
|
|
// HACK: This is here to prevent applications using only hidden windows from
|
|
|
|
// being activated, but should probably not be done every time any
|
|
|
|
// window is shown
|
2013-11-07 12:07:46 -05:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2013-01-01 19:40:42 -05:00
|
|
|
[window->ns.object makeKeyAndOrderFront:nil];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2012-08-21 14:01:57 -04:00
|
|
|
}
|
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
|
|
|
_GLFWmonitor* monitor,
|
|
|
|
int xpos, int ypos,
|
|
|
|
int width, int height,
|
|
|
|
int refreshRate)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
if (window->monitor == monitor)
|
|
|
|
{
|
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
if (monitor->window == window)
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const NSRect contentRect =
|
2019-04-10 15:19:40 -04:00
|
|
|
NSMakeRect(xpos, _glfwTransformYNS(ypos + height - 1), width, height);
|
2016-02-23 06:26:42 -05:00
|
|
|
const NSRect frameRect =
|
|
|
|
[window->ns.object frameRectForContentRect:contentRect
|
|
|
|
styleMask:getStyleMask(window)];
|
|
|
|
|
|
|
|
[window->ns.object setFrame:frameRect display:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->monitor)
|
|
|
|
releaseMonitor(window);
|
|
|
|
|
2017-10-26 12:05:56 -04:00
|
|
|
_glfwInputWindowMonitor(window, monitor);
|
2016-02-23 06:26:42 -05:00
|
|
|
|
2017-03-14 16:21:29 -04:00
|
|
|
// HACK: Allow the state cached in Cocoa to catch up to reality
|
|
|
|
// TODO: Solve this in a less terrible way
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
const NSUInteger styleMask = getStyleMask(window);
|
|
|
|
[window->ns.object setStyleMask:styleMask];
|
2018-02-05 11:56:37 -05:00
|
|
|
// HACK: Changing the style mask can cause the first responder to be cleared
|
2016-02-23 06:26:42 -05:00
|
|
|
[window->ns.object makeFirstResponder:window->ns.view];
|
|
|
|
|
2019-06-06 10:02:41 -04:00
|
|
|
if (window->monitor)
|
2016-02-23 06:26:42 -05:00
|
|
|
{
|
|
|
|
[window->ns.object setLevel:NSMainMenuWindowLevel + 1];
|
|
|
|
[window->ns.object setHasShadow:NO];
|
|
|
|
|
|
|
|
acquireMonitor(window);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-10 15:19:40 -04:00
|
|
|
NSRect contentRect = NSMakeRect(xpos, _glfwTransformYNS(ypos + height - 1),
|
2017-11-16 04:42:01 -05:00
|
|
|
width, height);
|
|
|
|
NSRect frameRect = [window->ns.object frameRectForContentRect:contentRect
|
|
|
|
styleMask:styleMask];
|
|
|
|
[window->ns.object setFrame:frameRect display:YES];
|
|
|
|
|
2016-02-23 06:26:42 -05:00
|
|
|
if (window->numer != GLFW_DONT_CARE &&
|
|
|
|
window->denom != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentAspectRatio:NSMakeSize(window->numer,
|
|
|
|
window->denom)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->minwidth != GLFW_DONT_CARE &&
|
|
|
|
window->minheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentMinSize:NSMakeSize(window->minwidth,
|
|
|
|
window->minheight)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->maxwidth != GLFW_DONT_CARE &&
|
|
|
|
window->maxheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
[window->ns.object setContentMaxSize:NSMakeSize(window->maxwidth,
|
|
|
|
window->maxheight)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->floating)
|
|
|
|
[window->ns.object setLevel:NSFloatingWindowLevel];
|
|
|
|
else
|
|
|
|
[window->ns.object setLevel:NSNormalWindowLevel];
|
|
|
|
|
|
|
|
[window->ns.object setHasShadow:YES];
|
2017-09-28 12:44:04 -04:00
|
|
|
// HACK: Clearing NSWindowStyleMaskTitled resets and disables the window
|
|
|
|
// title property but the miniwindow title property is unaffected
|
|
|
|
[window->ns.object setTitle:[window->ns.object miniwindowTitle]];
|
2016-02-23 06:26:42 -05:00
|
|
|
}
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2016-02-23 06:26:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 06:25:48 -05:00
|
|
|
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-12-26 06:25:48 -05:00
|
|
|
return [window->ns.object isKeyWindow];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2014-12-26 06:25:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-12-26 06:25:48 -05:00
|
|
|
return [window->ns.object isMiniaturized];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2014-12-26 06:25:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-12-26 06:25:48 -05:00
|
|
|
return [window->ns.object isVisible];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2012-08-21 14:01:57 -04:00
|
|
|
}
|
|
|
|
|
2015-10-13 06:50:59 -04:00
|
|
|
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2015-10-13 06:50:59 -04:00
|
|
|
return [window->ns.object isZoomed];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2015-10-13 06:50:59 -04:00
|
|
|
}
|
|
|
|
|
2018-01-04 07:50:58 -05:00
|
|
|
int _glfwPlatformWindowHovered(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2018-01-04 07:50:58 -05:00
|
|
|
const NSPoint point = [NSEvent mouseLocation];
|
|
|
|
|
|
|
|
if ([NSWindow windowNumberAtPoint:point belowWindowWithWindowNumber:0] !=
|
|
|
|
[window->ns.object windowNumber])
|
|
|
|
{
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-14 18:06:56 -04:00
|
|
|
return NSMouseInRect(point,
|
|
|
|
[window->ns.object convertRectToScreen:[window->ns.view frame]], NO);
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2018-01-04 07:50:58 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:10:57 -04:00
|
|
|
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2017-09-18 12:10:57 -04:00
|
|
|
return ![window->ns.object isOpaque] && ![window->ns.view isOpaque];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2017-09-18 12:10:57 -04:00
|
|
|
}
|
|
|
|
|
2016-09-29 19:52:22 -04:00
|
|
|
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2016-09-29 19:52:22 -04:00
|
|
|
[window->ns.object setStyleMask:getStyleMask(window)];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2016-09-29 19:52:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2016-09-29 19:52:22 -04:00
|
|
|
[window->ns.object setStyleMask:getStyleMask(window)];
|
|
|
|
[window->ns.object makeFirstResponder:window->ns.view];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2016-09-29 19:52:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2016-09-29 19:52:22 -04:00
|
|
|
if (enabled)
|
|
|
|
[window->ns.object setLevel:NSFloatingWindowLevel];
|
|
|
|
else
|
|
|
|
[window->ns.object setLevel:NSNormalWindowLevel];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2016-09-29 19:52:22 -04:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:14:45 -04:00
|
|
|
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2017-09-25 17:14:45 -04:00
|
|
|
return (float) [window->ns.object alphaValue];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2017-09-25 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2017-09-25 17:14:45 -04:00
|
|
|
[window->ns.object setAlphaValue:opacity];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2017-09-25 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
2019-02-11 13:10:20 -05:00
|
|
|
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
2018-12-13 21:08:25 -05:00
|
|
|
{
|
2020-05-20 12:02:58 -04:00
|
|
|
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
|
|
|
|
"Cocoa: Raw mouse motion not yet implemented");
|
2018-12-13 21:08:25 -05:00
|
|
|
}
|
|
|
|
|
2019-02-11 13:10:20 -05:00
|
|
|
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
2018-12-13 21:08:25 -05:00
|
|
|
{
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-15 12:57:25 -04:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2012-10-21 10:17:20 -04:00
|
|
|
for (;;)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2016-10-08 19:39:31 -04:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
2012-10-21 10:17:20 -04:00
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
if (event == nil)
|
|
|
|
break;
|
|
|
|
|
|
|
|
[NSApp sendEvent:event];
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-10-04 23:42:47 -04:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
// I wanted to pass NO to dequeue:, and rely on PollEvents to
|
|
|
|
// dequeue and send. For reasons not at all clear to me, passing
|
|
|
|
// NO to dequeue: causes this method never to return.
|
2016-10-08 19:39:31 -04:00
|
|
|
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
2010-09-07 11:34:51 -04:00
|
|
|
untilDate:[NSDate distantFuture]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2016-02-02 15:11:16 -05:00
|
|
|
void _glfwPlatformWaitEventsTimeout(double timeout)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-02-02 15:11:16 -05:00
|
|
|
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout];
|
2016-10-08 19:39:31 -04:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
2016-02-02 15:11:16 -05:00
|
|
|
untilDate:date
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
if (event)
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2016-02-02 15:11:16 -05:00
|
|
|
}
|
|
|
|
|
2014-02-10 12:16:58 -05:00
|
|
|
void _glfwPlatformPostEmptyEvent(void)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-10-08 19:39:31 -04:00
|
|
|
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
|
2014-02-10 12:16:58 -05:00
|
|
|
location:NSMakePoint(0, 0)
|
|
|
|
modifierFlags:0
|
|
|
|
timestamp:0
|
|
|
|
windowNumber:0
|
|
|
|
context:nil
|
|
|
|
subtype:0
|
|
|
|
data1:0
|
|
|
|
data2:0];
|
|
|
|
[NSApp postEvent:event atStart:YES];
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-02-10 12:16:58 -05:00
|
|
|
}
|
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2019-04-10 15:19:40 -04:00
|
|
|
// NOTE: The returned location uses base 0,1 not 0,0
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
2019-04-10 15:19:40 -04:00
|
|
|
*ypos = contentRect.size.height - pos.y;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-02-11 12:24:01 -05:00
|
|
|
}
|
|
|
|
|
2013-03-27 19:30:08 -04:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-05-30 15:21:09 -04:00
|
|
|
updateCursorImage(window);
|
2013-10-09 13:03:47 -04:00
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSRect contentRect = [window->ns.view frame];
|
2019-04-10 15:19:40 -04:00
|
|
|
// NOTE: The returned location uses base 0,1 not 0,0
|
2014-02-11 12:24:01 -05:00
|
|
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
|
|
|
|
2016-05-24 06:23:58 -04:00
|
|
|
window->ns.cursorWarpDeltaX += x - pos.x;
|
|
|
|
window->ns.cursorWarpDeltaY += y - contentRect.size.height + pos.y;
|
2014-02-11 12:24:01 -05:00
|
|
|
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2012-07-02 09:23:36 -04:00
|
|
|
{
|
2013-05-22 12:03:54 -04:00
|
|
|
CGDisplayMoveCursorToPoint(window->monitor->ns.displayID,
|
|
|
|
CGPointMake(x, y));
|
2012-07-02 09:23:36 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 13:38:32 -04:00
|
|
|
const NSRect localRect = NSMakeRect(x, contentRect.size.height - y - 1, 0, 0);
|
|
|
|
const NSRect globalRect = [window->ns.object convertRectToScreen:localRect];
|
|
|
|
const NSPoint globalPoint = globalRect.origin;
|
2013-05-22 12:03:54 -04:00
|
|
|
|
|
|
|
CGWarpMouseCursorPosition(CGPointMake(globalPoint.x,
|
2019-03-05 11:41:32 -05:00
|
|
|
_glfwTransformYNS(globalPoint.y)));
|
2012-07-02 09:23:36 -04:00
|
|
|
}
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 07:04:56 -04:00
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
2011-09-06 11:38:00 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2018-04-17 13:54:36 -04:00
|
|
|
if (_glfwPlatformWindowFocused(window))
|
|
|
|
updateCursorMode(window);
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2011-09-06 11:38:00 -04:00
|
|
|
}
|
|
|
|
|
2017-07-11 17:00:17 -04:00
|
|
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
2015-07-02 08:24:50 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2020-01-15 10:34:58 -05:00
|
|
|
if (scancode < 0 || scancode > 0xff ||
|
|
|
|
_glfw.ns.keycodes[scancode] == GLFW_KEY_UNKNOWN)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-22 15:31:46 -04:00
|
|
|
const int key = _glfw.ns.keycodes[scancode];
|
|
|
|
|
2015-07-02 08:24:50 -04:00
|
|
|
UInt32 deadKeyState = 0;
|
2019-08-22 15:31:46 -04:00
|
|
|
UniChar characters[4];
|
2015-07-02 08:24:50 -04:00
|
|
|
UniCharCount characterCount = 0;
|
|
|
|
|
|
|
|
if (UCKeyTranslate([(NSData*) _glfw.ns.unicodeData bytes],
|
|
|
|
scancode,
|
|
|
|
kUCKeyActionDisplay,
|
|
|
|
0,
|
|
|
|
LMGetKbdType(),
|
|
|
|
kUCKeyTranslateNoDeadKeysBit,
|
|
|
|
&deadKeyState,
|
|
|
|
sizeof(characters) / sizeof(characters[0]),
|
|
|
|
&characterCount,
|
|
|
|
characters) != noErr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!characterCount)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CFStringRef string = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
|
|
|
|
characters,
|
|
|
|
characterCount,
|
|
|
|
kCFAllocatorNull);
|
|
|
|
CFStringGetCString(string,
|
2019-08-22 15:31:46 -04:00
|
|
|
_glfw.ns.keynames[key],
|
|
|
|
sizeof(_glfw.ns.keynames[key]),
|
2015-07-02 08:24:50 -04:00
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(string);
|
|
|
|
|
2019-08-22 15:31:46 -04:00
|
|
|
return _glfw.ns.keynames[key];
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2015-07-02 08:24:50 -04:00
|
|
|
}
|
|
|
|
|
2016-09-06 09:40:31 -04:00
|
|
|
int _glfwPlatformGetKeyScancode(int key)
|
2016-08-11 13:11:40 -04:00
|
|
|
{
|
2016-09-07 09:43:39 -04:00
|
|
|
return _glfw.ns.scancodes[key];
|
2016-08-11 13:11:40 -04:00
|
|
|
}
|
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|
|
|
const GLFWimage* image,
|
|
|
|
int xhot, int yhot)
|
2013-12-04 08:19:22 -05:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
NSImage* native;
|
2013-12-04 08:19:22 -05:00
|
|
|
NSBitmapImageRep* rep;
|
|
|
|
|
|
|
|
rep = [[NSBitmapImageRep alloc]
|
|
|
|
initWithBitmapDataPlanes:NULL
|
2014-02-23 10:43:17 -05:00
|
|
|
pixelsWide:image->width
|
|
|
|
pixelsHigh:image->height
|
2013-12-04 08:19:22 -05:00
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSCalibratedRGBColorSpace
|
2018-10-26 06:56:02 -04:00
|
|
|
bitmapFormat:NSBitmapFormatAlphaNonpremultiplied
|
2014-02-23 10:43:17 -05:00
|
|
|
bytesPerRow:image->width * 4
|
2013-12-04 08:19:22 -05:00
|
|
|
bitsPerPixel:32];
|
|
|
|
|
|
|
|
if (rep == nil)
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
memcpy([rep bitmapData], image->pixels, image->width * image->height * 4);
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
native = [[NSImage alloc] initWithSize:NSMakeSize(image->width, image->height)];
|
2016-08-02 09:39:01 -04:00
|
|
|
[native addRepresentation:rep];
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
cursor->ns.object = [[NSCursor alloc] initWithImage:native
|
2014-01-23 09:24:57 -05:00
|
|
|
hotSpot:NSMakePoint(xhot, yhot)];
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
[native release];
|
2013-12-04 08:19:22 -05:00
|
|
|
[rep release];
|
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
if (cursor->ns.object == nil)
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
2014-09-02 10:52:16 -04:00
|
|
|
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2019-05-07 14:40:37 -04:00
|
|
|
SEL cursorSelector = NULL;
|
|
|
|
|
|
|
|
// HACK: Try to use a private message
|
|
|
|
if (shape == GLFW_RESIZE_EW_CURSOR)
|
2019-12-20 02:10:56 -05:00
|
|
|
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
|
2019-05-07 14:40:37 -04:00
|
|
|
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
2019-12-20 02:10:56 -05:00
|
|
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
|
2019-05-07 14:40:37 -04:00
|
|
|
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
2019-12-20 02:10:56 -05:00
|
|
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
|
2019-05-07 14:40:37 -04:00
|
|
|
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
2019-12-20 02:10:56 -05:00
|
|
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
|
2019-05-07 14:40:37 -04:00
|
|
|
|
|
|
|
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
|
|
|
|
{
|
|
|
|
id object = [NSCursor performSelector:cursorSelector];
|
|
|
|
if ([object isKindOfClass:[NSCursor class]])
|
|
|
|
cursor->ns.object = object;
|
|
|
|
}
|
2017-02-26 16:22:53 -05:00
|
|
|
|
2014-09-02 10:52:16 -04:00
|
|
|
if (!cursor->ns.object)
|
|
|
|
{
|
2019-05-07 14:40:37 -04:00
|
|
|
if (shape == GLFW_ARROW_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor arrowCursor];
|
|
|
|
else if (shape == GLFW_IBEAM_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor IBeamCursor];
|
|
|
|
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor crosshairCursor];
|
|
|
|
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor pointingHandCursor];
|
|
|
|
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor resizeLeftRightCursor];
|
|
|
|
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor resizeUpDownCursor];
|
|
|
|
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor closedHandCursor];
|
|
|
|
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
|
|
|
cursor->ns.object = [NSCursor operationNotAllowedCursor];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cursor->ns.object)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
|
|
|
"Cocoa: Standard cursor shape unavailable");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2014-09-02 10:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
[cursor->ns.object retain];
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-09-02 10:52:16 -04:00
|
|
|
}
|
|
|
|
|
2013-12-04 08:19:22 -05:00
|
|
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-01-23 09:24:57 -05:00
|
|
|
if (cursor->ns.object)
|
|
|
|
[(NSCursor*) cursor->ns.object release];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2019-01-22 14:54:16 -05:00
|
|
|
if (cursorInContentArea(window))
|
2016-05-30 15:21:09 -04:00
|
|
|
updateCursorImage(window);
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
2017-11-04 16:11:58 -04:00
|
|
|
void _glfwPlatformSetClipboardString(const char* string)
|
2014-09-09 10:26:57 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
2014-09-09 10:26:57 -04:00
|
|
|
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
2018-12-24 17:41:29 -05:00
|
|
|
[pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil];
|
2019-01-03 13:32:45 -05:00
|
|
|
[pasteboard setString:@(string) forType:NSPasteboardTypeString];
|
2019-03-05 13:05:57 -05:00
|
|
|
} // autoreleasepool
|
2014-09-09 10:26:57 -04:00
|
|
|
}
|
|
|
|
|
2017-11-04 16:11:58 -04:00
|
|
|
const char* _glfwPlatformGetClipboardString(void)
|
2014-09-09 10:26:57 -04:00
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-09-09 10:26:57 -04:00
|
|
|
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
|
|
|
2018-10-26 06:56:02 -04:00
|
|
|
if (![[pasteboard types] containsObject:NSPasteboardTypeString])
|
2014-09-09 10:26:57 -04:00
|
|
|
{
|
2015-03-10 14:51:14 -04:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"Cocoa: Failed to retrieve string from pasteboard");
|
2014-09-09 10:26:57 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-26 06:56:02 -04:00
|
|
|
NSString* object = [pasteboard stringForType:NSPasteboardTypeString];
|
2014-09-09 10:26:57 -04:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to retrieve object from pasteboard");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(_glfw.ns.clipboardString);
|
2018-01-17 05:56:35 -05:00
|
|
|
_glfw.ns.clipboardString = _glfw_strdup([object UTF8String]);
|
2014-09-09 10:26:57 -04:00
|
|
|
|
|
|
|
return _glfw.ns.clipboardString;
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2014-09-09 10:26:57 -04:00
|
|
|
}
|
|
|
|
|
2020-06-25 12:22:08 -04:00
|
|
|
EGLenum _glfwPlatformGetEGLPlatform(EGLint** attribs)
|
2020-06-03 16:02:25 -04:00
|
|
|
{
|
2020-06-25 12:22:08 -04:00
|
|
|
if (_glfw.egl.ANGLE_platform_angle)
|
|
|
|
{
|
|
|
|
int type = 0;
|
|
|
|
|
|
|
|
if (_glfw.egl.ANGLE_platform_angle_opengl)
|
|
|
|
{
|
|
|
|
if (_glfw.hints.init.angleType == GLFW_ANGLE_PLATFORM_TYPE_OPENGL)
|
|
|
|
type = EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfw.egl.ANGLE_platform_angle_metal)
|
|
|
|
{
|
|
|
|
if (_glfw.hints.init.angleType == GLFW_ANGLE_PLATFORM_TYPE_METAL)
|
|
|
|
type = EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
*attribs = calloc(3, sizeof(EGLint));
|
|
|
|
(*attribs)[0] = EGL_PLATFORM_ANGLE_TYPE_ANGLE;
|
|
|
|
(*attribs)[1] = type;
|
|
|
|
(*attribs)[2] = EGL_NONE;
|
|
|
|
return EGL_PLATFORM_ANGLE_ANGLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 16:02:25 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:49:36 -04:00
|
|
|
EGLNativeDisplayType _glfwPlatformGetEGLNativeDisplay(void)
|
|
|
|
{
|
|
|
|
return EGL_DEFAULT_DISPLAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return window->ns.layer;
|
|
|
|
}
|
|
|
|
|
2016-08-22 14:25:52 -04:00
|
|
|
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
2015-08-10 14:19:04 -04:00
|
|
|
{
|
2020-01-15 19:52:50 -05:00
|
|
|
if (_glfw.vk.KHR_surface && _glfw.vk.EXT_metal_surface)
|
|
|
|
{
|
|
|
|
extensions[0] = "VK_KHR_surface";
|
|
|
|
extensions[1] = "VK_EXT_metal_surface";
|
|
|
|
}
|
|
|
|
else if (_glfw.vk.KHR_surface && _glfw.vk.MVK_macos_surface)
|
|
|
|
{
|
|
|
|
extensions[0] = "VK_KHR_surface";
|
|
|
|
extensions[1] = "VK_MVK_macos_surface";
|
|
|
|
}
|
2015-08-10 14:19:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
|
|
|
VkPhysicalDevice device,
|
2016-03-23 05:24:01 -04:00
|
|
|
uint32_t queuefamily)
|
2015-08-10 14:19:04 -04:00
|
|
|
{
|
2016-10-13 19:46:56 -04:00
|
|
|
return GLFW_TRUE;
|
2015-08-10 14:19:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|
|
|
_GLFWwindow* window,
|
|
|
|
const VkAllocationCallbacks* allocator,
|
|
|
|
VkSurfaceKHR* surface)
|
|
|
|
{
|
2019-03-05 13:05:57 -05:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-10-13 19:46:56 -04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
|
|
|
// HACK: Dynamically load Core Animation to avoid adding an extra
|
|
|
|
// dependency for the majority who don't use MoltenVK
|
|
|
|
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
|
|
|
|
if (!bundle)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to find QuartzCore.framework");
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Create the layer here as makeBackingLayer should not return nil
|
|
|
|
window->ns.layer = [[bundle classNamed:@"CAMetalLayer"] layer];
|
|
|
|
if (!window->ns.layer)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to create layer for view");
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:07:44 -04:00
|
|
|
if (window->ns.retina)
|
|
|
|
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
|
|
|
|
|
2019-03-27 11:28:16 -04:00
|
|
|
[window->ns.view setLayer:window->ns.layer];
|
2016-10-13 19:46:56 -04:00
|
|
|
[window->ns.view setWantsLayer:YES];
|
|
|
|
|
2020-01-15 19:52:50 -05:00
|
|
|
VkResult err;
|
|
|
|
|
|
|
|
if (_glfw.vk.EXT_metal_surface)
|
|
|
|
{
|
|
|
|
VkMetalSurfaceCreateInfoEXT sci;
|
2016-10-13 19:46:56 -04:00
|
|
|
|
2020-01-15 19:52:50 -05:00
|
|
|
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT;
|
|
|
|
vkCreateMetalSurfaceEXT = (PFN_vkCreateMetalSurfaceEXT)
|
|
|
|
vkGetInstanceProcAddr(instance, "vkCreateMetalSurfaceEXT");
|
|
|
|
if (!vkCreateMetalSurfaceEXT)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"Cocoa: Vulkan instance missing VK_EXT_metal_surface extension");
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
2020-01-05 10:46:42 -05:00
|
|
|
|
2020-01-15 19:52:50 -05:00
|
|
|
memset(&sci, 0, sizeof(sci));
|
|
|
|
sci.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
|
|
|
|
sci.pLayer = window->ns.layer;
|
|
|
|
|
|
|
|
err = vkCreateMetalSurfaceEXT(instance, &sci, allocator, surface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VkMacOSSurfaceCreateInfoMVK sci;
|
|
|
|
|
|
|
|
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK;
|
|
|
|
vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
|
|
|
|
vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
|
|
|
|
if (!vkCreateMacOSSurfaceMVK)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"Cocoa: Vulkan instance missing VK_MVK_macos_surface extension");
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&sci, 0, sizeof(sci));
|
|
|
|
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
|
|
|
sci.pView = window->ns.view;
|
|
|
|
|
|
|
|
err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface);
|
|
|
|
}
|
2020-01-05 10:46:42 -05:00
|
|
|
|
2016-10-13 19:46:56 -04:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Cocoa: Failed to create Vulkan surface: %s",
|
|
|
|
_glfwGetVulkanResultString(err));
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
#else
|
2015-08-10 14:19:04 -04:00
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
2016-10-13 19:46:56 -04:00
|
|
|
#endif
|
2019-03-05 13:05:57 -05:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2015-08-10 14:19:04 -04:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:38:14 -05:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 18:28:08 -05:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
|
2013-01-15 16:38:14 -05:00
|
|
|
return window->ns.object;
|
|
|
|
}
|
|
|
|
|