blob: 91654baa9e755122bb8601ed09f123a5241eb887 [file] [log] [blame]
Quentin Glidic642bcaf2017-01-27 17:30:23 +01001/*
2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
4 * Copyright © 2013 Raspberry Pi Foundation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdlib.h>
29#include <stdint.h>
30#include <stdio.h>
31#include <string.h>
32#include <unistd.h>
33#include <linux/input.h>
34#include <assert.h>
35#include <signal.h>
36#include <math.h>
37#include <sys/types.h>
38
39#include "compositor/weston.h"
Pekka Paalanen91b10102019-04-04 14:27:31 +030040#include <libweston/config-parser.h>
Quentin Glidic642bcaf2017-01-27 17:30:23 +010041#include "shared/helpers.h"
Pekka Paalanen8ebd9812019-04-04 16:02:14 +030042#include <libweston-desktop/libweston-desktop.h>
Quentin Glidic642bcaf2017-01-27 17:30:23 +010043
Pekka Paalanen7bcec202017-01-27 17:30:24 +010044struct desktest_shell {
45 struct wl_listener compositor_destroy_listener;
46 struct weston_desktop *desktop;
47 struct weston_layer background_layer;
48 struct weston_surface *background_surface;
49 struct weston_view *background_view;
50 struct weston_layer layer;
51 struct weston_view *view;
52};
Quentin Glidic642bcaf2017-01-27 17:30:23 +010053
54static void
55desktop_surface_added(struct weston_desktop_surface *desktop_surface,
56 void *shell)
57{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010058 struct desktest_shell *dts = shell;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010059
Pekka Paalanen7bcec202017-01-27 17:30:24 +010060 assert(!dts->view);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010061
Pekka Paalanen7bcec202017-01-27 17:30:24 +010062 dts->view = weston_desktop_surface_create_view(desktop_surface);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010063
Pekka Paalanen7bcec202017-01-27 17:30:24 +010064 assert(dts->view);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010065}
66
67static void
68desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
69 void *shell)
70{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010071 struct desktest_shell *dts = shell;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010072
Pekka Paalanen7bcec202017-01-27 17:30:24 +010073 assert(dts->view);
74
75 weston_desktop_surface_unlink_view(dts->view);
76 weston_view_destroy(dts->view);
77 dts->view = NULL;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010078}
79
80static void
81desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
Pekka Paalanen7bcec202017-01-27 17:30:24 +010082 int32_t sx, int32_t sy, void *shell)
Quentin Glidic642bcaf2017-01-27 17:30:23 +010083{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010084 struct desktest_shell *dts = shell;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010085 struct weston_surface *surface =
86 weston_desktop_surface_get_surface(desktop_surface);
87 struct weston_geometry geometry =
88 weston_desktop_surface_get_geometry(desktop_surface);
89
Pekka Paalanen7bcec202017-01-27 17:30:24 +010090 assert(dts->view);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010091
92 if (weston_surface_is_mapped(surface))
93 return;
94
95 surface->is_mapped = true;
Pekka Paalanen7bcec202017-01-27 17:30:24 +010096 weston_layer_entry_insert(&dts->layer.view_list, &dts->view->layer_link);
97 weston_view_set_position(dts->view, 0 - geometry.x, 0 - geometry.y);
98 weston_view_update_transform(dts->view);
99 dts->view->is_mapped = true;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100100}
101
102static void
103desktop_surface_move(struct weston_desktop_surface *desktop_surface,
104 struct weston_seat *seat, uint32_t serial, void *shell)
105{
106}
107
108static void
109desktop_surface_resize(struct weston_desktop_surface *desktop_surface,
110 struct weston_seat *seat, uint32_t serial,
111 enum weston_desktop_surface_edge edges, void *shell)
112{
113}
114
115static void
116desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface,
117 bool fullscreen,
118 struct weston_output *output, void *shell)
119{
120}
121
122static void
123desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface,
124 bool maximized, void *shell)
125{
126}
127
128static void
129desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface,
130 void *shell)
131{
132}
133
134static void
135desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client,
136 void *shell)
137{
138}
139
140static void
141desktop_surface_pong(struct weston_desktop_client *desktop_client,
142 void *shell)
143{
144}
145
146static const struct weston_desktop_api shell_desktop_api = {
147 .struct_size = sizeof(struct weston_desktop_api),
148 .surface_added = desktop_surface_added,
149 .surface_removed = desktop_surface_removed,
150 .committed = desktop_surface_committed,
151 .move = desktop_surface_move,
152 .resize = desktop_surface_resize,
153 .fullscreen_requested = desktop_surface_fullscreen_requested,
154 .maximized_requested = desktop_surface_maximized_requested,
155 .minimized_requested = desktop_surface_minimized_requested,
156 .ping_timeout = desktop_surface_ping_timeout,
157 .pong = desktop_surface_pong,
158};
159
Pekka Paalanene948bd42022-01-24 14:49:30 +0200160static int
161background_get_label(struct weston_surface *surface, char *buf, size_t len)
162{
163 return snprintf(buf, len, "test desktop shell background");
164}
165
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100166static void
167shell_destroy(struct wl_listener *listener, void *data)
168{
169 struct desktest_shell *dts;
170
171 dts = container_of(listener, struct desktest_shell,
172 compositor_destroy_listener);
173
Leandro Ribeiroa7e0e712020-10-08 17:14:08 -0300174 wl_list_remove(&dts->compositor_destroy_listener.link);
175
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100176 weston_desktop_destroy(dts->desktop);
177 weston_view_destroy(dts->background_view);
178 weston_surface_destroy(dts->background_surface);
Pekka Paalanen6a0a3a02021-05-14 14:37:46 +0300179
180 weston_layer_fini(&dts->layer);
181 weston_layer_fini(&dts->background_layer);
182
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100183 free(dts);
184}
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100185
186WL_EXPORT int
187wet_shell_init(struct weston_compositor *ec,
188 int *argc, char *argv[])
189{
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100190 struct desktest_shell *dts;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100191
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100192 dts = zalloc(sizeof *dts);
193 if (!dts)
194 return -1;
195
Pekka Paalanen6ffbba32019-11-06 12:59:32 +0200196 if (!weston_compositor_add_destroy_listener_once(ec,
197 &dts->compositor_destroy_listener,
198 shell_destroy)) {
199 free(dts);
200 return 0;
201 }
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100202
203 weston_layer_init(&dts->layer, ec);
204 weston_layer_init(&dts->background_layer, ec);
205
206 weston_layer_set_position(&dts->layer,
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100207 WESTON_LAYER_POSITION_NORMAL);
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100208 weston_layer_set_position(&dts->background_layer,
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100209 WESTON_LAYER_POSITION_BACKGROUND);
210
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100211 dts->background_surface = weston_surface_create(ec);
212 if (dts->background_surface == NULL)
213 goto out_free;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100214
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100215 dts->background_view = weston_view_create(dts->background_surface);
216 if (dts->background_view == NULL)
217 goto out_surface;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100218
Pekka Paalanene948bd42022-01-24 14:49:30 +0200219 weston_surface_set_role(dts->background_surface,
220 "test-desktop background", NULL, 0);
221 weston_surface_set_label_func(dts->background_surface,
222 background_get_label);
Pekka Paalanena21b5eb2017-01-27 17:30:25 +0100223 weston_surface_set_color(dts->background_surface, 0.16, 0.32, 0.48, 1.);
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100224 pixman_region32_fini(&dts->background_surface->opaque);
225 pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000);
226 pixman_region32_fini(&dts->background_surface->input);
227 pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000);
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100228
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100229 weston_surface_set_size(dts->background_surface, 2000, 2000);
230 weston_view_set_position(dts->background_view, 0, 0);
231 weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link);
232 weston_view_update_transform(dts->background_view);
233
234 dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts);
235 if (dts->desktop == NULL)
236 goto out_view;
237
Leandro Ribeiro9e907602020-10-17 15:03:09 -0300238 screenshooter_create(ec);
239
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100240 return 0;
241
242out_view:
243 weston_view_destroy(dts->background_view);
244
245out_surface:
246 weston_surface_destroy(dts->background_surface);
247
248out_free:
Pekka Paalanene5e81882019-11-06 12:07:23 +0200249 wl_list_remove(&dts->compositor_destroy_listener.link);
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100250 free(dts);
251
252 return -1;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100253}