Commit graph

259 commits

Author SHA1 Message Date
Daniel Stone 17331a0c7d frontend: Add FDSTR_INIT macro
This initialises fdstr to 'safe' values so we can reliably deinit them.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-04-19 08:28:21 +00:00
Lyude Paul 6a06669b58 clients: Add support for tablet cursor motion to window frames in libtoytoolkit
When it comes to a window frame, a tablet tool and cursor act almost
identical; they click things, drag things, etc. The tool type and extra
axes don't serve any use in the context of a window frame, so tablet
pointers share the frame_pointer structures used for the mouse pointer.

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Lyude Paul <thatslyude@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Signed-off-by: Bastian Farkas <bfarkas@de.adit-jv.com>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2023-03-31 12:10:26 +00:00
Michael Olbrich 2a48ab8c1e shared/frame: add helper to get decoration sizes without shadow
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2023-03-22 14:43:20 +00:00
Derek Foreman 87881e2cf6 xwm: Add support for xwayland_shell_v1
Use the new protocol to prevent races in surface to window association.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-03-03 08:21:24 +00:00
Michael Tretter 48b39d31ef shared: extract hash table implementation from xwayland
The hash table implementation is useful for other modules as well. Move it from
xwayland to the shared code.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-03-03 08:08:46 +00:00
Marius Vlad 7aac1acad8 cairo-util: Add missing HAVE_PANGO guard
For pango_cairo_font_map_set_default().

Fixes #720

Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-02-20 11:04:23 +00:00
Derek Foreman e1b4ad7d0b matrix: Introduce weston_coord
All through weston we have code that passes int x, y or
float x, y or wl_fixed_t x, y pairs. These pairs are frequently
converted to/from wl_fixed_t and other types.

We also have struct vec2d and struct weston_geometry which also
contain coordinate pairs.

Let's create a family of coordinate vector structures for coordinate
pairs and use it anywhere we sensibly can.

This has a few benefits - it helps remove intermediate conversion
between fixed/float/int types. It lets us roll the homogenous
coordinate normalization bits into helper functions instead of
needing them open coded throughout the source.

Possibly most importantly, it also allows us to do some compile time
validation of what coordinate space we're working in.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-02-01 07:27:05 -06:00
Marius Vlad 59ac0a38da libweston/vertex-clipping: Use shared helper
And introduced a new helper, CLIP, with it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-01-24 16:59:37 +02:00
Derek Foreman 31b3527418 libweston: Factor out transform matrix setup code
We want to use this in other places too, instead of open coding it
multiple times.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-16 17:01:54 +00:00
Emmanuel Gil Peyrot e13c99690b libweston: Optimise matrix multiplication
The previous version used div() to separate the column and row of the
current element, but that function is implemented as a libc call, which
prevented the compiler from vectorising the loop and made matrix
multiplication appear quite high in profiles.

With div() removed, we are down from 64 calls to vfmadd132ss acting on
one float at a time, to just 8 calls to vfmadd132ps when compiled with
AVX2 support (or 16 mulps, 16 addps with SSE2 support only), and the
function isn’t a hot spot any more.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2023-01-11 20:03:36 +00:00
Daniel Stone ef87ad2237 build: Add unreachable()
unreachable() is used to hint to the compiler that a certain branch
cannot ever be reached. The implementation is taken from Mesa.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-01-10 10:59:04 +02:00
Marius Vlad eeef6be8e2 doc/sphinx: Include weston-config and shell-utils in docs
libweston contains weston_config and weston_shell_utils utilities
functions so include these in the sphinx documentation as well.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2023-01-09 22:13:07 +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
Derek Foreman 92a9860e1d libweston: Add function to find the output transform of a matrix
When we build up a matrix from a series of operations, it's very useful
to know if the combined operations still result in something that matches
a wl_output_transform.

This adds a function to test if a matrix leads to a standard output
transform, and returns the transform if it does.

Tests are provided that check if complex series of operations return
expected results - the weston_matrix_needs_filtering function is tested
at the same time.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-25 08:29:05 -06:00
Derek Foreman 0e2136df7b libweston: Add a function to test if transformed images need filters
If a transformation matrix causes a scale, a rotation not a multiple of 90
degrees or a non-integral translation then textures rendered with
it would benefit from bilinear filtering.

