Commit Graph

120 Commits

Author SHA1 Message Date
Camilla Löwy
a9cc7c7260 Add GLFW_SCALE_FRAMEBUFFER window hint
This adds the GLFW_SCALE_FRAMEBUFFER window hint, enabling control of
framebuffer scaling across Wayland and macOS.  On macOS, this window
hint is a new name for GLFW_COCOA_RETINA_FRAMEBUFFER, and both hint
names will modify the same hint.

This is now a more symmetric counterpart to GLFW_SCALE_TO_MONITOR and,
weirdly, they each apply neatly to half of the supported platforms.

This commit is mostly documentation updates to better integrate and
contrast these two scaling mechanisms.
2024-02-14 22:35:46 +01:00
Camilla Löwy
6f1ddf51a1 Wayland: Remove unused struct member 2024-02-12 13:06:59 +01:00
Camilla Löwy
9953f7ead1 Wayland: Cache framebuffer size
The calculation of framebuffer size is about to get more complicated
with the introduction of fractional-scale-v1, so only do it in one
place.

This is also a tiny preparation for eventually behaving better towards
wl_egl_window_resize.
2024-02-12 13:06:59 +01:00
Camilla Löwy
1be7bc546b Wayland: Clean up data types related to scales 2024-02-12 13:06:59 +01:00
Camilla Löwy
4c283e4a3c Wayland: Be more specific about scales
We are about to introduce another scaling method (fractional-scale-v1),
so it will become more important to be specific about what scales are
used where and what their units are.

This removes 'content scale' from window and monitor structs.  A monitor
(output) now has just a 'scale', which becomes a 'buffer scale' when
applied to a window.  A window now has a list of 'output scales' to
select its buffer scale from.  Content scales are calculated from the
respective monitor or window when queried, even if the calculation right
now is to just return the same value as before.
2024-02-12 13:06:59 +01:00
Camilla Löwy
e25c1cc74f Wayland: Make fallback concepts more distinct 2024-02-12 13:06:59 +01:00
Camilla Löwy
72164e6921 Wayland: Remove fallback decoration edge enum 2024-02-12 13:06:32 +01:00
Camilla Löwy
a268b4b3a4 Wayland: Cleanup 2024-02-11 12:32:46 +01:00
Camilla Löwy
4baeadbd66 Wayland: Put fallback decorations behind a boolean 2024-02-11 12:32:27 +01:00
Camilla Löwy
ea6dd72c71 Wayland: Fix GLFW_HOVERED for fallback decorations
When using the fallback decorations, GLFW_HOVERED was true also when the
cursor was over one of the window decorations.

This also disentangles the GLFW_HOVERED state from the fallback
decorations.  Because GLFW_HOVERED should have had the same behavior as
GLFW_MAIN_WINDOW, the latter has been removed.
2024-02-09 14:33:01 +01:00
Camilla Löwy
5e97447dd5 Wayland: Clarify fallback decoration struct name
We now have three window decoration paths in the Wayland backend:
libdecor decorations, XDG decorations and fallback decorations.

This makes it clearer when code relates to the fallback decoration path,
which should increasingly (hopefully) not get used.
2024-02-09 14:22:23 +01:00
Jan Schürkamp
9317970243 Wayland: Implement glfwRequestWindowAttention
This implements window attention requests via the xdg-activation-v1
protocol.

This was updated by @ elmindreda to work with recent Wayland related
 changes to the main branch:
 - Switched to current way of handling Wayland protocol files
 - Added the xdg-activation-v1.xml protocol file to deps/wayland
 - Added missing macros to rename protocol interface globals

The protocol file was copied from wayland-protocols 1.33.

Closes #2287
2024-01-30 20:20:42 +01:00
Camilla Löwy
9fdc425931 Wayland: Use Wayland to wait for libdecor to init
Much of libdecor is initialized only after certain events have been
received from the compositor and some parts of libdecor 0.1 are unsafe
to use until this delayed initialization has completed.

Since libdecor does not provide an API to query if or be notified when
this has happened, GLFW processed events until its newly created
libdecor frame had created its XDG shell objects.

This commit switches to using a generic Wayland sync point created just
after libdecor (and presumably its plugin) has set up its delayed
initialization, instead of relying on the more specific implementation
detail mentioned above.

It also makes this wait mandatory before the first libdecor frame is
created instead of a pre-condition for certain libdecor frame calls,
hopefully removing even more dependence on implementation details.
2023-11-30 18:52:12 +01: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
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
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
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
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
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
80dc0533cf Wayland: Use enum type to store enum value 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
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
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
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
24cdc5afda Wayland: Rename window frame size constants 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
ddd087d662 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
2022-06-20 00:57:17 +02:00
Camilla Löwy
736a88b067 Fix return type of functions returning bool values 2022-06-08 22:14:38 +02:00
Camilla Löwy
e9c58bc181 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.
2022-06-08 19:20:01 +02:00
Camilla Löwy
4cb36872a5 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
2022-04-03 20:09:42 +02:00
Camilla Löwy
f010335b8c Wayland: Make data offer reading a generic utility
This will be needed for drag and drop reception as well.
2022-04-03 20:09:42 +02:00
Camilla Löwy
b7a3af9b79 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.
2022-04-03 20:09:42 +02:00
Camilla Löwy
4651165272 Wayland: Simplify clipboard string allocation 2022-04-03 19:45:09 +02:00
Camilla Löwy
8d87be1268 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
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
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
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
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
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
17a9e34fbc Wayland: Implement key name support 2021-12-31 13:27:22 +01: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
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
efe764b492 Remove blank line before the end of some structs 2021-10-12 12:54:35 +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
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