Commit Graph

2840 Commits

Author SHA1 Message Date
Camilla Löwy
c807f386c2 Wayland: Fix mapping failure on wlroots compositor
When showing a window that had already been shown once (and so already
had its shell objects), GLFW would attach a new buffer and commit it
before waiting for the next configure event.  This was a violation of
the XDG shell protocol.

This was allowed to work as intended on GNOME and KDE without error.
However wlroots based compositors would (correctly) emit an error.

Unfortunately, I haven't been able to find a way to get both KDE, GNOME
and Sway to send the configure event we need in order to map the
wl_surface again while keeping our existing shell objects, so with this
commit we now create them for each call to glfwShowWindow and destroy
them for each call to glfwHideWindow.

Fixes #1268

(cherry picked from commit 83a134a92f)
2022-07-13 22:48:35 +02:00
Camilla Löwy
fae1d349d3 Wayland: Rename fallback decoration functions
We are soon going to have three kinds of decorations; XDG, libdecor and
our last resort fallback ones.

(cherry picked from commit eb9c3bee71)
2022-07-13 22:48:35 +02:00
Camilla Löwy
593b85380e Wayland: Remove function only called once
(cherry picked from commit 0cd1916de3)
2022-07-13 22:48:35 +02:00
Camilla Löwy
a0259b9426 Wayland: Fix maximized state lost while hidden
If a window was created as maximized, or created as hidden and then
iconified or maximized before first being shown, that state was lost and
the window was shown as restored.

(cherry picked from commit 77819c0c54)
2022-07-13 22:48:35 +02:00
Camilla Löwy
e79d6fe40a Wayland: Fix events emitted before ack_configure
Window iconfication and maximization events were being emitted before
xdg_surface::configure, making it possible for user code to indirectly
commit surface changes from those event callbacks before
xdg_surface::ack_configure.

This postpones those events until after the ack has been sent.

(cherry picked from commit 85f5a51912)
2022-07-13 22:48:35 +02:00
Camilla Löwy
498a4d0635 Wayland: Fix missing error reporting
(cherry picked from commit 9ad9f5c52a)
2022-07-13 22:48:35 +02:00
Camilla Löwy
35fd90aff1 Wayland: Cleanup
Make Wayland code use 'native' in the same senses as the rest of GLFW.

(cherry picked from commit 5002522f73)
2022-07-13 22:48:35 +02:00
Camilla Löwy
6b9087c575 Wayland: Fix error from glfwSetWindowAspectRatio
The aspect ratio was applied during resize but any call to
glfwSetWindowAspectRatio emitted a GLFW_FEATURE_UNIMPLEMENTED error.

(cherry picked from commit 91f18fb576)
2022-07-13 22:48:35 +02:00
Camilla Löwy
48e0e0acf5 Wayland: Fix reporting of monitor scale changes
Content scale events would be emitted when a window surface entered or
left an output, but not when one of a window's current outputs had its
scale changed.

(cherry picked from commit e37ba80b13)
2022-07-13 22:48:35 +02:00
Camilla Löwy
557da4cdc4 Wayland: Fix duplicate monitor connection events
GLFW would report a monitor as connected each time its wl_output
received an update, for example if its scale changed.

This would also cause the monitor to be added to the monitor array
again, causing glfwTerminate to segfault when it attempted to destroy
its already destroyed wl_output.

(cherry picked from commit c3ad3d49ed)
2022-07-13 22:48:35 +02:00
Camilla Löwy
50ea41cb04 Wayland: Add support for wl_output::name
We now use wl_output::name as the GLFW monitor name, on compositors that
provide this event.

(cherry picked from commit 209f6cf093)
2022-07-13 22:48:28 +02:00
Camilla Löwy
2529e663d7 Wayland: Cleanup
(cherry picked from commit 33d37782c6)
2022-07-13 22:47:03 +02:00
Camilla Löwy
8b26801a30 Wayland: Fix toggling of server-side decorations
This is a temporary local fix to have updates to GLFW_DECORATED mostly
work as intended.  The whole decoration state machine needs to be
restructured, but not by this commit.

(cherry picked from commit 229d628ec4)
2022-07-13 22:47:03 +02:00
Camilla Löwy
e04a7d152a Wayland: Remove duplicate fullscreen check
This check is already performed in shared code.

