Commit Graph

112 Commits

Author SHA1 Message Date
Olivier Fourdan 73b9ff53c3 xwayland: Add a helper function to update fullscreen
Whenever the output configuration changes, if Xwayland is running
fullscreen, we may need to update the viewport in use or even update the
output on which Xwayland is currently running fullscreen.

Add a new helper function xwl_window_rootful_update_fullscreen() that
will recompute the fullscreen state and the viewport setup so that the
fullscreen Xwayland rootful window matches the new setup.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Kenny Levinsen <kl@kl.wtf>
2023-11-16 11:14:04 +01:00
Kenny Levinsen 53b6d4db7e xwayland: Apply root toplevel configure dimensions
While we now have support for resize of the root window through
libdecor, we still ignore toplevel configure dimensions when libdecor is
not in use. This ignores user intent in many Wayland servers, and some
xdg_toplevel states when active have strong requirements for adherence
to configure dimensions.

Resize in response to xdg_toplevel configure dimensions like we do for
libdecor configure events.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
2023-08-11 17:26:35 +02:00
Kenny Levinsen 4f869c6eda xwayland: Make xwl_window_libdecor_resize reusable
The upcoming handling of plain xdg_toplevel.configure events will need
to use the xwl_window resize helper. Move it outside XWL_HAS_LIBDECOR,
move the remaining dimension logic from handle_libdecor_configure into
it and update the name accordingly.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
2023-08-11 17:18:08 +02:00
Kenny Levinsen 295fb71653 xwayland: Commit after acknowledging configure
When handling libdecor configure, we first update our xwl output and
screen if dimensions differ from the current xwl_screen, and then commit
a new libdecor frame which acknowledges the xdg_surface.configure event.

If the initial configure events contains non-zero dimensions, we will
update the xwl output before acknowledging the initial configure. As we
attach a buffer and commit the surface when updating the output, this
leads to a protocol error.

Instead, move the surface commit till the end of the configure handler
so it always happens after the ack.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
2023-08-10 16:20:08 +02:00
Olivier Fourdan 881e1a5693 xwayland: Set min/max size for rootful with lidecor
Enforce sensible min/max values for the window size when using libdecor.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan f19fe9d260 xwayland: Use update size from libdecor configure handler
This is to avoid repeating the same code in two places.

This is essentially a cosmetic change, not a functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan c180eca8ef xwayland: Add configuration to libdecor update size
Allow passing an optional libdecor configuration pointer to
xwl_window_update_libdecor_size() so that we can reuse it from more than
one place and avoid duplicating that code.

No functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan 6d00c2bc10 xwayland: attach new buffer from libdecor handlers
The configure handler in libdecor is triggered any time a new
configuration is received.

According to the documentation from libdecor, an application should
respond to that event by creating a suitable libdecor_state, and apply
it using libdecor_frame_commit().

So we ought to attach a new buffer matching the new size and commit
the Wayland surface.

The actual content of the window does not need to be explicitly
repainted, that occurs through the call to SetRootClip():

  xwl_output_set_mode_fixed()
  -> update_screen_size()
     -> SetRootClip()
        -> miHandleValidateExposures()
           -> miWindowExposures()
              -> miPaintWindow()

This fixes an issue with mutter where maximizing a window and then
switching to another window would sometimes resize the Xwayland window
back to its pre-maximized size, or with Weston where the Xwayland window
would initially show up black until the pointer moves to the window.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan e37539e1e2 xwayland: Move the libdecor resize to its own function
This moves the code which updates the XRandR modes and sets the root
window size to its own function.

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

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan cda004c2a9 xwayland: Use the screen width/height for libdecor state
The configure handler for libdecor, namely handle_libdecor_configure(),
is where both the content and the decorations get resized (when needed).

If for any reason, the actual size of the Xwayland screen fails to be
updated, we would still appy the expected size rather than the actual
one for the libdecor state.

To avoid this, use the actual xwl_screen width/height for the libdecor
state.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan 8bbd908d1d xwayland: Move attach buffer out of post damage
For libdecor, we will have to attach a new buffer and commit from two
different handlers (libdecor configure and commit).

Having xwl_window_attach_buffer() separate from xwl_window_post_damage()
is to allow for that.

This commit should not introduce any functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2023-07-27 09:58:51 +02:00
Olivier Fourdan 516f1b96cd xwayland: Make Xwayland rootful resizable
By default, the Xwayland window in rootful mode was not resizable.

