Commit Graph

549 Commits

Author SHA1 Message Date
Jonas Ådahl
cc3d30c28b shell: Keep window 'activated' state if child has focus
Popups should have keyboard focus when active, but the toplevel window
should still appear "active". Make sure this is the case by changing the
"active" tracking to see whether any child surface has keyboard focus.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2023-03-30 17:14:29 +00:00
Michael Olbrich
00f08ec79c compositor/text-backend: use xzalloc everywhere
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2023-02-27 16:01:18 +01:00
Derek Foreman
48c93e84e6 desktop-shell: Use weston_coord for saved position
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-24 18:44:19 +00:00
Derek Foreman
59a0bd99bd libweston: Use weston_coord in surface committed handler
I also snuck in a trivial change to drag_surface_configure at the same
time to avoid yet another micro patch.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-24 18:44:19 +00:00
Derek Foreman
5e353d523f libweston: Use weston_coord in struct weston_view
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-24 18:44:19 +00:00
Vinh Nguyen Trong
a1b7f1a5a2 desktop-shell: Fade animation should base on output power state
When compositor is active, we cannot make sure that the output power
state is normal, if the output power was forced off, there is nothing can
display on the output. Therefore, only do fade animations when the output
power state is normal

Signed-off-by: Vinh Nguyen Trong <Vinh.NguyenTrong@vn.bosch.com>
2023-02-23 11:44:30 +00:00
Michael Olbrich
06365e602b desktop-shell: avoid crashes when a surface disappears during resize
The desktop_surface object is destroyed first so it can happen that the shsurf
still exists but desktop_surface is already NULL. So expand the check to make
sure the desktop_surface is still available in the resize callbacks.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2023-02-20 12:48:43 +02:00
Derek Foreman
583fbcda3b libweston: Use weston_coord in struct weston_pointer
Convert the bare x,y coordinates into struct weston_coord and update all
users.

We keep the surface position in wl_fixed_t for now so it still exactly
matches the position most recently sent to clients.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-17 13:51:23 +00:00
Derek Foreman
c3cd8306c9 libweston: Pass weston_coords to weston_compositor_pick_view
Continuing to convert things to weston_coord.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-17 13:51:23 +00:00
Leandro Ribeiro
831e36c7d9 Revert "desktop-shell: avoid alternating surface between outputs"
This reverts commit 4eea291512.

There were some details and cases that I've missed when writing this
commit, resulting in some weird behaviors. Trying to cover all of them
became a nightmare, and the function got really hard to read.

So it's better to revert this commit and think about other possible
solutions for the issue.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-02-14 13:09:36 +00:00
Leandro Ribeiro
ba82af938a desktop-shell: do not forget to reset pending config size after resizes
During interactive resizes, we progressively change the size of the
client surface and send config events with these sizes to the client.
After that, the toplevel->pending.size keeps the size of the last config
event that we've sent, i.e. the surface size after the resize is over.

Later, if the client spontaneously resize (by attaching a buffer with a
different size or setting the viewport destination, for instance), their
surface size will change, but toplevel->pending.size continues being
that old size from after the resize. If something happens and Weston
decides to send a config event, clients may re-allocate to that old
size, resulting in a sudden resize.

This does not happen when a client goes from fullscreen/maximized to
windowed mode because in such cases we are resetting
toplevel->pending.size to zero. So in the next config event that clients
receive they are allowed to attach buffers with the size that they
prefer.

So do the same after a resize: set the pending config size to zero.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-02-07 09:59:16 +00:00
Tran Ba Khang(MS/EMC31-XC)
776fafe13a libweston/desktop: committed when transiting from valid to invalid buffer
Every shells have an implementation of weston_desktop_api structures.
It includes some callbacks to listen to xdg_surface signals. Committed callback
is one of them.

Currently, the xdg_shell don't invoke the weston_desktop_api->committed
callback when the xdg_surface is initial stage or no surface content.

In the case: the client attached a null buffer after the valid buffer,
the shell isn't going to invoke to xdg_surface committed, and don't know
the surface is disappeared. If the surface is fullscreen, we will get
a black background on the screen until a new valid frame come. That
should not happen.

Signed-off-by: Tran Ba Khang(MS/EMC31-XC) <Khang.TranBa@vn.bosch.com>
2023-02-02 11:05:19 +02:00
Derek Foreman
64d9270804 libweston: Use weston_coord space conversion functions
Update users of the old coordinate space conversion functions that take
x, y pairs to the new weston_coord versions.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-01 07:27:05 -06:00
Leandro Ribeiro
4eea291512 desktop-shell: avoid alternating surface between outputs
In commit d611ab24fd "libweston: Update
view transforms more often", a call to weston_view_update_transform()
was introduced to desktop_surface_committed(). It was added between the
point in which we call unset_fullscreen() and
shell_configure_fullscreen(), right after the view geometry dirty bit is
set.

There's a scenario with dual displays in which this change resulted in
the surface being alternated between two outputs:

---

Dual display configuration:

    1st display: DP1, with scale 1 - origin 0, 0
    2nd display: DP2, with scale 2 - origin 1920, 0

We start the app with the cursor on DP2. Function
desktop_surface_committed() gets called a few times, and it ends up
setting shsurf->saved_x and shsurf->saved_y to the origin of DP2.

Application wants to become fullscreen on DP1, so when the surface gets
committed again and desktop_surface_committed() gets called, we have the
following sequence:

