Commit Graph

423 Commits

Author SHA1 Message Date
FuzzyQuills
8e9a5d29a8
Cocoa: No NSWindowStyleMaskResizable in fullscreen
On macOS 10.15 Catalina and earlier, not having the resizable bit
cleared in NSWindowStyleMask in fullscreen leads to windows minimising
when clicked anywhere in the content area.

On all tested macOS versions it also causes the fullscreen window to be
resizable by the user.

Regression introduced by 0d599026d0.

Fixes #2377
Closes #2405
2023-12-11 21:25:44 +01:00
Camilla Löwy
5e4496cb42 Cocoa: Fix compilation error on OS X 10.8
The occlusion state parts of NSWindow are OS X 10.9+ only but we still
(technically) support building for only 10.8.

Fixes #2161
2023-12-06 18:34:22 +01:00
Camilla Löwy
c812b9d87c Add conditional compilation for platform units
This is a step towards being able to compile GLFW manually without
needing to duplicate a lot of platform- or OS-specific logic.
2022-09-15 22:24:39 +02:00
Camilla Löwy
0f9a9578f3 Add window hints for initial position
This adds window hints for the initial position, in screen coordinates,
of a window.  The special value GLFW_ANY_POSITION means the window
manager will be allowed to position the window.

It is not possible to set window positions on Wayland and GLFW will
always behave as if these hints are set to GLFW_ANY_POSITION.

Fixes #1603
Fixes #1747
2022-07-29 11:50:13 +02:00
Camilla Löwy
488008e0a2 Add cursor mode GLFW_CURSOR_CAPTURED
This adds a cursor mode that provides a visible cursor confined to the
content area of the window.

Fixes #58
2022-07-25 18:02:57 +02:00
Camilla Löwy
36f0bf00a9 Cocoa: Fix build failure on OS X 10.11
The NSWindowCollectionBehaviorFullScreenNone enum value is missing from
system headers on 10.11 despite the documentation claiming it was added
in 10.7.

Unfortunately Apple has taken down all API release notes for versions
prior to 10.14.

This fixes a build failure introduced with
98d6e8485b.
2022-07-08 16:07:11 +02:00
Camilla Löwy
0d599026d0 Cocoa: Fix clearing of unrelated window style bits
Whenever GLFW changed the window style mask, a new mask was created
from scratch based on the attributes set on the GLFW window object.
This caused us to potentially clear unrelated window style bits.

This was always wrong but became a critical issue when Cocoa began
throwing an exception if an application cleared the
NSWindowStyleMaskFullScreen while the window is in macOS fullscreen.

This commit reworks all style mask editing so it only changes the
relevant bits, preserving all others.

This is only a narrow bug fix to prevent crashes, intended for the
stable branch.  Our interaction with macOS fullscreen is still very
poor.  The next step after this is a set of patches that improve the
interaction between the current API and macOS fullscreen.

Fixes #1886
Fixes #2110
2022-07-07 23:47:48 +02:00
Camilla Löwy
6f8ec4075b Cocoa: Fix GLFW_MAXIMIZED for nonresizable windows
The reasoning here is that glfwRestoreWindow will change nothing for
a windowed non-resizable window on Cocoa, and silently refusing to
maximize seems slightly more like something other platforms would do.

This is possibly either the right thing to do or the wrong one.
2022-07-07 22:24:09 +02:00
Camilla Löwy
98d6e8485b Cocoa: Disable macOS fullscreen when non-resizable
Windows with GLFW_RESIZABLE set to false should not be resizable by the
user.
2022-07-07 22:23:54 +02:00
Camilla Löwy
736a88b067 Fix return type of functions returning bool values 2022-06-08 22:14:38 +02:00
Camilla Löwy
09653b8c54 Move last bits of window setup to platform code
This avoids glfwCreateWindow emitting GLFW_FEATURE_UNAVAILABLE or
GLFW_FEATURE_UNIMPLEMENTED on Wayland because shared code was calling
unimplemented or unavailable platform functions during final setup.

