1
0
Fork 0
Commit graph

11037 commits

Author SHA1 Message Date
Carlos Garnacho
12773cf8e2 window: Drop frame_action argument from meta_window_begin_grab_op()
The final effect of this boolean can now be expressed through the
META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED flag to MetaGrabOp. Use that
in the relevant places, and drop the argument.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
f62200a17b core: Drop unused arguments to meta_display_grab_op()
Now that it is called from a single place, there's a few arguments
that are unnecessary:

- button and modifiers are unused
- already_grabbed was originally added to handle grab transitions between
  window menus (GtkMenus, back in the day) with display grabs. It's no
  longer necessary now
- frame_action can be passed through the META_GRAB_OP_WINDOW_FLAG UNCONSTRAINED
  flag

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
57e56ee866 core: Make MetaDisplay grab API private
Leave meta_window_begin_grab_op() as the only public API to initiate
a display grab. There's no longer grab operations that don't attain
windows, and ending these grabs usually happen through user interaction
when the right circumstances happen.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
8685a706cc x11: Use meta_window_begin_grab_op() to begin window grab
Move away from meta_display_begin_grab_op().

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
84ed992a18 core: Port to meta_window_begin_grab_op()
There is no longer reason to call meta_display_begin_grab_op() except
for window grab operations, and meta_window_begin_grab_op() is a
perfectly fine entry point for all window grab operations.

Move away from meta_display_begin_grab_op().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
5e4d69c3a8 core: Make meta_window_begin_grab_op() more generic
Currently, it is thought out to be called with META_GRAB_OP_KEYBOARD*
grab op parameters. Make it more generic so it can also be called for
pointer operations (avoiding pointer warping in that situation).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
43081fc8bd core: Simplify handling of ungrabbing condition
Unlike the comment suggests, this piece of event handling manages
the ungrabbing of a window on button press in the following 2
conditions:

- If a keyboard grab operation was triggered, the window does
  additionally follow the pointer, and first button press ends
  the grab.

- If a button-press grab is ongoing on the window, but more buttons
  are pressed.

We can simplify this to just happen every time a button press event
is received while a window grab op is ongoing. The only case where
this might diverge a bit is same button presses from different
pointer devices, and it's not a big stretch to also undo the grab
in that situation.

This also happens to make the "button" argument in
meta_display_begin_grab_op() completely unused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
2d8fa26c8e core: Pass "frame action" grab operations as an "unconstrained" grab op
The frame_action boolean is only used by constraints.c code, in order to
determine whether a moving window should be able to move past the top
bar or not.

We can avoid the special casing by passing this information as a
META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED flag passed with the grab op.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
a91feeb5df core: Drop check on META_EVENT_ROUTE_WAYLAND_POPUP grabs
Query the MetaWaylandCompositor directly for it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
cca531339d core: Drop META_GRAB_OP_WAYLAND_POPUP
This is no longer used, these being fully handled on the wayland
side.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
1198fe700a core: Use is_grabbed() method to find existing grabs
The whole reason for META_GRAB_OP_WAYLAND_POPUP to exist is to
avoid windows from being activatable/movable/resizable when a
grabbing xdg_popup is active.

Use the meta_display_is_grabbed() method which can tell this
from existing MetaWaylandCompositor grabs, so that this remains
true after dropping META_GRAB_OP_WAYLAND_POPUP.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
1e990ad823 core: Change meta_display_get_grab_op() to has_grab()
Make this public API check just return a boolean about whether
there is an existing grab, instead of exposing MetaGrabOp.

It is desirable to avoid exposing details like
META_GRAB_OP_WAYLAND_POPUP, so that MetaDisplay and wayland
grabs can port to ClutterGrab at their own pace, but also
this further information is unused.

This is likely to be temporary API anyways, after both
MetaDisplay and wayland grabs port to Clutter, it will be
possible to check the ClutterStage for all of them.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
1e289e8d81 keybindings: Minor refactor
Rewrite this codepath so it handles the grab ops that it cares
about, and ignores the rest. This way the code works despite
possible future modifications to MetaGrabOp (e.g.
META_GRAB_OP_WAYLAND_POPUP removal).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
a7b8f06196 core: Move grab_op check for handling window events from passive grabs
This piece of event handling only applies on windows receiving events while
the display is ungrabbed (i.e. for raising it, or beginning a move/resize
operation).

