1
0
Fork 0
Commit graph

10927 commits

Author SHA1 Message Date
Carlos Garnacho
2fb3c5a4f5 x11: Move Motif WM hints to a separate header
These are now referenced on the frames client side (in order to
track deletable state from the client window) and the mutter side
(pretty much everything else, like figuring out if a window wants
WM decorations).

It makes sense to make this a separate header, so that we don't
need to doubly define these flags/structs.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2735>
2022-12-05 12:40:53 +01:00
Carlos Garnacho
dfaa6fdc14 frames: Fix check of Motif WM hints
We use this for tracking the deletable state of the client window,
but forgot to check that the MWM_HINT_FUNCTIONS hint is set in
hints.flags before checking hints.functions.

This resulted in windows that do not specify this flag (and thus
should go with the defaults) in being mistakenly removed the close
button, as the functions flags would be typically 0 in that case.

Fixes issues with Chromium and Electron applications missing the
close button, since Chromium does this on X11.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2735>
2022-12-05 12:40:53 +01:00
Carlos Garnacho
6c0254bf02 frames: Double check _MUTTER_NEEDS_FRAME property changes
Recalculating window features is a busy thing on the Mutter side, the
different properties being (re)set will overwrite the current state
and cause some side work. Between that is the rewriting of the
_MUTTER_NEEDS_FRAME property on the window being recalculated, which
throws the frames client off, by thinking the window does actually
require a new frame.

It is not sufficient to trust that PropertyNewValue means the property
or the value are new, also double check that the window did not have
in fact a frame, and avoid the busy work if it did.

Besides the busywork that can be easily avoided, this also fixes the
window close button state being stuck if the window changed its
deletable state, since the frame being respawn managed to miss the
property change.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2735>
2022-12-04 12:09:43 +01:00
Georges Basile Stavracas Neto
381de44c5d window-actor: Use logical monitor scale on cursor scale
When using 'scale-monitor-framebuffer', it's important to use the
monitor's scale on top of the cursor texture scale. This matches
what the monitor screencast source does.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2737>
2022-12-03 15:22:31 -03:00
Georges Basile Stavracas Neto
1f705ee10a window-actor: Apply resource scale to cursor position
meta_screen_cast_window_stream_src_set_cursor_metadata() relies
entirely on meta_screen_cast_window_transform_cursor_position()
to return the correct relative cursor position.

However, this function actually does not return the expected
values, since it does not apply the resource scale to the
transformed position.

Actually apply the cursor scale when calculating the cursor
position.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2737>
2022-12-03 15:21:46 -03:00
Georges Basile Stavracas Neto
4d4e8e5862 screen-cast/src: Ceil cursor buffer size
meta_screen_cast_stream_src_set_cursor_sprite_metadata() receives
the cursor sprite, position, and scale, and with that it downloads
the cursor sprite by drawing it into a separate framebuffer, then
calls cogl_framebuffer_read_pixels() in it - this is the offscren
path that is very common when using screen capturing applications
such as OBS Studio.

There's a sneaky issue in this code path though: the 'scale' value
is a float. The cursor size is then determined by multiplying the
sprite width and height - two integer variables - by scale, and
this relies on standard float-to-int conversions. This is problematic
as sometimes the rounded values disagree with what is expected by
cogl_framebuffer_read_pixels(). If the packing of either the cursor
width or height is off by one, glReadPixels() will try to write into
off bounds, which crashes.

This can be reproduced by enabling fractional scaling, setting a 150%
zoom level, on a 4K screen, and opening any commit with an image diff
in gitlab.gnome.org, all while screencasting. When hovering the new
image, the cursor sprite will be such that it triggers this code path,
and reproduces this issue.

Fix this by always ceiling the cursor sprite sizes.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2736>
2022-12-03 09:25:52 -03:00
Bram Stolk
7a103bbfe9 core: Avoid generating XEvent from uninitialized data
The uninitialized fields in this event causes use of uninitialised
data as seen in valgrind:

==71864== Syscall param writev(vector[0]) points to uninitialised byte(s)
==71864==    at 0x5026EBD: __writev (writev.c:26)
==71864==    by 0x5026EBD: writev (writev.c:24)
==71864==    by 0x6482A3B: UnknownInlinedFun (xcb_conn.c:296)
==71864==    by 0x6482A3B: _xcb_conn_wait.part.0 (xcb_conn.c:551)
==71864==    by 0x6482BAF: UnknownInlinedFun (xcb_out.c:469)
==71864==    by 0x6482BAF: _xcb_out_send (xcb_out.c:470)
==71864==    by 0x6483DD7: UnknownInlinedFun (xcb_out.c:416)
==71864==    by 0x6483DD7: xcb_writev (xcb_out.c:409)
==71864==    by 0x53B79B4: _XSend (xcb_io.c:587)
==71864==    by 0x53BBF38: _XReply (xcb_io.c:679)
==71864==    by 0x53AFFC9: XQueryTree (QuTree.c:47)
==71864==    by 0x4982A5F: query_xserver_stack (stack-tracker.c:508)
==71864==    by 0x4EA1F5F: g_closure_invoke (gclosure.c:832)
==71864==    by 0x4ECFD45: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
==71864==    by 0x4EC0129: g_signal_emit_valist (gsignal.c:3549)
==71864==    by 0x4EC03B2: g_signal_emit (gsignal.c:3606)
==71864==  Address 0x287d5900 is 32 bytes inside a block of size 16,384 alloc'd
==71864==    at 0x4849444: calloc (vg_replace_malloc.c:1340)
==71864==    by 0x53A5FE8: XOpenDisplay (OpenDis.c:240)
==71864==    by 0x6100E3C: _gdk_x11_display_open (gdkdisplay-x11.c:1565)
==71864==    by 0x60CF675: gdk_display_manager_open_display (gdkdisplaymanager.c:462)
==71864==    by 0x49D59F1: open_gdk_display (meta-x11-display.c:1041)
==71864==    by 0x49D5D64: meta_x11_display_new (meta-x11-display.c:1156)
==71864==    by 0x49564AD: meta_display_init_x11_finish (display.c:743)
==71864==    by 0x495679D: on_x11_initialized (display.c:818)
==71864==    by 0x4D67558: g_task_return_now (gtask.c:1232)
==71864==    by 0x4D67782: UnknownInlinedFun (gtask.c:1301)
==71864==    by 0x4D67782: g_task_return (gtask.c:1258)
==71864==    by 0x495663C: on_xserver_started (display.c:788)
==71864==    by 0x4D67558: g_task_return_now (gtask.c:1232)
==71864==  Uninitialised value was created by a stack allocation
==71864==    at 0x49D4A59: take_manager_selection (meta-x11-display.c:640)
==71864==

To fix this, fully initialize the event struct before sending it.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2535
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2724>
2022-12-01 20:42:36 +00:00
Carlos Garnacho
20bf7f5ceb x11: Delay next resize op after sync resize until frame is painted
Since the frames are now rendered by a separate process, we no longer
can guarantee at this point that all updates were handled. Engaging
in a new synchronous resize operation will again freeze the actor,
so sometimes we are left with a not-quite-current buffer for the
frame+window surface.

In order to ensure that the right changes made it onscreen, delay
this next synchronous resize step until the moment the surface was
repainted. This avoids those glitches, while still ensuing the
resize operation ends up in sync with the pointer.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
9feac5ce62 compositor: Opt out compositor shadows from windows with frames
Let the frames client render its own shadow. In order to do that,
avoid double painting a shadow on the compositor side, and extend
the mask area of the frame, so it does unveil the (so far)
hidden frames-client-side shadows.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
84785951fd x11: Remove MetaX11WindowControl
These interfaces are no longer used, in favor of CSD-alike messaging
between the frames client and Mutter.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
92feea3033 ui: Excise old frames UI
This is no longer used, in favor of the standalone frames client.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1077
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
f2237fa0c8 x11: Add frame synchronization to window frames
There's two meanings of "frame" there! Since SSD frames are now
rendered by an external client, and there are no actual mechanism
that ensures the frame did already get painted when the client did
respond to its NET_WM_FRAME_SYNC_REQUEST request, there may be
artifacts when resizing windows.

In order to get always the best visual result, we should actually
synchronize rendering with both the client window and the window
frame window.

This commit adds these mechanisms, so a sync alarm update is
expected on both windows until further resizes are allowed, this
ensures window and frame stay in sync, even after moving rendering
elsewhere.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
782d200d6c x11: Add "source_xwindow" parameter to MetaPropValue
It will become necessary to track properties and changes from frame windows,
and it will be more convenient to have this managed by the common property
tracking mechanisms.

Add this source_xwindow parameter so property handler functions can check
whether the property belonged to the client Window or the frame Window.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
a22c66fa51 x11: Add intermediate helper function to update X11 window after sync
This function will be added some more logic in future commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
6a80bc3a54 x11: Decouple sync alarms from window XIDs
Store the alarms in a different hashtable, and look up the MetaSyncCounter
right away. It so far avoids the MetaWindow middle man, but will also be
simpler when each window can possibly have more than one active alarms.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
f5cb8a73d5 x11: Fix size delta calculations
This used to be a comparison between old/new width and height, but
broke long ago.