It also makes it consistent with the final setup of full screen windows.
2022-04-28 21:58:06 +02: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
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
6ed5294223 Cocoa: Fix unresponsive cursor after cursor warp
This is a companion to 157ebb80aa and
fixes the same issue for calls to glfwSetCursorPos.

Related to #1962
2021-09-12 20:01:34 +02:00
Ioannis Tsakpinis
157ebb80aa Cocoa: Fix unresponsive cursor after ungrab
There is a suppression interval (0.25 seconds by default) after a call
to CGWarpMouseCursorPosition, during which local hardware events
(keyboard and mouse) are ignored. GLFW already calls
CGEventSourceSetLocalEventsSuppressionInterval with a value of 0.0, but
it doesn't help in this case, there is still a short delay before the
cursor can be moved. Moving the CGAssociateMouseAndMouseCursorPosition
call after the cursor position has been restored, fixes the issue.

Closes #1962
2021-09-10 18:52:47 +02:00
Camilla Löwy
22b586b3d8 Add pluggable heap allocator
This adds the glfwInitAllocator function for specifying a custom memory
allocator to use instead of the C runtime library.

The allocator is a struct of type GLFWallocator with fields
corresponding to malloc, realloc and free, while the internal API
corresponds to calloc, realloc and free.

Heap allocation calls are filtered before reaching the user-provided
functions, so deallocation of NULL and allocations of zero bytes are not
passed on, reallocating NULL is transformed into an allocation and
reallocating to size zero is transformed into deallocation.

The clearing of a new block to zero is performed by the internal
calloc-like function.

Closes #544.
Fixes #1628.
Closes #1947.
2021-08-25 21:00:10 +02:00
Camilla Löwy
56092814f3 Improve error description for invalid scancodes 2021-07-29 21:50:24 +02:00
Camilla Löwy
076bfd55be Cocoa: Fix MoltenVK layer scale out of sync
The contents scale of the hosted CAMetalLayer created for MoltenVK was
updated only after the GLFW content scale and framebuffer size events
were emitted, causing the layer to get out of sync with the monitor the
window was on.
2021-07-16 20:10:19 +02:00
Camilla Löwy
836e709503 Cocoa: Remove calls to -update on nil
These calls have no effect unless the context was created with NSGL.
2021-07-16 19:54:21 +02:00
Luflosi
08e5a17063 Use switch statement instead of if-else-chain for cursor shapes
Closes #1739.
2020-12-08 15:45:14 +01:00
Camilla Löwy
6d2003d07a Move management of shared state to shared code
Platform code may not modify shared state.

Related to #1568.
2020-07-15 18:02:38 +02:00
Rokas Kupstys
d285a9fdeb Add support for mouse input transparency
This adds the GLFW_MOUSE_PASSTHROUGH window hint and attribute for
controlling whether mouse input passes through the window to whatever
window is behind it.

Fixes #1236.
Closes #1568.
2020-07-15 17:59:55 +02:00
Camilla Löwy
e47832ffcf Cocoa: Fix regression in private use area check
This fixes a regression introduced by
ad9eb768c9.
2020-06-29 23:23:26 +02:00
Camilla Löwy
ad9eb768c9 Cocoa: Fix non-BMP Unicode codepoint input
Supplimentary Plane codepoints were reported as UTF-16 surrogate pairs.

Fixes #1635.
2020-06-29 23:03:24 +02:00
Camilla Löwy
0dea8a4441 EGL: Add support for EGL_ANGLE_platform_angle
This adds basic support for selecting the platform type (rendering
backend) when running on ANGLE.

Related to #1380.
2020-06-29 00:02:22 +02:00
Camilla Löwy
aec9fae8f3 EGL: Add support for EGL_EXT_platform_base
This adds support for EGL_EXT_platform_base and its associated X11 and
Wayland extensions, allowing us to explicitly tell EGL which window
system we are using.

This is based on work by @linkmauve in #1691.

Closes #1691.
2020-06-24 00:49:55 +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
Camilla Löwy
9a87c2a4b4 Add feature available/implemented errors
This adds two new error codes: GLFW_FEATURE_UNAVAILABLE for when
a GLFW feature cannot be reasonably implemented on that platform, and
GLFW_FEATURE_UNIMPLEMENTED for when it can be but has not been yet.

