Commit Graph

3019 Commits

Author SHA1 Message Date
Camilla Löwy
00a663dafd Wayland: Fix fallback decorations emitting errors
A GLFW_CURSOR_UNAVAILABLE error would be emitted each time the cursor
moved over the fallback decorations if the standard cursor shape
appropriate for that part was missing on the system.

These errors served no useful purpose and have been removed.
2023-06-01 20:12:13 +02:00
TheBrokenRail
0b94e1b29b Wayland: Fix detection of joysticks after init
Closes #2198
2023-03-31 16:18:46 +02:00
Camilla Löwy
9cce2896ee Null: Add (fictional) scancodes
This replaces the previous scheme where scancodes were equal to keycodes
(an implausible and potentially misleading situation) with a set of
scancodes invented purely for the null platform.
2023-03-31 15:56:01 +02:00
Camilla Löwy
fbdb53b9ca Wayland: Add initial support for libdecor
This is partly based on the implementation of libdecor support in
PR #1693 by @ christianrauch.

Where available, the libdecor library is loaded at init and becomes the
preferred method for window decorations.  On compositors that support
XDG decorations, libdecor in turn uses those.  If not, libdecor has
a plug-in archtecture and may load additional libraries to either use
compositor-specific decorations or draw its own.

If necessary, support for libdecor can be disabled with the
GLFW_WAYLAND_LIBDECOR init hint.  This is mostly in case some part of
the dynamic loading or duplication of header material added here turns
out to cause problems with future versions of libdecor-0.so.0.

Fixes #1639
Closes #1693
Related to #1725
2023-03-27 22:03:36 +02:00
Camilla Löwy
cd466cf9fd Wayland: Simplify decoration side detection
This commit simplifies the detection of which element of a fallback
decorated window the pointer has entered.  Instead of looping through
the list of windows, the user pointer of fallback decoration surfaces is
set to the GLFW window object.
2023-03-27 22:03:36 +02:00
Camilla Löwy
39f0e86228 Wayland: Clean up enum value names 2023-03-27 22:03:36 +02:00
Camilla Löwy
efa9297a41 Wayland: Simplify per-window ouput scales tracking
This replaces (one case of) manual management of weak links between
windows and monitors, both objects with complex life times, with
wl_object pointers used as opaque key values.
2023-03-27 22:03:36 +02:00
Camilla Löwy
91c837ace5 Wayland: Use tags to verify proxy ownership
This is in preparation for adding support for libdecor, which creates
its own proxies on our display.  It will likely also be helpful to some
people using native access on Wayland.

This is partly based on the implementation of libdecor support in
PR #1693 by @ christianrauch.
2023-03-27 22:03:36 +02:00
Camilla Löwy
6d9083af03 Wayland: Remove duplicate setting of user data
The surface user data is already set by wl_surface_add_listener.
2023-03-27 22:03:36 +02:00
Camilla Löwy
4cf510511c Wayland: Stop manually tracking interface versions
This is already tracked by the proxies we care about.
2023-03-27 22:03:36 +02:00
Camilla Löwy
c1a79c1c41 Wayland: Emit size event when setting aspect ratio 2023-03-27 22:03:36 +02:00
Camilla Löwy
8397b39afa Wayland: Fix some missing window refresh events 2023-03-27 22:03:36 +02:00
Camilla Löwy
735fc101f5 Wayland: Fix decorations not always being created
If a window was initially fullscreen then it would not get an XDG
decoration object.  If the window was later switched to windowed mode it
would then get fallback decorations instead of XDG ones.
2023-03-27 22:03:36 +02:00
Camilla Löwy
228428fa4f Wayland: Simplify test for fallback decorations
The GLFW fallback decorations only exist when the window is visible,
decorated and in windowed mode.
2023-03-27 22:03:36 +02:00
Camilla Löwy
82e77dbff4 Wayland: Pick more plausible default cursor size
This is not intended as a replacement for actually querying the desktop
for the correct size, but it appears to be a better fallback value.
2023-03-27 22:03:36 +02:00
Yoshinori Sano
5c463a9070 Win32: Fix typo in error description
Closes #2199
2023-03-03 14:36:12 +01:00
Takuro Ashie
41d8da1cea
Wayland: Fix wrong array size for _GLFWofferWayland
Closes #2225
2022-12-16 13:40:36 +01:00
TheBrokenRail
00967cbb8a
Linux: Fix joystick input being disabled
Closes #2192
2022-12-15 20:18:59 +01:00
Camilla Löwy
ab3ea8ac9f Win32: Remove unhelpful helper function 2022-09-15 22:25:10 +02: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
8a72918bcd Move helper macros to single point of use 2022-09-15 22:14:41 +02:00
Camilla Löwy
ab1b1edfd0 EGL: Cleanup
Both config parameters are "desired", but one is older and never had its
name updated.

