blob: f67a8940427adf70981eef677d37619831c26429 [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 Paalanenba3cf952012-01-25 16:22:05 +0200349 surface->surface->geometry.x = surface->saved_x;
350 surface->surface->geometry.y = surface->saved_y;
351 surface->surface->geometry.dirty = 1;
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;
405
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200406 es->geometry.x = pes->geometry.x + x;
407 es->geometry.y = pes->geometry.y + y;
408 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400409
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200410 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400411}
412
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500413static struct weston_output *
414get_default_output(struct weston_compositor *compositor)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200415{
416 return container_of(compositor->output_list.next,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500417 struct weston_output, link);
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200418}
419
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400420static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200421shell_surface_set_fullscreen(struct wl_client *client,
422 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400423
424{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200425 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500426 struct weston_surface *es = shsurf->surface;
427 struct weston_output *output;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400428
Pekka Paalanen98262232011-12-01 10:42:22 +0200429 if (reset_shell_surface_type(shsurf))
430 return;
431
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400432 /* FIXME: Fullscreen on first output */
433 /* FIXME: Handle output going away */
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200434 output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400435 es->output = output;
436
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200437 shsurf->saved_x = es->geometry.x;
438 shsurf->saved_y = es->geometry.y;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200439 es->geometry.x = (output->current->width - es->geometry.width) / 2;
440 es->geometry.y = (output->current->height - es->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200441 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400442 es->fullscreen_output = output;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200443 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400444}
445
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500446static void
447popup_grab_focus(struct wl_grab *grab, uint32_t time,
448 struct wl_surface *surface, int32_t x, int32_t y)
449{
450 struct wl_input_device *device = grab->input_device;
451 struct shell_surface *priv =
452 container_of(grab, struct shell_surface, popup.grab);
453 struct wl_client *client = priv->surface->surface.resource.client;
454
Pekka Paalanencb108432012-01-19 16:25:40 +0200455 if (surface && surface->resource.client == client) {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500456 wl_input_device_set_pointer_focus(device, surface, time,
457 device->x, device->y, x, y);
458 grab->focus = surface;
459 } else {
460 wl_input_device_set_pointer_focus(device, NULL,
461 time, 0, 0, 0, 0);
462 grab->focus = NULL;
463 }
464}
465
466static void
467popup_grab_motion(struct wl_grab *grab,
468 uint32_t time, int32_t x, int32_t y)
469{
470 struct wl_input_device *device = grab->input_device;
471 struct wl_resource *resource;
472
473 resource = grab->input_device->pointer_focus_resource;
474 if (resource)
475 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
476 time, device->x, device->y, x, y);
477}
478
479static void
480popup_grab_button(struct wl_grab *grab,
481 uint32_t time, int32_t button, int32_t state)
482{
483 struct wl_resource *resource;
484 struct shell_surface *shsurf =
485 container_of(grab, struct shell_surface, popup.grab);
486
487 resource = grab->input_device->pointer_focus_resource;
488 if (resource) {
489 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
490 time, button, state);
491 } else if (state == 0 &&
492 (shsurf->popup.initial_up ||
493 time - shsurf->popup.time > 500)) {
494 wl_resource_post_event(&shsurf->resource,
495 WL_SHELL_SURFACE_POPUP_DONE);
496 wl_input_device_end_grab(grab->input_device, time);
497 shsurf->popup.grab.input_device = NULL;
498 }
499
500 if (state == 0)
501 shsurf->popup.initial_up = 1;
502}
503
504static const struct wl_grab_interface popup_grab_interface = {
505 popup_grab_focus,
506 popup_grab_motion,
507 popup_grab_button,
508};
509
510static void
511shell_map_popup(struct shell_surface *shsurf, uint32_t time)
512{
513 struct wl_input_device *device;
514 struct weston_surface *es = shsurf->surface;
515 struct weston_surface *parent = shsurf->parent->surface;
516
517 es->output = parent->output;
518
519 shsurf->popup.grab.interface = &popup_grab_interface;
520 device = es->compositor->input_device;
521
Pekka Paalanen938269a2012-02-07 14:19:01 +0200522 weston_surface_update_transform(parent);
523 if (parent->transform.enabled) {
524 shsurf->popup.parent_transform.matrix =
525 parent->transform.matrix;
526 } else {
527 /* construct x, y translation matrix */
528 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
529 shsurf->popup.parent_transform.matrix.d[12] =
530 parent->geometry.x;
531 shsurf->popup.parent_transform.matrix.d[13] =
532 parent->geometry.y;
533 }
534 wl_list_insert(es->geometry.transformation_list.prev,
535 &shsurf->popup.parent_transform.link);
536 es->geometry.x = shsurf->popup.x;
537 es->geometry.y = shsurf->popup.y;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200538 es->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500539
540 shsurf->popup.grab.input_device = device;
541 shsurf->popup.time = device->grab_time;
542 shsurf->popup.initial_up = 0;
543
544 wl_input_device_start_grab(shsurf->popup.grab.input_device,
545 &shsurf->popup.grab, shsurf->popup.time);
546}
547
548static void
549shell_surface_set_popup(struct wl_client *client,
550 struct wl_resource *resource,
551 struct wl_resource *input_device_resource,
552 uint32_t time,
553 struct wl_resource *parent_resource,
554 int32_t x, int32_t y, uint32_t flags)
555{
556 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500557
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500558 shsurf->type = SHELL_SURFACE_POPUP;
559 shsurf->parent = parent_resource->data;
560 shsurf->popup.x = x;
561 shsurf->popup.y = y;
562}
563
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200564static const struct wl_shell_surface_interface shell_surface_implementation = {
565 shell_surface_move,
566 shell_surface_resize,
567 shell_surface_set_toplevel,
568 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500569 shell_surface_set_fullscreen,
570 shell_surface_set_popup
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200571};
572
573static void
574destroy_shell_surface(struct wl_resource *resource)
575{
576 struct shell_surface *shsurf = resource->data;
577
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500578 if (shsurf->popup.grab.input_device)
579 wl_input_device_end_grab(shsurf->popup.grab.input_device, 0);
580
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200581 /* in case cleaning up a dead client destroys shell_surface first */
582 if (shsurf->surface)
583 wl_list_remove(&shsurf->surface_destroy_listener.link);
584
585 wl_list_remove(&shsurf->link);
586 free(shsurf);
587}
588
589static void
590shell_handle_surface_destroy(struct wl_listener *listener,
591 struct wl_resource *resource, uint32_t time)
592{
593 struct shell_surface *shsurf = container_of(listener,
594 struct shell_surface,
595 surface_destroy_listener);
596
597 shsurf->surface = NULL;
598 wl_resource_destroy(&shsurf->resource, time);
599}
600
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200601static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500602get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200603{
604 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
605 struct wl_listener *listener;
606
607 /* search the destroy listener list for our callback */
608 wl_list_for_each(listener, lst, link) {
609 if (listener->func == shell_handle_surface_destroy) {
610 return container_of(listener, struct shell_surface,
611 surface_destroy_listener);
612 }
613 }
614
615 return NULL;
616}
617
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200618static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200619shell_get_shell_surface(struct wl_client *client,
620 struct wl_resource *resource,
621 uint32_t id,
622 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200623{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500624 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200625 struct shell_surface *shsurf;
626
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200627 if (get_shell_surface(surface)) {
628 wl_resource_post_error(surface_resource,
629 WL_DISPLAY_ERROR_INVALID_OBJECT,
630 "wl_shell::get_shell_surface already requested");
631 return;
632 }
633
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200634 shsurf = calloc(1, sizeof *shsurf);
635 if (!shsurf) {
636 wl_resource_post_no_memory(resource);
637 return;
638 }
639
640 shsurf->resource.destroy = destroy_shell_surface;
641 shsurf->resource.object.id = id;
642 shsurf->resource.object.interface = &wl_shell_surface_interface;
643 shsurf->resource.object.implementation =
644 (void (**)(void)) &shell_surface_implementation;
645 shsurf->resource.data = shsurf;
646
647 shsurf->surface = surface;
648 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
649 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
650 &shsurf->surface_destroy_listener.link);
651
652 /* init link so its safe to always remove it in destroy_shell_surface */
653 wl_list_init(&shsurf->link);
654
Pekka Paalanen460099f2012-01-20 16:48:25 +0200655 /* empty when not in use */
656 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500657 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200658
Pekka Paalanen98262232011-12-01 10:42:22 +0200659 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200660
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200661 wl_client_add_resource(client, &shsurf->resource);
662}
663
664static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200665 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500666};
667
Kristian Høgsberg07937562011-04-12 17:25:42 -0400668static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500669handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200670{
671 proc->pid = 0;
672}
673
674static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200675launch_screensaver(struct wl_shell *shell)
676{
677 if (shell->screensaver.binding)
678 return;
679
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200680 if (!shell->screensaver.path)
681 return;
682
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500683 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200684 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200685 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200686 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200687}
688
689static void
690terminate_screensaver(struct wl_shell *shell)
691{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200692 if (shell->screensaver.process.pid == 0)
693 return;
694
695 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200696}
697
698static void
699show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
700{
701 struct wl_list *list;
702
703 if (shell->lock_surface)
704 list = &shell->lock_surface->surface->link;
705 else
706 list = &shell->compositor->surface_list;
707
708 wl_list_remove(&surface->surface->link);
709 wl_list_insert(list, &surface->surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200710 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200711 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200712}
713
714static void
715hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
716{
717 wl_list_remove(&surface->surface->link);
718 wl_list_init(&surface->surface->link);
719 surface->surface->output = NULL;
720}
721
722static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400723desktop_shell_set_background(struct wl_client *client,
724 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100725 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400726 struct wl_resource *surface_resource)
727{
728 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200729 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500730 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200731 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400732
Pekka Paalanen98262232011-12-01 10:42:22 +0200733 if (reset_shell_surface_type(shsurf))
734 return;
735
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100736 wl_list_for_each(priv, &shell->backgrounds, link) {
737 if (priv->output == output_resource->data) {
738 priv->surface->output = NULL;
739 wl_list_remove(&priv->surface->link);
740 wl_list_remove(&priv->link);
741 break;
742 }
743 }
744
Pekka Paalanen068ae942011-11-28 14:11:15 +0200745 shsurf->type = SHELL_SURFACE_BACKGROUND;
746 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100747
Pekka Paalanen068ae942011-11-28 14:11:15 +0200748 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100749
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200750 surface->geometry.x = shsurf->output->x;
751 surface->geometry.y = shsurf->output->y;
752 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200753
Kristian Høgsberg75840622011-09-06 13:48:16 -0400754 wl_resource_post_event(resource,
755 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500756 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200757 shsurf->output->current->width,
758 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400759}
760
761static void
762desktop_shell_set_panel(struct wl_client *client,
763 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100764 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400765 struct wl_resource *surface_resource)
766{
767 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200768 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500769 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200770 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400771
Pekka Paalanen98262232011-12-01 10:42:22 +0200772 if (reset_shell_surface_type(shsurf))
773 return;
774
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100775 wl_list_for_each(priv, &shell->panels, link) {
776 if (priv->output == output_resource->data) {
777 priv->surface->output = NULL;
778 wl_list_remove(&priv->surface->link);
779 wl_list_remove(&priv->link);
780 break;
781 }
782 }
783
Pekka Paalanen068ae942011-11-28 14:11:15 +0200784 shsurf->type = SHELL_SURFACE_PANEL;
785 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100786
Pekka Paalanen068ae942011-11-28 14:11:15 +0200787 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100788
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200789 surface->geometry.x = shsurf->output->x;
790 surface->geometry.y = shsurf->output->y;
791 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200792
Kristian Høgsberg75840622011-09-06 13:48:16 -0400793 wl_resource_post_event(resource,
794 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500795 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200796 shsurf->output->current->width,
797 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400798}
799
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200800static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500801handle_lock_surface_destroy(struct wl_listener *listener,
802 struct wl_resource *resource, uint32_t time)
803{
804 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +0200805 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500806
807 fprintf(stderr, "lock surface gone\n");
808 shell->lock_surface = NULL;
809}
810
811static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200812desktop_shell_set_lock_surface(struct wl_client *client,
813 struct wl_resource *resource,
814 struct wl_resource *surface_resource)
815{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200816 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200817 struct shell_surface *surface = surface_resource->data;
818
819 if (reset_shell_surface_type(surface))
820 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200821
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200822 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200823
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200824 if (!shell->locked)
825 return;
826
Pekka Paalanen98262232011-12-01 10:42:22 +0200827 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200828
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500829 shell->lock_surface_listener.func = handle_lock_surface_destroy;
830 wl_list_insert(&surface_resource->destroy_listener_list,
831 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200832
Pekka Paalanen068ae942011-11-28 14:11:15 +0200833 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200834}
835
836static void
837resume_desktop(struct wl_shell *shell)
838{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500839 struct weston_surface *surface;
Pekka Paalanenfe340832011-11-25 16:07:52 +0200840 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200841 struct shell_surface *tmp;
842
843 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
844 hide_screensaver(shell, tmp);
845
846 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200847
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200848 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +0200849 weston_surface_assign_output(surface);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200850
Pekka Paalanenfe340832011-11-25 16:07:52 +0200851 if (wl_list_empty(&shell->backgrounds)) {
852 list = &shell->compositor->surface_list;
853 } else {
854 struct shell_surface *background;
855 background = container_of(shell->backgrounds.prev,
856 struct shell_surface, link);
857 list = background->surface->link.prev;
858 }
859
860 if (!wl_list_empty(&shell->hidden_surface_list))
861 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500862 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200863
864 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500865 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200866 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500867 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200868 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200869}
870
871static void
872desktop_shell_unlock(struct wl_client *client,
873 struct wl_resource *resource)
874{
875 struct wl_shell *shell = resource->data;
876
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200877 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200878
879 if (shell->locked)
880 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200881}
882
Kristian Høgsberg75840622011-09-06 13:48:16 -0400883static const struct desktop_shell_interface desktop_shell_implementation = {
884 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200885 desktop_shell_set_panel,
886 desktop_shell_set_lock_surface,
887 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400888};
889
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200890static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500891get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200892{
893 struct shell_surface *shsurf;
894
895 shsurf = get_shell_surface(surface);
896 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200897 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200898 return shsurf->type;
899}
900
Kristian Høgsberg75840622011-09-06 13:48:16 -0400901static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400902move_binding(struct wl_input_device *device, uint32_t time,
903 uint32_t key, uint32_t button, uint32_t state, void *data)
904{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500905 struct weston_surface *surface =
906 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500907
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100908 if (surface == NULL)
909 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400910
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200911 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100912 case SHELL_SURFACE_PANEL:
913 case SHELL_SURFACE_BACKGROUND:
914 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200915 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100916 return;
917 default:
918 break;
919 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400920
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500921 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400922}
923
924static void
925resize_binding(struct wl_input_device *device, uint32_t time,
926 uint32_t key, uint32_t button, uint32_t state, void *data)
927{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500928 struct weston_surface *surface =
929 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400930 uint32_t edges = 0;
931 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200932 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500933
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100934 if (surface == NULL)
935 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200936
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200937 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200938 if (!shsurf)
939 return;
940
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200941 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100942 case SHELL_SURFACE_PANEL:
943 case SHELL_SURFACE_BACKGROUND:
944 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200945 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100946 return;
947 default:
948 break;
949 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400950
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200951 weston_surface_from_global(surface,
952 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400953
Pekka Paalanen60921e52012-01-25 15:55:43 +0200954 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200955 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200956 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400957 edges |= 0;
958 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200959 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400960
Pekka Paalanen60921e52012-01-25 15:55:43 +0200961 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200962 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200963 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400964 edges |= 0;
965 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200966 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400967
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500968 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200969 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400970}
971
972static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500973terminate_binding(struct wl_input_device *device, uint32_t time,
974 uint32_t key, uint32_t button, uint32_t state, void *data)
975{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500976 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500977
978 if (state)
979 wl_display_terminate(compositor->wl_display);
980}
981
982static void
Pekka Paalanen460099f2012-01-20 16:48:25 +0200983rotate_grab_motion(struct wl_grab *grab,
984 uint32_t time, int32_t x, int32_t y)
985{
986 struct rotate_grab *rotate =
987 container_of(grab, struct rotate_grab, grab);
988 struct wl_input_device *device = grab->input_device;
989 struct shell_surface *surface = rotate->surface;
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +0200990 GLfloat cx = 0.5f * surface->surface->geometry.width;
991 GLfloat cy = 0.5f * surface->surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200992 GLfloat dx, dy;
993 GLfloat r;
994
995 dx = device->x - rotate->center.x;
996 dy = device->y - rotate->center.y;
997 r = sqrtf(dx * dx + dy * dy);
998
999 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001000 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001001
1002 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001003 struct weston_matrix *matrix =
1004 &surface->rotation.transform.matrix;
1005
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001006 weston_matrix_init(&rotate->rotation);
1007 rotate->rotation.d[0] = dx / r;
1008 rotate->rotation.d[4] = -dy / r;
1009 rotate->rotation.d[1] = -rotate->rotation.d[4];
1010 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001011
1012 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001013 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001014 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1015 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001016 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001017
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001018 wl_list_insert(
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001019 &surface->surface->geometry.transformation_list,
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001020 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001021 } else {
1022 wl_list_init(&surface->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001023 weston_matrix_init(&surface->rotation.rotation);
1024 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001025 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001026
1027 /* Repaint implies weston_surface_update_transform(), which
1028 * lazily applies the damage due to rotation update.
1029 */
1030 weston_compositor_schedule_repaint(surface->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001031}
1032
1033static void
1034rotate_grab_button(struct wl_grab *grab,
1035 uint32_t time, int32_t button, int32_t state)
1036{
1037 struct rotate_grab *rotate =
1038 container_of(grab, struct rotate_grab, grab);
1039 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001040 struct shell_surface *surface = rotate->surface;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001041
1042 if (device->button_count == 0 && state == 0) {
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001043 weston_matrix_multiply(&surface->rotation.rotation,
1044 &rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001045 wl_input_device_end_grab(device, time);
1046 free(rotate);
1047 }
1048}
1049
1050static const struct wl_grab_interface rotate_grab_interface = {
1051 noop_grab_focus,
1052 rotate_grab_motion,
1053 rotate_grab_button,
1054};
1055
1056static void
1057rotate_binding(struct wl_input_device *device, uint32_t time,
1058 uint32_t key, uint32_t button, uint32_t state, void *data)
1059{
1060 struct weston_surface *base_surface =
1061 (struct weston_surface *) device->pointer_focus;
1062 struct shell_surface *surface;
1063 struct rotate_grab *rotate;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001064 GLfloat dx, dy;
1065 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001066
1067 if (base_surface == NULL)
1068 return;
1069
1070 surface = get_shell_surface(base_surface);
1071 if (!surface)
1072 return;
1073
1074 switch (surface->type) {
1075 case SHELL_SURFACE_PANEL:
1076 case SHELL_SURFACE_BACKGROUND:
1077 case SHELL_SURFACE_FULLSCREEN:
1078 case SHELL_SURFACE_SCREENSAVER:
1079 return;
1080 default:
1081 break;
1082 }
1083
Pekka Paalanen460099f2012-01-20 16:48:25 +02001084 rotate = malloc(sizeof *rotate);
1085 if (!rotate)
1086 return;
1087
1088 rotate->grab.interface = &rotate_grab_interface;
1089 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001090
1091 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001092 surface->surface->geometry.width / 2,
1093 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001094 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001095
1096 wl_input_device_start_grab(device, &rotate->grab, time);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001097
1098 dx = device->x - rotate->center.x;
1099 dy = device->y - rotate->center.y;
1100 r = sqrtf(dx * dx + dy * dy);
1101 if (r > 20.0f) {
1102 struct weston_matrix inverse;
1103
1104 weston_matrix_init(&inverse);
1105 inverse.d[0] = dx / r;
1106 inverse.d[4] = dy / r;
1107 inverse.d[1] = -inverse.d[4];
1108 inverse.d[5] = inverse.d[0];
1109 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1110 } else {
1111 weston_matrix_init(&surface->rotation.rotation);
1112 weston_matrix_init(&rotate->rotation);
1113 }
1114
Pekka Paalanen460099f2012-01-20 16:48:25 +02001115 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
1116}
1117
1118static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001119activate(struct weston_shell *base, struct weston_surface *es,
1120 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001121{
1122 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001123 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001124 struct wl_list *list;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001125
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001126 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001127
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001128 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001129 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001130
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001131 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001132 case SHELL_SURFACE_BACKGROUND:
1133 /* put background back to bottom */
Kristian Høgsberg75840622011-09-06 13:48:16 -04001134 wl_list_remove(&es->link);
1135 wl_list_insert(compositor->surface_list.prev, &es->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001136 break;
1137 case SHELL_SURFACE_PANEL:
1138 /* already put on top */
1139 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001140 case SHELL_SURFACE_SCREENSAVER:
1141 /* always below lock surface */
1142 if (shell->lock_surface) {
1143 wl_list_remove(&es->link);
1144 wl_list_insert(&shell->lock_surface->surface->link,
1145 &es->link);
1146 }
1147 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001148 default:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001149 if (!shell->locked) {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001150 list = weston_compositor_top(compositor);
1151
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001152 /* bring panel back to top */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001153 struct shell_surface *panel;
1154 wl_list_for_each(panel, &shell->panels, link) {
1155 wl_list_remove(&panel->surface->link);
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001156 wl_list_insert(list, &panel->surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001157 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001158 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001159 }
1160}
1161
1162static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001163click_to_activate_binding(struct wl_input_device *device,
1164 uint32_t time, uint32_t key,
1165 uint32_t button, uint32_t state, void *data)
1166{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001167 struct weston_input_device *wd = (struct weston_input_device *) device;
1168 struct weston_compositor *compositor = data;
1169 struct weston_surface *focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001170
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001171 focus = (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001172 if (state && focus && device->grab == &device->default_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001173 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001174}
1175
1176static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001177lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001178{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001179 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001180 struct wl_list *surface_list = &shell->compositor->surface_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001181 struct weston_surface *cur;
1182 struct weston_surface *tmp;
1183 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001184 struct shell_surface *shsurf;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001185 uint32_t time;
1186
1187 if (shell->locked)
1188 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001189
1190 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001191
1192 /* Move all surfaces from compositor's list to our hidden list,
1193 * except the background. This way nothing else can show or
1194 * receive input events while we are locked. */
1195
1196 if (!wl_list_empty(&shell->hidden_surface_list)) {
1197 fprintf(stderr,
1198 "%s: Assertion failed: hidden_surface_list is not empty.\n",
1199 __func__);
1200 }
1201
1202 wl_list_for_each_safe(cur, tmp, surface_list, link) {
1203 /* skip input device sprites, cur->surface is uninitialised */
1204 if (cur->surface.resource.client == NULL)
1205 continue;
1206
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001207 if (get_shell_surface_type(cur) == SHELL_SURFACE_BACKGROUND)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001208 continue;
1209
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001210 cur->output = NULL;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001211 wl_list_remove(&cur->link);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001212 wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001213 }
1214
Pekka Paalanen77346a62011-11-30 16:26:35 +02001215 launch_screensaver(shell);
1216
1217 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1218 show_screensaver(shell, shsurf);
1219
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001220 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001221 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001222 weston_compositor_wake(shell->compositor);
1223 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001224 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001225
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001226 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001227 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001228
1229 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001230 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001231 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1232 wl_input_device_set_keyboard_focus(&device->input_device,
1233 NULL, time);
1234 }
1235
1236 /* TODO: disable bindings that should not work while locked. */
1237
1238 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001239}
1240
1241static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001242unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001243{
1244 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1245
Pekka Paalanend81c2162011-11-16 13:47:34 +02001246 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001247 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001248 return;
1249 }
1250
1251 /* If desktop-shell client has gone away, unlock immediately. */
1252 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001253 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001254 return;
1255 }
1256
1257 if (shell->prepare_event_sent)
1258 return;
1259
1260 wl_resource_post_event(shell->child.desktop_shell,
1261 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1262 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001263}
1264
1265static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001266center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001267{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001268 struct weston_mode *mode = output->current;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001269
Pekka Paalanen60921e52012-01-25 15:55:43 +02001270 surface->geometry.x =
1271 output->x + (mode->width - surface->geometry.width) / 2;
1272 surface->geometry.y =
1273 output->y + (mode->height - surface->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001274 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001275}
1276
1277static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001278map(struct weston_shell *base,
1279 struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001280{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001281 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001282 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001283 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001284 struct shell_surface *shsurf;
1285 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1286 int do_configure;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001287
Pekka Paalanen77346a62011-11-30 16:26:35 +02001288 shsurf = get_shell_surface(surface);
1289 if (shsurf)
1290 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001291
Pekka Paalanen77346a62011-11-30 16:26:35 +02001292 if (shell->locked) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001293 list = &shell->hidden_surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001294 do_configure = 0;
1295 } else {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001296 list = weston_compositor_top(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001297 do_configure = 1;
1298 }
1299
Pekka Paalanen60921e52012-01-25 15:55:43 +02001300 surface->geometry.width = width;
1301 surface->geometry.height = height;
1302 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001303
1304 /* initial positioning, see also configure() */
1305 switch (surface_type) {
1306 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001307 surface->geometry.x = 10 + random() % 400;
1308 surface->geometry.y = 10 + random() % 400;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001309 break;
1310 case SHELL_SURFACE_SCREENSAVER:
1311 case SHELL_SURFACE_FULLSCREEN:
1312 center_on_output(surface, surface->fullscreen_output);
1313 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001314 case SHELL_SURFACE_LOCK:
1315 center_on_output(surface, get_default_output(compositor));
1316 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001317 case SHELL_SURFACE_POPUP:
1318 shell_map_popup(shsurf, shsurf->popup.time);
1319 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001320 default:
1321 ;
1322 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001323
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001324 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001325 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001326 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001327 /* background always visible, at the bottom */
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001328 wl_list_insert(compositor->surface_list.prev, &surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001329 do_configure = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001330 break;
1331 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001332 /* panel always on top, hidden while locked */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001333 wl_list_insert(list, &surface->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001334 break;
1335 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001336 /* lock surface always visible, on top */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001337 wl_list_insert(&compositor->surface_list, &surface->link);
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001338
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001339 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001340 do_configure = 1;
1341 break;
1342 case SHELL_SURFACE_SCREENSAVER:
1343 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001344 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001345 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001346 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001347 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001348 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001349 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001350 }
Pekka Paalanen77346a62011-11-30 16:26:35 +02001351 do_configure = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001352 break;
1353 default:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001354 /* everything else just below the panel */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001355 if (!wl_list_empty(&shell->panels)) {
1356 struct shell_surface *panel =
1357 container_of(shell->panels.prev,
1358 struct shell_surface, link);
1359 wl_list_insert(&panel->surface->link, &surface->link);
1360 } else {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001361 wl_list_insert(list, &surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001362 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001363 }
1364
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001365 if (do_configure) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001366 weston_surface_assign_output(surface);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001367 weston_compositor_repick(compositor);
1368 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001369
Juan Zhao7bb92f02011-12-15 11:31:51 -05001370 switch (surface_type) {
1371 case SHELL_SURFACE_TOPLEVEL:
1372 case SHELL_SURFACE_TRANSIENT:
1373 case SHELL_SURFACE_FULLSCREEN:
1374 if (!shell->locked)
1375 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001376 (struct weston_input_device *)
Juan Zhao7bb92f02011-12-15 11:31:51 -05001377 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001378 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001379 break;
1380 default:
1381 break;
1382 }
1383
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001384 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001385 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001386}
1387
1388static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001389configure(struct weston_shell *base, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001390 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001391{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001392 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1393 int do_configure = !shell->locked;
1394 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1395 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001396
Pekka Paalanen77346a62011-11-30 16:26:35 +02001397 shsurf = get_shell_surface(surface);
1398 if (shsurf)
1399 surface_type = shsurf->type;
1400
Pekka Paalanen60921e52012-01-25 15:55:43 +02001401 surface->geometry.width = width;
1402 surface->geometry.height = height;
1403 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001404
1405 switch (surface_type) {
1406 case SHELL_SURFACE_SCREENSAVER:
1407 do_configure = !do_configure;
1408 /* fall through */
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001409 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001410 center_on_output(surface, surface->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001411 break;
1412 default:
1413 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001414 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001415
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001416 /* XXX: would a fullscreen surface need the same handling? */
Pekka Paalanen77346a62011-11-30 16:26:35 +02001417 if (do_configure) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001418 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001419 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001420
1421 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1422 surface->output = shsurf->output;
1423 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001424}
1425
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001426static int launch_desktop_shell_process(struct wl_shell *shell);
1427
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001428static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001429desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001430{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001431 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001432 struct wl_shell *shell =
1433 container_of(process, struct wl_shell, child.process);
1434
1435 shell->child.process.pid = 0;
1436 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001437
1438 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1439 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001440 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001441 shell->child.deathstamp = time;
1442 shell->child.deathcount = 0;
1443 }
1444
1445 shell->child.deathcount++;
1446 if (shell->child.deathcount > 5) {
1447 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1448 return;
1449 }
1450
1451 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1452 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001453}
1454
1455static int
1456launch_desktop_shell_process(struct wl_shell *shell)
1457{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001458 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001459
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001460 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001461 &shell->child.process,
1462 shell_exe,
1463 desktop_shell_sigchld);
1464
1465 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001466 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001467 return 0;
1468}
1469
1470static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001471bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1472{
1473 struct wl_shell *shell = data;
1474
1475 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001476 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001477}
1478
Kristian Høgsberg75840622011-09-06 13:48:16 -04001479static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001480unbind_desktop_shell(struct wl_resource *resource)
1481{
1482 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001483
1484 if (shell->locked)
1485 resume_desktop(shell);
1486
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001487 shell->child.desktop_shell = NULL;
1488 shell->prepare_event_sent = false;
1489 free(resource);
1490}
1491
1492static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001493bind_desktop_shell(struct wl_client *client,
1494 void *data, uint32_t version, uint32_t id)
1495{
1496 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001497 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001498
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001499 resource = wl_client_add_object(client, &desktop_shell_interface,
1500 &desktop_shell_implementation,
1501 id, shell);
1502
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001503 if (client == shell->child.client) {
1504 resource->destroy = unbind_desktop_shell;
1505 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001506 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001507 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001508
1509 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1510 "permission to bind desktop_shell denied");
1511 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001512}
1513
Pekka Paalanen6e168112011-11-24 11:34:05 +02001514static void
1515screensaver_set_surface(struct wl_client *client,
1516 struct wl_resource *resource,
1517 struct wl_resource *shell_surface_resource,
1518 struct wl_resource *output_resource)
1519{
1520 struct wl_shell *shell = resource->data;
1521 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001522 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001523
Pekka Paalanen98262232011-12-01 10:42:22 +02001524 if (reset_shell_surface_type(surface))
1525 return;
1526
Pekka Paalanen77346a62011-11-30 16:26:35 +02001527 surface->type = SHELL_SURFACE_SCREENSAVER;
1528
1529 surface->surface->fullscreen_output = output;
1530 surface->output = output;
1531 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001532}
1533
1534static const struct screensaver_interface screensaver_implementation = {
1535 screensaver_set_surface
1536};
1537
1538static void
1539unbind_screensaver(struct wl_resource *resource)
1540{
1541 struct wl_shell *shell = resource->data;
1542
Pekka Paalanen77346a62011-11-30 16:26:35 +02001543 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001544 free(resource);
1545}
1546
1547static void
1548bind_screensaver(struct wl_client *client,
1549 void *data, uint32_t version, uint32_t id)
1550{
1551 struct wl_shell *shell = data;
1552 struct wl_resource *resource;
1553
1554 resource = wl_client_add_object(client, &screensaver_interface,
1555 &screensaver_implementation,
1556 id, shell);
1557
Pekka Paalanen77346a62011-11-30 16:26:35 +02001558 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001559 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001560 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001561 return;
1562 }
1563
1564 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1565 "interface object already bound");
1566 wl_resource_destroy(resource, 0);
1567}
1568
Pekka Paalanen3c647232011-12-22 13:43:43 +02001569static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001570shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001571{
1572 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1573
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001574 if (shell->child.client)
1575 wl_client_destroy(shell->child.client);
1576
Pekka Paalanen3c647232011-12-22 13:43:43 +02001577 free(shell->screensaver.path);
1578 free(shell);
1579}
1580
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001581int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001582shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001583
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001584WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001585shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001586{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001587 struct wl_shell *shell;
1588
1589 shell = malloc(sizeof *shell);
1590 if (shell == NULL)
1591 return -1;
1592
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001593 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001594 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001595 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001596 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001597 shell->shell.map = map;
1598 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02001599 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001600
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001601 wl_list_init(&shell->hidden_surface_list);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001602 wl_list_init(&shell->backgrounds);
1603 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001604 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001605
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001606 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001607
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001608 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
1609 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001610 return -1;
1611
Kristian Høgsberg75840622011-09-06 13:48:16 -04001612 if (wl_display_add_global(ec->wl_display,
1613 &desktop_shell_interface,
1614 shell, bind_desktop_shell) == NULL)
1615 return -1;
1616
Pekka Paalanen6e168112011-11-24 11:34:05 +02001617 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
1618 shell, bind_screensaver) == NULL)
1619 return -1;
1620
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001621 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001622 if (launch_desktop_shell_process(shell) != 0)
1623 return -1;
1624
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001625 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001626 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001627 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001628 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001629 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001630 MODIFIER_CTRL | MODIFIER_ALT,
1631 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001632 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001633 click_to_activate_binding, ec);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001634 weston_compositor_add_binding(ec, 0, BTN_LEFT,
1635 MODIFIER_SUPER | MODIFIER_ALT,
1636 rotate_binding, NULL);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001637
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001638 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001639
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001640 return 0;
1641}