desktop_surface_committed():

        was_fullscreen = shsurf->state.fullscreen
        is_fullscreen = weston_desktop_surface_get_fullscreen()

        if (!weston_surface_is_mapped(desktop_surf))
                map(shell, desktop_surf)
                return;

        /* POINT A, this is important for understanding the issue. */
        if (shsurf size didn't change and
            fullscreen state didn't change)
                return;

        if (was_fullscreen)
                /* This function calls weston_view_set_pos(saved_x,
                 * saved_y), and the saved position is the origin of
                 * DP2. Then it invalidates the saved position */
                unset_fullscreen(shsurf)

        if (is_fullscreen && !shsurf->saved_position_valid)
                /* Saves the position (as it just have been
                 * invalidated), which will be the origin of DP2
                 * again. */
                shsurf->saved_x = shsurf->view->geometry.x
                shsurf->saved_y = shsurf->view->geometry.y
                shsurf->saved_position_valid = true

        /* This function calls weston_view_assign_output(), which then
         * calls weston_surface_assign_output(). The effect of these two
         * functions is that the view gets assigned to an output, and to
         * choose the output it takes into consideration the position in
         * which it is and the area that it occupies on the output. As
         * the view has been moved to the origin of DP2, it gets
         * assigned to this output. Then Weston sends the enter/leave
         * surface events. */
        weston_view_update_transform()

        if (is_fullscreen)
                /* This function positions the view on DP1, because
                 * that's the output in which the wine app wants to
                 * become fullscreen. */
                shell_configure_fullscreen(shsurf)

        /* Now we call weston_view_update_transform() again to each view
         * of the surface, and so we end up sending enter/leave surface
         * events. But notice that now we are positioned on DP1. */
        wl_list_for_each(view, &surface->views, surface_link)
                weston_view_update_transform(view);

The next time the surface gets committed and desktop_surface_committed()
gets called, the same sequence will happen. So we'll continue in this
weird loop.

The reason why the surface size changes and we don't return in POINT A
in this scenario is because the application uses a viewport, and then
when its surface moves to the output with scale 2 it sets the surface
size to half its size. That happens for apps that want to keep a
reasonable DPI on scaled displays.

This only happens after the change that introduced the call to
weston_view_update_transform() in this function. Without this call we'd
not reposition the view on DP2 and send enter/leave events at that
point.

---

So in order to avoid that, be more careful before calling
unset_fullscreen() and then shell_configure_fullscreen(). Only do that
when:

  - the surface was not fullscreen, and now it becomes.
  - the surface was fullscreen, but now it becomes fullscreen on a
    different output.

In order to be consistent, do something similar to the maximized state.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-01-31 19:22:45 +00:00
Marius Vlad
6293ab1f90 libweston, shared: Move out weston_shell_get_binding_modifier
This doesn't really belong into shell-utils,  so better move it out to
shared/config-parser. Renamed to weston_config_get_binding_modifier
to maintain the same namespace.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-01-09 22:13:07 +00:00
Marius Vlad
19d32da742 shell-utils: Integrate shell-utils into libweston
These shell utils functions are potentially useful to other shells as
well, so make them widely available.

Renamed all functions to weston_shell_utils namespace.

No functional change, copied ad litteram.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-01-09 22:13:07 +00:00
Derek Foreman
71cf2783d6 desktop-shell: Fix stuck panel
Ever since d611ab24 the panel surface's frame callback gets lost and the
panel stops updating after its first draw.

Fix this by dirtying the geometry in configure_static_view() after it
changes the layer list, since the layer list is considered part of
geometry.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-12-01 09:34:17 +00:00
Derek Foreman
061c2b7382 desktop-shell: Update view transform when resizing windows
After commit 2dc8680d71 this started crashing. We need to update the
view transform here too.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-24 15:59:26 -06:00
Derek Foreman
d611ab24fd libweston: Update view transforms more often
These places all eventually lead to calling weston_view_to_global_float()
or weston_view_from_global_float() on a view with a dirty transform.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-14 16:05:46 -06:00
Marius Vlad
bf0c99f519 libweston/desktop, desktop-shell: Add getters for pending state
This introduces a few getters to retrieve the pending state from
libweston-desktop, now just libweston, and makes use of it,
specifically get_pending_maximized to avoid sending invalid
dimensions to the client in the particular use case
set_maximized/unset_fullscreen.

These pending state getters are useful to query/poke a not-applied
yet state, and could be useful where we don't have a buffer attached
where the client might be set-up as maximized, but internally libweston
hasn't yet applied that pending state.

Fixes #645

Suggested-by: Morgane Glidic <sardemff7+git@sardemff7.net>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 13:06:07 +02:00
Derek Foreman
4d141a7881 libweston: Don't return coordinates from weston_compositor_pick_view
Sometimes callers don't want them, and sometimes (when view is NULL) the
coordinate is invalid.

Waste a tiny bit of time calculating them as needed in the callers
instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-02 10:25:15 +00:00
Derek Foreman
eed00f679e input: Don't pass surface coordinates to weston_pointer_set_focus
We're always passing pointer->x, y converted to surface coordinates, or
garbage if view is NULL. Let's just stop passing those coordinates
entirely and calculate them in the function.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-02 10:25:15 +00:00
Derek Foreman
fe0292d272 desktop-shell: Use the current pointer location for grab start
0, 0 doesn't make much sense, since we're not warping the cursor.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-02 10:25:15 +00:00
Derek Foreman
bb8ef7d271 libweston: Refactor point in output test
This is arguably a little nicer without calling the pixman functions
directly.

In the future when we have different datatypes for coordinates in different
spaces, this test will only be valid on global coordinates, so this change
is also a precursor to stronger type validation.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 12:08:34 +00:00
Derek Foreman
e5e9980391 desktop-shell: Remove unused params from internal map() function
We don't use these.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:57:57 +00:00
Marius Vlad
1b4def3c48 libweston/desktop: Migrate libweston-desktop/libweston-desktop.h
With commit 'Move libweston-desktop into libweston' we've moved out
libweston-desktop DSO into libweston.  Move also the header to
libweston/desktop.

This removes removes the libweston-desktop pc file and bumps libweston
major version to 12.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-09-23 13:57:26 +03:00
Marius Vlad
c33e8d2c10 desktop-shell: Handle tiled orientation in various circumstances
This properly handles transition states to, and from, maximized,
fullscreen, surface movement and resizing.

Specifically for surface movement and resizing we unset any
(previously set) tiled information we might have. The same happens for
maximized and fullscreen but additionally we attempt re-install the
orientation if we had one previously.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-08-09 13:36:43 +03:00
Marius Vlad
5bcbe92d51 desktops-shell: Add tiled orientation support using key-bindings
Patch adds KEY_UP/KEY_DOWN for tiled top and bottom positioning,
KEY_LEFT/KEY_RIGHT correspondingly, for left and right positioning.

It also modifies the man page to include these new bindings, But also with
commit 'compositor: Remove desktop zoom' we no longer have zoom effects
so removed them.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-08-09 13:36:43 +03:00
Marius Vlad
478b24cae0 desktops-shell: Re-use helper for modifier retrieval
As we now have a helper to retrieve the binding modifier, use it
in desktop-shell as well.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-08-08 14:22:31 +00:00
Marius Vlad
f9e52eb0d7 desktop-shell: Always update the shsurf's output to that of the view
In case shsurfs are migrated/moved or started on different outputs other
than the default one, it causes fullscreen views to never being demoted
to a lower stacking level, due to the fact we never update
the view's output whenever that has changed.

Synchronize the desktop shell output's with the view's output in the
transform_handler.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2022-08-01 15:35:00 +03:00
Derek Foreman
d615abdffd shells: Add libweston-desktop API to query position and add to shells
We're going to need this to properly send xwayland events later, so add
API to get the current x,y co-ordinates of a shell surface and add it to
the kiosk and desktop shells.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-29 11:44:48 +00:00
Daniel Stone
9336263d9b Move libweston-desktop into libweston
It's not really useful to have libweston without libweston-desktop. It's
also very little code.

Merging both into the same DSO will allow us to cut out a bunch of
indirection and pain.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-28 10:35:52 +00:00
Daniel Stone
61d8238874 desktop-shell: Remove multiple workspace support
It's not the most code ever, but it does make desktop-shell somewhat
more complicated for questionable (i.e. no) end-user benefit.

When desktop-shell is back in more healthy shape it could potentially be
reintroduced, but for now it's just making it more difficult to reason
about desktop-shell and fix it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-24 10:47:42 +03:00
Daniel Stone
af7dcdddac desktop-shell: Map surfaces in map()
The only caller of map() then manually sets is_mapped = true. Just do it
in the function which makes you think that's what it would do.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-16 12:17:15 +03:00
Daniel Stone
0c69688aa2 libweston: Add weston_surface_map() wrapper
Change all instances of surface->is_mapped = true, to a specialised
function.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-16 12:17:15 +03:00
Daniel Stone
888d08d8a5 desktop-shell: Use weston_surface_has_content()
Now we've got a wrapper which can tell us whether or not a surface has
content, use it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-16 12:17:15 +03:00
Marius Vlad
2327daf96b desktop-shell: Handle weston_curtain destruction
This fixes the following leaks for
weston_curtain/weston_buffer_create_solid_rgba when shutting down the
compositor:

        #0 0x7f9170372987 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x7f915bfeb8b7 in zalloc ../include/libweston/zalloc.h:38
        #2 0x7f915bfec71d in weston_curtain_create ../shell-utils/shell-utils.c:150
        #3 0x7f915bfd9e51 in shell_ensure_fullscreen_black_view ../desktop-shell/shell.c:2082
        #4 0x7f915bfda2a9 in shell_configure_fullscreen ../desktop-shell/shell.c:2118
        #5 0x7f915bfdc72d in desktop_surface_committed ../desktop-shell/shell.c:2538
        #6 0x7f915bfa3ef5 in weston_desktop_api_committed ../libweston-desktop/libweston-desktop.c:159
        #7 0x7f915bfae778 in weston_desktop_xdg_toplevel_committed ../libweston-desktop/xdg-shell.c:746
        #8 0x7f915bfb0d45 in weston_desktop_xdg_surface_committed ../libweston-desktop/xdg-shell.c:1374
        #9 0x7f915bfa7382 in weston_desktop_surface_surface_committed ../libweston-desktop/surface.c:174
        #10 0x7f916fe628a6 in wl_signal_emit /home/mvlad/install-amd64/include/wayland-server-core.h:481
        #11 0x7f916fe7c0e2 in weston_surface_commit_state ../libweston/compositor.c:4062
        #12 0x7f916fe7c161 in weston_surface_commit ../libweston/compositor.c:4068
        #13 0x7f916fe7c6ef in surface_commit ../libweston/compositor.c:4146
        #14 0x7f916fc847e9  (/usr/lib/x86_64-linux-gnu/libffi.so.8+0x77e9)

        #0 0x7f9170372987 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x7f916fe62aa3 in zalloc ../include/libweston/zalloc.h:38
        #2 0x7f916fe7398d in weston_buffer_create_solid_rgba ../libweston/compositor.c:2603
        #3 0x7f915bfec879 in weston_curtain_create ../shell-utils/shell-utils.c:162
        #4 0x7f915bfd9e51 in shell_ensure_fullscreen_black_view ../desktop-shell/shell.c:2082
        #5 0x7f915bfda2a9 in shell_configure_fullscreen ../desktop-shell/shell.c:2118
        #6 0x7f915bfdc72d in desktop_surface_committed ../desktop-shell/shell.c:2538
        #7 0x7f915bfa3ef5 in weston_desktop_api_committed ../libweston-desktop/libweston-desktop.c:159
        #8 0x7f915bfae778 in weston_desktop_xdg_toplevel_committed ../libweston-desktop/xdg-shell.c:746
        #9 0x7f915bfb0d45 in weston_desktop_xdg_surface_committed ../libweston-desktop/xdg-shell.c:1374
        #10 0x7f915bfa7382 in weston_desktop_surface_surface_committed ../libweston-desktop/surface.c:174
        #11 0x7f916fe628a6 in wl_signal_emit /home/mvlad/install-amd64/include/wayland-server-core.h:481
        #12 0x7f916fe7c0e2 in weston_surface_commit_state ../libweston/compositor.c:4062
        #13 0x7f916fe7c161 in weston_surface_commit ../libweston/compositor.c:4068
        #14 0x7f916fe7c6ef in surface_commit ../libweston/compositor.c:4146
        #15 0x7f916fc847e9  (/usr/lib/x86_64-linux-gnu/libffi.so.8+0x77e9)

We do not migrate the weston_curtain destruction from
desktop_surface_removed() to desktop_shell_destroy_surface() because
we'd want have the curtain removed before the animation starts.

If we were to move the black view destruction, *and* only handle it from
desktop_shell_destroy_surface() the animation runs but the black curtain
will be removed right at the end, effectively diminishing the effect of
the animations.

To this end, we keep both of the two worlds, if the client terminates on
its own, we keep the same animation effect, but if the compositor is
shutting down we destroy it immediately.

We remove wl_list_for_each_safe() and instead loop each time to avoid
using a stale pointer iterator which could cause a UAF as the shsurf
would be free'ed.

Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-18 09:46:37 +03:00
Marius Vlad
ab42159bf3 desktop-shell: Add missing weston_view_destroy()
This fixes the following weston_view leak at compositor shutdown:

    #0 0x7f4250247987 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f424fd37aa3 in zalloc ../include/libweston/zalloc.h:38
    #2 0x7f424fd3a05f in weston_view_create ../libweston/compositor.c:386
    #3 0x7f423be7be6a in weston_desktop_surface_create_desktop_view ../libweston-desktop/surface.c:364
    #4 0x7f423be7c0a8 in weston_desktop_surface_create_view ../libweston-desktop/surface.c:404
    #5 0x7f423beae91d in desktop_surface_added ../desktop-shell/shell.c:2273
    #6 0x7f423be77db1 in weston_desktop_api_surface_added ../libweston-desktop/libweston-desktop.c:138
    #7 0x7f423be80c73 in weston_desktop_xdg_toplevel_ensure_added ../libweston-desktop/xdg-shell.c:362
    #8 0x7f423be8207a in weston_desktop_xdg_toplevel_committed ../libweston-desktop/xdg-shell.c:697
    #9 0x7f423be84d45 in weston_desktop_xdg_surface_committed ../libweston-desktop/xdg-shell.c:1374
    #10 0x7f423be7b382 in weston_desktop_surface_surface_committed ../libweston-desktop/surface.c:174
    #11 0x7f424fd378a6 in wl_signal_emit /home/mvlad/install-amd64/include/wayland-server-core.h:481
    #12 0x7f424fd510e2 in weston_surface_commit_state ../libweston/compositor.c:4062
    #13 0x7f424fd51161 in weston_surface_commit ../libweston/compositor.c:4068
    #14 0x7f424fd516ef in surface_commit ../libweston/compositor.c:4146
    #15 0x7f424fb597e9  (/usr/lib/x86_64-linux-gnu/libffi.so.8+0x77e9)

With commit 'libweston, desktop-shell: Add a wrapper for weston_surface
reference' we've removed an explicit weston_view_destroy() call due to a
UAF which would've happen if we had close animations enabled, upon
terminating a client. In that patch I've incorrectly wrote this happened
when animations are off, but in fact it happened when they're on, see the
following trace:

READ of size 8 at 0x616000026498 thread T0
    #0 0x7f757fba8797 in weston_signal_emit_mutable ../shared/signal.c:52
    #1 0x7f757fb4bba1 in weston_view_destroy ../libweston/compositor.c:2269
    #2 0x7f756bca89c0 in desktop_shell_destroy_surface ../desktop-shell/shell.c:275
    #3 0x7f756bcb379e in fade_out_done_idle_cb ../desktop-shell/shell.c:2228
    #4 0x7f757faec1da in wl_event_loop_dispatch_idle ../src/event-loop.c:969
    #5 0x7f757faec31d in wl_event_loop_dispatch ../src/event-loop.c:1032
    #6 0x7f757faea114 in wl_display_run ../src/wayland-server.c:1408
    #7 0x7f757ff777ba in wet_main ../compositor/main.c:3589
    #8 0x55f765c8d17d in main ../compositor/executable.c:33
    #9 0x7f757fd997fc in __libc_start_main ../csu/libc-start.c:332
    #10 0x55f765c8d099 in _start (/home/mvlad/install-amd64/bin/weston+0x1099)

0x616000026498 is located 24 bytes inside of 608-byte region [0x616000026480,0x6160000266e0)
freed by thread T0 here:
    #0 0x7f758004c4d7 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x7f757fb4bdc8 in weston_view_destroy ../libweston/compositor.c:2295
    #2 0x7f757fb4c14d in weston_surface_unref ../libweston/compositor.c:2334
    #3 0x7f756bca898b in desktop_shell_destroy_surface ../desktop-shell/shell.c:273
    #4 0x7f756bcb379e in fade_out_done_idle_cb ../desktop-shell/shell.c:2228
    #5 0x7f757faec1da in wl_event_loop_dispatch_idle ../src/event-loop.c:969

This patch re-introduces it to avoid leaking the view upon compositor
shutdown, but it does it in tandem with weston_desktop_surface_unlink_view(),
(which was added in a later patch) and before weston_surface_unref() call.

This way we should be safe to terminate/close  clients with additional views
created by libweston-desktop (pop-ups), but also in other different situations.

Verified it in the following circumstances:

- terminating a client with close animation on
- terminating a client with close animations off
- shutting down the compositor with clients running, with and
  without close animations
- terminating top-level clients with additional pop-ups with both with
  and without close animations

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-16 08:59:11 +00:00
Derek Foreman
db06aea171 desktop-shell: Check height instead of checking width a second time
Fix an apparent copy and paste error in resize code. I'm not sure anything
sets the relevant callback that would lead to height being different than
width, so there's no easy way to demonstrate a bug, but this change
appears to rectify the intent of the code.

Reported-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-05-13 08:17:02 -05:00
Marius Vlad
299f87f073 desktop-shell: Clarify weston_view destruction at tear down
This documents the fact that other views are handled implictly by
libweston-desktop, and we shouldn't attempt to destroy indiscriminately
views that aren't created by desktop-shell.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:55 +03:00
Marius Vlad
d03f01377a desktop-shell: Check for a valid desktop_surface
This patch fixes the following trace:

    #0 0x7f07d1bcecfa in weston_desktop_surface_get_surface ../libweston-desktop/surface.c:585
    #1 0x7f07d1bfc9b8 in move_grab_motion ../desktop-shell/shell.c:1499
    #2 0x7f07e539f841 in notify_motion ../libweston/input.c:1794
    #3 0x7f07e1e8ace4 in handle_pointer_motion ../libweston/libinput-device.c:132
    #4 0x7f07e1e8cad5 in evdev_device_process_event ../libweston/libinput-device.c:535
    #5 0x7f07e1e89311 in udev_input_process_event ../libweston/libinput-seat.c:208
    #6 0x7f07e1e8932f in process_event ../libweston/libinput-seat.c:218
    #7 0x7f07e1e8935f in process_events ../libweston/libinput-seat.c:228
    #8 0x7f07e1e8940a in udev_input_dispatch ../libweston/libinput-seat.c:239
    #9 0x7f07e1e89437 in libinput_source_dispatch ../libweston/libinput-seat.c:249
    #10 0x7f07e53122b1 in wl_event_loop_dispatch ../src/event-loop.c:1027
    #11 0x7f07e5310114 in wl_display_run ../src/wayland-server.c:1408
    #12 0x7f07e579c7ba in wet_main ../compositor/main.c:3589
    #13 0x555611d6b17d in main ../compositor/executable.c:33
    #14 0x7f07e55be7fc in __libc_start_main ../csu/libc-start.c:332
    #15 0x555611d6b099 in _start (/home/mvlad/install-amd64/bin/weston+0x1099)

A highly unlikely, but still valid operation, is to close/destroy the
window while still having it grabbed and moved around, basically having
an in-flight destruction of grabbed moving window. Another situation
would be that the client terminates abruptly (crashing for instance),
while being dragged which might take down the compositor.

This could happen for both touch/pointer grab operations and could cause
a NULL pointer access while accessing desktop_surface when being used
to retrieve the underlying weston_surface.

With this patch we check for a valid desktop_surface and return early
if that's not the case.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:55 +03:00
Marius Vlad
c41cdcabb4 desktop-shell: Migrate surface_unlink_view
Moving weston_desktop_surface_unlink_view() to
desktop_shell_destroy_surface() makes sure we don't leak the underlying
weston_desktop_view when tearing/shutting down the compositor.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:55 +03:00
Marius Vlad
be5b6f9cdc desktop-shell: Rename destroy_layer functions
No functional change. Makes it obvious that we also call
weston_layer_fini().

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:55 +03:00
Marius Vlad
9cf602840d desktop-shell: Create a distinct view for the fade-out close anim
Creates a distinct view, separated from the one created by
libweston-desktop, in order to avoid a potential ownership fight with
libweston-desktop upon destroying the view. Upon weston_desktop_surface
destruction, libweston-desktop inflicts damage on the view it creates,
so we need the view to be alive at that time.

This wasn't such an issue before because we had different destruction paths but
with commit 'desktop-shell: Do not leave views in layers upon shell
destruction' all of the destruction paths now land in the same spot
+ handle compositor tear down.

Note as we still use the same weston_surface we'll keep the previous
construct where we were taking a reference to keep it alive.

The original view is destroyed when releasing the ownership, while for
the view created in this patch we handle the destruction directly upon
compositor tear down.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:55 +03:00
Marius Vlad
bd8314078d libweston, desktop-shell: Add a wrapper for weston_surface reference
Similar to how we do it with drm_fb ref counts, increase a reference
count and return the same object.

Plug-in in desktop-shell when we map up the view in order to survive a
weston_surface destruction.

Astute readers will notice that this patch removes weston_view_destroy()
while keeping the balance between removing and adding a
weston_surface_unref() call in desktop_shell_destroy_surface().

The reason is to let weston_surface_unref() handle destruction on its
own. If multiple references are taken, then weston_surface_unref()
doesn't destroy the view, it just decreases the reference, with
a latter call to weston_surface_unref() to determine if the view
should be destroyed as well.  This situation happens if we have
close animation enabled, were we have more than one reference taken: one
when mapping the view/surface and when when the surface itself was created,
(what we call, a weak reference).

If only a single reference is taken (for instance if we don't have close
animations enabled) then this weston_surface_unref()
call is inert as that reference is not set-up, leaving libweston to
handle the view destruction.

Following that with a weston_view_destroy() explicit call would cause a
UAF as the view was previous destroyed by a weston_surface_unref() call.

A side-effect of not keeping the weston_view_destroy() call would
happen when tearing down the compositor. If close animations are enabled,
weston_surface_unref() would not destroy the view, and because
weston_view_destroy() no longer exists, we would still have the
view in the other layers by the time we check-up if layers
have views present.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:53:34 +03:00
Marius Vlad
0d8e94af61 libweston: Rename weston_surface_destroy() to weston_surface_unref()
Make it obvious that weston_surface has a reference counting happening
and destruction of the weston_surface happens when the last
weston_surface reference has been accounted for.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-12 16:46:31 +03:00
Marius Vlad
70353dace3 desktop-shell: Refuse to set a surface to maximized
For a surface that is already fullscreen making it maximized means to
exit fullscreen then set to it maximized. Instead of doing it, refuse to
do anything until the user explicitly performs that operation.

With this approach we follow other DE (desktop environments) which would
not perform any operation until the user exits fullscreen state.

Fixes #321

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-10 12:13:28 +00:00
Daniel Stone
06472fb136 desktop-shell: Delete Exposay
Exposay was done as a showcase for what we could do with Weston and an
efficient compositing pipeline. This was mostly with the old
vendor-specific Raspberry Pi backend which could actually process that
many surfaces bypassing the GPU.

Given enough bitrot, Exposay is now pretty exemplary as what _not_ to do
in a Weston shell - particularly the way it manipulates existing
weston_views rather than create its own non-destructive stack.

As it's annoying technical debt, a terrible example to others, and not a
very compelling showcase in 2022, just delete it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-28 15:19:06 +00:00
Marius Vlad
509398dc25 desktop-shell: Avoid spurious configure events for xdg-shell activation
This is a minor re-work of how we de-activate and activate the surfaces
in desktop-shell. As activate() is being used for handling keyboard
input events, this basically rectifies that such that  activation
happens only if the passed surface is different from the currently
focused surface.

Fixes: #593

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-04-26 15:59:29 +00:00
Derek Foreman
ca979aa219 desktop-shell: Fix incorrect use of black_surface_get_label
By some dark magic this accidentally doesn't crash because there are
zeroes in the right places at startup, but black_surface_get_label()
very much expects surface_private to be a view.

Let's hand craft a new bespoke label function for this use.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-04-14 07:39:25 +00:00
Daniel Stone
6cb2526b67 Move shell-utils to its own directory
shell-utils contains a number of helpers which are currently in use by
both desktop-shell and kiosk-shell. In order to extend this use to
fullscreen-shell as well (which can benefit from reusing the
weston_curtain infrastructure to be able to create solid-colour views
which may or may not be opaque, as well as one function within
fullscreen-shell which was copied wholesale to shell-utils), we need to
create a separate Meson dependency object, and avoid the existing
pattern of including the source from shared/ within the source list for
each shell.

This requires creating a new top-level directory for these shared helper
functions which are required by each shell, but are not part of
libweston in and of itself.

shell-utils depends on libweston-desktop; libweston-desktop depends on
libweston; libweston depends on shared.

Thus it is not possible to expose a dependency object from the shared/
directory which declares a dependency on the libweston-desktop
dependency, as Meson processes directories in order and resolves
variable references as they are parsed.

In order to break this deadlock, this commit creates a new top-level
directory called 'shell-utils' containing only this file, which can be
parsed by Meson after libweston-desktop (making the libweston-desktop
Meson dependency variable available to the build file to declare a
dependency on that), but before the shells (making the new Meson
depenendency object available to each shell which wishes to use it).

This commit contains no functional changes to any observable code.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
15a553053a desktop-shell: Reuse curtains for fades
Use the common infrastructure we have, rather than open-coding again.

In changing to the common weston_curtain infrastructure which was
introduced in a previous commit, there are two small functional
derivations.

After adding the view to a layer, we explicitly call
weston_view_geometry_dirty(). This is believed to have no functional
impact, as weston_views have their geometry-dirty flag set when they are
created.

weston_surface_damage() is also called to ensure that the surface is
scheduled for a repaint. As there is currently no good common mechanic
in the common code to ensure that output repaint will occur, due to the
damage propagating outwards from the weston_surface, we are forced to
call this to predictably ensure that the output will be repainted after
we have made this change to the scene graph which should result in the
user observing the new content being repainted.

It is possible that these changes are not strictly required in order for
the correct behaviour to occur. However, it is felt that explicitly
adding these calls is perhaps the least fragile way to ensure that the
behaviour continues to be correct and breakage is not observed,
especially with both view mapping and surface damage identified as areas
for future work which could be beneficial to Weston. If it is felt that
these calls can be removed, then this is certainly possible at a later
stage.

Lastly, there are many users within desktop-shell of the common pattern
of creating a weston_curtain and inserting it into the scene graph to be
painted. These users have been an area of both theoretical concern and
real-life observed fragility and breakage recently. By making each user
follow a common and predictable pattern of usage, each user is no longer
its own special case. This should make it easier to make the
desktop-shell codebase more robust, not only simplifying the codebase,
but improving observed behaviour.

In doing this, it is hoped that future structural and interface changes
become easier to make, allowing us to improve some of the more difficult
corners of the libweston API.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
dc0f73bcac shell: Encapsulate weston_curtain in its own struct
This will allow us to create a solid weston_buffer as well, since we
need to store that separately.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
e031397e09 desktop-shell: Reuse curtains for focus animations
Just as we do for fullscreen backgrounds, reuse the curtain infrastructure
for focus animations.

This introduces a small functional change, in that the surface's output
is no longer directly assigned. Instead, we call
weston_view_set_output() ourselves. As setting the weston_view's
position (done from the common helper function of weston_curtain_create
which has been introduced in previous commits) will call
weston_view_set_position(), the view's geometry will be dirtied as a
result.

When the geometry of a weston_view is dirty, it is marked to be updated,
which will occur whilst traversing the view list during output repaint.
This occurs for every view which is currently assigned to a layer; when
building the view list, any view reachable through the view list whose
geometry is dirty will have its position recalculated and an output
assigned. Doing so results in the surface's current output being
updated.

It is believed that there is no functional impact from the
weston_surface not having a primary output assigned between creation and
output repaint being called.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
bd9b0676dd shell: Make input capture optional for curtains
desktop-shell's focus surfaces want to reuse this, but they don't want
to capture the input, instead allowing it to fall through.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
64ef87554b desktop-shell: Clean up fullscreen black view code
Rationalise it a little bit so we don't need pre-declarations of static
functions, and the order of creation more closely matches the others,
including making the same calls to explicitly set the output.

Doing this makes the behaviour match the other users of the same code
pattern. In making them the same, we make desktop-shell code a little
less magically divergent where people might wonder what the correct
pattern is to use. After we have moved all users to a uniform pattern,
later commits are then able to migrate these users to common helper
code, which reduces code duplication, improves code clarity as it is no
longer necessary to wonder about the exact semantics of every
special-case user of this common pattern, and makes it easier to make
interface changes which improve and clarify the patterns which are
prevalent throughout the desktop-shell code.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
de0cd53264 desktop-shell: Remove redundant geometry dirty call
Dirtying the geometry only sets a flag on the view saying that the
geometry is dirty, so we don't need to do it twice back-to-back.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
791e8b1c5f desktop-shell: Fix opaque region co-ordinate confusion
Opaque regions are in surface co-ordinate space, not global co-ordinate
space, so the region should be anchored to (0,0).

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
e81b8d7cc9 shell: Add alpha to weston_curtain_create
Not all solid-colour views want to be opaque: sometimes we use them with
non-opaque alpha values in order to shade views underneath them.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
d21563360a shell: Move weston_curtain_create params into the struct
Given that we have a struct for argument params, we might as well use it
rather than have them split between the struct and native params. For
consistency between the implementations, this also includes a shift from
float to int positioning for the base offset within the compositor's
global co-ordinate space.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
3a298b0b05 shell: Rename weston_solid_color_surface to weston_curtain_params
The name implied that it was a surface in and of itself, rather than
parameters used by a helper to create a surface and view.

Rename it now that we have weston_curtain as a name, and clean up
initialisers.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
b77c2374ee shell: Rename solid_color_surface to weston_curtain
create_solid_color_surface actually returns a weston_view that it
creates internally. Since weston_solid_color_view is long and dull,
rename it to weston_curtain.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Daniel Stone
7059ec7807 desktop-shell: Explicitly destroy black views on shutdown
desktop_shell_removed() won't get called when we shut down, so
explicitly destroy the fullscreen black view.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-03-31 17:15:55 +00:00
Marius Vlad
d40cedc8af desktop-shell: Remove wl_shell_surface::resize enum
And use the ones provided by libweston-desktop, as they are one
and the same.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-03-08 15:12:56 +02:00
Derek Foreman
66374d48f1 compositor: Remove desktop zoom
Zoom is a neat trick, but in its current form it's very hard to test
and maintain.

It also causes output damage to scale outside of the output's boundaries,
which leads to an extra clipping step that's only necessary when zoom
is enabled.

Remove it to simplify desktop-shell and compositor.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-02-03 15:51:20 +00:00
Marius Vlad
d25d63e692 desktop-shell: Do not leave views in layers upon shell destruction
This properly takes care of removing any of the views being added into
different layers upon shell destruction. Aggregates the shell_surface
destruction into one place to make things much more clearer. Keep  the
animation part only the weston_desktop_surface destruction rather than
doing it at shutdown.

Fixes #509.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-12-17 11:04:28 +02:00
Marius Vlad
137c793f22 desktop-shell: Guard against invalid seats in get_shell_seat()
Starting with commit 'desktop-shell: Embed keyboard focus handle code
when activating' we are iterating over all the seats when removing a
weston_desktop_surface to be able to invalidate the activate surface.

Upon compositor tear down the shell destroy might invalidate seats
before removal of the weston_desktop_surface making the shell_seat
itself invalid. This wasn't apparent at that time because we're not
handling at that the removal of surfaces from layers.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-24 12:17:26 +00:00
Marius Vlad
5699dbaae7 desktop-shell: Don't crash on when attemping to switch
Attempting to perform a switch on a surface (already) closed will trip
the assert in activate(), so check if we have a weston_desktop_surface
before trying to activate it.

Fixes #543

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-03 10:10:58 +02:00
Marius Vlad
2be09373b4 desktop-shell, kiosk-shell: Migrate helpers to create a view to shell-utils
Incidentally fixes #553

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:32:24 +02:00
Marius Vlad
d98c7e86fb shared/shell-utils: Create common helpers functions for shells
Group common functions found in both kiosk-shell and deskop-shell to
a shared utils file.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:29:50 +02:00
Marius Vlad
d6ccc8b025 libweston: Rename weston_view_activate() to weston_view_activate_input()
This way, we try to differentiate between input focus and window/surface
activation.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:04:33 +02:00
Marius Vlad
f3584cf995 desktop-shell: Remove keyboard_focus_listener
We no longer make use of the keyboard_focus_listener so remove it
entirely.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Derek Foreman <derek.foreman@collabora.com>
2021-11-02 19:04:33 +02:00
Marius Vlad
f12697bb3e desktop-shell: Embed keyboard focus handle code when activating
We shouldn't be constrained by having a keyboard plugged-in, so avoid
activating/de-activating the window/surface in the keyboard focus
handler and embed it straight into the window activation part.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:04:33 +02:00
Marius Vlad
ab39e1d76d desktop-shell: Rename gain/lose keyboard focus to activate/de-activate
This way it better reflects that it handles activation rather that input
focus.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:04:33 +02:00
Marius Vlad
05bef4c18a desktop-shell: Remove no-op de-activation of the xdg top-level surface
The shsurf is calloc'ed so the surface count is always 0.  Not only
that but the surface is not set as active by default, so there's no
need to de-activate it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-11-02 19:04:33 +02:00
Takuro Ashie
beff0bd0f9 desktop-shell: Fix wrong initial position of input panel
When the surface type of input panel is set as an overlay panel, it's
expected to be shown at near the input cursor. But the current
implementation shows it at center-bottom on the desktop at first then
move it to the correct position while typing.

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
2021-10-14 21:17:07 +09:00
Marius Vlad
a7392c855d desktop-shell: Clear out missing listeners
The keyboard focus listener, caps changed and pointer focus listener
were missing when destroying the seat. These are necessary to avoid
using weston_desktop object even if it was destroyed, which happens due
to a focus out event and ultimately handled by the keyboard focus notify
callback.

Once the seats are destroyed (and implictly the focus handlers) we're
safe to destroy weston_desktop object as well.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-10-14 09:06:44 +00:00
Marius Vlad
c114fd6ef6 desktop-shell: Keep track of seats
This properly tracks the seats and with it, destroys them before
destroying weston_desktop object.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-10-14 09:06:44 +00:00
Jonas Ådahl
56958aa6e9 desktop-shell: Damage subsurfaces when minimizing
Fixes an issue where subsurface extending outside of the main surface
wasn't damaged when minimized resulting in left-over content.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2021-10-01 12:03:11 +02:00
Marius Vlad
c30cb29248 desktop-shell: Use weston_surface_destroy() directly
Follow-up from commit 'desktop-shell: don't run fade animation if
compositor is inactive' where the reference was dropped directly,
instead of using weston_surface_destroy().

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-08-03 10:44:26 +03:00
Emmanuel Gil Peyrot
eff793ab46 Fix indentation all through the project
Fixes a “regression” from 04918f3b0b, but
also other missed pieces.
2021-07-31 15:28:20 +00:00
Erik Kurzinger
04918f3b0b desktop-shell: don't run fade animation if compositor is inactive
When a window is closed, Weston will, by default, run a fade out animation and
defer destroying the underlying surface until it completes. However, if the
compositor is sleeping, and therefore not rendering any frames, this animation
will *never* complete. Therefore, if windows are repeatedly created and
destroyed while in sleep mode, these surfaces will keep accumulating, and since
the buffers attached to them may be backed by an fd, eventually the ulimit will
be reached resulting in a potential crash or other errors.

This can be demonstrated repeatedly launching and killing an X11 application
with Xwayland running.

while true; do xterm & pid=$!; sleep 0.5; kill $pid; done

As soon as the compositor goes to sleep, one can observe a steadily growing
list of dmabufs in the output of lsof.

As a fix, desktop_surface_removed should check whether the compositor is active
before kicking off the fade animation. If it is not, it should instead drop the
extra reference taken in desktop_surface_committed and then destroy the surface
immediately.

Signed-off-by: Erik Kurzinger <ekurzinger@nvidia.com>
2021-07-31 13:47:45 +00:00
Pekka Paalanen
719ca87399 desktop-shell: clean up shell_output better
This fixes the following ASan detected leaks:

Direct leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f8c3455f330 in __interceptor_malloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9330)
    #1 0x7f8c33c60906 in wl_event_loop_add_timer ../../git/wayland/src/event-loop.c:571
    #2 0x7f8c2ff98f46 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4211
    #3 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266
    #4 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #5 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434
    #6 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #7 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #8 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #9 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #10 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661
    #11 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308
    #12 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

