blob: 78120ef573dbfedddfd18c7b47fc206d181876c1 [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;
106 int32_t initial_up;
107 } popup;
108
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500109 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100110 struct wl_list link;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200111};
112
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500113struct weston_move_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500114 struct wl_grab grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500115 struct weston_surface *surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500116 int32_t dx, dy;
117};
118
Pekka Paalanen460099f2012-01-20 16:48:25 +0200119struct rotate_grab {
120 struct wl_grab grab;
121 struct shell_surface *surface;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500122 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200123 struct {
124 int32_t x;
125 int32_t y;
126 } center;
127};
128
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500129static void
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200130shell_configuration(struct wl_shell *shell)
131{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200132 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200133 char *path = NULL;
134 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200135
136 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200137 { "path", CONFIG_KEY_STRING, &path },
138 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200139 };
140
141 struct config_section cs[] = {
142 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
143 };
144
Kristian Høgsberg9724b512012-01-03 14:35:49 -0500145 config_file = config_file_path("weston-desktop-shell.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500146 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200147 free(config_file);
148
Pekka Paalanen7296e792011-12-07 16:22:00 +0200149 shell->screensaver.path = path;
150 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200151}
152
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200153static void
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500154noop_grab_focus(struct wl_grab *grab, uint32_t time,
155 struct wl_surface *surface, int32_t x, int32_t y)
156{
157 grab->focus = NULL;
158}
159
160static void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500161move_grab_motion(struct wl_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500162 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500163{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500164 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500165 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500166 struct weston_surface *es = move->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500167
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500168 weston_surface_configure(es,
169 device->x + move->dx,
170 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200171 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500172}
173
174static void
175move_grab_button(struct wl_grab *grab,
176 uint32_t time, int32_t button, int32_t state)
177{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500178 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500179
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500180 if (device->button_count == 0 && state == 0) {
181 wl_input_device_end_grab(device, time);
182 free(grab);
183 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500184}
185
186static const struct wl_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500187 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500188 move_grab_motion,
189 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500190};
191
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400192static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500193weston_surface_move(struct weston_surface *es,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500194 struct weston_input_device *wd, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500195{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500196 struct weston_move_grab *move;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500197
198 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400199 if (!move)
200 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500201
202 move->grab.interface = &move_grab_interface;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200203 move->dx = es->geometry.x - wd->input_device.grab_x;
204 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -0500205 move->surface = es;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500206
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500207 wl_input_device_start_grab(&wd->input_device, &move->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500208
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400209 wl_input_device_set_pointer_focus(&wd->input_device,
210 NULL, time, 0, 0, 0, 0);
211
212 return 0;
213}
214
215static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200216shell_surface_move(struct wl_client *client, struct wl_resource *resource,
217 struct wl_resource *input_resource, uint32_t time)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400218{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500219 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200220 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400221
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500222 if (wd->input_device.button_count == 0 ||
223 wd->input_device.grab_time != time ||
224 wd->input_device.pointer_focus != &shsurf->surface->surface)
225 return;
226
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500227 if (weston_surface_move(shsurf->surface, wd, time) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400228 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500229}
230
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500231struct weston_resize_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500232 struct wl_grab grab;
233 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200234 int32_t width, height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200235 struct shell_surface *shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500236};
237
238static void
239resize_grab_motion(struct wl_grab *grab,
240 uint32_t time, int32_t x, int32_t y)
241{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500242 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500243 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500244 int32_t width, height;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200245 int32_t from_x, from_y;
246 int32_t to_x, to_y;
247
248 weston_surface_from_global(resize->shsurf->surface,
249 device->grab_x, device->grab_y,
250 &from_x, &from_y);
251 weston_surface_from_global(resize->shsurf->surface,
252 device->x, device->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500253
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200254 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200255 width = resize->width + from_x - to_x;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200256 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200257 width = resize->width + to_x - from_x;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500258 } else {
259 width = resize->width;
260 }
261
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200262 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200263 height = resize->height + from_y - to_y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200264 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200265 height = resize->height + to_y - from_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500266 } else {
267 height = resize->height;
268 }
269
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200270 wl_resource_post_event(&resize->shsurf->resource,
271 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
272 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500273}
274
275static void
276resize_grab_button(struct wl_grab *grab,
277 uint32_t time, int32_t button, int32_t state)
278{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500279 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500280
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500281 if (device->button_count == 0 && state == 0) {
282 wl_input_device_end_grab(device, time);
283 free(grab);
284 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500285}
286
287static const struct wl_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500288 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500289 resize_grab_motion,
290 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500291};
292
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400293static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500294weston_surface_resize(struct shell_surface *shsurf,
295 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200296 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500297{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500298 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500299
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500300 /* FIXME: Reject if fullscreen */
301
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200302 if (edges == 0 || edges > 15 ||
303 (edges & 3) == 3 || (edges & 12) == 12)
304 return 0;
305
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500306 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400307 if (!resize)
308 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500309
310 resize->grab.interface = &resize_grab_interface;
311 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200312 resize->width = shsurf->surface->geometry.width;
313 resize->height = shsurf->surface->geometry.height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200314 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400315
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500316 wl_input_device_start_grab(&wd->input_device, &resize->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500317
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400318 wl_input_device_set_pointer_focus(&wd->input_device,
319 NULL, time, 0, 0, 0, 0);
320
321 return 0;
322}
323
324static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200325shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
326 struct wl_resource *input_resource, uint32_t time,
327 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400328{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500329 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200330 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400331
332 /* FIXME: Reject if fullscreen */
333
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500334 if (wd->input_device.button_count == 0 ||
335 wd->input_device.grab_time != time ||
336 wd->input_device.pointer_focus != &shsurf->surface->surface)
337 return;
338
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500339 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400340 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500341}
342
Pekka Paalanen98262232011-12-01 10:42:22 +0200343static int
344reset_shell_surface_type(struct shell_surface *surface)
345{
346 switch (surface->type) {
347 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200348 surface->surface->geometry.x = surface->saved_x;
349 surface->surface->geometry.y = surface->saved_y;
350 surface->surface->geometry.dirty = 1;
Pekka Paalanen98262232011-12-01 10:42:22 +0200351 surface->surface->fullscreen_output = NULL;
352 break;
353 case SHELL_SURFACE_PANEL:
354 case SHELL_SURFACE_BACKGROUND:
355 wl_list_remove(&surface->link);
356 wl_list_init(&surface->link);
357 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200358 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200359 case SHELL_SURFACE_LOCK:
360 wl_resource_post_error(&surface->resource,
361 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200362 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200363 return -1;
364 case SHELL_SURFACE_NONE:
365 case SHELL_SURFACE_TOPLEVEL:
366 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500367 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200368 break;
369 }
370
371 surface->type = SHELL_SURFACE_NONE;
372 return 0;
373}
374
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500375static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200376shell_surface_set_toplevel(struct wl_client *client,
377 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400378
379{
Pekka Paalanen98262232011-12-01 10:42:22 +0200380 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400381
Pekka Paalanen98262232011-12-01 10:42:22 +0200382 if (reset_shell_surface_type(surface))
383 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400384
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500385 weston_surface_damage(surface->surface);
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
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500410 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200411 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400412}
413
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500414static struct weston_output *
415get_default_output(struct weston_compositor *compositor)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200416{
417 return container_of(compositor->output_list.next,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500418 struct weston_output, link);
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200419}
420
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400421static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200422shell_surface_set_fullscreen(struct wl_client *client,
423 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400424
425{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200426 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500427 struct weston_surface *es = shsurf->surface;
428 struct weston_output *output;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400429
Pekka Paalanen98262232011-12-01 10:42:22 +0200430 if (reset_shell_surface_type(shsurf))
431 return;
432
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400433 /* FIXME: Fullscreen on first output */
434 /* FIXME: Handle output going away */
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200435 output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400436 es->output = output;
437
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200438 shsurf->saved_x = es->geometry.x;
439 shsurf->saved_y = es->geometry.y;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200440 es->geometry.x = (output->current->width - es->geometry.width) / 2;
441 es->geometry.y = (output->current->height - es->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200442 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400443 es->fullscreen_output = output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500444 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200445 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400446}
447
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500448static void
449popup_grab_focus(struct wl_grab *grab, uint32_t time,
450 struct wl_surface *surface, int32_t x, int32_t y)
451{
452 struct wl_input_device *device = grab->input_device;
453 struct shell_surface *priv =
454 container_of(grab, struct shell_surface, popup.grab);
455 struct wl_client *client = priv->surface->surface.resource.client;
456
Pekka Paalanencb108432012-01-19 16:25:40 +0200457 if (surface && surface->resource.client == client) {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500458 wl_input_device_set_pointer_focus(device, surface, time,
459 device->x, device->y, x, y);
460 grab->focus = surface;
461 } else {
462 wl_input_device_set_pointer_focus(device, NULL,
463 time, 0, 0, 0, 0);
464 grab->focus = NULL;
465 }
466}
467
468static void
469popup_grab_motion(struct wl_grab *grab,
470 uint32_t time, int32_t x, int32_t y)
471{
472 struct wl_input_device *device = grab->input_device;
473 struct wl_resource *resource;
474
475 resource = grab->input_device->pointer_focus_resource;
476 if (resource)
477 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
478 time, device->x, device->y, x, y);
479}
480
481static void
482popup_grab_button(struct wl_grab *grab,
483 uint32_t time, int32_t button, int32_t state)
484{
485 struct wl_resource *resource;
486 struct shell_surface *shsurf =
487 container_of(grab, struct shell_surface, popup.grab);
488
489 resource = grab->input_device->pointer_focus_resource;
490 if (resource) {
491 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
492 time, button, state);
493 } else if (state == 0 &&
494 (shsurf->popup.initial_up ||
495 time - shsurf->popup.time > 500)) {
496 wl_resource_post_event(&shsurf->resource,
497 WL_SHELL_SURFACE_POPUP_DONE);
498 wl_input_device_end_grab(grab->input_device, time);
499 shsurf->popup.grab.input_device = NULL;
500 }
501
502 if (state == 0)
503 shsurf->popup.initial_up = 1;
504}
505
506static const struct wl_grab_interface popup_grab_interface = {
507 popup_grab_focus,
508 popup_grab_motion,
509 popup_grab_button,
510};
511
512static void
513shell_map_popup(struct shell_surface *shsurf, uint32_t time)
514{
515 struct wl_input_device *device;
516 struct weston_surface *es = shsurf->surface;
517 struct weston_surface *parent = shsurf->parent->surface;
518
519 es->output = parent->output;
520
521 shsurf->popup.grab.interface = &popup_grab_interface;
522 device = es->compositor->input_device;
523
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200524 es->geometry.x = shsurf->parent->surface->geometry.x + shsurf->popup.x;
525 es->geometry.y = shsurf->parent->surface->geometry.y + shsurf->popup.y;
526 es->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500527
528 shsurf->popup.grab.input_device = device;
529 shsurf->popup.time = device->grab_time;
530 shsurf->popup.initial_up = 0;
531
532 wl_input_device_start_grab(shsurf->popup.grab.input_device,
533 &shsurf->popup.grab, shsurf->popup.time);
534}
535
536static void
537shell_surface_set_popup(struct wl_client *client,
538 struct wl_resource *resource,
539 struct wl_resource *input_device_resource,
540 uint32_t time,
541 struct wl_resource *parent_resource,
542 int32_t x, int32_t y, uint32_t flags)
543{
544 struct shell_surface *shsurf = resource->data;
545 struct weston_surface *es = shsurf->surface;
546
547 weston_surface_damage(es);
548 shsurf->type = SHELL_SURFACE_POPUP;
549 shsurf->parent = parent_resource->data;
550 shsurf->popup.x = x;
551 shsurf->popup.y = y;
552}
553
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200554static const struct wl_shell_surface_interface shell_surface_implementation = {
555 shell_surface_move,
556 shell_surface_resize,
557 shell_surface_set_toplevel,
558 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500559 shell_surface_set_fullscreen,
560 shell_surface_set_popup
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200561};
562
563static void
564destroy_shell_surface(struct wl_resource *resource)
565{
566 struct shell_surface *shsurf = resource->data;
567
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500568 if (shsurf->popup.grab.input_device)
569 wl_input_device_end_grab(shsurf->popup.grab.input_device, 0);
570
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200571 /* in case cleaning up a dead client destroys shell_surface first */
572 if (shsurf->surface)
573 wl_list_remove(&shsurf->surface_destroy_listener.link);
574
575 wl_list_remove(&shsurf->link);
576 free(shsurf);
577}
578
579static void
580shell_handle_surface_destroy(struct wl_listener *listener,
581 struct wl_resource *resource, uint32_t time)
582{
583 struct shell_surface *shsurf = container_of(listener,
584 struct shell_surface,
585 surface_destroy_listener);
586
587 shsurf->surface = NULL;
588 wl_resource_destroy(&shsurf->resource, time);
589}
590
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200591static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500592get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200593{
594 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
595 struct wl_listener *listener;
596
597 /* search the destroy listener list for our callback */
598 wl_list_for_each(listener, lst, link) {
599 if (listener->func == shell_handle_surface_destroy) {
600 return container_of(listener, struct shell_surface,
601 surface_destroy_listener);
602 }
603 }
604
605 return NULL;
606}
607
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200608static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200609shell_get_shell_surface(struct wl_client *client,
610 struct wl_resource *resource,
611 uint32_t id,
612 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200613{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500614 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200615 struct shell_surface *shsurf;
616
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200617 if (get_shell_surface(surface)) {
618 wl_resource_post_error(surface_resource,
619 WL_DISPLAY_ERROR_INVALID_OBJECT,
620 "wl_shell::get_shell_surface already requested");
621 return;
622 }
623
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200624 shsurf = calloc(1, sizeof *shsurf);
625 if (!shsurf) {
626 wl_resource_post_no_memory(resource);
627 return;
628 }
629
630 shsurf->resource.destroy = destroy_shell_surface;
631 shsurf->resource.object.id = id;
632 shsurf->resource.object.interface = &wl_shell_surface_interface;
633 shsurf->resource.object.implementation =
634 (void (**)(void)) &shell_surface_implementation;
635 shsurf->resource.data = shsurf;
636
637 shsurf->surface = surface;
638 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
639 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
640 &shsurf->surface_destroy_listener.link);
641
642 /* init link so its safe to always remove it in destroy_shell_surface */
643 wl_list_init(&shsurf->link);
644
Pekka Paalanen460099f2012-01-20 16:48:25 +0200645 /* empty when not in use */
646 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500647 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200648
Pekka Paalanen98262232011-12-01 10:42:22 +0200649 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200650
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200651 wl_client_add_resource(client, &shsurf->resource);
652}
653
654static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200655 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500656};
657
Kristian Høgsberg07937562011-04-12 17:25:42 -0400658static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500659handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200660{
661 proc->pid = 0;
662}
663
664static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200665launch_screensaver(struct wl_shell *shell)
666{
667 if (shell->screensaver.binding)
668 return;
669
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200670 if (!shell->screensaver.path)
671 return;
672
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500673 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200674 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200675 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200676 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200677}
678
679static void
680terminate_screensaver(struct wl_shell *shell)
681{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200682 if (shell->screensaver.process.pid == 0)
683 return;
684
685 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200686}
687
688static void
689show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
690{
691 struct wl_list *list;
692
693 if (shell->lock_surface)
694 list = &shell->lock_surface->surface->link;
695 else
696 list = &shell->compositor->surface_list;
697
698 wl_list_remove(&surface->surface->link);
699 wl_list_insert(list, &surface->surface->link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500700 weston_surface_configure(surface->surface,
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200701 surface->surface->geometry.x,
702 surface->surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200703 surface->surface->geometry.width,
704 surface->surface->geometry.height);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200705 surface->surface->output = surface->output;
706}
707
708static void
709hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
710{
711 wl_list_remove(&surface->surface->link);
712 wl_list_init(&surface->surface->link);
713 surface->surface->output = NULL;
714}
715
716static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400717desktop_shell_set_background(struct wl_client *client,
718 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100719 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400720 struct wl_resource *surface_resource)
721{
722 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200723 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500724 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200725 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400726
Pekka Paalanen98262232011-12-01 10:42:22 +0200727 if (reset_shell_surface_type(shsurf))
728 return;
729
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100730 wl_list_for_each(priv, &shell->backgrounds, link) {
731 if (priv->output == output_resource->data) {
732 priv->surface->output = NULL;
733 wl_list_remove(&priv->surface->link);
734 wl_list_remove(&priv->link);
735 break;
736 }
737 }
738
Pekka Paalanen068ae942011-11-28 14:11:15 +0200739 shsurf->type = SHELL_SURFACE_BACKGROUND;
740 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100741
Pekka Paalanen068ae942011-11-28 14:11:15 +0200742 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100743
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200744 surface->geometry.x = shsurf->output->x;
745 surface->geometry.y = shsurf->output->y;
746 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200747
Kristian Høgsberg75840622011-09-06 13:48:16 -0400748 wl_resource_post_event(resource,
749 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500750 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200751 shsurf->output->current->width,
752 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400753}
754
755static void
756desktop_shell_set_panel(struct wl_client *client,
757 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100758 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400759 struct wl_resource *surface_resource)
760{
761 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200762 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500763 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200764 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400765
Pekka Paalanen98262232011-12-01 10:42:22 +0200766 if (reset_shell_surface_type(shsurf))
767 return;
768
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100769 wl_list_for_each(priv, &shell->panels, link) {
770 if (priv->output == output_resource->data) {
771 priv->surface->output = NULL;
772 wl_list_remove(&priv->surface->link);
773 wl_list_remove(&priv->link);
774 break;
775 }
776 }
777
Pekka Paalanen068ae942011-11-28 14:11:15 +0200778 shsurf->type = SHELL_SURFACE_PANEL;
779 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100780
Pekka Paalanen068ae942011-11-28 14:11:15 +0200781 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100782
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200783 surface->geometry.x = shsurf->output->x;
784 surface->geometry.y = shsurf->output->y;
785 surface->geometry.dirty = 1;
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
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500842 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200843 weston_surface_configure(surface, surface->geometry.x,
844 surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200845 surface->geometry.width,
846 surface->geometry.height);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200847
Pekka Paalanenfe340832011-11-25 16:07:52 +0200848 if (wl_list_empty(&shell->backgrounds)) {
849 list = &shell->compositor->surface_list;
850 } else {
851 struct shell_surface *background;
852 background = container_of(shell->backgrounds.prev,
853 struct shell_surface, link);
854 list = background->surface->link.prev;
855 }
856
857 if (!wl_list_empty(&shell->hidden_surface_list))
858 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500859 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200860
861 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500862 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200863 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500864 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200865}
866
867static void
868desktop_shell_unlock(struct wl_client *client,
869 struct wl_resource *resource)
870{
871 struct wl_shell *shell = resource->data;
872
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200873 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200874
875 if (shell->locked)
876 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200877}
878
Kristian Høgsberg75840622011-09-06 13:48:16 -0400879static const struct desktop_shell_interface desktop_shell_implementation = {
880 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200881 desktop_shell_set_panel,
882 desktop_shell_set_lock_surface,
883 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400884};
885
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200886static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500887get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200888{
889 struct shell_surface *shsurf;
890
891 shsurf = get_shell_surface(surface);
892 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200893 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200894 return shsurf->type;
895}
896
Kristian Høgsberg75840622011-09-06 13:48:16 -0400897static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400898move_binding(struct wl_input_device *device, uint32_t time,
899 uint32_t key, uint32_t button, uint32_t state, void *data)
900{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500901 struct weston_surface *surface =
902 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500903
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100904 if (surface == NULL)
905 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400906
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200907 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100908 case SHELL_SURFACE_PANEL:
909 case SHELL_SURFACE_BACKGROUND:
910 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200911 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100912 return;
913 default:
914 break;
915 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400916
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500917 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400918}
919
920static void
921resize_binding(struct wl_input_device *device, uint32_t time,
922 uint32_t key, uint32_t button, uint32_t state, void *data)
923{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500924 struct weston_surface *surface =
925 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400926 uint32_t edges = 0;
927 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200928 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500929
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100930 if (surface == NULL)
931 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200932
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200933 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200934 if (!shsurf)
935 return;
936
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200937 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100938 case SHELL_SURFACE_PANEL:
939 case SHELL_SURFACE_BACKGROUND:
940 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200941 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100942 return;
943 default:
944 break;
945 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400946
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200947 weston_surface_from_global(surface,
948 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400949
Pekka Paalanen60921e52012-01-25 15:55:43 +0200950 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200951 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200952 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400953 edges |= 0;
954 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200955 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400956
Pekka Paalanen60921e52012-01-25 15:55:43 +0200957 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200958 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200959 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400960 edges |= 0;
961 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200962 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400963
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500964 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200965 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400966}
967
968static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500969terminate_binding(struct wl_input_device *device, uint32_t time,
970 uint32_t key, uint32_t button, uint32_t state, void *data)
971{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500972 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500973
974 if (state)
975 wl_display_terminate(compositor->wl_display);
976}
977
978static void
Pekka Paalanen460099f2012-01-20 16:48:25 +0200979rotate_grab_motion(struct wl_grab *grab,
980 uint32_t time, int32_t x, int32_t y)
981{
982 struct rotate_grab *rotate =
983 container_of(grab, struct rotate_grab, grab);
984 struct wl_input_device *device = grab->input_device;
985 struct shell_surface *surface = rotate->surface;
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +0200986 GLfloat cx = 0.5f * surface->surface->geometry.width;
987 GLfloat cy = 0.5f * surface->surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200988 GLfloat dx, dy;
989 GLfloat r;
990
991 dx = device->x - rotate->center.x;
992 dy = device->y - rotate->center.y;
993 r = sqrtf(dx * dx + dy * dy);
994
995 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200996 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200997
998 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200999 struct weston_matrix *matrix =
1000 &surface->rotation.transform.matrix;
1001
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001002 weston_matrix_init(&rotate->rotation);
1003 rotate->rotation.d[0] = dx / r;
1004 rotate->rotation.d[4] = -dy / r;
1005 rotate->rotation.d[1] = -rotate->rotation.d[4];
1006 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001007
1008 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001009 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001010 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1011 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001012 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001013
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001014 wl_list_insert(
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001015 &surface->surface->geometry.transformation_list,
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001016 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001017 } else {
1018 wl_list_init(&surface->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001019 weston_matrix_init(&surface->rotation.rotation);
1020 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001021 }
1022
1023 weston_compositor_damage_all(surface->surface->compositor);
1024}
1025
1026static void
1027rotate_grab_button(struct wl_grab *grab,
1028 uint32_t time, int32_t button, int32_t state)
1029{
1030 struct rotate_grab *rotate =
1031 container_of(grab, struct rotate_grab, grab);
1032 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001033 struct shell_surface *surface = rotate->surface;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001034
1035 if (device->button_count == 0 && state == 0) {
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001036 weston_matrix_multiply(&surface->rotation.rotation,
1037 &rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001038 wl_input_device_end_grab(device, time);
1039 free(rotate);
1040 }
1041}
1042
1043static const struct wl_grab_interface rotate_grab_interface = {
1044 noop_grab_focus,
1045 rotate_grab_motion,
1046 rotate_grab_button,
1047};
1048
1049static void
1050rotate_binding(struct wl_input_device *device, uint32_t time,
1051 uint32_t key, uint32_t button, uint32_t state, void *data)
1052{
1053 struct weston_surface *base_surface =
1054 (struct weston_surface *) device->pointer_focus;
1055 struct shell_surface *surface;
1056 struct rotate_grab *rotate;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001057 GLfloat dx, dy;
1058 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001059
1060 if (base_surface == NULL)
1061 return;
1062
1063 surface = get_shell_surface(base_surface);
1064 if (!surface)
1065 return;
1066
1067 switch (surface->type) {
1068 case SHELL_SURFACE_PANEL:
1069 case SHELL_SURFACE_BACKGROUND:
1070 case SHELL_SURFACE_FULLSCREEN:
1071 case SHELL_SURFACE_SCREENSAVER:
1072 return;
1073 default:
1074 break;
1075 }
1076
Pekka Paalanen460099f2012-01-20 16:48:25 +02001077 rotate = malloc(sizeof *rotate);
1078 if (!rotate)
1079 return;
1080
1081 rotate->grab.interface = &rotate_grab_interface;
1082 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001083
1084 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001085 surface->surface->geometry.width / 2,
1086 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001087 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001088
1089 wl_input_device_start_grab(device, &rotate->grab, time);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001090
1091 dx = device->x - rotate->center.x;
1092 dy = device->y - rotate->center.y;
1093 r = sqrtf(dx * dx + dy * dy);
1094 if (r > 20.0f) {
1095 struct weston_matrix inverse;
1096
1097 weston_matrix_init(&inverse);
1098 inverse.d[0] = dx / r;
1099 inverse.d[4] = dy / r;
1100 inverse.d[1] = -inverse.d[4];
1101 inverse.d[5] = inverse.d[0];
1102 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1103 } else {
1104 weston_matrix_init(&surface->rotation.rotation);
1105 weston_matrix_init(&rotate->rotation);
1106 }
1107
Pekka Paalanen460099f2012-01-20 16:48:25 +02001108 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
1109}
1110
1111static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001112activate(struct weston_shell *base, struct weston_surface *es,
1113 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001114{
1115 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001116 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001117 struct wl_list *list;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001118
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001119 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001120
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001121 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001122 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001123
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001124 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001125 case SHELL_SURFACE_BACKGROUND:
1126 /* put background back to bottom */
Kristian Høgsberg75840622011-09-06 13:48:16 -04001127 wl_list_remove(&es->link);
1128 wl_list_insert(compositor->surface_list.prev, &es->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001129 break;
1130 case SHELL_SURFACE_PANEL:
1131 /* already put on top */
1132 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001133 case SHELL_SURFACE_SCREENSAVER:
1134 /* always below lock surface */
1135 if (shell->lock_surface) {
1136 wl_list_remove(&es->link);
1137 wl_list_insert(&shell->lock_surface->surface->link,
1138 &es->link);
1139 }
1140 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001141 default:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001142 if (!shell->locked) {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001143 list = weston_compositor_top(compositor);
1144
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001145 /* bring panel back to top */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001146 struct shell_surface *panel;
1147 wl_list_for_each(panel, &shell->panels, link) {
1148 wl_list_remove(&panel->surface->link);
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001149 wl_list_insert(list, &panel->surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001150 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001151 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001152 }
1153}
1154
1155static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001156click_to_activate_binding(struct wl_input_device *device,
1157 uint32_t time, uint32_t key,
1158 uint32_t button, uint32_t state, void *data)
1159{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001160 struct weston_input_device *wd = (struct weston_input_device *) device;
1161 struct weston_compositor *compositor = data;
1162 struct weston_surface *focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001163
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001164 focus = (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001165 if (state && focus && device->grab == &device->default_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001166 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001167}
1168
1169static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001170lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001171{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001172 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001173 struct wl_list *surface_list = &shell->compositor->surface_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001174 struct weston_surface *cur;
1175 struct weston_surface *tmp;
1176 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001177 struct shell_surface *shsurf;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001178 uint32_t time;
1179
1180 if (shell->locked)
1181 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001182
1183 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001184
1185 /* Move all surfaces from compositor's list to our hidden list,
1186 * except the background. This way nothing else can show or
1187 * receive input events while we are locked. */
1188
1189 if (!wl_list_empty(&shell->hidden_surface_list)) {
1190 fprintf(stderr,
1191 "%s: Assertion failed: hidden_surface_list is not empty.\n",
1192 __func__);
1193 }
1194
1195 wl_list_for_each_safe(cur, tmp, surface_list, link) {
1196 /* skip input device sprites, cur->surface is uninitialised */
1197 if (cur->surface.resource.client == NULL)
1198 continue;
1199
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001200 if (get_shell_surface_type(cur) == SHELL_SURFACE_BACKGROUND)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001201 continue;
1202
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001203 cur->output = NULL;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001204 wl_list_remove(&cur->link);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001205 wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001206 }
1207
Pekka Paalanen77346a62011-11-30 16:26:35 +02001208 launch_screensaver(shell);
1209
1210 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1211 show_screensaver(shell, shsurf);
1212
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001213 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001214 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001215 weston_compositor_wake(shell->compositor);
1216 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001217 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001218
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001219 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001220 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001221
1222 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001223 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001224 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1225 wl_input_device_set_keyboard_focus(&device->input_device,
1226 NULL, time);
1227 }
1228
1229 /* TODO: disable bindings that should not work while locked. */
1230
1231 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001232}
1233
1234static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001235unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001236{
1237 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1238
Pekka Paalanend81c2162011-11-16 13:47:34 +02001239 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001240 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001241 return;
1242 }
1243
1244 /* If desktop-shell client has gone away, unlock immediately. */
1245 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001246 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001247 return;
1248 }
1249
1250 if (shell->prepare_event_sent)
1251 return;
1252
1253 wl_resource_post_event(shell->child.desktop_shell,
1254 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1255 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001256}
1257
1258static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001259center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001260{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001261 struct weston_mode *mode = output->current;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001262
Pekka Paalanen60921e52012-01-25 15:55:43 +02001263 surface->geometry.x =
1264 output->x + (mode->width - surface->geometry.width) / 2;
1265 surface->geometry.y =
1266 output->y + (mode->height - surface->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001267 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001268}
1269
1270static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001271map(struct weston_shell *base,
1272 struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001273{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001274 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001275 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001276 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001277 struct shell_surface *shsurf;
1278 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1279 int do_configure;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001280
Pekka Paalanen77346a62011-11-30 16:26:35 +02001281 shsurf = get_shell_surface(surface);
1282 if (shsurf)
1283 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001284
Pekka Paalanen77346a62011-11-30 16:26:35 +02001285 if (shell->locked) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001286 list = &shell->hidden_surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001287 do_configure = 0;
1288 } else {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001289 list = weston_compositor_top(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001290 do_configure = 1;
1291 }
1292
Pekka Paalanen60921e52012-01-25 15:55:43 +02001293 surface->geometry.width = width;
1294 surface->geometry.height = height;
1295 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001296
1297 /* initial positioning, see also configure() */
1298 switch (surface_type) {
1299 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001300 surface->geometry.x = 10 + random() % 400;
1301 surface->geometry.y = 10 + random() % 400;
1302 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001303 break;
1304 case SHELL_SURFACE_SCREENSAVER:
1305 case SHELL_SURFACE_FULLSCREEN:
1306 center_on_output(surface, surface->fullscreen_output);
1307 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001308 case SHELL_SURFACE_LOCK:
1309 center_on_output(surface, get_default_output(compositor));
1310 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001311 default:
1312 ;
1313 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001314
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001315 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001316 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001317 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001318 /* background always visible, at the bottom */
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001319 wl_list_insert(compositor->surface_list.prev, &surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001320 do_configure = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001321 break;
1322 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001323 /* panel always on top, hidden while locked */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001324 wl_list_insert(list, &surface->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001325 break;
1326 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001327 /* lock surface always visible, on top */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001328 wl_list_insert(&compositor->surface_list, &surface->link);
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001329
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001330 weston_compositor_repick(compositor);
1331 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 switch (surface_type) {
1358 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001359 surface->geometry.x = 10 + random() % 400;
1360 surface->geometry.y = 10 + random() % 400;
1361 surface->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001362 break;
1363 case SHELL_SURFACE_POPUP:
1364 shell_map_popup(shsurf, shsurf->popup.time);
1365 break;
1366 default:
1367 break;
1368 }
1369
Pekka Paalanen60921e52012-01-25 15:55:43 +02001370 surface->geometry.width = width;
1371 surface->geometry.height = height;
1372 surface->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001373 if (do_configure) {
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001374 weston_surface_configure(surface, surface->geometry.x,
1375 surface->geometry.y,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001376 width, height);
1377 weston_compositor_repick(compositor);
1378 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001379
Juan Zhao7bb92f02011-12-15 11:31:51 -05001380 switch (surface_type) {
1381 case SHELL_SURFACE_TOPLEVEL:
1382 case SHELL_SURFACE_TRANSIENT:
1383 case SHELL_SURFACE_FULLSCREEN:
1384 if (!shell->locked)
1385 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001386 (struct weston_input_device *)
Juan Zhao7bb92f02011-12-15 11:31:51 -05001387 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001388 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001389 break;
1390 default:
1391 break;
1392 }
1393
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001394 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001395 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001396}
1397
1398static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001399configure(struct weston_shell *base, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001400 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001401{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001402 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1403 int do_configure = !shell->locked;
1404 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1405 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001406
Pekka Paalanen77346a62011-11-30 16:26:35 +02001407 shsurf = get_shell_surface(surface);
1408 if (shsurf)
1409 surface_type = shsurf->type;
1410
Pekka Paalanen60921e52012-01-25 15:55:43 +02001411 surface->geometry.width = width;
1412 surface->geometry.height = height;
1413 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001414
1415 switch (surface_type) {
1416 case SHELL_SURFACE_SCREENSAVER:
1417 do_configure = !do_configure;
1418 /* fall through */
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001419 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001420 center_on_output(surface, surface->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001421 break;
1422 default:
1423 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001424 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001425
Pekka Paalanen77346a62011-11-30 16:26:35 +02001426 /*
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001427 * weston_surface_configure() will assign an output, which means
Pekka Paalanen77346a62011-11-30 16:26:35 +02001428 * the surface is supposed to be in compositor->surface_list.
1429 * Be careful with that, and make sure we stay on the right output.
1430 * XXX: would a fullscreen surface need the same handling?
1431 */
1432 if (do_configure) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001433 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001434
1435 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1436 surface->output = shsurf->output;
1437 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001438}
1439
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001440static int launch_desktop_shell_process(struct wl_shell *shell);
1441
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001442static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001443desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001444{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001445 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001446 struct wl_shell *shell =
1447 container_of(process, struct wl_shell, child.process);
1448
1449 shell->child.process.pid = 0;
1450 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001451
1452 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1453 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001454 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001455 shell->child.deathstamp = time;
1456 shell->child.deathcount = 0;
1457 }
1458
1459 shell->child.deathcount++;
1460 if (shell->child.deathcount > 5) {
1461 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1462 return;
1463 }
1464
1465 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1466 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001467}
1468
1469static int
1470launch_desktop_shell_process(struct wl_shell *shell)
1471{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001472 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001473
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001474 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001475 &shell->child.process,
1476 shell_exe,
1477 desktop_shell_sigchld);
1478
1479 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001480 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001481 return 0;
1482}
1483
1484static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001485bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1486{
1487 struct wl_shell *shell = data;
1488
1489 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001490 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001491}
1492
Kristian Høgsberg75840622011-09-06 13:48:16 -04001493static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001494unbind_desktop_shell(struct wl_resource *resource)
1495{
1496 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001497
1498 if (shell->locked)
1499 resume_desktop(shell);
1500
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001501 shell->child.desktop_shell = NULL;
1502 shell->prepare_event_sent = false;
1503 free(resource);
1504}
1505
1506static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001507bind_desktop_shell(struct wl_client *client,
1508 void *data, uint32_t version, uint32_t id)
1509{
1510 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001511 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001512
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001513 resource = wl_client_add_object(client, &desktop_shell_interface,
1514 &desktop_shell_implementation,
1515 id, shell);
1516
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001517 if (client == shell->child.client) {
1518 resource->destroy = unbind_desktop_shell;
1519 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001520 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001521 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001522
1523 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1524 "permission to bind desktop_shell denied");
1525 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001526}
1527
Pekka Paalanen6e168112011-11-24 11:34:05 +02001528static void
1529screensaver_set_surface(struct wl_client *client,
1530 struct wl_resource *resource,
1531 struct wl_resource *shell_surface_resource,
1532 struct wl_resource *output_resource)
1533{
1534 struct wl_shell *shell = resource->data;
1535 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001536 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001537
Pekka Paalanen98262232011-12-01 10:42:22 +02001538 if (reset_shell_surface_type(surface))
1539 return;
1540
Pekka Paalanen77346a62011-11-30 16:26:35 +02001541 surface->type = SHELL_SURFACE_SCREENSAVER;
1542
1543 surface->surface->fullscreen_output = output;
1544 surface->output = output;
1545 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001546}
1547
1548static const struct screensaver_interface screensaver_implementation = {
1549 screensaver_set_surface
1550};
1551
1552static void
1553unbind_screensaver(struct wl_resource *resource)
1554{
1555 struct wl_shell *shell = resource->data;
1556
Pekka Paalanen77346a62011-11-30 16:26:35 +02001557 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001558 free(resource);
1559}
1560
1561static void
1562bind_screensaver(struct wl_client *client,
1563 void *data, uint32_t version, uint32_t id)
1564{
1565 struct wl_shell *shell = data;
1566 struct wl_resource *resource;
1567
1568 resource = wl_client_add_object(client, &screensaver_interface,
1569 &screensaver_implementation,
1570 id, shell);
1571
Pekka Paalanen77346a62011-11-30 16:26:35 +02001572 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001573 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001574 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001575 return;
1576 }
1577
1578 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1579 "interface object already bound");
1580 wl_resource_destroy(resource, 0);
1581}
1582
Pekka Paalanen3c647232011-12-22 13:43:43 +02001583static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001584shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001585{
1586 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1587
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001588 if (shell->child.client)
1589 wl_client_destroy(shell->child.client);
1590
Pekka Paalanen3c647232011-12-22 13:43:43 +02001591 free(shell->screensaver.path);
1592 free(shell);
1593}
1594
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001595int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001596shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001597
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001598WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001599shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001600{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001601 struct wl_shell *shell;
1602
1603 shell = malloc(sizeof *shell);
1604 if (shell == NULL)
1605 return -1;
1606
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001607 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001608 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001609 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001610 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001611 shell->shell.map = map;
1612 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02001613 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001614
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001615 wl_list_init(&shell->hidden_surface_list);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001616 wl_list_init(&shell->backgrounds);
1617 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001618 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001619
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001620 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001621
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001622 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
1623 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001624 return -1;
1625
Kristian Høgsberg75840622011-09-06 13:48:16 -04001626 if (wl_display_add_global(ec->wl_display,
1627 &desktop_shell_interface,
1628 shell, bind_desktop_shell) == NULL)
1629 return -1;
1630
Pekka Paalanen6e168112011-11-24 11:34:05 +02001631 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
1632 shell, bind_screensaver) == NULL)
1633 return -1;
1634
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001635 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001636 if (launch_desktop_shell_process(shell) != 0)
1637 return -1;
1638
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001639 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001640 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001641 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001642 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001643 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001644 MODIFIER_CTRL | MODIFIER_ALT,
1645 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001646 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001647 click_to_activate_binding, ec);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001648 weston_compositor_add_binding(ec, 0, BTN_LEFT,
1649 MODIFIER_SUPER | MODIFIER_ALT,
1650 rotate_binding, NULL);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001651
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001652 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001653
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001654 return 0;
1655}