Commit Graph

2739 Commits

Author SHA1 Message Date
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
2a78a2cf82 Refactor platform selection for clarity? 2021-10-27 18:22:06 +02:00
Camilla Löwy
76a5f781db Add glfwInitVulkanLoader
This removes the GLFW_VULKAN_STATIC CMake option and the
_GLFW_VULKAN_STATIC configuration macro and replaces them with the
glfwInitVulkanLoader function, allowing a single library binary to
provide both behaviors.

This is based on the design from PR #1374 by @pmuetschard.

Closes #1374
Closes #1890
2021-10-27 18:22:05 +02:00
Camilla Löwy
db91507956 Remove saving a function pointer only used once
This removes the global struct member for
vkEnumerateInstanceExtensionProperties, which is only used in the same
function that fetches the function from the loader.

The pattern is now more in line with how other single uses of Vulkan
functions are structures, such as window surface creation.
2021-10-27 18:22:05 +02:00
Camilla Löwy
ee6ff939a5 Fix invalid pointer conversions
C does not allow conversions between data pointers and function
pointers.

Yes, the name of the macro is reserved.  That's something for a future
commit to fix.

Fixes #1703
2021-10-27 18:22:05 +02:00
Camilla Löwy
68534cc2ce Null: Remove unused function 2021-10-27 18:22:05 +02:00
Camilla Löwy
4005f70eef WGL: Limit DWM swap interval hack to Vista and 7
This hack breaks when switching a window to fullscreen, if the OpenGL
ICD detects this and switches its swapchain to exclusive mode.

This limits the hack to Windows Vista and 7.  This hack was added
because of vsync jitter under DWM on Windows 7 and I have been unable
to reproduce it on any later version.

Is this change causing any problems on any version of Windows?  Please
open an issue!

Fixes #1072
2021-10-27 18:22:05 +02:00
luz paz
0fe96ec202 Fix various typos
Found via `codespell -q 3 -S ./deps -L fo,numer,te,uint,wille`

Closes #1965
2021-10-25 23:39:06 +02:00
Camilla Löwy
3d52f7e345 Limit scope of some loop counters in C99 files 2021-10-25 23:39:06 +02:00
Camilla Löwy
f4d0365a5a Use switch statement instead of if-else-chain
Related to #1739
2021-10-25 23:39:06 +02:00
Ioannis Tsakpinis
727db55c3a
Fix context API checks in native access functions 2021-10-23 16:20:18 +03: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
ff9d9515f6 Remove typedefs only used in one place 2021-10-12 12:54:37 +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
bdfe6b09af Win32: Make timer functions backend independent
This is work towards allowing the Null backend to build for Windows
using the Win32 timer API, without the Win32 backend being enabled.
2021-10-12 12:54:37 +02:00
Camilla Löwy
b6834bf2a1 Win32: Remove timeGetTime fallback for timer
The performance counter API is guaranteed to succeed on Windows XP and
later so there is no need for a fallback.

This removes our last dependency on winmm.
2021-10-12 12:54:37 +02:00
Camilla Löwy
35f3b58c21 Win32: Make thread functions backend independent
This is work towards allowing the Null backend to build for Windows
using the Win32 threading API, without the Win32 backend being enabled.
2021-10-12 12:54:36 +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
6d51b39106 Select mapping platform name at runtime
This is done in preparation for runtime platform selection.
2021-10-12 12:54:35 +02:00
Camilla Löwy
d0776e04a3 Null: Add non-functional EGL support
This is done in preparation for runtime platform selection, to make sure
every platform can build with EGL enabled.

It may be possible to add support for things like the ANGLE null
platform later.
2021-10-12 12:54:35 +02:00
Camilla Löwy
8b8d10bc01 Move library dependency logic to src directory
This finally eliminates the glfw_INCLUDE_DIRS and glfw_LIBRARIES CMake
variables entirely.
2021-10-12 12:54:35 +02:00
Camilla Löwy
0a9488e3f0 Remove configuration header 2021-10-12 12:54:35 +02:00
Camilla Löwy
efe764b492 Remove blank line before the end of some structs 2021-10-12 12:54:35 +02:00
Camilla Löwy
cca9008db2 Make native access functions verify context API
The native access functions for context handles did not verify that the
context had been created with the same API the function was for.

This makes these functions emit GLFW_NO_WINDOW_CONTEXT on API mismatch.
2021-10-12 12:54:35 +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
Waris Boonyasiriwat
e7758c506d Wayland: Fix cursor offset when shape changes
The Wayland protocol spec[1] states that set_cursor must be called
with the serial number of the enter event.  However, GLFW is passing in
the serial number of the latest received event, which does not meet the
protocol spec.

[1] https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_pointer

As a result, set_cursor calls were simply ignored by the compositor.

This fix complies with the protocol more closely by specifically caching
the enter event serial, and using it for all set_cursor calls.

Fixes #1706
Closes #1899
2021-09-02 19:09:33 +02:00
Camilla Löwy
4cbe743b74 Wayland: Fix standard cursor name selection
Regression introduced by 08e5a17063.
2021-09-02 18:30:41 +02:00
Koray Kilinc
216d5e8402 Wayland: Fix some keys not repeating
According to the libxkbcommon documentation[1], xkb_keymap_key_repeats
requires keymap and keycode as input:

