1
0
Fork 0
Commit graph

2099 commits

Author SHA1 Message Date
Niels De Graef
3dd9f15eba shaped-texture: Start using MetaMultiTexture
To be able to later support more complex YUV formats, we need to make
sure that MetaShapedTexture (the one who will actually render the
texture) can use the MetaMultiTexture class.

Co-Authored-By: Robert Mader <robert.mader@collabora.com>
Co-Authored-By: Daniel van Vugt <daniel.van.vugt@canonical.com>
Co-Authored-By: Sebastian Wick <sebastian.wick@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Gergo Koteles
7b04e8be15 wayland: Find touch grab sequence in subsurfaces also
With libdecor, window moving/resizing only works with
the pointer, not with touch.
The meta_wayland_pointer_can_grab_surface checks for subsurfaces,
but the meta_wayland_touch_find_grab_sequence does not.

Add a similar subsurface check to
meta_wayland_touch_find_grab_sequence.

Closes: GNOME/mutter#2872
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3125>
2023-07-19 13:07:51 +00:00
Bilal Elmoussaoui
b852bbba47 cleanup: Stop translating nick/blurb for pspecs
As those strings are intended to be used by some UI but nothing uses
that in reality except GStreamer.
So drop them similar to what GTK did at
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4717

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3101>
2023-07-19 11:33:59 +00:00
Robert Mader
efe884a97f wayland: Remove DRM_FORMAT_MOD_INVALID defines
In both cases we already unconditionally import drm_fourcc.h and all
distros shipping recent Mutter should by now have versions of that file
containing MOD_INVALID.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
96778aa8b1 wayland/dma-buf: Make use of meta-cogl-drm-formats
Removing duplication, making it easier to add new formats and ensuring
that the native backend and Wayland clients can use the same formats.

Also improve related build files so the Wayland backend can be build
without the native backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
ae88e13c5a wayland/buffer: Clean up format map
Use the newly introduced opaque formats where appropriate, allowing us
to drop the custom components handling.

Also use pre-mult alpha. This may slightly improve upload times
and should generally be more correct.

Tested with `weston-simple-shm`, ensuring the alpha channel still gets
ignored for opaque formats, and `gradient-test` from
https://gitlab.freedesktop.org/jadahl/wayland-test-clients

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Corentin Noël
6b9efc3b0c wayland: Make the MetaWaylandCompositor type public
Allows mutter implementation to have access to the underlying wl_display.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3092>
2023-06-27 16:17:16 +00:00
Carlos Garnacho
c858ad7f91 wayland: Unset keyboard focus if surface is destroyed
Depending on the ordering of the surface-associated resources
being destroyed, we may fall into the following situation:

 - wl_surface is destroyed
 - destruction notifications for the surface runs
 - The MetaWaylandKeyboard attempts to synchronize the window
   focus
 - The MetaWindow is not destroyed yet, so the focused window
   remains the same, and the MetaWaylandKeyboard keeps the same
   focus MetaWaylandSurface.
 - wl_surface finalizes destruction, MetaWaylandSurface now has
   a NULL resource
 - xdg_toplevel destructor kicks in, it unmanages the window
 - The current focus window is again looked up, forced to look
   a different window
 - The MetaWaylandKeyboard focus now changes, tries to leave the
   old surface, but it has a NULL resource already, and raises
   a protocol error.

If the order is inverted, the window being unmanaged triggers a
focus change into a different window, the MetaWaylandKeyboard
triggers a focus change while the MetaWaylandSurface is still
intact, it succeeds, and the window gets properly destroyed.

In order to make this independent of the order, it makes sense
to make MetaWaylandKeyboard do like the other objects tracking
focus surfaces, and have it care of its own little parcel. The
surface destructor changed to simply unsetting the keyboard focus
to NULL (guaranteeing that the old focus is left while the surface
resource is still up), and leaving potential focus changes to
the xdg_toplevel_destructor->unmanage->update_focus paths.

Doing that alone is basically a revert of commit 228d681b, thus
is still subject to keyboard focus being lost after a popup is
destroyed. Change the approach to trigger the focus sync (and
new focus surface lookup) so it happens from xdg_popup_destructor
specifically to popups and alike xdg_toplevel.

Fixes: 228d681b ("wayland: Trigger full focus sync after keyboard focus surface is destroyed")

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2853
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3077>
2023-06-19 13:13:54 +00:00
Carlos Garnacho
bc04fcb89d core: Change MetaWaylandTextInput event forwarding to IMs
We need to juggle with some things here to keep key event ordering
and accounting consistent.

The keyboard internal state changes (and maybe modifier event emission)
happening through meta_wayland_seat_update() should ideally happen
from the same key events that reach the client through wl_keyboard.key,
so that wl_keyboard.modifier events are emitted in the right relative
order to other key events.

In order to fix this, we need to decide at an earlier point whether
the event will get processed through IM (and maybe be reinjected),
thus ignored in wait of IM-postprocessed events.

This means we pay less attention to whether events are first-hand
hardware events for some things and go with the event that does
eventually reach to us (hardware or IM).

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5890
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3044>
2023-06-13 14:21:41 +00:00
Carlos Garnacho
eaa09be17c wayland: Account for doubly pressed/released keys in MetaWaylandKeyboard
Given the presence of IMs and the different paths in event handling to reach
one of them, we cannot make guesses about whether should stick to the original
hardware-triggered event, or wait/prefer a second hand IM event that might or
might not arrive. We also have no say for other IM foci unrelated to wayland
(e.g. ClutterText) triggering the double event emission.

So go with it and maintain our own internal state for keys, we already kinda
do, but mainly for warning purposes, at the time of updating the
MetaWaylandKeyboard state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3044>
2023-06-13 14:21:41 +00:00
Carlos Garnacho
7b26aab08d wayland: Add compositor API to get the text input object
We need to open code a bit the event handling of MetaWaylandTextInput,
in order to avoid out of order events.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3044>
2023-06-13 14:21:41 +00:00
Carlos Garnacho
7716b62fa2 clutter: Separate ClutterInputFocus event processing and filtering
Currently, we let the same function handle key event filtering as they
are passed to the IM, and the IM events resulting in actions like text
commit or preedit changes.

Split these two aspects into filter/process functions, and port
ClutterText to it. MetaWaylandTextInput still handles everything in
a single place, but that will be split in later commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3044>
2023-06-13 14:21:41 +00:00
Carlos Garnacho
ff4953caa6 wayland: Remove redundant ifdef
It's already surrounded by the same ifdef

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3044>
2023-06-13 14:21:41 +00:00
Jonas Ådahl
cef1a5d377 wayland/actor-surface: Only set input region of non-X11 window actors
Xwayland nevers sets the input region since that is handled using
`XShapeGetRectangles()` called with `ShapeInput`. Setting it from the
wl_surface would mean setting it to "infinite", effectively undoing what
`ShapeInput` communicated.

https://gitlab.gnome.org/GNOME/mutter/-/issues/2788

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3022>
2023-05-29 13:21:14 +00:00
Jonas Ådahl
e829862249 wayland/actor-surface: Set opaque region even without X11 client support
A `#ifdef` macro wrapped too much making opaque regions no longer being
set if mutter would be compiled without X11 client support.

Fixes: 6e818c8c38 ("build: Allow disabling xwayland")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3022>
2023-05-29 13:21:14 +00:00
Robert Mader
4a5a31edc6 mutter: Remove stray spaces
To silence code-style-check complains.

Fixes d44f02ba64

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3018>
2023-05-24 14:16:41 +02:00
Bilal Elmoussaoui
d44f02ba64 mutter: Cleanup gi-docgen annotations
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2939>
2023-05-22 15:47:37 +00:00
msizanoen1
ae403f2e94 wayland: Use new highest scale monitor tracking for fractional_scale_v1
This ensures consistency with the surface pixel alignment transforms.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2726>
2023-05-22 14:44:33 +00:00
msizanoen1
e94b527777 surface-actor/wayland: Implement stable size and position rounding
Implement the stable rounding algorithm as described in the discussions
for the fractional-scale-v1 protocol.