(cherry picked from commit c28d420060)
2022-07-13 22:47:03 +02:00
Camilla Löwy
8de0c1cdc1 Wayland: Cleanup
(cherry picked from commit 18df0baea6)
2022-07-13 22:47:03 +02:00
Camilla Löwy
fead23153e Wayland: Fix size limits for fallback decorations
The size limits set on our XDG surface did not include the sizes of the
fallback decorations on all sides, when in use.  This led to its content
area being too small.

Related to #2127

(cherry picked from commit a7b6f35500)
2022-07-13 22:47:03 +02:00
Camilla Löwy
cdbcb8c5a7 Wayland: Fix erratic fallback decoration behavior
The handler for xdg_toplevel::configure treated the provided size as the
content area size when instead it is the size of the bounding rectangle
of the wl_surface and all its subsurfaces.

This caused the fallback decorations to try positioning themselves
outside themselves, causing feedback loops during interactive resizing.

Fixes #1991
Fixes #2115
Closes #2127
Related to #1914

(cherry picked from commit 0f5b095042)
2022-07-13 22:47:03 +02:00
Camilla Löwy
4ba1208239 Wayland: Rename window frame size constants
(cherry picked from commit 24cdc5afda)
2022-07-13 22:47:03 +02:00
Camilla Löwy
941744a59a Wayland: Remove unused code path
(cherry picked from commit 75295f4878)
2022-07-13 22:47:03 +02:00
Camilla Löwy
f454410b79 Wayland: Cleanup
(cherry picked from commit 040712ce99)
2022-07-13 22:47:03 +02:00
Camilla Löwy
5feaa33529 Wayland: Remove superfluous comments
These are just repeating parts of the identifier.

(cherry picked from commit 2877fea550)
2022-07-13 22:47:03 +02:00
Camilla Löwy
e894bf71a2 Wayland: Fix resize events before ack_configure
The surface was resized and the size event was emitted before we had
sent xdg_surface::ack_configure.  If user code then called some GLFW
function that commited the surface, those changes would all get applied
to the wrong configure event.

This postpones size changes until after the ack.

(cherry picked from commit e33db6d7aa)
2022-07-13 22:47:03 +02:00
Camilla Löwy
ebe2b648ea Wayland: Add tracking of XDG fullscreen state
(cherry picked from commit afb127769a)
2022-07-13 22:47:03 +02:00
Camilla Löwy
51018f19d0 Wayland: Use named constants for version checks
The wayland-scanner output provides really nice, self-documenting
version macros, so we should use them whenever possible.

(cherry picked from commit ed39ff43f9)
2022-07-13 22:47:03 +02:00
Camilla Löwy
1ad9c2d5dd Wayland: Cleanup
(cherry picked from commit 98c9961f32)
2022-07-13 22:47:03 +02:00
Camilla Löwy
1c4284e449 Wayland: Fix glfwInit closing stdin on failure
If platform initialization failed before either timer fd member had been
set to -1 or a valid fd, termination would close stdin.

(cherry picked from commit 3bbb41eacc)
2022-07-13 22:47:03 +02:00
Camilla Löwy
608007673f Wayland: Fix duplicate window content scale events
The window content scale event was emitted every time the window content
area was resized, even if its scale had not changed.

(cherry picked from commit 0b76e3a6f1)
2022-07-13 22:47:03 +02:00
Camilla Löwy
589385aada Wayland: Fix glfwSetWindowSize resizing fs windows
glfwSetWindowSize would change the size of fullscreen mode windows as
if they were windowed mode.

(cherry picked from commit 6857995498)
2022-07-13 22:47:03 +02:00
Camilla Löwy
15050f5711 Wayland: Fix missing fullscreen code path
glfwRestoreWindow assumed it was only called in windowed mode.

(cherry picked from commit fdc72edf81)
2022-07-13 22:47:03 +02:00
Camilla Löwy
562eca6f28 Wayland: Fix maximization by user being ignored
The internal maximization state was not updated when an event was
received that the user had changed the maximization state of a window,
and no maximization events were emitted.

This affected both the GLFW_MAXIMIZED attribute and glfwRestoreWindow.

(cherry picked from commit f39ffefb6a)
2022-07-13 22:47:03 +02:00
Camilla Löwy
dea602623d Wayland: Fix behavior of leaving full screen mode
These changes make GLFW fullscreen more consistent, but unfortunately
also make GLFW even more oblivious to user-initiated XDG shell
fullscreen changes.

Fixes #1995

