Commit Graph

136 Commits

Author SHA1 Message Date
Camilla Löwy
736a88b067 Fix return type of functions returning bool values 2022-06-08 22:14:38 +02:00
Camilla Löwy
97da62a027 Cocoa: Clarify comments on compatibility macros 2022-02-09 22:13:14 +01:00
Camilla Löwy
7f6aa587f8 Cocoa: Fix deprecation warning for kUTTypeURL
We switched to kUTTypeURL when NSURLPboardType was deprecated, as the
official replacement symbol NSPasteboardTypeURL was not available on
every version of macOS supported by GLFW.

kUTTypeURL has now also been deprecated.

This commit moves to a compile-time choice between NSURLPboardType and
NSPasteboardTypeURL depending on the minimum targeted macOS version.

Fixes #2003
2022-02-02 19:20:32 +01:00
Jan Ekström
544790666b Cocoa: Use MACH_PORT_NULL for default IOKit port
Looking into the definition of kIOMainPortDefault, the following
description can be found:

When specifying a main port to IOKit functions, the NULL argument
indicates "use the default". This is a synonym for NULL, if you'd
rather use a named constant.

Thus, we do not have to utilize an external symbol for the identifier
of the default main IOKit port, but MACH_PORT_NULL suffice. This
simplifies compatibility between macOS versions as the symbol was
renamed with macOS 12.0.

Fixes #1985
Closes #1994
2021-11-22 21:30:53 +01:00
Josh Codd
f75c251dec Cocoa: Fix deprecation of kIOMasterPortDefault
This adds a workaround for kIOMasterPortDefault having been deprecated
in favor of kIOMainPortDefault in macOS 12.0.

Closes #1980
2021-10-27 23:09:40 +02:00
Camilla Löwy
56a4cb0a3a Add runtime platform selection
This adds compile-time support for multiple platforms and runtime
detection of them.  Window system related platform functions are now
called from shared code via the function pointer struct _GLFWplatform.

The timer, thread and module loading platform functions are still called
directly by name and the implementation chosen at link-time.  These
functions are the same for any backend on a given OS, including the Null
backend.

The platforms are now enabled via CMake dependent options following the
GLFW_BUILD_<platform> pattern instead of a mix of automagic and ad-hoc
option names.  There is no longer any option for the Null backend as it
is now always enabled.

Much of the struct stitching work in platform.h was based on an earlier
experimental branch for runtime platform selection by @ronchaine.

Every platform function related to windows, contexts, monitors, input,
event processing and Vulkan have been renamed so that multiple sets of
them can exist without colliding.  Calls to these are now routed through
the _glfw.platform struct member.  These changes makes up most of this
commit.

For Wayland and X11 the client library loading and display creation is
used to detect a running compositor/server.  The XDG_SESSION_TYPE
environment variable is ignored for now, as X11 is still by far the more
complete implementation.

Closes #1655
Closes #1958
2021-10-13 21:47:11 +02:00
Camilla Löwy
36ea36736d Cocoa: Change helper function suffix to Cocoa
This makes it clearer which platform a helper function belongs to.
2021-10-12 12:54:37 +02:00
Camilla Löwy
09f9773e6f Cocoa: Make timer functions backend independent
This is work towards allowing the Null backend to build for macOS
using the Darwin timer API, without the Cocoa backend being enabled.
2021-10-12 12:54:37 +02:00
Camilla Löwy
f5758d75d0 Remove context creation backend headers
These headers come from when GLFW only supported a single context
creation API at a time, chosen at compile-time.

Since EGL and OSMesa are now always enabled and the platform-specific
APIs are tied to their specific window system, there is no reason to
keep these declarations separate from the internal.h and *_platform.h
header files.
2021-10-12 12:54:36 +02:00
Camilla Löwy
b7d0c6037d Make dynamic module loading part of platform API
This is part of the preparations for runtime platform selection.
2021-10-12 12:54:36 +02:00
Camilla Löwy
e31deedc99 Make timer init part of platform API
This is part of runtime platform selection because the null backend
needs the timer implementation for the current OS.
2021-10-12 12:54:36 +02:00
Camilla Löwy
efe764b492 Remove blank line before the end of some structs 2021-10-12 12:54:35 +02:00
Stephen Gowen
1d88a2e3d6 Cocoa: Fix macro redefinition warning
This avoids generating a macro redefinition warning when the
GL_SILENCE_DEPRECATION macro has been defined for the whole of a larger
project.

Closes #1840.
2021-07-29 21:21:45 +02:00
Camilla Löwy
bcb8558189 Remove EGL and OSMesa struct member macros
Now that the EGL and OSMesa structs can be used safely by any platform,
the member macros serve no purpose.
2020-06-24 00:50:49 +02:00
Camilla Löwy
d7f7b0e1b5 EGL: Replace native handle macros with functions
This change is in preparation both for EGL_EXT_platform_base and runtime
GLFW platform selection.