Move the checks on the current grab operation outside of window.c and into
events.c, so all checks about the current grab operation move closer to the
main event handler.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Carlos Garnacho
970ef35a62 core: Drop META_GRAB_OP_FRAME_BUTTON
This is no longer used, since frames and their buttons are no longer
handled by Mutter.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
2023-01-30 10:56:29 +00:00
Anders Jonsson
0d6b0fc165 settings: Fix spelling of endianness
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2813>
2023-01-29 17:37:43 +01:00
Jonas Ådahl
bef9cecb81 build: Make D-Bus codegen declarative
This makes it a bit less cumbersome to add more D-Bus codegen
interfaces.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2811>
2023-01-28 12:41:12 +01:00
Jonas Ådahl
8b92a00dd1 Use the same prefix for all generated D-Bus boiler plate
A somewhat painful rename, but it'll open up for simplifying the build
script a bit, while at the same time bringing consistency to chaos.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2811>
2023-01-28 12:35:54 +01:00
Jonas Ådahl
176b706e66 screen-cast: Fix warning message
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2811>
2023-01-28 12:35:54 +01:00
Jonas Ådahl
c95a24f6e8 backend: Fix a couple of minor GError leaks
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2811>
2023-01-28 12:35:54 +01:00
Jan Tojnar
81cc05e61e build: Fix Sysprof interface path with split sysprof package
When sysprof-4 and libsysprof-capture-4 are installed into different
prefixes, such as with Nix package manager, the D-Bus interfaces
are likely not discoverable from the latter package.

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

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

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

Fixes: 56260e3e07
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2805>
2023-01-25 13:53:11 +00:00
Florian Müllner
0e6395d932 x11/events: Do not update focus XWindow during grabs
During grabs, it is expected that the X11 focus does not correspond
to the display's focus window, as focus should be on the stage's
XWindow instead.

This still messes up the keyboard focus even after we stopped moving
the X11 focus, because we end up with a presumed X11 focus window
of None, and as a result the stage is considered unfocused.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5932

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2776>
2023-01-25 13:31:49 +00:00
Florian Müllner
7531669b4f display: Do not move X11 input focus during grabs
On X11, the stage itself is backed by an XWindow, and moving the
input focus elsewhere will bypass any Clutter-level grabs.

This effectively allows newly opened windows to steal the focus
from gnome-shell itself, which is clearly undesirable. To prevent
that, only move the X11 focus when no grab is in place, just like
commit 50e89e376 did for the stage focus.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5932

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2776>
2023-01-25 13:31:49 +00:00
Florian Müllner
24f796a30c x11/display: Add some logging
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5932

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2776>
2023-01-25 13:31:49 +00:00
Carlos Garnacho
8f268f2930 backends/native: Keep general direction when crossing monitors
When the pointer crosses monitors, we account for a single motion event
resulting in the pointer moving across more than 2 monitors, in order
to correctly account each monitor scale and the distance traversed
across each monitor in the resulting relative motion vector.

However, memory on the direction is kept short, each iteration to
find the target view just remembers the direction it came from. This
brings a pathological case with 4 monitors with the same resolution
in a 2x2 grid, and a motion vector that crosses monitors at the
intersection of all 4 in a perfect diagonal. (Say, monitors are
all 1920x1080 and pointer moves from 1920,1080 to 1919,1079).

In that case, the intersection point at the crossing between 4
monitors (say, 1920,1080) will be considered to intersect with 2
edges of each view. Since there is always at least 2 directions to
try, the loop will always find the direction other than the one
it came from, and as a result endlessly jump across all 4 possible
choices.

In order to fix this, consider only the global v/h directions,
we already know if the pointer moves left/right or up/down, so
only consider those directions to jump across monitors.

For the case at hand, this will result in three monitors visited,
(either bottomright/bottomleft/topleft, or bottomright/topright/topleft)
with a total distance of 0,0 in the middle one, effectively
resulting in a correct diagonal motion.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2598
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2803>
2023-01-24 17:30:46 +00:00
Carlos Garnacho
34a9141a6c backends/native: Minor refactor
Refactor code so that variables don't depend the on motion line
content, but the other way around. This makes it clearer what each
vector means.

This has no functional changes.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2803>
2023-01-24 17:30:46 +00:00
Jonas Ådahl
5235f2b4ac tests/color: Assert we saw the expected messages
g_test_expect_message() needs a g_test_assert_expected_messages() to be
of much use, so add those calls too.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2800>
2023-01-24 13:09:42 +00:00
Jonas Ådahl
11d35f99be util: Make meta_topic() log using the debug level in tests
Some tests expect warnings to be logged, and handle that using
g_test_expect_message(). However, if debug topics are enabled, this
causes g_logv() to expect expected messages to also contain entries with
the debug level 'message' or higher to be listed in the expected message
list. Since meta_topic() always logged using g_message(), enabling debug
topics caused any test that used g_test_expect_message() and had debug
logging somewhere along the code path to fail.

Fix this by changing the log level of meta_topic() to 'debug' if we're
in a test. This doesn't mean they won't be visible, they still will
since debug log entries are printed by default during testing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2800>
2023-01-24 13:09:42 +00:00
Jonas Ådahl
e5602062e2 cogl/frame: Keep track of target presentation time
It's yet to be used for anything, but will later on.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2795>
2023-01-23 15:57:50 +01:00
Jonas Ådahl
24f44aa33e tests/kms/render: Fix paint-view callback type signature
It was missing a cairo_region_t. This also needs adapting the test case,
since prior to this, we didn't actually bump the paint counter when
painting.