(cherry picked from commit ddd087d662)
2022-07-13 22:47:03 +02:00
Emmanuel Gil Peyrot
581fed38be Wayland: Remove support for wl_shell
This is adapted to 3.3-stable from
599fb3de34 and
27295b508f.
2022-07-13 22:40:46 +02:00
Camilla Löwy
9f8ec83411 Wayland: Cleanup
(cherry picked from commit 523fdf50c1)
2022-07-12 20:29:22 +02:00
Camilla Löwy
631da8cc2f X11: Fix previous error handler not being restored
GLFW did not restore the previous Xlib error handler when removing its
own, instead resetting to the default handler.

This commit saves and restores the previous error handler.

None of this is thread-safe or could ever be.

Fixes #2108

(cherry picked from commit 26920a1a38)
2022-07-12 20:29:22 +02:00
Camilla Löwy
416f7828ff Fix joystick user pointer NULL during disconnect
The joystick code did not distinguish between the allocation status of
the GLFW joystick object and whether it is connection to an OS level
joystick object.

These are now tracked separately.

Fixes #2092

This is adapted to 3.3-stable from
2c204ab52e and
fd7e737216.
2022-07-12 20:27:34 +02:00
Camilla Löwy
6de6446aca Wayland: Fix missing lock key modifier bits
The modifier bits for lock keys were only set when the corresponding key
was reported as held down or latched, but not when it was released and
locked.

(cherry picked from commit e9c58bc181)
2022-06-10 17:11:25 +02:00
Camilla Löwy
2a6d25d1aa Win32: Add comment clarifying use of ToUnicode
Fixes #2100

(cherry picked from commit 62e175ef9f)
2022-06-10 17:11:13 +02:00
Camilla Löwy
f4e36e5389 Win32: Make monitor area retrieval more consistent
The rest of this file uses GetMonitorInfoW to retrieve this information.

(cherry picked from commit 7dfd84c458)
2022-06-10 17:11:13 +02:00
Camilla Löwy
b9ea733ca8 Move last bits of window setup to platform code
This avoids glfwCreateWindow emitting GLFW_PLATFORM_ERROR 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.

This is adapted to 3.3-stable from
09653b8c54.
2022-06-10 17:11:01 +02:00
Camilla Löwy
c8be8606f0 Win32: Fix message reported by VS 2022
(cherry picked from commit acf0c10e7a)
2022-06-09 19:55:34 +02:00
Camilla Löwy
1b3b2108e3 Win32: Remove superfluous cast
(cherry picked from commit 80e31ce9e1)
2022-06-09 19:55:30 +02:00
Camilla Löwy
65b8c4a46b X11: Fix segfault on malformed INCR response
The code assumed that at least some data would be received via the INCR
mechanism and that, as a result, the string buffer would be allocated.

Bug found by Clang static analysis.

(cherry picked from commit 23e6e8e4b7)
2022-06-09 19:55:18 +02:00
Camilla Löwy
946312fe93 X11: Fix returned clipboard string freed too early
The clipboard string should not be freed on SelectionClear.  The user
may have received it from glfwGetClipboardString and it should remain
valid until the next call to a public clipboard string function.

(cherry picked from commit f60547ac80)
2022-06-09 19:53:23 +02:00
Camilla Löwy
53d40878c8 X11: Fix OSMesa library not being unloaded
(cherry picked from commit a8d8b760fb)
2022-06-09 19:49:15 +02:00
Camilla Löwy
6dd9bf0bef Wayland: Fix OSMesa library not being unloaded
(cherry picked from commit 2d281d7928)
2022-06-09 19:48:31 +02:00
Camilla Löwy
6d08e52bcf Cocoa: Fix EGL and OSMesa not being unloaded
(cherry picked from commit 89514cf0fc)
2022-06-09 19:47:36 +02:00
Camilla Löwy
3d9d4e311c Win32: Fix OSMesa library not being unloaded
(cherry picked from commit 10e9033a29)
2022-06-09 19:42:44 +02:00
Camilla Löwy
af612103d0 Fix order of error checks in glfwSetGammaRamp
Initialization should be checked before arguments.

(cherry picked from commit 29523dbfbf)
2022-06-09 19:41:56 +02:00
Camilla Löwy
4143d96228 Fix glfwMakeContextCurrent using uninitialized TLS
Issue reported by danhambleton on the GLFW forum:
https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034

(cherry picked from commit f843d53333)
2022-06-09 19:41:10 +02:00
Camilla Löwy
05422e2824 Wayland: Add support for file drop events
This adds support for file path drop events in text/uri-list format.

It is based on work by Pilzschaf in #2040.

Closes #2040

(cherry picked from commit 4cb36872a5)
2022-06-09 19:39:28 +02:00
Camilla Löwy
2b504e41d5 Wayland: Clean up listener struct initialization
Adapt style to match the rest of the project.

