Commit Graph

4705 Commits

Author SHA1 Message Date
Camilla Löwy
990dc4b388 Wayland: Fix error paths not closing sending fd
Whatever error happens on our end, we should still close the fd so the
other end can move on.
2022-04-03 19:45:09 +02:00
Camilla Löwy
a4460b694e Wayland: Rename listener user data parameters 2022-04-03 19:45:09 +02:00
Camilla Löwy
4506175023 Wayland: Clean up pointer declarations
Adapt style to match the rest of the project.
2022-04-03 19:44:56 +02:00
Camilla Löwy
ba11e60859 Wayland: Rename data transfer parameters
No rationale beyond personal preference.
2022-04-03 18:14:50 +02:00
Camilla Löwy
2d45681bc3 Wayland: Fix phrasing and type of error messages 2022-04-03 18:14:50 +02:00
Camilla Löwy
4c110bba41 Wayland: Fix partial writes of clipboard string
The string pointer used to write the contents of our clipboard data
offer was never updated, causing it to repeat parts of the beginning of
the string until the correct number of bytes had been written.
2022-04-03 18:14:50 +02:00
Camilla Löwy
738b1c73b5 Wayland: Remove superfluous global struct member
It seems unlikely that strlen will be a bottleneck when sending
clipboard contents.
2022-04-03 18:14:50 +02:00
Camilla Löwy
b386371f57 Wayland: Fix double free on data source error
If data source creation fails, the string containing the data for it
would be freed a second time during termination.
2022-04-03 18:14:50 +02:00
Camilla Löwy
9c95cfb9f1 Wayland: Fix handling of clipboard set to self
Passing any part of the result of glfwGetClipboardString to
glfwSetClipboardString would result in, at best, a use-after-free error.
2022-04-03 18:14:50 +02:00
Camilla Löwy
920d110b6c Fix missing newline 2022-04-03 18:14:50 +02:00
Camilla Löwy
554cbdb205 POSIX: Fix data type of return values 2022-04-03 18:14:50 +02:00
Camilla Löwy
955fbd9d26 Cocoa: Fix AirPlay causing harmless init error
Emitting an error for one specific type of failure in retrieving the
correct name for a display is not very useful, especially when
initialization is otherwise unaffected.

There should be a path for information like that but this isn't it.

Fixes #1791
2022-03-18 00:45:12 +01:00
Camilla Löwy
07a5518c3e Win32: Fix using executable instance and not ours
Operations that take an instance handle should be passed the handle of
whatever module we are inside instead of blindly passing the handle of
the executable.

This commit makes GLFW retrieve its own instance on initialization.

This makes the most difference for window classes, which are
per-instance.  Using the executable instance led to name conflicts if
there were several copies of GLFW in a single process.

Note that having this is still a bad idea unless you know what things to
avoid, and those things are mostly platform-specific.  This is partly
because the library wasn't designed for it and partly because it needs
to save, update and restore various per-process and per-session settings
like current context and video mode.

However, multiple simultaneous copies of GLFW in a single Win32 process
should now at least initialize, like is already the case on other
platforms.

Fixes #469
Fixes #1296
Fixes #1395
Related to #927
Related to #1885
2022-03-18 00:45:04 +01:00
Camilla Löwy
66a4882eb1 Add checks for some invalid values to public API
There were no checks for invalid values or asserts for all invalid NULL
pointers to glfwSetWindowIcon or glfwCreateCursor.

Fixes #1862
2022-03-18 00:23:20 +01:00
Camilla Löwy
8d9231fe5e Win32: Fix glfwGetKeyScancode for GLFW_KEY_PAUSE
The bug described in 03cfe957e7 was
already present for another key where modifiers changes its scancode.

Related to #1993
2022-03-18 00:22:20 +01:00
Camilla Löwy
03cfe957e7 Win32: Fix scancode and key for Alt+PrtSc events
Alt+PrtSc emits a different scancode than just PrtSc.  Since the GLFW
API assumes each key corresponds to only one scancode, this cannot be
added to the keycodes array.

Instead we replace the scancode at the point of entry.

Fixes #1993
2022-03-18 00:19:01 +01:00
Camilla Löwy
add0521efb Fix accidental C99 in C89 header 2022-03-16 18:41:27 +01:00
Camilla Löwy
535c3ce632 Fix GLAPIENTRY redefinition warning
On a Unix system, if you define GLFW_INCLUDE_NONE and
GLFW_EXPOSE_NATIVE_GLX, then include glfw3.h and glfw3native.h, you will
get a redefinition warning for GLAPIENTRY.

