blob: 168443b0f927599fa44fc0e22ff10c612fe03236 [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;
234 int32_t dx, dy, 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;
245
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200246 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500247 width = device->grab_x - device->x + resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200248 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500249 width = device->x - device->grab_x + resize->width;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500250 } else {
251 width = resize->width;
252 }
253
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200254 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500255 height = device->grab_y - device->y + resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200256 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500257 height = device->y - device->grab_y + resize->height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500258 } else {
259 height = resize->height;
260 }
261
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200262 wl_resource_post_event(&resize->shsurf->resource,
263 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
264 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500265}
266
267static void
268resize_grab_button(struct wl_grab *grab,
269 uint32_t time, int32_t button, int32_t state)
270{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500271 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500272
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500273 if (device->button_count == 0 && state == 0) {
274 wl_input_device_end_grab(device, time);
275 free(grab);
276 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500277}
278
279static const struct wl_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500280 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500281 resize_grab_motion,
282 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500283};
284
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400285static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500286weston_surface_resize(struct shell_surface *shsurf,
287 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200288 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500289{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500290 struct weston_resize_grab *resize;
291 struct weston_surface *es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500292
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500293 /* FIXME: Reject if fullscreen */
294
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500295 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400296 if (!resize)
297 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500298
299 resize->grab.interface = &resize_grab_interface;
300 resize->edges = edges;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200301 resize->dx = es->geometry.x - wd->input_device.grab_x;
302 resize->dy = es->geometry.y - wd->input_device.grab_y;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200303 resize->width = es->geometry.width;
304 resize->height = es->geometry.height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200305 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400306
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500307 if (edges == 0 || edges > 15 ||
308 (edges & 3) == 3 || (edges & 12) == 12)
Pekka Paalanen61b5c672012-01-04 14:09:05 +0200309 goto err_out;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500310
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500311 wl_input_device_start_grab(&wd->input_device, &resize->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500312
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400313 wl_input_device_set_pointer_focus(&wd->input_device,
314 NULL, time, 0, 0, 0, 0);
315
316 return 0;
Pekka Paalanen61b5c672012-01-04 14:09:05 +0200317
318err_out:
319 free(resize);
320 return 0;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400321}
322
323static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200324shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
325 struct wl_resource *input_resource, uint32_t time,
326 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400327{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500328 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200329 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400330
331 /* FIXME: Reject if fullscreen */
332
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500333 if (wd->input_device.button_count == 0 ||
334 wd->input_device.grab_time != time ||
335 wd->input_device.pointer_focus != &shsurf->surface->surface)
336 return;
337
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500338 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400339 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500340}
341
Pekka Paalanen98262232011-12-01 10:42:22 +0200342static int
343reset_shell_surface_type(struct shell_surface *surface)
344{
345 switch (surface->type) {
346 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200347 surface->surface->geometry.x = surface->saved_x;
348 surface->surface->geometry.y = surface->saved_y;
349 surface->surface->geometry.dirty = 1;
Pekka Paalanen98262232011-12-01 10:42:22 +0200350 surface->surface->fullscreen_output = NULL;
351 break;
352 case SHELL_SURFACE_PANEL:
353 case SHELL_SURFACE_BACKGROUND:
354 wl_list_remove(&surface->link);
355 wl_list_init(&surface->link);
356 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200357 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200358 case SHELL_SURFACE_LOCK:
359 wl_resource_post_error(&surface->resource,
360 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200361 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200362 return -1;
363 case SHELL_SURFACE_NONE:
364 case SHELL_SURFACE_TOPLEVEL:
365 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500366 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200367 break;
368 }
369
370 surface->type = SHELL_SURFACE_NONE;
371 return 0;
372}
373
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500374static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200375shell_surface_set_toplevel(struct wl_client *client,
376 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400377
378{
Pekka Paalanen98262232011-12-01 10:42:22 +0200379 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400380
Pekka Paalanen98262232011-12-01 10:42:22 +0200381 if (reset_shell_surface_type(surface))
382 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400383
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500384 weston_surface_damage(surface->surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200385 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400386}
387
388static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200389shell_surface_set_transient(struct wl_client *client,
390 struct wl_resource *resource,
391 struct wl_resource *parent_resource,
392 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400393{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200394 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500395 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200396 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500397 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400398
Pekka Paalanen98262232011-12-01 10:42:22 +0200399 if (reset_shell_surface_type(shsurf))
400 return;
401
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400402 /* assign to parents output */
403 es->output = pes->output;
404
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200405 es->geometry.x = pes->geometry.x + x;
406 es->geometry.y = pes->geometry.y + y;
407 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400408
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500409 weston_surface_damage(es);
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;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500443 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200444 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400445}
446
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500447static void
448popup_grab_focus(struct wl_grab *grab, uint32_t time,
449 struct wl_surface *surface, int32_t x, int32_t y)
450{
451 struct wl_input_device *device = grab->input_device;
452 struct shell_surface *priv =
453 container_of(grab, struct shell_surface, popup.grab);
454 struct wl_client *client = priv->surface->surface.resource.client;
455
Pekka Paalanencb108432012-01-19 16:25:40 +0200456 if (surface && surface->resource.client == client) {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500457 wl_input_device_set_pointer_focus(device, surface, time,
458 device->x, device->y, x, y);
459 grab->focus = surface;
460 } else {
461 wl_input_device_set_pointer_focus(device, NULL,
462 time, 0, 0, 0, 0);
463 grab->focus = NULL;
464 }
465}
466
467static void
468popup_grab_motion(struct wl_grab *grab,
469 uint32_t time, int32_t x, int32_t y)
470{
471 struct wl_input_device *device = grab->input_device;
472 struct wl_resource *resource;
473
474 resource = grab->input_device->pointer_focus_resource;
475 if (resource)
476 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
477 time, device->x, device->y, x, y);
478}
479
480static void
481popup_grab_button(struct wl_grab *grab,
482 uint32_t time, int32_t button, int32_t state)
483{
484 struct wl_resource *resource;
485 struct shell_surface *shsurf =
486 container_of(grab, struct shell_surface, popup.grab);
487
488 resource = grab->input_device->pointer_focus_resource;
489 if (resource) {
490 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
491 time, button, state);
492 } else if (state == 0 &&
493 (shsurf->popup.initial_up ||
494 time - shsurf->popup.time > 500)) {
495 wl_resource_post_event(&shsurf->resource,
496 WL_SHELL_SURFACE_POPUP_DONE);
497 wl_input_device_end_grab(grab->input_device, time);
498 shsurf->popup.grab.input_device = NULL;
499 }
500
501 if (state == 0)
502 shsurf->popup.initial_up = 1;
503}
504
505static const struct wl_grab_interface popup_grab_interface = {
506 popup_grab_focus,
507 popup_grab_motion,
508 popup_grab_button,
509};
510
511static void
512shell_map_popup(struct shell_surface *shsurf, uint32_t time)
513{
514 struct wl_input_device *device;
515 struct weston_surface *es = shsurf->surface;
516 struct weston_surface *parent = shsurf->parent->surface;
517
518 es->output = parent->output;
519
520 shsurf->popup.grab.interface = &popup_grab_interface;
521 device = es->compositor->input_device;
522
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200523 es->geometry.x = shsurf->parent->surface->geometry.x + shsurf->popup.x;
524 es->geometry.y = shsurf->parent->surface->geometry.y + shsurf->popup.y;
525 es->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500526
527 shsurf->popup.grab.input_device = device;
528 shsurf->popup.time = device->grab_time;
529 shsurf->popup.initial_up = 0;
530
531 wl_input_device_start_grab(shsurf->popup.grab.input_device,
532 &shsurf->popup.grab, shsurf->popup.time);
533}
534
535static void
536shell_surface_set_popup(struct wl_client *client,
537 struct wl_resource *resource,
538 struct wl_resource *input_device_resource,
539 uint32_t time,
540 struct wl_resource *parent_resource,
541 int32_t x, int32_t y, uint32_t flags)
542{
543 struct shell_surface *shsurf = resource->data;
544 struct weston_surface *es = shsurf->surface;
545
546 weston_surface_damage(es);
547 shsurf->type = SHELL_SURFACE_POPUP;
548 shsurf->parent = parent_resource->data;
549 shsurf->popup.x = x;
550 shsurf->popup.y = y;
551}
552
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200553static const struct wl_shell_surface_interface shell_surface_implementation = {
554 shell_surface_move,
555 shell_surface_resize,
556 shell_surface_set_toplevel,
557 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500558 shell_surface_set_fullscreen,
559 shell_surface_set_popup
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200560};
561
562static void
563destroy_shell_surface(struct wl_resource *resource)
564{
565 struct shell_surface *shsurf = resource->data;
566
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500567 if (shsurf->popup.grab.input_device)
568 wl_input_device_end_grab(shsurf->popup.grab.input_device, 0);
569
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200570 /* in case cleaning up a dead client destroys shell_surface first */
571 if (shsurf->surface)
572 wl_list_remove(&shsurf->surface_destroy_listener.link);
573
574 wl_list_remove(&shsurf->link);
575 free(shsurf);
576}
577
578static void
579shell_handle_surface_destroy(struct wl_listener *listener,
580 struct wl_resource *resource, uint32_t time)
581{
582 struct shell_surface *shsurf = container_of(listener,
583 struct shell_surface,
584 surface_destroy_listener);
585
586 shsurf->surface = NULL;
587 wl_resource_destroy(&shsurf->resource, time);
588}
589
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200590static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500591get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200592{
593 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
594 struct wl_listener *listener;
595
596 /* search the destroy listener list for our callback */
597 wl_list_for_each(listener, lst, link) {
598 if (listener->func == shell_handle_surface_destroy) {
599 return container_of(listener, struct shell_surface,
600 surface_destroy_listener);
601 }
602 }
603
604 return NULL;
605}
606
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200607static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200608shell_get_shell_surface(struct wl_client *client,
609 struct wl_resource *resource,
610 uint32_t id,
611 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200612{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500613 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200614 struct shell_surface *shsurf;
615
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200616 if (get_shell_surface(surface)) {
617 wl_resource_post_error(surface_resource,
618 WL_DISPLAY_ERROR_INVALID_OBJECT,
619 "wl_shell::get_shell_surface already requested");
620 return;
621 }
622
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200623 shsurf = calloc(1, sizeof *shsurf);
624 if (!shsurf) {
625 wl_resource_post_no_memory(resource);
626 return;
627 }
628
629 shsurf->resource.destroy = destroy_shell_surface;
630 shsurf->resource.object.id = id;
631 shsurf->resource.object.interface = &wl_shell_surface_interface;
632 shsurf->resource.object.implementation =
633 (void (**)(void)) &shell_surface_implementation;
634 shsurf->resource.data = shsurf;
635
636 shsurf->surface = surface;
637 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
638 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
639 &shsurf->surface_destroy_listener.link);
640
641 /* init link so its safe to always remove it in destroy_shell_surface */
642 wl_list_init(&shsurf->link);
643
Pekka Paalanen460099f2012-01-20 16:48:25 +0200644 /* empty when not in use */
645 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500646 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200647
Pekka Paalanen98262232011-12-01 10:42:22 +0200648 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200649
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200650 wl_client_add_resource(client, &shsurf->resource);
651}
652
653static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200654 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500655};
656
Kristian Høgsberg07937562011-04-12 17:25:42 -0400657static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500658handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200659{
660 proc->pid = 0;
661}
662
663static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200664launch_screensaver(struct wl_shell *shell)
665{
666 if (shell->screensaver.binding)
667 return;
668
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200669 if (!shell->screensaver.path)
670 return;
671
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500672 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200673 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200674 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200675 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200676}
677
678static void
679terminate_screensaver(struct wl_shell *shell)
680{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200681 if (shell->screensaver.process.pid == 0)
682 return;
683
684 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200685}
686
687static void
688show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
689{
690 struct wl_list *list;
691
692 if (shell->lock_surface)
693 list = &shell->lock_surface->surface->link;
694 else
695 list = &shell->compositor->surface_list;
696
697 wl_list_remove(&surface->surface->link);
698 wl_list_insert(list, &surface->surface->link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500699 weston_surface_configure(surface->surface,
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200700 surface->surface->geometry.x,
701 surface->surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200702 surface->surface->geometry.width,
703 surface->surface->geometry.height);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200704 surface->surface->output = surface->output;
705}
706
707static void
708hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
709{
710 wl_list_remove(&surface->surface->link);
711 wl_list_init(&surface->surface->link);
712 surface->surface->output = NULL;
713}
714
715static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400716desktop_shell_set_background(struct wl_client *client,
717 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100718 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400719 struct wl_resource *surface_resource)
720{
721 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200722 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500723 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200724 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400725
Pekka Paalanen98262232011-12-01 10:42:22 +0200726 if (reset_shell_surface_type(shsurf))
727 return;
728
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100729 wl_list_for_each(priv, &shell->backgrounds, link) {
730 if (priv->output == output_resource->data) {
731 priv->surface->output = NULL;
732 wl_list_remove(&priv->surface->link);
733 wl_list_remove(&priv->link);
734 break;
735 }
736 }
737
Pekka Paalanen068ae942011-11-28 14:11:15 +0200738 shsurf->type = SHELL_SURFACE_BACKGROUND;
739 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100740
Pekka Paalanen068ae942011-11-28 14:11:15 +0200741 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100742
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200743 surface->geometry.x = shsurf->output->x;
744 surface->geometry.y = shsurf->output->y;
745 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200746
Kristian Høgsberg75840622011-09-06 13:48:16 -0400747 wl_resource_post_event(resource,
748 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500749 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200750 shsurf->output->current->width,
751 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400752}
753
754static void
755desktop_shell_set_panel(struct wl_client *client,
756 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100757 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400758 struct wl_resource *surface_resource)
759{
760 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200761 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500762 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200763 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400764
Pekka Paalanen98262232011-12-01 10:42:22 +0200765 if (reset_shell_surface_type(shsurf))
766 return;
767
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100768 wl_list_for_each(priv, &shell->panels, link) {
769 if (priv->output == output_resource->data) {
770 priv->surface->output = NULL;
771 wl_list_remove(&priv->surface->link);
772 wl_list_remove(&priv->link);
773 break;
774 }
775 }
776
Pekka Paalanen068ae942011-11-28 14:11:15 +0200777 shsurf->type = SHELL_SURFACE_PANEL;
778 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100779
Pekka Paalanen068ae942011-11-28 14:11:15 +0200780 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100781
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200782 surface->geometry.x = shsurf->output->x;
783 surface->geometry.y = shsurf->output->y;
784 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200785
Kristian Høgsberg75840622011-09-06 13:48:16 -0400786 wl_resource_post_event(resource,
787 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500788 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200789 shsurf->output->current->width,
790 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400791}
792
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200793static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500794handle_lock_surface_destroy(struct wl_listener *listener,
795 struct wl_resource *resource, uint32_t time)
796{
797 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +0200798 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500799
800 fprintf(stderr, "lock surface gone\n");
801 shell->lock_surface = NULL;
802}
803
804static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200805desktop_shell_set_lock_surface(struct wl_client *client,
806 struct wl_resource *resource,
807 struct wl_resource *surface_resource)
808{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200809 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200810 struct shell_surface *surface = surface_resource->data;
811
812 if (reset_shell_surface_type(surface))
813 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200814
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200815 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200816
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200817 if (!shell->locked)
818 return;
819
Pekka Paalanen98262232011-12-01 10:42:22 +0200820 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200821
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500822 shell->lock_surface_listener.func = handle_lock_surface_destroy;
823 wl_list_insert(&surface_resource->destroy_listener_list,
824 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200825
Pekka Paalanen068ae942011-11-28 14:11:15 +0200826 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200827}
828
829static void
830resume_desktop(struct wl_shell *shell)
831{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500832 struct weston_surface *surface;
Pekka Paalanenfe340832011-11-25 16:07:52 +0200833 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200834 struct shell_surface *tmp;
835
836 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
837 hide_screensaver(shell, tmp);
838
839 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200840
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500841 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200842 weston_surface_configure(surface, surface->geometry.x,
843 surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200844 surface->geometry.width,
845 surface->geometry.height);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200846
Pekka Paalanenfe340832011-11-25 16:07:52 +0200847 if (wl_list_empty(&shell->backgrounds)) {
848 list = &shell->compositor->surface_list;
849 } else {
850 struct shell_surface *background;
851 background = container_of(shell->backgrounds.prev,
852 struct shell_surface, link);
853 list = background->surface->link.prev;
854 }
855
856 if (!wl_list_empty(&shell->hidden_surface_list))
857 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500858 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200859
860 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500861 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200862 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500863 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200864}
865
866static void
867desktop_shell_unlock(struct wl_client *client,
868 struct wl_resource *resource)
869{
870 struct wl_shell *shell = resource->data;
871
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200872 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200873
874 if (shell->locked)
875 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200876}
877
Kristian Høgsberg75840622011-09-06 13:48:16 -0400878static const struct desktop_shell_interface desktop_shell_implementation = {
879 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200880 desktop_shell_set_panel,
881 desktop_shell_set_lock_surface,
882 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400883};
884
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200885static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500886get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200887{
888 struct shell_surface *shsurf;
889
890 shsurf = get_shell_surface(surface);
891 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200892 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200893 return shsurf->type;
894}
895
Kristian Høgsberg75840622011-09-06 13:48:16 -0400896static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400897move_binding(struct wl_input_device *device, uint32_t time,
898 uint32_t key, uint32_t button, uint32_t state, void *data)
899{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500900 struct weston_surface *surface =
901 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500902
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100903 if (surface == NULL)
904 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400905
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200906 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100907 case SHELL_SURFACE_PANEL:
908 case SHELL_SURFACE_BACKGROUND:
909 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200910 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100911 return;
912 default:
913 break;
914 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400915
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500916 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400917}
918
919static void
920resize_binding(struct wl_input_device *device, uint32_t time,
921 uint32_t key, uint32_t button, uint32_t state, void *data)
922{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500923 struct weston_surface *surface =
924 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400925 uint32_t edges = 0;
926 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200927 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500928
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100929 if (surface == NULL)
930 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200931
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200932 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200933 if (!shsurf)
934 return;
935
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200936 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100937 case SHELL_SURFACE_PANEL:
938 case SHELL_SURFACE_BACKGROUND:
939 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200940 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100941 return;
942 default:
943 break;
944 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400945
Pekka Paalanen60921e52012-01-25 15:55:43 +0200946 /* FIXME: convert properly to surface coordinates */
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200947 x = device->grab_x - surface->geometry.x;
948 y = device->grab_y - surface->geometry.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;
986 GLfloat dx, dy;
987 GLfloat r;
988
989 dx = device->x - rotate->center.x;
990 dy = device->y - rotate->center.y;
991 r = sqrtf(dx * dx + dy * dy);
992
993 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200994 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200995
996 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200997 struct weston_matrix *matrix =
998 &surface->rotation.transform.matrix;
999
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001000 weston_matrix_init(&rotate->rotation);
1001 rotate->rotation.d[0] = dx / r;
1002 rotate->rotation.d[4] = -dy / r;
1003 rotate->rotation.d[1] = -rotate->rotation.d[4];
1004 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001005
1006 weston_matrix_init(matrix);
1007 weston_matrix_translate(matrix, -rotate->center.x,
1008 -rotate->center.y, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001009 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1010 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001011 weston_matrix_translate(matrix, rotate->center.x,
1012 rotate->center.y, 0.0f);
1013
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001014 wl_list_insert(
1015 surface->surface->geometry.transformation_list.prev,
1016 &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,
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001400 int32_t x, int32_t y, int32_t width, int32_t height)
1401{
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}