Commit Graph

1759 Commits

Author SHA1 Message Date
Benjamin Otte
11aaa29a69 wayland: Use wl_surface_damage_buffer() in Cairo
... when it is available.

Also introduce the new function gdk_rectangle_transform_affine(), which
looks like overkill for this purpose, but I'm about to use it elsewhere.
2023-04-29 05:07:03 +02:00
Benjamin Otte
b4c859c011 wayland: Set EGL swap interval to 0.
There's no need for EGL to do any timing, we do it in GTK already.

This fixes hangs in Mesa when we hide a surface after a SwapBuffers()
but before the frame callback arrives.
If we then reshow the surface and immediately render to it, Mesa would
still have a frame callback from before the hiding and forever poll()
waiting for the compositor to send the callback.

Fixes #5761
2023-04-28 22:40:39 +02:00
Benjamin Otte
45216e1c88 wayland: Disconnect the frame callback when hiding
Do not leave spurious frame callbacks around wen hiding surfaces.
Instead, store the callback and remove it.
2023-04-28 22:21:42 +02:00
Benjamin Otte
9d0448756f display: Remove ::create_surface() vfunc
Instead, have a toplevel_type and popup_type in GdkDisplay and
call g_object_new() with those types.
2023-04-26 21:03:34 +02:00
Benjamin Otte
03d7ce3287 wayland: Set default title in toplevel_init() 2023-04-26 21:03:34 +02:00
Benjamin Otte
cb642bec25 gdk: Remove GDK_SURFACE_DRAG enum member
I want to remove the whole enum, but this value was used all over the
place. So removing it first ensures I didn't forget anything.
2023-04-26 21:03:34 +02:00
Benjamin Otte
8c530264f7 wayland: Create drag surface directly
... instead of going through create_surface().
2023-04-26 21:03:34 +02:00
Benjamin Otte
d99042dd91 wayland: Remove struct member
It's unused.
2023-04-26 21:03:34 +02:00
Benjamin Otte
808cde74be wayland: Construct the frame clock in the surface
... instead of passing it to g_object_new().
2023-04-26 21:03:34 +02:00
Benjamin Otte
b2e304189e wayland: Move surface initialization into constructed()
That way, it doesn't ned a specific init function.

Also chain up last, so that the generic initialization code can access a
fully initialized wayland surface.
2023-04-26 21:03:34 +02:00
Benjamin Otte
35c2d85468 wayland: Move toplevel-specific code into the toplevel
The display->toplevels tracking belongs to GdkWAylandToplevel.
2023-04-26 21:03:34 +02:00
Benjamin Otte
7ef5f6ef1a display: Remove x/y/w/h from create_surface() 2023-04-26 21:03:34 +02:00
Benjamin Otte
62951c7277 wayland: Don't leak all surfaces
X11 does add an extra reference to surfaces that gets released when the
DestroyNotify event arrives.
Wayland doesn't ave such an event, so that reference never gets
released.

This fixes a copy/paste error introduced in commit 590f3dfa1f.
2023-04-16 19:28:21 +02:00
Benjamin Otte
8e00f6e5e5 wayland: Don't insta-crash when a surface gets disposed
We want to remove the event queue from the list of event queues, not the
surface.
Otherwise the freed queue stays in the list and the next time an event
comes in, we access invalid memory.

Fixes thinko introduced in commit 7fafa5133b.

Luckily, we leak all surfaces, so this problem never occured.
2023-04-16 19:28:21 +02:00
Matthias Clasen
189aced844 wayland: Improve logging for primary selection 2023-04-15 15:02:52 +02:00
Benjamin Otte
75bea01a86 wayland: Keep EGL window around when hidden
See previous commit:

We want to keep resources around as long as the surface exists.
2023-04-13 05:19:18 +02:00
Benjamin Otte
5d3cec5441 wayland: Don't destroy the wl_surface on hide()
We want to keep the wl_surface around, because surfaces create their
resources on construct and keep them until destroyed. See the HWND ond
Windows and the XWindow on X11.

This is relevant for graphics resources, where we want to have access
to the VkSurface and eglSurface while the GdkSurface is hidden.
We also want these surfaces to be permanent and not change during the
lifetime of the GdkSurface.