This adds an override of the ClutterActor::apply_transform vfunc for
MetaSurfaceActorWayland that ensures the size and position of the
contents of the surface are rounded according to the stable rounding
algorithm.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2726>
2023-05-22 14:44:33 +00:00
Bilal Elmoussaoui
b9a6891910 display: Drop the indirection when initializating Xwayland
The init function didn't do much other then calling into the xwayland
one

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2445>
2023-05-15 20:47:06 +02:00
Bilal Elmoussaoui
02a436d607 wayland: Move surface check to MetaWaylandSurface
Allows dropping various HAVE_XWAYLAND ifdef as the function would always
return false if Mutter is built without XWayland

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2445>
2023-05-15 20:41:54 +02:00
Bilal Elmoussaoui
a27b9d9707 wayland: Guard XWayland types
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2445>
2023-05-15 20:41:54 +02:00
Jonas Ådahl
1a4f03bd79 wayland/surface: NULL check surface resource in handle_output_bound()
Otherwise binding new wl_output's might try to send enter to the
destroyed resource. Fixes the following crash:

     #0 wl_resource_get_client at ../src/wayland-server.c:801
     #1 handle_output_bound at ../src/wayland/meta-wayland-surface.c:1287
     #3 signal_emit_unlocked_R.isra.0 at ../gobject/gsignal.c:3812
     #6 ffi_call_unix64 at ../src/x86/unix64.S:104
     #7 ffi_call_int at ../src/x86/ffi64.c:673
     #8 ffi_call at ../src/x86/ffi64.c:710
     #9 wl_closure_invoke at ../src/connection.c:1025
    #10 wl_client_connection_data at ../src/wayland-server.c:438
    #11 wl_event_loop_dispatch at ../src/event-loop.c:1027
    #12 wayland_event_source_dispatch at ../src/wayland/meta-wayland.c:125
    #15 g_main_context_iterate.isra.0 at ../glib/gmain.c:4276
    #17 meta_context_run_main_loop at ../src/core/meta-context.c:482

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2196527
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2992>
2023-05-09 15:26:32 +00:00
Robert Mader
754a1a1ce6 wayland/dma-buf: Enable modifiers by default on non-native backend
If the used EGL backend supports it. In practice this should currently
only affect the nested backend.

Enabling modifiers can help with app development. An example is
`weston-simple-dmabuf-v4l`, which requires the linear modifier to be
available.

Note that Weston behaves similar already.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2972>
2023-04-20 15:34:00 +00:00
Robert Mader
b56ab36704 xdg-shell: Always handle frame callbacks in popup_apply_state()
Just like we do in `toplevel_apply_state()`.

Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/2752

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2963>
2023-04-20 12:34:47 +00:00
Michel Dänzer
db24557e40 wayland/xdg-shell: Bail from popup_configure if resource was destroyed
This function gets called when a surface state transaction is applied.
Applying a transaction can get delayed, so the Wayland resource may have
already been destroyed when we get here. In that case we cannot send
events, so there's nothing to do.

v2:
* Drop code comment, expand commit log instead. (Jonas Ådahl)

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2737
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2967>
2023-04-18 10:37:18 +00:00
Jonas Ådahl
867494d3df wayland/cursor-surface: Update cursor on dispose
Otherwise we'll have a cursor sprite backed by a surface that no longer
exist. This usually doesn't happen, but can happen in rare situations
related to pointer capability changes Wayland client cursor changes and
hotplugs.

Fixes the following crash:

  #0 meta_wayland_buffer_get_resource() at ../src/wayland/meta-wayland-buffer.c:128
  #1 realize_cursor_sprite_from_wl_buffer_for_gpu() at ../src/backends/native/meta-cursor-renderer-native.c:1649
  #2 realize_cursor_sprite_for_gpu() at ../src/backends/native/meta-cursor-renderer-native.c:1869
  #3 realize_cursor_sprite() at ../src/backends/native/meta-cursor-renderer-native.c:1887
  #4 meta_cursor_renderer_native_update_cursor() at ../src/backends/native/meta-cursor-renderer-native.c:1100
  #5 meta_cursor_renderer_update_cursor() at ../src/backends/meta-cursor-renderer.c:414
  #6 meta_cursor_renderer_force_update() at ../src/backends/meta-cursor-renderer.c:449
  #7 update_cursors() at ../src/backends/meta-backend.c:328
  #8 meta_backend_monitors_changed() at ../src/backends/meta-backend.c:338
  #9 meta_monitor_manager_notify_monitors_changed() at ../src/backends/meta-monitor-manager.c:3590
 #10 meta_monitor_manager_rebuild() at ../src/backends/meta-monitor-manager.c:3678
 #11 meta_monitor_manager_native_apply_monitors_config() at ../src/backends/native/meta-monitor-manager-native.c:343
 #12 meta_monitor_manager_apply_monitors_config() at ../src/backends/meta-monitor-manager.c:706
 #13 meta_monitor_manager_ensure_configured() at ../src/backends/meta-monitor-manager.c:779
 #14 meta_monitor_manager_reconfigure() at ../src/backends/meta-monitor-manager.c:3738
 #15 meta_monitor_manager_reload() at ../src/backends/meta-monitor-manager.c:3745

or the following on gnome-43:

 #0 meta_wayland_surface_get_buffer at ../src/wayland/meta-wayland-surface.c:441
 #1 meta_cursor_sprite_wayland_get_buffer at ../src/wayland/meta-cursor-sprite-wayland.c:83
 #2 realize_cursor_sprite_from_wl_buffer_for_gpu at ../src/backends/native/meta-cursor-renderer-native.c:1612
 #3 realize_cursor_sprite_for_gpu at ../src/backends/native/meta-cursor-renderer-native.c:1836
 #4 realize_cursor_sprite at ../src/backends/native/meta-cursor-renderer-native.c:1854
 #5 meta_cursor_renderer_native_update_cursor at ../src/backends/native/meta-cursor-renderer-native.c:1087
 #6 meta_cursor_renderer_update_cursor at ../src/backends/meta-cursor-renderer.c:413
 #7 meta_cursor_renderer_force_update at ../src/backends/meta-cursor-renderer.c:448
 #8 update_cursors at ../src/backends/meta-backend.c:344
 #9 meta_backend_monitors_changed at ../src/backends/meta-backend.c:354

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2185113
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2968>
2023-04-17 19:53:35 +00:00
Robert Mader
a7a7933e03 wayland: Emit frame events in GSource after "empty" updates
Under certain conditions a stage-view update does not trigger a kms
update.

In such cases we still want the next update to run within the same
refresh cycle, as otherwise we'd waste the remaining time in the
current one.
At the same time we currently use the `after-update` signal for Wayland
frame events, which again may result in more "empty" updates -
creating an unthrottled feedback loop. This can trigger excessive
load both in the compositor as well as in clients.

Introduce a new GSource that is dispatched once per refresh cycle at
maximum per stage view and use it to emit frame events. Do so by
computing the time from when on we can be sure that an update resulting
from a client commit would certainly get scheduled to the next refresh
cycle.

Note: this only works on the native backend. Given that chances are
small that we hit the corresponding issue on e.g. the nested backend,
stick to the previous behavior there for now.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2823>
2023-04-17 09:16:10 +00:00
Sebastian Keller
a86900091d wayland: Set compositor when creating MetaWaylandDataSourceXWayland
create_and_send_dnd_offer() sets the compositor of the offer to the one
from the MetaWaylandDataSource. This then later gets used in
display_from_offer() when trying to get the context from the compositor.
meta_wayland_data_source_xwayland_new() however was not setting the
compositor, so this was causing crashes when dragging things from X11
windows on Wayland.

Fixes: 2731f0cda ("wayland: Setup and use ownership chains")
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2723
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2956>
2023-04-15 16:01:42 +00:00
msizanoen1
1b140e8cb9 wayland/data-device: Clear data source when cancelling drag with ESC
This ensures a consistent code path with other cases where the drag
operation might be cancelled.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2953>
2023-04-15 10:11:07 +00:00
Sebastian Keller
5a4b67dd9e wayland: Don't leak XDnD mime type strings
After this got changed from gdk_x11_get_xatom_name() to XGetAtomName(),
this no longer returns a const char* and it now also needs to be freed.

Fixes: 014cde646 ("wayland: Do not use GDK functions on XDnD implementation")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2957>
2023-04-14 13:27:19 +00:00
Jonas Ådahl
47b6e76578 xdg-shell: Early out of apply if dismissed
We might end up trying to apply a pending state late if it was delayed
by DMA buffers not being ready. Trying to discard the pending state from
the transaction when dismissing is hard, because we might be applying a
chain of transactions that would disqualify subsequent transactions if a
former one dismisses the popup, so lets just drop what the apply would
otherwise do, if we're not going to use it anyway.