Related to #1691.
2020-06-24 00:48:53 +02:00
Corentin Wallez
91eebe922d Use CALayer instead of NSView for EGLNativeWindowType
The only two EGL implementations on macOS are Swiftshader and ANGLE.
While Swiftshader supports both `NSView` and `CALayer` as
`EGLNativeWindowType`, ANGLE supports only `CALayer`. Furthermore
Swiftshader's OpenGL ES frontend is deprecated in favor of using ANGLE's
Vulkan backend on top of Swiftshader's Vulkan frontend.

This means that on macOS `EGLNativeWindowType` should be a `CALayer` for
compatibility with ANGLE.

Fixes #1169.
Closes #1680.
2020-05-22 17:37:44 +02:00
Camilla Löwy
949275bbed Cocoa: Fix call to NSWindow from non-main threads
glfwSwapBuffers may be called by any thread but NSWindow may not.

Bug introduced by c3ca88055f and reported
by @crujose.
2020-04-30 22:44:54 +02:00
Camilla Löwy
72366ac9a9 Cocoa: Finish launching NSApp in glfwInit
This moves the remaining bits of NSApplication initialization into
_glfwPlatformInit.  As a side-effect of this, any command-line program
initializing GLFW will get a menu bar, which is not ideal.

If this has happened to you and a bisect led you here, please see the
GLFW_COCOA_MENUBAR init hint introduced in GLFW 3.3.

If this patch is a terrible idea, please get in touch in the 3.4 release
timeframe.

This is a replacement for 6e6805000a,
which attempts to preserve the existing menu bar creation behavior for
the 3.3-stable branch.

Fixes #1649.
2020-03-12 01:56:35 +01:00
Camilla Löwy
7da87aaae7 Cocoa: Add fully dynamic loading of Vulkan loader
If the application is not linked against the Vulkan loader and relies on
a third-party loader library or glfwGetInstanceProcAddress, then our
call to dlopen will fail without a custom dyld environment variable.

This adds a fallback of looking in the directory of the main executable,
which matches the bundle structure recommended by the Vulkan SDK, making
that finally work out of the box for fully dynamic loading.
2020-01-16 22:15:30 +01:00
Camilla Löwy
15d91801b7 Cocoa: Select Vulkan surface extension at runtime
This mostly just follows the pattern established by X11.

Related to #1619.
2020-01-16 21:53:18 +01:00
ByunghoonKim
c5cb4a253a Cocoa: Add support for VK_EXT_metal_surface
This adds optional support for the VK_EXT_metal_surface instance
extension.

Closes #1619.
2020-01-16 05:28:24 +01:00
Camilla Löwy
4ec7daf3e9 Cocoa: Replace display link with IOKit query
This removes the final dependency on CoreVideo, using a display link to
get the refresh rate of monitors where Core Graphics report a refresh
rate of zero.  Instead we now query the I/O registry directly, similarly
to what the display link does at creation.

Thanks to @OneSadCookie for pointers to this solution.
2019-12-25 21:53:04 +01:00
Camilla Löwy
b4a8eb9b19 Cocoa: Only create per-monitor display link once
The display link query is not specific to any particular display mode
and so only needs to be done once.

The next step is to replace the display link altogether by querying
IOKit directly, which is what the display link does.
2019-12-20 09:46:48 +01:00
Camilla Löwy
94cb0347ab Cocoa: Add comments for Cocoa symbol macros 2019-11-11 22:49:00 +01:00
Camilla Löwy
56ca0cb3b3 Unify key name string handling
This makes key names per-key static strings for all supported platforms.

Fixes #1200.
2019-08-27 19:29:56 +02:00
Camilla Löwy
a337c56848 Start 3.4 2019-04-16 23:08:39 +02:00
Camilla Löwy
ab118b2529 Fix copyright years (somewhat) 2019-04-15 20:50:00 +02:00
Camilla Löwy
980fc9b52f Cocoa: Apply retina window hint to Metal layer
Related to #1340.
2019-03-27 17:14:30 +01:00
Camilla Löwy
056c5d3f90 Cleanup 2019-03-27 01:26:39 +01:00
Camilla Löwy
a4fbc6fe91 NSGL: Disable API deprecation warnings 2019-03-26 18:30:17 +01:00
Camilla Löwy
8d7e5cdb49 NSGL: Update current display for display link
This solution of one display link per window is far from ideal but is
still better than no solution.

As a side-effect this fixes swap interval breaking being ignored for
occluded windows on earlier versions of macOS.