Make the Xwayland window resizable using libdecor in rootful mode.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2023-07-18 12:25:26 +02:00
Xaver Hugl 1ce2025822 xwayland: add support for wp-tearing-control-v1
Signed-off-by: Xaver Hugl <xaver.hugl@gmail.com>
Acked-by: Michel Dänzer <mdaenzer@redhat.com>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2023-06-19 12:19:35 +02:00
Jonas Ådahl 9a55c402aa xwayland/window: Queue damage after commits are allowed
Compositors may use XWAYLAND_ALLOW_COMMITS to communicate when Xwayland
may or may not commit new buffers to a wl_surface. If commits are
denied, then later allowed, we'll only get a buffer attached if there is
actual damage posted, which might be long after.

This fixes an issue where the window manager would reparent a window
while denying commits, then after reparenting, allow commits. The window
in question belonged to a game and took several seconds produce the next
frame, resulting in an empty window appearing as if it had just
disappeared.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2023-04-26 07:46:45 +00:00
Jonas Ådahl 5ce96a2a73 xwayland/window: Move set-allow functions lower down
This will make some helper functions in the same file usable without
extra declarations.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2023-04-26 07:46:45 +00:00
Michel Dänzer 754d6b6dd0 xwayland: Prevent nested xwl_present_for_each_frame_callback calls
It could happen with the following call path:

frame_callback
 xwl_present_frame_callback
  xwl_present_msc_bump
   xwl_present_execute
    xwl_present_flip
     xwl_window_create_frame_callback

The nested loop called xwl_present_reset_timer, which may end up calling
xorg_list_del for the entry after the one frame_callback started the
chain for. This resulted in the outer loop never terminating, because
its next element wasn't hooked up to the list anymore.

We avoid this by calling xwl_present_reset_timer as needed in
frame_callback, and bailing from xwl_window_create_frame_callback if it
was called from the former.

We also catch nested calls and FatalError if they ever happen again due
to another bug.

v2:
* Leave xwl_present_reset_timer call in xwl_present_frame_callback,
  needed if xwl_present_msc_bump didn't hook up the window to the frame
  callback list again.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1442
2023-03-27 08:19:31 +00:00
Michel Dänzer 4d1cd7cdc2 xwayland: Refactor xwl_present_for_each_frame_callback helper
Preparation for following changes, no functional change intended.
2023-03-27 08:19:31 +00:00
Simon Ser 6f0b9deed6 xwayland: use drmDevice to compare DRM devices
The linux_dmabuf_v1 protocol doesn't guarantee any DRM node type:
the compositor may send a primary node or a render node. Use
drmDevice so that device comparisons are node-type-insensitive.

Signed-off-by: Simon Ser <contact@emersion.fr>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1447
2023-03-03 14:18:49 +00:00
Michel Dänzer b5aa70503a xwayland: Spell XWAYLAND consistently in debug messages 2023-02-13 13:02:55 +00:00
Minh Phan ba644a64a4 xwayland/window: Do not double add window to damage list
The window might be retained in the damage list after
`xwl_screen_post_damage` in certain conditions. This means we need to
check if the window is already in the list to avoid adding the same
window twice which will lead to list corruption resulting in server freeze
in `xwl_screen_post_damage`.

Signed-off-by: Minh Phan <phanquangminh217@gmail.com>
2023-02-10 14:57:59 +00:00
Olivier Fourdan a7ee25f67d xwayland: Commit surface changes with libdecor configure
With libdecor, when the state changes (in the configure handler), we
need to commit the libdecor frame but also the wl_surface, otherwise
the surface is left in a uncommitted state until a wl_surface commit
eventually occurs later.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Fixes: c74c6add3e - xwayland: add optional support for libdecor
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2023-02-03 11:06:55 +01:00
Austin Shafer bddfe190de xwayland: Implement linux_dmabuf_feedback event handlers
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>

[ Michel Dänzer:
* Sort protocol #includes lexically.
* memcpy to &xwl_feedback->main_dev directly in
  xwl_dmabuf_feedback_main_device. ]
2023-01-20 17:56:54 +00:00
Joshua Ashton 87e5db75fb xwayland: Implement xwayland_shell_v1
Implements the xwayland_shell protocol which makes the surface
association happen via a shared serial, rather than sharing a wl_surface
resource ID across an X atom.