This fixes the following crash:

  0) meta_wayland_surface_get_window (surface=0x0)
  1) meta_wayland_xdg_popup_apply_state (surface_role=0xf5ee80, pending=0xf662a0)
  2) meta_wayland_surface_role_apply_state (surface_role=0xf5ee80, pending=0xf662a0)
  3) meta_wayland_surface_apply_state (surface=0xf5e640, state=0xf662a0)
  4) meta_wayland_transaction_apply (transaction=0xf56170, first_candidate=0x7fffffffcee8)
  5) meta_wayland_transaction_maybe_apply_one (transaction=0xf56170, first_candidate=0x7fffffffcee8)
  6) meta_wayland_transaction_maybe_apply (transaction=0xf56170)
  7) meta_wayland_transaction_dma_buf_dispatch (buffer=0xf448a0, user_data=0xf56200)
  8) meta_wayland_dma_buf_source_dispatch (base=0xf5f140, callback=0x0, user_data=0x0)
  9) g_main_dispatch (context=0x41baa0)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2940>
2023-04-13 21:02:08 +02:00
Jonas Ådahl
50a37a7fc0 wayland/xdg-shell: Dismiss instead of destroy invalid popup
Destroying is insufficient as it doesn't end any popup pointer grab, if
the dismissed popup was the last. This would later hit an assert as the
popup grab is assumed to always have at least one popup in its chain.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2728
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2940>
2023-04-13 21:02:03 +02:00
Jonas Ådahl
697b99ee13 wayland/xdg-shell: Ignore reposition if popup was dismissed
If the popup was dismissed (i.e. has no MetaWindow anymore), it'll also
have no parent surface. With no parent surface, we'd try to fetch a
transaction from NULL and crash, but if we don't try if we were
dismissed, we won't reach here anyway.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2940>
2023-04-13 21:02:03 +02:00
Daniel van Vugt
46e1ede687 wayland/buffer: Avoid spamming the log when a buffer is not scanoutable
It's not really an error and we recover seamlessly.

If someone really wants to check if/why direct scanout is failing then
they can still use `env MUTTER_DEBUG=render,kms`.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2702
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2918>
2023-03-20 07:22:03 +00:00
Robert Mader
c64a04678a wayland/surface: Export get_buffer_[width|height] to tests
It will be used in fractional scale tests.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2394>
2023-03-04 22:13:45 +01:00
Robert Mader
305931e2dd wayland: Implement fractional_scale_v1 protocol
Giving clients hints about optimal fractional scaling ratios,
to be used together with the `wp_viewport` protocol.

See
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/1.31/staging/fractional-scale/fractional-scale-v1.xml

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2394>
2023-03-04 22:13:45 +01:00
Robert Mader
ef2e9dade8 wayland/surface: Fix can_scanout_untransformed() for transform+viewport
The buffer needs to match the untransformed layout size.

While on it simplify the check from floats to ints where possible - and
improve logging a bit.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2394>
2023-03-04 22:13:45 +01:00
Michel Dänzer
3d28e03a29 wayland: Take surface reference for presentation-time feedback
Without this, the feedback->surface pointer could outlive the surface
it pointed to, which could result in use-after-free.

One consequence of this is that if a MetaWaylandPresentationFeedback
object ever lingers on longer than expected, it would keep the
MetaWaylandSurface alive as well.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2585
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2886>
2023-03-03 21:14:07 +00:00
Robert Mader
b521747d81 Remove support for window shading
It's been broken for an unknown time and was never supported on Wayland.
Thus let's remove the leftovers.

Helpful command: `rg 'shade(?!r)' --pcre2`

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2884>
2023-03-03 19:17:51 +00:00
Jonas Ådahl
02b1cfe08f onscreen/native: Handle unexpected scanout failures async
We test direct client buffer scanout using a TEST_ONLY commit on atomic,
and with various conditions in non-atomic, but if we end up failing to
actually commit despite this, handle the fallout asynchronously. What
this means is that we'll reschedule a new frame immediately.

For this to work, the same scanout buffer needs to be avoided for the
same CRTC. This is done by using the newly added signal on the
CoglScanout object to let the MetaWaylandBuffer object mark the current
buffer as non-working for the onsrceen that it failed on. This allows to
re-try buffers on the same onscreen when new ones are attached.

This queues a full damage, since we consumed the qeued redraw rect. The
redraw rect wasn't lost - it was accumulated to make sure the whole
primary plane was redrawed according to the damage region, whenever we
would end up no longer doing direct scanout, but this accumulation only
works when we're not intentionally stopping to scanout. For now, lets
just damage the whole view, it's just an graceful fallback in response
to an unexpected error anyway.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2854>
2023-03-01 23:57:32 +00:00
Jonas Dreßler
0dd170264d window-wayland: Remove unused API
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2873>
2023-03-01 09:48:14 +00:00
Robert Mader
fe17dbc322 wayland/actor-surface: Always schedule stage updates on frame callbacks
There is an increasing number of cases where we want the frame callback
logic to run for a stage-view and the complexity needed to avoid these,
combined with the likelyhood of bugs, arguably does not justify the
benefit any more.

Thus unconditionally schedule updates for all stage-views when frame
callbacks are requested.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2789>
2023-02-28 12:01:17 +01:00
Robert Mader
6b84f5bd00 wayland/pointer: Check for surface resource
Like we do in several other places since
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880

Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/2645

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2869>
2023-02-25 19:18:43 +01:00
msizanoen1
36ae716e4d window/xwayland: Relayout when fullscreen client update emulated RandR mode
This fixes an issue when GLFW tries to change the display resolution
while fullscreen where the application window size doesn't get updated
according to the emulated resolution.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2725>
2023-02-20 16:55:36 +00:00
Matthias Clasen
ea373cb059 wayland: Don't overwrite surface offsets
The intention when the offset request was added to protocol was
that the attach request in a new enough protocol version should
require dx/dy to be zero, but ignore them otherwise.

The current code checks for 0, but then overwrites the existing
dx/dy with it, which renders an earlier wl_surface_offset() call
ineffective.

Fixes: #2622
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2843>
2023-02-14 10:29:00 -05:00
Jonas Ådahl
32dc870f37 wayland: Add X11 interop service client protocol
This protocol is intended to let special clients create transient-for
relationships between X11 and Wayland windows. The client that needs
this is xdg-desktop-portal-gnome, which will create e.g. file chooser
Wayland dialogs that should be mapped on top of X11 windows.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
5d001a38b5 wayland: Don't set X11 envvars when we don't support X11
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
1b75a62030 wayland/surface: Add getter for MetaWaylandCompositor
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
74fcdb9a62 Introduce the 'service channel' D-Bus service
The service channel D-Bus interface aims to be a "back door" for
services that needs special casing in Mutter, e.g. have custom private
protocols only meant to be used by that particular service.

There are currently no special casing implemented; only the basic
service channel infrastructure is added. There is a single method on the
interface, that is meant to eventually be used by
xdg-desktop-portal-gnome to open a Wayland connection with a private
protocol needed for the portal backend's rather special window
management needs.

The service channel Wayland client works by allowing one instance of
each "type", where each time needs to be defined to work in parallel. If
a new service client connects, the old one will be disconnected.

MetaWaylandClient's are used to manage the service clients, and are
assigned the service client type.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
a2f93e76a3 wayland/surface: Add getter for the surface wl_resource
Meant to avoid dereferencing the MetaWaylandSurface struct directly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
91c40a47b3 wayland: Add wl_global filter manager
One can add a wl_global filter to a wl_display instance, which can be
used to decide what clients should see what globals. This has so far
been used to limit a Xwayland specific protocol extension to only
Xwayland. In order to expand the logic about what globals are filtered
to what clients, introduce a filter manager and port the Xwayland
specific protocol filter to this new manager.