Indirect leak of 856 byte(s) in 1 object(s) allocated from:
    #0 0x7f8c3455f518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f8c33c99b73 in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7f8c33c9cfb1 in weston_surface_create ../../git/weston/libweston/compositor.c:574
    #3 0x7f8c2ff98230 in shell_fade_create_surface_for_output ../../git/weston/desktop-shell/shell.c:4059
    #4 0x7f8c2ff98df6 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4202
    #5 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266
    #6 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #7 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434
    #8 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #9 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #10 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #11 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #12 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661
    #13 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308
    #14 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

Indirect leak of 608 byte(s) in 1 object(s) allocated from:
    #0 0x7f8c3455f518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f8c33c99b73 in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7f8c33c9bed5 in weston_view_create ../../git/weston/libweston/compositor.c:365
    #3 0x7f8c2ff98251 in shell_fade_create_surface_for_output ../../git/weston/desktop-shell/shell.c:4063
    #4 0x7f8c2ff98df6 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4202
    #5 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266
    #6 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #7 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434
    #8 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #9 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #10 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #11 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #12 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661
    #13 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308
    #14 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

They were found with:

	ASAN_OPTIONS=fast_unwind_on_malloc=0,malloc_context_size=50 \
	LSAN_OPTIONS=suppressions=/home/pq/git/weston/.gitlab-ci/leak-sanitizer.supp \
	./tests/test-viewporter test_viewporter_double_create