int xkb_keymap_key_repeats( struct xkb_keymap * keymap,
			    xkb_keycode_t key)

However, in inputChar in wl_input.c we are passing in xkb_keysym_t,
which was a type mismatch.

This results in some keys not repeating when they should and vice versa.

[1] https://xkbcommon.org/doc/current/group__components.html#ga9d7f998efeca98b3afc7c257bbac90a8

Closes #1908.
2021-08-31 20:48:12 +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
Richard Boldiš
2ac7e20aaf Win32: Fix invalid preprocessor command 'warning'
The GCCism #warning had snuck into the Win32 platform code.

Merges #1953.
2021-08-24 23:24:14 +02:00
Camilla Löwy
85348c67cd Wayland: Load functions for new atomic marshalling
The wayland-scanner program recently changed how it generates
marshalling, requiring a couple of new core functions.

Fixes #1949.
2021-08-19 18:55:35 +02:00
Camilla Löwy
071d7c0f46 X11: Fix function returning before cleanup
The _glfwPlatformSetWindowFloating function would return without freeing
the state array if the window was already in the requested state.
2021-08-16 21:27:40 +02:00
Camilla Löwy
d83849792b Add override variable for CMake library type
This adds the GLFW_LIBRARY_TYPE CMake cache variable, which allows users
and higher-level projects to set what type of library GLFW is built as.

When not empty, this value overrides the standard BUILD_SHARED_LIBS
option for GLFW while still allowing it to control the type of other
libraries in a larger project.

This also allows building GLFW as an object library without adding dummy
source files (as required by Xcode) or producing unused library
binaries.

Projects using CMake 3.12 or later can link the resulting GLFW object
library normally using target_link_libraries.

Fixes #279.
Related to #1307.
Closes #1497.
Closes #1574.
Closes #1928.
2021-08-15 22:44:43 +02:00
Camilla Löwy
dffe203c17 Wayland: Make libwayland-client dynamically loaded
The insight to use wayland.xml to resolve the difficult-to-redirect
interface symbols was gleaned from SDL.

Instead of compiling the code output of wayland-scanner separately it is
made part of the wl_init compilation unit.  This lets us do things like
transparently rename our copies of Wayland globals.

The OS version of wayland-client-protocol.h is no longer used by GLFW,
but it is presumably ABI compatible with the output of wayland-scanner.

Closes #1174.
Closes #1338.
Related to #1655.
Closes #1943.
2021-08-15 21:58:19 +02:00
Camilla Löwy
87d5646f5d Remove unneccessary quotes in CMake conditions 2021-08-13 17:27:38 +02:00
Camilla Löwy
aff00d0dd8 POSIX: Use frequency member for clarity 2021-08-13 17:27:38 +02:00
Camilla Löwy
111c02d74e POSIX: Remove use of deprecated gettimeofday
POSIX.1-2008 deprecated gettimeofday, which we used as a fallback if the
monotonic clock was unavailable.

This replaces that fallback with the non-monotonic real-time clock.

Because of the Gordian knot of feature test macros across Unices, this
also includes the shift from some platform source files defining
_POSIX_C_SOURCE to various values to _DEFAULT_SOURCE being defined for
all source files on Linux.  This is because -std=c99 on Linux disables
_DEFAULT_SOURCE (POSIX 2008 and extensions).

Once runtime platform selection comes in, this kind of platform-specific
preprocessor logic can be moved into the platform glue files and won't
need to be replicated by third-party build setups, but for now, sorry.
2021-08-13 17:18:56 +02:00
Camilla Löwy
58b48a3a00 Win32: Remove changing the foreground lock timeout
It's rude to ignore the foreground lock timeout, especially by default.

Discussion of this code and its removal:
https://discourse.glfw.org/t/why-is-spi-setforegroundlocktimeout-set-to-zero-on-glfwinit-win32
2021-08-12 20:50:30 +02:00
Camilla Löwy
201400b974 Simplify parsing of default gamepad mappings
The outer glfwUpdateGamepadMappings function is now bypassed when
parsing the default gamepad mappings.  The data in mappings.h does not
contain any comments or line breaks.  Also this is done before joystick
support has been initialized, so there is no need to look for matching
devices.

Finally, the array of default mappings is pre-allocated.  This has no
measurable performance impact but does generate a lot of calls, which
won't be nice for a user provided custom allocator to deal with.
2021-08-01 20:57:28 +02:00
Camilla Löwy
afa78b4270 Update gamepad mappings from upstream 2021-08-01 20:17:21 +02:00
Camilla Löwy
0c90e1a33f Add gamepad mapping filtering by backend
This fixes gamepad mappings being included in GLFW binaries that would
then never use them because they were for a different platform.
2021-08-01 20:17:21 +02:00
Camilla Löwy
01778329ec Add custom target for updating gamepad mappings 2021-08-01 20:16:17 +02:00
Camilla Löwy
56092814f3 Improve error description for invalid scancodes 2021-07-29 21:50:24 +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
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