13417 Commits

Author SHA1 Message Date
Mattia Formichetti
970ac8ff50 core/place: Simplify meta_window_place
This is a preparatory commit, it refactors away of the
done_check_denied_focus label, simplifying the control flow.

The only functional difference is that now the auto-maximization when
windows don't fit the work_area is always applied.

The next commits will adapt find_next_cascade to properly handle this.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4202>
2025-02-19 19:20:38 +00:00
Mattia Formichetti
b3fd815bed core/place: Drop unused arguments in find_next_cascade
We drop the x and y arguments from find_next_cascade
since they're unused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4202>
2025-02-19 19:20:38 +00:00
Mattia Formichetti
61a7b21d08 core/place: Drop unused arguments in find_first_fit
We drop the x and y arguments from find_first_fit since they're unused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4202>
2025-02-19 19:20:38 +00:00
Mattia Formichetti
7c5005b9b0 core/place: Reformat place.c
This commit only reformats place.c, starting off uncrustify's output, no
functional change is intended.
It mostly aligns comments, as well as properly space out math,
follow current formatter enforced guidelines and fix alignment on a rogue
bracket.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4202>
2025-02-19 19:20:38 +00:00
José Expósito
5d07e69461 onscreen/native: Allow to force copy mode
Create an environment variable to allow to set the copy mode.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4251>
2025-02-19 19:10:02 +00:00
José Expósito
8245f9f790 onscreen/native: Allow to force CPU copy on copy mode primary
By default, copy mode primary tries to use the GPU to perform the copy
and, in case of error, it fallbacks to CPU.

Add a flag (unused for the moment) to allow to use the CPU to perform
the copy.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4251>
2025-02-19 19:10:01 +00:00
Sebastian Wick
005b969227 wayland: Implement the cursor_shape_v1 protocol
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3668>
2025-02-19 18:06:45 +00:00
Sebastian Wick
25bb319ec2 debug-control: Add property for toggling the cursor shape protocol
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3668>
2025-02-19 18:06:45 +00:00
Sebastian Wick
92c6452753 cursor: Support css and wayland cursor-shape cursors
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3668>
2025-02-19 18:06:45 +00:00
Sebastian Wick
4009bfe006 wayland: Move pointer and tablet tool focus serial check to function
This will be used by the cursor_shape protocol in the next commit.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3668>
2025-02-19 18:06:45 +00:00
Michel Dänzer
ba4cb3e021 kms: Add debug logging about full resource change triggers
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
3fde2f7100 kms/connector: Fix kms_modes_equal
It would return FALSE if any pair of one mode from each list didn't
match, which is always the case if either list has at least two modes.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3831
Fixes: a8d11161b6b4 ("kms: Only emit resources-changed signal if we recorded a change")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
6fe8993e35 kms/connector: Return TRUE from edid_equal if both EDID pointers are NULL
Fixes: a8d11161b6b4 ("kms: Only emit resources-changed signal if we recorded a change")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
71603c22fb kms/connector: Refactor edid_equal helper out of _state_changes
No functional change intended.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
313860e2fa kms: Wait for 2 seconds before handling udev hotplug events
More precisely, wait until no further udev hotplug events have arrived
in 2 seconds.

Keep a list of unique UpdateStatesData structs which have received
hotplug events, and call handle_hotplug_event for all of them once the
timeout expires.

This avoids problems due to some monitors generating hotplug events
when power saving is enabled on locking the session, and then
temporarily appearing disconnected.

v2:
* Make meta_test_disconnect_connect wait and run main context dispatch
  before checking the number of logical monitors.
v3:
* Call g_source_unref immediately after g_source_attach, simplifies
  source cleanup. (Sebastian Wick)
* Free hotplug devices list in meta_kms_finalize. (Sebastian Wick)
* Add KMS debug logging in on_udev_hotplug & hotplug_timeout.
* Bump timeout to 2 seconds. With my affected monitor, the second udev
  hotplug event normally arrives almost a second after the first one,
  occasionally more than 1.5 seconds though.
* Use UpdateStatesData with custom compare function for hotplug_devices
  list data, since the GUdevDevice / device path string pointer values
  are always different.