Turns out shell_destroy() had an open-coded and outdated copy of the
tear-down sequence, so fixing the leaks in only handle_output_destroy()
was not enough.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-31 12:35:01 +03:00
Pekka Paalanen
0d5e4ffb96 desktop-shell: rename output_listener to shell_output
Most other places call a variable like this 'shell_output', so let's do
that here too. The old name was really confusing.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-31 12:35:01 +03:00
Pekka Paalanen
abd7292969 desktop-shell: destroy weston_desktop
Plugs ASan reported leaks:

Direct leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f338f70a518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f338afe22f3 in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7f338afe3cc2 in weston_desktop_xwayland_init ../../git/weston/libweston-desktop/xwayland.c:410
    #3 0x7f338afdbaef in weston_desktop_create ../../git/weston/libweston-desktop/libweston-desktop.c:87
    #4 0x7f338b148d39 in wet_shell_init ../../git/weston/desktop-shell/shell.c:5224
    #5 0x7f338f5e9de5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #6 0x7f338f5fadb9 in wet_main ../../git/weston/compositor/main.c:3434
    #7 0x5646d2392fc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #8 0x5646d23969fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #9 0x5646d2386bd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #10 0x5646d2386c58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #11 0x5646d2396faf in main ../../git/weston/tests/weston-test-runner.c:661
    #12 0x7f338f25f09a in __libc_start_main ../csu/libc-start.c:308
    #13 0x5646d2386769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

