Commit graph

9065 commits

Author SHA1 Message Date
Ian Douglas Scott
4262fb182b xwayland: Release keys on keyboard enter event if leave wasn't received
The code here assumed a `leave` event always occurs between two `enter`
events. On Sway (and presumably other compositors) this happens even if
the client has destroyed the `wl_surface`, but the client gets a null
`surface` here. (Which presumably on on the wire is the id of the
destroyed surface.)

This seems like a bad thing to rely on, and is easy to avoid. But if
this is correct to assume, the Wayland protocol should be explicit about
this.

(cherry picked from commit 386b54fbe9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
54a591b9b8 xwayland: Do not include sys/eventfd.h without DRI3
Now that we won't enable DRI3 if <sys/eventfd.h> is not available, there
is not point in trying to include that header without DRI3.

That allows to build Xwayland with GLAMOR enabled (without DRI3) on
platforms which do not support eventfd.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 23c295ea8b)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
2a360e5c0f xwayland: Fix build without DRI3 enabled
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1668
(cherry picked from commit a58352b985)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
8937d47d08 xwayland/ei: Dequeue events when all caps are available
Currently, we would start dequeuing events as soon as a device is
resumed, regardless of its capabilities.

If the capabilities are not available, we would just fallback to the
regular XTEST code path and not use input emulation.

As a result, it is very likely that we shall lose the first events until
the compositor resumes first a device with the requested capabilities.

To avoid that issue, start emulating only once we have the requested
capabilities, if they match the seat capabilities.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1732
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 0525b9a5b9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
a1651d41e7 xwayland/ei: Move code to helper function
This is a small code refactoring to help with clarity, simply move the
code from the switch case for device resume to a dedicated function.

No functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 68ec297ee9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
fac3486a66 xwayland/ei: Log the type name of unhandled events
Currently, we would log only the event type, use the libei API to also
log the name in plain text, so we can quickly identify the events we're
missing out.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 1a42fe40d0)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
ce7fb8139a xwayland/ei: Handle EI_EVENT_KEYBOARD_MODIFIERS
Although we do not do anything with that event, handle it so we don't
end up in the "Unhandled event" territory.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1722
Fixes: a133334270 - xwayland: Add XTEST support using EIS
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit bfabd3bdab)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
98326b8c9f xwayland: Make sure output is suitable for fullscreen
Since commit d370f1e58, Xwayland can optionally be started rootful and
fullscreen.

To do so, it will setup a viewport to scale the root window to match the
size of the output.

However, if the rootful Xwayland window receives an xdg-surface configure
event before the output definition is complete, as with e.g. the labwc
Wayland compositor, we might end up trying to setup a viewport with a
destination size of 0x0 which is a protocol violation, and that kills
Xwayland.

To avoid that issue, only setup the viewport if the output size is
meaningful.

Also, please note that once the output definition is complete, i.e. when
the "done" event is eventually received, we shall recompute the size for
fullscreen again, hence achieving the desired fullscreen state.

Fixes: d370f1e58 - xwayland: add fullscreen mode for rootful
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1717
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 66f5e7e96a)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Alan Coopersmith
ca52da8cba Move sizeof to second argument in calloc calls
Clears -Wcalloc-transposed-args warnings from gcc 14.1, such as:

../dix/main.c:165:42: warning: ‘calloc’ sizes specified with ‘sizeof’ in the
 earlier argument and not in the later argument [-Wcalloc-transposed-args]
  165 |             serverClient = calloc(sizeof(ClientRec), 1);
      |                                          ^~~~~~~~~
../dix/main.c:165:42: note: earlier argument should specify number of
 elements, later size of each element

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
(cherry picked from commit 522f469fe9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1635>
2024-08-06 10:00:59 +02:00
Olivier Fourdan
8130fa083c xwayland: Check for pointer in xwl_seat_leave_ptr()
Since commit 792758fa ("xwayland: Update lost focus on deactivation"),
in rootful mode, if we receive an "activated" state from xdg-shell
indicating that the surface is no longer active, we shall end up calling
xwl_seat_leave_ptr().

But xwl_seat_leave_ptr() does not actually check whether the seat has
pointer capabilities, and if not, get_pointer_device() will return NULL.

As a result, we would crash using a NULL pointer in GetMaster(). This
typically can happen when using Xwayland rootful on headless compositors
such as "cage" which do not advertise any capabilities for the seat.

To avoid the issue, simply check whether get_pointer_device() returns a
valid non-null device and bail out early otherwise.

Fixes: 792758fa - xwayland: Update lost focus on deactivation
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1700
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 7203626173)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1592>
2024-07-09 11:35:49 +02:00
Olivier Fourdan
38060228c1 xwayland: Force disposal of windows buffers for root on destroy
With explicit buffer synchronization in use, the window buffers use a
file descriptor for event notification to keep the buffer alive for
synchronization purpose.