This solves a race that can happen if the wl_surface
associated with a WL_SURFACE_ID for a window was destroyed before the
update of the atom was processed by the compositor and another surface
(or other object) had taken its id due to recycling.

Closes: #1157

Signed-off-by: Joshua Ashton <joshua@froggi.es>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-21 11:13:07 +00:00
Olivier Fourdan a1d14aa8c5 xwayland: Clear the "xwl-window" tag on unrealize
Now that we keep the Wayland surface around for longer than the
xwl_window, we might get events for that surface after the X11 window
is unrealized.

Make sure we untag the Wayland surface when the Wayland surface is
delayed, to break the wl_surface/xwl_window relationship, so that events
for that surface are discarded by Xwayland.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Fixes: e37f18ee9 - xwayland: Delay wl_surface destruction
2022-10-19 07:26:59 +00:00
Olivier Fourdan e37f18ee97 xwayland: Delay wl_surface destruction
X11 and Wayland requests are unordered, causing a race in the X11 window
and wl_surface association.

To mitigate that race, delay the wl_surface destruction by 1 second,
so that the compositor has time to establish the association before the
wl_surface is destroyed: to see both the wl_surface created and the
WL_SURFACE_ID X11 property set.

This is only a mitigation though, a more robust solution requires a
future dedicated Wayland protocol.

v2: Clean up pending wl_surface destroy on exit as well.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1157
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Tested-by: Joshua Ashton <joshua@froggi.es>
Tested-by: Sterophonick <sterophonick@gmail.com>
See-also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/163
2022-09-28 17:00:48 +02:00
Olivier Fourdan c74c6add3e xwayland: add optional support for libdecor
When running rootful, the Xwayland window is not decorated (as all
Wayland surfaces), which makes it quite inconvenient to move on screen.

libdecor is "a client-side decorations library for Wayland clients"
which can be used precisely for adding decorations to Wayland surfaces.

Add optional support for libdecor in Xwayland to gain decorations when
running rootful and a new command line option "-decorate".

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1332
2022-06-30 17:53:01 +02:00
Olivier Fourdan 8a5f3ddb2e xwayland: set tag on our surfaces
That allows to differentiate Xwayland's own surfaces from others.

This is preparation work for optional libdecor support.

v2: Check for surface not being NULL (Jonas Ådahl <jadahl@gmail.com>)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan 41f3419fee xwayland: set the app_id and install a desktop launcher
The app_id is used to identify applications (and group windows), some
desktops (such as GNOME Shell) use it in their top bar.

Set the XDG toplevel "app_id" to "org.freedesktop.Xwayland" and install
a desktop file for Xwayland rootful.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan f31f059934 xwayland: add xdg-toplevel listener
So that when running rootful, the compositor can close the Xwayland
window using the xdg-toplevel protocol.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan 7a517f3967 xwayland: set the surface title when running rootful
Set a meaningful title for the xdg_surface, it's nicer when running
rootful.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan d0466e842a xwayland: move the root window surface to its own function
Currently, when running rootful, the toplevel root surface is created in
the same function as the rest of the Wayland surfaces.

Move it to its own function to improve readability - No function change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan d370f1e58a xwayland: add fullscreen mode for rootful
Add a new command line option "-fullscreen" to make the rootful Xwayland
window appear fullscreen.

This requires viewport support in the compositor and when used with
"-geometry" can emulate the full range of XRandR resolutions.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan 28e5faab28 xwayland: pass the emulated mode by reference
When using xrandr emulation, the emulated mode is passed as a pointer to
the XRandR mode from the xwl_output associated with the X11 client.

In preparation for fullscreen mode, we want to be able to reuse that
code but use a separate emulated mode.

Simply change the internal API to pass a reference to the emulated mode.

This introduces no functional change.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan f3e32cae51 xwayland: keep the xdg_toplevel around
The xdg_toplevel object was used solely when creating the window
surface, and the value of the object discarded.

To be able to make the surface fullscreen using the xdg_toplevel
protocol, we need to have access that object, so keep it around along
with the xwl_window.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Olivier Fourdan c7a50db7ff xwayland: keep track of the wl_output enter/leave
Keep track of the output the surface enters/leaves.

This is fairly basic tracking though, we do not keep a full list of
outputs a surface may be covering partially, we just keep the output
the surface entered last.