When a scanout test isn't waiting to go from compositing to scanout, but
from scanout to compositing, we should not early out when we actually
composited, since that's what we're expecting to see.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2795>
2023-01-23 15:57:30 +01:00
Jonas Ådahl
916b21674e clutter/frame-clock: Pass ClutterFrame via the frame clock interface
Let the ClutterFrame live for the whole frame, and be carried as an
argument to the frame clock listener interface functions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2795>
2023-01-23 12:19:54 +01:00
Jonas Ådahl
84538f402e tests/kvm: Run with 1GB RAM
This makes things like valgrind and catch able to run.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2798>
2023-01-21 14:22:33 +01:00
Carlos Garnacho
c6c7f310d8 x11: Account for variable being possibly NULL
We might end up with a NULL opaque_region here in some circumstances
(client deleted _NET_WM_OPAQUE_REGION, or passed invalid data or a
region with 0 rectangles), account for that when freeing the variable.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
2023-01-20 22:23:55 +00:00
Carlos Garnacho
2b6651327e compositor: Observe frame opaque region when updating shapes
Apply either frame or client window opaque regions (or both as
an union). For client windows without an alpha channel, the frame
shape already contains the client area. If the client window does
have an alpha channel, the client rectangle is cleared to let the
client's opaque region take care of it.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2555
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
2023-01-20 22:23:55 +00:00
Carlos Garnacho
4752a8055c core: Update frame opaque region from _NET_WM_OPAQUE_REGION property
Both read this property on frame creation, and listen to property changed
events about it in the frame window.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
2023-01-20 22:23:55 +00:00
Carlos Garnacho
82b2b76882 core: Add infrastructure to keep window frames' opaque regions
These frames client will use a visual with alpha information, and
report the opaque frame shapes through the _NET_WM_OPAQUE_REGION
window property. We can use this information in the Mutter side
for accurate opaque shapes, despite X11 windows with frames now
being seen as possibly transparent.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
2023-01-20 22:23:55 +00:00
Carlos Garnacho
07e1f87e3b x11: Add function to know whether a client X11 window has an alpha channel
Since the windows created by the frames client will have a RGBA visual, we
no longer can perform simple tests about whether the window is opaque. For
that, we will need to additionally know whether the client-side window has
a visual with an alpha channel.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2758>
2023-01-20 22:23:55 +00:00
Carlos Garnacho
1f51dfa112 x11: Wait synchronously for the frames client to exit
This does nothing wrt making race conditions shorter in the
X11 window manager switch case, but is a nice to have in order
to ensure an orderly shutdown of X11 stuff.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2796>
2023-01-20 21:25:02 +00:00
Carlos Garnacho
a9bf493ec7 frames: Quit immediately on SIGTERM
Restarting a X11 window manager is a busy process, trying to leniently
quit the main loop may result in old and new instances each having a
frames client up and running, and the window handover to be less clean
than it should due to the frames client that is about to exit still
being able to react to the batch of events resulting from the window
manager switch that is already undergoing.

In order to avoid extending this transition period any long, make
the frames client exit() the process immediately when SIGTERM is
gotten from the parent process.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2796>
2023-01-20 21:25:02 +00:00
Florian Müllner
0fa1581699 frames/window-tracker: Stop using deprecated API
GTK deprecated gtk_widget_show() in favor of gtk_widget_set_visible()
and gtk_window_present().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2783>
2023-01-20 20:41:30 +00:00
Jonas Ådahl
ad371a4435 color-device: Don't write to fields when cancelled
Writing to fields (in this case the MetaColorDevice::pending_state) in
response to an asynchronous operation that was cancelled means we'll
write to an arbitrary memory location, potentially causing segmentation
faults or memory corruption.

Avoid these segfaults or memory corruption by only updating state if we
weren't cancelled. Also avoid trying to dereference the device pointer
if we're cancelled.

The memory corruption due to this has been causing test flakyness in the
monitor unit tests due, which should now hopefully be fixed.

Fixes: 19837796fe
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2794>
2023-01-20 15:34:53 +00:00
Carlos Garnacho
e4ee40d7ff compositor: Wrap x11 surface actor destruction in error trap
This does a number of X11 calls. For what it might happen, better
wrap these in error traps.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2793>
2023-01-19 13:57:35 +00:00
Carlos Garnacho
2be5662ee9 compositor: Wrap XDamageCreate call with error trap
I hit this rare error running the "x11" test from the suite locally:

(mutter:194027): Gdk-ERROR **: 18:21:52.525: The program 'mutter' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
  (Details: serial 663 error_code 9 request_code 143 (DAMAGE) minor_code 1)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