This test is done in a lazy fashion by examining elements of the matrix
to check for a simple pattern that indicates these conditions are met.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-25 08:25:53 -06:00
Marius Vlad fb57ce17ef shared/cairo-util: Release any fontmap laying around
This is particularly useful when using the weston-editor which seems to
cause an issue with cairo_debug_reset_static_data(), as that still seems
to find out there are references laying around, causing a crash when
exiting:

 ../../../../src/cairo-hash.c:217: _cairo_hash_table_destroy: Assertion
 `hash_table->live_entries == 0' failed

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 11:07:12 +02:00
Marius Vlad cfe35b591f shared/cairo-util: Re-use the PangoContext for layout creation
Rather than creating a new PangoContext each time the menu redraw
handler is triggered re-use it if one was created previously.

All toytoolkit clients do create a layout (and implicitly a
PangoContext) but only those that have menu redraw
handler installed will create a new layout for each redraw of the menu,
effectively creating a new PangoContext each time.

Reported-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 11:07:12 +02:00
Marius Vlad 60b307e3ce shared/cairo-util: Zero out the memory when creating a new theme
Having the memory zeroed out just works better and avoids any possible
illegal access.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 11:07:12 +02:00
Marius Vlad f8a9ce3f55 shared/cairo-util: Do not save/restore the cairo context twice
We are already doing that before calling theme_render_frame() so no need
to do it again in layout creation.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 11:07:12 +02:00
Derek Foreman 5079f0b2f9 helpers: Add a u64 from 2 u32 helper
We do this enough that having a single implementation for it is probably
a win.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-10-27 08:13:30 +00:00
Derek Foreman 3a61976af7 matrix: Make matrix const in weston_matrix_transform
This function doesn't need to change the matrix, so we might as well
enforce that.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 12:00:59 +00:00
Marius Vlad 8c4cdd782e compositor/shared: Suppress write(2) warnings
Fixes the following warnings when building with _FORTIFY_SOURCE
and optimizations enabled:

../shared/xalloc.h:49:9: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
   49 |         write(STDERR_FILENO, oommsg, strlen(oommsg));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

or
../compositor/main.c:427:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  427 |                         write(STDERR_FILENO, fail_seteuid,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  428 |                               strlen(fail_seteuid));
      |                               ~~~~~~~~~~~~~~~~~~~~~
../compositor/main.c:434:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  434 |                         write(STDERR_FILENO, fail_cloexec,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435 |                               strlen(fail_cloexec));
      |                               ~~~~~~~~~~~~~~~~~~~~~
../compositor/main.c:442:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  442 |                         write(STDERR_FILENO, fail_exec, strlen(fail_exec));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-09-23 11:32:19 +00:00
Derek Foreman dac2f146ea xwm: Perform a roundtrip to send a deferred WM_TAKE_FOCUS
WM_TAKE_FOCUS requires a valid timestamp that isn't XCB_TIME_CURRENT. To
get one, we set a property on the window and wait for the notification
that it was set - this notification comes with a valid timestamp.

Once we have that timestamp, delete the property, and fire off the slightly
delayed WM_TAKE_FOCUS client request.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-08-08 12:43:34 +00:00
Pekka Paalanen fc26c749df shared/xalloc.h: do not rely on zalloc()
The definition of zalloc is trivial, so let's just have it here instead
of loading libweston/zalloc.h.

Now xalloc.h does not depend on any libweston header, which makes me
feel slightly better. It's more clean.

Who knows, maybe one day libweston/zalloc.h will be removed.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-07-20 12:47:11 +03:00
Pekka Paalanen 9229a45116 shared: rewrite fail_on_null() as abort_oom_if_null()
Recently I learnt that fprintf() is not async-signal-safe. Maybe it also
attempts to allocate memory sometimes. Hence, using it when we
presumably are out of memory is wishful thinking.

Therefore replace that with async-signal-safe code. If you have to check
pointers from traditional signal handlers, now you could do that too!

While doing this, we also lose the string formatting for line number. I
would argue that printing file and line number is not that useful, if
the system really is out of memory. If not out of memory, a core dump
would give us much more detailed information about what went wrong.

clients/window.c had some calls to fail_on_null() and these are simply
replaced. They were used for checking that creating new wl_proxy by
issuing a protocol request worked, and IIRC that only fails on
out-of-memory, so the same rationale applies here.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-07-20 12:44:12 +03:00
Pekka Paalanen cbbf0e59a5 ivi-shell: replace MEM_ALLOC() with mostly xcalloc()
Drop the even more home-grown alloc wrapper and use the xalloc.h
wrappers directly.

xcalloc() is added and used, because calloc() will detect integer
overflows in the size multiplication, while doing a simple
multiplication in the caller is subject to overflows which may result in
allocating not what was expected, subjecting to out-of-bounds access.

All MEM_ALLOC() calls that had a meaningful multiplication in them were
converted to xcalloc(), the rest to xzalloc().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-07-20 12:12:22 +03:00
Daniel Stone 2cdb473690 custom-env: Add helper to parse combined env/arg strings
Users like desktop-shell want to parse a provided string containing a
combination of environment and arg, e.g.: ENV=stuff /path/to/thing --good

Add support to custom-env for parsing this, with tests, so we can delete
the custom implementation inside desktop-shell.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-19 14:12:37 +00:00
Daniel Stone e568a025e1 custom-env: Add support for argument array
execve() takes the same form for arguments as environment: an array of
constant pointers to mutable strings, terminated by a NULL.

To make it easier for users who want to build up their own argument
strings to pass to execve, add support for argument arrays to custom_env.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-19 14:12:37 +00:00
Daniel Stone fafe5f0fc2 custom-env: Prepare for handling args as well as environment
Rename the bits handling environment variables (currently, all of it),
so we have room to handle args as well.

No functional changes.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-19 14:12:37 +00:00
Daniel Stone 3af823b69b process-util: Assert we don't finalize twice
Make sure that we only try to finalize once.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-19 14:12:37 +00:00
Daniel Stone b685e075cd process-util: Move Xwayland fork helpers to shared
We'll want to reuse these inside desktop-shell as well as the Weston
frontend.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-19 14:12:37 +00:00
Pekka Paalanen 99b2b958f9 shared: introduce os_fd_clear_cloexec()
This function will be used between fork() and exec() to remove the
close-on-exec flag. The first user will be compositor/xwayland.c.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-07-12 08:30:22 +00:00
Pekka Paalanen 0260b8a0b5 shared: fcntl uses int, not long
fcntl(2) manual says the return type is int, and that F_SETFD takes an
int. So use int.

Noticed by code inspection.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-07-12 08:30:22 +00:00
Daniel Stone f52231660e tests: Use memstream for config-parser test
Using real files is unnecessarily heavy and error-prone. Fixes timeouts
seen on CI with ASan.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-05 10:15:49 +01:00
Daniel Stone c55a14206d cairo-util: Clean up more Cairo detritus; almost all of it
Pango, Cairo, and fontconfig, all want to leave thread-global data
hanging around in order to maintain a cache. Try to clean up as much of
it as we possibly can on exit, apart from the Pango language string
which appears to be unfreeable, so has been added to LSan suppressions.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-29 14:33:21 +01:00
Daniel Stone 29c3422e05 cairo-util: Don't leak Pango objects
Rework PangoCairo context initialisation, so we don't leak either the
Pango layout, or any of the derived objects it creates.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-29 14:33:21 +01:00
Derek Foreman 0df0dccc84 shared: Make xalloc.h stand alone
Make fail_on_null static inline and put it in xalloc.h so we can use the
header exclusively instead of having to link with the library for it.

This is so we can use xalloc in places (like the RDP backend) without
having to bring in libshared.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-28 10:43:39 +00:00
Marius Vlad 59a72dcf63 shared/xcb-xwayland: Add missing atoms
Particularly important was _XWAYLAND_ALLOW_COMMITS atom which caused
some annoying flicker when resizing or hoovering over buttons.

This was introduced with 'shared/xcb-xwayland: Split into common
helpers' and somehow I missed those atoms.

Fixes 49d6532254

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-06-23 14:13:41 +00:00
Derek Foreman af51618708 xwayland/window-manager: Add support for _NET_FRAME_EXTENTS
https://specifications.freedesktop.org/wm-spec/1.4/ar01s05.html says
"The Window Manager MUST set _NET_FRAME_EXTENTS to the extents of the
window's frame", so this is probably something we should be doing.

Some programs (such as some versions of Firefox) expect this to be present,
and will render popups in wrong locations if it's not.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-22 12:05:23 -05:00
Derek Foreman 769e4376c6 shared/frame: Provide a function to get decoration sizes and use it
We need these values to calculate frame extents to properly set
_NET_FRAME_EXTENTS, but we don't want to calculate them twice.

Break out these bits from frame_resize_inside, and update it to use
the new function.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-22 12:04:06 -05:00
Hideyuki Nagase d902088bfc xwayland: support minimizing
Allow minimizing xwayland windows.

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
2022-06-22 09:57:25 -05:00
Marius Vlad 49d6532254 shared/xcb-xwayland: Split into common helpers
Avoid duplication of atom retrieval. This is particuarly useful
if one would one to reuse atom retrival in other parts, like tests.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2022-06-22 08:08:41 +00:00
Derek Foreman 2afb812d1e shared/cairo-util: Hold onto our pattern reference until we're done
This doesn't actually fix a bug - cairo refcounts this. But I
really don't like the look of code that drops a reference then
continues to use it.

While we're here, set a different pattern when we're done so the
one we allocated loses its last reference.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-09 12:29:46 +00:00
Pekka Paalanen 8bbd1a995b libweston: remove UNIT_TEST
This #define was used only by the matrix-test program, which was removed
in the previous commit.

Remove it as unused and fold away MATRIX_TEST_EXPORT.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-31 12:26:09 +00:00
Pekka Paalanen b383f52d31 gl_renderer: print more GL ES feature flags
This is a human readable replacement for printing out the list of all
available GL extensions that doesn't happen anymore by default.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-18 14:18:53 +03: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 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 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 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