* Don't wait for timeout if meta_is_udev_test_device returns TRUE, to
  hopefully fix VKMS CI tests. Drop meta_test_disconnect_connect changes
  again.
v4:
* Use hash table instead of list for hotplug_events set. (Sebastian Wick)
* Add comment describing the keys & values in the hash table. (Sebastian Wick)
* Add KMS debug logging in handle_hotplug_event as well.
* Dropped Closes:, this might not suffice to fully address
  https://gitlab.gnome.org/GNOME/mutter/-/issues/3831 after all.
v5:
* Simplify hash table annotation comment. (Sebastian Wick)
v6:
* Rename hotplug_timeout local string pointer to hotplug_event.
* Drop g_clear_pointer in favour of g_autofree in on_udev_hotplug.
  (Sebastian Wick)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
7f78b6a9e5 kms: Use encoded strings instead of UpdateStatesData
Handle NULL string pointer in meta_kms_update_states_in_impl.

Drop second parameter of meta_kms_update_states_sync, which wasn't used
by the external test caller anyway. Split out static update_states_sync
function which takes a hotplug event string pointer instead.

Preparation for next commit.

v2:
* Drop UpdteStatesData for encoded hotplug event strings.
v3:
* Put device path at the end of encoded string, allows simplifying
  meta_kms_update_states_in_impl slightly further.
v4: (Sebastian Wick)
* Use g_autofree for hotplug_event string in on_udev_hotplug, fixes
  leak.
* Store pointer to hotplug event device path string in local variable in
  meta_kms_update_states_in_impl.
v5:
* Initialize `path` local variable to `NULL` and test it instead of the
  `hotplug_event` parameter. Avoids (false-positive) compiler warning
  about `path` possibly being used uninitialized.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
ec73076e07 monitor-manager/native: Remove _read_current_state specialization
It forced the power save mode to META_POWER_SAVE_ON when reading the
current KMS state.

This was problematic when a hotplug event is emitted while the session
is locked, which can be triggered by monitors polling all their inputs
for a signal: There's no mechanism to restore the previous power save
mode in this case, so the monitors would fail to actually enter power
saving mode but stayed on with a blank screen. This was at least one
cause of the symptoms described in
https://gitlab.freedesktop.org/drm/amd/-/issues/662 .