When running rootful, the root window (which is visible) is destroyed
directly from the resource manager on server reset, and the window
buffer's eventfd will trigger after the window is destroyed, leading to
a use after free and a crash of the xserver.

To avoid the issue, check whether the window being destroyed is the root
window in rootless mode, and make sure to force the disposal of the
window buffers in that case.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1699
(cherry picked from commit a5e863963e)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
4942b7c137 xwayland/window-buffers: optionally force disposal
For cases (to come) where we would want to force the disposal of the
window buffers, add a parameter to force the disposal by calling
dispose() directly instead of maybe_dispose().

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit fa04e15afc)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
f834e104aa xwayland/window-buffers: Move buffer disposal to its own function
No functional change, this is just preparation work for the next commit.

v2: Reshuffle functions (Michel)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 571cb13342)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
aa0ea88e13 xwayland: Make sure we do not leak xwl_window on destroy
Right now, we would dispose the xwl_window and all the data associated
with it on unrealize.

But not all window destruction go through the unrealize code path, for
example when the root window (running rootful) is destroyed from the
resource manager on server reset, we do not get to the unrealize window
step, but straight to destroy window.

As a result, we are leaking the xwl_window and all the data associated
with it, for example:

| 65,536 bytes in 1 blocks are possibly lost in loss record 12,462 of 12,488
|    at 0x484A0FC: calloc (vg_replace_malloc.c:1675)
|    by 0x48B661C: UnknownInlinedFun (pixman-bits-image.c:1273)
|    by 0x48B661C: _pixman_bits_image_init (pixman-bits-image.c:1296)
|    by 0x48B6754: create_bits_image_internal (pixman-bits-image.c:1349)
|    by 0x64180DE: UnknownInlinedFun (cairo-image-surface.c:380)
|    by 0x64180DE: UnknownInlinedFun (cairo-image-surface.c:366)
|    by 0x64180DE: cairo_image_surface_create (cairo-image-surface.c:432)
|    by 0x6346B44: UnknownInlinedFun (libdecor-gtk.c:467)
|    by 0x6346B44: libdecor_plugin_gtk_frame_new (libdecor-gtk.c:546)
|    by 0x4B7F297: libdecor_decorate (libdecor.c:559)
|    by 0x42C6F3: xwl_create_root_surface (xwayland-window.c:1266)
|    by 0x42CD97: ensure_surface_for_window (xwayland-window.c:1466)
|    by 0x42D0D1: xwl_realize_window (xwayland-window.c:1560)
|    by 0x50858F: compRealizeWindow (compwindow.c:279)
|    by 0x4FF2A2: MapWindow (window.c:2706)
|    by 0x4F9E7F: InitRootWindow (window.c:697)

To avoid that issue, check whether there is still an xwl_window
associated with the X11 window on destroy, and if that's the case,
dispose the xwl_window.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 0e1a98f52f)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
6a916c9658 xwayland: Move xwl_window disposal to its own function
No functional change intended, this is just preparation work for the
next commit.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 74be7a7f36)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
8f611b0f22 xwayland/window-buffers: Set syncpnts for all pixmaps
The wp_linux_drm_syncobj_v1 protocol states that :

| If at surface commit time there is a pending buffer attached but no
| pending release timeline point set, the no_release_point protocol
| error is raised.

So we need to set a release timeline point in any case from the swap
pixmap routine, even for the early out code paths.

Failing to do so may cause a Wayland protocol error that is fatal to the
Wayland client, in this case Xwayland:

| wp_linux_drm_syncobj_surface_v1: error 4: No Acquire point provided
| (EE) failed to dispatch Wayland events: Protocol error

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1688
Fixes: 87bf2cafcc - xwayland: add support for wp_linux_drm_syncobj_v1
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit bc9bf56360)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
33486519dc xwayland/window-buffers: Move code to submit pixmaps
Move the code which takes care of submitting pixmaps and the
synchronization points to its own function.

This will allow to reuse that code from different code path.