Fixes: 6e06648f - window: Refactor all move/resize operations to be in frame rect space
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
bbd988cbc5 core: Shuffle function to get description string from a frame
This will remain used (and mildly useful), so move it outside of src/ui.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
3994297429 x11: Integrate frames client into Mutter
Replace the in-process implementation of frames with the external
frames client.

When a client window is created and managed by Mutter, Mutter will
determine whether it is a window that requires decorations and
hint the creation of a frame for it by setting the _MUTTER_NEEDS_FRAME
property on the client window.

After the frames client created a window that has the _MUTTER_FRAME_FOR
property, Mutter will proceed to reparent the client window on the
frame window, and show them as a single unit.

Rendering and event handling on the frame window will be performed by
the external client, Mutter is still responsible for everything else,
namely resizing client and frame window in synchronization, and
managing updates on the MetaWindowActor.

In order to let the frame be managed by the external client, Mutter
needs to change the way some properties are forwarded to the client
and/or frame windows. Some properties are necessary to keep propagating
to the client window only, some others need to happen on the frame
window now, and some others needs to be propagated on both so they
are synchronized about the behavior.

Also, some events that were previously totally unexpected in frame
windows are now susceptible to happen, so must be allowed now.

MetaFrame in src/core/frame.c now acts as the wrapper of foreign
windows created by the frames client, from the Mutter side. Location,
size, and lifetime are still largely in control of Mutter, some
details like visible/invisible borders are obtained from the client
instead (through the _MUTTER_FRAME_EXTENTS and _GTK_FRAME_EXTENTS
properties, respectively).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
3f8e4d515e frames: Add new X11 frames client
This small X11 client takes care of creating frames for client
windows, Mutter will use this client to delegate window frame
rendering and event handling.

The MetaWindowTracker object will keep track of windows created
from other clients, and will await for _MUTTER_NEEDS_FRAME property
updates on those (coming from Mutter), indicating the need for a
frame window.

This process is resilient to restarts of the frames client, existing
windows will be queried during start, and the existence of relevant
properties checked. Mutter will be able to just hide/show
SSD-decorated windows while the frames client restarts.

The frames are created through GTK4 widgets, the MetaWindowContent
widget acts as a replacement prop for the actual client window,
and the MetaFrameHeader wraps GtkHeaderBar so that windows can be
overshrunk, but otherwise a MetaFrame is a 100% true GTK4 GtkWindow.

After a frame window is created for a client window, the
_MUTTER_FRAME_FOR property will be set on the frame window,
indicating to mutter the correspondence between both Windows.

Additionally, the pixel sizes of the visible left/right/top/bottom
borders of the frame will be set through the _MUTTER_FRAME_EXTENTS
property, set on the frame window.

In order to make the frame window behave as the frame for the
client window, a number of properties will be tracked from the
client window to update the relevant frame behavior (window title,
resizability, availability of actions...), and also some forwarding
of events happening in the frame will be forwarded to the client
window (mainly, WM_DELETE_WINDOW when the close button is clicked).

Other than that, the frames are pretty much CSD GTK4 windows, so
window drags and resizes, and window context menus are forwarded for
the WM to handle.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
ad02ef6f44 x11: Drop unnecessary check to ignore crossing events
This check dates all the way back to commit ac2aa5337d. At the time, the
window switcher was an actual X window, that could generate crossing events
if popped up under the pointer. Checking for this kind of crossing events
made sense back at the time in order not to break focus-follows-mouse as
it's been behaving for long.

But now, this UI is all Clutter widgetry, which in the worst case (X11
sessions, of course) it will update the stage window shape to make these
parts clickable. This happens in other places of code that do already
check for ignoring crossing events.

Underneath, this looked up for a Mutter-local GdkWindow of type
GDK_WINDOW_TEMP, only the main MetaFrames window matches those characteristics
nowadays, notably no window switcher popups. Since the remaining window is
never unmapped (until perhaps shutdown), the paths were functionally dead.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
2af2b5254d ui: Drop undeclared function definition from header
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:53 +00:00
Carlos Garnacho
450be1dc95 x11: Do not fake frame extents if unmanaged window asks for _NET_FRAME_EXTENTS
If the window is not managed, it's weird that it asks for _NET_FRAME_EXTENTS,
it's even weirder that mutter replies with a frame border that would only
apply if the window were managed. Stop doing the latter, and drop the
MetaUI call that calculates borders from the theme settings.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
b891f8a52c compositor: Move frame drawn x11 management to MetaSyncCounter
This is part of the same MetaSyncCounter mechanism, so move it together
on one place.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
740b8e8cce x11: Replace MetaWindow sync request handling with MetaSyncCounter
Put the helper to use, in order to lift MetaWindow itself from this
accounting. As a bonus, the data itself now moved to the MetaWindowX11
private struct, since this may only happen with X11 windows (or its
Xwayland subclass).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
235a86ab41 x11: Add standalone MetaSyncCounter helper struct
This helper struct takes care of the handling of requests and alarms
in order to satisfy NET_WM_SYNC_REQUEST. It will be necessary to
decouple rendering of windows and frames in future commits, so each
window may need its own synchronization and accounting.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
ab06232dbe compositor: Ensure atom existence initializing DnD
These only exist because GTK creates them ahead of us, stop relying
on that.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
dae981cc5c core: Avoid notifying the stack manager of frame reparents during unmanaging
This may result in a view of the stack in MetaStackManager that does not correspond
to reality, since the window is already being unmanaged, there is no point either in
notifying the stack manager about it.

This slight divergence with reality in the MetaStackManager may produce a non-accurate
view if querying its state has to go through the predicted branches. Later synchronization
with the X11 stack may even this out, but the result really depends on when it is asked.
Fixes some intermittent failures in the stacking/closed-transient-only-take-focus-parents
unit test.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
a60863838e core: Synchronize client window mapped state before showing window
The meta_window_show() method internally relies on window->mapped being
up-to-date, or attempting to focus it may fail since the window is not
mapped yet, resulting on the window being mapped, but not focused as
it would be expected.

This is moot so far, since windows with frames are created sort-of
synchronously and showing them will result in the focus attempt happening
when the window is already mapped, but things will break when this
becomes an asynchronous step.

Ensure to synchronize client state before showing, so any attempts to
focus the window are able to succeed despite the initial state when
calling meta_window_update_visibility().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
9135931385 tests: Ensure that restore-size resizes the client before maximize/unmaximize
The test does simply "wait" which apparently is not enough to ensure the
client window did resize to the expected dimensions. Use "wait_reconfigure"
and assert that the size after resize is the expected, before going further
at testing its behavior after maximize/unmaximize; it might end up with the
unexpected size after the whole operation.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +00:00
Carlos Garnacho
62d91bb5fd tests: Wait for windows being mapped after show
Since having a window shown is becoming a more asynchronous process,
we should wait for the window actor being mapped after requesting
the window to be shown.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
2022-12-01 20:10:52 +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
Jonas Ådahl
db1000e264 plugin-manager: Don't try to starte effect when shutting down
Add internal state (starting, running, stopping), and use this instead
of MetaDisplay struct fields to determine whether to start animations.

This fixes issues when we try to animate things when shutting down.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2716>
2022-11-25 10:26:52 +00:00
Jonas Ådahl
c1982218e1 context: Add 'started' and 'prepare-shutdown' signals
The backend is changed to listen to 'prepare-shutdown' and forward, but
the 'started' signal will be used later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2716>
2022-11-25 10:26:52 +00:00
Jonas Ådahl
8bc375005c kms/connector: Don't query the kernel twice when updating
On hotplug, the events we receive from the kernel are async, and
connectors in the kernel come and go as they please. In practice, this
means that calling drmModeGetConnector() twice more or less directly
after each other, there is no guarantee that the latter call will return
anything if the former did.

When updating the connector in response to hotplugs, we'd first update
the list of existing connectors, and following that, query each and
every one again for their current state, to update our internal
representation; only the former handled drmModeGetConnector() returning
NULL, meaning if unlucky, we'd end up doing a null pointer dereference
when trying to update the state.

Handle this by querying the kernel for the current connector state only
once per connector, updating the list of connectors and their
corresponding state at the same time.