(cherry picked from commit 0f38382e25)
2022-06-09 19:34:29 +02:00
Camilla Löwy
50d5de7cd4 Wayland: Make data offer reading a generic utility
This will be needed for drag and drop reception as well.

(cherry picked from commit f010335b8c)
2022-06-09 19:32:18 +02:00
Camilla Löwy
4d0e98d90c Wayland: Move window related code to window module
The Wayland backend was the only one where half the window and input
related code was in the init module.  As those bits want to share more
utility code with the window module, the interface between them grows.

To prevent that, this gathers nearly all window and input related code
into the window module.

This is adapted to 3.3-stable from
b7a3af9b79.
2022-06-09 19:29:12 +02:00
Camilla Löwy
c0c0d172a1 Wayland: Remove check for error that cannot happen
Famous last words.

(cherry picked from commit 967282c2e6)
2022-05-06 19:34:06 +02:00
Camilla Löwy
9e852ec39e Wayland: Remove error reporting of external bugs
Not sure that GLFW should be reporting that another client has made an
invalid receive request.

(cherry picked from commit 8d216054ad)
2022-05-06 19:34:06 +02:00
Camilla Löwy
4d68daedc9 Wayland: Clean up clipboard writing
(cherry picked from commit 34418951cc)
2022-05-06 19:34:06 +02:00
Camilla Löwy
ea1b6b9638 Move URI list parsing to shared code
This will soon be used by the Wayland backend.

(cherry picked from commit ad4a9e42f0)
2022-05-06 19:34:06 +02:00
Camilla Löwy
f145e1f930 Wayland: Add strerror output to error descriptions
(cherry picked from commit e0889736fd)
2022-05-06 19:34:06 +02:00
Camilla Löwy
915e43885c Wayland: Clean up clipboard reading
(cherry picked from commit c132135332)
2022-05-06 19:34:06 +02:00
Camilla Löwy
857fae4920 Wayland: Simplify clipboard string allocation
(cherry picked from commit 4651165272)
2022-05-06 19:34:06 +02:00
Camilla Löwy
a31c648127 Wayland: Improve handling of pending data offers
The code assumed that all data offers were selections that supported
plaintext UTF-8.

The initial data offer events are now handled almost tolerably.  Only
selection data offers are used for clipboard string and only if they
provide plaintext UTF-8.  Drag and drop data offers are now rejected as
soon as they enter a surface.

Related to #2040

(cherry picked from commit 8d87be1268)
2022-05-06 19:34:06 +02:00
Camilla Löwy
c89899a428 Wayland: Return our clipboard without roundtrips
(cherry picked from commit 89d3ea8d69)
2022-05-06 19:34:06 +02:00
Camilla Löwy
75b27849f6 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.

(cherry picked from commit 990dc4b388)
2022-05-06 19:34:05 +02:00
Camilla Löwy
f51ec79951 Wayland: Rename listener user data parameters
(cherry picked from commit a4460b694e)
2022-05-06 19:34:05 +02:00
Camilla Löwy
3599fe4a78 Wayland: Clean up pointer declarations
Adapt style to match the rest of the project.

(cherry picked from commit 4506175023)
2022-05-06 19:34:05 +02:00
Camilla Löwy
1ee540bf48 Wayland: Rename data transfer parameters
No rationale beyond personal preference.

(cherry picked from commit ba11e60859)
2022-05-06 19:34:05 +02:00
Camilla Löwy
32bedd9a94 Wayland: Fix phrasing of error messages
This is adapted to 3.3-stable from
2d45681bc3.
2022-05-06 19:34:05 +02:00
Camilla Löwy
25db8f8014 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.

(cherry picked from commit 4c110bba41)
2022-05-06 19:34:05 +02:00
Camilla Löwy
2430d6b7f7 Wayland: Remove superfluous global struct member
It seems unlikely that strlen will be a bottleneck when sending
clipboard contents.

(cherry picked from commit 738b1c73b5)
2022-05-06 19:34:05 +02:00
Camilla Löwy
53bd67ccfe 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.

(cherry picked from commit b386371f57)
2022-05-06 19:34:05 +02:00
Camilla Löwy
22f718dcf4 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.

(cherry picked from commit 9c95cfb9f1)
2022-05-06 19:34:05 +02:00
Camilla Löwy
f93751ce68 Fix missing newline
(cherry picked from commit 920d110b6c)
2022-05-06 19:34:05 +02:00
Camilla Löwy
8897c8a1cb POSIX: Fix data type of return values
(cherry picked from commit 554cbdb205)
2022-05-06 19:34:05 +02:00
Camilla Löwy
307ccd68a5 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