No functional change intended.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 33330f0dc9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
6636b7c003 xwayland/window-buffers: Do not always set syncpnts
The function xwl_window_swap_pixmap() can be called from two places,
either from xwl_window_attach_buffer() or from damage_report().

When called from xwl_window_attach_buffer(), the new buffer is attached
and the surface committed.

However, when called from damage_report(), a new buffer might not be
attached before the surface is committed.

That's fine with implicit synchronization, but if we use explicit
synchronization, committing a surface without a new buffer attached but
with a release timeline point set is a protocol error:

| If at surface commit time there is a pending release timeline point
| set but no pending buffer attached, a no_buffer error is raised.

To avoid such an issue, add a new parameter to xwl_window_swap_pixmap()
to hint whether it should set the synchronization points, and have the
synchronization points set only from xwl_window_attach_buffer().

v2: Rename param to handle_sync (Michel)

Suggested-by: Michel Dänzer <mdaenzer@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit aab01c7391)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
4382a4f84e xwayland/window-buffers: Use synchronization from GLAMOR/GBM
Now that we have the buffer synchronization implemented in the
GLAMOR/GBM code, switch to use that code.

At this point, there is still not functional change intended, this is
still preparation work for a fix that is still to come.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 256cef8b20)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
1539f208e2 xwayland/glamor/gbm: Copy explicit sync code to GLAMOR/GBM
Copy the code to deal with synchronization objects from the window
buffers to the GLAMOR/GBM code.

The idea is to deal with synchronizations for all pixmaps, even when
there is no window buffer involved.

This is still preparation work for the following commits, no functional
change intended at this point.

v2: Use a "xwl_window_buffer *" instead of a "void *data" (Michel)
v3: Bail early if there's no xwl_window_buffer (Michel)
v4: Rename xwl_window_submit_pixmap() to
    xwl_glamor_gbm_wait_release_fence() (Michel)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit cc021aca99)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
b1734ae737 xwayland/window-buffers: Add xwl_window_buffer_release()
We want to decorrelate the explicit buffer synchronization from the
window buffers, and move that to the GLAMOR/GBM code instead.

To do that, we need to be able to invoke the xwl_window_buffer's
release_callback() routine from outside the window buffer code.

For that purpose, introduce xwl_window_buffer_release() which calls
xwl_window_buffer_release_callback() for us.

This is preparation work for the following changes, no functional change
intended at this point.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit b5082073b0)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
23400afb72 xwayland/window-buffers: Promote xwl_window_buffer
Make the (opaque) definition of the xwl_window_buffer generally
available.

No functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 0e0472a005)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
05f4411523 xwayland: Stop on first unmapped child
If a child window of the same size is unmapped, we should stop walking
the tree looking for the surface window to use.

Whatever lies beneath is not visible anyway.

This also fixes an issue with the Damage list becoming corrupted when
destroying a window, because the first thing that DeleteWindow() does
is to unmap the window and crush the window tree underneath it.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Fixes: 3a0fc268 - xwayland: Add xwl_window::surface_window
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1680
(cherry picked from commit 32e16082c5)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
fbd40e878b xwayland: Do not use manual redirect windows as surface window
While walking the window tree looking for the surface window to use, we
should ignore windows using manual redirection.

If a client manually redirects a window, it has control over how the
contents of that window are presented. It's not safe to present them
directly to the Wayland compositor.

v2: break instead of continue, reword commit message (Michel)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Fixes: 3a0fc268 - xwayland: Add xwl_window::surface_window
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1677
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1679
(cherry picked from commit 0509b13fa2)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Chenx Dust
526dcbe120 xwayland: fix segment fault in xwl_glamor_gbm_init_main_dev
Function `xwl_glamor_gbm_init_main_dev` does not check whether
`xwl_screen->default_feedback.main_dev` a.k.a. `main_dev` is a
valid pointer. This result in some special situation where main
linux-dmabuf device is not accessible, such as KWin nested desktop,
raising segment fault.

This commit add a null pointer check to prevent crashing.

Signed-off-by: Chenx Dust <chenx_dust@outlook.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1683
Fixes: d7f1909e - xwayland/glamor/gbm: make wl_drm optional
See-also: https://bugzilla.redhat.com/2284141
(cherry picked from commit 7605833315)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Rouven Czerwinski
59bf93c770 xwayland: remove includedir from pkgconfig
Before this change, the xwayland pkgconfig file will always contain an
includedir directive, even though xwayland is not a linkable shared
library:

  prefix=/nix/store/3spcjqp5zcyg8arz6dnsj59fal5yk3jy-xwayland-23.2.6
  includedir=${prefix}/include

  exec_prefix=${prefix}
  xwayland=/nix/store/3spcjqp5zcyg8arz6dnsj59fal5yk3jy-xwayland-23.2.6/bin/Xwayland
  […]
  Cflags: -I${includedir}