Fixes the following crash:

    #0 meta_kms_connector_read_state at ../src/backends/native/meta-kms-connector.c:684
    #1 meta_kms_connector_update_state at ../src/backends/native/meta-kms-connector.c:767
    #2 meta_kms_impl_device_update_states at ../src/backends/native/meta-kms-impl-device.c:916
    #3 meta_kms_device_update_states_in_impl at ../src/backends/native/meta-kms-device.c:267
    #4 meta_kms_update_states_in_impl at ../src/backends/native/meta-kms.c:604
    #5 update_states_in_impl at ../src/backends/native/meta-kms.c:620
    #6 meta_kms_run_impl_task_sync at ../src/backends/native/meta-kms.c:435
    #7 meta_kms_update_states_sync at ../src/backends/native/meta-kms.c:641
    #8 handle_hotplug_event at ../src/backends/native/meta-kms.c:651
    #9 on_udev_hotplug at ../src/backends/native/meta-kms.c:668

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2131269
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2709>
2022-11-24 16:18:22 +00:00
Corentin Noël
66dcef7ac1 window-actor: Add several (nullable) annotations
Many getters might return a NULL value, let's reflect this in the annotations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2715>
2022-11-24 15:16:13 +01:00
Peter Hutterer
8206208a22 backends: Fix a typo
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2714>
2022-11-24 12:25:29 +00:00
Jonas Ådahl
ec82b6e869 keybindings: Use proper enum type in MetaKeyHandler
This simplifies inspecting runtime state using gdb.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2714>
2022-11-24 12:25:29 +00:00
Jonas Ådahl
990a10fe78 barrier/native: Fix coding style
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2714>
2022-11-24 12:25:29 +00:00
Jonas Ådahl
ecaf091eb4 x11-display: Use autoptr during construction
This simplifies error paths, as they don't need to unref.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2714>
2022-11-24 12:25:29 +00:00
Jonas Ådahl
28cbc213d0 x11/cm: Stop using intermediate bypass_clutter variable
There is no need to use the 'bypass-*' method of event processing in the
changed function since in all cases the 'bypass-*' variable was set, any
following event processing functions would ignore the event anyway.
Simplify things a bit by just returning TRUE if the event is consumed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2714>
2022-11-24 12:25:29 +00:00
Jonas Dreßler
1816f21e21 window: Avoid focusing during workspace changes
We can land inside meta_window_focus() in the middle of changing the
window workspace, because some signal handler of MetaWorkspace's
"window-removed" signal triggers a focus. This can cause a crash in
`g_assert (link)` when updating the MRU list because we still think
we're on the old workspace when actually we are already removed from
this workspaces MRU list.

To avoid crashes like this, bail out of meta_window_focus() when we're
in the middle of a workspace change.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5368

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2691>
2022-11-24 12:09:23 +00:00
Jonas Dreßler
098c627f11 window: Move all single-bit booleans to the end of the struct
It's a bad idea to have data like this in the middle of a struct, as it
will easily cause everything behind it to be badly aligned and thus
increase memory access times.

So move all those bitfield booleans to the end of the struct.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2691>
2022-11-24 12:09:23 +00:00
Jonas Ådahl
1645171d4b seat/impl: Wait for pointer constraining when updating viewports
It is generally assumed here and there that the pointer at all point in
time is within some logical monitor, if there is any logical monitor to
be within.

With the input thread, this was for a short amount of time not reliable,
resulting in crashes in combination with hotplugging or suspend/resume,
where monitors come and go quickly.

What happens is that the pointer at first is within a logical monitor,
but when that logical monitor is removed, while the new monitor
viewports are handed to the input thread, the constraining happens
asynchronously, meaning there is a time between between the new
viewports are sent, and before clutter_seat_query_state() starts
reporting the constrained position.

If a new client mapped a maximized window during this short time frame,
we'd crash with

    #0 meta_window_place at ../src/core/place.c:883
    #1 place_window_if_needed at ../src/core/constraints.c:562
    #2 meta_window_constrain at ../src/core/constraints.c:310
    #3 meta_window_move_resize_internal at ../src/core/window.c:3869
    #4 meta_window_force_placement at ../src/core/window.c:2120
    #5 xdg_toplevel_set_maximized at ../src/wayland/meta-wayland-xdg-shell.c:429
    #6 ffi_call_unix64 at ../src/x86/unix64.S:105
    #7 ffi_call_int at ../src/x86/ffi64.c:672
    #8 wl_closure_invoke at ../src/connection.c:1025
    #9 wl_client_connection_data at ../src/wayland-server.c:437

The fix for this is to make sure that the viewports are updated and
pointers constrained synchronously, i.e. the main thread will wait until
after the input thread is done constraining before continuing.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2147502
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2711>
2022-11-24 11:28:55 +01:00
Jonas Ådahl
eb7abdacd8 plugin/default: Autostart localed when querying keyboard layout
Otherwise it's required that systemd-localed is already running, which
is unlikely, since it will auto-terminate by default.

Fixes: 562024f746
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2710>
2022-11-24 01:16:31 +00:00
Bilal Elmoussaoui
74bb480753 sound player: Don't unref undefined fields
If the sound player feature is disabled, none of those fields are
instantiated which causes the crash reported in #2451

Also switch to using g_clear_pointer while we are at it

Fixes https://gitlab.gnome.org/GNOME/mutter/-/issues/2451

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2706>
2022-11-23 10:37:19 +01:00
Jonas Dreßler
260ea37312 tests/clutter/conform: Add a test for event delivery
Add a test for everything related to event delivery. The first test we
add here is making sure we don't regress on the bug fixed with commit
edc226a04d.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2697>
2022-11-22 20:31:42 +00:00
Jonas Dreßler
0d0a6ece32 tests/backend-test: Wait for stage update in add and remove_device
We put a DEVICE_ADDED or DEVICE_REMOVED event into Clutters event queue
here, so we should also wait for Clutter to process events once.

Just putting an event into the queue doesn't mean it gets processed
immediately (especially when the commit after this one is applied), so
wait for a stage update here.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2697>
2022-11-22 20:31:42 +00:00
Bilal Elmoussaoui
bb5af3a6bd g-i: Drop unneeded since/stability annotations
They are no longer useful since the merge of cogl inside mutter

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2708>
2022-11-22 13:32:52 +01: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
Jonas Ådahl
425e80adc2 display: Freeze stack when closing X11 display
If two X11 windows were the last two, we'd remove them from the stack
while unmanaging them. That'd hit an assert in
meta_stack_tracker_restack_managed(), resulting in the following crash
when Xwayland exited unexpectedly with two or more X11 windows being the
only windows on the stack:

  #1  g_assertion_message() at ../glib/gtestutils.c:3256
  #2  g_assertion_message_expr() at ../glib/gtestutils.c:3282
  #3  meta_stack_tracker_restack_managed() at ../src/core/stack-tracker.c:1210
  #4  on_stack_changed() at ../src/core/stack.c:142
  #5  _g_closure_invoke_va() at ../gobject/gclosure.c:895
  #6  g_signal_emit_valist() at ../gobject/gsignal.c:3456
  #7  g_signal_emit() at ../gobject/gsignal.c:3606
  #8 meta_stack_changed() at ../src/core/stack.c:265
  #9 meta_stack_remove() at ../src/core/stack.c:324
 #10 meta_window_unmanage() at ../src/core/window.c:1542
 #11 meta_x11_display_unmanage_windows() at ../src/x11/meta-x11-display.c:111
 #12 meta_x11_display_dispose() at ../src/x11/meta-x11-display.c:141
 #13 g_object_run_dispose() at ../gobject/gobject.c:1448
 #14 meta_display_shutdown_x11() at ../src/core/display.c:831

The added test specifically checks that this scenario is handled
gracefully.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2143637
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2704>
2022-11-21 16:30:06 +00:00
Jonas Ådahl
dec3c49e5a tests/test-client: Handle alarm event processing automatically
Instead of having users of the test client manually deal with alarm
filters, let the test client automatically add itself as filters. This
changes the MetaX11Display a bit, to handle an array of filters instead
of a single filter.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2704>
2022-11-21 16:30:05 +00:00
Florian Müllner
c4f43b65ed build: Replace deprecated meson functions
The `dep.get_<type>_variable()` methods have been deprecated in
favor of the generic `dep.get_variable()` method.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2702>
2022-11-19 02:21:05 +01:00
Jonas Ådahl
db2387d7f8 tests/clutter: Use a 800x600 10 Hz virtual monitor
This matches what CI did, and will hopefully help make some tests that
rely on timings less flaky.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2701>
2022-11-18 19:46:09 +01:00
Jonas Ådahl
22d08501a8 cursor-renderer/native: Fix cursor sprite CRTC scale
The CRTC cursor sprite scale was incorrectly assumed to be always 1.0
when using the default not-scale-monitor-framebuffer mode. This is
harmless in most cases, as most clients provide HiDPI capable cursors,
but for the ones that didn't, we'd end up drawing their cursors
unscaled, when using the cursor planes.

Fix this by using the "texture scale" which is what is intended for
this.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2477
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2698>
2022-11-18 11:26:30 +00:00
Jonas Ådahl
a1d14a6176 cursor-renderer/native: Don't put opaque buffers in cursor plane
Cursor planes tend to be ARGB8888 and support no other format (ideally
we should not hard code this, but un-hard-coding that is for another
day), and if we put e.g. a XRGB8888 buffer in there, it'll either result
in the gbm_bo allocation failing (it doesn't allow USE_CURSOR with any
other format) or mode setting failing if using  dumb buffers directly.
In the former case, we'll fall back to OpenGL indefinitely, and in the
latter, we'll have failed mode sets as long as we try to set the invalid
cursor buffer as the cursor plane.