Tests are added, using a new dummy protocol, to ensure that filtering is
working as expected.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
192401dee5 wayland/compositor: Add API to get wl_display
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
63c8c229d6 wayland/client: Add API to check if it matches a wl_client
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
61a3188d44 wayland/client: Add way to create indirectly launched clients
This API creates a "client" then later sets up a wl_client and returns a
file descriptor some Wayland client can connect to. It's meant to be
used as a method other than WAYLAND_SOCKET and process launching, e.g.
passing a file descriptor via a D-Bus API.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
f129929c3f wayland/client: Put subprocess specific fields in anon struct
There will be two kind of client instances, lets move fields that are
only relevant to the current way of operation in an anonymous struct to
keep things a bit separate.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
3042f56450 wayland/client: Put wl_client creator in helper
Will be used to create clients in other way than a subprocess launcher
and WAYLAND_SOCKET environment variable.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Jonas Ådahl
ff56305e6f wayland/client: Keep track of wl_client aliveness
Clear the wl_client pointer if the client is destroyed, and emit new
signal if it happened.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2810>
2023-02-13 15:34:24 +00:00
Carlos Garnacho
014cde6461 wayland: Do not use GDK functions on XDnD implementation
We used it to retrieve a Display, and convert between Atoms and
strings. We can just use the MetaX11Display's Display (It's the
same than GDK's anyways) and use XInternAtom/XGetAtomName for
these conversions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2836>
2023-02-10 20:43:11 +00:00
Jonas Ådahl
84b6913f8a wayland/xdg-foreign: Fix race condition crash
We didn't always set an implementation, when the foreign toplevel wasn't
found, and when the importer tried to set the parent-child relationship,
the implementation was missing and we'd crash in wl_closure_invoke() in
libwayland-server.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2834>
2023-02-10 18:38:39 +00:00
Carlos Garnacho
228d681be8 wayland: Trigger full focus sync after keyboard focus surface is destroyed
This used to be implicitly done by popups using a META_GRAB_OP_WAYLAND_POPUP
MetaDisplay grab. Since commit a8cd488c6f Wayland popups no longer do that,
so the keyboard focus was simply unset if a popup was destroyed while having
the keyboard focus.

Trigger a full input focus sync, so the correct MetaWaylandKeyboard focus
surface is looked up from the focused MetaWindow.

Fixes: a8cd488c6f - wayland: Drop redundant MetaDisplay grab op
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2833>
2023-02-09 16:23:36 +01:00
Carlos Garnacho
c4d8ba0f72 wayland: Avoid entering MetaWindow on other than user pointer motions
On one hand, this used to be handled generically in all the paths that
changed the MetaWaylandPointer focus surface, induced by user interaction
or not.

On the other hand, just listening for crossing events is not sufficient
since those also do happen programmatically. We must only listen to
crossing events that have a physical source device, meaning this was
created through user interaction.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/888
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2828>
2023-02-09 14:41:04 +01:00
Keyu Tao
c1ab3f39d7 wayland/outputs: Fix potential crash when output has no monitor
bind_output() creates output interface resource, but does not
set implementation for it when wayland_output->monitor is NULL.
However, when the wayland library is running wl_closure_invoke(),
it expects the implementation to be non-NULL, and if not, it just
segfaults mutter by NULL pointer dereference.

This commit tries to address this issue by setting an implementation
when wayland_output->monitor is NULL. This could help prevent crash
when resuming from suspend or hotplugging displays.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2570
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2827>
2023-02-06 21:37:04 +08:00
Robert Mader
120e21db7c wayland/surface: Reenable WL_SURFACE_ERROR_INVALID_SIZE check
This partly reverts f9857cb8 but leaves an exception for cursor
surfaces in place, as some apps/toolkits will likely not get updated
anytime soon to ensure cursor themes comply with the Wayland spec.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2815>
2023-02-01 17:42:04 +00:00
Carlos Garnacho
35e7feac8c wayland: Check that the current backend is native before using DMA-BUF FDs
We may fall through these paths on --nested too, resulting in us poking the
wrong internals from the wrong MetaRenderer subclass. Fixes launching of
clients using wl_drm in --nested.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2818>
2023-01-31 11:08:26 +00:00
Jonas Ådahl
49b0a8921c Use g_clear_fd() instead of open coding the same behavior
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2806>
2023-01-30 15:11:26 +00:00
Carlos Garnacho
d687e5634d core: Pass device/sequence on meta_window_begin_grab_op()
This is a public API change. Add device/sequence parameters to this
operation, so that window dragging and resizing can stick to one
set of pointing events of them all.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
18535928e7 wayland: Add device/sequence out parameters getting wayland grab info
This information will become necessary for window move/resize ops.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
bec8a5860a core,wayland,compositor,x11: Migrate to MetaWindowDrag
Flip the switch in using MetaWindowDrag, leaving display grab
ops and a bunch other code unused. Some places checked the grab op
and/or window in complex ways, others just checked for grab existence
and should now look for clutter ones, and others already were already
doing this in addition.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
6bd4468b25 wayland: Move away from MetaEventRoute
Use the current grab op for the same effect.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
12773cf8e2 window: Drop frame_action argument from meta_window_begin_grab_op()
The final effect of this boolean can now be expressed through the
META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED flag to MetaGrabOp. Use that
in the relevant places, and drop the argument.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
78a5921066 wayland: Port to meta_window_begin_grab_op()
Move away from meta_display_begin_grab_op(), and start window
grab operations through the MetaWindow API.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
589ec26b04 core: Drop META_EVENT_ROUTE_WAYLAND_POPUP
This is now unused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
a8cd488c6f wayland: Drop redundant MetaDisplay grab op
This is no longer necessary to prevent the bits we wanted to be
prevented by the presence of this grab. We can drop this, and
let it work through the MetaWaylandPointerGrab interface.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
aed3979064 wayland: Add meta_wayland_compositor_is_grabbed() method
This will return TRUE if there is an existing pointer or keyboard
grab from the wayland compositor.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
a5bd0c39fe core: Drop META_EVENT_ROUTE_FRAME_BUTTON
With META_GRAB_OP_FRAME_BUTTON gone, this is no longer used. Drop
this event route.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Jonas Ådahl
8abdbbdf24 wayland/transaction: Don't free queue node on tear down
The GQueue node for transactions are inlined in the transaction struct,
meaning we should never let the GQueue API free the node itself, as that
actuall frees the transaction itself.

We did this during tear down if there were left-over transactions,
meaning we ended up with use-after-free issues after having popped
transactions from the queue.

Fix this by just popping the link itself, which won't attempt to free
it. It is effectively freed when freeing the transaction itself so we
won't leak any memory.

Fixes: 56260e3e07
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2805>
2023-01-25 13:53:11 +00:00
Jonas Ådahl
08b0e563d4 clutter: Pass 'ClutterFrame' in all stage update signals
That means before-update, prepare-paint, before-paint, paint-view, after-paint,
after-update. While yet to be used, it will be used as a transient frame
book keeping object, to maintain object and state that is only valid
during a frame dispatch.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2795>
2023-01-23 15:57:50 +01:00
Olivier Fourdan
8ee85cb228 xwayland: Add support for byte-swapped clients
Instructs Xwayland to allow/disallow connections from X11 clients with a
different endianess based on the "xwayland-allow-byte-swapped-clients"
setting.

This option has no effect if Xwayland does not support the command
option +byteswappedclients/-byteswappedclients.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2576
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2785>
2023-01-17 11:14:19 +01:00
Carlos Garnacho
95c2154039 wayland: Drop HAVE_XSETIOERROREXITHANDLER checks
This define was dropped by commit 0e8aaebc00 (xwayland: Make
XSetIOErrorExitHandler() mandatory), but some #ifdef checks were
brought back by commit 36f30341ac (wayland: Add a prepare-shutdown
signal).

Since there's no define anymore in config.h, these pieces of code
were unintentionally disabled, and a meta_get_display() call be
also left over. Remove the ifdefs and update the code to build
again.

