blob: 66c4f01f8f034677038aaf83845409683d918535 [file] [log] [blame]
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001/*
2 * Copyright © 2010 Intel Corporation
Pekka Paalanend581a8f2012-01-27 16:25:16 +02003 * Copyright © 2011-2012 Collabora, Ltd.
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#include <stdlib.h>
Kristian Høgsberg75840622011-09-06 13:48:16 -040025#include <stdio.h>
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020026#include <stdbool.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050027#include <string.h>
28#include <unistd.h>
Kristian Høgsberg07937562011-04-12 17:25:42 -040029#include <linux/input.h>
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020030#include <assert.h>
Pekka Paalanen18027e52011-12-02 16:31:49 +020031#include <signal.h>
Pekka Paalanen460099f2012-01-20 16:48:25 +020032#include <math.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050033
Pekka Paalanen50719bc2011-11-22 14:18:50 +020034#include <wayland-server.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050035#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040036#include "desktop-shell-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020037#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050038
Pekka Paalanen068ae942011-11-28 14:11:15 +020039struct shell_surface;
40
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040041struct wl_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050042 struct weston_compositor *compositor;
43 struct weston_shell shell;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020044
45 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050046 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020047 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020048 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +020049
50 unsigned deathcount;
51 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020052 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020053
54 bool locked;
55 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020056
Pekka Paalanen068ae942011-11-28 14:11:15 +020057 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050058 struct wl_listener lock_surface_listener;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020059 struct wl_list hidden_surface_list;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010060
61 struct wl_list backgrounds;
62 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020063
Pekka Paalanen77346a62011-11-30 16:26:35 +020064 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +020065 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020066 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020067 struct wl_resource *binding;
68 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050069 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020070 } screensaver;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040071};
72
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050073enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020074 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050075
Pekka Paalanen57da4a82011-11-23 16:42:16 +020076 SHELL_SURFACE_PANEL,
77 SHELL_SURFACE_BACKGROUND,
78 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020079 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050080
81 SHELL_SURFACE_TOPLEVEL,
82 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050083 SHELL_SURFACE_FULLSCREEN,
84 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +020085};
86
Pekka Paalanen56cdea92011-11-23 16:14:12 +020087struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020088 struct wl_resource resource;
89
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050090 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020091 struct wl_listener surface_destroy_listener;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050092 struct shell_surface *parent;
Pekka Paalanen57da4a82011-11-23 16:42:16 +020093
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050094 enum shell_surface_type type;
95 int32_t saved_x, saved_y;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010096
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050097 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +020098 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -050099 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200100 } rotation;
101
102 struct {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500103 struct wl_grab grab;
104 uint32_t time;
105 int32_t x, y;
Pekka Paalanen938269a2012-02-07 14:19:01 +0200106 struct weston_transform parent_transform;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500107 int32_t initial_up;
108 } popup;
109
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500110 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100111 struct wl_list link;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200112};
113
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500114struct weston_move_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500115 struct wl_grab grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500116 struct weston_surface *surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500117 int32_t dx, dy;
118};
119
Pekka Paalanen460099f2012-01-20 16:48:25 +0200120struct rotate_grab {
121 struct wl_grab grab;
122 struct shell_surface *surface;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500123 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200124 struct {
125 int32_t x;
126 int32_t y;
127 } center;
128};
129
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500130static void
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200131shell_configuration(struct wl_shell *shell)
132{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200133 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200134 char *path = NULL;
135 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200136
137 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200138 { "path", CONFIG_KEY_STRING, &path },
139 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200140 };
141
142 struct config_section cs[] = {
143 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
144 };
145
Kristian Høgsberg9724b512012-01-03 14:35:49 -0500146 config_file = config_file_path("weston-desktop-shell.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500147 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200148 free(config_file);
149
Pekka Paalanen7296e792011-12-07 16:22:00 +0200150 shell->screensaver.path = path;
151 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200152}
153
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200154static void
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500155noop_grab_focus(struct wl_grab *grab, uint32_t time,
156 struct wl_surface *surface, int32_t x, int32_t y)
157{
158 grab->focus = NULL;
159}
160
161static void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500162move_grab_motion(struct wl_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500163 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500164{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500165 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500166 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500167 struct weston_surface *es = move->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500168
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500169 weston_surface_configure(es,
170 device->x + move->dx,
171 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200172 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500173}
174
175static void
176move_grab_button(struct wl_grab *grab,
177 uint32_t time, int32_t button, int32_t state)
178{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500179 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500180
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500181 if (device->button_count == 0 && state == 0) {
182 wl_input_device_end_grab(device, time);
183 free(grab);
184 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500185}
186
187static const struct wl_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500188 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500189 move_grab_motion,
190 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500191};
192
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400193static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500194weston_surface_move(struct weston_surface *es,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500195 struct weston_input_device *wd, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500196{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500197 struct weston_move_grab *move;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500198
199 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400200 if (!move)
201 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500202
203 move->grab.interface = &move_grab_interface;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200204 move->dx = es->geometry.x - wd->input_device.grab_x;
205 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -0500206 move->surface = es;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500207
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500208 wl_input_device_start_grab(&wd->input_device, &move->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500209
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400210 wl_input_device_set_pointer_focus(&wd->input_device,
211 NULL, time, 0, 0, 0, 0);
212
213 return 0;
214}
215
216static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200217shell_surface_move(struct wl_client *client, struct wl_resource *resource,
218 struct wl_resource *input_resource, uint32_t time)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400219{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500220 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200221 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400222
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500223 if (wd->input_device.button_count == 0 ||
224 wd->input_device.grab_time != time ||
225 wd->input_device.pointer_focus != &shsurf->surface->surface)
226 return;
227
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500228 if (weston_surface_move(shsurf->surface, wd, time) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400229 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500230}
231
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500232struct weston_resize_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500233 struct wl_grab grab;
234 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200235 int32_t width, height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200236 struct shell_surface *shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500237};
238
239static void
240resize_grab_motion(struct wl_grab *grab,
241 uint32_t time, int32_t x, int32_t y)
242{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500243 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500244 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500245 int32_t width, height;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200246 int32_t from_x, from_y;
247 int32_t to_x, to_y;
248
249 weston_surface_from_global(resize->shsurf->surface,
250 device->grab_x, device->grab_y,
251 &from_x, &from_y);
252 weston_surface_from_global(resize->shsurf->surface,
253 device->x, device->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500254
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200255 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200256 width = resize->width + from_x - to_x;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200257 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200258 width = resize->width + to_x - from_x;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500259 } else {
260 width = resize->width;
261 }
262
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200263 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200264 height = resize->height + from_y - to_y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200265 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200266 height = resize->height + to_y - from_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500267 } else {
268 height = resize->height;
269 }
270
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200271 wl_resource_post_event(&resize->shsurf->resource,
272 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
273 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500274}
275
276static void
277resize_grab_button(struct wl_grab *grab,
278 uint32_t time, int32_t button, int32_t state)
279{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500280 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500281
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500282 if (device->button_count == 0 && state == 0) {
283 wl_input_device_end_grab(device, time);
284 free(grab);
285 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500286}
287
288static const struct wl_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500289 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500290 resize_grab_motion,
291 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500292};
293
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400294static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500295weston_surface_resize(struct shell_surface *shsurf,
296 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200297 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500298{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500299 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500300
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500301 /* FIXME: Reject if fullscreen */
302
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200303 if (edges == 0 || edges > 15 ||
304 (edges & 3) == 3 || (edges & 12) == 12)
305 return 0;
306
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500307 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400308 if (!resize)
309 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500310
311 resize->grab.interface = &resize_grab_interface;
312 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200313 resize->width = shsurf->surface->geometry.width;
314 resize->height = shsurf->surface->geometry.height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200315 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400316
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500317 wl_input_device_start_grab(&wd->input_device, &resize->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500318
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400319 wl_input_device_set_pointer_focus(&wd->input_device,
320 NULL, time, 0, 0, 0, 0);
321
322 return 0;
323}
324
325static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200326shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
327 struct wl_resource *input_resource, uint32_t time,
328 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400329{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500330 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200331 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400332
333 /* FIXME: Reject if fullscreen */
334
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500335 if (wd->input_device.button_count == 0 ||
336 wd->input_device.grab_time != time ||
337 wd->input_device.pointer_focus != &shsurf->surface->surface)
338 return;
339
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500340 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400341 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500342}
343
Pekka Paalanen98262232011-12-01 10:42:22 +0200344static int
345reset_shell_surface_type(struct shell_surface *surface)
346{
347 switch (surface->type) {
348 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200349 weston_surface_set_position(surface->surface,
350 surface->saved_x,
351 surface->saved_y);
Pekka Paalanen98262232011-12-01 10:42:22 +0200352 surface->surface->fullscreen_output = NULL;
353 break;
354 case SHELL_SURFACE_PANEL:
355 case SHELL_SURFACE_BACKGROUND:
356 wl_list_remove(&surface->link);
357 wl_list_init(&surface->link);
358 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200359 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200360 case SHELL_SURFACE_LOCK:
361 wl_resource_post_error(&surface->resource,
362 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200363 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200364 return -1;
365 case SHELL_SURFACE_NONE:
366 case SHELL_SURFACE_TOPLEVEL:
367 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500368 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200369 break;
370 }
371
372 surface->type = SHELL_SURFACE_NONE;
373 return 0;
374}
375
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500376static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200377shell_surface_set_toplevel(struct wl_client *client,
378 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400379
380{
Pekka Paalanen98262232011-12-01 10:42:22 +0200381 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400382
Pekka Paalanen98262232011-12-01 10:42:22 +0200383 if (reset_shell_surface_type(surface))
384 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400385
Pekka Paalanen98262232011-12-01 10:42:22 +0200386 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400387}
388
389static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200390shell_surface_set_transient(struct wl_client *client,
391 struct wl_resource *resource,
392 struct wl_resource *parent_resource,
393 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400394{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200395 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500396 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200397 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500398 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400399
Pekka Paalanen98262232011-12-01 10:42:22 +0200400 if (reset_shell_surface_type(shsurf))
401 return;
402
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400403 /* assign to parents output */
404 es->output = pes->output;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200405 weston_surface_set_position(es, pes->geometry.x + x,
406 pes->geometry.y + y);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400407
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200408 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400409}
410
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500411static struct weston_output *
412get_default_output(struct weston_compositor *compositor)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200413{
414 return container_of(compositor->output_list.next,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500415 struct weston_output, link);
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200416}
417
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400418static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200419shell_surface_set_fullscreen(struct wl_client *client,
420 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400421
422{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200423 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500424 struct weston_surface *es = shsurf->surface;
425 struct weston_output *output;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400426
Pekka Paalanen98262232011-12-01 10:42:22 +0200427 if (reset_shell_surface_type(shsurf))
428 return;
429
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400430 /* FIXME: Fullscreen on first output */
431 /* FIXME: Handle output going away */
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200432 output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400433 es->output = output;
434
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200435 shsurf->saved_x = es->geometry.x;
436 shsurf->saved_y = es->geometry.y;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200437 weston_surface_set_position(es,
438 (output->current->width - es->geometry.width) / 2,
439 (output->current->height - es->geometry.height) / 2);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400440 es->fullscreen_output = output;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200441 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400442}
443
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500444static void
445popup_grab_focus(struct wl_grab *grab, uint32_t time,
446 struct wl_surface *surface, int32_t x, int32_t y)
447{
448 struct wl_input_device *device = grab->input_device;
449 struct shell_surface *priv =
450 container_of(grab, struct shell_surface, popup.grab);
451 struct wl_client *client = priv->surface->surface.resource.client;
452
Pekka Paalanencb108432012-01-19 16:25:40 +0200453 if (surface && surface->resource.client == client) {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500454 wl_input_device_set_pointer_focus(device, surface, time,
455 device->x, device->y, x, y);
456 grab->focus = surface;
457 } else {
458 wl_input_device_set_pointer_focus(device, NULL,
459 time, 0, 0, 0, 0);
460 grab->focus = NULL;
461 }
462}
463
464static void
465popup_grab_motion(struct wl_grab *grab,
466 uint32_t time, int32_t x, int32_t y)
467{
468 struct wl_input_device *device = grab->input_device;
469 struct wl_resource *resource;
470
471 resource = grab->input_device->pointer_focus_resource;
472 if (resource)
473 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
474 time, device->x, device->y, x, y);
475}
476
477static void
478popup_grab_button(struct wl_grab *grab,
479 uint32_t time, int32_t button, int32_t state)
480{
481 struct wl_resource *resource;
482 struct shell_surface *shsurf =
483 container_of(grab, struct shell_surface, popup.grab);
484
485 resource = grab->input_device->pointer_focus_resource;
486 if (resource) {
487 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
488 time, button, state);
489 } else if (state == 0 &&
490 (shsurf->popup.initial_up ||
491 time - shsurf->popup.time > 500)) {
492 wl_resource_post_event(&shsurf->resource,
493 WL_SHELL_SURFACE_POPUP_DONE);
494 wl_input_device_end_grab(grab->input_device, time);
495 shsurf->popup.grab.input_device = NULL;
496 }
497
498 if (state == 0)
499 shsurf->popup.initial_up = 1;
500}
501
502static const struct wl_grab_interface popup_grab_interface = {
503 popup_grab_focus,
504 popup_grab_motion,
505 popup_grab_button,
506};
507
508static void
509shell_map_popup(struct shell_surface *shsurf, uint32_t time)
510{
511 struct wl_input_device *device;
512 struct weston_surface *es = shsurf->surface;
513 struct weston_surface *parent = shsurf->parent->surface;
514
515 es->output = parent->output;
516
517 shsurf->popup.grab.interface = &popup_grab_interface;
518 device = es->compositor->input_device;
519
Pekka Paalanen938269a2012-02-07 14:19:01 +0200520 weston_surface_update_transform(parent);
521 if (parent->transform.enabled) {
522 shsurf->popup.parent_transform.matrix =
523 parent->transform.matrix;
524 } else {
525 /* construct x, y translation matrix */
526 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
527 shsurf->popup.parent_transform.matrix.d[12] =
528 parent->geometry.x;
529 shsurf->popup.parent_transform.matrix.d[13] =
530 parent->geometry.y;
531 }
532 wl_list_insert(es->geometry.transformation_list.prev,
533 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200534 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500535
536 shsurf->popup.grab.input_device = device;
537 shsurf->popup.time = device->grab_time;
538 shsurf->popup.initial_up = 0;
539
540 wl_input_device_start_grab(shsurf->popup.grab.input_device,
541 &shsurf->popup.grab, shsurf->popup.time);
542}
543
544static void
545shell_surface_set_popup(struct wl_client *client,
546 struct wl_resource *resource,
547 struct wl_resource *input_device_resource,
548 uint32_t time,
549 struct wl_resource *parent_resource,
550 int32_t x, int32_t y, uint32_t flags)
551{
552 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500553
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500554 shsurf->type = SHELL_SURFACE_POPUP;
555 shsurf->parent = parent_resource->data;
556 shsurf->popup.x = x;
557 shsurf->popup.y = y;
558}
559
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200560static const struct wl_shell_surface_interface shell_surface_implementation = {
561 shell_surface_move,
562 shell_surface_resize,
563 shell_surface_set_toplevel,
564 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500565 shell_surface_set_fullscreen,
566 shell_surface_set_popup
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200567};
568
569static void
570destroy_shell_surface(struct wl_resource *resource)
571{
572 struct shell_surface *shsurf = resource->data;
573
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500574 if (shsurf->popup.grab.input_device)
575 wl_input_device_end_grab(shsurf->popup.grab.input_device, 0);
576
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200577 /* in case cleaning up a dead client destroys shell_surface first */
578 if (shsurf->surface)
579 wl_list_remove(&shsurf->surface_destroy_listener.link);
580
581 wl_list_remove(&shsurf->link);
582 free(shsurf);
583}
584
585static void
586shell_handle_surface_destroy(struct wl_listener *listener,
587 struct wl_resource *resource, uint32_t time)
588{
589 struct shell_surface *shsurf = container_of(listener,
590 struct shell_surface,
591 surface_destroy_listener);
592
593 shsurf->surface = NULL;
594 wl_resource_destroy(&shsurf->resource, time);
595}
596
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200597static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500598get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200599{
600 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
601 struct wl_listener *listener;
602
603 /* search the destroy listener list for our callback */
604 wl_list_for_each(listener, lst, link) {
605 if (listener->func == shell_handle_surface_destroy) {
606 return container_of(listener, struct shell_surface,
607 surface_destroy_listener);
608 }
609 }
610
611 return NULL;
612}
613
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200614static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200615shell_get_shell_surface(struct wl_client *client,
616 struct wl_resource *resource,
617 uint32_t id,
618 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200619{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500620 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200621 struct shell_surface *shsurf;
622
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200623 if (get_shell_surface(surface)) {
624 wl_resource_post_error(surface_resource,
625 WL_DISPLAY_ERROR_INVALID_OBJECT,
626 "wl_shell::get_shell_surface already requested");
627 return;
628 }
629
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200630 shsurf = calloc(1, sizeof *shsurf);
631 if (!shsurf) {
632 wl_resource_post_no_memory(resource);
633 return;
634 }
635
636 shsurf->resource.destroy = destroy_shell_surface;
637 shsurf->resource.object.id = id;
638 shsurf->resource.object.interface = &wl_shell_surface_interface;
639 shsurf->resource.object.implementation =
640 (void (**)(void)) &shell_surface_implementation;
641 shsurf->resource.data = shsurf;
642
643 shsurf->surface = surface;
644 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
645 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
646 &shsurf->surface_destroy_listener.link);
647
648 /* init link so its safe to always remove it in destroy_shell_surface */
649 wl_list_init(&shsurf->link);
650
Pekka Paalanen460099f2012-01-20 16:48:25 +0200651 /* empty when not in use */
652 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500653 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200654
Pekka Paalanen98262232011-12-01 10:42:22 +0200655 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200656
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200657 wl_client_add_resource(client, &shsurf->resource);
658}
659
660static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200661 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500662};
663
Kristian Høgsberg07937562011-04-12 17:25:42 -0400664static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500665handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200666{
667 proc->pid = 0;
668}
669
670static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200671launch_screensaver(struct wl_shell *shell)
672{
673 if (shell->screensaver.binding)
674 return;
675
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200676 if (!shell->screensaver.path)
677 return;
678
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500679 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200680 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200681 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200682 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200683}
684
685static void
686terminate_screensaver(struct wl_shell *shell)
687{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200688 if (shell->screensaver.process.pid == 0)
689 return;
690
691 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200692}
693
694static void
695show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
696{
697 struct wl_list *list;
698
699 if (shell->lock_surface)
700 list = &shell->lock_surface->surface->link;
701 else
702 list = &shell->compositor->surface_list;
703
704 wl_list_remove(&surface->surface->link);
705 wl_list_insert(list, &surface->surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200706 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200707 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200708}
709
710static void
711hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
712{
713 wl_list_remove(&surface->surface->link);
714 wl_list_init(&surface->surface->link);
715 surface->surface->output = NULL;
716}
717
718static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400719desktop_shell_set_background(struct wl_client *client,
720 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100721 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400722 struct wl_resource *surface_resource)
723{
724 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200725 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500726 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200727 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400728
Pekka Paalanen98262232011-12-01 10:42:22 +0200729 if (reset_shell_surface_type(shsurf))
730 return;
731
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100732 wl_list_for_each(priv, &shell->backgrounds, link) {
733 if (priv->output == output_resource->data) {
734 priv->surface->output = NULL;
735 wl_list_remove(&priv->surface->link);
736 wl_list_remove(&priv->link);
737 break;
738 }
739 }
740
Pekka Paalanen068ae942011-11-28 14:11:15 +0200741 shsurf->type = SHELL_SURFACE_BACKGROUND;
742 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100743
Pekka Paalanen068ae942011-11-28 14:11:15 +0200744 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100745
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200746 weston_surface_set_position(surface, shsurf->output->x,
747 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200748
Kristian Høgsberg75840622011-09-06 13:48:16 -0400749 wl_resource_post_event(resource,
750 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500751 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200752 shsurf->output->current->width,
753 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400754}
755
756static void
757desktop_shell_set_panel(struct wl_client *client,
758 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100759 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400760 struct wl_resource *surface_resource)
761{
762 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200763 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500764 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200765 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400766
Pekka Paalanen98262232011-12-01 10:42:22 +0200767 if (reset_shell_surface_type(shsurf))
768 return;
769
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100770 wl_list_for_each(priv, &shell->panels, link) {
771 if (priv->output == output_resource->data) {
772 priv->surface->output = NULL;
773 wl_list_remove(&priv->surface->link);
774 wl_list_remove(&priv->link);
775 break;
776 }
777 }
778
Pekka Paalanen068ae942011-11-28 14:11:15 +0200779 shsurf->type = SHELL_SURFACE_PANEL;
780 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100781
Pekka Paalanen068ae942011-11-28 14:11:15 +0200782 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100783
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200784 weston_surface_set_position(surface, shsurf->output->x,
785 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200786
Kristian Høgsberg75840622011-09-06 13:48:16 -0400787 wl_resource_post_event(resource,
788 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500789 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200790 shsurf->output->current->width,
791 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400792}
793
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200794static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500795handle_lock_surface_destroy(struct wl_listener *listener,
796 struct wl_resource *resource, uint32_t time)
797{
798 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +0200799 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500800
801 fprintf(stderr, "lock surface gone\n");
802 shell->lock_surface = NULL;
803}
804
805static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200806desktop_shell_set_lock_surface(struct wl_client *client,
807 struct wl_resource *resource,
808 struct wl_resource *surface_resource)
809{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200810 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200811 struct shell_surface *surface = surface_resource->data;
812
813 if (reset_shell_surface_type(surface))
814 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200815
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200816 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200817
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200818 if (!shell->locked)
819 return;
820
Pekka Paalanen98262232011-12-01 10:42:22 +0200821 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200822
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500823 shell->lock_surface_listener.func = handle_lock_surface_destroy;
824 wl_list_insert(&surface_resource->destroy_listener_list,
825 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200826
Pekka Paalanen068ae942011-11-28 14:11:15 +0200827 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200828}
829
830static void
831resume_desktop(struct wl_shell *shell)
832{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500833 struct weston_surface *surface;
Pekka Paalanenfe340832011-11-25 16:07:52 +0200834 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200835 struct shell_surface *tmp;
836
837 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
838 hide_screensaver(shell, tmp);
839
840 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200841
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200842 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +0200843 weston_surface_assign_output(surface);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200844
Pekka Paalanenfe340832011-11-25 16:07:52 +0200845 if (wl_list_empty(&shell->backgrounds)) {
846 list = &shell->compositor->surface_list;
847 } else {
848 struct shell_surface *background;
849 background = container_of(shell->backgrounds.prev,
850 struct shell_surface, link);
851 list = background->surface->link.prev;
852 }
853
854 if (!wl_list_empty(&shell->hidden_surface_list))
855 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500856 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200857
858 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500859 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200860 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500861 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200862 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200863}
864
865static void
866desktop_shell_unlock(struct wl_client *client,
867 struct wl_resource *resource)
868{
869 struct wl_shell *shell = resource->data;
870
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200871 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200872
873 if (shell->locked)
874 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200875}
876
Kristian Høgsberg75840622011-09-06 13:48:16 -0400877static const struct desktop_shell_interface desktop_shell_implementation = {
878 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200879 desktop_shell_set_panel,
880 desktop_shell_set_lock_surface,
881 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400882};
883
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200884static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500885get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200886{
887 struct shell_surface *shsurf;
888
889 shsurf = get_shell_surface(surface);
890 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200891 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200892 return shsurf->type;
893}
894
Kristian Høgsberg75840622011-09-06 13:48:16 -0400895static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400896move_binding(struct wl_input_device *device, uint32_t time,
897 uint32_t key, uint32_t button, uint32_t state, void *data)
898{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500899 struct weston_surface *surface =
900 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500901
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100902 if (surface == NULL)
903 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400904
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200905 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100906 case SHELL_SURFACE_PANEL:
907 case SHELL_SURFACE_BACKGROUND:
908 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200909 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100910 return;
911 default:
912 break;
913 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400914
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500915 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400916}
917
918static void
919resize_binding(struct wl_input_device *device, uint32_t time,
920 uint32_t key, uint32_t button, uint32_t state, void *data)
921{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500922 struct weston_surface *surface =
923 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400924 uint32_t edges = 0;
925 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200926 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500927
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100928 if (surface == NULL)
929 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200930
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200931 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200932 if (!shsurf)
933 return;
934
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200935 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100936 case SHELL_SURFACE_PANEL:
937 case SHELL_SURFACE_BACKGROUND:
938 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200939 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100940 return;
941 default:
942 break;
943 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400944
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200945 weston_surface_from_global(surface,
946 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400947
Pekka Paalanen60921e52012-01-25 15:55:43 +0200948 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200949 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200950 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400951 edges |= 0;
952 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200953 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400954
Pekka Paalanen60921e52012-01-25 15:55:43 +0200955 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200956 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200957 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400958 edges |= 0;
959 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200960 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400961
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500962 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200963 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400964}
965
966static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500967terminate_binding(struct wl_input_device *device, uint32_t time,
968 uint32_t key, uint32_t button, uint32_t state, void *data)
969{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500970 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500971
972 if (state)
973 wl_display_terminate(compositor->wl_display);
974}
975
976static void
Pekka Paalanen460099f2012-01-20 16:48:25 +0200977rotate_grab_motion(struct wl_grab *grab,
978 uint32_t time, int32_t x, int32_t y)
979{
980 struct rotate_grab *rotate =
981 container_of(grab, struct rotate_grab, grab);
982 struct wl_input_device *device = grab->input_device;
983 struct shell_surface *surface = rotate->surface;
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +0200984 GLfloat cx = 0.5f * surface->surface->geometry.width;
985 GLfloat cy = 0.5f * surface->surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200986 GLfloat dx, dy;
987 GLfloat r;
988
989 dx = device->x - rotate->center.x;
990 dy = device->y - rotate->center.y;
991 r = sqrtf(dx * dx + dy * dy);
992
993 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200994 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200995
996 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200997 struct weston_matrix *matrix =
998 &surface->rotation.transform.matrix;
999
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001000 weston_matrix_init(&rotate->rotation);
1001 rotate->rotation.d[0] = dx / r;
1002 rotate->rotation.d[4] = -dy / r;
1003 rotate->rotation.d[1] = -rotate->rotation.d[4];
1004 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001005
1006 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001007 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001008 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1009 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001010 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001011
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001012 wl_list_insert(
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001013 &surface->surface->geometry.transformation_list,
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001014 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001015 } else {
1016 wl_list_init(&surface->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001017 weston_matrix_init(&surface->rotation.rotation);
1018 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001019 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001020
1021 /* Repaint implies weston_surface_update_transform(), which
1022 * lazily applies the damage due to rotation update.
1023 */
1024 weston_compositor_schedule_repaint(surface->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001025}
1026
1027static void
1028rotate_grab_button(struct wl_grab *grab,
1029 uint32_t time, int32_t button, int32_t state)
1030{
1031 struct rotate_grab *rotate =
1032 container_of(grab, struct rotate_grab, grab);
1033 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001034 struct shell_surface *surface = rotate->surface;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001035
1036 if (device->button_count == 0 && state == 0) {
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001037 weston_matrix_multiply(&surface->rotation.rotation,
1038 &rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001039 wl_input_device_end_grab(device, time);
1040 free(rotate);
1041 }
1042}
1043
1044static const struct wl_grab_interface rotate_grab_interface = {
1045 noop_grab_focus,
1046 rotate_grab_motion,
1047 rotate_grab_button,
1048};
1049
1050static void
1051rotate_binding(struct wl_input_device *device, uint32_t time,
1052 uint32_t key, uint32_t button, uint32_t state, void *data)
1053{
1054 struct weston_surface *base_surface =
1055 (struct weston_surface *) device->pointer_focus;
1056 struct shell_surface *surface;
1057 struct rotate_grab *rotate;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001058 GLfloat dx, dy;
1059 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001060
1061 if (base_surface == NULL)
1062 return;
1063
1064 surface = get_shell_surface(base_surface);
1065 if (!surface)
1066 return;
1067
1068 switch (surface->type) {
1069 case SHELL_SURFACE_PANEL:
1070 case SHELL_SURFACE_BACKGROUND:
1071 case SHELL_SURFACE_FULLSCREEN:
1072 case SHELL_SURFACE_SCREENSAVER:
1073 return;
1074 default:
1075 break;
1076 }
1077
Pekka Paalanen460099f2012-01-20 16:48:25 +02001078 rotate = malloc(sizeof *rotate);
1079 if (!rotate)
1080 return;
1081
1082 rotate->grab.interface = &rotate_grab_interface;
1083 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001084
1085 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001086 surface->surface->geometry.width / 2,
1087 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001088 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001089
1090 wl_input_device_start_grab(device, &rotate->grab, time);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001091
1092 dx = device->x - rotate->center.x;
1093 dy = device->y - rotate->center.y;
1094 r = sqrtf(dx * dx + dy * dy);
1095 if (r > 20.0f) {
1096 struct weston_matrix inverse;
1097
1098 weston_matrix_init(&inverse);
1099 inverse.d[0] = dx / r;
1100 inverse.d[4] = dy / r;
1101 inverse.d[1] = -inverse.d[4];
1102 inverse.d[5] = inverse.d[0];
1103 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1104 } else {
1105 weston_matrix_init(&surface->rotation.rotation);
1106 weston_matrix_init(&rotate->rotation);
1107 }
1108
Pekka Paalanen460099f2012-01-20 16:48:25 +02001109 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
1110}
1111
1112static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001113activate(struct weston_shell *base, struct weston_surface *es,
1114 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001115{
1116 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001117 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001118 struct wl_list *list;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001119
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001120 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001121
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001122 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001123 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001124
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001125 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001126 case SHELL_SURFACE_BACKGROUND:
1127 /* put background back to bottom */
Kristian Høgsberg75840622011-09-06 13:48:16 -04001128 wl_list_remove(&es->link);
1129 wl_list_insert(compositor->surface_list.prev, &es->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001130 break;
1131 case SHELL_SURFACE_PANEL:
1132 /* already put on top */
1133 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001134 case SHELL_SURFACE_SCREENSAVER:
1135 /* always below lock surface */
1136 if (shell->lock_surface) {
1137 wl_list_remove(&es->link);
1138 wl_list_insert(&shell->lock_surface->surface->link,
1139 &es->link);
1140 }
1141 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001142 default:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001143 if (!shell->locked) {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001144 list = weston_compositor_top(compositor);
1145
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001146 /* bring panel back to top */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001147 struct shell_surface *panel;
1148 wl_list_for_each(panel, &shell->panels, link) {
1149 wl_list_remove(&panel->surface->link);
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001150 wl_list_insert(list, &panel->surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001151 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001152 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001153 }
1154}
1155
1156static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001157click_to_activate_binding(struct wl_input_device *device,
1158 uint32_t time, uint32_t key,
1159 uint32_t button, uint32_t state, void *data)
1160{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001161 struct weston_input_device *wd = (struct weston_input_device *) device;
1162 struct weston_compositor *compositor = data;
1163 struct weston_surface *focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001164
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001165 focus = (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001166 if (state && focus && device->grab == &device->default_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001167 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001168}
1169
1170static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001171lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001172{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001173 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001174 struct wl_list *surface_list = &shell->compositor->surface_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001175 struct weston_surface *cur;
1176 struct weston_surface *tmp;
1177 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001178 struct shell_surface *shsurf;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001179 uint32_t time;
1180
1181 if (shell->locked)
1182 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001183
1184 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001185
1186 /* Move all surfaces from compositor's list to our hidden list,
1187 * except the background. This way nothing else can show or
1188 * receive input events while we are locked. */
1189
1190 if (!wl_list_empty(&shell->hidden_surface_list)) {
1191 fprintf(stderr,
1192 "%s: Assertion failed: hidden_surface_list is not empty.\n",
1193 __func__);
1194 }
1195
1196 wl_list_for_each_safe(cur, tmp, surface_list, link) {
1197 /* skip input device sprites, cur->surface is uninitialised */
1198 if (cur->surface.resource.client == NULL)
1199 continue;
1200
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001201 if (get_shell_surface_type(cur) == SHELL_SURFACE_BACKGROUND)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001202 continue;
1203
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001204 cur->output = NULL;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001205 wl_list_remove(&cur->link);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001206 wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001207 }
1208
Pekka Paalanen77346a62011-11-30 16:26:35 +02001209 launch_screensaver(shell);
1210
1211 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1212 show_screensaver(shell, shsurf);
1213
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001214 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001215 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001216 weston_compositor_wake(shell->compositor);
1217 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001218 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001219
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001220 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001221 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001222
1223 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001224 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001225 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1226 wl_input_device_set_keyboard_focus(&device->input_device,
1227 NULL, time);
1228 }
1229
1230 /* TODO: disable bindings that should not work while locked. */
1231
1232 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001233}
1234
1235static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001236unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001237{
1238 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1239
Pekka Paalanend81c2162011-11-16 13:47:34 +02001240 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001241 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001242 return;
1243 }
1244
1245 /* If desktop-shell client has gone away, unlock immediately. */
1246 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001247 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001248 return;
1249 }
1250
1251 if (shell->prepare_event_sent)
1252 return;
1253
1254 wl_resource_post_event(shell->child.desktop_shell,
1255 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1256 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001257}
1258
1259static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001260center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001261{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001262 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001263 GLfloat x = (mode->width - surface->geometry.width) / 2;
1264 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001265
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001266 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001267}
1268
1269static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001270map(struct weston_shell *base,
1271 struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001272{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001273 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001274 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001275 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001276 struct shell_surface *shsurf;
1277 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1278 int do_configure;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001279
Pekka Paalanen77346a62011-11-30 16:26:35 +02001280 shsurf = get_shell_surface(surface);
1281 if (shsurf)
1282 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001283
Pekka Paalanen77346a62011-11-30 16:26:35 +02001284 if (shell->locked) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001285 list = &shell->hidden_surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001286 do_configure = 0;
1287 } else {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001288 list = weston_compositor_top(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001289 do_configure = 1;
1290 }
1291
Pekka Paalanen60921e52012-01-25 15:55:43 +02001292 surface->geometry.width = width;
1293 surface->geometry.height = height;
1294 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001295
1296 /* initial positioning, see also configure() */
1297 switch (surface_type) {
1298 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001299 weston_surface_set_position(surface, 10 + random() % 400,
1300 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001301 break;
1302 case SHELL_SURFACE_SCREENSAVER:
1303 case SHELL_SURFACE_FULLSCREEN:
1304 center_on_output(surface, surface->fullscreen_output);
1305 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001306 case SHELL_SURFACE_LOCK:
1307 center_on_output(surface, get_default_output(compositor));
1308 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001309 case SHELL_SURFACE_POPUP:
1310 shell_map_popup(shsurf, shsurf->popup.time);
1311 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001312 default:
1313 ;
1314 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001315
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001316 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001317 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001318 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001319 /* background always visible, at the bottom */
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001320 wl_list_insert(compositor->surface_list.prev, &surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001321 do_configure = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001322 break;
1323 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001324 /* panel always on top, hidden while locked */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001325 wl_list_insert(list, &surface->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001326 break;
1327 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001328 /* lock surface always visible, on top */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001329 wl_list_insert(&compositor->surface_list, &surface->link);
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001330
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001331 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001332 do_configure = 1;
1333 break;
1334 case SHELL_SURFACE_SCREENSAVER:
1335 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001336 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001337 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001338 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001339 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001340 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001341 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001342 }
Pekka Paalanen77346a62011-11-30 16:26:35 +02001343 do_configure = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001344 break;
1345 default:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001346 /* everything else just below the panel */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001347 if (!wl_list_empty(&shell->panels)) {
1348 struct shell_surface *panel =
1349 container_of(shell->panels.prev,
1350 struct shell_surface, link);
1351 wl_list_insert(&panel->surface->link, &surface->link);
1352 } else {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001353 wl_list_insert(list, &surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001354 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001355 }
1356
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001357 if (do_configure) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001358 weston_surface_assign_output(surface);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001359 weston_compositor_repick(compositor);
1360 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001361
Juan Zhao7bb92f02011-12-15 11:31:51 -05001362 switch (surface_type) {
1363 case SHELL_SURFACE_TOPLEVEL:
1364 case SHELL_SURFACE_TRANSIENT:
1365 case SHELL_SURFACE_FULLSCREEN:
1366 if (!shell->locked)
1367 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001368 (struct weston_input_device *)
Juan Zhao7bb92f02011-12-15 11:31:51 -05001369 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001370 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001371 break;
1372 default:
1373 break;
1374 }
1375
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001376 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001377 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001378}
1379
1380static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001381configure(struct weston_shell *base, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001382 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001383{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001384 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1385 int do_configure = !shell->locked;
1386 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1387 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001388
Pekka Paalanen77346a62011-11-30 16:26:35 +02001389 shsurf = get_shell_surface(surface);
1390 if (shsurf)
1391 surface_type = shsurf->type;
1392
Pekka Paalanen60921e52012-01-25 15:55:43 +02001393 surface->geometry.width = width;
1394 surface->geometry.height = height;
1395 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001396
1397 switch (surface_type) {
1398 case SHELL_SURFACE_SCREENSAVER:
1399 do_configure = !do_configure;
1400 /* fall through */
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001401 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001402 center_on_output(surface, surface->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001403 break;
1404 default:
1405 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001406 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001407
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001408 /* XXX: would a fullscreen surface need the same handling? */
Pekka Paalanen77346a62011-11-30 16:26:35 +02001409 if (do_configure) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001410 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001411 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001412
1413 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1414 surface->output = shsurf->output;
1415 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001416}
1417
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001418static int launch_desktop_shell_process(struct wl_shell *shell);
1419
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001420static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001421desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001422{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001423 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001424 struct wl_shell *shell =
1425 container_of(process, struct wl_shell, child.process);
1426
1427 shell->child.process.pid = 0;
1428 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001429
1430 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1431 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001432 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001433 shell->child.deathstamp = time;
1434 shell->child.deathcount = 0;
1435 }
1436
1437 shell->child.deathcount++;
1438 if (shell->child.deathcount > 5) {
1439 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1440 return;
1441 }
1442
1443 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1444 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001445}
1446
1447static int
1448launch_desktop_shell_process(struct wl_shell *shell)
1449{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001450 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001451
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001452 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001453 &shell->child.process,
1454 shell_exe,
1455 desktop_shell_sigchld);
1456
1457 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001458 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001459 return 0;
1460}
1461
1462static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001463bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1464{
1465 struct wl_shell *shell = data;
1466
1467 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001468 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001469}
1470
Kristian Høgsberg75840622011-09-06 13:48:16 -04001471static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001472unbind_desktop_shell(struct wl_resource *resource)
1473{
1474 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001475
1476 if (shell->locked)
1477 resume_desktop(shell);
1478
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001479 shell->child.desktop_shell = NULL;
1480 shell->prepare_event_sent = false;
1481 free(resource);
1482}
1483
1484static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001485bind_desktop_shell(struct wl_client *client,
1486 void *data, uint32_t version, uint32_t id)
1487{
1488 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001489 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001490
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001491 resource = wl_client_add_object(client, &desktop_shell_interface,
1492 &desktop_shell_implementation,
1493 id, shell);
1494
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001495 if (client == shell->child.client) {
1496 resource->destroy = unbind_desktop_shell;
1497 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001498 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001499 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001500
1501 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1502 "permission to bind desktop_shell denied");
1503 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001504}
1505
Pekka Paalanen6e168112011-11-24 11:34:05 +02001506static void
1507screensaver_set_surface(struct wl_client *client,
1508 struct wl_resource *resource,
1509 struct wl_resource *shell_surface_resource,
1510 struct wl_resource *output_resource)
1511{
1512 struct wl_shell *shell = resource->data;
1513 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001514 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001515
Pekka Paalanen98262232011-12-01 10:42:22 +02001516 if (reset_shell_surface_type(surface))
1517 return;
1518
Pekka Paalanen77346a62011-11-30 16:26:35 +02001519 surface->type = SHELL_SURFACE_SCREENSAVER;
1520
1521 surface->surface->fullscreen_output = output;
1522 surface->output = output;
1523 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001524}
1525
1526static const struct screensaver_interface screensaver_implementation = {
1527 screensaver_set_surface
1528};
1529
1530static void
1531unbind_screensaver(struct wl_resource *resource)
1532{
1533 struct wl_shell *shell = resource->data;
1534
Pekka Paalanen77346a62011-11-30 16:26:35 +02001535 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001536 free(resource);
1537}
1538
1539static void
1540bind_screensaver(struct wl_client *client,
1541 void *data, uint32_t version, uint32_t id)
1542{
1543 struct wl_shell *shell = data;
1544 struct wl_resource *resource;
1545
1546 resource = wl_client_add_object(client, &screensaver_interface,
1547 &screensaver_implementation,
1548 id, shell);
1549
Pekka Paalanen77346a62011-11-30 16:26:35 +02001550 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001551 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001552 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001553 return;
1554 }
1555
1556 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1557 "interface object already bound");
1558 wl_resource_destroy(resource, 0);
1559}
1560
Pekka Paalanen3c647232011-12-22 13:43:43 +02001561static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001562shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001563{
1564 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1565
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001566 if (shell->child.client)
1567 wl_client_destroy(shell->child.client);
1568
Pekka Paalanen3c647232011-12-22 13:43:43 +02001569 free(shell->screensaver.path);
1570 free(shell);
1571}
1572
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001573int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001574shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001575
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001576WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001577shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001578{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001579 struct wl_shell *shell;
1580
1581 shell = malloc(sizeof *shell);
1582 if (shell == NULL)
1583 return -1;
1584
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001585 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001586 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001587 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001588 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001589 shell->shell.map = map;
1590 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02001591 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001592
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001593 wl_list_init(&shell->hidden_surface_list);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001594 wl_list_init(&shell->backgrounds);
1595 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001596 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001597
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001598 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001599
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001600 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
1601 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001602 return -1;
1603
Kristian Høgsberg75840622011-09-06 13:48:16 -04001604 if (wl_display_add_global(ec->wl_display,
1605 &desktop_shell_interface,
1606 shell, bind_desktop_shell) == NULL)
1607 return -1;
1608
Pekka Paalanen6e168112011-11-24 11:34:05 +02001609 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
1610 shell, bind_screensaver) == NULL)
1611 return -1;
1612
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001613 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001614 if (launch_desktop_shell_process(shell) != 0)
1615 return -1;
1616
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001617 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001618 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001619 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001620 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001621 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001622 MODIFIER_CTRL | MODIFIER_ALT,
1623 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001624 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001625 click_to_activate_binding, ec);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001626 weston_compositor_add_binding(ec, 0, BTN_LEFT,
1627 MODIFIER_SUPER | MODIFIER_ALT,
1628 rotate_binding, NULL);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001629
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001630 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001631
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001632 return 0;
1633}