The glfw3.h header defines GLAPIENTRY as a service for OpenGL related
headers that assume it's already defined.  However, glx.h includes gl.h,
which defines GLAPIENTRY unconditionally.

If not for Hyrum's law, the better solution would have been not to
define GLAPIENTRY if GLFW_INCLUDE_NONE is defined.

Fixes #2010
2022-03-16 18:40:26 +01:00
Camilla Löwy
3ee5031fd7 Add shared min and max functions for int 2022-03-15 22:22:13 +01:00
Camilla Löwy
9cc252a406 Revert ad01c1b614
This change broke key names for dead keys, because that depends on
the effect on the global state of simulating two key presses.

Issue found by CTest tests.

Reverts #2018
2022-03-13 16:01:41 +01:00
Camilla Löwy
46950a5e61 Fix button field names in input guide
Fixes #2056
2022-03-13 15:27:25 +01:00
Camilla Löwy
1461c59aa2 Update changelog and add credit
Related to #1951
2022-03-10 20:04:56 +01:00
Slemmie
b54fb0af10 X11: Fix undefined behavior in bit shift of int
Closes #1951
2022-03-10 19:58:41 +01:00
Camilla Löwy
8f9ff8503e Formatting 2022-03-10 19:36:10 +01:00
Camilla Löwy
aa803f7de5 Win32: Update rationale for reimplementation
It is true that plain MinGW lacks this header, but that is not the main
reason for reimplementing IsWindowsVersionOrGreater.
2022-03-10 19:35:23 +01:00
Camilla Löwy
34573798f4 Win32: Rename Windows 10 macros for clarity
This switches the Windows 10 version helper macros to include the
version numbers listed in MSDN requirements sections.
2022-03-10 19:32:21 +01:00
Camilla Löwy
8ff9ed92b4 Win32: Fix calls to encoding compatibility macros
Calls to Unicode specific functions should be made explicit.
2022-03-10 19:31:28 +01:00
Camilla Löwy
723f3eb40d Win32: Fix maximization showing a hidden window
The normal way of maximizing a window also makes it visible.  This
implements window maximization manually for when the window passed to
glfwMaximizeWindow is hidden.

This will very likely not be forward-compatible and should be replaced.
2022-03-10 19:30:20 +01:00
Camilla Löwy
1eef3a363e Fix dependency list for X11 on Cygwin 2022-03-10 19:15:13 +01:00
Camilla Löwy
367d06deaf Win32: Fix scale fixup losing initial position
The window content scale correction at creation overwrote the inital,
more pleasant placement of the window by CW_USEDEFAULT, if the window
was created with GLFW_MAXIMIZED set.  This is because the translation
to screen coordinates was done using the current position, not the
position from the restored window rect.
2022-03-10 17:10:55 +01:00
Camilla Löwy
a730acf8e5 Win32: Fix rect of undecorated maximized windows
A window created maximized and undecorated would cover the whole monitor
Windows placed it on instead of just that monitor's workarea.

This commit adjusts the maximized rect to cover just the workarea,
similar to how undecorated windows that become maximized are handled
during WM_GETMINMAXINFO.

Fixes #1806
2022-03-10 17:07:55 +01:00
Camilla Löwy
adc202d2c3 POSIX: Fix undeclared function warning on Cygwin 2022-03-04 13:37:38 +01:00
Camilla Löwy
d78b0a4ead X11: Fix sonames for loaded libraries on NetBSD
The NetBSD sonames for X11 and related libraries is more stable than on
OpenBSD but the version numbers are still bumped more often than their
Linux counterparts, even excluding the one-time version bump across all
X11 related libraries.

This commit moves to using version-less sonames for X11 and related
libraries on NetBSD, which will hopefully be more forward-compatible
than hard-coding NetBSD-specific sonames.

This may not be the correct long-term solution but it runs now.

Binaries also appear to need an LD_LIBRARY_PATH or rpath entry of
/usr/X11R7/lib in order for the libraries to be found by dlopen.

Tested on NetBSD 9.2.
2022-03-04 00:00:59 +01:00
Camilla Löwy
1e0c3bca7f Update version of VS used on windows-latest 2022-03-03 23:17:45 +01:00
Camilla Löwy
71742d9a27 Wayland: Improve event processing with timeout
If the polling was interrupted by a signal or by incomplete or unrelated
data on any file descriptor, handleEvents could return before the full
timeout had elapsed.

This retries the Wayland prepare-to-read and poll until the full timeout
has elapsed or until any event was processed.  Unfortunately, due to how
the Wayland client API is designed, this also includes the delete_id
for the frame callback created by eglSwapBuffers.