Indirect leak of 152 byte(s) in 1 object(s) allocated from:
    #0 0x7f338f70a518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f338afdb811 in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7f338afdb92d in weston_desktop_create ../../git/weston/libweston-desktop/libweston-desktop.c:65
    #3 0x7f338b148d39 in wet_shell_init ../../git/weston/desktop-shell/shell.c:5224
    #4 0x7f338f5e9de5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #5 0x7f338f5fadb9 in wet_main ../../git/weston/compositor/main.c:3434
    #6 0x5646d2392fc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #7 0x5646d23969fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #8 0x5646d2386bd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #9 0x5646d2386c58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #10 0x5646d2396faf in main ../../git/weston/tests/weston-test-runner.c:661
    #11 0x7f338f25f09a in __libc_start_main ../csu/libc-start.c:308
    #12 0x5646d2386769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

Indirect leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f338f70a518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f338afdc5ae in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7f338afdc89e in weston_desktop_client_create ../../git/weston/libweston-desktop/client.c:108
    #3 0x7f338afe3d2a in weston_desktop_xwayland_init ../../git/weston/libweston-desktop/xwayland.c:415
    #4 0x7f338afdbaef in weston_desktop_create ../../git/weston/libweston-desktop/libweston-desktop.c:87
    #5 0x7f338b148d39 in wet_shell_init ../../git/weston/desktop-shell/shell.c:5224
    #6 0x7f338f5e9de5 in wet_load_shell ../../git/weston/compositor/main.c:956
    #7 0x7f338f5fadb9 in wet_main ../../git/weston/compositor/main.c:3434
    #8 0x5646d2392fc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #9 0x5646d23969fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #10 0x5646d2386bd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46
    #11 0x5646d2386c58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48
    #12 0x5646d2396faf in main ../../git/weston/tests/weston-test-runner.c:661
    #13 0x7f338f25f09a in __libc_start_main ../csu/libc-start.c:308
    #14 0x5646d2386769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769)