Moreover, I suspect it hasn't had any effect for the actual reading of
KMS state since 5f6aee341959 ("kms/update: Make power saving an update
wide change"), as changing the power save mode to META_POWER_SAVE_ON no
longer results in any immediate KMS state change, it's now only taken
into account for the next mode set.

It's not clear what the intended effect was in the first place, it was
originally added as part of 65db8efbe8b1 ("MonitorManager: add a KMS
backend") without rationale. It might have been cargo-culted from
somewhere else. It shouldn't be necessary from a KMS API PoV though.

Also adjust the KMS hotplug test to assert that a hotplug event doesn't
implicitly change the power save mode.

v2: (Sebastian Wick)
* Fix shortlog of commit which added
  meta_monitor_manager_native_read_current_state.
v3:
* Adjust KMS hotplug test for the change.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Michel Dänzer
a5f1bdff1a kms: Delete unused members of MetaKms
Unused since f27ca241f9a2 ("renderer/native: Move per frame KMS update
to MetaFrameNative") / a6baa77eab89 ("kms: Split out impl/non-impl
separation into MetaThread(Impl)").

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4209>
2025-02-19 16:53:58 +00:00
Alessandro Astone
f31539984d tests/cursor: Embed a copy of the Adwaita cursor theme
As a follow-up to 87cc6633a5, embed a partial copy of the Adwaita cursor theme
and point to it with XCURSOR_PATH to make the test completely independent
from the installed cursor themes.

Indeed, adwaita-icon-theme changed ever so slightly in version 48 so the
ref tests started failing when the new version was installed.

This is a copy of adwaita-icon-theme 47, which is what was used to generate
the ref images.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4252>
2025-02-19 09:21:32 +00:00
Michel Dänzer
eeaff29264 tests/kms/render: Disable triple buffering for now
This requires reverting the previous changes intended for adapting to
triple buffering.

Fixes these tests randomly failing, also in CI pipelines of MRs not
directly related to any of this.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4290>
2025-02-19 06:54:06 +00:00
Marco Trevisan (Treviño)
169ea4cf81 tests: Use env in bash scripts shebang
Bash can be in both /usr/bin/bash or /bin/bash (or elsewhere!) depending on
the distro, so let's be generic using env to figure it out.

This comes from a packaging lintian error we get:

 E: mutter-16-tests: wrong-path-for-interpreter /usr/bin/bash != /bin/bash
    [usr/share/mutter-16/tests/socket-launch.sh]

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4288>
2025-02-18 18:56:29 +00:00
Michel Dänzer
fac0854a4f cursor-renderer/native: Cast MetaGpu to MetaGpuKms only if it is one
Fixes crash in gnome-shell CSS styling test.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4289>
2025-02-18 17:58:20 +00:00
Bilal Elmoussaoui
8223f58b98 frames: Don't set prefer-dark-theme if adwaita is loaded
Avoids the following warning in the logs
mutter-x11-frame[4003]: Using
GtkSettings:gtk-application-prefer-dark-theme with libadwaita is
unsupported. Please use AdwStyleManager:color-scheme instead.

When initializing libadwaita, the AdwStyleManager default instance is
initialized taking care of loading the appropriate stylesheet.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4276>
2025-02-18 18:24:44 +01:00
Michel Dänzer
45f60a2cd4 tests: Use g_assert_nonnull in kms-cursor-force-disable test
Suggested by Carlos Garnacho.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4285>
2025-02-18 11:53:26 +01:00
Michel Dänzer
576f802e26 tests: Add test for MUTTER_DEBUG_DISABLE_HW_CURSORS=1
It tests that the cursor renderer can successfully initialize with the
environment variable MUTTER_DEBUG_DISABLE_HW_CURSORS=1.

It would have caught the crash fixed by the previous commit.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4272>
2025-02-18 09:32:31 +00:00
Michel Dänzer
9b44ebf326 cursor-renderer/native: Fix crash with MUTTER_DEBUG_DISABLE_HW_CURSORS=1
Don't try to realize the cursor sprite for the HW cursor when it's set.

v2:
* Refactor is_hw_cursor_supported helper out of
  realize_cursor_sprite_from_wl_buffer_for_crtc. (Jonas Ådahl)
v3:
* Keep meta_crtc_native_is_hw_cursor_supported check in
  meta_cursor_renderer_native_update_cursor, to try and avoid
  mysterious CI failure.
v4:
* Rename is_hw_cursor_supported → is_hw_cursor_available_for_gpu
  and take a MetaGpuKms * parameter.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4272>
2025-02-18 09:32:31 +00:00
Marco Trevisan (Treviño)
63744815b9 tests/x11-test: Enable x11 debug logs by default
Since META_DEBUG_X11 has been introduced it's useful to run x11 tests
with it set

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4278>
2025-02-17 15:52:13 +00:00
Marco Trevisan (Treviño)
ee496490b6 monitor-dbus-tests: Merge stderr with stdout in gdctl tests
We want to ensure that also the stderr is matching our golden files
and at the same time we should be able to see it in logs (especially
when there's a python error to catch).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4277>
2025-02-17 14:58:06 +00:00
Marco Trevisan (Treviño)
c91c4d2d4e monitor-dbus-test: Do not fail early on wait check
In this way if we fail because of a python error in the launched
script we can still print the output in the test logs

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4277>
2025-02-17 14:58:06 +00:00
Marco Trevisan (Treviño)
f823f1052d monitor-dbus-tests: Use autopointer to free errors
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4277>
2025-02-17 14:58:06 +00:00
Marco Trevisan (Treviño)
73d4bbd1ad tests/build: Require zenity if x11 tests are enabled
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4280>
2025-02-17 10:30:08 +00:00
Florian Müllner
897cc303cb tests/shell: Do not set key-focus to stage
Moving the key focus to the stage should be done by unsetting the
focus rather than setting it to the stage itself.

`clutter_stage_set_key_focus()` already "normalizes" the stage to
NULL internally, so this does not change the actual behavior of the
code.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4256>
2025-02-14 20:19:45 +01:00
Florian Müllner
e49edebf92 clutter/stage: Turn get_key_focus() into a proper getter
The method currently returns the stage itself when the property
is NULL.

This has become particularly problematic as the method is detected
as getter by gobject introspection, and gjs now optimizes property
accesses by calling the getter method instead.

Address this by turning the method into a genuine getter without
falling back to the stage.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4256>
2025-02-14 20:19:45 +01:00
Florian Müllner
1d69b1b505 clutter: Prepare for get_key_focus() returning NULL
While the existing `get_key_focus()` methods looks like a getter of the
`key-focus` property and is detected as such by gobject introspection,
it behaves differently in that it returns the stage if no explicit
focus has been set.

This is about to change, so adjust the couple of cases that rely
on the fallback to the stage.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4256>
2025-02-14 20:17:58 +01:00
Daniel van Vugt
463fc8b92c clutter: Enable triple buffering and adapt the KMS render tests
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
9dec39d92e renderer/native: Discard pending swaps when rebuilding views
It's analogous to discard_pending_page_flips but represents swaps that
might become flips after the next frame notification callbacks, thanks
to triple buffering. Since the views are being rebuilt and their onscreens
are about to be destroyed, turning those swaps into more flips/posts would
just lead to unexpected behaviour (like trying to flip on a half-destroyed
inactive CRTC).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
c681b6977c onscreen/native: Increase secondary GPU dumb_fbs from 2 to 3
So that they don't get overwritten prematurely during triple buffering
causing tearing.

https://launchpad.net/bugs/1999216

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
ffc2a7d3cd onscreen/native: Defer posting if there's already a post in progress
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
5426935adb onscreen/native: Pass frame as a parameter to flip_crtc
Minor style change requested by jadahl. This makes it clear earlier on
in post_next_frame that next_frame has been consumed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
4d4bf1244a onscreen/native: Merge composite and direct scanout posting code paths
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
b6841e2e33 onscreen/native: Insert a 'posted' frame between 'next' and 'presented'
This will allow us to keep track of up to two buffers that have been
swapped but not yet scanning out, for triple buffering.

This commit replaces mutter!1968

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
54b393c2b3 onscreen/native: Split swap_buffers_with_damage into two functions
1. The EGL part: meta_onscreen_native_swap_buffers_with_damage
2. The KMS part: post_next_frame

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
f3688190bf onscreen/native: Deduplicate calls to clutter_frame_set_result
All paths out of `meta_onscreen_native_swap_buffers_with_damage` from
here onward would set the same `CLUTTER_FRAME_RESULT_PENDING_PRESENTED`
(or terminate with `g_assert_not_reached`).

Even failed posts set this result because they will do a
`meta_onscreen_native_notify_frame_complete` in
`page_flip_feedback_discarded`.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
0f7183ebef onscreen/native: Invert the early exit from swap_buffers_with_damage
A long overdue tidy-up. Most of the logic doesn't even need to be
indented under the if statement.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
77590d5e65 onscreen/native: Replace an assertion that double buffering is the maximum
Because it soon won't be the maximum. But we do want to verify that the
frame info queue is not empty, to avoid NULL dereferencing and catch logic
errors.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
980658ed58 backends/native: Add set/steal_sync_fd functions to MetaFrameNative
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
47f485e94e backends/native: Add set/get_damage functions to MetaFrameNative
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
be7fc75878 renderer/native: Steal the power save flip list before iterating over it
Because a single iteration might also grow the list again.

This is now a partial revert of a5be92e03d3b8f74222c5d53ba1332cdeae69bcc.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
fccfaca9fc renderer/native: Avoid requeuing the same onscreen for a power save flip
This is a case that triple buffering will encounter. We don't want it
to queue the same onscreen multiple times because that would represent
multiple flips occurring simultaneously.

It's a linear search but the list length is typically only 1 or 2 so
no need for anything fancier yet.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00
Daniel van Vugt
f7b296f2a9 kms: Keep a shutting_down flag
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1441>
2025-02-14 17:39:09 +00:00