Fixes: 36f30341ac - wayland: Add a prepare-shutdown signal
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2786>
2023-01-12 14:54:31 +00:00
Carlos Garnacho
1cee0579fa wayland: Push an error trap while querying XDND mimetype list
It is a possibility that this request results in an error, so handle the
possible fallout.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
2023-01-12 14:00:52 +01:00
Bilal Elmoussaoui
4bbad6063a wayland: Move Xwayland specific call to xwayland
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2399>
2023-01-03 20:45:04 +00:00
Bilal Elmoussaoui
36f30341ac wayland: Add a prepare-shutdown signal
This allows moving the xwayland shutdown logic to the xwayland
implementation

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2399>
2023-01-03 20:45:04 +00:00
Bilal Elmoussaoui
6e818c8c38 build: Allow disabling xwayland
Mostly moving things around to allow a build without xwayland.
Note that more work might still be needed once the x11 build option
lands as that would allow us to have a proper xwayland only build
without the x server part.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2272
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2399>
2023-01-03 20:45:04 +00:00
Bilal Elmoussaoui
abef37f5ee core: Add a copy of GDK_PRIORITY_EVENTS
Quoting Carlos:
The META_PRIORITY_EVENTS ± 1 happening below are in order to set these idles
and timeouts in a priority that is relative to the literal GDK event priority,
making those diverge is a likely way to sneakily break things.
But that's unlikely to happen, and decoupling mutter from GTK further
should make it moot, so perhaps it's alright after all.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
64ee8d02f7 core: Add a in-tree copy of GtkBorder
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Jonas Ådahl
6adc2e4b59 pointer-lock/wayland: Fix coding style
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 13:17:49 +01:00
Jonas Ådahl
4edcdd8a7f pointer-lock/wayland: Remove unused instance struct field
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 10:00:34 +01:00
Jonas Ådahl
2762a67000 pointer-lock/wayland: Get compositor from surface
This avoids trying to get it from an pointer that was never set to
anything.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2558
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 10:00:14 +01:00
Jonas Ådahl
439856e7aa wayland/gtk-shell: Dereference surface after NULL check
Spotted by coverity.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 09:47:29 +01:00
Jason Francis
aa0b1fbc88 wayland/xdg-foreign: Add support for xdg-foreign-v2
This replaces the v1 implementation, which is now renamed to
legacy-xdg-foreign. Both implementations use the same data structures
internally, so that protocol version mismatches between
the importer client and exporter client don't fail.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
2022-12-17 20:38:23 +00:00
Jonas Ådahl
4b3cab2cca compositor: Don't make internal API public
Things like meta_compositor_destroy() and meta_compositor_add_window()
isn't intended to be used externally, and if they was, things would
probably fall apart rather quickly.

MetaCompositor also isn't introspected, meaning things that technically
belong to the compositing parts isn't easily available via some object,
but much take detours via other objects like MetaDisplay.

So move the API intended for internal usage to compositor-private.h, and
leave API that is meant to be expose in the public compositor.h.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
82abee5ad7 wayland: Remove meta_wayland_compositor_get_default()
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
5e67e35ec5 compositor: Setup and use ownership chains
As with the backend commit, this means all objects can reach the
MetaContext by walking up the chain, thus can e.g. get the backend from
the context, instead of the global singleton.

This also is a squashed commit containing:

compositor: Get backend via the context

The MetaCompositor instance is owned by MetaDisplay, which is owned by
MetaContext. Get the backend via that chain of ownership.

dnd: Don't get backend from singleton

window-actor: Don't get backend from singleton

dnd: Don't get Wayland compositor via singleton

background: Don't get the monitor manager from the singleton

plugins: Don't get backend from singleton

This applies to MetaPlugin, it's manager class, and the default plugin.

feedback-actor: Pass a compositor pointer when constructing

This allows getting to the display.

later: Keep a pointer to the manager object

This allows using the non-singleton API in idle callbacks.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
2731f0cda4 wayland: Setup and use ownership chains
As elsewhere, make sure objects that need to have a ownership up to the
context, and use this ownership chain to find relevant components, such
as the backend or the Wayland compositor object instance.

wayland/data-device: Hook up data devices to seats

They are tied to a seat - make that connection in struct fields too, so
that related objects can get to the context via it.

wayland: Don't get Wayland compositor via singleton getter

This means via the ownership chain or equivalent.

xwayland: Hook up manager to Wayland compositor

Same applies to the drag-n-drop struct.

xwayland: Make X11 event handling compositor instance aware

This avoids finding it via singletons in the callee.

xwayland: Don't get Wayland compositor from singleton

xwayland: Pass manager when handling dnd event

window/xwayland: Don't get Wayland compositor from singleton

xwayland/grab-keyboard: Don't get backend from singleton

xwayland: Don't get backend from singleton

wayland: Always get the backend from the context

This means traveling up the ownership chain or equivalent when
necessary.

wayland: Hook up data devices, offers and sources to the compositor

This allows tying them to a context without going through any
singletons.

wayland: Don't get display from singleton

xwayland: Don't get display from singleton

tablet: Don't get display from singleton

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
dd2beae6a8 core: Setup and use ownership chains
As with other parts, make objects have the ability to walk up the
ownership chain to the context, to get things like the Wayland
compositor or backend instances.

Contains these squashed commits:

display: Don't get backend from singleton

window: Don't get backend from singleton

keybindings: Don't get backend from singleton

workspace: Don't get backend from singleton

display: Don't get Wayland compositor from singleton

selection: Add display getter

context/main: Get backend directly from the context

clipboard-manager: Don't get display from singleton

stack-tracker: Don't use singleton MetaLater API

startup-notification: Hook up sequences and activations to display

This allows using context aware API directly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
0e8aaebc00 xwayland: Make XSetIOErrorExitHandler() mandatory
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
7e974ba6cc backend: Get 'is-stage-views-scaled' from backend
It did, but used the old backend singleton.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Sebastian Wick
a2ed0f97c3 wayland/outputs: Make wl_output mode independent of the orientation
wl_output describes the physical attributes and the mode of an output is
such a physical attribute. Swapping the width and height creates
another, incorrect mode.

Other compositors also report the physical mode and don't try to
transform it based on the orientation of buffers.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2519
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2723>
2022-12-17 10:09:37 +00:00
Robert Mader
35ecaafd6b wayland/actor-surface: Optimize update scheduling
This code path is important for "empty" commits to ensure we schedule
frame callbacks even if previous commits didn't cause stage redraws.
There is, however, no reason to schedule updates on all stage views
instead of only those the actor is on.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2671>
2022-12-16 16:27:33 +00:00
Robert Mader
292a8500ed surface-actor-wayland: Clean up and optimize check for primary view
Avoid some allocations, save some CPU cycles and make the code easier
to read.

Behaviourwise the only expected change is that now, if there are mapped
clones, we unconditionally choose the view with the highest refresh
rate the actor (or one of its clones) is on and don't check the
obscurred region any more.

Thus in some cases a client may receive a higher rate of frame callbacks
when obscured on a faster view while a clone is present on a slower
one. The assumption is that cases like this are relatively rare and
that the reduction of code complexity, the reduction of allocations in
`meta_surface_actor_is_obscured_on_stage_view()` whenever the actor is
not fully obscured and has clones on other views, as well as generally
fewer lookups and less code in most common cases, compensate for that.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2671>
2022-12-16 16:27:33 +00:00
Robert Mader
08a4caff6f wayland/pointer-constraints: Adjustments for subsurface support
After the commit "wayland/subsurface: Implement
meta_wayland_surface_get_window()" subsurfaces are supported. Adjust
some comments and fix a warning that could occur when closing a window.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2717>
2022-12-09 20:48:55 +00:00
Robert Mader
225f7d46a3 wayland/subsurface: Check ancestor instead of toplevel window for actor sync
The intention here was to check if the subsurface belongs to a window.
Thus it didn't behave as expected for subsurfaces belonging to non-toplevel
windows.

After the previous commit we can use `get_window()` to check for what we
actually want here.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2717>
2022-12-09 20:48:55 +00:00
Robert Mader
8af356c2c7 wayland/subsurface: Implement meta_wayland_surface_get_window()
Subsurfaces are special regarding windows as they don't have a window,
but usually have an ancestor which does. All current users of
`get_window()` are either used for known surface roles, such as xdg-*
ones, or, as is the case for pointer constrains, would actually want to
get the ancestors window.

Thus implement `get_window()` to allow pointer constrains to work.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2223
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2717>
2022-12-09 20:48:55 +00:00
Robert Mader
e0b2966dd0 wayland/dma-buf: Add 'render' debug prints
And change existing ones where it makes sense.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
28a3da8d28 wayland/buffer: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
4a2a467b68 wayland/surface: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Michel Dänzer
05efcb4b21 wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.

The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.

Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.

v2:
* Handle NULL priv->buffer_ref in
  meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
  to MetaWaylandBuffer itself. Much simpler, and doesn't run into
  lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
  committed buffers. If the client attaches a buffer and then destroys
  it before commit, we ignore the buffer attachement, same as before
  this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
  ::newly_attached is TRUE, simplify accordingly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 17:23:34 +01:00
Michel Dänzer
6e6a38342e wayland/surface: Defer meta_wayland_transaction_apply for dma-bufs
Until all dma-buf file descriptors for all buffers in the transaction
are readable, which corresponds to when the client drawing to the
buffers has finished.

This fixes https://gitlab.gnome.org/GNOME/mutter/-/issues/1162 if the
GPU & drivers support high priority contexts which can preempt lower
priority contexts.

v2:
* Also remove dma-buf fds from transaction and try applying it from
  pending_buffer_resource_destroyed. Avoids freeze due to leaving a
  GSource based on a closed fd attached if a client destroys a wl_buffer
  which is part of a transaction which was committed but not applied
  yet. (Robert Mader)