This is sufficient as a preparation work for fullscreen though.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2022-06-30 17:53:01 +02:00
Michel Dänzer 9e5a379610 xwayland: Always hook up frame_callback_list in xwl_present_queue_vblank
Even if there's no pending frame callback yet.

Without this, if there was no pending frame callback yet in
xwl_present_queue_vblank, xwl_present_msc_bump would only get called
from xwl_present_timer_callback, resulting in the MSC ticking at ~58
Hertz.

Doing this requires some adjustments elsewhere:

1. xwl_present_reset_timer needs to check for a pending frame callback
   as well.
2. xwl_window_create_frame_callback needs to call
   xwl_present_reset_timer for all child windows hooked up to
   frame_callback_list, to make sure the timer length takes the pending
   frame callback into account.
3. xwl_present_flip needs to hook up the window to frame_callback_list
   before calling xwl_window_create_frame_callback, for 2. to work.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1309
Fixes: 9b31358c52 ("xwayland: Use frame callbacks for Present vblank events")
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2022-03-17 10:22:34 +01:00
Olivier Fourdan 42113ab289 xwayland/present: Fix use-after-free in xwl_unrealize_window()
When a window is unrealized, Xwayland would destroy the Wayland surface
prior to unrealizing the present window.

xwl_present_flip() will then do a wl_surface_commit() of that surface,
hence causing a use-after-free:

 Invalid read of size 8
    at 0x49F7FD4: wl_proxy_marshal_array_flags (wayland-client.c:852)
    by 0x49F823A: wl_proxy_marshal_flags (wayland-client.c:784)
    by 0x42B877: wl_surface_commit (wayland-client-protocol.h:3914)
    by 0x42CAA7: xwl_present_flip (xwayland-present.c:717)
    by 0x42CD0E: xwl_present_execute (xwayland-present.c:783)
    by 0x42C26D: xwl_present_msc_bump (xwayland-present.c:416)
    by 0x42C2D1: xwl_present_timer_callback (xwayland-present.c:433)
    by 0x42BAC4: xwl_present_reset_timer (xwayland-present.c:149)
    by 0x42D1F8: xwl_present_unrealize_window (xwayland-present.c:945)
    by 0x4230E2: xwl_unrealize_window (xwayland-window.c:616)
    by 0x4FCDD8: compUnrealizeWindow (compwindow.c:292)
    by 0x4F3F5C: UnrealizeTree (window.c:2805)
  Address 0x1390b8d8 is 24 bytes inside a block of size 80 free'd
    at 0x48470E4: free (vg_replace_malloc.c:872)
    by 0x49F8029: wl_proxy_destroy_caller_locks (wayland-client.c:523)
    by 0x49F8029: wl_proxy_marshal_array_flags (wayland-client.c:861)
    by 0x49F823A: wl_proxy_marshal_flags (wayland-client.c:784)
    by 0x421984: wl_surface_destroy (wayland-client-protocol.h:3672)
    by 0x423052: xwl_unrealize_window (xwayland-window.c:599)
    by 0x4FCDD8: compUnrealizeWindow (compwindow.c:292)
    by 0x4F3F5C: UnrealizeTree (window.c:2805)
    by 0x4F424B: UnmapWindow (window.c:2863)
    by 0x4EF58C: DeleteWindow (window.c:1075)
    by 0x4E24B3: doFreeResource (resource.c:885)
    by 0x4E2ED7: FreeClientResources (resource.c:1151)
    by 0x4ACBA4: CloseDownClient (dispatch.c:3546)
  Block was alloc'd at
    at 0x4849464: calloc (vg_replace_malloc.c:1328)
    by 0x49F7F29: zalloc (wayland-private.h:233)
    by 0x49F7F29: proxy_create (wayland-client.c:422)
    by 0x49F7F29: create_outgoing_proxy (wayland-client.c:664)
    by 0x49F7F29: wl_proxy_marshal_array_flags (wayland-client.c:831)
    by 0x49F823A: wl_proxy_marshal_flags (wayland-client.c:784)
    by 0x4218CA: wl_compositor_create_surface (wayland-client-protocol.h:1291)
    by 0x422A0D: ensure_surface_for_window (xwayland-window.c:445)
    by 0x4231E8: xwl_window_set_window_pixmap (xwayland-window.c:647)
    by 0x5232D6: damageSetWindowPixmap (damage.c:1565)
    by 0x4FC7BC: compSetPixmapVisitWindow (compwindow.c:129)
    by 0x4EDB3F: TraverseTree (window.c:441)
    by 0x4FC851: compSetPixmap (compwindow.c:151)
    by 0x4F8C1A: compAllocPixmap (compalloc.c:616)
    by 0x4FC938: compCheckRedirect (compwindow.c:174)