According to a bug reporter this trips up cmake [1], which expects that
the include directory exists, which it does not since xwayland does not
install any header files.

Add the dataonly directive to pkgsconfig.generate() which will remove
the default "." subdir and ensures that includedir is not set inside the
pkgconfig file. Additionally enforce the install directory to
$libdir/pkgconfig, since it otherwise will be installed to
$datadir/pkgconfig, which precludes programs from finding the pkgconfig
because share/pkgconfig is usually not included in the search path.

The resulting pkgconfig does not contain an includedir:

  prefix=/nix/store/p7xhdzl65hfhzf36vxykzp2i9cyy7y6c-xwayland-23.2.6

  exec_prefix=${prefix}
  xwayland=/nix/store/p7xhdzl65hfhzf36vxykzp2i9cyy7y6c-xwayland-23.2.6/bin/Xwayland
  have_glamor=true
  have_eglstream=true
  have_initfd=true
  have_listenfd=true
  have_verbose=true
  have_terminate_delay=true
  have_no_touch_pointer_emulation=true
  have_force_xrandr_emulation=true
  have_geometry=true
  have_fullscreen=true
  have_host_grab=true
  have_decorate=false
  have_enable_ei_portal=true
  have_byteswappedclients=true

  Name: Xwayland
  Description: X Server for Wayland
  Version: 23.2.6

[1]: https://github.com/NixOS/nixpkgs/pull/309075#issuecomment-2108381428

Signed-off-by: Rouven Czerwinski <rouven@czerwinskis.de>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 9df084c8d1)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1569>
2024-07-04 08:36:40 +00:00
Olivier Fourdan
ce0e52dd0b xwayland: Move XRandR emulation to the ResizeWindow hook
This restores the handling of the XRandR emulation for Xwayland rootless
where it was before commit fa7b1c20.

Some compositors may trigger a protocol error if the viewport source is
larger than the actual window size, having that handled in the window
resize hook makes sure we do not regress.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 702a419c39)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1535>
2024-05-13 13:43:31 +02:00
Olivier Fourdan
2d0dabbe10 xwayland: Handle rootful resize in ResizeWindow
Commit fa7b1c20 ("xwayland: Use ConfigNotify screen hook instead of
ResizeWindow") replaced the WindowResize hook with ConfigNotify.

However, that's breaking rootful Xwayland with libdecor because the root
window size is already set so the libdecor size is not updated, and the
root size will be reverted back as soon as the focus changes.

Reinstate the rootful size change in ResizeWindow to avoid that issue.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1669
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1671
Fixes: fa7b1c20 - xwayland: Use ConfigNotify screen hook instead of ResizeWindow
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 31d6f9998d)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1535>
2024-05-13 13:43:24 +02:00
Olivier Fourdan
ce6c665e77 xwayland: Restore the ResizeWindow handler
For now it just chains to ResizeWindow hook.

This is preparation work for the next commit, no functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 539859bde0)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1535>
2024-05-13 13:43:21 +02:00
Joshua Ashton
3f4745cc4a xwayland: Send ei_device_frame on device_scroll_discrete
This fixes the scroll action in Steam Input in SteamOS/Gamescope when using the new libeis backend.

Fixes: a133334270 ("xwayland: Add XTEST support using EIS")
Signed-off-by: Joshua Ashton <joshua@froggi.es>
(cherry picked from commit 7745fde24e)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1535>
2024-05-13 13:43:07 +02:00
Vlad Zahorodnii
88ab664fab xwayland: Use correct xwl_window lookup function in xwl_set_shape
In xwl_set_shape(), xwl_window_set_input_region() should be called only
when the input shape of the toplevel window changes.

However, given that xwl_window_from_window() is going to walk the
ancestor tree until it finds an xwl_window, that lookup function cannot
be used. Instead, xwl_window_get() should be used. It's going to return
a valid xwl_window object iff the specified window has one associated
with it.