* Tweak transaction cleanup logic in wl_surface_destructor.
v3:
* Adapt to meta_wayland_dma_buf_get_source.
v4:
* Adapt to new commits using transactions for (sub-)surface destruction,
  drop code to remove destroyed surfaces from pending transactions.
v5:
* Use g_clear_pointer in meta_wayland_transaction_destroy.
  (Georges Basile Stavracas Neto)
* Add spaces between type casts and values. (Carlos Garnacho)
* Use (gpointer *) instead of (void**). (Carlos Garnacho)
* Use gpointer instead of void * in
  meta_wayland_transaction_dma_buf_dispatch.
v6:
* Use g_hash_table_remove in meta_wayland_transaction_dma_buf_dispatch.
  (Carlos Garnacho)
v7: (Jonas Ådahl)
* Move include of glib-unix.h below that of meta-wayland-transaction.h.
* Split up g_hash_table_iter_next call to multiple lines in
  meta_wayland_transaction_commit.
* Call g_source_destroy as well as g_source_unref when freeing a
  committed but not yet applied transaction (during mutter shutdown).
v8:
* Drop dma_buf_source_destroy, can use g_source_destroy directly.
  (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 16:35:19 +01:00
Michel Dänzer
b7599fb766 wayland/xdg-shell: Defer meta_wayland_xdg_positioner_to_placement call
From xdg_surface_constructor_get_popup / xdg_popup_reposition (called
during Wayland protocol processing) to finish_popup_setup /
meta_wayland_xdg_popup_apply_state (called when the popup state is
applied).

This makes sure that the parent window frame rectangle is up to date in
meta_wayland_xdg_positioner_to_placement.

v2:
* Use meta_wayland_surface_state_new () in
  meta_wayland_transaction_add_xdg_popup_reposition.
v3:
* Move xdg_popup_repositioned handling to
  meta_wayland_xdg_popup_apply_state.
v4:
* Do not steal pending->xdg_positioner in
  meta_wayland_xdg_popup_apply_state, fixes leaking the corresponding
  memory.
* Drop MetaWaylandSurfaceState::xdg_popup_repositioned, just use
  ::xdg_positioner.
v5:
* Reformat meta_wayland_xdg_positioner_to_placement calls to stay within
  80 columns. (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
6c3879766d wayland/xdg-shell: Add parent surface entry to popup setup transaction
This makes sure that finish_popup_setup is called after any previous
transactions for the parent surface have been applied, so the parent
window geometry is up to date.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
26346a06ee wayland/surface: Make meta_wayland_transaction_ensure_entry non-static
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
9ed6a3dffb wayland/surface: Add role commit_state callback
Which gets called when pending state is committed for the surface.

This callback may amend the pending transaction or surface state as
needed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
79dc41499d wayland/surface: Call meta_wayland_buffer_attach from surface commit
Preparation for potentially calling meta_wayland_transaction_apply some
time after surface commit, in which case doing it in the former would be
too late: The client may legally destroy the attached wl_buffer
immediately after commit, in which case meta_wayland_buffer_attach would
spuriously fail and disconnect the client (or possibly even crash mutter
due to NULL error).

Requires splitting up the surface texture between protocol and output
state, and propagating from the former to the latter via
MetaWaylandSurfaceState.

v2: (Jonas Ådahl)
* Move meta_wayland_surface_get_texture call to separate line.
* Use g_autoptr for GError.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
80c6b7d82b wayland/surface: Use transactions for all sub-surface hierarchy changes
And keep track of the hierarchy separately for the Wayland protocol and
for output. Protocol state is updated immediately as protocol requests
are processed, output state only when the corresponding transaction is
applied (which may be deferred until the next commit of the parent
surface).

v2:
* Directly add placement ops to a transaction, instead of going via
  pending_state.
* Use transaction entry for the sub-surface instead of that for its
  parent surface.
v3:
* Use transaction entry for the parent surface again, to ensure proper
  ordering of placement ops, and call
  meta_wayland_surface_notify_subsurface_state_changed only once per
  parent surface.
* Drop all use of wl_resource_add_destroy_listener, transactions are
  keeping surfaces alive as long as needed.
v4:
* Rebase on https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2501
* Drop ClutterActor code from meta_wayland_surface_apply_placement_ops.
  (Robert Mader)
v5:
* Rename MetaWaylandSubSurfaceState to MetaWaylandSurfaceSubState, since
  the next commit adds not sub-surface specific state to it.
v6:
* Move include of meta-wayland-subsurface.h from
  meta-wayland-transaction.c to .h, since the latter references
  MetaWaylandSubsurfacePlacementOp.
v7:
* Drop superfluous !entry check from meta_wayland_transaction_apply.
v8:
* Rename output/protocol fields to output/protocol_state. (Jonas Ådahl)
v9:
* Use meta_wayland_surface_state_new in
  meta_wayland_transaction_add_placement_op.
v10:
* Fix a few style issues per check-style.py.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
4eef08c5c3 wayland/surface: Two phase surface destruction
Destroy Wayland protocol related state immediately when the Wayland
resource is destroyed, but keep the rest alive by any transaction which
references the surface.

This makes it easier and cleaner to deal with a surface getting
destroyed while it's still referenced by transactions.

v2:
* No more need to keep references for surfaces in the entries hash
  table.
v3:
* Do not use surface->sub.transaction in wl_surface_destructor, just
  destroy it.
v4:
* No need for wl_surface_destructor to use its own transaction.
v5:
* Use g_steal_pointer & (more) g_clear_pointer in wl_surface_destructor.
v6:
* Leave SURFACE_DESTROY signal emission in wl_surface_destructor.
v7:
* Use finalize instead of dispose callback.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
ff707a6de6 wayland/surface: Store pointers to next transaction with same surface
This saves traversing all committed transactions to find the next one
which references the same surface.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
e26df6ac14 wayland/surface: Keep transaction entries for all referenced surfaces
This keeps all surfaces referenced by a transaction alive until the
transaction is destroyed, and makes sure transactions are applied in
the same order as they were committed with respect to all surfaces
they reference.

v2:
* Guard against NULL entry in meta_wayland_transaction_apply.
v3:
* Keep single entries hash table.
v4:
* Unref the surface in the meta_wayland_transaction_merge_into while
  loop only if the "to" transaction didn't already have an entry for it,
  to prevent premature finalization of the surface (likely followed by a
  crash).
v5:
* Unref the surface (implicitly via g_hash_table_iter_remove) in the
  meta_wayland_transaction_merge_into while loop even if the "to"
  transaction already had an entry for it, or we leak a reference.
* Use g_clear_object & g_steal_pointer to not leave behind a dangling
  from->state pointer in meta_wayland_transaction_entry_merge_into.
v6:
* Add curly braces around
  meta_wayland_transaction_add_placement_surfaces calls. (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
5fa4ce6fa8 wayland/surface: Use transactions for synchronized sub-surface state
Instead of cached_state.

surface_commit for a synchronized sub-surface either commits the
transaction or merges it into the parent surface's transaction (if
the parent is a synchronized sub-surface itself).

This should fix or at least improve the behaviour of nested synchronized
sub-surfaces.

Also change wl_subsurface_set_desync:

* Commit sub-surface transactions separately. This may allow some of
  them to be applied earlier in some cases.
* Commit transaction only for descendant sub-surfaces which become
  newly de-synchronized themselves.

v2:
* Drop unused function prototypes
v3:
* Use g_clear_pointer for surface->sub.transaction.
v4:
* Use g_steal_pointer instead of g_clear_pointer. (Sebastian Wick, Jonas
  Ådahl)
v5: (Carlos Garnacho)
* Add spaces between type casts and values.
* Use (gpointer *) instead of (void**).
v6: (Jonas Ådahl)
* Use g_clear_object in meta_wayland_transaction_entry_merge_into.
* Use meta_wayland_transaction_entry_free in
  meta_wayland_transaction_merge_into.
* Fix alignment of meta_wayland_transaction_merge_pending_state
  parameters.
* Remove unused meta_wayland_transaction_add_state declaration.
v7:
* Use meta_wayland_surface_state_new in
  meta_wayland_transaction_merge_pending_state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
0bae4ece19 wayland/surface: Use transactions for applying committed states
A transaction contains the committed state for a surface, plus any
cached state for synchronized subsurfaces.

v2:
* Handle sub-surface positions separately from surface states.
v3:
* Sync child states only for surfaces with state in the transaction.
v4: (Jonas Ådahl)
* Drop unnecessary g_object_new call from wl_subsurface_set_desync. (me)
* Fix indentation & formatting in meta_wayland_surface_commit.
* Add meta_wayland_surface_state_new helper function.
* Fix alignment of meta_wayland_transaction_apply_subsurface_position
  parameters.
* Add curly braces around meta_wayland_transaction_sync_child_states
  call in meta_wayland_transaction_apply.
v5:
* Make meta_wayland_surface_state_new an inline function.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
56260e3e07 wayland/surface: Make sure transactions are applied in consistent order
If multiple transactions have entries for the same surface, they are
applied in the same order as they were committed. Otherwise, they can
be applied in any order.

This is preparation for following changes, transactions are still
applied as soon as they're committed.

v2:
* Move GQueue for transactions to MetaWaylandCompositor (Jonas Ådahl)
v3
* Say "entry for" instead of "state for", since there can be transaction
  entries with no state (for surfaces which are getting destroyed).
v4:
* Use a hash table to keep track of all candidate transactions which
  might be newly ready to be applied.
* Use clearer function / variable names.
v5:
* Use custom single-linked list instead of hash table for candidate
  transactions, ordered by the transaction commit sequence number, so
  that they're attempted to be applied in the same order as they were
  committed.
* Rename transaction->queue to transaction->committed_queue, and
  simplify its handling.
v6: (Carlos Garnacho)
* Add spaces between type casts and values.
* Use (gpointer *) instead of (void**).
v7: (Jonas Ådahl)
* Use G_MAXSIZE instead of ULONG_MAX.
* Fix indentation of meta_wayland_transaction_apply &
  meta_wayland_transaction_maybe_apply_one parameters.
* Refactor find_next_transaction_for_surface & ensure_next_candidate
  helper functions out of meta_wayland_transaction_apply.
* Refactor has_unapplied_dependencies helper function out of
  meta_wayland_transaction_maybe_apply_one.
* Make while (TRUE) loop in meta_wayland_transaction_maybe_apply
  consistent with general usage.
* Drop unused value local from meta_wayland_transaction_commit.
* Store pointer to compositor object in transactions, instead of
  pointer to the queue of committed transactions.
* Drop tautological g_assert from meta_wayland_transaction_apply. (me)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
207847e8cf wayland: Add transaction skeleton
v2:
* Use single hash table with struct which will contain all kinds of
  state handled by a transaction.
v3:
* Add meta_wayland_transaction_destroy.
v4 (Georges Basile Stavracas Neto)
* Fix struct _MetaWaylandTransaction(Entry) formatting.
* Explicitly test against NULL.
* Use gpointer insteadof void * for
  meta_wayland_transaction_entry_destroy.
v5: (Robert Mader)
* Use for loop in is_ancestor.
* Include meta-wayland-transaction.h first in
  meta-wayland-transaction.c.
v6:
* Use g_autofree & g_clear_object.
v7: (Jonas Ådahl)
* Rename meta_wayland_transaction_entry_destroy to
  meta_wayland_transaction_entry_free.
* Drop g_autofree use from meta_wayland_transaction_entry_free again.
* Make meta_wayland_transaction_entry_free take a
  MetaWaylandTransactionEntry pointer.
* Rename meta_wayland_transaction_destroy to
  meta_wayland_transaction_free.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
6379e54847 wayland/surface: Prepare for decoupled surface & resource lifetimes
Need to deal with surface->resource == NULL and
surface->pending_state == NULL in some places.

v2:
* Avoid expanding conditions to multiple lines.
  (Georges Basile Stavracas Neto)
v3:
* Use a single bailout condition in meta_wayland_client_owns_window as
  well.
v4:
* Remove spare empty line in meta_wayland_surface_apply_state.
  (Robert Mader)
* Add wl_resource_post_error calls in xdg-shell request handlers.
  (Robert Mader)
* Drop checks in functions which can only be called if there's a valid
  resource.
* Drop more checks which are unnecessary due to leaving the
  SURFACE_DESTROY signal emission in wl_surface_destructor later.
v5:
* Move resource = surface->resource assignments to if (!resource) tests.
  (Jonas Ådahl)
v6:
* Fix style issue per check-style.py.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
a99198de83 wayland/surface: Rename "should_cache_state" to "is_synchronized"
Also remove the stale meta_wayland_surface_is_effectively_synchronized
prototype.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
e7d589d45b wayland/surface: Move out meta_wayland_surface_state_reset calls
From meta_wayland_surface_apply_state / _state_merge_into to their
callers.

Preparation for changing behaviour in the callers, no functional
change intended.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
854c02651f wayland/surface: Discard presentation feedback in _state_merge_into
Newly merged state is always from a different surface commit than the
existing state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 12:41:32 +01:00
Michel Dänzer
d43150573e wayland/dma-buf: Add meta_wayland_dma_buf_create_source
Creates a GSource which will call the specified dispatch callback when
all dma-buf file descriptors for the buffer have become readable.

v2:
* Hold a reference to the buffer in the source, to prevent the buffer
  from getting destroyed before the source.
v3:
* Do not use check callback, handle everything in dispatch callback.
  (Dor Askayo)
v4: (Georges Basile Stavracas Neto)
* Define and use MetaWaylandDmaBufSource & MetaWaylandDmaBufSourceDispatch
  types.
* Fix meta_wayland_dma_buf_source_dispatch &
  meta_wayland_dma_buf_source_funcs formatting.
* Use gpointer instead of void*.
* Rename meta_wayland_dma_buf_get_source to
  meta_wayland_dma_buf_create_source. (Carlos Garnacho)
v5:
* Explicitly handle NULL return value. (Jonas Ådahl)
v6:
* Fix style issue per check-style.py.
v7:
* Fix code style harder. (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 09:40:38 +01:00
Michel Dänzer
416285d1b7 wayland/dma-buf: Add meta_wayland_dma_buf_fds_for_wayland_buffer
And call it from meta_wayland_buffer_realize. This makes dma-buf fds
available for EGL image type buffers as well.

v2:
* Move buffer->dma_buf.dma_buf assignment value to next line.
  (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-12-01 09:40:38 +01:00
Sebastian Keller
f0fd013262 window/wayland: Calculate bottom and right frame extents
The bottom and right frame extents were never calculated and thus always
remained 0. This did not lead to any obvious problems until 6cbc5180
which started relying on those to calculate the buffer rect. This
resulted for example in window screenshots being cut off at the bottom
right corner of the window rather than the buffer.

Fixes: 6cbc5180
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6050
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2720>
2022-11-26 15:04:00 +01:00
msizanoen1
992e169d84 wayland/pointer-gestures: Fix crash in get_*_gesture after pointer is destroyed
Properly handle cases where the pointer object has already been
destroyed to prevent the compositor from crashing with a null pointer
dereference when a client invokes a get_*_gesture method after the
pointer object is destroyed e.g. when the current login session is not on
foreground.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2237
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2690>
2022-11-25 15:40:12 +00:00
Bilal Elmoussaoui
7bf07d2980 core/window: Implement GInitable
Currently, we will notify the display about a new window being created
during the constructed phase of the GObject. During this time,
property-change notifications are frozen by GObject, so we'll emit a few
::notify signals only after the window-created signal, although
the actual property change happened before that.

This caused confusion in gnome-shell code where a notify::skip-taskbar =
true emission was seen when the property already was true inside a
window-created handler before.

In order to fix that that, we notify the window creation
post-construction
of the GObject on GInitable.init vfunc

Details
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6119#note_1598983
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6119

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2703>
2022-11-22 11:29:38 +01:00
Bilal Elmoussaoui
5aa104c48d xwayland: Correct the flag of the surface property
As the surface is cleaned up when the window is dropped, marking it
as construct property more correct & mark it as static_strings while at
it.

Fixes a regression caused by
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2418

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2703>
2022-11-22 11:27:17 +01:00
Bilal Elmoussaoui
6b77532a23 window: Move surface property to it subclasses
As we have specific window types per display server,
having it in the parent class makes building without wayland
harder to achieve

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2418>
2022-11-17 11:30:56 +00:00
Bilal Elmoussaoui
c3a01e4e18 core: Untangle meta_window_shared_new
The constructor used to take Wayland/X11 specific types which makes
building without Wayland/X11 not possible.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2272
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2418>
2022-11-17 11:30:56 +00:00
Robert Mader
7e838b1115 wayland/outputs: Implement wl_output v4
This version adds the name and description events already present
in xdg_output.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2692>
2022-11-10 13:45:05 +01:00
Robert Mader
1b1eed0dbd wayland/outputs: Implement wl_output v3
This version adds a release event, allowing clients to tell the
server that it can clean up the related wl_resource.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2692>
2022-11-10 13:45:05 +01:00
Jonas Ådahl
ac093dc651 wayland/xdg-shell: Send xdg_popup.popup_done when position invalid
A client may provide a positioner that places the window outside of its
parent. This isn't allowed, according to spec, so we hide the window and
log a warning. This, however, leads these affected clients with an
incorrect view of what is mapped or not, meaning it becomes harder to
recover.

Fix this by sending xdg_popup.done when we hide the popup due to an
invalid position. Don't error out the client, let the bug slide, as
that's a less jarring experience for existing applications that
reproduce this than being disconnected, which practically feels like a
crash.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2408
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2645>
2022-11-06 13:06:37 +00:00
Robert Mader
d313c8f4fe Revert "wayland/pointer-constraints: Fix window check on subsurfaces"
This reverts commit 50288d1ead.

The fix is uncomplete and causes crashes under certain circumstances.
As we are close to the next point release let's revert it for now.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2685>
2022-11-03 13:17:40 +01:00
Robert Mader
50288d1ead wayland/pointer-constraints: Fix window check on subsurfaces
`get_window()` is not implemented by the subsurface role, returning
`NULL`, breaking constrains for subsurfaces.
While the `get_window()` behaviour could change in the future, for now
use `get_toplevel_window()` which does what we need here while avoiding
possible regressions.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2223
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2681>
2022-11-01 17:04:16 +01:00
msizanoen1
b61b0478f7 xwayland: Always require X11 authentication
This reverts commit eac227a203.

Currently, Flatpak applications can bypass the X11 permission setting
and access the X server through abstract sockets because X11 authentication
is not enforced for the current user ID.

Fix this by always requiring X11 authentication for Xwayland. This also
means applications without XAUTHORITY set to the file with Mutter's
Xwayland credentials cannot connect to X, including apps launched from
VT or SSH.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2633>
2022-10-21 14:06:28 +00:00
Jonas Ådahl
cefa4044d1 Revert "wayland-keyboard: Don't send pressed keys on enter"
Back in 2014 sending pressed keys to Wayland clients caused issues,
because at least Xwayland didn't handle that gracefully, causing issues
like ghost-pressed keys. A way it was reproduced was quickly alt-tab:ing
to and from a Firefox window, which would cause the File menu bar
incorrectly appearing.

While this was reported to the Xwayland component back then, it was,
probably by mistake, assumed to be an issue in mutter, and mutter
stopped sending pressed key events on enter.

The following year, Xwayland was eventually fixed, but the work around
in mutter has been kept around until it was again noticed as an
inconsistency between compositor implementations.

Lets remove the work around, and follow the spec, again.

This reverts commit c39f18c2d4.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2457
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2657>
2022-10-19 15:19:34 +00:00
Jonas Ådahl
ed8275ec33 wayland/seat: Don't double-disable input classes
We'd set the capabilities to 'none', meaning all previously enabled
device classes would be disabled. That means we shouldn't re-disable
them directly after.

This ensures '..disable()' is only called once for every '..enable()'.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2657>
2022-10-19 15:19:34 +00:00
Max Zhao
87e1d72cd4 wayland: Fix null pointer deference in meta_get_first_subsurface_node.
In fcfe90aa, multiple for loops were replaced with
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE.

However, this substitution was not side-effect free, and introduced a
null-pointer dereference risk as shown in the example below:

Old:

    for (n = g_node_first_child (surface->subsurface_branch_node);
         n;
         n = g_node_next_sibling (n))
      {
        if (G_NODE_IS_LEAF (n))
          continue;

        meta_wayland_surface_update_outputs_recursively (n->data);
      }

n is checked for NULL during each loop in the condition expression.
Therefore, when `G_NODE_IS_LEAF (n)` is called, `n` is guaranteed not to
be NULL. Note also that g_node_first_child is also NULL-safe since it
performs a NULL check internally.

New:

    META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
      meta_wayland_surface_update_outputs_recursively (subsurface_surface);
    =
    for (GNode *G_PASTE(__n, __LINE__) = meta_get_first_subsurface_node ((surface)); \
     (subsurface = (G_PASTE (__n, __LINE__) ? G_PASTE (__n, __LINE__)->data : NULL)); \
     G_PASTE (__n, __LINE__) = meta_get_next_subsurface_sibling (G_PASTE (__n, __LINE__)))

In the new logic `subsurface` is still checked for NULL in the loop
condition. However, in the new loop init:

    ...
    meta_get_first_subsurface_node (MetaWaylandSurface *surface)
    ...

    n = g_node_first_child (surface->subsurface_branch_node);
    if (!G_NODE_IS_LEAF (n))
    ...

The above implementation performs a `G_NODE_IS_LEAF` call, which
performs a dereference on `n`, without first checking for NULLs.

This NULL dereference triggers the following gnome-shell crash:

    Core was generated by `/usr/bin/gnome-shell'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  meta_get_first_subsurface_node (surface=0x55d589623450) at ../src/wayland/meta-wayland-surface.h:399
    #1  pointer_can_grab_surface (pointer=0x7f6dc4012700, surface=0x55d589623450) at ../src/wayland/meta-wayland-pointer.c:1306
    #2  0x00007f6ddb94d509 in meta_wayland_pointer_can_grab_surface (pointer=<optimized out>, surface=surface@entry=0x55d589623450, serial=serial@entry=996) at ../src/wayland/meta-wayland-pointer.c:1321
    #3  0x00007f6ddb950d05 in meta_wayland_seat_get_grab_info (seat=seat@entry=0x55d586c24f20, surface=0x55d589623450, serial=996, require_pressed=require_pressed@entry=0, x=x@entry=0x0, y=y@entry=0x0)
        at ../src/wayland/meta-wayland-seat.c:467

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2655>
2022-10-17 12:38:21 +00:00
Jonas Ådahl
21cddbae95 tests/wayland-fullscreen: Also test toggling fullscreen
This tests that unfullscreen makes the black background disappear, and
that fullscreening again makes it re-appear.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
19df8888fb tests/wayland-fullscreen: Check surface size
In the test in question, it should be smaller than the window geometry,
since the black background makes the window geomerty larger than the
surface.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Sebastian Wick
909616b208 window-actor/wayland: Draw black background for fullscreen windows
Fullscreen Wayland toplevel surfaces don't need to respect the
configured size in which case it should be shown centered on the monitor
with a black background. The black background becomes part of the window
geometry.

The surface container is responsible for correctly culling the surfaces
and making sure the surface actors are removed from the actor tree to
avoid destroying them.

The window actor culling implementation assumes all surfaces to be direct
children of said actor. The introduction of the surface_container actor
broke that assumption. This implements the culling interface in
MetaWindowActorWayland which is aware of the actor surface_container and
fullscreen state.

v2: Fix forwarding culling to surface even if there is a background.
v2: Don't alter passed geometry.
v2: Update window geometry code documentation to reflect these changes.
v2: Only use constrained rect if we're acked fullscreen.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
8832a5a1c2 window/wayland: Keep track of last acked configuration
This is helpful to know what current state a window actually have, in
contrast to the state in MetaWindow (e.g. MetaWindow::fullscreen) which
is the intended state, be it current or not yet so.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
6cbc518089 window/wayland: Update buffer and frame rect in the same place
First make sure we call 'move_resize()' in all cases where the size or
position can change, then move the updating of the buffer rect to the
same place as we update the frame rect. This means keeping track of
surface size changes, in addition to geometry changes, and calling
finish_move_resize() whenever any of those changes, in addition to
acknowledged configurations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
47c8063b30 window/wayland: Calculate position also for acked fullscreen configs
An acked fullscreen window also need to have its position updated in
response to a configure ack, so that it's moved to the right position
(e.g. correct monitor).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
2a62e690a2 window/wayland: Use scale for configured rect in configuration
When a window configuration is constructed for a Wayland surface it
contains a position, size and a scale. The scale is the geometry scale
for the configuration, i.e. before the size is sent the passed dimension
is divided with the passed scale.

When moving between monitors with different scales, if we use the
existing geometry scale, this means we will send a configure event with
incorrect dimensions. Fix this by calculating the scale used in the
configuration given the rect we're configuring with as this will mean
the correct size will be sent to the client.

v2: Removed the fullscreen condition. Don't know why it was added to
begin with.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00