Fixes #680.
Fixes #1337.
Related to #1417.
Fixes #1435.
2019-03-05 20:22:00 +01:00
Camilla Löwy
4e3204d86d Cocoa: Replace global autorelease pool with blocks
This is another small step towards having GLFW play nice with other
toolkits sharing the same process, including AppKit.

Any macOS platform function that touches Cocoa must now wrap itself in
an autoreleasepool block.

Since GLFW no longer provides an autoreleasepool outside of its
functions, THIS MAY BREAK EXISTING CODE MIXING GLFW AND COCOA.  Sorry!
Please add your own autoreleasepool blocks as needed.

Fixes #1107.
Closes #1114.
2019-03-05 20:11:20 +01:00
Camilla Löwy
4b20fb705b Cocoa: Fix work area using NS screen coordinates
Related to #1322.
2019-03-05 17:41:32 +01:00
Camilla Löwy
ea7eb2ddab Cocoa: Move app delegate and menu creation to init
The application delegate needs to be set at init to receive monitor
events before window creation.  Menu creation is moved to
applicationWillFinishLaunching: to play nicer with other toolkits in the
same process.

Related to #1317.
2019-01-11 01:05:00 +01:00
Camilla Löwy
88c5edb409 Cocoa: Remove subclassing of NSApplication
This removes the GLFW NSApplication subclass as a step towards better
coexistence with other libraries that touch Cocoa.

This moves application object creation to platform init to allow event
processing before window creation.

Related to #1317.
2018-12-25 18:13:59 +01:00
Camilla Löwy
031a8f9583 Cocoa: Cleanup 2018-10-24 18:01:12 +02:00
Camilla Löwy
1d75b205cb Cleanup
Allow window creation despite video mode setting failure.

Video mode setting failure is ignored the rest of the time and the
desired video mode has never been a hard constraint anyway.
2018-02-07 16:46:58 +01:00
Camilla Löwy
370eac3c48 Add glfwSetWindowContentScaleCallback
Related to #677.
Related to #1115.
2018-01-09 18:00:22 +01:00
Camilla Löwy
1fe319d234 Cocoa: Filter out duplicate size events
Fixes #1085.
2017-11-16 11:56:06 +01:00
Camilla Löwy
16bf872117 Add content scale queries
This adds glfwGetWindowContentScale and glfwGetMonitorContentScale for
querying the recommended drawing scale factor for DPI-aware rendering.

Parts of this patch are based on code by @ferreiradaselva.

Fixes #235.
Fixes #439.
Fixes #677.
Fixes #845.
Fixes #898.
2017-10-26 17:26:36 +02:00
Camilla Löwy
ce5e649d3b Cleanup
Move global data to library struct.  Simplify semantics.  Update
changelog.

Related to #1028.
2017-08-23 13:24:05 +02:00
Sergey Tikhomirov
80e4922b5e Cocoa: Hide cursor instead of using blank image
When cursor isn't in normal mode and should be hidden, use [NSCursor hide]
method instead of setting it to blank image. This should prevent
situations when hidden cursor becomes visible after system notification
was shown.

Fixes #971.
Closes #1028.
2017-08-23 08:44:56 +03:00
Camilla Löwy
a3007b9b0e Rename thread source files
This to reflect that they now contain more than TLS.
2017-06-08 16:09:14 +02:00
Camilla Löwy
372e908682 Remove internal header inclusion guards
Inclusion of internal headers is already both centralized and follows
strict rules.  Inclusion guards are both an unneccessary maintenance
burden and may hide inclusion order bugs.
2017-05-25 19:35:13 +02:00
Camilla Löwy
1982543cd2 Cleanup 2017-03-19 02:46:16 +01:00
Camilla Löwy
e9560ef021 Add GLFW_OSMESA_CONTEXT_API
This allows the creation of OpenGL contexts via OSMesa on existing
platforms.  It does not add a compile- or link-time dependency on
OSMesa.

Fixes #281.
2017-02-28 20:38:10 +01:00
Camilla Löwy
ec410fb6fe Cocoa: Enable EGL 2017-01-02 15:32:55 +01:00
Camilla Löwy
04f559e28d Restructure monitor enumeration
This way is both kinder on event-based enumeration and less work to
unwind allocations for when properly implementing GLFW_OUT_OF_MEMORY.
2017-01-02 06:03:02 +01:00
Camilla Löwy
ecda05af29 Cocoa: Implement window cascading
Related to #195.
2017-01-02 04:49:16 +01:00
Sergey Tikhomirov
11a2413476 Cocoa: Fix issue with application sandboxing
Fixes #816.
Closes #882.
2016-12-06 17:39:51 +01:00