Fixes: a4ed100c0 - xwayland: Set wl_surface input region
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1672
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
(cherry picked from commit 8c2b9f4e71)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1535>
2024-05-13 13:42:41 +02:00
Michel Dänzer
9f28e2a85d xwayland/present: Skip queued flip when a new one becomes ready
If multiple flips become ready for the same MSC, we would previously
execute them all sequentially, one per MSC for sync flips. This could
result in an unbounded flip queue and corresponding memory consumption.

With implicit sync, leave the mailbox handling to the compositor for
async flips though.

v2:
* Use present_vblank_rec::sync_flip.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1664
Fixes: e1f16fb1ac ("xwayland: don't scrap pending present requests")
(cherry picked from commit 0d9a54aa97)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:50:04 +02:00
Erik Kurzinger
f10354d16a xwayland: use write fence in xwl_glamor_dmabuf_import_sync_file
The functions xwl_glamor_dmabuf_import_sync_file and
xwl_glamor_dmabuf_export_sync_file are used to ensure proper
synchronization between clients using PresentPixmapSynced and
compositors that do not support the wp_linux_drm_syncobj_v1 protocol
when presenting by flipping. The acquire point's fence will be imported
as the DMA-BUF's implicit fence before handing it off to the compositor,
and then, after the DMA-BUF has been released, its new implicit fence
will be exported and become the release point's fence which the client
is expected to wait for before re-using the buffer.

Both functions currently set the flags arguments of their respective
ioctls to DMA_BUF_SYNC_READ. When importing a sync file, this means that
any subsequent implicitly synchronized reads from the buffer will not
wait for the fence, and when exporting a sync file it means that the
returned fence may be signaled before preceeding reads from the buffer
have completed.

While this is correct for xwl_glamor_dmabuf_export_sync_file since the
compositor will never write to the buffer, it is incorrect for
xwl_glamor_dmabuf_import_sync_file. To avoid corruption, we need any
reads from the buffer by the compositor to wait on the acquire point's
fence.

As a fix, instead of setting the DMA_BUF_SYNC_READ flag in
xwl_glamor_dmabuf_import_sync_file, we set the DMA_BUF_SYNC_WRITE flag.
This *does* provide the necessary guarantees.

Signed-off-by: Erik Kurzinger <ekurzinger@nvidia.com>
(cherry picked from commit d5192ba8eb)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:18:51 +02:00
Vlad Zahorodnii
de65e7df4d xwayland: Set wl_surface input region
Some applications that use client side decorations usually set custom
input shape in order to prevent drop shadows stealing pointer events
from windows below. Currently, the only way to get it is to use some
XFixes APIs.

On the other hand, plenty of wayland compositors use solely the
wl_surface input region to decide what view can receive pointer input,
which results in some pointer input issues around client side drop
shadows because Xwayland doesn't set wl_surface.input_region.

See-also: https://bugs.kde.org/show_bug.cgi?id=448119
Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit a4ed100c0c)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:17:45 +02:00
Olivier Fourdan
eec66b819d xwayland: Do not remove output on withdraw if leased
On DRM lease connector withdrawn event, Xwayland would free the
corresponding xwl_output offered for lease.

However, the pointer is still referenced from the rrLease->outputs[],
meaning that trying to clean up the RANDR DRM leases as done with commit
ef181265 (xwayland: Clean up drm lease when terminating) would cause a
use after free and random crashes.

To avoid that issue, on the connector withdraw event, set the connector
withdrawn flag but do not to remove (i.e. free) the xwayland output if
its is offered for lease.