This commit at least makes it clearer that they are similar.
2022-09-15 22:14:41 +02:00
Camilla Löwy
93e93135f2 EGL: Add better error for no stereo 2022-09-15 22:14:41 +02:00
Camilla Löwy
e057666642 EGL: Add better errors for client API mismatch
Because EGL ties client API support to configs, attempts to create
a context with an unavailable client API will fail with the unhelpful
"failed to find suitable config" error description.

This attempts to detect cases where there are usable configs for the
other client API and emit a hopefully more helpful error.

Related to #2173
2022-09-15 22:09:56 +02:00
Camilla Löwy
6b57e08bb0 Check if context creation APIs match when sharing 2022-08-22 19:17:12 +02:00
Camilla Löwy
2c0f34b60f WGL: Fix count of displayable pixel formats
We only care about displayable pixel formats (as defined in
WGL_ARB_pixel_format) for window context creation.

This changes pixel format enumeration to ignore non-displayable formats,
which are specified to be listed after displayable ones, by always using
the return value of DescribePixelFormat as the pixel format count.
2022-08-22 19:15:41 +02:00
Camilla Löwy
ef6c9d8b4f Wayland: Fix window opacity on older systems
On systems lacking the EGL_EXT_present_opaque extension, some
compositors treat any buffer with an alpha channel as per-pixel
transparent.

This commit ignores any EGLConfig with an alpha channel if the extension
is missing and the window is created with GLFW_TRANSPARENT_FRAMEBUFFER
set to false.

This is technically not a breaking change since GLFW_ALPHA_BITS is not
a hard constraint, but it is still going to inconvenience anyone using
the framebuffer alpa channel to store other kinds of data.

Related to #1895
2022-08-01 19:19:51 +02:00
Camilla Löwy
c18851f52e GLX: Add support for loading glvnd libGLX 2022-07-29 19:14:04 +02:00
Camilla Löwy
55aad3c37b EGL: Add support for loading glvnd libOpenGL 2022-07-29 19:14:04 +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
7d73629e50 X11: Preserve unrelated values in WM_NORMAL_HINTS
This stops GLFW overwriting the whole WM_NORMAL_HINTS property every
time it updates size-related parts of it.
2022-07-28 22:50:17 +02:00
Camilla Löwy
3a60992a41 Wayland: Add error for unsupported feature 2022-07-25 18:02:57 +02:00
Camilla Löwy
3a5c726d1b Wayland: Remove unreachable code
This platform function is only called if the cursor is enabled.
2022-07-25 18:02:57 +02:00
Camilla Löwy
7be6a2cabe Wayland: Clean up pointer helper function order 2022-07-25 18:02:57 +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
a46f829de8 Refactor cursor mode paths
This is the refactoring part of adding GLFW_CURSOR_CAPTURED, separated
out to help keep 3.3-stable similar to the main branch.

Related to #58.
2022-07-25 18:02:57 +02:00
Camilla Löwy
03af6b3d4c Wayland: Fix leaks of pointer related objects 2022-07-25 18:02:35 +02:00
Camilla Löwy
09ebf3f0bf Wayland: Fix error for missing protocol
A protocol not being available is not a platform error.  The platform is
doing fine; we're just sad that it lacks a feature we want.
2022-07-25 18:00:59 +02:00
Camilla Löwy
e85b645b8a Wayland: Clean up pointer locking
Shorten names and allow C99 declarations.  Replace helper function with
the NULL check it was hiding.  Separate cursor hiding from pointer
locking.
2022-07-25 17:53:04 +02:00
Michael Pennington
b9ed25d2e9 Wayland: Add GLFW_WAYLAND_APP_ID window hint
This adds a window hint string for the xdg_toplevel::app_id, which is
used by desktop environments to connect windows with application icons
and other information.  This is similar to the WM_CLASS property on X11.

A few very minor fixes were done by @elmindreda during merge.

Fixes #2121
Closes #2122
2022-07-24 17:51:54 +02:00
Camilla Löwy
26b85215c0 Wayland: Static function more static when static 2022-07-22 18:00:40 +02:00
Camilla Löwy
6987294df9 Wayland: Clean up cursor theme loading 2022-07-15 16:17:12 +02:00
Camilla Löwy
71be34a6c3 Wayland: Fix crash if mouse connected after init
The cursor theme was only loaded if the chosen seat had a mouse
(wl_pointer) during initialization.  If a mouse was connected only after
glfwInit, there would be no cursor theme but the rest of the cursor
related code assumed one had already been loaded.