This means glfwWaitEvents* are still not fully functional on Wayland.
See #1911 for more details.
2022-03-03 22:58:09 +01:00
Camilla Löwy
a32cbf6d4f Wayland: Fix glfwPostEmptyEvent not always working
The display sync requests in glfwPostEmptyEvent could just accumulate as
the display was never flushed on secondary threads.

This adds a proper flush after each sync request.

Fixes #1520
Closes #1521
2022-03-03 22:24:09 +01:00
Camilla Löwy
7ce1f3e1cf Formatting 2022-03-03 22:24:09 +01:00
Camilla Löwy
bb9d699ae6 Share X11 fd polling logic with Wayland
This moves the X11 polling implementation to a separate file where it
can be used by either the X11 or Wayland backend or both.

This code should be POSIX compatible where necessary but will use the
lower latency but non-standard polling functions ppoll or pollts where
those are available.

This commit is based on work by OlivierSohn and kovidgoyal.

Fixes #1281
Closes #1285
2022-03-03 22:23:57 +01:00
Camilla Löwy
203a7c59d2 Wayland: Cancel display fd read before callbacks
Cancel the prepared-to-read state on the calling thread before starting
to call back to user code.

Emitting close requests here is not a good choice but that is for
a future commit to address.
2022-03-03 22:16:59 +01:00
Camilla Löwy
3c2913dcb9 Wayland: Fix potential incomplete display flushing
The flushing of a Wayland display may need to be done in several steps,
signalled by it failing with EAGAIN.
2022-03-03 22:16:59 +01:00
Camilla Löwy
84b0923fe6 X11: Use lower-latency poll where available
This uses ppoll for waiting on file descriptors with a timeout, where
that function has been available a while.  On NetBSD, which will be
getting ppoll in the next release, the equivalent pollts is used.

This commit is based on work by OlivierSohn and kovidgoyal.

Related to #1281
Related to #1285
2022-03-03 22:16:59 +01:00
Camilla Löwy
cd22e28495 X11: Fix empty event race condition with a pipe
There is a seemingly unavoidable race condition when waiting for data on
the X11 display connection, as long as any other thread is also making
Xlib calls.  The event data we are waiting for could be read by the
other thread as part of looking for the reply to its request, before our
poll has begun.

This commit replaces the X11 event sent by glfwPostEmptyEvent with
writing to an unnamed pipe.  The race condition remains if other Xlib
calls are made on other threads, but glfwPostEmptyEvent should now be
race-free.

This commit is based on work by pcwalton, OlivierSohn, kovidgoyal and
joaodasilva.

Closes #2033
Related to #379
Related to #1281
Related to #1285
2022-03-03 22:16:59 +01:00
Camilla Löwy
363d471441 Cleanup 2022-03-03 22:16:59 +01:00
Camilla Löwy
87970b7f26 X11: Fix glfwWaitEvents* ignoring joystick events
The data available on the X11 connection may be a reply or an internal
event for an X11 extension.  Previously the check for whether an event
was available for us was done outside waitForEvent.  This prevented data
available on other file descriptors from breaking the outer wait loop.

This commit moves the check for whether an event is available into the
wait functions, where there is enough knowledge to limit the check to
the X11 connection.

Related to #932
2022-03-03 22:16:49 +01:00
Camilla Löwy
1e987cb92e X11: Fix joystick events causing busy waiting
On Linux, the inotify descriptor was included in the set used for
select, but could not break the outer loop, leading to busy waiting
until timeout or the correct X11 event arrived.

This commit adds a new function for waiting just on X11 events.

Fixes #1872
2022-03-03 22:15:42 +01:00
Camilla Löwy
92b5c67b50 X11: Retry poll when failed with EINTR or EAGAIN
Both of these errors should just lead to local retry.
2022-03-02 19:59:08 +01:00
Camilla Löwy
d3e4fcf8b7 X11: Fix event polling when event fd > 1023
This replaces select with poll for checking for data on event file
descriptors, as select cannot handle file descriptors larger than 1023.

Closes #2024
2022-03-02 19:38:41 +01:00
Camilla Löwy
ad01c1b614 Win32: Fix key name code changing global key state
This prevents glfwInit from potentially clobbering the dead key state
for other applications.

Closes #2018
2022-03-02 19:38:41 +01:00
Camilla Löwy
789d2924c0 Formatting
Make it clear that context attribute helper macros are macros.
2022-03-02 19:38:41 +01:00
Camilla Löwy
2e656afc49 GLX: Fix context creation failing unnecessarily
Regression introduced with 3bb5c459d6.
2022-03-02 19:38:41 +01:00