Then, once the lease is terminated, check for the xwl_outputs with a
withdrawn connector and remove them (once we have no use for them
anymore.

Note that we cannot do that cleanup from xwl_randr_terminate_lease() as
removing the xwl_output will free the RRcrtc resources, which checks for
leases in XRANDR, and calls RRTerminateLease(), which chains back to
xwl_randr_terminate_lease().

v2: Use a "withdrawn_connector" flag to mark outputs to remove (Xaver)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Xaver Hugl <xaver.hugl@kde.org>
fixes: ef181265 - xwayland: Clean up drm lease when terminating

See-also: https://gitlab.freedesktop.org/xorg/xserver/-/issues/946
See-also: https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1130
(cherry picked from commit 4053782443)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:17:42 +02:00
Olivier Fourdan
cb6c7256ab xwayland: Check for outputs before lease devices
In xwl_randr_request_lease(), the code checks first for leased device,
and then checks for existing output for lease.

The former assumes there are outputs for lease whereas the latter checks
for the output, connector and lease.

So if there is any existing rrLease->outputs[]->devPrivate unset, the
code would crash on a NULL pointer dereference on the first sanity check
before having a chance to reach the second check that would have caught
the problem.

Invert the sanity checks so that we would catch this first and return a
BadValue instead of possibly segfaulting.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Xaver Hugl <xaver.hugl@kde.org>
(cherry picked from commit 21916ae148)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:17:39 +02:00
Michel Dänzer
34832a182c xwayland/glamor: Handle depth 15 in gbm_format_for_depth
Prevents Xwayland with glamor from logging

 unexpected depth: 15

to stderr many times when running

 rendercheck -t blend -o clear

(cherry picked from commit 08113b8923)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:17:36 +02:00
Olivier Fourdan
74d02b98ab xwayland: Use the connector name for XRANDR leases
Use the connector name as basis for the Xwayland output name in XRANDR,
similar to what we do for regular outputs, instead of the generic
"XWAYLAND<n>" name which changes every time the output is leased.

Prefix the actual name with "lease-" to distinguish from duplicate names
from the regular outputs.

v2: avoid duplicate names (Simon)
v3: Move the check for duplicates to xwl_output_set_name() (Simon)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 49b8f131f7)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:17:32 +02:00
Olivier Fourdan
aa17d7eba6 xwayland: Check for duplicate output names
Even though the name provided by either xdg-output or wl_output are
guaranteed to be unique, that might not be the case with output names
between different protocols, such as the one offered for DRM lease.

To avoid running into name conflicts, check that no other existing
output of the same name exists prior to changing the output name.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit d36f66f15d)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:16:44 +02:00
Olivier Fourdan
158246a0af xwayland: Make xwl_output_set_name() public
No functional change, this is preparation work for the next commit.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 0cb4ec4dbd)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:16:41 +02:00
Olivier Fourdan
80af615ea9 xwayland: Define MAX_OUTPUT_NAME in the header
So that other parts of the Xwayland code can use it.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 12265aaa1c)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-05-02 10:16:37 +02:00
Olivier Fourdan
4725674a23 xwayland: Use the path to Xwayland as installed
Otherwise the executable cannot be found where specified.

v2: Use 'xwayland_path' (Simon)

Fixes: fbf5e26b5 - xwayland: Use full path for Xwayland exec
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
(cherry picked from commit 8ff88ffec9)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1494>
2024-04-18 14:00:03 +02:00
Michel Dänzer
3d5eb2df23 Don't install Xvfb
We're keeping it for unit tests, but we don't want to ship it from this
branch.

Also disable Xvfb in CI for ninja test. It's still built and used for
unit tests as part of ninja dist, but we don't want to run XTS on Xvfb.

(cherry picked from commit 0408fcb329)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Michel Dänzer
1f80c795e0 Drop Xephyr / kdrive DDX
(cherry picked from commit 9335ee7994)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Michel Dänzer
dfea734656 Drop Xorg DDX
v2: Change the FDO_DISTRIBUTION_TAG (Michel)

(cherry picked from commit 4f4b8e00fc)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Michel Dänzer
34fac2d7df Drop Xwin DDX and x86 MinGW-w64 cross build
(cherry picked from commit 8f480147f6)

This partly reverts commit d3933a24d1.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Michel Dänzer
735009cda3 Drop Xnest DDX
(cherry picked from commit 69cc6a6caa)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Michel Dänzer
700cdeeee4 Drop Xquartz DDX
(cherry picked from commit 6cae4b397d)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1483>
2024-04-12 10:40:05 +02:00
Olivier Fourdan
385226bdaf xwayland: Walk the regions' boxes
In xwl_source_validate(), the actual box wasn't updated, so we would
possibly copy several times the same first box.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Fixes: aa05f38f3 - xwayland: Add SourceValidate hook
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1485>
2024-04-12 07:38:26 +00:00
Michel Dänzer
4dc7e99840 xwayland: Use drmDevicesEqual in xwl_dmabuf_feedback_tranche_done
xwl_dmabuf_feedback_tranche_target_device always allocates a new
drmDevice for xwl_feedback->tmp_tranche.drm_dev, so the pointers are
never equal here.

Fixes: 6f0b9deed6 ("xwayland: use drmDevice to compare DRM devices")

v2:
* Flip order of checks, so drmDevicesEqual is called only if the
  supports_scanout flags match.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1484>
2024-04-12 07:25:55 +00:00