Oops.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-31 12:35:01 +03:00
Pekka Paalanen
4bb326bc8c desktop-shell: call weston_layer_fini()
This ensures the layers are torn down properly.

See commit: libweston: add weston_layer_fini()

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-28 13:38:28 +03:00
Leandro Ribeiro
2ac73a8b53 exposay: delete outer padding from struct exposay_output
After some changes in the exposay layout, the outer padding makes
no sense anymore. It was used to avoid the panel to get overlapped
by the exposay surfaces and to keep distance from the borders
of the window.

Currently, the exposay is centralized and the panel cannot get
overlapped. The outer padding just creates unnecessary unused
space, what makes exposay's surfaces smaller.

Delete outer padding from struct exposay_output.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
82b4d42943 exposay: centralize surfaces of the last row when we don't have enough surfaces
The exposay grid is square, but we don't always have enough surfaces
to fill all the columns of the last row. The code to centralize
the surfaces of the last row is not working.

Fix the code that centralizes the surfaces in the last row, making
it more visually pleasant.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
55b4b47ec1 exposay: centralize exposay's surfaces in their own square
Commit "exposay: add margins to centralize exposay" has centralized
the whole exposay, but that's not enough. The internal surfaces of
exposay are not centralized.

Each internal surface of exposay is a square, but most of the windows
are rectangular. Add margin to centralize exposay's surfaces in their
own square.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
048c628139 exposay: add margins to centralize exposay
The exposay is being rendered in the top-left corner of the
screen. Add margins to render it in the center, making it
more visually pleasant.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
33e29d88cc exposay: make inner border dependent of exposay's surfaces size
We've been using an inner border of fixed size (80px), but this
is dangerous. If you have too many open applications or a small
window, the surface size computed will be negative, crashing
the exposay: "error: weston_view transformation not invertible".

Also, it creates a lot of unnecessary space, making the exposay
unusable when we have a small window or many applications open.

Make inner border to be 10% of surface size and surface size to
be 90% of its original size, avoiding the crashes and making it
more visually pleasant.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
b68454e893 exposay: do not account panel size to compute exposay area
Commit "desktop-shell: make get_output_work_area() global" allowed
the usage of get_output_work_area() in exposay. This is necessary to
avoid overlapping the panel when rendering exposay's surfaces.

Use get_output_work_area() to not take into account the panel size,
instead of considering that the whole screen is available to
render exposay's surfaces.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
0c59e92f0c desktop-shell: make get_output_work_area() global
get_output_work_area() can be used by exposay to know the free space
where it can render its surfaces, what avoids overlapping the panel.

Currently this function is declared as static in
desktop-shell/shell.c, so it cannot be used by exposay.

Remove static from get_output_work_area() and add it to shell.h
so it can be used by exposay as well.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
Leandro Ribeiro
fd874ff533 exposay: move constant value calculation out of loop
In exposay_layout(), int pad is being calculated within the
loop. This is unnecessary, as its value is constant. Move it
out of the loop.

Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
2020-08-26 14:10:50 +00:00
ganjing
c1e7151eb6 desktop-shell: check memory allocation in switcher_binding
after calling malloc() , be sure to determine whether the allocating for memory space is successful

Signed-off-by: ganjing <ganjing@uniontech.com>
2020-08-14 02:00:25 +00:00
Marius Vlad
6ebda36a3f desktop-shell: Avoid retrieving output's width/height if none present
As in some circumstances there could be no output connected, avoid
retrieving the width/height of the output if none was found/connected.

Fixes: #384

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2020-06-23 10:36:47 +00:00
Philipp Zabel
4b1de0112b build: add rpath to modules that use symbols from libexec_weston
The cms-static, desktop-shell, hmi-controller, ivi-shell, and screen-share
modules use symbols from libexec_weston, e.g.:

  $ ldd /usr/lib/x86_64-linux-gnu/weston/desktop-shell.so | grep "not found"
  	libexec_weston.so.0 => not found

Loading these modules from weston happens to work because the weston executable
itself links against libexec_weston, and has an rpath set. Still, these modules
depend on a library in a non-standard location. Adding an rpath could help
static checkers to make sure all shared objects' dependencies are present.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2020-02-06 09:00:42 +00:00
Marius Vlad
a27658e981 desktop-shell: Do not try to add a child to a non-existent parent
Introduced with a8da2084, it seems that there are cases when there's no
parent available (zenity, for instance).

Removes any potential child and re-initialize it, in case the parent is
not set. (Simon Ser)

Fixes: #340

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Reported-by: n3rdopolis <bluescreenavenger@gmail.com>
2020-01-17 12:47:32 +02:00
Stefan Agner
a8da208453 desktop-shell: make sure child window stays active
If a xdg_toplevel surface has a child (or multiple), the desktop shell
still allows to activate the parent. This can be problematic with
modal dialogs such as message boxes which then are hidden behind the
main window, which might be non-responsive to inputs at this this
point.

The protocol specifies set_parent as follows: "Set the 'parent' of
this surface. This surface should be stacked above the parent surface
and all other ancestor surfaces."

Track parent/child relationship in desktop-shell. Follow the protocol
recommendation and make sure the child stays stacked above the parent.

Fixes: #231

Signed-off-by: Stefan Agner <stefan@agner.ch>
2020-01-13 13:18:00 +01:00
Daniel Stone
51d995ad82 config-parser: Make get_bool be bool
Wayland innovated a lot of cool things, but non-binary boolean values is
the great advances of our time.

Make config_parser_get_bool() work on boolean values, and switch all its
users.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2019-11-28 19:24:13 +00:00
Pekka Paalanen
6ffbba3ac1 Use weston_compositor_add_destroy_listener_once() in plugins
This introduces a new convention of checking through the compositor destroy
listener if the plugin is already initialized. If the plugin is already
initialized, then the plugin entry function succeeds as a no-op. This makes it
safe to load the same plugin multiple times in a running compositor.

Currently module loading functions return failure if a plugin is already
loaded, but that will change in the future. Therefore we need this other method
of ensuring we do not double-initialize a plugin which would lead to list
corruptions the very least.

All plugins are converted to use the new helper, except:
- those that do not have a destroy listener already, and
- hmi-controller which does the same open-coded as the common code pattern
  did not fit there.

Plugins should always have a compositor destroy listener registered since they
very least allocate a struct to hold their data. Hence omissions are
highlighted in code.

Backends do not need this because weston_compositor_load_backend() already
protects against double-init. GL-renderer does not export a standard module
init function so cannot be initialized the usual way and therefore is not
vulnerable to double-init.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-11-21 16:32:55 +00:00
Pekka Paalanen
8e7f9501e4 Link Weston plugins to libexec-weston.so
All these plugins use symbols that were exported by the weston executable and
are now exported by libexec-weston.so. Linking these to libexec-weston.so fixes
unresolved symbols.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-24 13:40:51 +03:00
Pekka Paalanen
5e734ba308 build: link libm explicitly
In the future libweston will stop providing it for its users, since it's not
part of libweston API.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-24 13:29:33 +03:00
Pekka Paalanen
71ff95a544 build: separate deps for int and ext libweston users
We have two kinds of libweston users: internal and external. Weston, the
frontend, counts as an external user, and should not have access to libweston
private headers. The shell plugins are external users as well, because we
intend people to be able to write them. Renderers, backends, and some plugins
are internal users who will need access to private headers.

Create two different Meson dependency objects, one for each kind.

This makes it less likely to accidentally use a private header.