The only call from the Damage extension in use by Mutter that could
return BadDrawable is XDamageCreate(), and it's likely to be this
call. Wrap this X11 in an error trap, in order to catch possible
failures.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2793>
2023-01-19 13:57:35 +00:00
Jonas Dreßler
57ce4e04e5 tests/clutter/event-delivery: Flush input thread inside wait_stage_updated()
Flushing the input thread might implicitly iterate the mainloop, and thus
update the stage while still inside the clutter_test_flush_input() call.
This means the stage update has already happened when we call
wait_stage_updated(), and that's why we call clutter_stage_schedule_update()
there currently.

This clutter_stage_schedule_update() call is not necessary though, instead
we can flush the input thread from inside wait_stage_updated() after
setting was_updated to FALSE.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2792>
2023-01-19 13:36:25 +00:00
Carlos Garnacho
909eaa117d core: Delete _MUTTER_NEEDS_FRAME property when destroying frame
If the window is unmapped or otherwise unmanaged while still existing,
we would fail to let the frames client follow up in destroying the
frame for the window.

Delete the _MUTTER_NEEDS_FRAME property, so that the frames client
can react to meta_window_destroy_frame(), this avoids stale invisible
frame windows for clients that simply unmap windows to reuse them
later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2791>
2023-01-18 15:35:58 +01:00
Carlos Garnacho
0fff52ee28 frames: Avoid default NULL frame title
The default GtkWindow title if NULL is set is obtained from g_get_prgname(),
prefer an empty string here.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2791>
2023-01-18 14:17:00 +01:00
Daniel van Vugt
89b254a74b gles3: Ensure missing_extensions is always populated
This appears to be the only explanation for `init_secondary_gpu_data_gpu`
crashing in `g_strjoinv`, but I don't know the exact conditions causing
`glGetString (GL_EXTENSIONS)` to return NULL.

https://launchpad.net/bugs/1994011

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

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

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2576
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2785>
2023-01-17 11:14:19 +01:00
Olivier Fourdan
5be6e7b18e settings: Add Xwayland byte-swapped clients
Recent versions of Xwayland can allow or disallow X11 clients from
different endianess to connect.

Add a setting to configure this feature from mutter, who spawns
Xwayland.

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

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

Fixes: 36f30341ac - wayland: Add a prepare-shutdown signal
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2786>
2023-01-12 14:54:31 +00:00
Carlos Garnacho
78a3631d15 core: Wrap XMapWindow() request with error traps
Other X11 calls happening during the process of assigning a frame
to a window are already wrapped with error traps, wrap this as well
to avoid possible X11 errors.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
2023-01-12 14:07:32 +01:00
Carlos Garnacho
2019536f3c core: Wrap an extra X11 call with error trap
This XChangeWindowAttributes call was never surrounded by an error trap
and was not really expected to fail with BadWindow since the frame window
would be owned by Mutter itself.

This however is no longer true, and we might be getting a BadWindow from
the frame window given the right timing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
2023-01-12 14:00:52 +01:00
Carlos Garnacho
c7b3d8c607 frames: Push error traps around various X11 calls
It is a possibility that these requests result in an error, so handle
the possible fallout.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
2023-01-12 14:00:52 +01:00
Carlos Garnacho
5816268c1d x11: Push error trap reading X11 selection
It is a possibility that this request results in an error, so handle
the possible fallout.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
2023-01-12 14:00:52 +01:00
Carlos Garnacho
8789e1b7d9 x11: Push error trap querying the _MUTTER_FRAME_FOR property
It is a possibility that this request results in an error, so handle the
possible fallout.

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

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

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

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2272
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2399>
2023-01-03 20:45:04 +00:00
Carlos Garnacho
717ee78997 backends/native: Set up keyboard a11y when keyboards are plugged
Commit 4e0ffba5c attempted to fix initialization of keyboard a11y,
but mousekeys do attempt to create a virtual input device at a
time that it is too early to try to create one.

Defer this operation until keyboard devices are added, so that
we are ensured to already have the seat input thread set up.