What we can - and must - destroy however are the xdg surfaces, because
those handle visibility on screen.
And we also need to ensure no buffer is attached, so that during the
next creation of the xdg surface we don't get a protocol error.
2023-04-13 04:23:35 +02:00
Benjamin Otte
891242920e wayland: Split out a function
We have a create_wl_surface(), create a matching destroy_wl_surface().
2023-04-13 02:56:12 +02:00
Benjamin Otte
b375f17f09 wayland: Remove useless function
gdk_wayland_surface_maybe_resize() just calls
gdk_wayland_surface_update_size(), so make all callers call that one
instead.

The check that it does is done by the other function again.
2023-04-13 02:48:47 +02:00
Benjamin Otte
ec69990126 wayland: Remove an old workaround
This workaround - were it ever to trigger - is broken today. It destroys
the wl_surface and all associated structs but does not recreate the
xdg_popup or xdg_toplevel struct, so it would cause a hidden window.

The workaround looked a lot different when it was introduced in commit
83b54bab57, too - both in what it did and
in what the vfuncs did that it called.
2023-04-13 02:44:05 +02:00
Matthias Clasen
5e95c22844 wayland: Be more careful about scale-factor
Only emit notify::scale-factor if it actually
changes. This potentially avoids a lot of work
in GTK (reloading icons, etc).
2023-04-02 13:23:19 -04:00
Matthias Clasen
4746ffc4eb Make fractional scaling for GL opt-in
Fractional scaling with the GL renderer is
experimental for now, so we disable it unless
GDK_DEBUG=gl-fractional is set.

This will give us time to work out the kinks.
2023-04-02 11:05:57 -04:00
Matthias Clasen
fa58dd9256 Use fractional scale for the GL renderer
This commit combines changes in the Wayland backend,
the GL context frontend, and the GL renderer to switch
them all to use the fractional scale.

In the Wayland backend, we now use the fractional scale
to size the EGL window.

In the GL frontend code, we use the fractional scale to
scale the damage region and surface in begin/end_frame.

And in the GL renderer, we replace gdk_surface_get_scale_factor()
with gdk_surface_get_scale().
2023-04-02 09:22:56 -04:00
Matthias Clasen
075bea788b Add gdk_surface_get_scale
Add a scale property to GdkSurface and use the
fractional scale for it on Wayland.
2023-04-01 19:09:16 -04:00
Benjamin Otte
6d4d9af14e wayland: Use fractional scaling with the Cairo renderer
Cairo can do that, so just enable it:

 * Create surfaces with the correct fractionally scaled size.
 * Set the Cairo surface's device scale to that number.
2023-04-01 20:05:06 +02:00
Benjamin Otte
84b235aac1 wayland: Allow creating fractional Cairo surfaces
We don't do that yet, because the buffer scale code can't deal with it,
but we can do it now.
2023-04-01 20:05:05 +02:00
Benjamin Otte
1a71e82fc5 wayland: Use wp_viewport to set buffer scale
Instead of setting the buffer scale via the buffer-scale command, set it
via the viewport.

This technically allows setting fractional scales, but we're not doing
that.
2023-04-01 20:05:01 +02:00
Benjamin Otte
8dd5d649b8 wayland: Use GdkFractionalScale for surface scale
We still always round it to integers when we read it, but we store it as a fraction.

So we could now use it for fractional scaling.
2023-04-01 18:23:38 +02:00
Benjamin Otte
40ac6f22a3 wayland: Introduce GdkFractionalScale type
We want to use it later for various things, this just adds the
infrastructure we will need.
2023-04-01 18:23:38 +02:00
Matthias Clasen
ffdbb9077c wayland: Some debug spew tweaks 2023-04-01 09:31:12 -04:00
Benjamin Otte
54e8bd898a wayland: Add support for the fractional scale protocol
April fools!

No, really.
The fractional scale protocol is just a way to track the surface scale,
but not a way to draw fractional content.
This commit uses it for that, so tht we don't rely on tracking outputs.