Screen-share is a Weston plugin and therefore counts as an external user, but
it needs the backend API to deliver input. Until we are comfortable exposing
public API for that purpose, let it use internal headers.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-24 13:29:33 +03:00
Pekka Paalanen
4f5e360180 build: simplify include_directories
Define common_inc which includes both public_inc and the project root directory.
The project root directory will allow access to config.h and all the shared/
headers.

Replacing all custom '.', '..', '../..', '../shared' etc. include paths with
common_inc reduces clutter in the target definitions and enforces the common
 #include directive style, as e.g. including shared/ headers without the
subdirectory name no longer works.

Unfortunately this does not prevent one from using private libweston headers
with the usual include pattern for public headers.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-04 17:14:22 +03:00
Pekka Paalanen
03eacfa618 build: shells do not need matrix.c
Do not build matrix.c into the shell plugins. The matrix functions are exported
by libweston.so and the shell plugins links to it.

Found by inspection.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-10-04 15:53:29 +03:00
Miguel A. Vico
620f68dc4f desktop-shell: Avoid NULL output dereference when getting surface label
When hotunplugging a display, the compositor will tear down the
corresponding output object.

Avoid NULL output dereferences by all surface label getters in
desktop-shell when hotunplugging happens.

Signed-off-by: Miguel A Vico Moya <mvicomoya@nvidia.com>
2019-09-25 13:25:39 -07:00
Tomohito Esaki
5898cd32c5 desktop-shell: unmap a view which was faded out
When Fading out a destroyed surface view finishes, the view is rendered
with very little alpha. After that, since the output isn't updated
unless a event on the output doesn't occurs, the view is still on the
output. By unmapping the view, the output repaint scheduled without the
surface.

Signed-off-by: Tomohito Esaki <etom@igel.co.jp>
2019-06-11 11:08:48 +00:00
Harish Krupo
dc3edc04aa desktop-shell: Re-position views when outputs change
When the last output is destroyed or when a new output is created after
the last output is destroyed, we need to re-position the views to ensure
that all the views are displayed on the output.

Fixes: https://gitlab.freedesktop.org/wayland/weston/issues/210

Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
2019-06-11 10:11:35 +00:00
Harish Krupo
2dff4dd695 desktop-shell: Don't re-position views when output_list is empty
Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
2019-06-11 10:11:35 +00:00
Pekka Paalanen
8ebd9817e7 Move libweston-desktop.h
This too is a public installed header.

The public headers are moved under a new top-level directory include/ to make
them clearly stand out as special (public API).

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-04-18 12:31:46 +03:00
Pekka Paalanen
eebb7dc9ce Rename xwayland-api.h to libweston/xwayland-api.h
See "Rename compositor.h to libweston/libweston.h" for rationale.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-04-18 12:31:46 +03:00
Pekka Paalanen
91b1010de9 Rename config-parser.h to libweston/config-parser.h
It is a public installed header used by libweston.h.

See "Rename compositor.h to libweston/libweston.h" for rationale.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-04-18 12:31:46 +03:00
Pekka Paalanen
3d5d9476e3 Rename compositor.h to libweston/libweston.h
The main idea is to make libweston users use the form

 #include <libweston/libweston.h>

instead of the plain

 #include <compositor.h>

which is prone to name conflicts. This is reflected both in the installed
files, and the internal header search paths so that Weston would use the exact
same form as an external project using libweston would.

The public headers are moved under a new top-level directory include/ to make
them clearly stand out as special (public API).

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-04-18 12:31:46 +03:00
Emmanuel Gil Peyrot
426c24673f Fix typos all around (thanks codespell!) 2019-02-20 16:47:35 +01:00
Sergey Bugaev
14ef201295 desktop-shell: don't crash if a surface disappears while grabbed
A surface can get destroyed while a shell grab is active, which can
for example happen if the command running in weston-terminal exits.

When a surface gets destroyed, grab->shsurf is reset to NULL by
destroy_shell_grab_shsurf(), but otherwise the grab remains active and
its callbacks continue to be called. Thus, dereferencing grab->shsurf
in a callback without checking it for NULL first can lead to undefined
behavior, including crashes.

Several functions were already properly checking grab->shsurf for NULL,
move_grab_motion() being one example. Others, however, were not, which
is what this commit fixes.

Related to https://gitlab.freedesktop.org/wayland/weston/issues/192

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2019-02-16 09:45:52 +00:00
Greg V
15d3d3004b desktop-shell: remove surface destroy listener when focus state is destroyed
Changing the focused surface did remove the surface_destroy_listener from the wl_signal list,
but destroying the focus state did not. As a result, sometimes the same listener would be added
to two surfaces, which would join their wl_signal lists together, which would cause infinite
loops and use-after-frees when closing desktop surfaces.
2019-02-16 09:45:52 +00:00
Greg V
ec3f779aa7 desktop-shell: fix resize grab related crash
This crash was happening when *releasing* a pointer button on a window
that was being resized and got destroyed during the grab.

[@daniels: Cosmetic fixes; apply same fix to grab cancel.]
2019-02-16 09:45:36 +00:00
Pekka Paalanen
052032d730 desktop-shell: use weston_compositor_exit
Use the proper weston_compositor_exit API instead of wl_display_terminate() to
allow the compositor main to prepare for exit, and most importantly to set the
exit error code as appropriate.

I have some brokenness in my test suite running, and weston-desktop-shell was
crashing at start, yet the tests did not notice. With this patch, the tests
where the helper crashes are properly marked as failed.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-02-06 10:58:22 +00:00
Greg V
f57774e112 desktop-shell: extract view_get_transform, make it reliable
Avoid crashes related to get_shell_surface returning NULL.

Surfaces are already allowed to be neither focus nor shell in
e.g. focus_state_surface_destroy.
2019-01-31 01:47:27 +00:00
Marius Vlad
64fbd0f41f compositor: Add some handy wrappers for wet_get_binary_path()
This allows to possibility to specify where to look for the executable
but also simplifies the need of having to pass either BINDIR/LIBEXECDIR
for retrieving full-path of the executable.

Signed-off-by: Marius Vlad <marius.vlad0@gmail.com>
2018-12-18 15:37:34 +02:00
Daniel Stone
8011b0fa03 Add Meson build system
Meson is a build system, currently implemented in Python, with multiple
output backends, including Ninja and Make. The build file syntax is
clean and easy to read unlike autotools. In practise, configuring and
building with Meson and Ninja has been observed to be much faster than
with autotools. Also cross-building support is excellent.

More information at http://mesonbuild.com

Since moving to Meson requires some changes from users in any case, we
took this opportunity to revamp build options. Most of the build options
still exist, some have changed names or more, and a few have been
dropped. The option to choose the Cairo flavour is not implemented since
for the longest time the Cairo image backend has been the only
recommended one.

This Meson build should be fully functional and it installs everything
an all-enabled autotools build does. Installed pkg-config files have
some minor differences that should be insignificant. Building of some
developer documentation that was never installed with autotools is
missing.

It is expected that the autotools build system will be removed soon
after the next Weston release.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Co-authored-by: Pekka Paalanen <pq@iki.fi>
Signed-off-by: Pekka Paalanen <pq@iki.fi>
2018-12-09 14:50:54 +02:00
Harsha M M
b8b2c72709 libweston: Remove signals from the list during de-init
During de-init ensure removal of added signals from list. Otherwise
a dongling pointer is left behind which will affect other plugins.

Signed-off-by: Harsha M M <harsha.manjulamallikarjun@in.bosch.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-08-08 12:22:24 +03:00
Daniel Stone
11f91bbd36 helpers: Move static_assert definition to shared
Collect the fallback definitions of static_assert() from desktop-shell
and the test shell, and move them to helpers.h. This allows code
throughout the tree to use static_assert() for build-time assertions,
where it is supported by the compiler.

As GCC goes out of its way to only add static_assert() when C11 has been
explicitly requested - which we don't do - make sure to use the more
widely available _Static_assert() if that is provided.

This will be used in future patches to ensure two array lengths don't go
out of sync.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-07-09 15:39:20 +01:00
Daniel Stone
e03c111e4e tests: Don't rely on build directory layout
Rather than having a hardcoded dependency on the build-directory layout,
use an explicit module-map environment variable, which rewrites requests
for modules and helper/libexec binaries to specific paths.

Pekka: This will help with migration to Meson where setting up the paths
according to autotools would be painful and unnecessary.

Emre: This should also help setting up the test suite after a
cross-compile.

Pekka: A caveat here is that this patch makes it slightly easier to load
external backends by abusing the module map. External backends are
specifically not supported in libweston.

Signed-off-by: Daniel Stone <daniels@collabora.com>

v2:

Fixed ivi_layout-test-plugin.c:wet_module_init().
Do not change the lookup name of ivi-layout.ivi.

Improved documentation of weston_module_path_from_env() and made it cope
with map strings that a) do not end with a semicolon, and b) have
multiple consecutive semicolons.

Let WESTON_MODULE_MAP be printed into the test log so that it is easier
to run tests manually.

Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Emre Ucan <eucan@de.adit-jv.com>

Suggested by Emil: Use a variable for strlen(name).

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2018-06-20 14:36:52 +03:00
Pekka Paalanen
c63acc4cb8 desktop-shell: survive NULL output in shell_configure_fullscreen()
Running 'weston-simple-egl -f -b' (fullscreen, unthrottled) caused a
crash in shell_ensure_fullscreen_black_view() due to
shsurf->fullscreen_output being NULL. Also shell_configure_fullscreen()
could crash on that condition.