This replaces the current situation where the Wayland code emitted
GLFW_PLATFORM_ERROR in both cases while the macOS code silently did
nothing.

If your application exits on any GLFW error, these error codes should at
least be easy to filter out from that behavior.

Ideally, GLFW_FEATURE_UNAVAILABLE should be rare and
GLFW_FEATURE_UNIMPLEMENTED should never be emitted at all.

Fixes #1692.
2020-06-02 17:18:18 +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
5f1631cb0e Check scancode before use in glfwGetKeyName 2020-01-16 23:17:49 +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
54e8e0b092 NSGL: Remove problematic swap interval workaround
Fixes #1483.
2019-12-20 09:46:48 +01:00
Camilla Löwy
28773a069e Cocoa: Fix undeclared selector warnings 2019-12-20 09:46:48 +01:00
Camilla Löwy
506a6aafde Formatting 2019-12-11 22:10:00 +01:00
Camilla Löwy
a875a536b7 Cocoa: Fix duplicate conversion of title string 2019-12-11 22:08:56 +01:00
Camilla Löwy
6e6805000a Cocoa: Fix pre-window-creation event processing
Polling the event queue before NSApp had been allowed to finish
launching, in our case by starting our self-terminating run loop,
triggered an assertion inside NSApplication.

This fix, which makes all event processing functions capable of starting
it, makes that assertion less likely.

A more Cocoa-friendly fix would be to finish launching NSApp during
glfwInit and let people annoyed by the menu bar disabled it with
GLFW_COCOA_MENUBAR.  That may not be suitable for 3.3-stable, though.

Fixes #1543.
2019-12-09 22:25:59 +01:00
Camilla Löwy
7dbdd2e6a5 Add more standard cursors
This adds the standard cursors for diagonal and omnidirectional
resize/move and operation-not-allowed.  It also adds new (better?) names
for the horizontal and vertical resize/move and pointing hand cursors.

References:
 - https://developer.apple.com/documentation/appkit/nscursor
 - https://stackoverflow.com/questions/10733228/
 - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsystemcursor
 - https://freedesktop.org/wiki/Specifications/cursor-spec/
 - https://tronche.com/gui/x/xlib/appendix/b/

Related to #427.
2019-11-28 22:24:00 +01:00
Camilla Löwy
2c519709be Cocoa: Fix full screen window iconification
Iconification (miniaturization) of undecorated windows stopped working
unless the window has the NSWindowStyleMaskMiniaturizable style.
2019-11-13 14:08:28 +01:00
Camilla Löwy
bac15f9449 Cocoa: Fix multiple methods warning
This fixes a warning due to us using bare ids and
NSCollectionLayoutAnchor having a message with the same name.
2019-11-11 22:49:00 +01:00
Camilla Löwy
c819f27ce3 Cocoa: Process events after window destruction
On macOS a destroyed window remained on screen until the next time
events were processed.  This makes the behavior more consistent with
other platforms.

Fixes #1412.
2019-11-11 22:49:00 +01:00
Camilla Löwy
7f02898264 Cocoa: Fix glfwSetWindowSize anchor point
This makes glfwSetWindowSize use the top-left corner as anchor point
instead of the bottom-left corner.

Fixes #1553.
2019-09-06 16:57:37 +02: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
3262c29440 Cocoa: Cleanup
This makes the Cocoa _glfwPlatformSetWindowMonitor consistent with its
X11 and Win32 counterparts.
2019-06-27 18:14:48 +02:00
Camilla Löwy
0c6b505619 Convert some declarations to C99 style 2019-06-27 18:13:29 +02:00
Camilla Löwy
56aad76b16 Add C dialect reminders to each source file
Files built for Win32 must use C89 style declarations for compatibility
with VS 2010 and 2012, which are still supported by GLFW.
2019-05-24 14:43:49 +02:00
Camilla Löwy
a337c56848 Start 3.4 2019-04-16 23:08:39 +02:00