To avoid that, call xwl_present_unrealize_window() before destroying the
Wayland surface.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2022-03-15 08:59:19 +00:00
Olivier Fourdan 47d3317464 Xwayland: Do not map the COW by default when rootless
The composite overlay window (COW) can be queried from any X11 client,
not just the X11 compositing manager.

If a client tries to get the composite overlay window, the Xserver will
map the window and block all pointer events (the window being mapped and
on top of the stack).

To avoid that issue, unset the "mapped" state of the composite overlay
window once realized when Xwayland is running rootless.

Note: All Xservers are actually affected by this issue, but with most
regular X servers, the compositing manager will take care of dealing
with the composite overlay window, and an X11 client using
GetOverlayWindow() won't break pointer events for all X11 clients.
Wayland compositors however usually run Xwayland rootless and have no
use for the COW.

v2: Avoid registering damage for the COW (Michel)
v3: Remove the "mapped" test to avoid calling register_damage() if the
    COW is not mapped (Michel)

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1314
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2022-03-08 16:43:01 +01:00
Olivier Fourdan 252cbad316 xwayland/glamor: Add return status to post_damage
If the glamor backend failed to post damage, the caller should do the
same to avoid a failure to attach the buffer to the Wayland surface.

Change the API of Xwayland's glamor backend post_damage() to return a
status so that xwl_window_post_damage() can tell whether the callee
failed.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1156
2021-05-11 14:08:58 +02:00
Olivier Fourdan 25d2f4948f xwayland: Check buffer prior to attaching it
If the buffer is NULL, do not even try to attach it, and risk a Wayland
protocol error which would be fatal to us.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Martin Peres <martin.peres@mupuf.org>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1156
2021-05-11 14:08:58 +02:00
Erik Kurzinger a9269808f3 xwayland: remove unused parameter of xwl_glamor_pixmap_get_wl_buffer
There are currently no callers that make use of the "created" output parameter
of xwl_glamor_pixmap_get_wl_buffer. Remove it, along with the corresponding
argument of the associated EGL backend entrypoint.
2021-01-08 06:17:51 -08:00
Mariusz Ceier 95539ab37b xwayland: Replace LogMessage with LogMessageVerb
LogMessage logs only when the XLOG_VERBOSITY is >= 1, but by default
XLOG_VERBOSITY is 0, so for example warning about deprected -listen
parameter is never shown when running "Xwayland -listen 32 -help".

Signed-off-by: Mariusz Ceier <mceier+freedesktop@gmail.com>
2020-12-08 09:16:52 +00:00
Michel Dänzer df3aa4922f xwayland: Make window_get_client_toplevel non-recursive
Noticed while reading the code.

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2020-11-09 09:54:09 +00:00
Olivier Fourdan 606ba7fc51 xwayland: Create an xwl_window for toplevel only
One general assumption in Xwayland is that the xwl_window remains the
same for all the child windows of the toplevel window.

When mapping a new X11 window, ensure_surface_for_window() checks for an
existing xwl_window by using xwl_window_get() which will just check for
the registered xwl_window for the window.

That means that a client mapping a child window of an existing window
with a xwl_window will get another different xwl_window.

If an X11 client issues a Present request on the parent window, hence
placed underneath its child window of the same size, the Wayland
compositor may not send the frame callback event for the parent's
Wayland surface which is reckoned to be not visible, obscured behind
the other Wayland surface for the child X11 window.

