blob: de8442512e4ff4c21d0a7d170996436570accf3a [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"
40#include "shared/config-parser.h"
41#include "shared/helpers.h"
42#include "libweston-desktop/libweston-desktop.h"
43
44#ifndef static_assert
45#define static_assert(cond, msg)
46#endif
47
Pekka Paalanen7bcec202017-01-27 17:30:24 +010048struct desktest_shell {
49 struct wl_listener compositor_destroy_listener;
50 struct weston_desktop *desktop;
51 struct weston_layer background_layer;
52 struct weston_surface *background_surface;
53 struct weston_view *background_view;
54 struct weston_layer layer;
55 struct weston_view *view;
56};
Quentin Glidic642bcaf2017-01-27 17:30:23 +010057
58static void
59desktop_surface_added(struct weston_desktop_surface *desktop_surface,
60 void *shell)
61{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010062 struct desktest_shell *dts = shell;
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
Pekka Paalanen7bcec202017-01-27 17:30:24 +010066 dts->view = weston_desktop_surface_create_view(desktop_surface);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010067
Pekka Paalanen7bcec202017-01-27 17:30:24 +010068 assert(dts->view);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010069}
70
71static void
72desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
73 void *shell)
74{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010075 struct desktest_shell *dts = shell;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010076
Pekka Paalanen7bcec202017-01-27 17:30:24 +010077 assert(dts->view);
78
79 weston_desktop_surface_unlink_view(dts->view);
80 weston_view_destroy(dts->view);
81 dts->view = NULL;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010082}
83
84static void
85desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
Pekka Paalanen7bcec202017-01-27 17:30:24 +010086 int32_t sx, int32_t sy, void *shell)
Quentin Glidic642bcaf2017-01-27 17:30:23 +010087{
Pekka Paalanen7bcec202017-01-27 17:30:24 +010088 struct desktest_shell *dts = shell;
Quentin Glidic642bcaf2017-01-27 17:30:23 +010089 struct weston_surface *surface =
90 weston_desktop_surface_get_surface(desktop_surface);
91 struct weston_geometry geometry =
92 weston_desktop_surface_get_geometry(desktop_surface);
93
Pekka Paalanen7bcec202017-01-27 17:30:24 +010094 assert(dts->view);
Quentin Glidic642bcaf2017-01-27 17:30:23 +010095
96 if (weston_surface_is_mapped(surface))
97 return;
98
99 surface->is_mapped = true;
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100100 weston_layer_entry_insert(&dts->layer.view_list, &dts->view->layer_link);
101 weston_view_set_position(dts->view, 0 - geometry.x, 0 - geometry.y);
102 weston_view_update_transform(dts->view);
103 dts->view->is_mapped = true;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100104}
105
106static void
107desktop_surface_move(struct weston_desktop_surface *desktop_surface,
108 struct weston_seat *seat, uint32_t serial, void *shell)
109{
110}
111
112static void
113desktop_surface_resize(struct weston_desktop_surface *desktop_surface,
114 struct weston_seat *seat, uint32_t serial,
115 enum weston_desktop_surface_edge edges, void *shell)
116{
117}
118
119static void
120desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface,
121 bool fullscreen,
122 struct weston_output *output, void *shell)
123{
124}
125
126static void
127desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface,
128 bool maximized, void *shell)
129{
130}
131
132static void
133desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface,
134 void *shell)
135{
136}
137
138static void
139desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client,
140 void *shell)
141{
142}
143
144static void
145desktop_surface_pong(struct weston_desktop_client *desktop_client,
146 void *shell)
147{
148}
149
150static const struct weston_desktop_api shell_desktop_api = {
151 .struct_size = sizeof(struct weston_desktop_api),
152 .surface_added = desktop_surface_added,
153 .surface_removed = desktop_surface_removed,
154 .committed = desktop_surface_committed,
155 .move = desktop_surface_move,
156 .resize = desktop_surface_resize,
157 .fullscreen_requested = desktop_surface_fullscreen_requested,
158 .maximized_requested = desktop_surface_maximized_requested,
159 .minimized_requested = desktop_surface_minimized_requested,
160 .ping_timeout = desktop_surface_ping_timeout,
161 .pong = desktop_surface_pong,
162};
163
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100164static void
165shell_destroy(struct wl_listener *listener, void *data)
166{
167 struct desktest_shell *dts;
168
169 dts = container_of(listener, struct desktest_shell,
170 compositor_destroy_listener);
171
172 weston_desktop_destroy(dts->desktop);
173 weston_view_destroy(dts->background_view);
174 weston_surface_destroy(dts->background_surface);
175 free(dts);
176}
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100177
178WL_EXPORT int
179wet_shell_init(struct weston_compositor *ec,
180 int *argc, char *argv[])
181{
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100182 struct desktest_shell *dts;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100183
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100184 dts = zalloc(sizeof *dts);
185 if (!dts)
186 return -1;
187
188 dts->compositor_destroy_listener.notify = shell_destroy;
189 wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener);
190
191 weston_layer_init(&dts->layer, ec);
192 weston_layer_init(&dts->background_layer, ec);
193
194 weston_layer_set_position(&dts->layer,
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100195 WESTON_LAYER_POSITION_NORMAL);
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100196 weston_layer_set_position(&dts->background_layer,
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100197 WESTON_LAYER_POSITION_BACKGROUND);
198
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100199 dts->background_surface = weston_surface_create(ec);
200 if (dts->background_surface == NULL)
201 goto out_free;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100202
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100203 dts->background_view = weston_view_create(dts->background_surface);
204 if (dts->background_view == NULL)
205 goto out_surface;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100206
Pekka Paalanena21b5eb2017-01-27 17:30:25 +0100207 weston_surface_set_color(dts->background_surface, 0.16, 0.32, 0.48, 1.);
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100208 pixman_region32_fini(&dts->background_surface->opaque);
209 pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000);
210 pixman_region32_fini(&dts->background_surface->input);
211 pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000);
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100212
Pekka Paalanen7bcec202017-01-27 17:30:24 +0100213 weston_surface_set_size(dts->background_surface, 2000, 2000);
214 weston_view_set_position(dts->background_view, 0, 0);
215 weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link);
216 weston_view_update_transform(dts->background_view);
217
218 dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts);
219 if (dts->desktop == NULL)
220 goto out_view;
221
222 return 0;
223
224out_view:
225 weston_view_destroy(dts->background_view);
226
227out_surface:
228 weston_surface_destroy(dts->background_surface);
229
230out_free:
231 free(dts);
232
233 return -1;
Quentin Glidic642bcaf2017-01-27 17:30:23 +0100234}