Fix shell_configure_fullscreen() to bail out with minimal work if there
is no fullscreen_output.

It is unclear if anything will cause a reconfiguration when an output is
plugged in.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Ian Ray <ian.ray@ge.com>
2018-05-24 17:20:04 +03:00
Pekka Paalanen
87860c20ee desktop-shell: do not lower_fullscreen_layer(s, NULL)
In activate, do not call lower_fullscreen_layer() at all if the output
is NULL. It should not do anything in that case, per the existing
comment.

This is a tentative crash fix for a case where there are no enabled
weston_outputs at all.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Ian Ray <ian.ray@ge.com>
2018-05-24 17:20:04 +03:00
Pekka Paalanen
30aa59759a desktop-shell: handle NULL output in center_on_output()
This is a tentative crash fix for a case where there are no enabled
weston_outputs at all.

If no output is given, just put the surface at 0,0. At least it should
become mostly visible if an output is plugged in, if not centered.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Ian Ray <ian.ray@ge.com>
2018-05-24 17:20:04 +03:00
Pekka Paalanen
99372bab4c desktop-shell: handle NULL output in get_output_work_area()
This is a tentative crash fix for a case where there are no
enabled weston_outputs at all.

Let get_output_work_area() return a zero area if the given output is
NULL. If there is no output, there is no area. Unfortunately we cannot
return "no position" but have to use 0,0 instead.

In send_configure_for_surface(), this causes a maximized surface to
receive width=0 and height=0 in the configure event, which means the
client is free to choose the size. There is no correct size to send for
maximizing for no output.

In constrain_position(), this has no effect. The interactive move of a
surface is restricted to not go below the panel, so even if a user
managed to move a surface without an output, it just prevents the
surface moving beyond y=0.

In weston_view_set_initial_position(), get_output_work_area() will not
be called with NULL output anyway.

In set_maximized_position(), this makes it behave as if the output was
at 0,0 which is the default position of the first output.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Ian Ray <ian.ray@ge.com>
2018-05-24 17:20:04 +03:00
Pekka Paalanen
99628000cb desktop-shell: fix output destroy signal list corruption
This issue was introduced by "desktop-shell: detect stale shell surface
outputs" which forgot to remove the output destroy listener when
shell_surface is destroyed, leading to memory corruption.

This was fairly easy to trigger by opening and closing an application
window a few times.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Ian Ray <ian.ray@ge.com>
2018-05-22 12:48:35 +03:00
Semi Malinen
99f8c08559 desktop-shell: detect stale shell surface outputs
When displays are hot (un)plugged, it may happen that
a shell surface is left with a stale pointer to an output
that has already been freed. Add an output destroy listener
to catch such situations and set the output pointer to NULL.

Signed-off-by: Semi Malinen <semi.malinen@ge.com>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-05-21 16:51:05 +03:00
Semi Malinen
e7a52fbb7d libweston: add weston_view_set_output()
Instead of desktop shell assigning view outputs directly,
use a new method, weston_view_set_output(). The method can
set up an output destroy listener to make sure that views
do not have stale output pointers.

Without this patch it is possible to end up in a scenario
where, e.g. configure_static_view() accesses memory that
has already been freed. The scenario can be provoked by
repeatedly plugging and unplugging a display. The faulty
memory accesses are reported by valgrind.

Signed-off-by: Semi Malinen <semi.malinen@ge.com>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-05-18 13:50:21 +03:00
Pekka Paalanen
055c1137ae libweston: make wl_output point to weston_head
The user data of a wl_resource representing a wl_output protocol object
used to be a pointer to weston_output. Now that weston_output is being
split, wl_output more accurately refers to weston_head which is a single
monitor.

Change the wl_output user data to point to weston_head.
weston_output_from_resource() is replaced with
weston_head_from_resource().

This change is not strictly necessary, but architecturally it is the
right thing to do. In the future there might appear the need to refer to
a specific head of a cloned pair, for instance.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v5 Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Ian Ray <ian.ray@ge.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Derek Foreman <derekf@osg.samsung.com>
2018-04-10 14:33:59 +03:00
Pekka Paalanen
9350bfd916 desktop-shell: fix shell_output_destroy_move_layer unused variable
/home/pq/git/weston/desktop-shell/shell.c: In function ‘shell_output_destroy_move_layer’:
/home/pq/git/weston/desktop-shell/shell.c:4718:24: warning: unused variable ‘output’ [-Wunused-variable]
  struct weston_output *output = data;

Since the data pointer is not used for anything, decided to also set it
to NULL in the caller. This caused another variable to become unused.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Marius-Vlad <marius-cristian.vlad@nxp.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-02-14 10:03:36 +02:00
Pekka Paalanen
1a0239e40f desktop-shell: handle redundant panels
If for some reason the helper client weston-desktop-shell would create
more than one panel surface for the same weston_output, this code would
corrupt the surface destroy listener list by adding a link already in
one list into another list.

Instead, do not store the new, redundant panel surface and do not
subscribe to its destruction. Also, tell the helper that the surface is
redundant by configuring it with a 0x0 size, so that we don't waste
memory on a panel that is never used.

(Clone mode is a valid reason why weston-desktop-shell could do that.)

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-02-12 13:14:39 +02:00
Pekka Paalanen
ff5e88d276 desktop-shell: handle redundant backgrounds
If for some reason the helper client weston-desktop-shell would create
more than one background surface for the same weston_output, this code
would corrupt the surface destroy listener list by adding a link already
in one list into another list.

Instead, do not store the new, redundant background surface and do not
subscribe to its destruction. Also, tell the helper that the surface is
redundant by configuring it with a 0x0 size, so that we don't waste
memory on a background that is never used.

(Clone mode is a valid reason why weston-desktop-shell could do that.)

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-02-12 13:14:39 +02:00
Marius Vlad
ea40d6dbfc desktop-shell: Correctly migrate views to other outputs when output is disabled/disconnected
Our case is when the view is the same as output being disabled/disconnected.
There's not need to check the views' output with the output being disabled
because weston_view_assign_output() already changes the output of the view when
the output has been disabled/disconnected hence the check is not needed at all.

The views' output will always be different than the output being disabled.

By the time shell_output_destroy_move_layer() gets called the views' output has
already changed to a "free" output. Tested this by unplugging/disabling the
output on purpose.

Signed-off-by: Marius Vlad <marius-cristian.vlad@nxp.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-02-09 15:45:46 +00:00
Tomohito Esaki
bf31f6cfb9 desktop-shell: remove surface listener when surface is destroyed
There may be race condition between destroying surface and destroying
output. If handle_output_destroy() is called after surface is destroyed,
illegal memory access occurs when surface destroy signals is
unregistered from the panel/background. This patch fixes this issue and
removes unnecessary initialization for panel surface listener.

Signed-off-by: Tomohito Esaki <etom@igel.co.jp>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-01-31 09:44:00 +02:00
Derek Foreman
e1af3d8d9d desktop-shell: Handle the fullscreen to maximized case safely
When a client transitions from maximized to fullscreen to maximized (run
weston-terminal, maximize it, hit f11 twice) we're sending size 0,0 for
the unfullscreen configure, which still has maximized set.

This results in clients correctly picking any size they like, and weston
disconnecting them for it.

Instead, pass the correct maximized size.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2017-12-04 21:58:15 +00:00
Derek Foreman
927d9e23fa desktop-shell: refactor maximized size calculation into its own function
We need to calculate maximized size to resolve a bug with unsetting
fullscreen, might as well share the code.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2017-12-04 21:58:08 +00:00
Alexandros Frantzis
409b01fd6d libweston: Use struct timespec for compositor time
Change weston_compositor_get_time to return the current compositor time
as a struct timespec. Also, use clock_gettime (with CLOCK_REALTIME) to
get the time, since it's equivalent to the currently used gettimeofday
call, but returns the data directly in a struct timespec.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
7d2abcf6c8 libweston: Use struct timespec for touch motion events
Change code related to touch motion events to use struct timespec to
represent time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
27a51b83e5 libweston: Use struct timespec for touch up events
Change code related to touch up events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
9448deb073 libweston: Use struct timespec for touch down events
Change code related to touch down events to use struct timespec to
represent time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
47e79c860b libweston: Use struct timespec for key events
Change code related to key events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
80321942e7 libweston: Use struct timespec for axis events
Change code related to axis events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
215bedc88b libweston: Use struct timespec for button events
Change code related to button events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
84b31f8956 libweston: Use struct timespec for motion events
Change code related to motion events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:42:07 +02:00
Alexandros Frantzis
8250a61de1 build,libweston: Use struct timespec for animations
Change code related to animations to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>

This bumps the libweston major version due to breakage in the animation
ABI. The commits following this one break more ABI in other parts.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-11-27 11:41:17 +02:00
Ian Ray
13404c4016 desktop-shell: disable opacity binding when modifier is none
This patch disables the opacity binding when the modifier is configured
to `none' in weston.ini, and thus supports use cases where one does not
want to have this binding.

Signed-off-by: Ian Ray <ian.ray@ge.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-09-18 16:17:08 +03:00