Fixes: 4e0ffba5c - backends/native: Initialize keyboard a11y on startup
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2778>
2022-12-23 14:51:01 +01:00
Bilal Elmoussaoui
d1d2496c99 core: Replace MetaVirtualModifier
By making all the types uses ClutterModifierType instead.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
8b42bc77dc build: Make GTK dependency specific to X11
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
4d7aedf90a compositor: Drop debug helpers
They can no longer be used as libmutter will drop it gdk/gtk
dependencies in the upcoming commits

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
7e9d9c7eb9 core: Add meta_accelerator_name
As we have switched to using meta_parse_accelerator in PadActionMapper.
We need a function that does the other direction for the client side
usage. See
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/f1d50a4a/js/ui/padOsd.js#L107

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
809eaf6e91 core: Replace gtk_accelerator_parse usage
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
c710f14cc5 core: Replace gtk_get_default_locale usage
Clutter has an API to get the text direction but used to depend
on gtk3's translation domain. In order to avoid broken i18n
in case gtk3 is not installed, move the transtalable string to
clutter itself.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
64ee8d02f7 core: Add a in-tree copy of GtkBorder
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:13:54 +01:00
Bilal Elmoussaoui
b0b21e8274 default-plugin: Remove unnused field
This drops the usage of GdkRGBA

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:09:03 +01:00
Bilal Elmoussaoui
fb4161853f cleanup: Make GDK dependency specific to X11
This way, the dependencies on GTK/GDK could be completely dropped if
built with Wayland only.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2407>
2022-12-22 15:09:03 +01:00
Carlos Garnacho
60e0fe776d backends: Do not require a physical device to update pointer visibility
We may also want to update pointer visibility from emulated events
emitted directly on logical devices, as those we generate from XI_RawMotion
on X11 when the pointer is not over a compositor window.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2344
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2766>
2022-12-19 18:30:34 +01:00
Jonas Ådahl
6adc2e4b59 pointer-lock/wayland: Fix coding style
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 13:17:49 +01:00
Jonas Ådahl
4edcdd8a7f pointer-lock/wayland: Remove unused instance struct field
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 10:00:34 +01:00
Jonas Ådahl
2762a67000 pointer-lock/wayland: Get compositor from surface
This avoids trying to get it from an pointer that was never set to
anything.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2772>
2022-12-18 09:47:29 +01:00
Jonas Ådahl
ca98895185 tests/cogl: Add test checking rgb10 fbo precision
There are two tests; one checks that clearing with a color that cannot
be represented using 8 bits per channel doesn't loose precision when
painted, then read back using glReadPixels(). Would the texture backing
store have 8 bits per channel instead of 10, we'd get a different value
back.

The other test checks that painting from one fbo to another also doesn't
loose that precision.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2461>
2022-12-17 23:12:34 +00:00
Olivier Fourdan
9e8d32980a meta: Move enum definitions to meta-enums.h
Commit bf84b24 created meta-enums.h but it's pretty empty so far, the
vast majority of enum definitions is still in common.h.

Move the Meta enum definitions to meta-enums.h as one would expect them
to be found.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2467>
2022-12-17 22:49:44 +00:00
Jonas Ådahl
ea7175f6b7 tests/wayland: Add test for xdg-foreign
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
2022-12-17 20:38:23 +00:00
Jonas Ådahl
474c093801 tests/wayland-client-utils: Add simple toplevel helper
Add a helper to create a toplevel painted with a given color, size and
title. It's meant to be "dumb" and have a default size, but respect any
configured size.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
2022-12-17 20:38:23 +00:00
Jonas Ådahl
d97c160122 tests/wayland-test-client-utils: Add helper to wait for event
Useful for synchronization.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
2022-12-17 20:38:23 +00:00
Robert Mader
7441d4f8e1 core/selection: Set display on creation
Otherwise the getter always returns `NULL`.

Fixes dd2beae6a8

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2768>
2022-12-17 16:47:46 +01:00
Jonas Ådahl
471d23ba43 Remove meta_get_display()
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
d7f26136b4 later: Remove old API
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
d7f5477103 compositor: Enable introspection
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
7a62e55c54 laters: Turn into GObject
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
4b3cab2cca compositor: Don't make internal API public
Things like meta_compositor_destroy() and meta_compositor_add_window()
isn't intended to be used externally, and if they was, things would
probably fall apart rather quickly.

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

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
6487415e88 Deprecate meta_get_feedback_group_for_display()
Callers should replace with meta_compositor_get_feedback_group().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
2340af8d93 Remove meta_get_backend()
It should be retrieved from the context via an ownership chain.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
aa2a663380 meta: Remove meta_monitor_manager_get()
It has no more users and shouldn't be used.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
82abee5ad7 wayland: Remove meta_wayland_compositor_get_default()
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
f8376a43d3 Always queue MetaLater via compositor instance
The "later" API is used to queue actions in relation to compositing,
thus is owned by the MetaCompositor instance. Make users of this
functionality get MetaLaters instance from the compositor, and stop
using the global meta_later() API.

display: Use non-singleton MetaLater API

tests: Use non-singleton MetaLater API

meta/common: Make docs refer to context aware MetaLater API

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
342c94076d display: Destroy unmanaged compositor a bit later
This allows for things that want to get some state or manager objects
(MetaLaters to be specific) a bit later in the tear down procedures.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
e9cd2b60a6 tests: Make tests components have ownership chains as well
This means we can eliminate the use of scattered singletons that isn't
added by the tests or the test framework itself.

tests: Don't get backend from old singleton getter

Either use the ownership chain, or the explicit test context instance
pointer.

tests/wayland: Pass context to test client constructor

So that we can get the Wayland compositor directly from the context.

tests: Don't get display from singleton

tests/client: Make test client carry a context pointer

tests/runner: Have test cases carry a context pointer

