summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2022-02-23 13:24:49 +0000
committerDaniel Stone <daniels@collabora.com>2022-03-31 17:15:55 +0000
commit6cb2526b675be0c7af2840e6bd951fef64486d02 (patch)
treeabe24f82a41cb8498763013003f1cf698a077343 /shared
parent15a553053a35c68212b9d99927261cc0d7a8c473 (diff)
downloadweston-6cb2526b675be0c7af2840e6bd951fef64486d02.tar.gz
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>
Diffstat (limited to 'shared')
-rw-r--r--shared/shell-utils.c208
-rw-r--r--shared/shell-utils.h64
2 files changed, 0 insertions, 272 deletions
diff --git a/shared/shell-utils.c b/shared/shell-utils.c
deleted file mode 100644
index 7a2f1df5..00000000
--- a/shared/shell-utils.c
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright 2010-2012 Intel Corporation
- * Copyright 2013 Raspberry Pi Foundation
- * Copyright 2011-2012,2021 Collabora, Ltd.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "config.h"
-#include "shared/shell-utils.h"
-#include <libweston-desktop/libweston-desktop.h>
-
-struct weston_output *
-get_default_output(struct weston_compositor *compositor)
-{
- if (wl_list_empty(&compositor->output_list))
- return NULL;
-
- return container_of(compositor->output_list.next,
- struct weston_output, link);
-}
-
-struct weston_output *
-get_focused_output(struct weston_compositor *compositor)
-{
- struct weston_seat *seat;
- struct weston_output *output = NULL;
-
- wl_list_for_each(seat, &compositor->seat_list, link) {
- struct weston_touch *touch = weston_seat_get_touch(seat);
- struct weston_pointer *pointer = weston_seat_get_pointer(seat);
- struct weston_keyboard *keyboard =
- weston_seat_get_keyboard(seat);
-
- /* Priority has touch focus, then pointer and
- * then keyboard focus. We should probably have
- * three for loops and check first for touch,
- * then for pointer, etc. but unless somebody has some
- * objections, I think this is sufficient. */
- if (touch && touch->focus)
- output = touch->focus->output;
- else if (pointer && pointer->focus)
- output = pointer->focus->output;
- else if (keyboard && keyboard->focus)
- output = keyboard->focus->output;
-
- if (output)
- break;
- }
-
- return output;
-}
-
-/* TODO: Fix this function to take into account nested subsurfaces. */
-void
-surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
- int32_t *y, int32_t *w, int32_t *h)
-{
- pixman_region32_t region;
- pixman_box32_t *box;
- struct weston_subsurface *subsurface;
-
- pixman_region32_init_rect(&region, 0, 0,
- surface->width,
- surface->height);
-
- wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
- pixman_region32_union_rect(&region, &region,
- subsurface->position.x,
- subsurface->position.y,
- subsurface->surface->width,
- subsurface->surface->height);
- }
-
- box = pixman_region32_extents(&region);
- if (x)
- *x = box->x1;
- if (y)
- *y = box->y1;
- if (w)
- *w = box->x2 - box->x1;
- if (h)
- *h = box->y2 - box->y1;
-
- pixman_region32_fini(&region);
-}
-
-void
-center_on_output(struct weston_view *view, struct weston_output *output)
-{
- int32_t surf_x, surf_y, width, height;
- float x, y;
-
- if (!output) {
- weston_view_set_position(view, 0, 0);
- return;
- }
-
- surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height);
-
- x = output->x + (output->width - width) / 2 - surf_x / 2;
- y = output->y + (output->height - height) / 2 - surf_y / 2;
-
- weston_view_set_position(view, x, y);
-}
-
-int
-surface_get_label(struct weston_surface *surface, char *buf, size_t len)
-{
- const char *t, *c;
- struct weston_desktop_surface *desktop_surface =
- weston_surface_get_desktop_surface(surface);
-
- t = weston_desktop_surface_get_title(desktop_surface);
- c = weston_desktop_surface_get_app_id(desktop_surface);
-
- return snprintf(buf, len, "%s window%s%s%s%s%s",
- "top-level",
- t ? " '" : "", t ?: "", t ? "'" : "",
- c ? " of " : "", c ?: "");
-}
-
-struct weston_curtain *
-weston_curtain_create(struct weston_compositor *compositor,
- struct weston_curtain_params *params)
-{
- struct weston_curtain *curtain;
- struct weston_surface *surface = NULL;
- struct weston_view *view;
-
- curtain = zalloc(sizeof(*curtain));
- if (curtain == NULL)
- goto err;
-
- surface = weston_surface_create(compositor);
- if (surface == NULL)
- goto err_curtain;
-
- view = weston_view_create(surface);
- if (view == NULL)
- goto err_surface;
-
- surface->committed = params->surface_committed;
- surface->committed_private = params->surface_private;
-
- curtain->view = view;
-
- weston_surface_set_color(surface,
- params->r, params->g, params->b, params->a);
- weston_surface_set_label_func(surface, params->get_label);
-
- pixman_region32_fini(&surface->opaque);
- if (params->a == 1.0) {
- pixman_region32_init_rect(&surface->opaque, 0, 0,
- params->width, params->height);
- } else {
- pixman_region32_init(&surface->opaque);
- }
-
- pixman_region32_fini(&surface->input);
- if (params->capture_input) {
- pixman_region32_init_rect(&surface->input, 0, 0,
- params->width, params->height);
- } else {
- pixman_region32_init(&surface->input);
- }
-
- weston_surface_set_size(surface, params->width, params->height);
- weston_view_set_position(view, params->x, params->y);
-
- return curtain;
-
-err_surface:
- weston_surface_destroy(surface);
-err_curtain:
- free(curtain);
-err:
- weston_log("no memory\n");
- return NULL;
-}
-
-void
-weston_curtain_destroy(struct weston_curtain *curtain)
-{
- struct weston_surface *surface = curtain->view->surface;
-
- weston_view_destroy(curtain->view);
- weston_surface_destroy(surface);
- free(curtain);
-}
diff --git a/shared/shell-utils.h b/shared/shell-utils.h
deleted file mode 100644
index 8e2e5cb3..00000000
--- a/shared/shell-utils.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2021 Collabora, Ltd.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "config.h"
-#include "shared/helpers.h"
-#include <libweston/libweston.h>
-
-/* parameter for weston_curtain_create() */
-struct weston_curtain_params {
- int (*get_label)(struct weston_surface *es, char *buf, size_t len);
- void (*surface_committed)(struct weston_surface *es, int32_t sx, int32_t sy);
- void *surface_private;
- float r, g, b, a;
- int x, y, width, height;
- bool capture_input;
-};
-
-struct weston_curtain {
- struct weston_view *view;
-};
-
-struct weston_output *
-get_default_output(struct weston_compositor *compositor);
-
-struct weston_output *
-get_focused_output(struct weston_compositor *compositor);
-
-void
-center_on_output(struct weston_view *view, struct weston_output *output);
-
-void
-surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
- int32_t *y, int32_t *w, int32_t *h);
-
-int
-surface_get_label(struct weston_surface *surface, char *buf, size_t len);
-
-/* helper to create a view w/ a color */
-struct weston_curtain *
-weston_curtain_create(struct weston_compositor *compositor,
- struct weston_curtain_params *params);
-void
-weston_curtain_destroy(struct weston_curtain *curtain);