2021-03-08 19:02:32 +03:00
|
|
|
/*
|
|
|
|
* 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"
|
2022-11-22 14:28:57 +03:00
|
|
|
#include <libweston/shell-utils.h>
|
2022-06-30 12:59:45 +03:00
|
|
|
#include <libweston/desktop.h>
|
2023-09-08 20:44:12 +03:00
|
|
|
#include "shared/helpers.h"
|
2021-03-08 19:02:32 +03:00
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \defgroup shell-utils Shell utils
|
|
|
|
*
|
|
|
|
* These are some commonly used functions in our shells, useful for other shells
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT struct weston_output *
|
|
|
|
weston_shell_utils_get_default_output(struct weston_compositor *compositor)
|
2021-03-08 19:02:32 +03:00
|
|
|
{
|
|
|
|
if (wl_list_empty(&compositor->output_list))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return container_of(compositor->output_list.next,
|
|
|
|
struct weston_output, link);
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT struct weston_output *
|
|
|
|
weston_shell_utils_get_focused_output(struct weston_compositor *compositor)
|
2021-03-08 19:02:32 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*
|
|
|
|
* TODO: Fix this function to take into account nested subsurfaces.
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT void
|
|
|
|
weston_shell_utils_subsurfaces_boundingbox(struct weston_surface *surface,
|
|
|
|
int32_t *x, int32_t *y,
|
|
|
|
int32_t *w, int32_t *h)
|
2021-03-08 19:02:32 +03:00
|
|
|
{
|
|
|
|
pixman_region32_t region;
|
|
|
|
pixman_box32_t *box;
|
|
|
|
struct weston_subsurface *subsurface;
|
|
|
|
|
|
|
|
pixman_region32_init_rect(®ion, 0, 0,
|
|
|
|
surface->width,
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
|
|
|
|
pixman_region32_union_rect(®ion, ®ion,
|
2022-02-04 02:07:06 +03:00
|
|
|
subsurface->position.offset.c.x,
|
|
|
|
subsurface->position.offset.c.y,
|
2021-03-08 19:02:32 +03:00
|
|
|
subsurface->surface->width,
|
|
|
|
subsurface->surface->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
box = pixman_region32_extents(®ion);
|
|
|
|
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(®ion);
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT void
|
|
|
|
weston_shell_utils_center_on_output(struct weston_view *view,
|
|
|
|
struct weston_output *output)
|
2021-03-08 19:02:32 +03:00
|
|
|
{
|
|
|
|
int32_t surf_x, surf_y, width, height;
|
2022-11-09 22:39:08 +03:00
|
|
|
struct weston_coord_global pos;
|
2021-03-08 19:02:32 +03:00
|
|
|
|
|
|
|
if (!output) {
|
2022-11-09 22:39:08 +03:00
|
|
|
pos.c = weston_coord(0, 0);
|
|
|
|
weston_view_set_position(view, pos);
|
2021-03-08 19:02:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-22 14:28:57 +03:00
|
|
|
weston_shell_utils_subsurfaces_boundingbox(view->surface, &surf_x,
|
|
|
|
&surf_y, &width, &height);
|
2021-03-08 19:02:32 +03:00
|
|
|
|
2022-11-09 23:28:15 +03:00
|
|
|
pos = output->pos;
|
2022-11-09 22:39:08 +03:00
|
|
|
pos.c.x += (output->width - width) / 2 - surf_x / 2;
|
|
|
|
pos.c.y += (output->height - height) / 2 - surf_y / 2;
|
2021-03-08 19:02:32 +03:00
|
|
|
|
2022-11-09 22:39:08 +03:00
|
|
|
weston_view_set_position(view, pos);
|
2021-03-08 19:02:32 +03:00
|
|
|
}
|
2021-03-08 23:45:52 +03:00
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT int
|
|
|
|
weston_shell_utils_surface_get_label(struct weston_surface *surface,
|
|
|
|
char *buf, size_t len)
|
2021-03-08 23:45:52 +03:00
|
|
|
{
|
|
|
|
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 ?: "");
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT struct weston_curtain *
|
|
|
|
weston_shell_utils_curtain_create(struct weston_compositor *compositor,
|
|
|
|
struct weston_curtain_params *params)
|
2021-03-08 23:45:52 +03:00
|
|
|
{
|
2022-01-17 17:24:03 +03:00
|
|
|
struct weston_curtain *curtain;
|
2021-03-08 23:45:52 +03:00
|
|
|
struct weston_surface *surface = NULL;
|
2022-01-17 17:48:19 +03:00
|
|
|
struct weston_buffer_reference *buffer_ref;
|
2021-03-08 23:45:52 +03:00
|
|
|
struct weston_view *view;
|
|
|
|
|
2022-01-17 17:24:03 +03:00
|
|
|
curtain = zalloc(sizeof(*curtain));
|
|
|
|
if (curtain == NULL)
|
|
|
|
goto err;
|
|
|
|
|
2021-03-08 23:45:52 +03:00
|
|
|
surface = weston_surface_create(compositor);
|
2022-01-17 17:24:03 +03:00
|
|
|
if (surface == NULL)
|
|
|
|
goto err_curtain;
|
|
|
|
|
2021-03-08 23:45:52 +03:00
|
|
|
view = weston_view_create(surface);
|
2022-01-17 17:24:03 +03:00
|
|
|
if (view == NULL)
|
|
|
|
goto err_surface;
|
2021-03-08 23:45:52 +03:00
|
|
|
|
2022-01-17 17:48:19 +03:00
|
|
|
buffer_ref = weston_buffer_create_solid_rgba(compositor,
|
|
|
|
params->r,
|
|
|
|
params->g,
|
|
|
|
params->b,
|
|
|
|
params->a);
|
|
|
|
if (buffer_ref == NULL)
|
|
|
|
goto err_view;
|
2021-03-08 23:45:52 +03:00
|
|
|
|
2022-01-17 17:24:03 +03:00
|
|
|
curtain->view = view;
|
2022-01-17 17:48:19 +03:00
|
|
|
curtain->buffer_ref = buffer_ref;
|
2022-01-17 17:24:03 +03:00
|
|
|
|
2022-01-17 16:58:16 +03:00
|
|
|
weston_surface_set_label_func(surface, params->get_label);
|
2022-01-17 17:48:19 +03:00
|
|
|
surface->committed = params->surface_committed;
|
|
|
|
surface->committed_private = params->surface_private;
|
2022-01-18 21:17:17 +03:00
|
|
|
|
2022-01-17 17:48:19 +03:00
|
|
|
weston_surface_attach_solid(surface, buffer_ref, params->width,
|
|
|
|
params->height);
|
2022-01-18 21:17:17 +03:00
|
|
|
|
2021-03-08 23:45:52 +03:00
|
|
|
pixman_region32_fini(&surface->input);
|
2022-01-18 21:59:33 +03:00
|
|
|
if (params->capture_input) {
|
|
|
|
pixman_region32_init_rect(&surface->input, 0, 0,
|
|
|
|
params->width, params->height);
|
|
|
|
} else {
|
|
|
|
pixman_region32_init(&surface->input);
|
|
|
|
}
|
2021-03-08 23:45:52 +03:00
|
|
|
|
2022-06-02 12:10:56 +03:00
|
|
|
weston_surface_map(surface);
|
|
|
|
|
2022-09-06 15:50:53 +03:00
|
|
|
weston_view_set_position(view, params->pos);
|
2021-03-08 23:45:52 +03:00
|
|
|
|
2022-01-17 17:24:03 +03:00
|
|
|
return curtain;
|
|
|
|
|
2022-01-17 17:48:19 +03:00
|
|
|
err_view:
|
|
|
|
weston_view_destroy(view);
|
2022-01-17 17:24:03 +03:00
|
|
|
err_surface:
|
2022-02-07 11:59:41 +03:00
|
|
|
weston_surface_unref(surface);
|
2022-01-17 17:24:03 +03:00
|
|
|
err_curtain:
|
|
|
|
free(curtain);
|
|
|
|
err:
|
|
|
|
weston_log("no memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:27:47 +03:00
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
2022-11-22 14:28:57 +03:00
|
|
|
WL_EXPORT void
|
|
|
|
weston_shell_utils_curtain_destroy(struct weston_curtain *curtain)
|
2022-01-17 17:24:03 +03:00
|
|
|
{
|
|
|
|
struct weston_surface *surface = curtain->view->surface;
|
|
|
|
|
|
|
|
weston_view_destroy(curtain->view);
|
2022-02-07 11:59:41 +03:00
|
|
|
weston_surface_unref(surface);
|
2022-01-17 17:48:19 +03:00
|
|
|
weston_buffer_destroy_solid(curtain->buffer_ref);
|
2022-01-17 17:24:03 +03:00
|
|
|
free(curtain);
|
2021-03-08 23:45:52 +03:00
|
|
|
}
|
kiosk-shell: Redesign the function 'find_focus_successor()'
The function find_focus_successor() is called when destroying a surface to find
a successor to the current focus. It, however, has the following issues:
- Its first parameter is the weston layer from which to search for a successor.
This is an unnecessary flexibility for our use, which only adds complexity to
the user of the function by having to make a call for each layer. We know
that we want to search for a successor first in the normal layer, and if that
fails, then in the inactive layer. So we change the signature of
find_focus_successor(), removing this first parameter.
- It includes logic to decide whether to do the search or not: if the destroyed
surface is different from the surface that currently has focus, and if their
outputs are the same, then abort and don't do the search. This returns NULL to
the calling function. The problem is that the function also returns NULL if
it does the search and finds no successor. The distinction for the failing
reason is lost, and the user of the function needs to add more logic to know
the reason for failure. To simplify, we take the logic out of
find_focus_successor() and inside the caller.
- It returns the successor view, although it receives surfaces and the client
has logic to retrieve the surface corresponding to the returned view. To
simplify and maintain symmetry, we change the signature so that the function
returns the surface corresponding to the successor view.
Fixes: #738
Signed-off-by: Sergio Gómez <sergio.g.delreal@gmail.com>
2023-07-20 05:46:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup shell-utils
|
|
|
|
*/
|
|
|
|
WL_EXPORT enum weston_layer_position
|
|
|
|
weston_shell_utils_view_get_layer_position(struct weston_view *view)
|
|
|
|
{
|
|
|
|
if (!weston_view_is_mapped(view))
|
|
|
|
return WESTON_LAYER_POSITION_NONE;
|
|
|
|
|
|
|
|
return view->layer_link.layer->position;
|
|
|
|
}
|