Change things to process all buffers that are not ARGB8888 using the
scale/rotate machinery we already have, turning XRGB8888 into ARGB8888.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2477
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2698>
2022-11-18 11:26:30 +00: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
Jonas Ådahl
58e89b3a5d tests/clutter: Use the headless backend
One test depends on a pointer event having been emitted so that the
stage has a focused pointer; make sure that has happened.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2699>
2022-11-17 10:25:37 +00:00
Jonas Ådahl
b15be5e287 backend/native: Don't assume passed error points to anything
It's common practice to not require a non-NULL error passed to `GError
**error` arguments, so do not make that assumption here.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2699>
2022-11-17 10:25:37 +00:00
Sebastian Wick
d6d6dc65c1 window-actor/wayland: Do not crash when there is no monitor
When all monitors are blanking or after suspending there might not be
any monitors temporarily. We can't draw a black background when we don't
know the size of the monitor it's fullscreen on but it's fine because
there actually is no monitor.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2508
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2695>
2022-11-15 22:46:30 +01:00
Sebastian Krzyszkowiak
e331e38a19 shaped-texture: Reset pipelines after setting a texture with new size
Attaching a new buffer with a different size than the old one means
that the viewport needs to be recalculated.

Not doing this caused the viewport to be incorrectly applied when
viewport_src_rect remained the same after attaching such buffer.
Pipeline reset usually happens when applying a new viewport,
but it doesn't happen when the viewport values remain the same.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2689>
2022-11-13 18:02:30 +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
Carlos Garnacho
e43234f464 backends: Use Clutter API to get dimensions at MetaInputMapper
We can now ask the ClutterInputDevice about its physical size, instead
of resorting to udev.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
b040964025 backends/x11: Implement get_dimensions() in X11 input devices
We can get the information from X11 itself, so do the calculations to return
the device physical size.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
21fb6cc412 backends/native: Implement get_dimensions() in native devices
We already poked the libinput device size, so use that.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
a37bec258c backends: Drop MetaInputSettings vfunc to figure out trackballs
These now have a capability, so we don't need this vfunc anymore.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
23c931ff18 backends/x11: Avoid usage of udev in MetaInputSettingsX11
Use device capabilities instead.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
7dd25b62ed backends/native: Avoid direct udev usage in MetaInputSettingsNative
Use device capabilities to figure out whether configuration applies to
a device or not.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
46643b895c backends: Use capabilities to figure out trackballs in MetaInputSettings
Port these configuration methods to use capabilities, instead of using the
internal vfunc.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
5471b866b3 backends/x11: Set trackball/trackpoint capabilities
Use gudev to detect these capabilities in input devices.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
Carlos Garnacho
d274d4359f backends/native: Set up trackball/trackpoint capabilities
Use udev to detect these features in input devices.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2617>
2022-11-09 10:46:55 +00:00
John Wudrick
d889aad7cf window: Update ongoing edge resistance flags with input
Fix a recent regression where edge resistance flags where no
longer updated during the move/resize operation.

Fixes: bd6b14a843 (window: Throttle window move grab updates)

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2492
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2687>
2022-11-08 05:01:49 +00: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
Jonas Dreßler
28982ade94 gesture-tracker: Never reject sequences in Wayland sessions
In constrast to x11, Wayland has sane handling for touch events and
allows the compositor to handle a touch event while the clients are
already seeing it. This means we don't need the REJECTED state on
Wayland, since we can also grab sequences after the client has seen
them.

So disallow moving sequences to the REJECTED state on Wayland.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2508>
2022-11-04 19:09:56 +00:00
Jonas Dreßler
fc1b4ae149 gesture-tracker: Only track actions which are actually enabled
Tracking disabled actions doesn't make sense, these will never recognize
anyway.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2508>
2022-11-04 19:09:56 +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
Jonas Ådahl
ec18a1d7ae tests/dbus-runner: Add way to launch custom services
This will be used by CI to launch wireplumber inside the D-Bus session
started by meta-dbus-runner.py.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2678>
2022-11-01 21:04:21 +00:00
Jonas Ådahl
562024f746 plugin/default: Don't load properties when getting locale proxy
This cuts away between 7 and 40 ms from the startup of tests.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2678>
2022-11-01 21:04:21 +00:00
Jonas Ådahl
1efb93e145 profiler: Allow enable tracing via env var
This is helpful to e.g. trace e.g. launching.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2678>
2022-11-01 21:04:21 +00:00
Jonas Ådahl
ca2057da9a Move MetaProfiler from the backend to core
It's not really a backend thing, and we'll want to profile e.g. loading
the backend too, so create it very early and destroy it very late and
let MetaContextMain own it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2678>
2022-11-01 21:04:21 +00: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
Łukasz Spintzyk
c57a500ccb backend/native: Create MetaRenderDevice on_gpu_added when it does not exists
Fixes GNOME/mutter#2481

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2676>
2022-11-01 11:13:38 +01:00
Salman Malik
986d3be7ac virtual-stream: Paint stage properly with/without cursor
This change ensures that when the painted stage is
written out to the buffer, it respects the clients
desire to either desire to either embed the cursor
in the view or not.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2142
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2629>
2022-10-24 19:38:08 +00:00
Salman Malik
abc8555463 virtual-stream: Fix always embedded cursor
This change fixes the issue where the cursor is always
embedded in the frames even when the client has requested
the cursor information be sent as metadata in the stream.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2629>
2022-10-24 19:38:08 +00: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
Sebastian Keller
184055b2bb window/x11: Ignore the _NET_WM_BYPASS_COMPOSITOR = 1 hint
We already detect all the cases that allow a window to be properly
unredirected. Using this hint to bypass some of those checks only causes
windows that can not be unredirected properly to get unredirected
regardless.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2434
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2651>
2022-10-21 12:58:07 +00:00
Sebastian Keller
46fc94b67f surface-actor-x11: Only unredirect fullscreen windows for full damage
When deciding if a window should be unredirected because it was causing
fullscreen damage in the past, it was not considered whether the window
is still fullscreen. This could result in a floating window being
unredirected if it was chosen for unredirection because of
_NET_WM_BYPASS_COMPOSITOR = 1 and was previously fullscreened for >= 100
frames, long enough to change does_full_damage, before getting
unfullscreened.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2434
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2651>
2022-10-21 12:58:07 +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
Jonas Ådahl
bd6b14a843 window: Throttle window move grab updates
There is no point in moving a window at the input event refresh rate,
when the end result will only be used once per update, thus, throttle
the move done during grabs to once per stage update.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2233
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2652>
2022-10-18 18:12:03 +00:00
Jonas Ådahl
11a50fffa2 window: Throttle resize-grab updates to stage updates
With high frequency mouse devices, we would send very many configure
events per each update cycle, which had the end result that some clients
constantly re-allocating and redrawing their buffers far too often, if
they did this in direct response to xdg_toplevel configure events.

Lets throttle the interactive resize updates to stage updates, to avoid
having these clients doing the excessive buffer reallocation.

This also removes some old legacy X11 client resize throttling, that
throttled a bit arbitrarily on 25 resizes a second; it is probably
enough to throttle on stage updates for these clients.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2652>
2022-10-18 18:12:03 +00:00
José Expósito
5fa1a8cf42 backends/native: Send lores scroll in the middle of the detent
Some mice send a value slightly lower than 120 for some detents. The
current approach waits until a value of 120 is reached before sending a
low-resolution scroll event.

For example, the MX Master 3 sends a value of 112 in some detents:

              detent                   detent
    |                        |                       |
                        ^    ^                    ^
                        112  REL_WHEEL            224

As illustrated, only one event was sent but two were expected. However,
sending the low-resolution scroll event in the middle plus the existing
heuristics to reset the accumulator solve this issue:

              detent                   detent
    |                        |                       |
                ^          ^             ^          ^
                REL_WHEEL  112           REL_WHEEL  224

Send low-resolution scroll events in the middle of the detent to solve
this problem.

Fix https://gitlab.gnome.org/GNOME/mutter/-/issues/2469

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2668>
2022-10-18 17:28:32 +00:00
José Expósito
92a90774a4 virtual-input-device/native: Emit discrete scroll when the source is a wheel
Previously, when scroll was received in a remote session, it was handled
as continuous scroll.

This generated issues with clients without high-resolution scroll
support as the code path in charge of accumulating scroll until 120 is
reached was not used and therefore discrete scroll events were not being
generated.

Handle scroll generated in a remote session as discrete scroll when the
source is CLUTTER_SCROLL_SOURCE_WHEEL to fix this issue.

Fix https://gitlab.gnome.org/GNOME/mutter/-/issues/2473

Fixes: 9dd6268d13 ("wayland/pointer: Send high-resolution scroll data")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2664>
2022-10-18 08:16:11 +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
a331d4e45a window: Type check some wm functions
These might get called from JS, so avoid crashing on bogus calls.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5952
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2661>
2022-10-17 11:41:55 +00:00
Robert Mader
4079afe0c7 surface-actor-wayland: Fix assumption in get_current_primary_view
Unlike the multi-view path, the optimized/single-view one doesn't check
if the surface-actor is really present on the view. That is the case
whenever it's hidden - e.g. when the window is minimized.

Fixes 3b7137cb35

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2662>
2022-10-15 21:45:10 +02:00
Daniel van Vugt
100c02e514 drm-buffer: Clarify misleading error message on drmModeAddFB2 failure
The real error is more likely to do with the drmModeAddFB2 failure than
the format not being compatible with drmModeAddFB.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2379
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2656>
2022-10-13 16:06:57 +08: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
6db67c3f21 tests: Add ref-test for Wayland fullscreen client
The ref-test makes sure the actual content is centered and everything
not covered by the actual content is black.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
bb19fe2bd4 tests: Add Wayland fullscreen test client
Fullscreen Wayland toplevel surfaces don't need to respect the
configured size in which case the window content get centered on a black
background which covers the whole monitor.

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
Sebastian Wick
0034b54877 window-actor: Move culling logic into child classes
Prepare for adding Wayland specific culling logic to the
MetaWindowActorWayland class by moving all the logic to the non-abstract
classes, since there will be no reason to keep the logic in
MetaWindowActor around.

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
5be8c50746 window-actor: Rename confusing variable name
A "window rect" in most places refers to the rectangle the window
corresponds to when it comes to window management. MetaWindow::rect also
refers to this window management related rectangle. However in the
geometry sync functions, it instead called what was to be the rectangle
the actor should have as "window rect", which is arguably a bit
confusing. Fix this by renaming it "actor_rect" so that it becomes clear
that it's the rectangle the actor should get on the stage.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Sebastian Wick
c6b4b33570 window-actor: Make meta_window_actor_get_image fastpath reachable
MetaWindowActor previously peeked at the number of child Actors to
determine the number of surfaces. The following commit rearranged the
tree such that MetaWindowActorWayland always has two Actors. This change
lets the subclass determine if the main surface describes the whole
window.

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
Jonas Ådahl
f4645b0a37 window: Make the caller decide when to constrain
There were some magic conditions that decided when
meta_window_constrain() was to be called or not. Reasoning about and
changing these conditions were complicated, and in practice the caller
knows when constraining should be done. Lets change things by adding a
'constrain' flag to the move-resize flags that makes this clearer. This
way we can, if needed, have better control of when a window is
constrained or not without leaking that logic into the generic
to-constrain-or-not expression.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>
2022-10-10 18:16:51 +00:00
Jonas Ådahl
2c8adb1966 output/kms: Don't attemp to add common modes on connectors without modes
We have no way to sanely add safe modes if there are no modes we can
compare with, thus don't try.

Fixes the following crash:

 #0 are_all_modes_equally_sized at ../src/backends/native/meta-output-kms.c:284
 #1 maybe_add_fallback_modes at ../src/backends/native/meta-output-kms.c:310
 #2 init_output_modes at ../src/backends/native/meta-output-kms.c:347
 #3 meta_output_kms_new at ../src/backends/native/meta-output-kms.c:414
 #4 init_outputs at ../src/backends/native/meta-gpu-kms.c:332
 #5 meta_gpu_kms_read_current at ../src/backends/native/meta-gpu-kms.c:368
 #6 meta_gpu_kms_new at ../src/backends/native/meta-gpu-kms.c:403
 #7 create_gpu_from_udev_device at ../src/backends/native/meta-backend-native.c:461
 #8 init_gpus at ../src/backends/native/meta-backend-native.c:551
 #9 meta_backend_native_initable_init at ../src/backends/native/meta-backend-native.c:632

Fixes: 877cc3eb7d44e2886395151f763ec09bea350444
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2127801
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2646>
2022-09-29 14:29:43 +00:00
Sebastian Wick
88504b96d0 tests/color: Test EDIDs with bogus data
Make sure the profile creation fails without crashing and that the
device still becomes ready when we fail to create a profile.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2627>
2022-09-29 13:41:17 +00:00
Sebastian Wick
19837796fe color-device: Clear pending flags always when finished
Even if the task was cancelled or an error occured.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2627>
2022-09-29 13:41:17 +00:00
Sebastian Wick
a8259240ae color-device: Don't create profiles from obvious garbage data
This just checks for any chromaticity being zero and gamma being in
range but we could do a better job at detecting bad data in the future.

Also check the return value of cmsCreateRGBProfileTHR which can be NULL.

Fixes gnome-shell#5875

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2627>
2022-09-29 13:41:17 +00:00
Sebastian Wick
2476a8cedd color-device: Return early if the deivce becomes ready due to an error
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2627>
2022-09-29 13:41:17 +00:00
Sebastian Wick
ed554615f8 color-device: Always become ready no matter if we succeeded or not
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2627>
2022-09-29 13:41:17 +00:00
Carlos Garnacho
1023592f8a wayland: Cancel active pointer gestures with wl_pointer.leave
There may be an active pointer gesture at the time of a focus change, in
which case we should cancel it. Add the plumbing so that happens, by
looking at the active MetaWaylandPointerClient gesture.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5199
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2640>
2022-09-29 12:36:43 +00:00
Carlos Garnacho
57074463ab wayland: Add pointer gesture cancellation internal API
This is ATM unused, but will be used to trigger cancellation of
any active gesture.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2640>
2022-09-29 12:36:43 +00:00
Carlos Garnacho
bbf57d092c wayland: Keep track of active pointer gestures
Only one of them may be active at a time, so track the type
of active gesture so it can get properly cancelled.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2640>
2022-09-29 12:36:43 +00:00
Carlos Garnacho
b85f85d665 wayland: Refactor pointer gesture .end emission event
We will want to trigger this from multiple places for cancellation.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2640>
2022-09-29 12:36:43 +00:00
Michel Dänzer
efc4fa333c backend/native: Sending modifiers to clients can be disabled via udev
Using the new udev tag "mutter-device-disable-client-modifiers".

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2637>
2022-09-22 08:32:02 +00:00
Michel Dänzer
0b7de744a0 wayland/dma-buf: Use meta_renderer_native_send_modifiers
Do not send modifiers if meta_renderer_native_send_modifiers says not to
(and we use scanout).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2637>
2022-09-22 08:32:02 +00:00
Michel Dänzer
00ffe0b454 kms/device: Add flag to disable sending DRM modifiers to clients
So far the new flag can only be set via the new environment variable
MUTTER_DEBUG_SEND_KMS_MODIFIERS, and doesn't have any effect yet.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2637>
2022-09-22 08:32:02 +00:00
Jonas Ådahl
6601c3b02a tests: Add partial-overlapping scanout test
Make sure that if we wiggle a scan-out capable surface a bit, it won't
scan out if it's not exactly in the right position. Do this by first
making the window not fullscreen, then moving it back and forth,
verifying the correct scanout state for each presented frame.

This test addition reproduces the issue described in
https://gitlab.gnome.org/GNOME/mutter/-/issues/2387.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2624>
2022-09-20 18:47:06 +00:00
Jonas Ådahl
85ef0d1a46 compositor-view/native: Check that the actor covers the the view
If we have a window that match the size (i.e. will pass the "fits
framebuffer" low level check), that doesn't mean it matches the
position. For example, if we have two monitors 2K monitors, with two 2K
sized windows, one on monitor A, and one on monitor both monitor A and
B, overlapping both, if the latter window is above the former, it'll end
up bing scanned out on both if it ends up fitting all the other
requirements.

Fix this by checking that the paint box matches the stage view layout,
as that makes sure the actor we're painting isn't just partially on the
right view.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2387
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2624>
2022-09-20 18:47:06 +00:00
Jonas Ådahl
41f488a65c tests/wayland-unit: Move out sync point wait helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2624>
2022-09-20 18:47:06 +00:00
Sebastian Wick
73695995a7 stage: Paint the untransformed swap region
Painting the swap region with CLUTTER_DEBUG_PAINT_DAMAGE_REGION happens
on the view framebuffer, so don't transform the region we paint to the
onscreen.

Fixes the swap region painting on rotated monitors.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2590>
2022-09-20 17:49:10 +00:00
Sebastian Wick
c89bae8594 tests/stacking: Alt+Tab focus+stacking test for globally active input
Gnome-shell uses meta_display_focus_default_window() when shell elements
loose focus which is the case with Alt+Tab window switching. Globally
active input clients don't immediately gain focus though so if
meta_display_focus_default_window focuses a wrong window stacking and
focus don't behave as expected.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
7ac982d0d2 tests/stacking: Test always-on-top stacking and focus
Adds the command make_above to set and unset always-on-top behavior of a
window and tests stacking and focus when activating other windows and
switching workspaces.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
ed7a9af62a tests/stacking: Add workspace management commands
New commands to set the number of workspaces, activate a workspace, with
and without focus, move windows to specific workspaces, and check the
stacking on a specific workspace.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
b4b9a7c90f core: Move remaining default focus window handling to workspace
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
3a96ef023b core: Focus on most recently focused window when switching workspaces
When switching workspaces we previously focused on whatever window is on
top of the stack. If a window is marked as "always on top" then it would
always receive focus when switching workspaces.

Fixes #2240
Fixes gnome-shell#5162
Fixes #178
Fixes #678

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
deae8aa7b1 core/window: Update workspace MRU list earlier
We want to use the workspace MRU list to decide the default focus but
Globally Active Input clients don't call
meta_window_set_focused_internal and therefore don't update the MRU
list. Move the update to meta_window_focus instead.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
f336911d8f default-plugin: Use stopped instead of completed signal
The completed signal is only emitted if the timeline actually completed
but when an actor is destroyed or removed from its parent the timeline
is stopped and not completed.

The workspace switch effect removes window actors from the window group
which destroys the timeline so on_$EFFECT_effect_stopped is never
called and the pointer to the timeline is dangling.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
bc6af4f1c8 default-plugin: Kill workspace switch animation on shutdown
The workspace switch animation moves the WindowActors out of the
WindowGroup so if we shut down while the animation is playing the
WindowActors will have queued a destroy but will be disposed only after
the compositor is destroyed, leaving the WindowActor with a dangling
pointer.

Fix the issue by killing the workspace switch animation on shutdown.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>
2022-09-20 17:14:53 +00:00
Sebastian Wick
89b8edcc6f monitor: Keep the dbus night-light-supported property in sync
Fixes #2424

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2623>
2022-09-19 15:13:12 +00:00
Jonas Ådahl
6edb399b2b x11-display: Keep track ourself if we're restarting
We still set the global state, so that e.g. GNOME Shell can continue
consuming it, but it looks a bit awkward to rely on a global state
inside a single function.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
fc8a4afc45 Remove meta_is_stage_views_enabled()
This is an old relic from when ClutterStageView was being added, and
tests were somewhat prepared to be able to test the "X11 style" of
things, with the nested backend some how managing to emulate that.

Lets drop that stuff, it isn't used by the test suite, and isn't useful
anyway; if we want to test X11 configurations, we should use the actual
X11 backend, which didn't make use of this anyway.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
d517f3ae61 feedback-actor: Make the other properties static strings
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
a9740074ca util: Remove left-over declaration
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
c1215f4213 window-actor/wayland: Add missing config.h
The lack of this resulted in some surprises in header file macro
processing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
bde4280f48 startup-notification/x11: Fix indentation
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
dad384376a wayland/data-device: Clean up coding style a bit
There were a few very long lines, it partly didn't follow function
argument alignment and used glib types instead of stdint types.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:01 +00:00
Jonas Ådahl
c676beea6c xwayland: Move "code like" declarations to the bottom
They'll be closer to the code but still after the "boring" declarations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:00 +00:00
Jonas Ådahl
81cc440f47 window/x11: Minor coding style cleanup
Break up a long somewhat unreadable line.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:00 +00:00
Jonas Ådahl
b9c3e2b01e x11-display: Fly-by coding style fix
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:00 +00:00
Jonas Ådahl
b8cdc91c19 x11-display: Clean up GdkDisplay opening
It exposed unnecessary public and private API, and used a global static
variable instead of a return value, none which was necessary. Remove
both API and use a return value for communicating to the caller.

This doesn't remove a public symbol, lets do that for GNOME 44.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
2022-09-19 14:46:00 +00:00
Jonas Ådahl
af65a01057 barrier: Make type derivable again
This was used gala to implement hot corners, and the way the barrier API
works, there isn't really any practical reasons to not make it
derivable, since the backend is a separate type and object.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2626>
2022-09-15 12:27:52 +00:00
Jonas Ådahl
cc9d2065e1 Revert "barrier: Get rid of private instance struct"
This reverts commit 4095c2431c.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2626>
2022-09-15 12:27:52 +00:00
Daniel van Vugt
a1873e0c4f core/events: Don't update the cursor renderer on motion under X11
Doing so was unnecessary and seemed to cause feedback to Xorg resulting
in heavy stuttering and random freezes.

We do however keep the call to `meta_cursor_tracker_invalidate_position`
so as to not undo the intention of 9bdf4b35.

Suggested by Carlos Garnacho.

Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5861 and
       https://launchpad.net/bugs/1989582

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2625>
2022-09-15 11:59:09 +00:00
Jonas Ådahl
da04ae4ca5 tests: Add duplicate color profile test case
This adds a copy of the calibration test profile and sets up a test to
first add it as a system profile, then setting up the XDG_DATA_HOME
directory so that the duplicate profile is detected, added, and later
discarded.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
94e1f8702d color: Handle profiles not initializing succesfully
We might fail with some part of the color profile construction and
initialization. For example there might be a system wide profile with
the same ID as one we attempt to add from a local ICC directory. When
this happens, we should drop these profiles, and use the ones from the
system instead.

Profiles may fail to initialize for other reasons too, e.g.
unpredictable colord errors, or other I/O issues.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2429
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
20a98e6849 color-profile: Fix error check in finalize
We won't get G_IO_ERROR's but CD_CLIENT_ERROR's.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
166ad34423 color-profile: Don't try to remove the wrong profile on finalize
If our profile wasn't fully initialized, we'd try to clean it up, in an
attempt to handle race conditions by finding synchronously then cleaning
it up, but don't attempt this if the profile is ready, as that means we
didn't create one in the first place.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
f94a5c7ff9 tests/dbusmock/colord: Fix system profile D-Bus path names
They had the username and userid in them, which they shouldn't.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
a2000a1132 tests/dbusmock/colord: Implement FindProfileById
It's used when cleaning up profiles on race conditions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
8a53020e80 tests/dbusmoc/colord: Return proper AlreadyExists error for profiles
This matches what colord does, and allows us to rely on checking error
codes both in production and in the test suite.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
3aecb1c262 color-profile: Rely on property on ICC for filename
This is instead of getting anything from the CdDevice. This avoids a
crash when CdDevice isn't successfully setup but something still tries
to look up the filename of the ICC profile.

This isn't a real bug fix for anything, but there is no reason having to
rely on CdDevice for this anyway, and as we don't really have control of
it, it's less reliable of containing something valid.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
2022-09-15 11:22:54 +00:00
Jonas Ådahl
be4e6484ae render-device: Unmake the EGLContext after checking whether hw accelerated
When creating a render device, we create a temporary EGLContext where we
then query the `GL_RENDERER` string to check whether the renderer is any
of the known software renderers. After we're done, we destroy the
context and move on.

This should be fine as according to specification eglDestroyContext(),
with the context being actually destroyed a bit later when it's no
longer current, but mesa, when running RK3399 (Pinebook Pro), this
results in a crash in a future eglMakeCurrent():

  #0 in dri_unbind_context () at ../src/gallium/frontends/dri/dri_context.c:266
  #1 in driUnbindContext () at ../src/gallium/frontends/dri/dri_util.c:763
  #2 in dri2_make_current () at ../src/egl/drivers/dri2/egl_dri2.c:1814
  #3 in eglMakeCurrent () at ../src/egl/main/eglapi.c:907
  ...

We can avoid this, however, by calling eglMakeCurrent() with
EGL_NO_CONTEXT on the EGLDisplay, prior to destroying, effectively
avoiding the crash, so lets do that.

Related: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7194
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2414
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2612>
2022-09-03 18:34:49 +02:00
Jonas Ådahl
b1a687ae57 tests/color: Test that we handle devices with no GAMMA_LUT
We should create the color device etc, but we shouldn't attempt to set
the GAMMA_LUT.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2611>
2022-09-03 14:41:36 +00:00
Jonas Ådahl
c724cb3720 tests/monitor-test-utils: Add way to make the GAMMA_LUT zero sized
This will be used to test devices that has no gamma capabilities.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2611>
2022-09-03 14:41:36 +00:00
Jonas Ådahl
b29604c3f8 tests/color-management: Move some utility functions higher up
That means they'll be re-usable without having to declare them on top.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2611>
2022-09-03 14:41:36 +00:00
Jonas Ådahl
255cd9a9ff color-device: Don't attempt to set GAMMA_LUT if LUT size is zero
This might happen on e.g. virtual machines. If we don't skip trying,
we'll end up crashing because we'll fail to create a look up table since
the size must be greater than zero to make any sense.

Fixes: baef39e603
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2415
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2611>
2022-09-03 14:41:36 +00:00
Jonas Ådahl
1d4cdd1eb5 wayland/dma-buf: Always send modifiers when using surfaceless
We'll never scan out, which is why ADDFB2 is required otherwise, and we
won't enable the DMA buffer extension if
'EGL_EXT_image_dma_buf_import_modifiers' is missing, so send modifiers
in this case.

This also happens to avoid crashing when the GPU is null, since we'd
otherwise attempt to dereference it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2578>
2022-09-02 20:43:05 +00:00
Jonas Ådahl
44dae3e160 kms: Only force legacy mode setting when using EGLStream
EGLStream is incompatible with atomic mode setting, but nvidia-drm when
using libgbm is not, so lets only deny using atomic mode setting when
the render device is an EGLStream based one.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2578>
2022-09-02 20:43:05 +00:00
Jonas Ådahl
58c3734d78 backend/native: Prepare render devices earlier than KMS
The type of render device used for a specific GPU affects the mode
setting backend that can be used, more specifically, when the render
device is an EGLStream based one, atomic mode setting isn't possible, as
page flipping is done via EGL, not via atomic mode setting commits.

Preparing the render devices before KMS devices means can make a more
informed decision whether to deny-list atomic mode setting for when
a certain GPU uses a EGLStream based render device instance.

This also means we need to translate mode setting devices to render node
devices when creating the render device itself, as doing it later when
creating the mode setting device is already too late.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2578>
2022-09-02 20:43:05 +00:00
Jonas Ådahl
1a0bd44694 backend: Hook up to the parent constructed()
Doing an early out in a constructed() is a bit awkward, and unexpected,
and makes it tricky to call the parents constructed() method (which we
didn't), so clean that up.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2578>
2022-09-02 20:43:05 +00:00
Carlos Garnacho
7a1beb817d backends: Expose InputMapping D-Bus path to determine tablet mapping
Currently, the peripheral "output" setting will be unset if Mutter is
deciding automatically the mapped output of a tablet device. In that
case, gnome-control-center will have a hard time figuring out itself
the better output to show the tablet calibration UI, unless it's hand
held by Mutter.

Add this private D-Bus interface so that gnome-control-center can look
up the output as determined by Mutter to bring the missing harmony
between both. This interface consists of a simple method to get the
mapped output for a input device node.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2605>
2022-09-02 18:34:36 +00:00
Jonas Ådahl
60b382c4e3 x11/session: Set the context as client data on connection watch
It was already assumed to be the context, but we never set it as such,
so things just crashed instead. Now when we set it up correctly,
hopefully that won't happen anymore.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2406
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2267
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5078
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2609>
2022-09-02 17:52:41 +00:00
Jonas Ådahl
b1cc591ef5 tests: Extract D-Bus runner as reusable python module
The D-Bus runner used by tests, including installed tests, is made to be
reusable from GNOME Shell. To do this, install it and the templates in
the pkgdatadir (e.g. /usr/share/mutter-APIVERSION/tests/), generate a
custom runner for the installed tests that uses the installed script and
templates, and change the non-installed original runner to use the
non-installed templates.

The end goal is to reuse the D-Bus session runner and templates used for
mutter when test running GNOME Shell.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1354>
2022-09-02 17:18:43 +00:00
Simon McVittie
4bc5833144 Consistently pass timestamp as uint64 when creating MetaStartupSequence
Passing the wrong type to a varargs function can cause a mismatch
between marshalling and unmarshalling on the stack, particularly on
32-bit architectures. This results in a build-time test failure.

Resolves: https://gitlab.gnome.org/GNOME/mutter/-/issues/2065
Signed-off-by: Simon McVittie <smcv@debian.org>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2182>
2022-09-02 15:21:27 +00:00
Sebastian Wick
449327093e backends: Implement gamma LUT virtual function for MetaCrtcDummy
Fixes a crash in the nested backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2606>
2022-09-02 14:53:56 +00:00
Alessandro Bono
33dc8ca187 window: Notify about size-change when changing monitor
When moving to another monitor the window size may change in some
cases. While unconditionally notifying a size change is not always
correct, it animates the window when moved to another monitor in
GNOME Shell.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2558>
2022-09-02 13:12:09 +00:00
Erico Nunes
932351c2bb backends: Set up swap_region without damage history
Following the EGL_KHR_swap_buffers_with_damage specification, the
surface damage used by eglSwapBuffersWithDamage does not need to
contain the damage history.
Rework that to initialize swap_region earlier, before appending the
damage history.
This may help optimizing the composition process in some cases (at least
on X11 when EGL_KHR_swap_buffers_with_damage is available) by not
accumulating additional regions as damaged unnecessarily.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2241>
2022-09-02 11:06:04 +00:00
Alessandro Bono
db0f12135e output-xrand: Plug a memory leak
Fixes: 99d84ae1cc
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2608>
2022-09-02 09:51:47 +00:00
Carlos Garnacho
a9ae43ff43 wayland: Ignore text_input requests from unfocused clients
This is what the protocol says we should do, and even though normally
an out of focus client should not have any reason to create IM requests,
there is a bit of a grey area around focus changes, as both the client
losing focus and the client gaining focus may respectively try to
disable/enable in an undetermined order.

Anyways, since in that situation the client losing focus is not aware
of the requests being ignored, the serial should always be incremented
in order not to break accounting of .done/.commit for that specific
client.

Fixes the IM focus being possibly "lost" after changing focus between
clients, if the race condition turned the odds in that direction.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2585>
2022-09-02 09:19:42 +00:00
Daniel van Vugt
cc729def90 monitor-config-store: Format <rate> using the C locale (. decimal point)
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2602>
2022-09-02 08:43:00 +00:00
Bilal Elmoussaoui
02110976dc workspace: Mark a string as translatable
This also replaces the wording as a desktop is no longer used to refer
to a workspace

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2375>
2022-09-02 08:04:31 +00:00
Bilal Elmoussaoui
7902fa3f9f core: Make sound player feature optional
Mutter can play sounds in some contexts and also provides an API
for libmutter users to do so using libcanberra internally.

In some specific use cases of Mutter, we would like to not depend
on libcanberra and not have any sound playing feature by default.

The changes keeps the sound player API but make it no-op if the
sound_player feature is disabled to not make it possible to break
a gnome-shell build.

See https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2270
for relevant discussion

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2375>
2022-09-02 08:04:31 +00:00
Daniel van Vugt
f94189d4eb clutter/utils: Remove magic numbers from fixed point calculations
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2587>
2022-09-02 07:33:26 +00:00
Alberts Muktupāvels
3c50a9f8aa output-xrandr: Fix memory leak
Introduced in 99d84ae1cc.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2589>
2022-09-02 07:02:30 +00:00
Jonas Ådahl
eb764e0f0d barrier/x11: Let the seat bind the input events for us
Without doing this, the events bound by the X11 barrier manager will get
overridden by the ones later bound by the seat.

Fixes: 0debb24e12
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2394
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2604>
2022-09-02 06:35:00 +00:00
Jonas Ådahl
73bb333000 backend: Remove unused barrier vfunc
It was added in error, and has been unused since its introduction. Lets
correct the error.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2604>
2022-09-02 06:35:00 +00:00
Sebastian Keller
3e22eb35ed color-store: Fix two small leaks in init_profile_directory
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2603>
2022-09-01 21:39:38 +00:00
Sebastian Keller
48ff211762 color-store: Fix small file path leak in ensure_device_profile
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2603>
2022-09-01 21:39:38 +00:00
Sebastian Keller
57c7d75c43 color-device: Don't wrongly use Unknown vendor in ICC profile from EDID
If the vendor_name was previously successfully determined, we would end
up in the else case, overwriting it with "Unknown vendor" and leaking
the previous vendor_name.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2603>
2022-09-01 21:39:37 +00:00
Jonas Ådahl
9aa9cacb3d color-device: Pass calibration state separately when creating profile
This allows using two separate ICC profiles for one "color profile",
which is necessary to properly support color transform
calibration profiles from an EFI variable.

These types of profiles are intended to be applied using the color
transformation matrix (CTM) property on the output, which makes the
presented output match sRGB. In order to avoid color profile aware
clients making the wrong assumption, we must set the profile exposed
externally to be what is the expected perceived result, i.e. sRGB, while
still applying CTM from the real ICC profile.

The separation is done by introducing a MetaColorCalibration struct,
that is filled with relevant data. For profiles coming from EFI, a
created profile is practically an sRGB one, but the calibration data
comes from EFI, while for other profiles, the calibration data and the
ICC profile itself come from the same source.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2568>
2022-09-01 21:09:28 +00:00
Jonas Ådahl
5b251bd8a7 color-device: Add API to set test efivar path
This will be used by tests to set the special efivar calibration
profile.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2568>
2022-09-01 21:09:28 +00:00
Robert Mader
2a87eb6226 renderer-view: Use common helper function to transform matrices
To deduplicate some code. Tested with all eight possible values.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2468>
2022-09-01 20:40:35 +00:00
Robert Mader
d3b81d70f0 stage-impl: Use onscreen framebuffer for scanout
We may want to use scanout even if the default framebuffer
of the stage view is an offscreen, for example when a Wayland
client provides pre-rotated buffers. The caller is responsible
to ensure this is correct - we already asserted on that before.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2468>
2022-09-01 20:40:35 +00:00
Robert Mader
3c79eb56b9 compositor/native: Allow scanout for offscreen rotated views
If a stage view uses an offscreen framebuffer exclusively for
rotation and a Wayland client provides pre-rotated buffers,
we should try to use scanout.
This saves us one copy more than scanout in the onscreen case,
i.e. two fullscreen copies in total.

Offscreen rotation is notably used for all 90/270 degree rotations
at the moment, as using display hardware for them is apparently
more complex than for x-/y-flips and can even have detrimental
effects on power consumption.

This can be tested with `weston-simple-egl`.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2468>
2022-09-01 20:40:35 +00:00
Jonas Ådahl
39e01d8700 color-manager/x11: Set color transformation matrix
As was done in gsd-color, set the "CTM" of the output. This is only done
in X11, as it was only ever implemented for X11.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2166>
2022-09-01 19:09:21 +02:00
Jonas Ådahl
17c99edfe0 x11: Add X11 color manager subclass
This is used as part of the X11 backend to updated X11 root window
properties according to the ICC Profiles in X Specification.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2166>
2022-09-01 19:09:21 +02:00
Jonas Ådahl
1adbb686bc tests/color: Add test for night light
This mocks gsd-colord to enable night ligth at a given temperature. The
test then verifies that the result exactly matches that of the gamma
ramps gsd-color generated for the same temperature and ICC profile.

There are two types of profiles tested; ones with VCGT, i.e. calibrated
profiles, and ones without. These are tested as the VCGT affects how the
gamma curve looks, while the non-VCGT profiles all only rely on
the blackbody temperature to generate a gamma ramp.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
ceedc0e5fb color: Emit signal when device is updated
Will be emitted when a device updated its color state. Will be used by
an X11 color manager implementation, and tests.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
99d0c37d32 tests/color: Auto cleanup devices after tests
This helps making the test cases smaller, skipping irrelevant repetitive
cleanup after each test.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
a232eb263f backend/test: Add support for gamma getting/setting
The set gamma is just stored in the object, nothing else. It's
initialized to a linear gamma ramp from 0 to UINT16_MAX for each color
channel.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
b7d3c9e3c5 color-device: Maybe update brightness from profile when updating
Some profiles have brightness metadata that also needs to be applied.
Make sure this happens.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
71009779c8 color-manager: Update gamma LUTs when needed
This means on
  - hotplugs
  - color temperature changes
  - service availability (gsd-color, gsd-power)
  - when color devices become ready
  - when color devices change

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
baef39e603 color-device: Add API to update gamma LUTs
This will generate a gamma LUT from the profile and apply it to the
monitor.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
3e1a3faa28 color-profile: Add gamma LUT generators
More or less copied from gnome-settings-daemon. The look up tables are
either calculated based on the VCGT (Video Card Gamma Table) and the
blackbody color for a given temperature, or the blackbody color for a
given temperature alone, if no VCGT is available.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
69df2a368d color-store: Monitor for non-EDID color profiles
This means that e.g. custom profiles or calibrated profiles will be
added and registered with colord. This does not use CdIccStore for two
reasons: don't want to generate duplicate entries for auto-generated
EDID or EFI profiles, and we want to store profiles as MetaColorProfile.
It also happens to be the case that CdIcc does synchronous I/O, which
should be avoided everywhere except on startup.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
22064055be color-profile: Add API to get file path
Each color profile has a corresponding ICC profile saved on the file
system. The getter returns a file path for that ICC profile file.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
16149d7c25 color-manager: Keep track of temperature
It will be used to generate gamma look up tables depending on
temperature.

The temperature comes from org.gnome.SettingsDaemon.Color and
depends on the current night light state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
b3fa4a6cd8 color-manager: Add API to set brightness
It uses the org.gnome.SettingsDaemon.Power.Screen D-Bus API. Currently
brightness set if the proxy is not ready are ignored; whether the
brightness value should be cached and set once it appears or whether
color profiles should be reapplied is yet to be decided.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
7b71ec8ff0 color-device: Add new 'changed' signal for when the device changes
What triggers emission right now is the assigned profile changing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
985292c109 color-profile: Add getter for brightness profile
Will be used to set brightness from a color profile.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
b59dc05b22 crtc: Get/set gamma via helper struct
Instead of passing 4 arguments (red, green and blue arrays as well as a
size), always pass them together in a new struct MetaGammaLut. Makes
things slightly less tedious.

The KMS layer still has its own variant, but lets leave it as that for
now, to keep the KMS layer "below" the cross backend CRTC layer.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
9dda79b281 monitor-manager: Move gamma LUT manipulation API to MetaCrtc
In practice, for KMS backend CRTC's, we cache the gamma in the monitor
manager instance, so that anyone asking gets the pending or up to date
value, instead of the potentially not up to date value if one queries
after gamma was scheduled to be updated, and before it was actually
updated.

While this is true, lets still move the API to the MetaCrtc type; the
backend specific implementation can still look up cached values from the
MetaMonitorManager, but for users, it becomes less cumbersome to not
have to go via the monitor manager.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>
2022-09-01 17:52:01 +02:00
Jonas Ådahl
0a0fb2fda9 color: Create color profile for assigned profile
We created device profiles, that we manage the lifetime of in colord,
but color devices can be assigned profiles other than the ones it was
created for. For example, this can include the standard sRGB profile
provided by colord.

To achieve this, keep track of the default profile of the CdDevice as
the "assigned" color profile of the device. Given this profile
(CdProfile), construct a MetaColorProfile that can then be interacted
with as if it was generated by ourself.

The assigned profile (default profile in colord terms) does nothing
special so far, but will later be used to determine how to apply CRTC
gamma ramps etc.

The sRGB.icc file used in the tests was copied from colord. It was
stated in the repository that it has no known copyright restrictions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
cc84a45b56 color-profile: Create colord profiles
This works similiarly to how MetaColorDevice works, by creating them
asynchronously then signalling the 'ready' signal when done. Also
similarly to MetaColorDevice, the on-demand sync cleanup on finalize is
added, to avoid race conditions when hotplugs happens very rapidly,
e.g. in tests.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
60d0394468 tests/mock/colord: Add profile mock support
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
062abe01b3 color: Generate and store ICC profiles from EDID or EFI
Just as gsd-color does, generate color profiles. This can either be done
from EFI, if available and the color device is associated with a built
in panel, or from the EDID. If no source for a profile is found, none is
created.

The ICC profiles are also stored on disk so that they can be read by
e.g. colord. The on disk stored profiles will only be used for storing,
not reading the profiles, as the autogenerated ones will no matter what
always be loaded to verify the on disk profiles are up to date. If a on
disk profile is not, it will be replaced. This is so that fixes or
improvements to the profile generation will be made available despite
having run an older version earlier.

After generating, add some metadata about the generated file itself
needed by colord, i.e. file MD5 checksum and the file path.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
7a242ff1a1 monitor: Add API to check color transform support
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
083b788c74 color-manager: Maintain a lcms context
Will be used from other color related units later on. This also adds an
explicit dependency on LCMS2.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
f4be29eec7 tests: Add rudimentary color device test
Tests that test case EDID is setup correctly, and that color devices for
monitors are created.

tests/color: Add hotplugging tests

Checks that changing the number of connected monitors reflects the
number of current color devices, and that we end up with the correct end
state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
8826b29329 color-manager: Add ready state
Ready means it has established the connection to colord and can operate.
Will be used by tests to make sure tests don't fail due to race
conditions when connecting to colord.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
41ebf3b1bf color-device: Add getter for the associated monitor
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
6403cfe170 color-manager: Add API to get the color device for a monitor
There is a 1-on-1 mapping between these two entities, so add a getter.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
b8ddf7ad8b monitor: Add getter for EDID info struct
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
9ece224718 output: Keep the EDID struct with the other output info
Will be used later to retrieve other EDID details, e.g. for color
management.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
43cd70089e color-manager: Set up a D-Bus proxy to org.gnome.SettingsDaemon.Color
gsd-color provides this API, which exposes details about the night light
state. Currently, gsd-color also turns this state into CRTC gamma
changes, but this will eventually change, and this is a preparation for
this.

The proxy isn't yet used for anything.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>
2022-09-01 16:54:04 +02:00
Jonas Ådahl
0dc6d76371 tests/kvm: Forward MUTTER_DEBUG to the virtual machine
This helps debugging the tests running using KVM.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2141>
2022-09-01 14:31:40 +00:00
Jonas Ådahl
3fe01ffc4a color-manager: Take over color device management from gsd-color
Previously, gsd-color handled adding color devices. It got information
about those via the GnomeRR API, which is part of libgnome-desktop.
libgnome-desktop itself got this information from the
org.gnome.Mutter.DisplayConfig.GetResources() D-Bus method, implemented
by mutter.

Now, mutter itself will add all the monitor color devices itself,
without having to go via gsd-color.

We sometimes need to delete colord devices synchronously, in certain
race conditions when we add and remove devices very quickly (e.g. in
tests). However, we cannot use libcolord's 'sync' API variants, as it
has a nested takes-all main loop as a way to invoke the sync call. This
effectively means we end up sometimes not return from this function in a
timely manner, causing wierd issues.

Instead, create our own sync helper, that uses a separate context that
we temporarly push as the thread-default one.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2141>
2022-09-01 14:31:40 +00:00
Jonas Ådahl
4fe743e03b dbus-runner: Add colord mocking
This will be needed for adding colord integration without breaking
testing.

The test context is altered to make sure any left over color devices are
cleaned up before starting. This means it becomes possible to run a test
case multiple times without having to restart meta-dbus-runner.py.

Note: Don't use os.getlogin() to get the current username; as that
requires a controlling terminal.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2141>
2022-09-01 14:31:40 +00:00
Jonas Ådahl
67e7140c25 monitor-manager: Move PNP lookup to MetaBackend
It's not really about monitors, even though it is used for monitors.
Lets shrink MetaMonitorManager a bit moving it to the backend.

While at it, stop leaking it too.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2141>
2022-09-01 14:31:40 +00:00