tests/wayland/test-driver: Get backend from context

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
3a1ded73ad x11/session: Make state tracking context aware
Instead of passing around state using GINT_TO_POINTER() pass around a
state struct that also carries a pointer to the context. This allows
avoiding using old singletons for getting a window list.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
1b737190cc x11: Setup and user ownership chains
On the path towards clear ownership chains and always using them to find
other components, do the same for X11 client support paths too.

x11-display: Don't get backend from signleton

x11/selection: Don't get display from singleton

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
e5908f5752 startup-notification/x11: Let the libsn user handle API annoyances
The API has no concept of user data, and requires the user to some how
get an instance without context, i.e. via static globals. Limit this to
the file where this is needed.

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

This also is a squashed commit containing:

compositor: Get backend via the context

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

dnd: Don't get backend from singleton

window-actor: Don't get backend from singleton

dnd: Don't get Wayland compositor via singleton

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

plugins: Don't get backend from singleton

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

feedback-actor: Pass a compositor pointer when constructing

This allows getting to the display.

later: Keep a pointer to the manager object

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 15:13:48 +01:00
Jonas Ådahl
4cc5e6d2bd compositor: Add API to get feedback group
It already had, except it was accessed via the MetaDisplay.

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

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

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

wayland: Don't get Wayland compositor via singleton getter

This means via the ownership chain or equivalent.

xwayland: Hook up manager to Wayland compositor

Same applies to the drag-n-drop struct.

xwayland: Make X11 event handling compositor instance aware

This avoids finding it via singletons in the callee.

xwayland: Don't get Wayland compositor from singleton

xwayland: Pass manager when handling dnd event

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

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

xwayland: Don't get backend from singleton

wayland: Always get the backend from the context

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

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

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

wayland: Don't get display from singleton

xwayland: Don't get display from singleton

tablet: Don't get display from singleton

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

Contains these squashed commits:

display: Don't get backend from singleton

window: Don't get backend from singleton

keybindings: Don't get backend from singleton

workspace: Don't get backend from singleton

display: Don't get Wayland compositor from singleton

selection: Add display getter

context/main: Get backend directly from the context

clipboard-manager: Don't get display from singleton

stack-tracker: Don't use singleton MetaLater API

startup-notification: Hook up sequences and activations to display

This allows using context aware API directly.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
c390f70edc backend: Set up and use ownership chains
This means objects have an owner, where the chain eventually always
leads to a MetaContext. This also means that all objects can find their
way to other object instances via the chain, instead of scattered global
singletons.

This is a squashed commit originally containing the following:

cursor-tracker: Don't get backend from singleton

idle-manager: Don't get backend from singleton

input-device: Pass pointer to backend during construction

The backend is needed during construction to get the wacom database.

input-mapper: Pass backend when constructing

monitor: Don't get backend from singleton

monitor-manager: Get backend directly from monitor manager

remote: Get backend from manager class

For the remote desktop and screen cast implementations, replace getting
the backend from singletons with getting it via the manager classes.

launcher: Pass backend during construction

device-pool: Pass backend during construction

Instead of passing the (maybe null) launcher, pass the backend, and get
the launcher from there. That way we always have a way to some known
context from the device pool.

drm-buffer/gbm: Get backend via device pool

cursor-renderer: Get backend directly from renderer

input-device: Get backend getter

input-settings: Add backend construct property and getter

input-settings/x11: Don't get backend from singleton

renderer: Get backend from renderer itself

seat-impl: Add backend getter

seat/native: Get backend from instance struct

stage-impl: Get backend from stage impl itself

x11/xkb-a11y: Don't get backend from singleton

backend/x11/nested: Don't get Wayland compositor from singleton

crtc: Add backend property

Adding a link to the GPU isn't enough; the virtual CRTCs of virtual
monitors doesn't have one.

cursor-tracker: Don't get display from singleton

remote: Don't get display from singleton

seat: Don't get display from singleton

backend/x11: Don't get display from singleton

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
c45ab10c0e Make VT switch API explicitly part of the native backend
It already was, more or less, but make it a bit more in your face.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
872420f460 monitor-manager: Make config timeout API non-static
While already cleaning up API, if this should ever be more non-static
than a constant, it's better if its a function on the monitor manager
instance than something static.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
71371750d2 clutter/input-device: Remove backend property
It will conflict with a MetaInputDevice property that'll have the same
name.