This also moves the details of cursor theme loading out into a separate
function to declutter platform init.

Because the original cursor theme loading code checked whether we got
a wl_shm, and because the rest of the code just assumes we have
a wl_shm, initialization will now fail if there isn't one.

Fixes #1450
2022-07-15 16:17:12 +02:00
Camilla Löwy
7cc8b053b8 Wayland: Clean up shared memory buffer creation 2022-07-15 16:17:12 +02:00
Björn Hempel
c424fe5589 Linux: Fix joystick without buttons being ignored
Joysticks in Linux without buttons were ignored by device enumeration.
Remove the mandatory button attribute from detection.

Fixes #2042
Closes #2043
2022-07-15 15:50:06 +02:00
Camilla Löwy
40b5a8a37c Wayland: Fix reappearing key repeat
If the key or character callback performs actions that indirectly
updates the key repeat timer, those changes would be undone once the key
callback returned.

This fixes the order of operations so that key repeat is fully set up
before the key related events are emitted.
2022-07-13 21:54:55 +02:00
Camilla Löwy
9180923ea0 Wayland: Clean up key repeat logic 2022-07-13 21:54:55 +02:00
Camilla Löwy
a1a73ee862 Wayland: Make text input logic static
Since the seat listener was moved into wl_window.c there is no reason
for text input to have external linkage.
2022-07-13 21:51:04 +02:00
Camilla Löwy
e47cb7c1e2 Wayland: Update state before emitting events 2022-07-13 20:47:10 +02:00
Camilla Löwy
4df24735ef Wayland: Do not emit events for destroyed window
During platform window destruction, all of its callbacks have already
been removed, so emitting events for it does nothing.
2022-07-13 20:47:10 +02:00
Camilla Löwy
d77aaa770f Wayland: Fix non-standard struct initialization 2022-07-13 12:53:25 +02:00
Camilla Löwy
fd7e737216 Linux: Fix duplicate joystick objects
This fixes a regression introduced by
2c204ab52e.  This broke the check for
whether there is already a GLFW joystick object for a given input
device, making it always fail.
2022-07-12 11:53:13 +02:00
Camilla Löwy
6dd526fb1a Win32: Fix right Shift scancode when using CJK IME
Fixes #2050
2022-07-11 20:54:22 +02:00
Camilla Löwy
88a39006e3 Wayland: Cleanup 2022-07-11 20:54:21 +02:00
Camilla Löwy
5c948a6e6e Wayland: Fix comment typo 2022-07-11 20:54:21 +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
2db528d8cd Cocoa: Cleanup 2022-07-07 23:48:43 +02:00
Nikita Fediuchin
9b7713cf92 Cocoa: Fix search path for private Vulkan loader
According to both Apple and LunarG, a private copy of the macOS Vulkan
loader libvulkan.1.dylib should be placed in the Frameworks directory
of the bundle and not its main executable directory.

This commit updates the dynamic loading path accordingly.

Fixes #2113
Closes #2120
2022-07-07 23:48:16 +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
da6713cd09 Wayland: Do not decorate fullscreen windows
If a fullscreen window with GLFW_DECORATED set had its XDG decorations
changed to client mode by the compositor, it would seemingly receive
GLFW fallback decorations as if it was windowed mode.

This is possibly related to #2001.
2022-06-21 21:50:51 +02:00
Camilla Löwy
d578c2ddfe Wayland: Only create EGL window if using EGL 2022-06-21 21:50:50 +02:00
Camilla Löwy
74b4ceb835 Wayland: Cleanup
This moves what is effectively showing the window to where that is done
on other platforms, i.e. last in the platform CreateWindow function.
2022-06-21 21:49:06 +02:00
Camilla Löwy
c4fbe80d90 Wayland: Make function behavior match name
The logic that checks the decorated attribute belongs on the outside
along with other related checks (fullscreen, monitor, decoration mode).
2022-06-21 21:49:06 +02:00
Camilla Löwy
be7f4513c0 Wayland: Remove premature surface commit calls
Note that the handling of configure events, acks and commits is still
not ideal.  This is just a small step in, hopefully, a good direction.

Fullscreen toggling via glfwSetWindowMonitor now works on Weston, but
mostly incidentally.
2022-06-21 21:49:06 +02:00
Camilla Löwy
47193f15de Wayland: Rename function to its purpose 2022-06-21 21:49:06 +02:00
Camilla Löwy
80dc0533cf Wayland: Use enum type to store enum value 2022-06-21 21:49:06 +02:00
Camilla Löwy
29b7669bc6 Wayland: Fix transition to server-side decorations 2022-06-21 21:49:06 +02:00
Camilla Löwy
f35e2274cb Wayland: Fix GLFW_DECORATED for XDG decorations
On a compositor that supports server-side decorations, they were always
enabled in windowed mode, even if GLFW_DECORATED was cleared.
2022-06-21 21:49:06 +02:00
Camilla Löwy
3203599cac Wayland: Fix map before XDG decoration configure
If the xdg_toplevel has a decoration, we need to wait for its first
configure event as well before we are allowed to attach the first
buffer.

