blob: c78061062433f4ae38ac3acb8669f0360b89a5e8 [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;
99 } rotation;
100
101 struct {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500102 struct wl_grab grab;
103 uint32_t time;
104 int32_t x, y;
105 int32_t initial_up;
106 } popup;
107
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500108 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100109 struct wl_list link;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200110};
111
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500112struct weston_move_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500113 struct wl_grab grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500114 struct weston_surface *surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500115 int32_t dx, dy;
116};
117
Pekka Paalanen460099f2012-01-20 16:48:25 +0200118struct rotate_grab {
119 struct wl_grab grab;
120 struct shell_surface *surface;
121 struct {
122 int32_t x;
123 int32_t y;
124 } center;
125};
126
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500127static void
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200128shell_configuration(struct wl_shell *shell)
129{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200130 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200131 char *path = NULL;
132 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200133
134 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200135 { "path", CONFIG_KEY_STRING, &path },
136 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200137 };
138
139 struct config_section cs[] = {
140 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
141 };
142
Kristian Høgsberg9724b512012-01-03 14:35:49 -0500143 config_file = config_file_path("weston-desktop-shell.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500144 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200145 free(config_file);
146
Pekka Paalanen7296e792011-12-07 16:22:00 +0200147 shell->screensaver.path = path;
148 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200149}
150
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200151static void
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500152noop_grab_focus(struct wl_grab *grab, uint32_t time,
153 struct wl_surface *surface, int32_t x, int32_t y)
154{
155 grab->focus = NULL;
156}
157
158static void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500159move_grab_motion(struct wl_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500160 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500161{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500162 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500163 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500164 struct weston_surface *es = move->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500165
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500166 weston_surface_configure(es,
167 device->x + move->dx,
168 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200169 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500170}
171
172static void
173move_grab_button(struct wl_grab *grab,
174 uint32_t time, int32_t button, int32_t state)
175{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500176 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500177
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500178 if (device->button_count == 0 && state == 0) {
179 wl_input_device_end_grab(device, time);
180 free(grab);
181 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500182}
183
184static const struct wl_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500185 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500186 move_grab_motion,
187 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500188};
189
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400190static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500191weston_surface_move(struct weston_surface *es,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500192 struct weston_input_device *wd, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500193{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500194 struct weston_move_grab *move;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500195
196 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400197 if (!move)
198 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500199
200 move->grab.interface = &move_grab_interface;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200201 move->dx = es->geometry.x - wd->input_device.grab_x;
202 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -0500203 move->surface = es;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500204
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500205 wl_input_device_start_grab(&wd->input_device, &move->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500206
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400207 wl_input_device_set_pointer_focus(&wd->input_device,
208 NULL, time, 0, 0, 0, 0);
209
210 return 0;
211}
212
213static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200214shell_surface_move(struct wl_client *client, struct wl_resource *resource,
215 struct wl_resource *input_resource, uint32_t time)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400216{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500217 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200218 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400219
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500220 if (wd->input_device.button_count == 0 ||
221 wd->input_device.grab_time != time ||
222 wd->input_device.pointer_focus != &shsurf->surface->surface)
223 return;
224
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500225 if (weston_surface_move(shsurf->surface, wd, time) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400226 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500227}
228
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500229struct weston_resize_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500230 struct wl_grab grab;
231 uint32_t edges;
232 int32_t dx, dy, width, height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200233 struct shell_surface *shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500234};
235
236static void
237resize_grab_motion(struct wl_grab *grab,
238 uint32_t time, int32_t x, int32_t y)
239{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500240 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500241 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500242 int32_t width, height;
243
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200244 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500245 width = device->grab_x - device->x + resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200246 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500247 width = device->x - device->grab_x + resize->width;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500248 } else {
249 width = resize->width;
250 }
251
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200252 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500253 height = device->grab_y - device->y + resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200254 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500255 height = device->y - device->grab_y + resize->height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500256 } else {
257 height = resize->height;
258 }
259
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200260 wl_resource_post_event(&resize->shsurf->resource,
261 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
262 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500263}
264
265static void
266resize_grab_button(struct wl_grab *grab,
267 uint32_t time, int32_t button, int32_t state)
268{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500269 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500270
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500271 if (device->button_count == 0 && state == 0) {
272 wl_input_device_end_grab(device, time);
273 free(grab);
274 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500275}
276
277static const struct wl_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500278 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500279 resize_grab_motion,
280 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500281};
282
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400283static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500284weston_surface_resize(struct shell_surface *shsurf,
285 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200286 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500287{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500288 struct weston_resize_grab *resize;
289 struct weston_surface *es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500290
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500291 /* FIXME: Reject if fullscreen */
292
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500293 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400294 if (!resize)
295 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500296
297 resize->grab.interface = &resize_grab_interface;
298 resize->edges = edges;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200299 resize->dx = es->geometry.x - wd->input_device.grab_x;
300 resize->dy = es->geometry.y - wd->input_device.grab_y;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200301 resize->width = es->geometry.width;
302 resize->height = es->geometry.height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200303 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400304
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500305 if (edges == 0 || edges > 15 ||
306 (edges & 3) == 3 || (edges & 12) == 12)
Pekka Paalanen61b5c672012-01-04 14:09:05 +0200307 goto err_out;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500308
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500309 wl_input_device_start_grab(&wd->input_device, &resize->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500310
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400311 wl_input_device_set_pointer_focus(&wd->input_device,
312 NULL, time, 0, 0, 0, 0);
313
314 return 0;
Pekka Paalanen61b5c672012-01-04 14:09:05 +0200315
316err_out:
317 free(resize);
318 return 0;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400319}
320
321static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200322shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
323 struct wl_resource *input_resource, uint32_t time,
324 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400325{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500326 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200327 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400328
329 /* FIXME: Reject if fullscreen */
330
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500331 if (wd->input_device.button_count == 0 ||
332 wd->input_device.grab_time != time ||
333 wd->input_device.pointer_focus != &shsurf->surface->surface)
334 return;
335
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500336 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400337 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500338}
339
Pekka Paalanen98262232011-12-01 10:42:22 +0200340static int
341reset_shell_surface_type(struct shell_surface *surface)
342{
343 switch (surface->type) {
344 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200345 surface->surface->geometry.x = surface->saved_x;
346 surface->surface->geometry.y = surface->saved_y;
347 surface->surface->geometry.dirty = 1;
Pekka Paalanen98262232011-12-01 10:42:22 +0200348 surface->surface->fullscreen_output = NULL;
349 break;
350 case SHELL_SURFACE_PANEL:
351 case SHELL_SURFACE_BACKGROUND:
352 wl_list_remove(&surface->link);
353 wl_list_init(&surface->link);
354 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200355 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200356 case SHELL_SURFACE_LOCK:
357 wl_resource_post_error(&surface->resource,
358 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200359 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200360 return -1;
361 case SHELL_SURFACE_NONE:
362 case SHELL_SURFACE_TOPLEVEL:
363 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500364 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200365 break;
366 }
367
368 surface->type = SHELL_SURFACE_NONE;
369 return 0;
370}
371
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500372static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200373shell_surface_set_toplevel(struct wl_client *client,
374 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400375
376{
Pekka Paalanen98262232011-12-01 10:42:22 +0200377 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400378
Pekka Paalanen98262232011-12-01 10:42:22 +0200379 if (reset_shell_surface_type(surface))
380 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400381
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500382 weston_surface_damage(surface->surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200383 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400384}
385
386static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200387shell_surface_set_transient(struct wl_client *client,
388 struct wl_resource *resource,
389 struct wl_resource *parent_resource,
390 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400391{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200392 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500393 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200394 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500395 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400396
Pekka Paalanen98262232011-12-01 10:42:22 +0200397 if (reset_shell_surface_type(shsurf))
398 return;
399
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400400 /* assign to parents output */
401 es->output = pes->output;
402
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200403 es->geometry.x = pes->geometry.x + x;
404 es->geometry.y = pes->geometry.y + y;
405 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400406
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500407 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200408 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400409}
410
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500411static struct weston_output *
412get_default_output(struct weston_compositor *compositor)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200413{
414 return container_of(compositor->output_list.next,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500415 struct weston_output, link);
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200416}
417
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400418static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200419shell_surface_set_fullscreen(struct wl_client *client,
420 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400421
422{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200423 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500424 struct weston_surface *es = shsurf->surface;
425 struct weston_output *output;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400426
Pekka Paalanen98262232011-12-01 10:42:22 +0200427 if (reset_shell_surface_type(shsurf))
428 return;
429
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400430 /* FIXME: Fullscreen on first output */
431 /* FIXME: Handle output going away */
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200432 output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400433 es->output = output;
434
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200435 shsurf->saved_x = es->geometry.x;
436 shsurf->saved_y = es->geometry.y;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200437 es->geometry.x = (output->current->width - es->geometry.width) / 2;
438 es->geometry.y = (output->current->height - es->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200439 es->geometry.dirty = 1;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400440 es->fullscreen_output = output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500441 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200442 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400443}
444
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500445static void
446popup_grab_focus(struct wl_grab *grab, uint32_t time,
447 struct wl_surface *surface, int32_t x, int32_t y)
448{
449 struct wl_input_device *device = grab->input_device;
450 struct shell_surface *priv =
451 container_of(grab, struct shell_surface, popup.grab);
452 struct wl_client *client = priv->surface->surface.resource.client;
453
Pekka Paalanencb108432012-01-19 16:25:40 +0200454 if (surface && surface->resource.client == client) {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500455 wl_input_device_set_pointer_focus(device, surface, time,
456 device->x, device->y, x, y);
457 grab->focus = surface;
458 } else {
459 wl_input_device_set_pointer_focus(device, NULL,
460 time, 0, 0, 0, 0);
461 grab->focus = NULL;
462 }
463}
464
465static void
466popup_grab_motion(struct wl_grab *grab,
467 uint32_t time, int32_t x, int32_t y)
468{
469 struct wl_input_device *device = grab->input_device;
470 struct wl_resource *resource;
471
472 resource = grab->input_device->pointer_focus_resource;
473 if (resource)
474 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
475 time, device->x, device->y, x, y);
476}
477
478static void
479popup_grab_button(struct wl_grab *grab,
480 uint32_t time, int32_t button, int32_t state)
481{
482 struct wl_resource *resource;
483 struct shell_surface *shsurf =
484 container_of(grab, struct shell_surface, popup.grab);
485
486 resource = grab->input_device->pointer_focus_resource;
487 if (resource) {
488 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
489 time, button, state);
490 } else if (state == 0 &&
491 (shsurf->popup.initial_up ||
492 time - shsurf->popup.time > 500)) {
493 wl_resource_post_event(&shsurf->resource,
494 WL_SHELL_SURFACE_POPUP_DONE);
495 wl_input_device_end_grab(grab->input_device, time);
496 shsurf->popup.grab.input_device = NULL;
497 }
498
499 if (state == 0)
500 shsurf->popup.initial_up = 1;
501}
502
503static const struct wl_grab_interface popup_grab_interface = {
504 popup_grab_focus,
505 popup_grab_motion,
506 popup_grab_button,
507};
508
509static void
510shell_map_popup(struct shell_surface *shsurf, uint32_t time)
511{
512 struct wl_input_device *device;
513 struct weston_surface *es = shsurf->surface;
514 struct weston_surface *parent = shsurf->parent->surface;
515
516 es->output = parent->output;
517
518 shsurf->popup.grab.interface = &popup_grab_interface;
519 device = es->compositor->input_device;
520
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200521 es->geometry.x = shsurf->parent->surface->geometry.x + shsurf->popup.x;
522 es->geometry.y = shsurf->parent->surface->geometry.y + shsurf->popup.y;
523 es->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500524
525 shsurf->popup.grab.input_device = device;
526 shsurf->popup.time = device->grab_time;
527 shsurf->popup.initial_up = 0;
528
529 wl_input_device_start_grab(shsurf->popup.grab.input_device,
530 &shsurf->popup.grab, shsurf->popup.time);
531}
532
533static void
534shell_surface_set_popup(struct wl_client *client,
535 struct wl_resource *resource,
536 struct wl_resource *input_device_resource,
537 uint32_t time,
538 struct wl_resource *parent_resource,
539 int32_t x, int32_t y, uint32_t flags)
540{
541 struct shell_surface *shsurf = resource->data;
542 struct weston_surface *es = shsurf->surface;
543
544 weston_surface_damage(es);
545 shsurf->type = SHELL_SURFACE_POPUP;
546 shsurf->parent = parent_resource->data;
547 shsurf->popup.x = x;
548 shsurf->popup.y = y;
549}
550
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200551static const struct wl_shell_surface_interface shell_surface_implementation = {
552 shell_surface_move,
553 shell_surface_resize,
554 shell_surface_set_toplevel,
555 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500556 shell_surface_set_fullscreen,
557 shell_surface_set_popup
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200558};
559
560static void
561destroy_shell_surface(struct wl_resource *resource)
562{
563 struct shell_surface *shsurf = resource->data;
564
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500565 if (shsurf->popup.grab.input_device)
566 wl_input_device_end_grab(shsurf->popup.grab.input_device, 0);
567
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200568 /* in case cleaning up a dead client destroys shell_surface first */
569 if (shsurf->surface)
570 wl_list_remove(&shsurf->surface_destroy_listener.link);
571
572 wl_list_remove(&shsurf->link);
573 free(shsurf);
574}
575
576static void
577shell_handle_surface_destroy(struct wl_listener *listener,
578 struct wl_resource *resource, uint32_t time)
579{
580 struct shell_surface *shsurf = container_of(listener,
581 struct shell_surface,
582 surface_destroy_listener);
583
584 shsurf->surface = NULL;
585 wl_resource_destroy(&shsurf->resource, time);
586}
587
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200588static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500589get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200590{
591 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
592 struct wl_listener *listener;
593
594 /* search the destroy listener list for our callback */
595 wl_list_for_each(listener, lst, link) {
596 if (listener->func == shell_handle_surface_destroy) {
597 return container_of(listener, struct shell_surface,
598 surface_destroy_listener);
599 }
600 }
601
602 return NULL;
603}
604
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200605static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200606shell_get_shell_surface(struct wl_client *client,
607 struct wl_resource *resource,
608 uint32_t id,
609 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200610{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500611 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200612 struct shell_surface *shsurf;
613
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200614 if (get_shell_surface(surface)) {
615 wl_resource_post_error(surface_resource,
616 WL_DISPLAY_ERROR_INVALID_OBJECT,
617 "wl_shell::get_shell_surface already requested");
618 return;
619 }
620
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200621 shsurf = calloc(1, sizeof *shsurf);
622 if (!shsurf) {
623 wl_resource_post_no_memory(resource);
624 return;
625 }
626
627 shsurf->resource.destroy = destroy_shell_surface;
628 shsurf->resource.object.id = id;
629 shsurf->resource.object.interface = &wl_shell_surface_interface;
630 shsurf->resource.object.implementation =
631 (void (**)(void)) &shell_surface_implementation;
632 shsurf->resource.data = shsurf;
633
634 shsurf->surface = surface;
635 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
636 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
637 &shsurf->surface_destroy_listener.link);
638
639 /* init link so its safe to always remove it in destroy_shell_surface */
640 wl_list_init(&shsurf->link);
641
Pekka Paalanen460099f2012-01-20 16:48:25 +0200642 /* empty when not in use */
643 wl_list_init(&shsurf->rotation.transform.link);
644
Pekka Paalanen98262232011-12-01 10:42:22 +0200645 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200646
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200647 wl_client_add_resource(client, &shsurf->resource);
648}
649
650static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200651 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500652};
653
Kristian Høgsberg07937562011-04-12 17:25:42 -0400654static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500655handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200656{
657 proc->pid = 0;
658}
659
660static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200661launch_screensaver(struct wl_shell *shell)
662{
663 if (shell->screensaver.binding)
664 return;
665
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200666 if (!shell->screensaver.path)
667 return;
668
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500669 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200670 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200671 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200672 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200673}
674
675static void
676terminate_screensaver(struct wl_shell *shell)
677{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200678 if (shell->screensaver.process.pid == 0)
679 return;
680
681 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200682}
683
684static void
685show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
686{
687 struct wl_list *list;
688
689 if (shell->lock_surface)
690 list = &shell->lock_surface->surface->link;
691 else
692 list = &shell->compositor->surface_list;
693
694 wl_list_remove(&surface->surface->link);
695 wl_list_insert(list, &surface->surface->link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500696 weston_surface_configure(surface->surface,
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200697 surface->surface->geometry.x,
698 surface->surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200699 surface->surface->geometry.width,
700 surface->surface->geometry.height);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200701 surface->surface->output = surface->output;
702}
703
704static void
705hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
706{
707 wl_list_remove(&surface->surface->link);
708 wl_list_init(&surface->surface->link);
709 surface->surface->output = NULL;
710}
711
712static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400713desktop_shell_set_background(struct wl_client *client,
714 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100715 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400716 struct wl_resource *surface_resource)
717{
718 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200719 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500720 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200721 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400722
Pekka Paalanen98262232011-12-01 10:42:22 +0200723 if (reset_shell_surface_type(shsurf))
724 return;
725
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100726 wl_list_for_each(priv, &shell->backgrounds, link) {
727 if (priv->output == output_resource->data) {
728 priv->surface->output = NULL;
729 wl_list_remove(&priv->surface->link);
730 wl_list_remove(&priv->link);
731 break;
732 }
733 }
734
Pekka Paalanen068ae942011-11-28 14:11:15 +0200735 shsurf->type = SHELL_SURFACE_BACKGROUND;
736 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100737
Pekka Paalanen068ae942011-11-28 14:11:15 +0200738 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100739
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200740 surface->geometry.x = shsurf->output->x;
741 surface->geometry.y = shsurf->output->y;
742 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200743
Kristian Høgsberg75840622011-09-06 13:48:16 -0400744 wl_resource_post_event(resource,
745 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500746 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200747 shsurf->output->current->width,
748 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400749}
750
751static void
752desktop_shell_set_panel(struct wl_client *client,
753 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100754 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400755 struct wl_resource *surface_resource)
756{
757 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200758 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500759 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200760 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400761
Pekka Paalanen98262232011-12-01 10:42:22 +0200762 if (reset_shell_surface_type(shsurf))
763 return;
764
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100765 wl_list_for_each(priv, &shell->panels, link) {
766 if (priv->output == output_resource->data) {
767 priv->surface->output = NULL;
768 wl_list_remove(&priv->surface->link);
769 wl_list_remove(&priv->link);
770 break;
771 }
772 }
773
Pekka Paalanen068ae942011-11-28 14:11:15 +0200774 shsurf->type = SHELL_SURFACE_PANEL;
775 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100776
Pekka Paalanen068ae942011-11-28 14:11:15 +0200777 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100778
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200779 surface->geometry.x = shsurf->output->x;
780 surface->geometry.y = shsurf->output->y;
781 surface->geometry.dirty = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200782
Kristian Høgsberg75840622011-09-06 13:48:16 -0400783 wl_resource_post_event(resource,
784 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500785 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200786 shsurf->output->current->width,
787 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400788}
789
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200790static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500791handle_lock_surface_destroy(struct wl_listener *listener,
792 struct wl_resource *resource, uint32_t time)
793{
794 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +0200795 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500796
797 fprintf(stderr, "lock surface gone\n");
798 shell->lock_surface = NULL;
799}
800
801static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200802desktop_shell_set_lock_surface(struct wl_client *client,
803 struct wl_resource *resource,
804 struct wl_resource *surface_resource)
805{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200806 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200807 struct shell_surface *surface = surface_resource->data;
808
809 if (reset_shell_surface_type(surface))
810 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200811
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200812 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200813
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200814 if (!shell->locked)
815 return;
816
Pekka Paalanen98262232011-12-01 10:42:22 +0200817 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200818
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500819 shell->lock_surface_listener.func = handle_lock_surface_destroy;
820 wl_list_insert(&surface_resource->destroy_listener_list,
821 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200822
Pekka Paalanen068ae942011-11-28 14:11:15 +0200823 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200824}
825
826static void
827resume_desktop(struct wl_shell *shell)
828{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500829 struct weston_surface *surface;
Pekka Paalanenfe340832011-11-25 16:07:52 +0200830 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200831 struct shell_surface *tmp;
832
833 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
834 hide_screensaver(shell, tmp);
835
836 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200837
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500838 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200839 weston_surface_configure(surface, surface->geometry.x,
840 surface->geometry.y,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200841 surface->geometry.width,
842 surface->geometry.height);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200843
Pekka Paalanenfe340832011-11-25 16:07:52 +0200844 if (wl_list_empty(&shell->backgrounds)) {
845 list = &shell->compositor->surface_list;
846 } else {
847 struct shell_surface *background;
848 background = container_of(shell->backgrounds.prev,
849 struct shell_surface, link);
850 list = background->surface->link.prev;
851 }
852
853 if (!wl_list_empty(&shell->hidden_surface_list))
854 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500855 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200856
857 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500858 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200859 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500860 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200861}
862
863static void
864desktop_shell_unlock(struct wl_client *client,
865 struct wl_resource *resource)
866{
867 struct wl_shell *shell = resource->data;
868
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200869 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200870
871 if (shell->locked)
872 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200873}
874
Kristian Høgsberg75840622011-09-06 13:48:16 -0400875static const struct desktop_shell_interface desktop_shell_implementation = {
876 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200877 desktop_shell_set_panel,
878 desktop_shell_set_lock_surface,
879 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400880};
881
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200882static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500883get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200884{
885 struct shell_surface *shsurf;
886
887 shsurf = get_shell_surface(surface);
888 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200889 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200890 return shsurf->type;
891}
892
Kristian Høgsberg75840622011-09-06 13:48:16 -0400893static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400894move_binding(struct wl_input_device *device, uint32_t time,
895 uint32_t key, uint32_t button, uint32_t state, void *data)
896{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500897 struct weston_surface *surface =
898 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500899
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100900 if (surface == NULL)
901 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400902
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200903 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100904 case SHELL_SURFACE_PANEL:
905 case SHELL_SURFACE_BACKGROUND:
906 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200907 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100908 return;
909 default:
910 break;
911 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400912
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500913 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400914}
915
916static void
917resize_binding(struct wl_input_device *device, uint32_t time,
918 uint32_t key, uint32_t button, uint32_t state, void *data)
919{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500920 struct weston_surface *surface =
921 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400922 uint32_t edges = 0;
923 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200924 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500925
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100926 if (surface == NULL)
927 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200928
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200929 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200930 if (!shsurf)
931 return;
932
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200933 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100934 case SHELL_SURFACE_PANEL:
935 case SHELL_SURFACE_BACKGROUND:
936 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200937 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100938 return;
939 default:
940 break;
941 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400942
Pekka Paalanen60921e52012-01-25 15:55:43 +0200943 /* FIXME: convert properly to surface coordinates */
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200944 x = device->grab_x - surface->geometry.x;
945 y = device->grab_y - surface->geometry.y;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400946
Pekka Paalanen60921e52012-01-25 15:55:43 +0200947 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200948 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200949 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400950 edges |= 0;
951 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200952 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400953
Pekka Paalanen60921e52012-01-25 15:55:43 +0200954 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200955 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +0200956 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -0400957 edges |= 0;
958 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200959 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400960
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500961 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200962 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400963}
964
965static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500966terminate_binding(struct wl_input_device *device, uint32_t time,
967 uint32_t key, uint32_t button, uint32_t state, void *data)
968{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500969 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500970
971 if (state)
972 wl_display_terminate(compositor->wl_display);
973}
974
975static void
Pekka Paalanen460099f2012-01-20 16:48:25 +0200976rotate_grab_motion(struct wl_grab *grab,
977 uint32_t time, int32_t x, int32_t y)
978{
979 struct rotate_grab *rotate =
980 container_of(grab, struct rotate_grab, grab);
981 struct wl_input_device *device = grab->input_device;
982 struct shell_surface *surface = rotate->surface;
983 GLfloat dx, dy;
984 GLfloat r;
985
986 dx = device->x - rotate->center.x;
987 dy = device->y - rotate->center.y;
988 r = sqrtf(dx * dx + dy * dy);
989
990 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200991 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200992
993 if (r > 20.0f) {
994 struct weston_matrix roto;
995 struct weston_matrix *matrix =
996 &surface->rotation.transform.matrix;
997
998 weston_matrix_init(&roto);
999 roto.d[0] = dx / r;
1000 roto.d[4] = -dy / r;
1001 roto.d[1] = -roto.d[4];
1002 roto.d[5] = roto.d[0];
1003
1004 weston_matrix_init(matrix);
1005 weston_matrix_translate(matrix, -rotate->center.x,
1006 -rotate->center.y, 0.0f);
1007 weston_matrix_multiply(matrix, &roto);
1008 weston_matrix_translate(matrix, rotate->center.x,
1009 rotate->center.y, 0.0f);
1010
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001011 wl_list_insert(
1012 surface->surface->geometry.transformation_list.prev,
1013 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001014 } else {
1015 wl_list_init(&surface->rotation.transform.link);
1016 }
1017
1018 weston_compositor_damage_all(surface->surface->compositor);
1019}
1020
1021static void
1022rotate_grab_button(struct wl_grab *grab,
1023 uint32_t time, int32_t button, int32_t state)
1024{
1025 struct rotate_grab *rotate =
1026 container_of(grab, struct rotate_grab, grab);
1027 struct wl_input_device *device = grab->input_device;
1028
1029 if (device->button_count == 0 && state == 0) {
1030 wl_input_device_end_grab(device, time);
1031 free(rotate);
1032 }
1033}
1034
1035static const struct wl_grab_interface rotate_grab_interface = {
1036 noop_grab_focus,
1037 rotate_grab_motion,
1038 rotate_grab_button,
1039};
1040
1041static void
1042rotate_binding(struct wl_input_device *device, uint32_t time,
1043 uint32_t key, uint32_t button, uint32_t state, void *data)
1044{
1045 struct weston_surface *base_surface =
1046 (struct weston_surface *) device->pointer_focus;
1047 struct shell_surface *surface;
1048 struct rotate_grab *rotate;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001049
1050 if (base_surface == NULL)
1051 return;
1052
1053 surface = get_shell_surface(base_surface);
1054 if (!surface)
1055 return;
1056
1057 switch (surface->type) {
1058 case SHELL_SURFACE_PANEL:
1059 case SHELL_SURFACE_BACKGROUND:
1060 case SHELL_SURFACE_FULLSCREEN:
1061 case SHELL_SURFACE_SCREENSAVER:
1062 return;
1063 default:
1064 break;
1065 }
1066
Pekka Paalanen460099f2012-01-20 16:48:25 +02001067 rotate = malloc(sizeof *rotate);
1068 if (!rotate)
1069 return;
1070
1071 rotate->grab.interface = &rotate_grab_interface;
1072 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001073
1074 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001075 surface->surface->geometry.width / 2,
1076 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001077 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001078
1079 wl_input_device_start_grab(device, &rotate->grab, time);
1080 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
1081}
1082
1083static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001084activate(struct weston_shell *base, struct weston_surface *es,
1085 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001086{
1087 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001088 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001089 struct wl_list *list;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001090
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001091 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001092
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001093 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001094 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001095
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001096 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001097 case SHELL_SURFACE_BACKGROUND:
1098 /* put background back to bottom */
Kristian Høgsberg75840622011-09-06 13:48:16 -04001099 wl_list_remove(&es->link);
1100 wl_list_insert(compositor->surface_list.prev, &es->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001101 break;
1102 case SHELL_SURFACE_PANEL:
1103 /* already put on top */
1104 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001105 case SHELL_SURFACE_SCREENSAVER:
1106 /* always below lock surface */
1107 if (shell->lock_surface) {
1108 wl_list_remove(&es->link);
1109 wl_list_insert(&shell->lock_surface->surface->link,
1110 &es->link);
1111 }
1112 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001113 default:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001114 if (!shell->locked) {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001115 list = weston_compositor_top(compositor);
1116
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001117 /* bring panel back to top */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001118 struct shell_surface *panel;
1119 wl_list_for_each(panel, &shell->panels, link) {
1120 wl_list_remove(&panel->surface->link);
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001121 wl_list_insert(list, &panel->surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001122 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001123 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001124 }
1125}
1126
1127static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001128click_to_activate_binding(struct wl_input_device *device,
1129 uint32_t time, uint32_t key,
1130 uint32_t button, uint32_t state, void *data)
1131{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001132 struct weston_input_device *wd = (struct weston_input_device *) device;
1133 struct weston_compositor *compositor = data;
1134 struct weston_surface *focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001135
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001136 focus = (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001137 if (state && focus && device->grab == &device->default_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001138 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001139}
1140
1141static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001142lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001143{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001144 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001145 struct wl_list *surface_list = &shell->compositor->surface_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001146 struct weston_surface *cur;
1147 struct weston_surface *tmp;
1148 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001149 struct shell_surface *shsurf;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001150 uint32_t time;
1151
1152 if (shell->locked)
1153 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001154
1155 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001156
1157 /* Move all surfaces from compositor's list to our hidden list,
1158 * except the background. This way nothing else can show or
1159 * receive input events while we are locked. */
1160
1161 if (!wl_list_empty(&shell->hidden_surface_list)) {
1162 fprintf(stderr,
1163 "%s: Assertion failed: hidden_surface_list is not empty.\n",
1164 __func__);
1165 }
1166
1167 wl_list_for_each_safe(cur, tmp, surface_list, link) {
1168 /* skip input device sprites, cur->surface is uninitialised */
1169 if (cur->surface.resource.client == NULL)
1170 continue;
1171
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001172 if (get_shell_surface_type(cur) == SHELL_SURFACE_BACKGROUND)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001173 continue;
1174
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001175 cur->output = NULL;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001176 wl_list_remove(&cur->link);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001177 wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001178 }
1179
Pekka Paalanen77346a62011-11-30 16:26:35 +02001180 launch_screensaver(shell);
1181
1182 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1183 show_screensaver(shell, shsurf);
1184
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001185 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001186 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001187 weston_compositor_wake(shell->compositor);
1188 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001189 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001190
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001191 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001192 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001193
1194 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001195 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001196 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1197 wl_input_device_set_keyboard_focus(&device->input_device,
1198 NULL, time);
1199 }
1200
1201 /* TODO: disable bindings that should not work while locked. */
1202
1203 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001204}
1205
1206static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001207unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001208{
1209 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1210
Pekka Paalanend81c2162011-11-16 13:47:34 +02001211 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001212 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001213 return;
1214 }
1215
1216 /* If desktop-shell client has gone away, unlock immediately. */
1217 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001218 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001219 return;
1220 }
1221
1222 if (shell->prepare_event_sent)
1223 return;
1224
1225 wl_resource_post_event(shell->child.desktop_shell,
1226 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1227 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001228}
1229
1230static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001231center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001232{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001233 struct weston_mode *mode = output->current;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001234
Pekka Paalanen60921e52012-01-25 15:55:43 +02001235 surface->geometry.x =
1236 output->x + (mode->width - surface->geometry.width) / 2;
1237 surface->geometry.y =
1238 output->y + (mode->height - surface->geometry.height) / 2;
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001239 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001240}
1241
1242static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001243map(struct weston_shell *base,
1244 struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001245{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001246 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001247 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001248 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001249 struct shell_surface *shsurf;
1250 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1251 int do_configure;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001252
Pekka Paalanen77346a62011-11-30 16:26:35 +02001253 shsurf = get_shell_surface(surface);
1254 if (shsurf)
1255 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001256
Pekka Paalanen77346a62011-11-30 16:26:35 +02001257 if (shell->locked) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001258 list = &shell->hidden_surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001259 do_configure = 0;
1260 } else {
Kristian Høgsberga82c4862012-01-26 01:03:58 -05001261 list = weston_compositor_top(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001262 do_configure = 1;
1263 }
1264
Pekka Paalanen60921e52012-01-25 15:55:43 +02001265 surface->geometry.width = width;
1266 surface->geometry.height = height;
1267 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001268
1269 /* initial positioning, see also configure() */
1270 switch (surface_type) {
1271 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001272 surface->geometry.x = 10 + random() % 400;
1273 surface->geometry.y = 10 + random() % 400;
1274 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001275 break;
1276 case SHELL_SURFACE_SCREENSAVER:
1277 case SHELL_SURFACE_FULLSCREEN:
1278 center_on_output(surface, surface->fullscreen_output);
1279 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001280 case SHELL_SURFACE_LOCK:
1281 center_on_output(surface, get_default_output(compositor));
1282 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001283 default:
1284 ;
1285 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001286
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001287 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001288 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001289 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001290 /* background always visible, at the bottom */
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001291 wl_list_insert(compositor->surface_list.prev, &surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001292 do_configure = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001293 break;
1294 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001295 /* panel always on top, hidden while locked */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001296 wl_list_insert(list, &surface->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001297 break;
1298 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001299 /* lock surface always visible, on top */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001300 wl_list_insert(&compositor->surface_list, &surface->link);
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001301
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001302 weston_compositor_repick(compositor);
1303 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001304 do_configure = 1;
1305 break;
1306 case SHELL_SURFACE_SCREENSAVER:
1307 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001308 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001309 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001310 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001311 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001312 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001313 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001314 }
Pekka Paalanen77346a62011-11-30 16:26:35 +02001315 do_configure = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001316 break;
1317 default:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001318 /* everything else just below the panel */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001319 if (!wl_list_empty(&shell->panels)) {
1320 struct shell_surface *panel =
1321 container_of(shell->panels.prev,
1322 struct shell_surface, link);
1323 wl_list_insert(&panel->surface->link, &surface->link);
1324 } else {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001325 wl_list_insert(list, &surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001326 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001327 }
1328
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001329 switch (surface_type) {
1330 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001331 surface->geometry.x = 10 + random() % 400;
1332 surface->geometry.y = 10 + random() % 400;
1333 surface->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001334 break;
1335 case SHELL_SURFACE_POPUP:
1336 shell_map_popup(shsurf, shsurf->popup.time);
1337 break;
1338 default:
1339 break;
1340 }
1341
Pekka Paalanen60921e52012-01-25 15:55:43 +02001342 surface->geometry.width = width;
1343 surface->geometry.height = height;
1344 surface->geometry.dirty = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001345 if (do_configure) {
Pekka Paalanenba3cf952012-01-25 16:22:05 +02001346 weston_surface_configure(surface, surface->geometry.x,
1347 surface->geometry.y,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001348 width, height);
1349 weston_compositor_repick(compositor);
1350 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001351
Juan Zhao7bb92f02011-12-15 11:31:51 -05001352 switch (surface_type) {
1353 case SHELL_SURFACE_TOPLEVEL:
1354 case SHELL_SURFACE_TRANSIENT:
1355 case SHELL_SURFACE_FULLSCREEN:
1356 if (!shell->locked)
1357 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001358 (struct weston_input_device *)
Juan Zhao7bb92f02011-12-15 11:31:51 -05001359 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001360 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001361 break;
1362 default:
1363 break;
1364 }
1365
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001366 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001367 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001368}
1369
1370static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001371configure(struct weston_shell *base, struct weston_surface *surface,
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001372 int32_t x, int32_t y, int32_t width, int32_t height)
1373{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001374 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1375 int do_configure = !shell->locked;
1376 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1377 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001378
Pekka Paalanen77346a62011-11-30 16:26:35 +02001379 shsurf = get_shell_surface(surface);
1380 if (shsurf)
1381 surface_type = shsurf->type;
1382
Pekka Paalanen60921e52012-01-25 15:55:43 +02001383 surface->geometry.width = width;
1384 surface->geometry.height = height;
1385 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001386
1387 switch (surface_type) {
1388 case SHELL_SURFACE_SCREENSAVER:
1389 do_configure = !do_configure;
1390 /* fall through */
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001391 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001392 center_on_output(surface, surface->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001393 break;
1394 default:
1395 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001396 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001397
Pekka Paalanen77346a62011-11-30 16:26:35 +02001398 /*
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001399 * weston_surface_configure() will assign an output, which means
Pekka Paalanen77346a62011-11-30 16:26:35 +02001400 * the surface is supposed to be in compositor->surface_list.
1401 * Be careful with that, and make sure we stay on the right output.
1402 * XXX: would a fullscreen surface need the same handling?
1403 */
1404 if (do_configure) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001405 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001406
1407 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1408 surface->output = shsurf->output;
1409 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001410}
1411
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001412static int launch_desktop_shell_process(struct wl_shell *shell);
1413
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001414static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001415desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001416{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001417 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001418 struct wl_shell *shell =
1419 container_of(process, struct wl_shell, child.process);
1420
1421 shell->child.process.pid = 0;
1422 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001423
1424 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1425 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001426 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001427 shell->child.deathstamp = time;
1428 shell->child.deathcount = 0;
1429 }
1430
1431 shell->child.deathcount++;
1432 if (shell->child.deathcount > 5) {
1433 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1434 return;
1435 }
1436
1437 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1438 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001439}
1440
1441static int
1442launch_desktop_shell_process(struct wl_shell *shell)
1443{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001444 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001445
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001446 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001447 &shell->child.process,
1448 shell_exe,
1449 desktop_shell_sigchld);
1450
1451 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001452 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001453 return 0;
1454}
1455
1456static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001457bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1458{
1459 struct wl_shell *shell = data;
1460
1461 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001462 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001463}
1464
Kristian Høgsberg75840622011-09-06 13:48:16 -04001465static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001466unbind_desktop_shell(struct wl_resource *resource)
1467{
1468 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001469
1470 if (shell->locked)
1471 resume_desktop(shell);
1472
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001473 shell->child.desktop_shell = NULL;
1474 shell->prepare_event_sent = false;
1475 free(resource);
1476}
1477
1478static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001479bind_desktop_shell(struct wl_client *client,
1480 void *data, uint32_t version, uint32_t id)
1481{
1482 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001483 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001484
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001485 resource = wl_client_add_object(client, &desktop_shell_interface,
1486 &desktop_shell_implementation,
1487 id, shell);
1488
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001489 if (client == shell->child.client) {
1490 resource->destroy = unbind_desktop_shell;
1491 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001492 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001493 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001494
1495 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1496 "permission to bind desktop_shell denied");
1497 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001498}
1499
Pekka Paalanen6e168112011-11-24 11:34:05 +02001500static void
1501screensaver_set_surface(struct wl_client *client,
1502 struct wl_resource *resource,
1503 struct wl_resource *shell_surface_resource,
1504 struct wl_resource *output_resource)
1505{
1506 struct wl_shell *shell = resource->data;
1507 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001508 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001509
Pekka Paalanen98262232011-12-01 10:42:22 +02001510 if (reset_shell_surface_type(surface))
1511 return;
1512
Pekka Paalanen77346a62011-11-30 16:26:35 +02001513 surface->type = SHELL_SURFACE_SCREENSAVER;
1514
1515 surface->surface->fullscreen_output = output;
1516 surface->output = output;
1517 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001518}
1519
1520static const struct screensaver_interface screensaver_implementation = {
1521 screensaver_set_surface
1522};
1523
1524static void
1525unbind_screensaver(struct wl_resource *resource)
1526{
1527 struct wl_shell *shell = resource->data;
1528
Pekka Paalanen77346a62011-11-30 16:26:35 +02001529 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001530 free(resource);
1531}
1532
1533static void
1534bind_screensaver(struct wl_client *client,
1535 void *data, uint32_t version, uint32_t id)
1536{
1537 struct wl_shell *shell = data;
1538 struct wl_resource *resource;
1539
1540 resource = wl_client_add_object(client, &screensaver_interface,
1541 &screensaver_implementation,
1542 id, shell);
1543
Pekka Paalanen77346a62011-11-30 16:26:35 +02001544 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001545 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001546 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001547 return;
1548 }
1549
1550 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1551 "interface object already bound");
1552 wl_resource_destroy(resource, 0);
1553}
1554
Pekka Paalanen3c647232011-12-22 13:43:43 +02001555static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001556shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001557{
1558 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1559
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001560 if (shell->child.client)
1561 wl_client_destroy(shell->child.client);
1562
Pekka Paalanen3c647232011-12-22 13:43:43 +02001563 free(shell->screensaver.path);
1564 free(shell);
1565}
1566
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001567int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001568shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001569
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001570WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001571shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001572{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001573 struct wl_shell *shell;
1574
1575 shell = malloc(sizeof *shell);
1576 if (shell == NULL)
1577 return -1;
1578
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001579 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001580 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001581 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001582 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001583 shell->shell.map = map;
1584 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02001585 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001586
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001587 wl_list_init(&shell->hidden_surface_list);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001588 wl_list_init(&shell->backgrounds);
1589 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001590 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001591
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001592 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001593
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001594 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
1595 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001596 return -1;
1597
Kristian Høgsberg75840622011-09-06 13:48:16 -04001598 if (wl_display_add_global(ec->wl_display,
1599 &desktop_shell_interface,
1600 shell, bind_desktop_shell) == NULL)
1601 return -1;
1602
Pekka Paalanen6e168112011-11-24 11:34:05 +02001603 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
1604 shell, bind_screensaver) == NULL)
1605 return -1;
1606
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001607 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001608 if (launch_desktop_shell_process(shell) != 0)
1609 return -1;
1610
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001611 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001612 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001613 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001614 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001615 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001616 MODIFIER_CTRL | MODIFIER_ALT,
1617 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001618 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001619 click_to_activate_binding, ec);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001620 weston_compositor_add_binding(ec, 0, BTN_LEFT,
1621 MODIFIER_SUPER | MODIFIER_ALT,
1622 rotate_binding, NULL);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001623
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001624 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001625
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001626 return 0;
1627}