Wasn't set by the native backend anyway, so probably harmless.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
002a7deddd input-device: Clean up object property setup
Use the more common PROP_0 approach and make the strings static.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
7aa56499ff backend: Sync cursor visibility after startup
When the stage is technically shown depends on when the plugin decides
to do so, so don't rely on it happening when everything is setup.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00
Jonas Ådahl
26dce13c52 x11-display: Remove init GDK method from public APi
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:50 +00:00
Jonas Ådahl
e709853ad3 workspace: Sanity check input to activate*()
The passed argument should be a workspace, and it should not have been
removed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2707>
2022-12-17 13:25:13 +00:00
Jonas Ådahl
9d9fcc0bb1 workspace: Cleanup workspace switch sound function
Expand aggressively abbreviated variable names; some style cleanups.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2707>
2022-12-17 13:25:13 +00:00
Jonas Ådahl
8a64746ce4 workspace: Warn instead of abort on incorrect API usage
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2707>
2022-12-17 13:25:13 +00:00
Carlos Garnacho
4e0ffba5c1 backends/native: Initialize keyboard a11y on startup
The MetaSeatImpl is tracking changes on keyboard a11y setting changes,
but missing its initialization on startup.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1858
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2750>
2022-12-17 12:03:49 +00:00
Carlos Garnacho
d15c6953d8 backends: Distinguish "no EDID" from "any EDID" mapping tablets
Since the Wacom panel rewrite, the "output" setting is handled as
a kind of tri-state for display-integrated tablets:
- If the setting is unset, the device is automatically mapped
  to an output
- If the setting is set and not empty, the device is mapped to
  the output defined by the EDID data
- If the setting is ['', '', ''], the device is mapped to the
  span of all displays, like opaque tablets do.

This distinction for the unset setting fell through the cracks,
so both "Automatic" and "All displays" options were handled as
the former.

Add this distinction, so that display-integrated tablets can
be used like opaque tablets of sorts with no limitations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2767>
2022-12-17 11:31:26 +00:00
Carlos Garnacho
ba25271408 backends: Only apply EDID-based tablet mapping heuristic on integrated devices
These are the ones attached to a display, thus they are the ones that may need
help from this heuristic. Non-integrated tablets (e.g. Intuos) will default to
the span of all monitors.

Fixes mapping of opaque tablets if a display-integrated tablet of the same
brand is also plugged in.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2767>
2022-12-17 11:31:26 +00:00
Sebastian Wick
0d69fabbe6 window: Update mru list for every workspace the window is on
If the window is on all workspaces we should update the mru list for all
those workspaces, otherwise the default focus window for a specific
workspace can be unexpected.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2548
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2747>
2022-12-17 10:39:02 +00:00
Sebastian Wick
058981dc12 workspace: Focus the default window only if no window is focused
This might happen when the workspace is not switched and
focus_default_window is called or when 'workspace on primary display
only' is enabled, a secondary display exists and the workspace is
switched.

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

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

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2519
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2723>
2022-12-17 10:09:37 +00:00
Carlos Garnacho
753c768578 core: Remove redundant ifdef
This code is already surrounded by the same ifdef.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2754>
2022-12-16 20:57:11 +00:00
Carlos Garnacho
02d4a07822 core: Consider ClutterGrabs checking whether windows are interactive
There's 2 users of this, meta_display_sync_wayland_input_focus() which
does already perform these checks on its own, and MetaCursorTracker's
update_displayed_cursor() to determine whether it should go with the
Wayland client's cursor.

This second check should also consider the existing ClutterGrabs, so
make meta_display_windows_are_interactable() handle them for both
callers.

Fixes the cursor shown over windows while e.g. there are menus opened.

Close: https://gitlab.gnome.org/GNOME/mutter/-/issues/2553
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2754>
2022-12-16 20:57:11 +00:00
Robert Mader
f9085b9f58 window-actor/wayland: Return NULL instead FALSE in get_scanout_candidate
Fixes 2933ca9e1c

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2765>
2022-12-16 20:42:45 +01:00
Robert Mader
3d618d5e45 window-actor/wayland: Ignore unmapped subsurfaces in direct scanout check
Clients expect us to ignore them, thus do so. Right now, if the topmost
subsurface is an unmapped subsurface, it will fail the
`meta_surface_actor_is_opaque()` check if it was never mapped before.
Further more, unmapped subsurfaces would wrongly disable our "only one
surface and fullscreen" optimization.

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

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

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

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

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2671>
2022-12-16 16:27:33 +00:00
Robert Mader
04655c8bff feedback-actor: Disable direct scanout during lifetime
We only support feedback-actors, such as DnD-icons, in the compositing
path at the moment.

The approach is similar to how we handle certain shell elements.
Implementations need to ensure no references to the object keep
around longer that necessary.

Arguably this should be replaced by a more robust and implicit actor
hierachy detection in the direct scanout code at some point.

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2677>
2022-12-16 15:25:41 +01:00
Georges Basile Stavracas Neto
abfedcb0c3 screen-cast/src: Fix unsigned integer overflow
The fields of 'priv->video_format.max_framerate' are all of type
uint32_t. Multiplying by G_USEC_PER_SEC can overflow, and equally,
dividing a large numerical type by uint32_t can err too.

Since the variable holding the result is int64_t, cast all uint32_t
fields to int64_t before doing any maths on it.