This also allows magnifiers etc to send us a larger (integer) scale if
they would like that, that is not represented by the outputs.
2023-04-01 12:57:03 +02:00
Benjamin Otte
b4492a97bf wayland: Use wl_seat_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
6f93f52b56 wayland: Use zwp_pointer_gestures_v1_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
68b8c5cd99 wayland: Use gtk_shell1_get_version()
... or correct gtk_surface1_get_version() alternative.
2023-04-01 02:22:21 +02:00
Benjamin Otte
9d99259cbd wayland: Use wl_data_device_manager_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
55b5c847f7 wayland: Use zxdg_output_manager_v1_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
3d3d22e844 wayland: Remove unused variable
Also, Wayland has get_version() functions, so if we ever need it, we can
use that.
2023-04-01 02:22:21 +02:00
Benjamin Otte
ae2c28af89 wayland: Check correct interface
buffer scale is a surface property, so check the version of the surface
interface, not the compositor one.
2023-04-01 02:22:21 +02:00
Benjamin Otte
c7499a33fd wayland: Use wl_compositor_get_version()
Wayland has functions to check versions, so use those.
2023-04-01 02:22:21 +02:00
Benjamin Otte
c97b489316 wayland: Use proper macro
Wayland has macros to check required versions. Use those instead of
custom ones.
2023-04-01 02:22:21 +02:00
Matthias Clasen
a1c5a806b3 Convert headers to #pragma once
The conversion was done by guard2one.
2023-03-31 15:11:10 -04:00
Georges Basile Stavracas Neto
8217b6e484 gdk/wayland/surface: Track and apply buffer scale
Add a new flag to track whether buffer scale is dirty or not,
and centralize calling wl_surface_set_buffer_scale() in a single
place: gdk_wayland_surface_sync_buffer_scale().

gdk_wayland_surface_sync_buffer_scale() is only called by
gdk_wayland_surface_sync(), which itself is called by the GL,
Vulkan, and Cairo contexts, right before submitting a frame.
This ensure that each frame has an up-to-date buffer scale.

This mimics how opaque and input regions are tracked.
2023-03-30 16:32:50 -03:00
Matthias Clasen
65dc4cac86 wayland: Fix corner cases in positioning
We were not handling some cases correctly.
This was making the dropdown in the gtk-demo
image-scaling demo appear in the top left
corner.
2023-03-28 20:37:54 -04:00
Matthias Clasen
ea572227f0 Merge branch 'wayland-popup-anchor' into 'main'
wayland: Comply with protocol requirements

See merge request GNOME/gtk!5723
2023-03-28 15:36:34 +00:00
Jonas Ådahl
c88f2caa04 wayland/popup: Handle late received reposition feedback
If we map, reposition, unmap, remap, the reposition feedback from the
last time a popup was mapped might be received while we're dealing with
the new version of the popup. At this point, the old reposition token
has no meating, so lets drop it. Also reset the reposition tokens when
creating new protocol objects, so that the reposition token are as if
we're in the initial state.

This fixes an issue where we'd get stuck if repeatedly smashing a button
that'd create popups that'd immediately get dismissed by the compositor.
2023-03-27 21:27:44 +02:00
Ludovico de Nittis
d2672db648 wayland: Try to open the display even if XDG_RUNTIME_DIR is unset
Since Wayland 1.15, it is now possible to use absolute paths in
"WAYLAND_DISPLAY".
In that scenario, having a valid "XDG_RUNTIME_DIR" is not a requirement
anymore.

For this reason we remove the "XDG_RUNTIME_DIR" check and we let
`wl_display_connect()` decide if our environment is correct.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2023-03-27 11:53:57 +02:00
Matthias Clasen
3a5282abe1 wayland: Don't crash without xdg_activation_v1
If the compositor does not support this protocol,
we can't use it.

Fixes: #5701
2023-03-26 10:11:14 -04:00
Matthias Clasen
b81f9d3f94 wayland: Comply with protocol requirements
If you send a bad anchor rect to mutter, it crashes.
Thats not great, so lets not do that.
2023-03-26 09:47:46 -04:00
Matthias Clasen
7adbbe6f35 wayland: Don't crash on cursor size 0
The cursor-theme-size setting is documented as
'0 means the default size'. Make it so by using
size 24 if we see a 0. Its better than crashing.

Fixes: #5700
2023-03-25 20:25:51 -04:00
Ivan Molodetskikh
54e36f6b73 wayland: Reset pending offset in GL path
Otherwise GL surfaces that redraw without changing the hotspot have it
applied on top every frame and quickly slide away.

The cairo path and the X11 backend do not have this bug.
2023-03-15 16:11:40 -07:00