Commit Graph

4668 Commits

Author SHA1 Message Date
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
Camilla Löwy
20adc18aa5 Wayland: Clean up monitor scale update 2022-03-02 19:38:41 +01:00
Camilla Löwy
152f50cd01 Wayland: Fix error type for allocation failure 2022-02-11 13:11:54 +01:00
Camilla Löwy
4a68926bfd Wayland: Remove unnecessary NULL checks
It is fine to pass NULL to _glfw_free.
2022-02-11 13:11:08 +01:00
Camilla Löwy
a28adba06a Wayland: Fix multiple copies of single constant 2022-02-11 13:11:08 +01:00
Camilla Löwy
97da62a027 Cocoa: Clarify comments on compatibility macros 2022-02-09 22:13:14 +01:00
Camilla Löwy
e023618daa Remove Doxyfile tag deprecated by Doxygen 1.9.3 2022-02-02 21:49:06 +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
Camilla Löwy
df8d7bc892 Wayland: Clean up modifier key event handler
Adapt style and naming to match the rest of the project.
2021-12-31 13:32:25 +01:00
Camilla Löwy
0ce611958e Wayland: Clean up key translation
Adapt style and naming to match the rest of the project.
2021-12-31 13:32:25 +01:00
Camilla Löwy
1a7da42e6e Wayland: Fix text input not following key repeat
The manual key repeat implementation did not call text input.
2021-12-31 13:30:16 +01:00
Camilla Löwy
bf99587005 Wayland: Clean up key event handler
Adapt style and naming to match the rest of the project.
2021-12-31 13:27:22 +01:00
Camilla Löwy
293d19a153 Wayland: Require xkbcommon 0.5.0 or greater
The Wayland backend now requires xkbcommon-compose, which was added in
version 0.5.0.  xkbcommon 0.5.0 was released in 2014.

This removes the non-composing fallback path for text input.
2021-12-31 13:27:22 +01:00
Camilla Löwy
b70259e52d Wayland: Clean up text input
Adapt style and naming to match the rest of the project.
2021-12-31 13:27:22 +01:00
Camilla Löwy
fe7be39793 Clean up internal Unicode code point handling
Call code points by their name and store them as uint32_t.
2021-12-31 13:27:22 +01:00
Camilla Löwy
17a9e34fbc Wayland: Implement key name support 2021-12-31 13:27:22 +01:00
Camilla Löwy
cb22c54119 Move UTF-8 encoding to shared code
This will be used by the Wayland code too.
2021-12-31 13:27:22 +01:00
Camilla Löwy
37b7540db9 Wayland: Fix keys reported as wrong or unknown key 2021-12-31 13:27:18 +01:00
Camilla Löwy
715b874db3 Wayland: Fix GLFW_VISIBLE affecting full screen
Full screen window creation was not ignoring the GLFW_VISIBLE hint.
2021-12-31 13:13:21 +01:00
Camilla Löwy
8aaea57421 Fix gamma test not checking for NULL return value 2021-12-31 13:13:21 +01:00
Camilla Löwy
25c521cbe5 Wayland: Fix missing damage event on window show
By definition a hidden window on Wayland does not have valid framebuffer
contents.

This adds a window damage (refresh) event when a window is shown, to
request an initial frame for the now visible window.
2021-12-31 13:13:21 +01:00
Camilla Löwy
c05acf6246 Wayland: Fix window not visible after initial swap
A window created with GLFW_VISIBLE set was not made visible by the
initial buffer swap during context attribute refresh.

Regression introduced by @elmindreda in
094aa6d3c7.
2021-12-31 01:32:18 +01:00
Camilla Löwy
12c2ccd609 Wayland: Remove window monitor array pre-alloc
The array will be allocated by surfaceHandleEnter when needed.
2021-12-31 01:32:18 +01:00
Camilla Löwy
216ea3d735 Wayland: Remove superfluous initialize to NULL
The whole window struct has already been cleared to zero.
2021-12-31 01:32:18 +01:00
Camilla Löwy
c1ecd4673e Wayland: Move window title cloning to creation 2021-12-31 01:32:18 +01:00
Camilla Löwy
7bede13b1d Wayland: Gather framebuffer transparency logic 2021-12-31 01:32:18 +01:00
Camilla Löwy
a3d1633e1d Wayland: Move surface creation function
This needs to be after createXdgSurface, which it will soon be calling.
2021-12-31 01:32:18 +01:00
Camilla Löwy
3f5dfeaf29 Wayland: Fix repeated key not released on defocus
Platform code should not generate key events with GLFW_REPEAT.
GLFW_PRESS is translated into GLFW_REPEAT by shared code based on the
key state cache.

This confused the automatic key release logic into not generating an
event with GLFW_RELEASE for a key being repeated when the window lost
input focus.
2021-12-31 01:32:18 +01:00
Camilla Löwy
850893a39f Wayland: Control key repeat via timerfd state
The key repeat logic is now controlled only via the key repeat timerfd.
2021-12-31 01:32:18 +01:00
Camilla Löwy
79e7e65c9d Wayland: Clean up event pump
Adapt style to the rest of the project.
2021-12-31 01:31:30 +01:00
Emmanuel Gil Peyrot
855d338a65 Wayland: Use correct action on fallback decoration
We were previously storing the pointer position only when on the main
window, so when the user clicked on a fallback decoration it would use
the last position of the cursor on the main window, instead of the
position in the decoration surface.

Fixes part of #1991.
2021-12-30 19:04:10 +01:00
Camilla Löwy
8edbc4971d Wayland: Document delayed window showing 2021-12-27 01:31:38 +01:00
Camilla Löwy
05b0e2fab2 Update docs for specific Vulkan surface extensions
Related to #2014
2021-12-26 18:10:18 +01:00
Camilla Löwy
7d060ba4f1 X11: Fix sonames for loaded libraries on OpenBSD
The OpenBSD ports tree assigns its own soname version numbers, so the
hardcoded sonames GLFW uses to load libraries on non-macOS Unices are
often incorrect.  Instead OpenBSD recommends that run-time loading
should leave out the version numbers entirely.  The OpenBSD ld.so then
finds the correct library.

This upstreams the ports tree fixes for Xcursor and EGL, and adds the
corresponding fix for all other run-time loaded library sonames.

Tested on OpenBSD 7.0.

This issue was initially reported on IRC.
2021-12-24 01:14:23 +01:00
Camilla Löwy
f8ef3ca719 Add hiding and showing to interactive window test 2021-12-24 00:56:44 +01:00
Jason Francis
094aa6d3c7 Wayland: Fix window hiding
Corrects the protocol violation when creating an xdg_surface from a
wl_surface that already has a buffer due to EGL buffer swaps.

This commit is based on PR #1731 by @ghost, but adapted and altered:
 - The XDG surface and role are now only created when a window is shown
   to prevent application lists from showing command-line applications
   with off-screen-only windows
 - The special case of Wayland+EGL buffer swap is now in the EGL code
   to mirror how X11 is handled
 - Adaption to run-time platform selection and separate credits file

Fixes #1492
Closes #1731
2021-12-24 00:55:31 +01:00
Camilla Löwy
e24fe4b189 Wayland: Fix key repeat continuing when refocused
If a window lost input focus while a key was held down, the key repeat
mechanism would resume once the window regained focus.
2021-12-22 14:51:05 +01:00
Camilla Löwy
c2f0a0ae59 Wayland: Fix duplicate focus event on activation 2021-12-22 14:51:04 +01:00