Spotted while trying to investigating an issue with framerates on
HDMI screencasts.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2762>
2022-12-15 16:51:54 -03:00
Jonas Ådahl
f8fe7dbdd7 tests/screen-cast: Enable 'screen-cast' debug topic
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
7cc10c86e4 screen-cast: Add some debug logging
Will potentially help debugging issues without needing to recompile.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
8b8b06e12e tests/clutter/event-delivery: Flush input thread after events
Otherwise the test becomes flaky, due to events not having ended up on
the main thread yet.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
c3f7bf331c tests/clutter/utils: Add helper to flush input thread
This helps making sure input events we inject have managed to reach the
main thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
489bc65381 tests/utils: Add helper to flush the input thread
Add a helper function that ensures any queued virtual input events have
been flushed from the input thread. This works by posting a task to the
input thread, which will itself queue another callback back to the main
thread. Once the main thread callback is invoked, the flush call is
unblocked and the function returns. Upon this, any previously emitted
virtual input event should have already passed through the input thread
back into the main thread, however not necessarily fully processed.

For making sure it has been processed, one also have to make sure the
stage has been updated, e.g. via `meta_wait_for_paint()`.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
bd72b671fc tests/clutter/event-delivery: Queue update before waiting
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Jonas Ådahl
2d7e5e7671 tests/screen-cast: Add debug logs to screen cast client
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
2022-12-13 18:31:14 +00:00
Carlos Garnacho
425c7652cf frames: Handle lack of WM_DELETE_WINDOW in WM_PROTOCOLS
It is expected that we XKillClient() those clients that do not handle
WM_DELETE_WINDOW messaging. Fixes closing glxgears.

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

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

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

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

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

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
28a3da8d28 wayland/buffer: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
4a2a467b68 wayland/surface: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
2933ca9e1c window-actor: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Robert Mader
bf6e735ef7 compositor-view/native: Add 'render' debug prints
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2680>
2022-12-09 20:14:26 +00:00
Carlos Garnacho
5cfc626bfb x11: Drop unused function
The meta_prop_get_motif_hints() function was only used in the
old MetaUI frames code. The remaining code in mutter accesses
directly the MetaPropValue when loading properties for a window,
and does not use this API call.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2741>
2022-12-09 16:28:33 +00:00
Carlos Garnacho
66b1f43967 Revert "x11: Move Motif WM hints to a separate header"
Since we use XCB in the Mutter side, but Xlib in the frames client,
we cannot share the same struct definition since both libraries
will expect different type lengths (respectively, 32-bit ints vs.
longs).

Revert the changes that made both executables share the same
struct, since not both of them can get it right (and retrieve
correctly the struct with the contained flags) in reading the
Motif WM hints.

This reverts commit 2fb3c5a4f5.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2741>
2022-12-09 16:28:33 +00:00
Georges Basile Stavracas Neto
ac09ce11fd frames: Add CSS class on init
Adding the 'default-decoration' CSS class to MetaFrameHeader after
it is set as the headerbar makes it not account for the minimum size
correctly sometimes. This is a bit racy though - if the window opens
very quickly, it works as expected.

Adding the CSS class before the widget is used guarantees it'll
always report the correct size though, so do that.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2753>
2022-12-09 12:25:07 -03:00
Michael Webster
ec17d19c76 tiling: Remove unnecessary update_edge_constraints().
Both meta_window_maximize and meta_window_tile use
meta_window_maximize_internal(), and edge constraints are already
recalculated and updated there.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2579>
2022-12-05 18:57:20 +00:00
Michael Webster
559e6ff327 tiling: Skip the resize effect for tiled windows during user grabs.
meta_window_tile gets called by the grabbed window's match during
tile resizing. These incremental changes don't need to be animated.

Closes: #2246
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2579>
2022-12-05 18:57:20 +00:00
Georges Basile Stavracas Neto
b1e08f683d frames/window-tracker: Trivial style cleanup
A space of indentation was missing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2740>
2022-12-05 14:20:18 -03:00
Georges Basile Stavracas Neto
62ddea304a frames: Add default-decoration CSS class
Add this CSS class both to the header bar itself, since it is what
actually contains the window controls, and to MetaFrameHeader too,
since it's what's directly attached to the window.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2740>
2022-12-05 14:16:27 -03:00
Georges Basile Stavracas Neto
f7f88c1557 frames/window-tracker: Initialize color scheme properly
Previous commit added support for setting the GTK4 theme setting
according to the color scheme setting. That's cool. What it didn't
add, though, was initializing the GTK4 theme setting to the proper
value. That means if the desktop starts at dark style, you'd still
get a light titlebar.

Fix that by updating the GTK4 theme setting on init as well.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2740>
2022-12-05 14:16:27 -03:00
Georges Basile Stavracas Neto
b3d4dbdbf1 frames/window-tracker: Reinstate dark titlebar support
Merge request !2541 [1] introduced support for integrating Mutter
frames with the dark style. This was lost after moving frames into
a separate client.

Bring that back. Don't depend on gdesktop-enums as it brings GTK3
into the header chain.

[1] https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2541

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2739>
2022-12-05 12:14:54 -03:00
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