That bug affects some games running in wine which may get 1 fps because
the repaint occurs only on timeout with a long interval (as with, e.g.
https://bugs.winehq.org/show_bug.cgi?id=47066)

Fix ensure_surface_for_window() by using xwl_window_from_window() which
will walk the window tree, so that a child window won't get another
xwl_window than its parent.

https://gitlab.freedesktop.org/xorg/xserver/-/issues/1099
See-also: https://bugs.winehq.org/show_bug.cgi?id=47066
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2020-11-09 09:03:47 +00:00
Michel Dänzer 2beefda5a8 xwayland: Move xwl_surface_damage definition to xwayland-screen.c
It was already declared in xwayland-screen.h, and only takes a screen
parameter, no window ones.

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2020-07-07 13:47:11 +00:00
Michel Dänzer 5e91587302 xwayland: Delete all frame_callback_list nodes in xwl_unrealize_window
We were only calling xwl_present_unrealize_window for the toplevel
window, but the list can contain entries from child windows as well,
in which case we were leaving dangling pointers to freed memory.

Closes: https://gitlab.freedesktop.org/xorg/xserver/issues/1000
Fixes: c5067feaee "xwayland: Use single frame callback for Present
                     flips and normal updates"
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
2020-03-17 11:45:22 +01:00
mntmn 3d6efc4aaf xwayland: port rooted xwayland from wl_shell to xdg-shell protocol
Recently, rooted Xwayland crashes on wlroots-based compositors, because
wlroots removed the deprecated wl_shell protocol.
This MR fixes this by changing the code in question to the xdg-shell
protocol. My motivation do this: on etnaviv-based embedded platforms,
rooted Xwayland is much faster and doesn't cause UI rendering bugs
compared to rootless Xwayland.

Signed-off-by: Lukas F. Hartmann <lukas@mntre.com>
2020-02-28 16:23:58 +00:00
Hans de Goede 148f428dfc xwayland: Fix setting of _XWAYLAND_RANDR_EMU_MONITOR_RECTS prop on new windows
For window-manager managed windows, xwl_realize_window is only called for
the window-manager's decoration window and not for the actual client window
on which we should set the _XWAYLAND_RANDR_EMU_MONITOR_RECTS prop.

Usualy this is not a problem since we walk all client windows to update
the property when the resolution is changed through a randr call.

But for apps which first do the randr change and only then create their
window this does not work, and our xwl_output_set_window_randr_emu_props
call in xwl_realize_window is a no-op as that is only called for the wm
decoration window and not for the actual client's window.

This commit fixes this by making ensure_surface_for_window() call
xwl_output_set_window_randr_emu_props on the first and only child of
window-manager managed windows.

Note this also removes the non-functional xwl_output_set_window_randr_emu_props
call from xwl_realize_window, which was intended to do this, but does not
work.

This fixes apps using the ogre3d library always running at the
monitors native resolution.

Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:05:15 +01:00
Hans de Goede 4cfc2677f5 xwayland: Call xwl_window_check_resolution_change_emulation() on newly created O-R windows
Some clients, which use vidmode to change the resolution when going fullscreen,
create an override-redirect window and never trigger the screen->ResizeWindow
callback we rely on to do the xwl_window_check_resolution_change_emulation().

This causes us to not apply a viewport to them, causing the fullscreen window
to not fill the entire monitor.

This commit adds a call to xwl_window_check_resolution_change_emulation()
at the end of ensure_surface_for_window() to fix this. Note that
ensure_surface_for_window() exits early without creating an xwl_window
for new windows which will not be backed by a wayland surface and which
thus will not have an xwl_window.

This fixes ClanLib-0.6.x and alleggl-4.4.x using apps not properly
fullscreening.

Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:05:11 +01:00
Hans de Goede 10df0437a2 xwayland: Also hook screen's MoveWindow method
Not only hook the ResizeWindow method of the screen (which really is
MoveAndResize) but also hook the MoveWindow method for checking if we
need to setup a viewport for resolution change emulation.

Our resolution change emulation check if the windows origin matches
the monitors origin and the windows origin can also be changed by just
a move without being resized.

Also checking on a move becomes esp. important when we move to checking
on changes to the top-level non-window-manager client (X11)Window instead
of on changes to the xwl_window later on in this patch series.

Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:05:05 +01:00
Hans de Goede 4fc107460a xwayland: Also check resolution-change-emulation when the xwl_window itself moves
The recent change to use the top-level non-window-manager Window drawable
coordinates from xwl_window_check_resolution_change_emulation() in
combination with only calling it on a resize when the top-level window
is moved breaks things with mutter/gnome-shell.

When fullscreening a X11 window, mutter moves its window-decoration Window
wrapping the top-level Window to the monitor's origin coordinates (e.g. 0x0)
last. This updates the top-level's drawable coordinates, but as the
actual MoveWindow is called on the wrapper Window and not on the toplevel
we do not call xwl_window_check_resolution_change_emulation() and we never
enable the viewport.

This commit fixes this by also calling
xwl_window_check_resolution_change_emulation() if the Window being moved
is an xwl_window itself.

Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:05:03 +01:00
Roman Gilg 6d98f840da xwayland: Check emulation on client toplevel resize
When a reparented window is resized directly check the emulation instead of
doing this only when the window manager parent window is resized, what might
never happen.

For that to work we need to make sure that we compare the current size of the
client toplevel when looking for an emulated mode.

Changes by Hans de Goede:
- Remove xwl_window x, y, width and height members as those are no longer used.
- Add check for xwl_window_from_window() returning NULL.

Signed-off-by: Roman Gilg <subdiff@gmail.com>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:05:00 +01:00
Roman Gilg 060f10062e xwayland: Make window_get_none_wm_owner return a Window instead of a Client
Make window_get_none_wm_owner return the first non-wm-window instead of the
owner (client) of the first non-wm-window and rename it to
window_get_client_toplevel to match its new behavior.

This is a preparation patch for switching to using the drawable coordinates
in xwl_window_should_enable_viewport()

Changes by Hans de Goede:
- Split this change out into a separate patch for easier reviewing
- Rename window_get_none_wm_owner to window_get_client_toplevel to match
  its new behavior

Signed-off-by: Roman Gilg <subdiff@gmail.com>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:04:55 +01:00
Roman Gilg a69f7fbb54 xwayland: Recurse on finding the none-wm owner
An X11 window manager might add a chain of parent windows when reparenting to a
decoration window.

That is for example the case for KWin, which reparents client windows to one
decoration and another wrapper parent window.

Account for that by a recursion into the tree. For now assume as before that
all X11 window managers reparent with one child only for these parent windows.

Changes by Hans de Goede:
- Move the xwl_window_is_toplevel() from a later patch in this series here
  as it really belongs together with these changes
- Drop no longer necessary xwl_window argument from window_get_none_wm_owner
  parameters

Signed-off-by: Roman Gilg <subdiff@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:04:52 +01:00
Roman Gilg 948e02872f xwayland: Reuse viewport instead of recreating
When a viewport is already created we can reuse this object instead of
destroying it and getting a new one for updating the source rectangle and
destination size.

Signed-off-by: Roman Gilg <subdiff@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:04:49 +01:00
Hans de Goede ded89300c1 xwayland: Cache client-id for the window-manager client
Instead of iterating over all clients which are listening for events on the
root window and checking if the client we are dealing with is the one
listening for SubstructureRedirectMask | ResizeRedirectMask events and thus
is the window-manager, cache the client-id of the window-manager in
xwl_screen and use that when checking if a client is the window-manager.

Note that we cache and compare the client-id rather then the ClienPtr,
this saves reading the ClientPtr from the global clients array when doing
the comparison.

Suggested-by: Olivier Fourdan <ofourdan@redhat.com>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2020-02-23 18:04:00 +01:00
Michel Dänzer f88d9b1f77 xwayland: Split up xwl_screen_post_damage into two phases
The first phase sets the new surface properties for all damaged
windows, then the second phase commits all surface updates.

This is preparatory for the next change, there should be no observable
change in behaviour (other than the order of Wayland protocol
requests).

Reviewed-by: Adam Jackson <ajax@redhat.com>
2020-02-11 16:06:13 +01:00
Olivier Fourdan 58155baeac xwayland: Cleanup and remove `xwayland.h`
Now that each source and header should be in order, we can safely cleaup
the last remaining bits from the main `xwayland.h` which is not needed
anymore and can be removed.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan 0617c635fa xwayland: Separate Xwayland screen code
Move Xwayland screen related code to a separate source file and header.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan 091b24f13e xwayland: Move Xwayland input declarations
Move the Xwayland input declarations to their own header file.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan e23d2223d8 xwayland: Move Xwayland present declarations
Move the Xwayland Present declarations to their own header file.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00
Olivier Fourdan 89e32d00f6 xwayland: Move Xwayland windows to its own sources
Over time, Xwayland main source file `xwayland.c` has grown in size
which makes it look cluttered and harder to read.

Move the code dealing with Xwayland window to its own source and header
files.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-12-20 16:19:01 +01:00