It seems racy to assume that this will always happen inside the first
surface configure sequence, so this commit makes that condition
explicit.  This may turn out to have been overly defensive.
2022-06-21 21:49:06 +02:00
Camilla Löwy
2df0ce07fa Wayland: Store and act on XDG decoration mode
Refer to the XDG decoration mode (or the lack of one) directly instead
of setting a boolean in a struct meant for the fallback decorations.

This makes things a bit more verbose but is in preparation for
a refactoring of all decoration paths.
2022-06-21 21:49:06 +02:00
Camilla Löwy
83a134a92f 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
2022-06-21 21:49:05 +02:00
Camilla Löwy
eb9c3bee71 Wayland: Rename fallback decoration functions
We are soon going to have three kinds of decorations; XDG, libdecor and
our last resort fallback ones.
2022-06-21 21:47:35 +02:00
Camilla Löwy
0cd1916de3 Wayland: Remove function only called once 2022-06-21 21:47:35 +02:00
Camilla Löwy
77819c0c54 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.
2022-06-21 21:47:35 +02:00
Camilla Löwy
e52046955d Wayland: Cleanup 2022-06-21 21:47:35 +02:00
Camilla Löwy
55fcfb1bb6 Wayland: Fix error for setting GLFW_FLOATING 2022-06-21 21:47:35 +02:00
Camilla Löwy
203002ef2c Wayland: Fix latent bug for glfwGetWindowTitle 2022-06-21 21:47:35 +02:00
Camilla Löwy
85f5a51912 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.
2022-06-21 21:47:35 +02:00
Camilla Löwy
9ad9f5c52a Wayland: Fix missing error reporting 2022-06-21 21:47:32 +02:00
Camilla Löwy
5002522f73 Wayland: Cleanup
Make Wayland code use 'native' in the same senses as the rest of GLFW.
2022-06-21 21:44:15 +02:00
Camilla Löwy
91f18fb576 Wayland: Fix error from glfwSetWindowAspectRatio
The aspect ratio was applied during resize but any call to
glfwSetWindowAspectRatio emitted a GLFW_FEATURE_UNIMPLEMENTED error.
2022-06-21 20:46:06 +02:00
Camilla Löwy
e37ba80b13 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.
2022-06-21 20:46:06 +02:00
Camilla Löwy
c3ad3d49ed 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.
2022-06-21 20:46:06 +02:00
Camilla Löwy
209f6cf093 Wayland: Add support for wl_output::name
We now use wl_output::name as the GLFW monitor name, on compositors that
provide this event.
2022-06-21 20:44:52 +02:00
Camilla Löwy
33d37782c6 Wayland: Cleanup 2022-06-21 16:00:33 +02:00
Camilla Löwy
229d628ec4 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.
2022-06-21 16:00:33 +02:00
Camilla Löwy
c28d420060 Wayland: Remove duplicate fullscreen check
This check is already performed in shared code.
2022-06-21 16:00:20 +02:00
Camilla Löwy
18df0baea6 Wayland: Cleanup 2022-06-20 00:57:17 +02:00
Camilla Löwy
a7b6f35500 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
2022-06-20 00:57:17 +02:00
Camilla Löwy
0f5b095042 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
2022-06-20 00:57:17 +02:00
Camilla Löwy
24cdc5afda Wayland: Rename window frame size constants 2022-06-20 00:57:17 +02:00
Camilla Löwy
75295f4878 Wayland: Remove unused code path 2022-06-20 00:57:17 +02:00
Camilla Löwy
040712ce99 Wayland: Cleanup 2022-06-20 00:57:17 +02:00
Camilla Löwy
2877fea550 Wayland: Remove superfluous comments
These are just repeating parts of the identifier.
2022-06-20 00:57:17 +02:00
Camilla Löwy
e33db6d7aa 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.
2022-06-20 00:57:17 +02:00
Camilla Löwy
afb127769a Wayland: Add tracking of XDG fullscreen state 2022-06-20 00:57:17 +02:00
Camilla Löwy
ed39ff43f9 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.
2022-06-20 00:57:17 +02:00
Camilla Löwy
98c9961f32 Wayland: Cleanup 2022-06-20 00:57:17 +02:00