(cherry picked from commit 955fbd9d26)
2022-05-06 19:34:05 +02:00
Camilla Löwy
de550b60e5 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

(cherry picked from commit 07a5518c3e)
2022-05-06 19:34:05 +02:00
Camilla Löwy
802882f7cb 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

(cherry picked from commit 66a4882eb1)
2022-05-06 19:34:05 +02:00
Camilla Löwy
c2ccf6f919 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

(cherry picked from commit 8d9231fe5e)
2022-05-06 19:34:04 +02:00
Camilla Löwy
32df2ed716 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

(cherry picked from commit 03cfe957e7)
2022-05-06 19:34:04 +02:00
Camilla Löwy
3006c02bc2 Add shared min and max functions for int
(cherry picked from commit 3ee5031fd7)
2022-05-03 15:33:08 +02:00
Slemmie
d9fd087bbf X11: Fix undefined behavior in bit shift of int
Closes #1951

(cherry picked from commit b54fb0af10)
2022-03-20 16:02:44 +01:00
Camilla Löwy
5688fb19e6 Win32: Update rationale for reimplementation
It is true that plain MinGW lacks this header, but that is not the main
reason for reimplementing IsWindowsVersionOrGreater.

(cherry picked from commit aa803f7de5)
2022-03-20 16:02:08 +01:00
Camilla Löwy
d1269c1b7d Win32: Fix calls to encoding compatibility macros
Calls to Unicode specific functions should be made explicit.

(cherry picked from commit 8ff9ed92b4)
2022-03-20 16:00:34 +01:00
Camilla Löwy
541b151cff 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.

(cherry picked from commit 723f3eb40d)
2022-03-20 15:57:10 +01:00
Camilla Löwy
85a3bf40fb 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.

(cherry picked from commit 367d06deaf)
2022-03-20 15:53:39 +01:00
Camilla Löwy
d9512b694b 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

(cherry picked from commit a730acf8e5)
2022-03-20 15:51:55 +01:00
Camilla Löwy
35a65361ff POSIX: Fix undeclared function warning on Cygwin
(cherry picked from commit adc202d2c3)
2022-03-13 16:45:17 +01:00
Camilla Löwy
6659a80040 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.

(cherry picked from commit d78b0a4ead)
2022-03-13 16:43:58 +01:00
Camilla Löwy
9cfd4c49b0 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.

(cherry picked from commit 71742d9a27)
2022-03-13 16:38:02 +01:00
Camilla Löwy
eac18b9324 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

(cherry picked from commit a32cbf6d4f)
2022-03-13 16:36:17 +01:00
Camilla Löwy
499a5a7917 Formatting
(cherry picked from commit 7ce1f3e1cf)
2022-03-13 16:35:41 +01:00
Camilla Löwy
b0af476799 Wayland: Adopt the poll wrapper from X11
This is adapted to 3.3-stable from
bb9d699ae6.
2022-03-13 16:25:19 +01:00
Camilla Löwy
9dd3f25d6d 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.

(cherry picked from commit 203a7c59d2)
2022-03-13 16:19:31 +01:00
Camilla Löwy
7302a8f520 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.

(cherry picked from commit 3c2913dcb9)
2022-03-13 16:18:56 +01:00
Camilla Löwy
9f73e9afa3 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

(cherry picked from commit 84b0923fe6)
2022-03-13 16:18:07 +01:00
Camilla Löwy
5ccc756c56 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

(cherry picked from commit cd22e28495)
2022-03-13 16:17:25 +01:00
Camilla Löwy
e219c00d87 Cleanup
(cherry picked from commit 363d471441)
2022-03-13 16:13:54 +01:00
Camilla Löwy
7f752c17c6 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

(cherry picked from commit 87970b7f26)
2022-03-13 16:13:34 +01:00
Camilla Löwy
811e6bb01c 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

(cherry picked from commit 1e987cb92e)
2022-03-13 16:11:28 +01:00
Camilla Löwy
b4aa5f626f X11: Retry poll when failed with EINTR or EAGAIN
Both of these errors should just lead to local retry.

(cherry picked from commit 92b5c67b50)
2022-03-13 16:08:48 +01:00
Camilla Löwy
ca1a98e7a2 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

(cherry picked from commit d3e4fcf8b7)
2022-03-13 16:07:11 +01:00