blob: 5274d524d2ca4f919c647caaa052f72a46bb2ce8 [file] [log] [blame]
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001/*
2 * Copyright © 2010 Intel Corporation
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003 * Copyright © 2011 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>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050032
Pekka Paalanen50719bc2011-11-22 14:18:50 +020033#include <wayland-server.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050034#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040035#include "desktop-shell-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020036#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050037
Pekka Paalanen068ae942011-11-28 14:11:15 +020038struct shell_surface;
39
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040040struct wl_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050041 struct weston_compositor *compositor;
42 struct weston_shell shell;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020043
44 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050045 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020046 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020047 struct wl_resource *desktop_shell;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020048 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020049
50 bool locked;
51 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020052
Pekka Paalanen068ae942011-11-28 14:11:15 +020053 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050054 struct wl_listener lock_surface_listener;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020055 struct wl_list hidden_surface_list;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010056
57 struct wl_list backgrounds;
58 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020059
Pekka Paalanen77346a62011-11-30 16:26:35 +020060 struct {
Pekka Paalanene955f1e2011-12-07 11:49:52 +020061 const char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020062 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020063 struct wl_resource *binding;
64 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050065 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020066 } screensaver;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040067};
68
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050069enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020070 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050071
Pekka Paalanen57da4a82011-11-23 16:42:16 +020072 SHELL_SURFACE_PANEL,
73 SHELL_SURFACE_BACKGROUND,
74 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020075 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050076
77 SHELL_SURFACE_TOPLEVEL,
78 SHELL_SURFACE_TRANSIENT,
79 SHELL_SURFACE_FULLSCREEN
Pekka Paalanen57da4a82011-11-23 16:42:16 +020080};
81
Pekka Paalanen56cdea92011-11-23 16:14:12 +020082struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020083 struct wl_resource resource;
84
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050085 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020086 struct wl_listener surface_destroy_listener;
Pekka Paalanen57da4a82011-11-23 16:42:16 +020087
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050088 enum shell_surface_type type;
89 int32_t saved_x, saved_y;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010090
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050091 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010092 struct wl_list link;
Pekka Paalanen56cdea92011-11-23 16:14:12 +020093};
94
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050095struct weston_move_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050096 struct wl_grab grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050097 struct weston_surface *surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050098 int32_t dx, dy;
99};
100
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200101static int
102shell_configuration(struct wl_shell *shell)
103{
104 int ret;
105 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200106 char *path = NULL;
107 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200108
109 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200110 { "path", CONFIG_KEY_STRING, &path },
111 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200112 };
113
114 struct config_section cs[] = {
115 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
116 };
117
118 config_file = config_file_path("wayland-desktop-shell.ini");
119 ret = parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
120 free(config_file);
121
Pekka Paalanen7296e792011-12-07 16:22:00 +0200122 shell->screensaver.path = path;
123 shell->screensaver.duration = duration;
124
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200125 return ret;
126 /* FIXME: free(shell->screensaver.path) on plugin fini */
127}
128
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200129static void
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500130move_grab_motion(struct wl_grab *grab,
131 uint32_t time, int32_t x, int32_t y)
132{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500133 struct weston_move_grab *move = (struct weston_move_grab *) grab;
134 struct weston_surface *es = move->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500135
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500136 weston_surface_configure(es, x + move->dx, y + move->dy,
Kristian Høgsberga691aee2011-06-23 21:43:50 -0400137 es->width, es->height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500138}
139
140static void
141move_grab_button(struct wl_grab *grab,
142 uint32_t time, int32_t button, int32_t state)
143{
144}
145
146static void
147move_grab_end(struct wl_grab *grab, uint32_t time)
148{
149 free(grab);
150}
151
152static const struct wl_grab_interface move_grab_interface = {
153 move_grab_motion,
154 move_grab_button,
155 move_grab_end
156};
157
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400158static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500159weston_surface_move(struct weston_surface *es,
160 struct weston_input_device *wd, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500161{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500162 struct weston_move_grab *move;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500163
164 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400165 if (!move)
166 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500167
168 move->grab.interface = &move_grab_interface;
169 move->dx = es->x - wd->input_device.grab_x;
170 move->dy = es->y - wd->input_device.grab_y;
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -0500171 move->surface = es;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500172
173 if (wl_input_device_update_grab(&wd->input_device,
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400174 &move->grab, &es->surface, time) < 0)
175 return 0;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500176
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400177 wl_input_device_set_pointer_focus(&wd->input_device,
178 NULL, time, 0, 0, 0, 0);
179
180 return 0;
181}
182
183static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200184shell_surface_move(struct wl_client *client, struct wl_resource *resource,
185 struct wl_resource *input_resource, uint32_t time)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400186{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500187 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200188 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400189
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500190 if (weston_surface_move(shsurf->surface, wd, time) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400191 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500192}
193
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500194struct weston_resize_grab {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500195 struct wl_grab grab;
196 uint32_t edges;
197 int32_t dx, dy, width, height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200198 struct shell_surface *shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500199};
200
201static void
202resize_grab_motion(struct wl_grab *grab,
203 uint32_t time, int32_t x, int32_t y)
204{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500205 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500206 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500207 int32_t width, height;
208
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200209 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500210 width = device->grab_x - x + resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200211 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500212 width = x - device->grab_x + resize->width;
213 } else {
214 width = resize->width;
215 }
216
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200217 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500218 height = device->grab_y - y + resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200219 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500220 height = y - device->grab_y + resize->height;
221 } else {
222 height = resize->height;
223 }
224
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200225 wl_resource_post_event(&resize->shsurf->resource,
226 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
227 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500228}
229
230static void
231resize_grab_button(struct wl_grab *grab,
232 uint32_t time, int32_t button, int32_t state)
233{
234}
235
236static void
237resize_grab_end(struct wl_grab *grab, uint32_t time)
238{
239 free(grab);
240}
241
242static const struct wl_grab_interface resize_grab_interface = {
243 resize_grab_motion,
244 resize_grab_button,
245 resize_grab_end
246};
247
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400248static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500249weston_surface_resize(struct shell_surface *shsurf,
250 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200251 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500252{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500253 struct weston_resize_grab *resize;
254 struct weston_surface *es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500255
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500256 /* FIXME: Reject if fullscreen */
257
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500258 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400259 if (!resize)
260 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500261
262 resize->grab.interface = &resize_grab_interface;
263 resize->edges = edges;
264 resize->dx = es->x - wd->input_device.grab_x;
265 resize->dy = es->y - wd->input_device.grab_y;
266 resize->width = es->width;
267 resize->height = es->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200268 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400269
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500270 if (edges == 0 || edges > 15 ||
271 (edges & 3) == 3 || (edges & 12) == 12)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400272 return 0;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500273
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500274 if (wl_input_device_update_grab(&wd->input_device,
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400275 &resize->grab, &es->surface, time) < 0)
276 return 0;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500277
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400278 wl_input_device_set_pointer_focus(&wd->input_device,
279 NULL, time, 0, 0, 0, 0);
280
281 return 0;
282}
283
284static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200285shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
286 struct wl_resource *input_resource, uint32_t time,
287 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400288{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500289 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200290 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400291
292 /* FIXME: Reject if fullscreen */
293
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500294 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400295 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500296}
297
Pekka Paalanen98262232011-12-01 10:42:22 +0200298static int
299reset_shell_surface_type(struct shell_surface *surface)
300{
301 switch (surface->type) {
302 case SHELL_SURFACE_FULLSCREEN:
303 surface->surface->x = surface->saved_x;
304 surface->surface->y = surface->saved_y;
305 surface->surface->fullscreen_output = NULL;
306 break;
307 case SHELL_SURFACE_PANEL:
308 case SHELL_SURFACE_BACKGROUND:
309 wl_list_remove(&surface->link);
310 wl_list_init(&surface->link);
311 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200312 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200313 case SHELL_SURFACE_LOCK:
314 wl_resource_post_error(&surface->resource,
315 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200316 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200317 return -1;
318 case SHELL_SURFACE_NONE:
319 case SHELL_SURFACE_TOPLEVEL:
320 case SHELL_SURFACE_TRANSIENT:
321 break;
322 }
323
324 surface->type = SHELL_SURFACE_NONE;
325 return 0;
326}
327
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500328static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200329shell_surface_set_toplevel(struct wl_client *client,
330 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400331
332{
Pekka Paalanen98262232011-12-01 10:42:22 +0200333 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400334
Pekka Paalanen98262232011-12-01 10:42:22 +0200335 if (reset_shell_surface_type(surface))
336 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400337
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500338 weston_surface_damage(surface->surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200339 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400340}
341
342static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200343shell_surface_set_transient(struct wl_client *client,
344 struct wl_resource *resource,
345 struct wl_resource *parent_resource,
346 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400347{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200348 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500349 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200350 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500351 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400352
Pekka Paalanen98262232011-12-01 10:42:22 +0200353 if (reset_shell_surface_type(shsurf))
354 return;
355
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400356 /* assign to parents output */
357 es->output = pes->output;
358
359 es->x = pes->x + x;
360 es->y = pes->y + y;
361
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500362 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200363 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400364}
365
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500366static struct weston_output *
367get_default_output(struct weston_compositor *compositor)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200368{
369 return container_of(compositor->output_list.next,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500370 struct weston_output, link);
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200371}
372
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400373static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200374shell_surface_set_fullscreen(struct wl_client *client,
375 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400376
377{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200378 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500379 struct weston_surface *es = shsurf->surface;
380 struct weston_output *output;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400381
Pekka Paalanen98262232011-12-01 10:42:22 +0200382 if (reset_shell_surface_type(shsurf))
383 return;
384
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400385 /* FIXME: Fullscreen on first output */
386 /* FIXME: Handle output going away */
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200387 output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400388 es->output = output;
389
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200390 shsurf->saved_x = es->x;
391 shsurf->saved_y = es->y;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400392 es->x = (output->current->width - es->width) / 2;
393 es->y = (output->current->height - es->height) / 2;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400394 es->fullscreen_output = output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500395 weston_surface_damage(es);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200396 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400397}
398
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200399static const struct wl_shell_surface_interface shell_surface_implementation = {
400 shell_surface_move,
401 shell_surface_resize,
402 shell_surface_set_toplevel,
403 shell_surface_set_transient,
404 shell_surface_set_fullscreen
405};
406
407static void
408destroy_shell_surface(struct wl_resource *resource)
409{
410 struct shell_surface *shsurf = resource->data;
411
412 /* in case cleaning up a dead client destroys shell_surface first */
413 if (shsurf->surface)
414 wl_list_remove(&shsurf->surface_destroy_listener.link);
415
416 wl_list_remove(&shsurf->link);
417 free(shsurf);
418}
419
420static void
421shell_handle_surface_destroy(struct wl_listener *listener,
422 struct wl_resource *resource, uint32_t time)
423{
424 struct shell_surface *shsurf = container_of(listener,
425 struct shell_surface,
426 surface_destroy_listener);
427
428 shsurf->surface = NULL;
429 wl_resource_destroy(&shsurf->resource, time);
430}
431
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200432static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500433get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200434{
435 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
436 struct wl_listener *listener;
437
438 /* search the destroy listener list for our callback */
439 wl_list_for_each(listener, lst, link) {
440 if (listener->func == shell_handle_surface_destroy) {
441 return container_of(listener, struct shell_surface,
442 surface_destroy_listener);
443 }
444 }
445
446 return NULL;
447}
448
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200449static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200450shell_get_shell_surface(struct wl_client *client,
451 struct wl_resource *resource,
452 uint32_t id,
453 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200454{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500455 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200456 struct shell_surface *shsurf;
457
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200458 if (get_shell_surface(surface)) {
459 wl_resource_post_error(surface_resource,
460 WL_DISPLAY_ERROR_INVALID_OBJECT,
461 "wl_shell::get_shell_surface already requested");
462 return;
463 }
464
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200465 shsurf = calloc(1, sizeof *shsurf);
466 if (!shsurf) {
467 wl_resource_post_no_memory(resource);
468 return;
469 }
470
471 shsurf->resource.destroy = destroy_shell_surface;
472 shsurf->resource.object.id = id;
473 shsurf->resource.object.interface = &wl_shell_surface_interface;
474 shsurf->resource.object.implementation =
475 (void (**)(void)) &shell_surface_implementation;
476 shsurf->resource.data = shsurf;
477
478 shsurf->surface = surface;
479 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
480 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
481 &shsurf->surface_destroy_listener.link);
482
483 /* init link so its safe to always remove it in destroy_shell_surface */
484 wl_list_init(&shsurf->link);
485
Pekka Paalanen98262232011-12-01 10:42:22 +0200486 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200487
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200488 wl_client_add_resource(client, &shsurf->resource);
489}
490
491static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200492 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500493};
494
Kristian Høgsberg07937562011-04-12 17:25:42 -0400495static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500496handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200497{
498 proc->pid = 0;
499}
500
501static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200502launch_screensaver(struct wl_shell *shell)
503{
504 if (shell->screensaver.binding)
505 return;
506
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200507 if (!shell->screensaver.path)
508 return;
509
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500510 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200511 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200512 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200513 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200514}
515
516static void
517terminate_screensaver(struct wl_shell *shell)
518{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200519 if (shell->screensaver.process.pid == 0)
520 return;
521
522 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200523}
524
525static void
526show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
527{
528 struct wl_list *list;
529
530 if (shell->lock_surface)
531 list = &shell->lock_surface->surface->link;
532 else
533 list = &shell->compositor->surface_list;
534
535 wl_list_remove(&surface->surface->link);
536 wl_list_insert(list, &surface->surface->link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500537 weston_surface_configure(surface->surface,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200538 surface->surface->x,
539 surface->surface->y,
540 surface->surface->width,
541 surface->surface->height);
542 surface->surface->output = surface->output;
543}
544
545static void
546hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
547{
548 wl_list_remove(&surface->surface->link);
549 wl_list_init(&surface->surface->link);
550 surface->surface->output = NULL;
551}
552
553static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400554desktop_shell_set_background(struct wl_client *client,
555 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100556 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400557 struct wl_resource *surface_resource)
558{
559 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200560 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500561 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200562 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400563
Pekka Paalanen98262232011-12-01 10:42:22 +0200564 if (reset_shell_surface_type(shsurf))
565 return;
566
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100567 wl_list_for_each(priv, &shell->backgrounds, link) {
568 if (priv->output == output_resource->data) {
569 priv->surface->output = NULL;
570 wl_list_remove(&priv->surface->link);
571 wl_list_remove(&priv->link);
572 break;
573 }
574 }
575
Pekka Paalanen068ae942011-11-28 14:11:15 +0200576 shsurf->type = SHELL_SURFACE_BACKGROUND;
577 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100578
Pekka Paalanen068ae942011-11-28 14:11:15 +0200579 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100580
Pekka Paalanen068ae942011-11-28 14:11:15 +0200581 surface->x = shsurf->output->x;
582 surface->y = shsurf->output->y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200583
Kristian Høgsberg75840622011-09-06 13:48:16 -0400584 wl_resource_post_event(resource,
585 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500586 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200587 shsurf->output->current->width,
588 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400589}
590
591static void
592desktop_shell_set_panel(struct wl_client *client,
593 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100594 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400595 struct wl_resource *surface_resource)
596{
597 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200598 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500599 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200600 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400601
Pekka Paalanen98262232011-12-01 10:42:22 +0200602 if (reset_shell_surface_type(shsurf))
603 return;
604
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100605 wl_list_for_each(priv, &shell->panels, link) {
606 if (priv->output == output_resource->data) {
607 priv->surface->output = NULL;
608 wl_list_remove(&priv->surface->link);
609 wl_list_remove(&priv->link);
610 break;
611 }
612 }
613
Pekka Paalanen068ae942011-11-28 14:11:15 +0200614 shsurf->type = SHELL_SURFACE_PANEL;
615 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100616
Pekka Paalanen068ae942011-11-28 14:11:15 +0200617 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100618
Pekka Paalanen068ae942011-11-28 14:11:15 +0200619 surface->x = shsurf->output->x;
620 surface->y = shsurf->output->y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200621
Kristian Høgsberg75840622011-09-06 13:48:16 -0400622 wl_resource_post_event(resource,
623 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500624 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200625 shsurf->output->current->width,
626 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400627}
628
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200629static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500630handle_lock_surface_destroy(struct wl_listener *listener,
631 struct wl_resource *resource, uint32_t time)
632{
633 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +0200634 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500635
636 fprintf(stderr, "lock surface gone\n");
637 shell->lock_surface = NULL;
638}
639
640static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200641desktop_shell_set_lock_surface(struct wl_client *client,
642 struct wl_resource *resource,
643 struct wl_resource *surface_resource)
644{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200645 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200646 struct shell_surface *surface = surface_resource->data;
647
648 if (reset_shell_surface_type(surface))
649 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200650
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200651 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +0200652
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200653 if (!shell->locked)
654 return;
655
Pekka Paalanen98262232011-12-01 10:42:22 +0200656 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200657
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500658 shell->lock_surface_listener.func = handle_lock_surface_destroy;
659 wl_list_insert(&surface_resource->destroy_listener_list,
660 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200661
Pekka Paalanen068ae942011-11-28 14:11:15 +0200662 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200663}
664
665static void
666resume_desktop(struct wl_shell *shell)
667{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500668 struct weston_surface *surface;
Pekka Paalanenfe340832011-11-25 16:07:52 +0200669 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200670 struct shell_surface *tmp;
671
672 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
673 hide_screensaver(shell, tmp);
674
675 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200676
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500677 wl_list_for_each(surface, &shell->hidden_surface_list, link)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500678 weston_surface_configure(surface, surface->x, surface->y,
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500679 surface->width, surface->height);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200680
Pekka Paalanenfe340832011-11-25 16:07:52 +0200681 if (wl_list_empty(&shell->backgrounds)) {
682 list = &shell->compositor->surface_list;
683 } else {
684 struct shell_surface *background;
685 background = container_of(shell->backgrounds.prev,
686 struct shell_surface, link);
687 list = background->surface->link.prev;
688 }
689
690 if (!wl_list_empty(&shell->hidden_surface_list))
691 wl_list_insert_list(list, &shell->hidden_surface_list);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500692 wl_list_init(&shell->hidden_surface_list);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200693
694 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500695 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +0200696 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500697 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200698}
699
700static void
701desktop_shell_unlock(struct wl_client *client,
702 struct wl_resource *resource)
703{
704 struct wl_shell *shell = resource->data;
705
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200706 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200707
708 if (shell->locked)
709 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200710}
711
Kristian Høgsberg75840622011-09-06 13:48:16 -0400712static const struct desktop_shell_interface desktop_shell_implementation = {
713 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200714 desktop_shell_set_panel,
715 desktop_shell_set_lock_surface,
716 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -0400717};
718
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200719static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500720get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200721{
722 struct shell_surface *shsurf;
723
724 shsurf = get_shell_surface(surface);
725 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +0200726 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200727 return shsurf->type;
728}
729
Kristian Høgsberg75840622011-09-06 13:48:16 -0400730static void
Kristian Høgsberg07937562011-04-12 17:25:42 -0400731move_binding(struct wl_input_device *device, uint32_t time,
732 uint32_t key, uint32_t button, uint32_t state, void *data)
733{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500734 struct weston_surface *surface =
735 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500736
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100737 if (surface == NULL)
738 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400739
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200740 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100741 case SHELL_SURFACE_PANEL:
742 case SHELL_SURFACE_BACKGROUND:
743 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200744 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100745 return;
746 default:
747 break;
748 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400749
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500750 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -0400751}
752
753static void
754resize_binding(struct wl_input_device *device, uint32_t time,
755 uint32_t key, uint32_t button, uint32_t state, void *data)
756{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500757 struct weston_surface *surface =
758 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400759 uint32_t edges = 0;
760 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200761 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500762
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100763 if (surface == NULL)
764 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200765
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200766 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200767 if (!shsurf)
768 return;
769
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200770 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100771 case SHELL_SURFACE_PANEL:
772 case SHELL_SURFACE_BACKGROUND:
773 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +0200774 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100775 return;
776 default:
777 break;
778 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -0400779
Kristian Høgsberg07937562011-04-12 17:25:42 -0400780 x = device->grab_x - surface->x;
781 y = device->grab_y - surface->y;
782
783 if (x < surface->width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200784 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400785 else if (x < 2 * surface->width / 3)
786 edges |= 0;
787 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200788 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400789
790 if (y < surface->height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200791 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400792 else if (y < 2 * surface->height / 3)
793 edges |= 0;
794 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200795 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -0400796
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500797 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200798 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400799}
800
801static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500802terminate_binding(struct wl_input_device *device, uint32_t time,
803 uint32_t key, uint32_t button, uint32_t state, void *data)
804{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500805 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500806
807 if (state)
808 wl_display_terminate(compositor->wl_display);
809}
810
811static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500812activate(struct weston_shell *base, struct weston_surface *es,
813 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -0400814{
815 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500816 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400817
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500818 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400819
Kristian Høgsbergd6e55252011-10-11 23:41:17 -0400820 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500821 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -0400822
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200823 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200824 case SHELL_SURFACE_BACKGROUND:
825 /* put background back to bottom */
Kristian Høgsberg75840622011-09-06 13:48:16 -0400826 wl_list_remove(&es->link);
827 wl_list_insert(compositor->surface_list.prev, &es->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200828 break;
829 case SHELL_SURFACE_PANEL:
830 /* already put on top */
831 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200832 case SHELL_SURFACE_SCREENSAVER:
833 /* always below lock surface */
834 if (shell->lock_surface) {
835 wl_list_remove(&es->link);
836 wl_list_insert(&shell->lock_surface->surface->link,
837 &es->link);
838 }
839 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200840 default:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100841 if (!shell->locked) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200842 /* bring panel back to top */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100843 struct shell_surface *panel;
844 wl_list_for_each(panel, &shell->panels, link) {
845 wl_list_remove(&panel->surface->link);
846 wl_list_insert(&compositor->surface_list,
847 &panel->surface->link);
848 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200849 }
Kristian Høgsberg75840622011-09-06 13:48:16 -0400850 }
851}
852
853static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500854click_to_activate_binding(struct wl_input_device *device,
855 uint32_t time, uint32_t key,
856 uint32_t button, uint32_t state, void *data)
857{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500858 struct weston_input_device *wd = (struct weston_input_device *) device;
859 struct weston_compositor *compositor = data;
860 struct weston_surface *focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500861
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500862 focus = (struct weston_surface *) device->pointer_focus;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500863 if (state && focus && device->grab == NULL)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -0500864 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -0500865}
866
867static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500868lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400869{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200870 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200871 struct wl_list *surface_list = &shell->compositor->surface_list;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500872 struct weston_surface *cur;
873 struct weston_surface *tmp;
874 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200875 struct shell_surface *shsurf;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200876 uint32_t time;
877
878 if (shell->locked)
879 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200880
881 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200882
883 /* Move all surfaces from compositor's list to our hidden list,
884 * except the background. This way nothing else can show or
885 * receive input events while we are locked. */
886
887 if (!wl_list_empty(&shell->hidden_surface_list)) {
888 fprintf(stderr,
889 "%s: Assertion failed: hidden_surface_list is not empty.\n",
890 __func__);
891 }
892
893 wl_list_for_each_safe(cur, tmp, surface_list, link) {
894 /* skip input device sprites, cur->surface is uninitialised */
895 if (cur->surface.resource.client == NULL)
896 continue;
897
Pekka Paalanen92a0dc42011-11-28 15:34:13 +0200898 if (get_shell_surface_type(cur) == SHELL_SURFACE_BACKGROUND)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200899 continue;
900
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500901 cur->output = NULL;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200902 wl_list_remove(&cur->link);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500903 wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200904 }
905
Pekka Paalanen77346a62011-11-30 16:26:35 +0200906 launch_screensaver(shell);
907
908 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
909 show_screensaver(shell, shsurf);
910
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +0200911 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200912 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500913 weston_compositor_wake(shell->compositor);
914 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +0200915 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +0200916
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200917 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500918 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200919
920 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500921 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200922 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
923 wl_input_device_set_keyboard_focus(&device->input_device,
924 NULL, time);
925 }
926
927 /* TODO: disable bindings that should not work while locked. */
928
929 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200930}
931
932static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500933unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200934{
935 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
936
Pekka Paalanend81c2162011-11-16 13:47:34 +0200937 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500938 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200939 return;
940 }
941
942 /* If desktop-shell client has gone away, unlock immediately. */
943 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200944 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200945 return;
946 }
947
948 if (shell->prepare_event_sent)
949 return;
950
951 wl_resource_post_event(shell->child.desktop_shell,
952 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
953 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400954}
955
956static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500957center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +0200958{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500959 struct weston_mode *mode = output->current;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200960
961 surface->x = output->x + (mode->width - surface->width) / 2;
962 surface->y = output->y + (mode->height - surface->height) / 2;
963}
964
965static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500966map(struct weston_shell *base,
967 struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400968{
Kristian Høgsberg75840622011-09-06 13:48:16 -0400969 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500970 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500971 struct wl_list *list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200972 struct shell_surface *shsurf;
973 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
974 int do_configure;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200975
Pekka Paalanen77346a62011-11-30 16:26:35 +0200976 shsurf = get_shell_surface(surface);
977 if (shsurf)
978 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500979
Pekka Paalanen77346a62011-11-30 16:26:35 +0200980 if (shell->locked) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500981 list = &shell->hidden_surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200982 do_configure = 0;
983 } else {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500984 list = &compositor->surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200985 do_configure = 1;
986 }
987
988 surface->width = width;
989 surface->height = height;
990
991 /* initial positioning, see also configure() */
992 switch (surface_type) {
993 case SHELL_SURFACE_TOPLEVEL:
994 surface->x = 10 + random() % 400;
995 surface->y = 10 + random() % 400;
996 break;
997 case SHELL_SURFACE_SCREENSAVER:
998 case SHELL_SURFACE_FULLSCREEN:
999 center_on_output(surface, surface->fullscreen_output);
1000 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001001 case SHELL_SURFACE_LOCK:
1002 center_on_output(surface, get_default_output(compositor));
1003 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001004 default:
1005 ;
1006 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001007
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001008 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001009 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001010 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001011 /* background always visible, at the bottom */
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001012 wl_list_insert(compositor->surface_list.prev, &surface->link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001013 do_configure = 1;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001014 break;
1015 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001016 /* panel always on top, hidden while locked */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001017 wl_list_insert(list, &surface->link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001018 break;
1019 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001020 /* lock surface always visible, on top */
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001021 wl_list_insert(&compositor->surface_list, &surface->link);
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001022
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001023 weston_compositor_repick(compositor);
1024 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001025 do_configure = 1;
1026 break;
1027 case SHELL_SURFACE_SCREENSAVER:
1028 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001029 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001030 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001031 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001032 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001033 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001034 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001035 }
Pekka Paalanen77346a62011-11-30 16:26:35 +02001036 do_configure = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001037 break;
1038 default:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001039 /* everything else just below the panel */
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001040 if (!wl_list_empty(&shell->panels)) {
1041 struct shell_surface *panel =
1042 container_of(shell->panels.prev,
1043 struct shell_surface, link);
1044 wl_list_insert(&panel->surface->link, &surface->link);
1045 } else {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001046 wl_list_insert(list, &surface->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001047 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001048 }
1049
Pekka Paalanen77346a62011-11-30 16:26:35 +02001050 if (do_configure)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001051 weston_surface_configure(surface,
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001052 surface->x, surface->y, width, height);
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001053
Juan Zhao7bb92f02011-12-15 11:31:51 -05001054 switch (surface_type) {
1055 case SHELL_SURFACE_TOPLEVEL:
1056 case SHELL_SURFACE_TRANSIENT:
1057 case SHELL_SURFACE_FULLSCREEN:
1058 if (!shell->locked)
1059 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001060 (struct weston_input_device *)
Juan Zhao7bb92f02011-12-15 11:31:51 -05001061 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001062 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001063 break;
1064 default:
1065 break;
1066 }
1067
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001068 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001069 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001070}
1071
1072static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001073configure(struct weston_shell *base, struct weston_surface *surface,
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001074 int32_t x, int32_t y, int32_t width, int32_t height)
1075{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001076 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1077 int do_configure = !shell->locked;
1078 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1079 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001080
Pekka Paalanen77346a62011-11-30 16:26:35 +02001081 shsurf = get_shell_surface(surface);
1082 if (shsurf)
1083 surface_type = shsurf->type;
1084
1085 surface->width = width;
1086 surface->height = height;
1087
1088 switch (surface_type) {
1089 case SHELL_SURFACE_SCREENSAVER:
1090 do_configure = !do_configure;
1091 /* fall through */
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001092 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001093 center_on_output(surface, surface->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001094 break;
1095 default:
1096 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001097 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001098
Pekka Paalanen77346a62011-11-30 16:26:35 +02001099 /*
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001100 * weston_surface_configure() will assign an output, which means
Pekka Paalanen77346a62011-11-30 16:26:35 +02001101 * the surface is supposed to be in compositor->surface_list.
1102 * Be careful with that, and make sure we stay on the right output.
1103 * XXX: would a fullscreen surface need the same handling?
1104 */
1105 if (do_configure) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001106 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001107
1108 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1109 surface->output = shsurf->output;
1110 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001111}
1112
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001113static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001114desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001115{
1116 struct wl_shell *shell =
1117 container_of(process, struct wl_shell, child.process);
1118
1119 shell->child.process.pid = 0;
1120 shell->child.client = NULL; /* already destroyed by wayland */
1121}
1122
1123static int
1124launch_desktop_shell_process(struct wl_shell *shell)
1125{
Kristian Høgsbergc4693c42011-11-14 14:57:17 -05001126 const char *shell_exe = LIBEXECDIR "/wayland-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001127
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001128 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001129 &shell->child.process,
1130 shell_exe,
1131 desktop_shell_sigchld);
1132
1133 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001134 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001135 return 0;
1136}
1137
1138static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001139bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1140{
1141 struct wl_shell *shell = data;
1142
1143 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001144 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001145}
1146
Kristian Høgsberg75840622011-09-06 13:48:16 -04001147static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001148unbind_desktop_shell(struct wl_resource *resource)
1149{
1150 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001151
1152 if (shell->locked)
1153 resume_desktop(shell);
1154
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001155 shell->child.desktop_shell = NULL;
1156 shell->prepare_event_sent = false;
1157 free(resource);
1158}
1159
1160static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001161bind_desktop_shell(struct wl_client *client,
1162 void *data, uint32_t version, uint32_t id)
1163{
1164 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001165 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001166
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001167 resource = wl_client_add_object(client, &desktop_shell_interface,
1168 &desktop_shell_implementation,
1169 id, shell);
1170
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001171 if (client == shell->child.client) {
1172 resource->destroy = unbind_desktop_shell;
1173 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001174 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001175 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001176
1177 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1178 "permission to bind desktop_shell denied");
1179 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001180}
1181
Pekka Paalanen6e168112011-11-24 11:34:05 +02001182static void
1183screensaver_set_surface(struct wl_client *client,
1184 struct wl_resource *resource,
1185 struct wl_resource *shell_surface_resource,
1186 struct wl_resource *output_resource)
1187{
1188 struct wl_shell *shell = resource->data;
1189 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001190 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001191
Pekka Paalanen98262232011-12-01 10:42:22 +02001192 if (reset_shell_surface_type(surface))
1193 return;
1194
Pekka Paalanen77346a62011-11-30 16:26:35 +02001195 surface->type = SHELL_SURFACE_SCREENSAVER;
1196
1197 surface->surface->fullscreen_output = output;
1198 surface->output = output;
1199 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001200}
1201
1202static const struct screensaver_interface screensaver_implementation = {
1203 screensaver_set_surface
1204};
1205
1206static void
1207unbind_screensaver(struct wl_resource *resource)
1208{
1209 struct wl_shell *shell = resource->data;
1210
Pekka Paalanen77346a62011-11-30 16:26:35 +02001211 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001212 free(resource);
1213}
1214
1215static void
1216bind_screensaver(struct wl_client *client,
1217 void *data, uint32_t version, uint32_t id)
1218{
1219 struct wl_shell *shell = data;
1220 struct wl_resource *resource;
1221
1222 resource = wl_client_add_object(client, &screensaver_interface,
1223 &screensaver_implementation,
1224 id, shell);
1225
Pekka Paalanen77346a62011-11-30 16:26:35 +02001226 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001227 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001228 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001229 return;
1230 }
1231
1232 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1233 "interface object already bound");
1234 wl_resource_destroy(resource, 0);
1235}
1236
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001237int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001238shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001239
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001240WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001241shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001242{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001243 struct wl_shell *shell;
1244
1245 shell = malloc(sizeof *shell);
1246 if (shell == NULL)
1247 return -1;
1248
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001249 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001250 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001251 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001252 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001253 shell->shell.map = map;
1254 shell->shell.configure = configure;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001255
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001256 wl_list_init(&shell->hidden_surface_list);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001257 wl_list_init(&shell->backgrounds);
1258 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001259 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001260
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001261 if (shell_configuration(shell) < 0)
1262 return -1;
1263
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001264 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
1265 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001266 return -1;
1267
Kristian Høgsberg75840622011-09-06 13:48:16 -04001268 if (wl_display_add_global(ec->wl_display,
1269 &desktop_shell_interface,
1270 shell, bind_desktop_shell) == NULL)
1271 return -1;
1272
Pekka Paalanen6e168112011-11-24 11:34:05 +02001273 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
1274 shell, bind_screensaver) == NULL)
1275 return -1;
1276
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001277 if (launch_desktop_shell_process(shell) != 0)
1278 return -1;
1279
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001280 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001281 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001282 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001283 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001284 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001285 MODIFIER_CTRL | MODIFIER_ALT,
1286 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001287 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001288 click_to_activate_binding, ec);
1289
1290
1291
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001292
1293 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001294
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001295 return 0;
1296}