blob: b37de80f802112f02d12d5c746774fb7df00e9fc [file] [log] [blame]
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001/*
Kristian Høgsberg07045392012-02-19 18:52:44 -05002 * Copyright © 2010-2012 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
Juan Zhaoe10d2792012-04-25 19:09:52 +080039enum animation_type {
40 ANIMATION_NONE,
41
42 ANIMATION_ZOOM,
43 ANIMATION_FADE
44};
45
Tiago Vignattibe143262012-04-16 17:31:41 +030046struct desktop_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050047 struct weston_compositor *compositor;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -040048
49 struct wl_listener lock_listener;
50 struct wl_listener unlock_listener;
51 struct wl_listener destroy_listener;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020052
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050053 struct weston_layer fullscreen_layer;
54 struct weston_layer panel_layer;
55 struct weston_layer toplevel_layer;
56 struct weston_layer background_layer;
57 struct weston_layer lock_layer;
58
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020059 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050060 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020061 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020062 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +020063
64 unsigned deathcount;
65 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020066 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020067
68 bool locked;
69 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020070
Pekka Paalanen068ae942011-11-28 14:11:15 +020071 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050072 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010073
74 struct wl_list backgrounds;
75 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020076
Pekka Paalanen77346a62011-11-30 16:26:35 +020077 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +020078 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020079 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020080 struct wl_resource *binding;
81 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050082 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020083 } screensaver;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -050084
Tiago Vignatti0b52d482012-04-20 18:54:25 +030085 uint32_t binding_modifier;
Juan Zhaoe10d2792012-04-25 19:09:52 +080086 enum animation_type win_animation_type;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -050087 struct weston_surface *debug_repaint_surface;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040088};
89
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050090enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020091 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050092
Pekka Paalanen57da4a82011-11-23 16:42:16 +020093 SHELL_SURFACE_PANEL,
94 SHELL_SURFACE_BACKGROUND,
95 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020096 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050097
98 SHELL_SURFACE_TOPLEVEL,
99 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500100 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +0800101 SHELL_SURFACE_MAXIMIZED,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500102 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200103};
104
Scott Moreauff1db4a2012-04-17 19:06:18 -0600105struct ping_timer {
106 struct wl_event_source *source;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600107 uint32_t serial;
108};
109
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200110struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200111 struct wl_resource resource;
112
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500113 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200114 struct wl_listener surface_destroy_listener;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500115 struct shell_surface *parent;
Tiago Vignattibe143262012-04-16 17:31:41 +0300116 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200117
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400118 enum shell_surface_type type, next_type;
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400119 char *title, *class;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500120 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800121 bool saved_position_valid;
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800122 bool saved_rotation_valid;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600123 int unresponsive;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100124
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500125 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200126 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500127 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200128 } rotation;
129
130 struct {
Scott Moreau447013d2012-02-18 05:05:29 -0700131 struct wl_pointer_grab grab;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500132 int32_t x, y;
Pekka Paalanen938269a2012-02-07 14:19:01 +0200133 struct weston_transform parent_transform;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500134 int32_t initial_up;
Daniel Stone37816df2012-05-16 18:45:18 +0100135 struct wl_seat *seat;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400136 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500137 } popup;
138
Alex Wu4539b082012-03-01 12:57:46 +0800139 struct {
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300140 int32_t x, y;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400141 uint32_t flags;
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300142 } transient;
143
144 struct {
Alex Wu4539b082012-03-01 12:57:46 +0800145 enum wl_shell_surface_fullscreen_method type;
146 struct weston_transform transform; /* matrix from x, y */
147 uint32_t framerate;
148 struct weston_surface *black_surface;
149 } fullscreen;
150
Scott Moreauff1db4a2012-04-17 19:06:18 -0600151 struct ping_timer *ping_timer;
152
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600153 struct {
154 struct weston_animation current;
155 int exists;
156 int fading_in;
157 uint32_t timestamp;
158 } unresponsive_animation;
159
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500160 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500161 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100162 struct wl_list link;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400163
164 const struct weston_shell_client *client;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200165};
166
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300167struct shell_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700168 struct wl_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300169 struct shell_surface *shsurf;
170 struct wl_listener shsurf_destroy_listener;
171};
172
173struct weston_move_grab {
174 struct shell_grab base;
Daniel Stone103db7f2012-05-08 17:17:55 +0100175 wl_fixed_t dx, dy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500176};
177
Pekka Paalanen460099f2012-01-20 16:48:25 +0200178struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300179 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500180 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200181 struct {
182 int32_t x;
183 int32_t y;
184 } center;
185};
186
Alex Wubd3354b2012-04-17 17:20:49 +0800187static struct shell_surface *
188get_shell_surface(struct weston_surface *surface);
189
190static struct desktop_shell *
191shell_surface_get_shell(struct shell_surface *shsurf);
192
193static bool
194shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
195{
196 struct desktop_shell *shell;
197 struct weston_surface *top_fs_es;
198
199 shell = shell_surface_get_shell(shsurf);
200
201 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
202 return false;
203
204 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
205 struct weston_surface,
206 layer_link);
207 return (shsurf == get_shell_surface(top_fs_es));
208}
209
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500210static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400211destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300212{
213 struct shell_grab *grab;
214
215 grab = container_of(listener, struct shell_grab,
216 shsurf_destroy_listener);
217
218 grab->shsurf = NULL;
219}
220
221static void
222shell_grab_init(struct shell_grab *grab,
223 const struct wl_pointer_grab_interface *interface,
224 struct shell_surface *shsurf)
225{
226 grab->grab.interface = interface;
227 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400228 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
229 wl_signal_add(&shsurf->resource.destroy_signal,
230 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300231
232}
233
234static void
235shell_grab_finish(struct shell_grab *grab)
236{
237 wl_list_remove(&grab->shsurf_destroy_listener.link);
238}
239
240static void
Alex Wu4539b082012-03-01 12:57:46 +0800241center_on_output(struct weston_surface *surface,
242 struct weston_output *output);
243
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300244static uint32_t
245get_modifier(char *modifier)
246{
247 if (!modifier)
248 return MODIFIER_SUPER;
249
250 if (!strcmp("ctrl", modifier))
251 return MODIFIER_CTRL;
252 else if (!strcmp("alt", modifier))
253 return MODIFIER_ALT;
254 else if (!strcmp("super", modifier))
255 return MODIFIER_SUPER;
256 else
257 return MODIFIER_SUPER;
258}
259
Juan Zhaoe10d2792012-04-25 19:09:52 +0800260static enum animation_type
261get_animation_type(char *animation)
262{
263 if (!animation)
264 return ANIMATION_NONE;
265
266 if (!strcmp("zoom", animation))
267 return ANIMATION_ZOOM;
268 else if (!strcmp("fade", animation))
269 return ANIMATION_FADE;
270 else
271 return ANIMATION_NONE;
272}
273
Alex Wu4539b082012-03-01 12:57:46 +0800274static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300275shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200276{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200277 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200278 char *path = NULL;
279 int duration = 60;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300280 char *modifier = NULL;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800281 char *win_animation = NULL;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200282
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400283 struct config_key shell_keys[] = {
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300284 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
Juan Zhaoe10d2792012-04-25 19:09:52 +0800285 { "animation", CONFIG_KEY_STRING, &win_animation},
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200286 };
287
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400288 struct config_key saver_keys[] = {
289 { "path", CONFIG_KEY_STRING, &path },
290 { "duration", CONFIG_KEY_INTEGER, &duration },
291 };
292
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200293 struct config_section cs[] = {
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400294 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200295 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
296 };
297
Tiago Vignatti9a206c42012-03-21 19:49:18 +0200298 config_file = config_file_path("weston.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500299 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200300 free(config_file);
301
Pekka Paalanen7296e792011-12-07 16:22:00 +0200302 shell->screensaver.path = path;
303 shell->screensaver.duration = duration;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300304 shell->binding_modifier = get_modifier(modifier);
Juan Zhaoe10d2792012-04-25 19:09:52 +0800305 shell->win_animation_type = get_animation_type(win_animation);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200306}
307
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200308static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400309noop_grab_focus(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100310 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500311{
312 grab->focus = NULL;
313}
314
315static void
Scott Moreau447013d2012-02-18 05:05:29 -0700316move_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100317 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500318{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500319 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100320 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300321 struct shell_surface *shsurf = move->base.shsurf;
322 struct weston_surface *es;
Daniel Stone37816df2012-05-16 18:45:18 +0100323 int dx = wl_fixed_to_int(pointer->x + move->dx);
324 int dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300325
326 if (!shsurf)
327 return;
328
329 es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500330
Daniel Stone103db7f2012-05-08 17:17:55 +0100331 weston_surface_configure(es, dx, dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200332 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500333}
334
335static void
Scott Moreau447013d2012-02-18 05:05:29 -0700336move_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +0100337 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500338{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300339 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
340 grab);
Daniel Stone37816df2012-05-16 18:45:18 +0100341 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500342
Daniel Stone37816df2012-05-16 18:45:18 +0100343 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300344 shell_grab_finish(shell_grab);
Daniel Stone37816df2012-05-16 18:45:18 +0100345 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500346 free(grab);
347 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500348}
349
Scott Moreau447013d2012-02-18 05:05:29 -0700350static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500351 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500352 move_grab_motion,
353 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500354};
355
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600356static void
357unresponsive_surface_fade(struct shell_surface *shsurf, bool reverse)
358{
359 shsurf->unresponsive_animation.fading_in = reverse ? 0 : 1;
360
361 if(!shsurf->unresponsive_animation.exists) {
362 wl_list_insert(&shsurf->surface->compositor->animation_list,
363 &shsurf->unresponsive_animation.current.link);
364 shsurf->unresponsive_animation.exists = 1;
365 shsurf->unresponsive_animation.timestamp = weston_compositor_get_time();
366 weston_surface_damage(shsurf->surface);
367 }
368}
369
370static void
Scott Moreau9521d5e2012-04-19 13:06:17 -0600371unresponsive_fade_frame(struct weston_animation *animation,
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600372 struct weston_output *output, uint32_t msecs)
373{
374 struct shell_surface *shsurf =
375 container_of(animation, struct shell_surface, unresponsive_animation.current);
376 struct weston_surface *surface = shsurf->surface;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600377 unsigned int step = 8;
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600378
379 if (!surface || !shsurf)
380 return;
381
382 if (shsurf->unresponsive_animation.fading_in) {
383 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
384 if (surface->saturation > 1)
385 surface->saturation -= 5;
386 if (surface->brightness > 200)
387 surface->brightness--;
388
389 shsurf->unresponsive_animation.timestamp += step;
390 }
391
392 if (surface->saturation <= 1 && surface->brightness <= 200) {
393 wl_list_remove(&shsurf->unresponsive_animation.current.link);
394 shsurf->unresponsive_animation.exists = 0;
395 }
396 }
397 else {
398 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
399 if (surface->saturation < 255)
400 surface->saturation += 5;
401 if (surface->brightness < 255)
402 surface->brightness++;
403
404 shsurf->unresponsive_animation.timestamp += step;
405 }
406
407 if (surface->saturation >= 255 && surface->brightness >= 255) {
408 surface->saturation = surface->brightness = 255;
409 wl_list_remove(&shsurf->unresponsive_animation.current.link);
410 shsurf->unresponsive_animation.exists = 0;
411 }
412 }
413
414 surface->geometry.dirty = 1;
415 weston_surface_damage(surface);
416}
417
Scott Moreau9521d5e2012-04-19 13:06:17 -0600418static void
419ping_timer_destroy(struct shell_surface *shsurf)
420{
421 if (!shsurf || !shsurf->ping_timer)
422 return;
423
424 if (shsurf->ping_timer->source)
425 wl_event_source_remove(shsurf->ping_timer->source);
426
427 free(shsurf->ping_timer);
428 shsurf->ping_timer = NULL;
429}
430
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400431static int
Scott Moreauff1db4a2012-04-17 19:06:18 -0600432ping_timeout_handler(void *data)
433{
434 struct shell_surface *shsurf = data;
435
Scott Moreau9521d5e2012-04-19 13:06:17 -0600436 /* Client is not responding */
437 shsurf->unresponsive = 1;
438 unresponsive_surface_fade(shsurf, false);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600439
440 return 1;
441}
442
443static void
444ping_handler(struct weston_surface *surface, uint32_t serial)
445{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -0400446 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600447 struct wl_event_loop *loop;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600448 int ping_timeout = 2500;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600449
450 if (!shsurf)
451 return;
Kristian Høgsbergca535c12012-04-21 23:20:07 -0400452 if (!shsurf->resource.client)
453 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600454
455 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +0300456 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600457 if (!shsurf->ping_timer)
458 return;
459
460 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600461 loop = wl_display_get_event_loop(surface->compositor->wl_display);
462 shsurf->ping_timer->source =
463 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
464 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
465
466 wl_shell_surface_send_ping(&shsurf->resource, serial);
467 }
468}
469
470static void
471shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
472 uint32_t serial)
473{
474 struct shell_surface *shsurf = resource->data;
475
Scott Moreauff1db4a2012-04-17 19:06:18 -0600476 if (shsurf->ping_timer->serial == serial) {
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600477 if (shsurf->unresponsive) {
478 /* Received pong from previously unresponsive client */
479 unresponsive_surface_fade(shsurf, true);
480 }
Scott Moreauff1db4a2012-04-17 19:06:18 -0600481 shsurf->unresponsive = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600482 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600483 }
484}
485
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400486static void
487shell_surface_set_title(struct wl_client *client,
488 struct wl_resource *resource, const char *title)
489{
490 struct shell_surface *shsurf = resource->data;
491
492 free(shsurf->title);
493 shsurf->title = strdup(title);
494}
495
496static void
497shell_surface_set_class(struct wl_client *client,
498 struct wl_resource *resource, const char *class)
499{
500 struct shell_surface *shsurf = resource->data;
501
502 free(shsurf->class);
503 shsurf->class = strdup(class);
504}
505
Scott Moreauff1db4a2012-04-17 19:06:18 -0600506static int
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400507surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500508{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500509 struct weston_move_grab *move;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300510
511 if (!shsurf)
512 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500513
514 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400515 if (!move)
516 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500517
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300518 shell_grab_init(&move->base, &move_grab_interface, shsurf);
519
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400520 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
Daniel Stone37816df2012-05-16 18:45:18 +0100521 ws->seat.pointer->grab_x;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400522 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
Daniel Stone37816df2012-05-16 18:45:18 +0100523 ws->seat.pointer->grab_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500524
Daniel Stone37816df2012-05-16 18:45:18 +0100525 wl_pointer_start_grab(ws->seat.pointer, &move->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500526
Daniel Stone37816df2012-05-16 18:45:18 +0100527 wl_pointer_set_focus(ws->seat.pointer, NULL,
528 wl_fixed_from_int(0),
529 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400530
531 return 0;
532}
533
534static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200535shell_surface_move(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100536 struct wl_resource *seat_resource, uint32_t serial)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400537{
Daniel Stone37816df2012-05-16 18:45:18 +0100538 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200539 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400540
Daniel Stone37816df2012-05-16 18:45:18 +0100541 if (ws->seat.pointer->button_count == 0 ||
542 ws->seat.pointer->grab_serial != serial ||
543 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500544 return;
545
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400546 if (surface_move(shsurf, ws) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400547 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500548}
549
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500550struct weston_resize_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300551 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500552 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200553 int32_t width, height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500554};
555
556static void
Scott Moreau447013d2012-02-18 05:05:29 -0700557resize_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100558 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500559{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500560 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100561 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400562 struct shell_surface *shsurf = resize->base.shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500563 int32_t width, height;
Daniel Stone103db7f2012-05-08 17:17:55 +0100564 wl_fixed_t from_x, from_y;
565 wl_fixed_t to_x, to_y;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200566
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400567 if (!shsurf)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300568 return;
569
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400570 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100571 pointer->grab_x, pointer->grab_y,
Daniel Stone103db7f2012-05-08 17:17:55 +0100572 &from_x, &from_y);
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400573 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100574 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500575
Daniel Stone103db7f2012-05-08 17:17:55 +0100576 width = resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200577 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100578 width += wl_fixed_to_int(from_x - to_x);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200579 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100580 width += wl_fixed_to_int(to_x - from_x);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500581 }
582
Daniel Stone103db7f2012-05-08 17:17:55 +0100583 height = resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200584 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100585 height += wl_fixed_to_int(from_y - to_y);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200586 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100587 height += wl_fixed_to_int(to_y - from_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500588 }
589
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400590 shsurf->client->send_configure(shsurf->surface,
591 resize->edges, width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500592}
593
594static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400595send_configure(struct weston_surface *surface,
596 uint32_t edges, int32_t width, int32_t height)
597{
598 struct shell_surface *shsurf = get_shell_surface(surface);
599
600 wl_shell_surface_send_configure(&shsurf->resource,
601 edges, width, height);
602}
603
604static const struct weston_shell_client shell_client = {
605 send_configure
606};
607
608static void
Scott Moreau447013d2012-02-18 05:05:29 -0700609resize_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +0100610 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500611{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300612 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100613 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500614
Daniel Stone37816df2012-05-16 18:45:18 +0100615 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300616 shell_grab_finish(&resize->base);
Daniel Stone37816df2012-05-16 18:45:18 +0100617 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500618 free(grab);
619 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500620}
621
Scott Moreau447013d2012-02-18 05:05:29 -0700622static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500623 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500624 resize_grab_motion,
625 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500626};
627
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400628static int
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400629surface_resize(struct shell_surface *shsurf,
630 struct weston_seat *ws, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500631{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500632 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500633
Alex Wu4539b082012-03-01 12:57:46 +0800634 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
635 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500636
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200637 if (edges == 0 || edges > 15 ||
638 (edges & 3) == 3 || (edges & 12) == 12)
639 return 0;
640
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500641 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400642 if (!resize)
643 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500644
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300645 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
646
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500647 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200648 resize->width = shsurf->surface->geometry.width;
649 resize->height = shsurf->surface->geometry.height;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400650
Daniel Stone37816df2012-05-16 18:45:18 +0100651 wl_pointer_start_grab(ws->seat.pointer, &resize->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500652
Daniel Stone37816df2012-05-16 18:45:18 +0100653 wl_pointer_set_focus(ws->seat.pointer, NULL,
654 wl_fixed_from_int(0),
655 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400656
657 return 0;
658}
659
660static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200661shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100662 struct wl_resource *seat_resource, uint32_t serial,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200663 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400664{
Daniel Stone37816df2012-05-16 18:45:18 +0100665 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200666 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400667
Alex Wu4539b082012-03-01 12:57:46 +0800668 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
669 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400670
Daniel Stone37816df2012-05-16 18:45:18 +0100671 if (ws->seat.pointer->button_count == 0 ||
672 ws->seat.pointer->grab_serial != serial ||
673 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500674 return;
675
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400676 if (surface_resize(shsurf, ws, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400677 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500678}
679
Juan Zhao96879df2012-02-07 08:45:41 +0800680static struct weston_output *
681get_default_output(struct weston_compositor *compositor)
682{
683 return container_of(compositor->output_list.next,
684 struct weston_output, link);
685}
686
Alex Wu4539b082012-03-01 12:57:46 +0800687static void
688shell_unset_fullscreen(struct shell_surface *shsurf)
689{
690 /* undo all fullscreen things here */
Alex Wubd3354b2012-04-17 17:20:49 +0800691 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
692 shell_surface_is_top_fullscreen(shsurf)) {
693 weston_output_switch_mode(shsurf->fullscreen_output,
694 shsurf->fullscreen_output->origin);
695 }
Alex Wu4539b082012-03-01 12:57:46 +0800696 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
697 shsurf->fullscreen.framerate = 0;
698 wl_list_remove(&shsurf->fullscreen.transform.link);
699 wl_list_init(&shsurf->fullscreen.transform.link);
Alex Wubd3354b2012-04-17 17:20:49 +0800700 if (shsurf->fullscreen.black_surface)
701 weston_surface_destroy(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800702 shsurf->fullscreen.black_surface = NULL;
703 shsurf->fullscreen_output = NULL;
Alex Wu4539b082012-03-01 12:57:46 +0800704 weston_surface_set_position(shsurf->surface,
705 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800706 if (shsurf->saved_rotation_valid) {
707 wl_list_insert(&shsurf->surface->geometry.transformation_list,
708 &shsurf->rotation.transform.link);
709 shsurf->saved_rotation_valid = false;
710 }
Alex Wu4539b082012-03-01 12:57:46 +0800711}
712
Pekka Paalanen98262232011-12-01 10:42:22 +0200713static int
714reset_shell_surface_type(struct shell_surface *surface)
715{
716 switch (surface->type) {
717 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800718 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200719 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800720 case SHELL_SURFACE_MAXIMIZED:
721 surface->output = get_default_output(surface->surface->compositor);
722 weston_surface_set_position(surface->surface,
723 surface->saved_x,
724 surface->saved_y);
725 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200726 case SHELL_SURFACE_PANEL:
727 case SHELL_SURFACE_BACKGROUND:
728 wl_list_remove(&surface->link);
729 wl_list_init(&surface->link);
730 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200731 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200732 case SHELL_SURFACE_LOCK:
733 wl_resource_post_error(&surface->resource,
734 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200735 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200736 return -1;
737 case SHELL_SURFACE_NONE:
738 case SHELL_SURFACE_TOPLEVEL:
739 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500740 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200741 break;
742 }
743
744 surface->type = SHELL_SURFACE_NONE;
745 return 0;
746}
747
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500748static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400749set_surface_type(struct shell_surface *shsurf)
750{
751 struct weston_surface *surface = shsurf->surface;
752 struct shell_surface *pshsurf = shsurf->parent;
753 struct weston_surface *pes;
754 struct shell_surface *priv;
755 struct desktop_shell *shell = shsurf->shell;
756
757 reset_shell_surface_type(shsurf);
758
759 shsurf->type = shsurf->next_type;
760 shsurf->next_type = SHELL_SURFACE_NONE;
761
762 switch (shsurf->type) {
763 case SHELL_SURFACE_TOPLEVEL:
764 break;
765 case SHELL_SURFACE_TRANSIENT:
766 pes = pshsurf->surface;
767 weston_surface_set_position(surface,
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300768 pes->geometry.x + shsurf->transient.x,
769 pes->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400770 break;
771
772 case SHELL_SURFACE_MAXIMIZED:
773 shsurf->saved_x = surface->geometry.x;
774 shsurf->saved_y = surface->geometry.y;
775 shsurf->saved_position_valid = true;
776 break;
777
778 case SHELL_SURFACE_FULLSCREEN:
779 shsurf->saved_x = surface->geometry.x;
780 shsurf->saved_y = surface->geometry.y;
781 shsurf->saved_position_valid = true;
782
783 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
784 wl_list_remove(&shsurf->rotation.transform.link);
785 wl_list_init(&shsurf->rotation.transform.link);
786 shsurf->surface->geometry.dirty = 1;
787 shsurf->saved_rotation_valid = true;
788 }
789 break;
790
791 case SHELL_SURFACE_BACKGROUND:
792 wl_list_for_each(priv, &shell->backgrounds, link) {
793 if (priv->output == shsurf->output) {
794 priv->surface->output = NULL;
795 wl_list_remove(&priv->surface->layer_link);
796 wl_list_remove(&priv->link);
797 break;
798 }
799 }
800
801 wl_list_insert(&shell->backgrounds, &shsurf->link);
802
803 weston_surface_set_position(surface, shsurf->output->x,
804 shsurf->output->y);
805 break;
806
807 case SHELL_SURFACE_PANEL:
808 wl_list_for_each(priv, &shell->panels, link) {
809 if (priv->output == shsurf->output) {
810 priv->surface->output = NULL;
811 wl_list_remove(&priv->surface->layer_link);
812 wl_list_remove(&priv->link);
813 break;
814 }
815 }
816
817 wl_list_insert(&shell->panels, &shsurf->link);
818
819 weston_surface_set_position(surface, shsurf->output->x,
820 shsurf->output->y);
821 break;
822
823 default:
824 break;
825 }
826}
827
828static void
Tiago Vignattibc052c92012-04-19 16:18:18 +0300829set_toplevel(struct shell_surface *shsurf)
830{
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400831 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Tiago Vignattibc052c92012-04-19 16:18:18 +0300832}
833
834static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200835shell_surface_set_toplevel(struct wl_client *client,
836 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400837{
Pekka Paalanen98262232011-12-01 10:42:22 +0200838 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400839
Tiago Vignattibc052c92012-04-19 16:18:18 +0300840 set_toplevel(surface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400841}
842
843static void
Tiago Vignatti491bac12012-05-18 16:37:43 -0400844set_transient(struct shell_surface *shsurf,
845 struct shell_surface *pshsurf, int x, int y, uint32_t flags)
846{
847 /* assign to parents output */
848 shsurf->parent = pshsurf;
849 shsurf->transient.x = x;
850 shsurf->transient.y = y;
851 shsurf->transient.flags = flags;
852 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
853}
854
855static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200856shell_surface_set_transient(struct wl_client *client,
857 struct wl_resource *resource,
858 struct wl_resource *parent_resource,
859 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400860{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200861 struct shell_surface *shsurf = resource->data;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400862 struct shell_surface *pshsurf = parent_resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200863
Tiago Vignatti491bac12012-05-18 16:37:43 -0400864 set_transient(shsurf, pshsurf, x, y, flags);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400865}
866
Tiago Vignattibe143262012-04-16 17:31:41 +0300867static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +0800868shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200869{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400870 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +0800871}
872
873static int
Tiago Vignattibe143262012-04-16 17:31:41 +0300874get_output_panel_height(struct desktop_shell *shell,
875 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +0800876{
877 struct shell_surface *priv;
878 int panel_height = 0;
879
880 if (!output)
881 return 0;
882
Tiago Vignattibe143262012-04-16 17:31:41 +0300883 wl_list_for_each(priv, &shell->panels, link) {
Juan Zhao96879df2012-02-07 08:45:41 +0800884 if (priv->output == output) {
885 panel_height = priv->surface->geometry.height;
886 break;
887 }
888 }
889 return panel_height;
890}
891
892static void
893shell_surface_set_maximized(struct wl_client *client,
894 struct wl_resource *resource,
895 struct wl_resource *output_resource )
896{
897 struct shell_surface *shsurf = resource->data;
898 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300899 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +0800900 uint32_t edges = 0, panel_height = 0;
901
902 /* get the default output, if the client set it as NULL
903 check whether the ouput is available */
904 if (output_resource)
905 shsurf->output = output_resource->data;
906 else
907 shsurf->output = get_default_output(es->compositor);
908
Tiago Vignattibe143262012-04-16 17:31:41 +0300909 shell = shell_surface_get_shell(shsurf);
910 panel_height = get_output_panel_height(shell, es->output);
Juan Zhao96879df2012-02-07 08:45:41 +0800911 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500912
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400913 shsurf->client->send_configure(shsurf->surface, edges,
914 es->output->current->width,
915 es->output->current->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +0800916
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400917 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200918}
919
Alex Wu21858432012-04-01 20:13:08 +0800920static void
921black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
922
Alex Wu4539b082012-03-01 12:57:46 +0800923static struct weston_surface *
924create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +0800925 struct weston_surface *fs_surface,
Alex Wu4539b082012-03-01 12:57:46 +0800926 GLfloat x, GLfloat y, int w, int h)
927{
928 struct weston_surface *surface = NULL;
929
930 surface = weston_surface_create(ec);
931 if (surface == NULL) {
932 fprintf(stderr, "no memory\n");
933 return NULL;
934 }
935
Alex Wu21858432012-04-01 20:13:08 +0800936 surface->configure = black_surface_configure;
937 surface->private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +0800938 weston_surface_configure(surface, x, y, w, h);
939 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
940 return surface;
941}
942
943/* Create black surface and append it to the associated fullscreen surface.
944 * Handle size dismatch and positioning according to the method. */
945static void
946shell_configure_fullscreen(struct shell_surface *shsurf)
947{
948 struct weston_output *output = shsurf->fullscreen_output;
949 struct weston_surface *surface = shsurf->surface;
950 struct weston_matrix *matrix;
951 float scale;
952
953 center_on_output(surface, output);
954
955 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500956 shsurf->fullscreen.black_surface =
957 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +0800958 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500959 output->x, output->y,
960 output->current->width,
961 output->current->height);
962
963 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
964 wl_list_insert(&surface->layer_link,
965 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800966 shsurf->fullscreen.black_surface->output = output;
967
968 switch (shsurf->fullscreen.type) {
969 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
970 break;
971 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
972 matrix = &shsurf->fullscreen.transform.matrix;
973 weston_matrix_init(matrix);
974 scale = (float)output->current->width/(float)surface->geometry.width;
975 weston_matrix_scale(matrix, scale, scale, 1);
976 wl_list_remove(&shsurf->fullscreen.transform.link);
977 wl_list_insert(surface->geometry.transformation_list.prev,
978 &shsurf->fullscreen.transform.link);
979 weston_surface_set_position(surface, output->x, output->y);
980 break;
981 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +0800982 if (shell_surface_is_top_fullscreen(shsurf)) {
983 struct weston_mode mode = {0,
984 surface->geometry.width,
985 surface->geometry.height,
986 shsurf->fullscreen.framerate};
987
988 if (weston_output_switch_mode(output, &mode) == 0) {
989 weston_surface_configure(shsurf->fullscreen.black_surface,
990 output->x, output->y,
991 output->current->width,
992 output->current->height);
993 weston_surface_set_position(surface, output->x, output->y);
994 break;
995 }
996 }
Alex Wu4539b082012-03-01 12:57:46 +0800997 break;
998 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
999 break;
1000 default:
1001 break;
1002 }
1003}
1004
1005/* make the fullscreen and black surface at the top */
1006static void
1007shell_stack_fullscreen(struct shell_surface *shsurf)
1008{
Alex Wubd3354b2012-04-17 17:20:49 +08001009 struct weston_output *output = shsurf->fullscreen_output;
Alex Wu4539b082012-03-01 12:57:46 +08001010 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +03001011 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001012
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001013 wl_list_remove(&surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001014 wl_list_insert(&shell->fullscreen_layer.surface_list,
1015 &surface->layer_link);
Alex Wubd3354b2012-04-17 17:20:49 +08001016 weston_surface_damage(surface);
1017
1018 if (!shsurf->fullscreen.black_surface)
1019 shsurf->fullscreen.black_surface =
1020 create_black_surface(surface->compositor,
1021 surface,
1022 output->x, output->y,
1023 output->current->width,
1024 output->current->height);
1025
1026 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001027 wl_list_insert(&surface->layer_link,
1028 &shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001029 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +08001030}
1031
1032static void
1033shell_map_fullscreen(struct shell_surface *shsurf)
1034{
Alex Wu4539b082012-03-01 12:57:46 +08001035 shell_stack_fullscreen(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001036 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001037}
1038
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001039static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001040shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -05001041 struct wl_resource *resource,
1042 uint32_t method,
1043 uint32_t framerate,
1044 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001045{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001046 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001047 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +08001048
1049 if (output_resource)
1050 shsurf->output = output_resource->data;
1051 else
1052 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001053
Alex Wu4539b082012-03-01 12:57:46 +08001054 shsurf->fullscreen_output = shsurf->output;
1055 shsurf->fullscreen.type = method;
1056 shsurf->fullscreen.framerate = framerate;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001057 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
Alex Wu4539b082012-03-01 12:57:46 +08001058
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001059 shsurf->client->send_configure(shsurf->surface, 0,
1060 shsurf->output->current->width,
1061 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001062}
1063
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001064static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001065popup_grab_focus(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001066 struct wl_surface *surface,
1067 wl_fixed_t x,
1068 wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001069{
Daniel Stone37816df2012-05-16 18:45:18 +01001070 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001071 struct shell_surface *priv =
1072 container_of(grab, struct shell_surface, popup.grab);
1073 struct wl_client *client = priv->surface->surface.resource.client;
1074
Pekka Paalanencb108432012-01-19 16:25:40 +02001075 if (surface && surface->resource.client == client) {
Daniel Stone37816df2012-05-16 18:45:18 +01001076 wl_pointer_set_focus(pointer, surface, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001077 grab->focus = surface;
1078 } else {
Daniel Stone37816df2012-05-16 18:45:18 +01001079 wl_pointer_set_focus(pointer, NULL,
1080 wl_fixed_from_int(0),
1081 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001082 grab->focus = NULL;
1083 }
1084}
1085
1086static void
Scott Moreau447013d2012-02-18 05:05:29 -07001087popup_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001088 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001089{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001090 struct wl_resource *resource;
1091
Daniel Stone37816df2012-05-16 18:45:18 +01001092 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001093 if (resource)
Daniel Stone37816df2012-05-16 18:45:18 +01001094 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001095}
1096
1097static void
Scott Moreau447013d2012-02-18 05:05:29 -07001098popup_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01001099 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001100{
1101 struct wl_resource *resource;
1102 struct shell_surface *shsurf =
1103 container_of(grab, struct shell_surface, popup.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001104 struct wl_display *display;
1105 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001106
Daniel Stone37816df2012-05-16 18:45:18 +01001107 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001108 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001109 display = wl_client_get_display(resource->client);
1110 serial = wl_display_get_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +01001111 wl_pointer_send_button(resource, serial, time, button, state);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001112 } else if (state == 0 &&
1113 (shsurf->popup.initial_up ||
Daniel Stone37816df2012-05-16 18:45:18 +01001114 time - shsurf->popup.seat->pointer->grab_time > 500)) {
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001115 wl_shell_surface_send_popup_done(&shsurf->resource);
Daniel Stone37816df2012-05-16 18:45:18 +01001116 wl_pointer_end_grab(grab->pointer);
1117 shsurf->popup.grab.pointer = NULL;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001118 }
1119
1120 if (state == 0)
1121 shsurf->popup.initial_up = 1;
1122}
1123
Scott Moreau447013d2012-02-18 05:05:29 -07001124static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001125 popup_grab_focus,
1126 popup_grab_motion,
1127 popup_grab_button,
1128};
1129
1130static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001131shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001132{
Daniel Stone37816df2012-05-16 18:45:18 +01001133 struct wl_seat *seat = shsurf->popup.seat;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001134 struct weston_surface *es = shsurf->surface;
1135 struct weston_surface *parent = shsurf->parent->surface;
1136
1137 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001138 shsurf->popup.grab.interface = &popup_grab_interface;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001139
Pekka Paalanen938269a2012-02-07 14:19:01 +02001140 weston_surface_update_transform(parent);
1141 if (parent->transform.enabled) {
1142 shsurf->popup.parent_transform.matrix =
1143 parent->transform.matrix;
1144 } else {
1145 /* construct x, y translation matrix */
1146 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1147 shsurf->popup.parent_transform.matrix.d[12] =
1148 parent->geometry.x;
1149 shsurf->popup.parent_transform.matrix.d[13] =
1150 parent->geometry.y;
1151 }
1152 wl_list_insert(es->geometry.transformation_list.prev,
1153 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001154 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001155
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001156 shsurf->popup.initial_up = 0;
1157
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001158 /* We don't require the grab to still be active, but if another
1159 * grab has started in the meantime, we end the popup now. */
Daniel Stone37816df2012-05-16 18:45:18 +01001160 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1161 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001162 } else {
1163 wl_shell_surface_send_popup_done(&shsurf->resource);
1164 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001165}
1166
1167static void
1168shell_surface_set_popup(struct wl_client *client,
1169 struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +01001170 struct wl_resource *seat_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001171 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001172 struct wl_resource *parent_resource,
1173 int32_t x, int32_t y, uint32_t flags)
1174{
1175 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001176
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001177 shsurf->type = SHELL_SURFACE_POPUP;
1178 shsurf->parent = parent_resource->data;
Daniel Stone37816df2012-05-16 18:45:18 +01001179 shsurf->popup.seat = seat_resource->data;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001180 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001181 shsurf->popup.x = x;
1182 shsurf->popup.y = y;
1183}
1184
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001185static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06001186 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001187 shell_surface_move,
1188 shell_surface_resize,
1189 shell_surface_set_toplevel,
1190 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001191 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08001192 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001193 shell_surface_set_maximized,
1194 shell_surface_set_title,
1195 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001196};
1197
1198static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001199destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001200{
Daniel Stone37816df2012-05-16 18:45:18 +01001201 if (shsurf->popup.grab.pointer)
1202 wl_pointer_end_grab(shsurf->popup.grab.pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001203
Alex Wubd3354b2012-04-17 17:20:49 +08001204 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1205 shell_surface_is_top_fullscreen(shsurf)) {
1206 weston_output_switch_mode(shsurf->fullscreen_output,
1207 shsurf->fullscreen_output->origin);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001208 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001209
Alex Wuaa08e2d2012-03-05 11:01:40 +08001210 if (shsurf->fullscreen.black_surface)
1211 weston_surface_destroy(shsurf->fullscreen.black_surface);
1212
Alex Wubd3354b2012-04-17 17:20:49 +08001213 /* As destroy_resource() use wl_list_for_each_safe(),
1214 * we can always remove the listener.
1215 */
1216 wl_list_remove(&shsurf->surface_destroy_listener.link);
1217 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001218 ping_timer_destroy(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001219
Rob Bradford579f2932012-05-21 18:04:15 +01001220 if (shsurf->unresponsive_animation.exists)
1221 wl_list_remove(&shsurf->unresponsive_animation.current.link);
1222
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001223 wl_list_remove(&shsurf->link);
1224 free(shsurf);
1225}
1226
1227static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001228shell_destroy_shell_surface(struct wl_resource *resource)
1229{
1230 struct shell_surface *shsurf = resource->data;
1231
1232 destroy_shell_surface(shsurf);
1233}
1234
1235static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001236shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001237{
1238 struct shell_surface *shsurf = container_of(listener,
1239 struct shell_surface,
1240 surface_destroy_listener);
1241
Tiago Vignattibc052c92012-04-19 16:18:18 +03001242 /* tricky way to check if resource was in fact created */
1243 if (shsurf->resource.object.implementation != 0)
1244 wl_resource_destroy(&shsurf->resource);
1245 else
1246 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001247}
1248
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001249static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001250get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001251{
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001252 struct wl_listener *listener;
1253
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001254 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
1255 shell_handle_surface_destroy);
1256 if (listener)
1257 return container_of(listener, struct shell_surface,
1258 surface_destroy_listener);
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001259
1260 return NULL;
1261}
1262
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001263static void
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001264shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1265
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001266static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001267create_shell_surface(void *shell, struct weston_surface *surface,
1268 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001269{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001270 struct shell_surface *shsurf;
1271
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001272 if (surface->configure) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001273 fprintf(stderr, "surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001274 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001275 }
1276
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001277 shsurf = calloc(1, sizeof *shsurf);
1278 if (!shsurf) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001279 fprintf(stderr, "no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001280 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001281 }
1282
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001283 surface->configure = shell_surface_configure;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001284 surface->compositor->shell_interface.shell = shell;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001285
Tiago Vignattibc052c92012-04-19 16:18:18 +03001286 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001287 shsurf->unresponsive = 0;
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001288 shsurf->unresponsive_animation.exists = 0;
1289 shsurf->unresponsive_animation.fading_in = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001290 shsurf->unresponsive_animation.current.frame = unresponsive_fade_frame;
Alex Wu4539b082012-03-01 12:57:46 +08001291 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08001292 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001293 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08001294 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1295 shsurf->fullscreen.framerate = 0;
1296 shsurf->fullscreen.black_surface = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001297 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08001298 wl_list_init(&shsurf->fullscreen.transform.link);
1299
Tiago Vignattibc052c92012-04-19 16:18:18 +03001300 wl_signal_init(&shsurf->resource.destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001301 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1302 wl_signal_add(&surface->surface.resource.destroy_signal,
1303 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001304
1305 /* init link so its safe to always remove it in destroy_shell_surface */
1306 wl_list_init(&shsurf->link);
1307
Pekka Paalanen460099f2012-01-20 16:48:25 +02001308 /* empty when not in use */
1309 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001310 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001311
Pekka Paalanen98262232011-12-01 10:42:22 +02001312 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001313 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001314
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001315 shsurf->client = client;
1316
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001317 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001318}
1319
1320static void
1321shell_get_shell_surface(struct wl_client *client,
1322 struct wl_resource *resource,
1323 uint32_t id,
1324 struct wl_resource *surface_resource)
1325{
1326 struct weston_surface *surface = surface_resource->data;
1327 struct desktop_shell *shell = resource->data;
1328 struct shell_surface *shsurf;
1329
1330 if (get_shell_surface(surface)) {
1331 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001332 WL_DISPLAY_ERROR_INVALID_OBJECT,
1333 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03001334 return;
1335 }
1336
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001337 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001338 if (!shsurf) {
1339 wl_resource_post_error(surface_resource,
1340 WL_DISPLAY_ERROR_INVALID_OBJECT,
1341 "surface->configure already set");
1342 return;
1343 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03001344
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001345 shsurf->resource.destroy = shell_destroy_shell_surface;
1346 shsurf->resource.object.id = id;
1347 shsurf->resource.object.interface = &wl_shell_surface_interface;
1348 shsurf->resource.object.implementation =
1349 (void (**)(void)) &shell_surface_implementation;
1350 shsurf->resource.data = shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001351
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001352 wl_client_add_resource(client, &shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001353}
1354
1355static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02001356 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001357};
1358
Kristian Høgsberg07937562011-04-12 17:25:42 -04001359static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001360handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02001361{
1362 proc->pid = 0;
1363}
1364
1365static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001366launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001367{
1368 if (shell->screensaver.binding)
1369 return;
1370
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001371 if (!shell->screensaver.path)
1372 return;
1373
Kristian Høgsberg32bed572012-03-01 17:11:36 -05001374 if (shell->screensaver.process.pid != 0) {
1375 fprintf(stderr, "old screensaver still running\n");
1376 return;
1377 }
1378
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001379 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001380 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001381 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001382 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001383}
1384
1385static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001386terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001387{
Pekka Paalanen18027e52011-12-02 16:31:49 +02001388 if (shell->screensaver.process.pid == 0)
1389 return;
1390
1391 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001392}
1393
1394static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001395show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001396{
1397 struct wl_list *list;
1398
1399 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001400 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001401 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001402 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001403
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001404 wl_list_remove(&surface->surface->layer_link);
1405 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001406 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001407 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001408}
1409
1410static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001411hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001412{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001413 wl_list_remove(&surface->surface->layer_link);
1414 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001415 surface->surface->output = NULL;
1416}
1417
1418static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001419desktop_shell_set_background(struct wl_client *client,
1420 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001421 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001422 struct wl_resource *surface_resource)
1423{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001424 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001425
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001426 shsurf->next_type = SHELL_SURFACE_BACKGROUND;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001427 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001428
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001429 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001430 surface_resource,
1431 shsurf->output->current->width,
1432 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001433}
1434
1435static void
1436desktop_shell_set_panel(struct wl_client *client,
1437 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001438 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001439 struct wl_resource *surface_resource)
1440{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001441 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001442
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001443 shsurf->next_type = SHELL_SURFACE_PANEL;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001444 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001445
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001446 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001447 surface_resource,
1448 shsurf->output->current->width,
1449 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001450}
1451
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001452static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001453handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001454{
Tiago Vignattibe143262012-04-16 17:31:41 +03001455 struct desktop_shell *shell =
1456 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001457
1458 fprintf(stderr, "lock surface gone\n");
1459 shell->lock_surface = NULL;
1460}
1461
1462static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001463desktop_shell_set_lock_surface(struct wl_client *client,
1464 struct wl_resource *resource,
1465 struct wl_resource *surface_resource)
1466{
Tiago Vignattibe143262012-04-16 17:31:41 +03001467 struct desktop_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001468 struct shell_surface *surface = surface_resource->data;
1469
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001470 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001471
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001472 if (!shell->locked)
1473 return;
1474
Pekka Paalanen98262232011-12-01 10:42:22 +02001475 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001476
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001477 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1478 wl_signal_add(&surface_resource->destroy_signal,
1479 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001480
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001481 shell->lock_surface->next_type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001482}
1483
1484static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001485resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001486{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001487 struct shell_surface *tmp;
1488
1489 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1490 hide_screensaver(shell, tmp);
1491
1492 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001493
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001494 wl_list_remove(&shell->lock_layer.link);
1495 wl_list_insert(&shell->compositor->cursor_layer.link,
1496 &shell->fullscreen_layer.link);
1497 wl_list_insert(&shell->fullscreen_layer.link,
1498 &shell->panel_layer.link);
1499 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001500
1501 shell->locked = false;
Pekka Paalanen7296e792011-12-07 16:22:00 +02001502 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001503 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001504 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001505}
1506
1507static void
1508desktop_shell_unlock(struct wl_client *client,
1509 struct wl_resource *resource)
1510{
Tiago Vignattibe143262012-04-16 17:31:41 +03001511 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001512
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001513 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001514
1515 if (shell->locked)
1516 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001517}
1518
Kristian Høgsberg75840622011-09-06 13:48:16 -04001519static const struct desktop_shell_interface desktop_shell_implementation = {
1520 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001521 desktop_shell_set_panel,
1522 desktop_shell_set_lock_surface,
1523 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001524};
1525
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001526static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001527get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001528{
1529 struct shell_surface *shsurf;
1530
1531 shsurf = get_shell_surface(surface);
1532 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001533 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001534 return shsurf->type;
1535}
1536
Kristian Høgsberg75840622011-09-06 13:48:16 -04001537static void
Daniel Stone37816df2012-05-16 18:45:18 +01001538move_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001539 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1540 void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001541{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001542 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001543 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001544 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001545
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001546 if (surface == NULL)
1547 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001548
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001549 shsurf = get_shell_surface(surface);
1550 if (shsurf == NULL)
1551 return;
1552
1553 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001554 case SHELL_SURFACE_PANEL:
1555 case SHELL_SURFACE_BACKGROUND:
1556 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001557 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001558 return;
1559 default:
1560 break;
1561 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001562
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001563 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001564}
1565
1566static void
Daniel Stone37816df2012-05-16 18:45:18 +01001567resize_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001568 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1569 void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001570{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001571 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001572 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001573 uint32_t edges = 0;
1574 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001575 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001576
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001577 if (surface == NULL)
1578 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001579
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001580 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001581 if (!shsurf)
1582 return;
1583
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001584 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001585 case SHELL_SURFACE_PANEL:
1586 case SHELL_SURFACE_BACKGROUND:
1587 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001588 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001589 return;
1590 default:
1591 break;
1592 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001593
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001594 weston_surface_from_global(surface,
Daniel Stone37816df2012-05-16 18:45:18 +01001595 wl_fixed_to_int(seat->pointer->grab_x),
1596 wl_fixed_to_int(seat->pointer->grab_y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001597 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001598
Pekka Paalanen60921e52012-01-25 15:55:43 +02001599 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001600 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001601 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001602 edges |= 0;
1603 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001604 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001605
Pekka Paalanen60921e52012-01-25 15:55:43 +02001606 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001607 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001608 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001609 edges |= 0;
1610 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001611 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001612
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001613 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001614}
1615
1616static void
Daniel Stone37816df2012-05-16 18:45:18 +01001617surface_opacity_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001618 uint32_t key, uint32_t button, uint32_t axis,
1619 int32_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001620{
Scott Moreau02709af2012-05-22 01:54:10 -06001621 float step = 0.05;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001622 struct shell_surface *shsurf;
1623 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001624 (struct weston_surface *) seat->pointer->focus;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001625
1626 if (surface == NULL)
1627 return;
1628
1629 shsurf = get_shell_surface(surface);
1630 if (!shsurf)
1631 return;
1632
1633 switch (shsurf->type) {
1634 case SHELL_SURFACE_BACKGROUND:
1635 case SHELL_SURFACE_SCREENSAVER:
1636 return;
1637 default:
1638 break;
1639 }
1640
1641 surface->alpha += value * step;
1642
Scott Moreau02709af2012-05-22 01:54:10 -06001643 if (surface->alpha > 1.0)
1644 surface->alpha = 1.0;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001645 if (surface->alpha < step)
1646 surface->alpha = step;
1647
1648 surface->geometry.dirty = 1;
1649 weston_surface_damage(surface);
1650}
1651
1652static void
Daniel Stone37816df2012-05-16 18:45:18 +01001653zoom_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001654 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1655 void *data)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001656{
Daniel Stone37816df2012-05-16 18:45:18 +01001657 struct weston_seat *ws = (struct weston_seat *) seat;
1658 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001659 struct weston_output *output;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001660 float maximum_level, increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001661
1662 wl_list_for_each(output, &compositor->output_list, link) {
1663 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01001664 wl_fixed_to_double(seat->pointer->x),
1665 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001666 NULL)) {
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001667 if (key == KEY_PAGEUP && value)
1668 increment = output->zoom.increment;
1669 else if (key == KEY_PAGEDOWN && value)
1670 increment = -output->zoom.increment;
1671 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
1672 increment = output->zoom.increment * value;
1673 else
1674 increment = 0;
1675
Scott Moreau1b45a792012-03-22 10:58:23 -06001676 output->zoom.active = 1;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001677 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001678
Scott Moreau850ca422012-05-21 15:21:25 -06001679 if (output->zoom.level <= 0.0) {
Scott Moreauc6d7f602012-02-23 22:28:37 -07001680 output->zoom.active = 0;
Scott Moreau850ca422012-05-21 15:21:25 -06001681 output->zoom.level = 0.0;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001682 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001683
Scott Moreau850ca422012-05-21 15:21:25 -06001684 maximum_level = 1 - output->zoom.increment;
1685
1686 if (output->zoom.level > maximum_level)
1687 output->zoom.level = maximum_level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001688
Daniel Stone37816df2012-05-16 18:45:18 +01001689 weston_output_update_zoom(output,
1690 seat->pointer->x,
1691 seat->pointer->y);
Scott Moreauccbf29d2012-02-22 14:21:41 -07001692 }
1693 }
1694}
1695
Scott Moreauccbf29d2012-02-22 14:21:41 -07001696static void
Daniel Stone37816df2012-05-16 18:45:18 +01001697terminate_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001698 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001699{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001700 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001701
1702 if (state)
1703 wl_display_terminate(compositor->wl_display);
1704}
1705
1706static void
Scott Moreau447013d2012-02-18 05:05:29 -07001707rotate_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001708 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001709{
1710 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001711 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001712 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001713 struct shell_surface *shsurf = rotate->base.shsurf;
1714 struct weston_surface *surface;
1715 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1716
1717 if (!shsurf)
1718 return;
1719
1720 surface = shsurf->surface;
1721
1722 cx = 0.5f * surface->geometry.width;
1723 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001724
Daniel Stone37816df2012-05-16 18:45:18 +01001725 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
1726 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001727 r = sqrtf(dx * dx + dy * dy);
1728
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001729 wl_list_remove(&shsurf->rotation.transform.link);
1730 shsurf->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001731
1732 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001733 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001734 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001735
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001736 weston_matrix_init(&rotate->rotation);
1737 rotate->rotation.d[0] = dx / r;
1738 rotate->rotation.d[4] = -dy / r;
1739 rotate->rotation.d[1] = -rotate->rotation.d[4];
1740 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001741
1742 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001743 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001744 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001745 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001746 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001747
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001748 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001749 &shsurf->surface->geometry.transformation_list,
1750 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001751 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001752 wl_list_init(&shsurf->rotation.transform.link);
1753 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001754 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001755 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001756
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001757 /* We need to adjust the position of the surface
1758 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001759 cposx = surface->geometry.x + cx;
1760 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001761 dposx = rotate->center.x - cposx;
1762 dposy = rotate->center.y - cposy;
1763 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001764 weston_surface_set_position(surface,
1765 surface->geometry.x + dposx,
1766 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001767 }
1768
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001769 /* Repaint implies weston_surface_update_transform(), which
1770 * lazily applies the damage due to rotation update.
1771 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001772 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001773}
1774
1775static void
Scott Moreau447013d2012-02-18 05:05:29 -07001776rotate_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01001777 uint32_t time, uint32_t button, uint32_t state)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001778{
1779 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001780 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001781 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001782 struct shell_surface *shsurf = rotate->base.shsurf;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001783
Daniel Stone37816df2012-05-16 18:45:18 +01001784 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001785 if (shsurf)
1786 weston_matrix_multiply(&shsurf->rotation.rotation,
1787 &rotate->rotation);
1788 shell_grab_finish(&rotate->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001789 wl_pointer_end_grab(pointer);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001790 free(rotate);
1791 }
1792}
1793
Scott Moreau447013d2012-02-18 05:05:29 -07001794static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001795 noop_grab_focus,
1796 rotate_grab_motion,
1797 rotate_grab_button,
1798};
1799
1800static void
Daniel Stone37816df2012-05-16 18:45:18 +01001801rotate_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001802 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1803 void *data)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001804{
1805 struct weston_surface *base_surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001806 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001807 struct shell_surface *surface;
1808 struct rotate_grab *rotate;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001809 GLfloat dx, dy;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001810 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001811
1812 if (base_surface == NULL)
1813 return;
1814
1815 surface = get_shell_surface(base_surface);
1816 if (!surface)
1817 return;
1818
1819 switch (surface->type) {
1820 case SHELL_SURFACE_PANEL:
1821 case SHELL_SURFACE_BACKGROUND:
1822 case SHELL_SURFACE_FULLSCREEN:
1823 case SHELL_SURFACE_SCREENSAVER:
1824 return;
1825 default:
1826 break;
1827 }
1828
Pekka Paalanen460099f2012-01-20 16:48:25 +02001829 rotate = malloc(sizeof *rotate);
1830 if (!rotate)
1831 return;
1832
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001833 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001834
1835 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001836 surface->surface->geometry.width / 2,
1837 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001838 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001839
Daniel Stone37816df2012-05-16 18:45:18 +01001840 wl_pointer_start_grab(seat->pointer, &rotate->base.grab);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001841
Daniel Stone37816df2012-05-16 18:45:18 +01001842 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
1843 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001844 r = sqrtf(dx * dx + dy * dy);
1845 if (r > 20.0f) {
1846 struct weston_matrix inverse;
1847
1848 weston_matrix_init(&inverse);
1849 inverse.d[0] = dx / r;
1850 inverse.d[4] = dy / r;
1851 inverse.d[1] = -inverse.d[4];
1852 inverse.d[5] = inverse.d[0];
1853 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001854
1855 weston_matrix_init(&rotate->rotation);
1856 rotate->rotation.d[0] = dx / r;
1857 rotate->rotation.d[4] = -dy / r;
1858 rotate->rotation.d[1] = -rotate->rotation.d[4];
1859 rotate->rotation.d[5] = rotate->rotation.d[0];
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001860 } else {
1861 weston_matrix_init(&surface->rotation.rotation);
1862 weston_matrix_init(&rotate->rotation);
1863 }
1864
Daniel Stone37816df2012-05-16 18:45:18 +01001865 wl_pointer_set_focus(seat->pointer, NULL,
1866 wl_fixed_from_int(0),
1867 wl_fixed_from_int(0));
Pekka Paalanen460099f2012-01-20 16:48:25 +02001868}
1869
1870static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001871activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01001872 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001873{
Alex Wu21858432012-04-01 20:13:08 +08001874 struct weston_surface *surf, *prev;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001875
Daniel Stone37816df2012-05-16 18:45:18 +01001876 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001877
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001878 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001879 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001880 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001881 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001882 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001883
Pekka Paalanen77346a62011-11-30 16:26:35 +02001884 case SHELL_SURFACE_SCREENSAVER:
1885 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001886 if (shell->lock_surface)
1887 weston_surface_restack(es,
1888 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001889 break;
Alex Wu4539b082012-03-01 12:57:46 +08001890 case SHELL_SURFACE_FULLSCREEN:
1891 /* should on top of panels */
Alex Wu21858432012-04-01 20:13:08 +08001892 shell_stack_fullscreen(get_shell_surface(es));
Alex Wubd3354b2012-04-17 17:20:49 +08001893 shell_configure_fullscreen(get_shell_surface(es));
Alex Wu4539b082012-03-01 12:57:46 +08001894 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001895 default:
Alex Wubd3354b2012-04-17 17:20:49 +08001896 /* move the fullscreen surfaces down into the toplevel layer */
Alex Wu21858432012-04-01 20:13:08 +08001897 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1898 wl_list_for_each_reverse_safe(surf,
1899 prev,
1900 &shell->fullscreen_layer.surface_list,
1901 layer_link)
1902 weston_surface_restack(surf,
1903 &shell->toplevel_layer.surface_list);
1904 }
1905
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001906 weston_surface_restack(es,
1907 &shell->toplevel_layer.surface_list);
1908 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001909 }
1910}
1911
Alex Wu21858432012-04-01 20:13:08 +08001912/* no-op func for checking black surface */
1913static void
1914black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1915{
1916}
1917
1918static bool
1919is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1920{
1921 if (es->configure == black_surface_configure) {
1922 if (fs_surface)
1923 *fs_surface = (struct weston_surface *)es->private;
1924 return true;
1925 }
1926 return false;
1927}
1928
Kristian Høgsberg75840622011-09-06 13:48:16 -04001929static void
Daniel Stone37816df2012-05-16 18:45:18 +01001930click_to_activate_binding(struct wl_seat *seat,
Alex Wu4539b082012-03-01 12:57:46 +08001931 uint32_t time, uint32_t key,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001932 uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001933{
Daniel Stone37816df2012-05-16 18:45:18 +01001934 struct weston_seat *ws = (struct weston_seat *) seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03001935 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001936 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001937 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001938
Daniel Stone37816df2012-05-16 18:45:18 +01001939 focus = (struct weston_surface *) seat->pointer->focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08001940 if (!focus)
1941 return;
1942
Alex Wu21858432012-04-01 20:13:08 +08001943 if (is_black_surface(focus, &upper))
Alex Wu4539b082012-03-01 12:57:46 +08001944 focus = upper;
Alex Wu4539b082012-03-01 12:57:46 +08001945
Daniel Stone37816df2012-05-16 18:45:18 +01001946 if (state && seat->pointer->grab == &seat->pointer->default_grab)
1947 activate(shell, focus, ws);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001948}
1949
1950static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001951lock(struct wl_listener *listener, void *data)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001952{
Tiago Vignattibe143262012-04-16 17:31:41 +03001953 struct desktop_shell *shell =
1954 container_of(listener, struct desktop_shell, lock_listener);
Daniel Stone37816df2012-05-16 18:45:18 +01001955 struct weston_seat *seat;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001956 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001957 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001958
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001959 if (shell->locked) {
1960 wl_list_for_each(output, &shell->compositor->output_list, link)
1961 /* TODO: find a way to jump to other DPMS levels */
1962 if (output->set_dpms)
1963 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001964 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001965 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001966
1967 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001968
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001969 /* Hide all surfaces by removing the fullscreen, panel and
1970 * toplevel layers. This way nothing else can show or receive
1971 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001972
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001973 wl_list_remove(&shell->panel_layer.link);
1974 wl_list_remove(&shell->toplevel_layer.link);
1975 wl_list_remove(&shell->fullscreen_layer.link);
1976 wl_list_insert(&shell->compositor->cursor_layer.link,
1977 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001978
Pekka Paalanen77346a62011-11-30 16:26:35 +02001979 launch_screensaver(shell);
1980
1981 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1982 show_screensaver(shell, shsurf);
1983
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001984 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001985 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001986 weston_compositor_wake(shell->compositor);
1987 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001988 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001989
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001990 /* reset pointer foci */
Kristian Høgsbergaa6019e2012-03-11 16:35:16 -04001991 weston_compositor_schedule_repaint(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001992
1993 /* reset keyboard foci */
Daniel Stone37816df2012-05-16 18:45:18 +01001994 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1995 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001996 }
1997
1998 /* TODO: disable bindings that should not work while locked. */
1999
2000 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002001}
2002
2003static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002004unlock(struct wl_listener *listener, void *data)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002005{
Tiago Vignattibe143262012-04-16 17:31:41 +03002006 struct desktop_shell *shell =
2007 container_of(listener, struct desktop_shell, unlock_listener);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002008
Pekka Paalanend81c2162011-11-16 13:47:34 +02002009 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002010 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002011 return;
2012 }
2013
2014 /* If desktop-shell client has gone away, unlock immediately. */
2015 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002016 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002017 return;
2018 }
2019
2020 if (shell->prepare_event_sent)
2021 return;
2022
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05002023 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002024 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002025}
2026
2027static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002028center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02002029{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002030 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002031 GLfloat x = (mode->width - surface->geometry.width) / 2;
2032 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002033
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002034 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002035}
2036
2037static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002038map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002039 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002040{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002041 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002042 struct shell_surface *shsurf;
2043 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002044 struct weston_surface *parent;
Juan Zhao96879df2012-02-07 08:45:41 +08002045 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002046
Pekka Paalanen77346a62011-11-30 16:26:35 +02002047 shsurf = get_shell_surface(surface);
2048 if (shsurf)
2049 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002050
Pekka Paalanen60921e52012-01-25 15:55:43 +02002051 surface->geometry.width = width;
2052 surface->geometry.height = height;
2053 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002054
2055 /* initial positioning, see also configure() */
2056 switch (surface_type) {
2057 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002058 weston_surface_set_position(surface, 10 + random() % 400,
2059 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002060 break;
2061 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002062 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002063 break;
Alex Wu4539b082012-03-01 12:57:46 +08002064 case SHELL_SURFACE_FULLSCREEN:
2065 shell_map_fullscreen(shsurf);
2066 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002067 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002068 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08002069 panel_height = get_output_panel_height(shell,surface->output);
2070 weston_surface_set_position(surface, surface->output->x,
2071 surface->output->y + panel_height);
2072 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002073 case SHELL_SURFACE_LOCK:
2074 center_on_output(surface, get_default_output(compositor));
2075 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02002076 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002077 shell_map_popup(shsurf);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002078 case SHELL_SURFACE_NONE:
2079 weston_surface_set_position(surface,
2080 surface->geometry.x + sx,
2081 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02002082 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002083 default:
2084 ;
2085 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04002086
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002087 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002088 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002089 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002090 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002091 wl_list_insert(&shell->background_layer.surface_list,
2092 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002093 break;
2094 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002095 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002096 wl_list_insert(&shell->panel_layer.surface_list,
2097 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002098 break;
2099 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002100 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002101 wl_list_insert(&shell->lock_layer.surface_list,
2102 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002103 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002104 break;
2105 case SHELL_SURFACE_SCREENSAVER:
2106 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002107 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02002108 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02002109 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002110 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02002111 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002112 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002113 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002114 break;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002115 case SHELL_SURFACE_POPUP:
2116 case SHELL_SURFACE_TRANSIENT:
2117 parent = shsurf->parent->surface;
2118 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2119 break;
Alex Wu4539b082012-03-01 12:57:46 +08002120 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02002121 case SHELL_SURFACE_NONE:
2122 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002123 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002124 wl_list_insert(&shell->toplevel_layer.surface_list,
2125 &surface->layer_link);
2126 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002127 }
2128
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002129 if (surface_type != SHELL_SURFACE_NONE) {
2130 weston_surface_assign_output(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002131 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2132 surface->output = shsurf->output;
2133 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002134
Juan Zhao7bb92f02011-12-15 11:31:51 -05002135 switch (surface_type) {
Juan Zhao7bb92f02011-12-15 11:31:51 -05002136 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03002137 if (shsurf->transient.flags ==
2138 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2139 break;
2140 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05002141 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08002142 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05002143 if (!shell->locked)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002144 activate(shell, surface,
Daniel Stone37816df2012-05-16 18:45:18 +01002145 (struct weston_seat *) compositor->seat);
Juan Zhao7bb92f02011-12-15 11:31:51 -05002146 break;
2147 default:
2148 break;
2149 }
2150
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002151 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08002152 {
2153 switch (shell->win_animation_type) {
2154 case ANIMATION_FADE:
2155 weston_fade_run(surface, NULL, NULL);
2156 break;
2157 case ANIMATION_ZOOM:
2158 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2159 break;
2160 default:
2161 break;
2162 }
2163 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002164}
2165
2166static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002167configure(struct desktop_shell *shell, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02002168 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002169{
Pekka Paalanen77346a62011-11-30 16:26:35 +02002170 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2171 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002172
Pekka Paalanen77346a62011-11-30 16:26:35 +02002173 shsurf = get_shell_surface(surface);
2174 if (shsurf)
2175 surface_type = shsurf->type;
2176
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002177 surface->geometry.x = x;
2178 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02002179 surface->geometry.width = width;
2180 surface->geometry.height = height;
2181 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002182
2183 switch (surface_type) {
2184 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002185 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002186 break;
Alex Wu4539b082012-03-01 12:57:46 +08002187 case SHELL_SURFACE_FULLSCREEN:
Alex Wubd3354b2012-04-17 17:20:49 +08002188 shell_stack_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002189 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002190 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002191 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002192 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002193 surface->geometry.x = surface->output->x;
2194 surface->geometry.y = surface->output->y +
2195 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08002196 break;
Alex Wu4539b082012-03-01 12:57:46 +08002197 case SHELL_SURFACE_TOPLEVEL:
2198 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002199 default:
2200 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002201 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002202
Alex Wu4539b082012-03-01 12:57:46 +08002203 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002204 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02002205 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002206
2207 if (surface_type == SHELL_SURFACE_SCREENSAVER)
2208 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08002209 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
2210 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002211 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04002212}
2213
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002214static void
2215shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2216{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03002217 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03002218 struct desktop_shell *shell = shsurf->shell;
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03002219 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002220
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002221 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002222 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002223 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002224 type_changed = 1;
2225 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002226
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002227 if (!weston_surface_is_mapped(es)) {
2228 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002229 } else if (type_changed || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002230 es->geometry.width != es->buffer->width ||
2231 es->geometry.height != es->buffer->height) {
2232 GLfloat from_x, from_y;
2233 GLfloat to_x, to_y;
2234
2235 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2236 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2237 configure(shell, es,
2238 es->geometry.x + to_x - from_x,
2239 es->geometry.y + to_y - from_y,
2240 es->buffer->width, es->buffer->height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002241 }
2242}
2243
Tiago Vignattibe143262012-04-16 17:31:41 +03002244static int launch_desktop_shell_process(struct desktop_shell *shell);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002245
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002246static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002247desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002248{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002249 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03002250 struct desktop_shell *shell =
2251 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002252
2253 shell->child.process.pid = 0;
2254 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002255
2256 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2257 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002258 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002259 shell->child.deathstamp = time;
2260 shell->child.deathcount = 0;
2261 }
2262
2263 shell->child.deathcount++;
2264 if (shell->child.deathcount > 5) {
2265 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
2266 return;
2267 }
2268
2269 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
2270 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002271}
2272
2273static int
Tiago Vignattibe143262012-04-16 17:31:41 +03002274launch_desktop_shell_process(struct desktop_shell *shell)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002275{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05002276 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002277
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002278 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02002279 &shell->child.process,
2280 shell_exe,
2281 desktop_shell_sigchld);
2282
2283 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002284 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002285 return 0;
2286}
2287
2288static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002289bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2290{
Tiago Vignattibe143262012-04-16 17:31:41 +03002291 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002292
2293 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002294 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002295}
2296
Kristian Høgsberg75840622011-09-06 13:48:16 -04002297static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002298unbind_desktop_shell(struct wl_resource *resource)
2299{
Tiago Vignattibe143262012-04-16 17:31:41 +03002300 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002301
2302 if (shell->locked)
2303 resume_desktop(shell);
2304
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002305 shell->child.desktop_shell = NULL;
2306 shell->prepare_event_sent = false;
2307 free(resource);
2308}
2309
2310static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04002311bind_desktop_shell(struct wl_client *client,
2312 void *data, uint32_t version, uint32_t id)
2313{
Tiago Vignattibe143262012-04-16 17:31:41 +03002314 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002315 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002316
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002317 resource = wl_client_add_object(client, &desktop_shell_interface,
2318 &desktop_shell_implementation,
2319 id, shell);
2320
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002321 if (client == shell->child.client) {
2322 resource->destroy = unbind_desktop_shell;
2323 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002324 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002325 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002326
2327 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2328 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002329 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002330}
2331
Pekka Paalanen6e168112011-11-24 11:34:05 +02002332static void
2333screensaver_set_surface(struct wl_client *client,
2334 struct wl_resource *resource,
2335 struct wl_resource *shell_surface_resource,
2336 struct wl_resource *output_resource)
2337{
Tiago Vignattibe143262012-04-16 17:31:41 +03002338 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002339 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002340 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002341
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002342 surface->next_type = SHELL_SURFACE_SCREENSAVER;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002343
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002344 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002345 surface->output = output;
2346 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002347}
2348
2349static const struct screensaver_interface screensaver_implementation = {
2350 screensaver_set_surface
2351};
2352
2353static void
2354unbind_screensaver(struct wl_resource *resource)
2355{
Tiago Vignattibe143262012-04-16 17:31:41 +03002356 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002357
Pekka Paalanen77346a62011-11-30 16:26:35 +02002358 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002359 free(resource);
2360}
2361
2362static void
2363bind_screensaver(struct wl_client *client,
2364 void *data, uint32_t version, uint32_t id)
2365{
Tiago Vignattibe143262012-04-16 17:31:41 +03002366 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002367 struct wl_resource *resource;
2368
2369 resource = wl_client_add_object(client, &screensaver_interface,
2370 &screensaver_implementation,
2371 id, shell);
2372
Pekka Paalanen77346a62011-11-30 16:26:35 +02002373 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02002374 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002375 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002376 return;
2377 }
2378
2379 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2380 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002381 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002382}
2383
Kristian Høgsberg07045392012-02-19 18:52:44 -05002384struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03002385 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002386 struct weston_surface *current;
2387 struct wl_listener listener;
2388 struct wl_keyboard_grab grab;
2389};
2390
2391static void
2392switcher_next(struct switcher *switcher)
2393{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002394 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002395 struct weston_surface *surface;
2396 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002397 struct shell_surface *shsurf;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002398
2399 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002400 switch (get_shell_surface_type(surface)) {
2401 case SHELL_SURFACE_TOPLEVEL:
2402 case SHELL_SURFACE_FULLSCREEN:
2403 case SHELL_SURFACE_MAXIMIZED:
2404 if (first == NULL)
2405 first = surface;
2406 if (prev == switcher->current)
2407 next = surface;
2408 prev = surface;
Scott Moreau02709af2012-05-22 01:54:10 -06002409 surface->alpha = 0.25;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05002410 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002411 weston_surface_damage(surface);
2412 break;
2413 default:
2414 break;
2415 }
Alex Wu1659daa2012-04-01 20:13:09 +08002416
2417 if (is_black_surface(surface, NULL)) {
Scott Moreau02709af2012-05-22 01:54:10 -06002418 surface->alpha = 0.25;
Alex Wu1659daa2012-04-01 20:13:09 +08002419 surface->geometry.dirty = 1;
2420 weston_surface_damage(surface);
2421 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05002422 }
2423
2424 if (next == NULL)
2425 next = first;
2426
Alex Wu07b26062012-03-12 16:06:01 +08002427 if (next == NULL)
2428 return;
2429
Kristian Høgsberg07045392012-02-19 18:52:44 -05002430 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002431 wl_signal_add(&next->surface.resource.destroy_signal,
2432 &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002433
2434 switcher->current = next;
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002435 next->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08002436
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002437 shsurf = get_shell_surface(switcher->current);
2438 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002439 shsurf->fullscreen.black_surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002440}
2441
2442static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002443switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002444{
2445 struct switcher *switcher =
2446 container_of(listener, struct switcher, listener);
2447
2448 switcher_next(switcher);
2449}
2450
2451static void
2452switcher_destroy(struct switcher *switcher, uint32_t time)
2453{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002454 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002455 struct weston_surface *surface;
Daniel Stone37816df2012-05-16 18:45:18 +01002456 struct wl_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002457
2458 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002459 surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002460 weston_surface_damage(surface);
2461 }
2462
Alex Wu07b26062012-03-12 16:06:01 +08002463 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01002464 activate(switcher->shell, switcher->current,
2465 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002466 wl_list_remove(&switcher->listener.link);
Daniel Stone37816df2012-05-16 18:45:18 +01002467 wl_keyboard_end_grab(keyboard);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002468 free(switcher);
2469}
2470
2471static void
2472switcher_key(struct wl_keyboard_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01002473 uint32_t time, uint32_t key, uint32_t state)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002474{
2475 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01002476 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002477
Daniel Stone37816df2012-05-16 18:45:18 +01002478 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002479 switcher_destroy(switcher, time);
2480 } else if (key == KEY_TAB && state) {
2481 switcher_next(switcher);
2482 }
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04002483}
Kristian Høgsberg07045392012-02-19 18:52:44 -05002484
2485static const struct wl_keyboard_grab_interface switcher_grab = {
2486 switcher_key
2487};
2488
2489static void
Daniel Stone37816df2012-05-16 18:45:18 +01002490switcher_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002491 uint32_t key, uint32_t button, uint32_t axis,
Daniel Stonee5a01202012-05-04 11:21:57 +01002492 int32_t value, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002493{
Tiago Vignattibe143262012-04-16 17:31:41 +03002494 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002495 struct switcher *switcher;
2496
2497 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002498 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002499 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002500 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002501 wl_list_init(&switcher->listener.link);
2502
2503 switcher->grab.interface = &switcher_grab;
Daniel Stone37816df2012-05-16 18:45:18 +01002504 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
2505 wl_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002506 switcher_next(switcher);
2507}
2508
Pekka Paalanen3c647232011-12-22 13:43:43 +02002509static void
Daniel Stone37816df2012-05-16 18:45:18 +01002510backlight_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002511 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002512{
2513 struct weston_compositor *compositor = data;
2514 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002515 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002516
2517 /* TODO: we're limiting to simple use cases, where we assume just
2518 * control on the primary display. We'd have to extend later if we
2519 * ever get support for setting backlights on random desktop LCD
2520 * panels though */
2521 output = get_default_output(compositor);
2522 if (!output)
2523 return;
2524
2525 if (!output->set_backlight)
2526 return;
2527
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002528 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2529 backlight_new = output->backlight_current - 25;
2530 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2531 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002532
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002533 if (backlight_new < 5)
2534 backlight_new = 5;
2535 if (backlight_new > 255)
2536 backlight_new = 255;
2537
2538 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002539 output->set_backlight(output, output->backlight_current);
2540}
2541
2542static void
Daniel Stone37816df2012-05-16 18:45:18 +01002543debug_repaint_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01002544 uint32_t key, uint32_t button, uint32_t axis,
2545 int32_t value, void *data)
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002546{
Tiago Vignattibe143262012-04-16 17:31:41 +03002547 struct desktop_shell *shell = data;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002548 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002549 struct weston_surface *surface;
2550
2551 if (shell->debug_repaint_surface) {
2552 weston_surface_destroy(shell->debug_repaint_surface);
2553 shell->debug_repaint_surface = NULL;
2554 } else {
2555 surface = weston_surface_create(compositor);
2556 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2557 weston_surface_configure(surface, 0, 0, 8192, 8192);
2558 wl_list_insert(&compositor->fade_layer.surface_list,
2559 &surface->layer_link);
2560 weston_surface_assign_output(surface);
2561 pixman_region32_init(&surface->input);
2562
2563 /* Here's the dirty little trick that makes the
2564 * repaint debugging work: we force an
2565 * update_transform first to update dependent state
2566 * and clear the geometry.dirty bit. Then we clear
2567 * the surface damage so it only gets repainted
2568 * piecewise as we repaint other things. */
2569
2570 weston_surface_update_transform(surface);
2571 pixman_region32_fini(&surface->damage);
2572 pixman_region32_init(&surface->damage);
2573 shell->debug_repaint_surface = surface;
2574 }
2575}
2576
2577static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002578shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02002579{
Tiago Vignattibe143262012-04-16 17:31:41 +03002580 struct desktop_shell *shell =
2581 container_of(listener, struct desktop_shell, destroy_listener);
Pekka Paalanen3c647232011-12-22 13:43:43 +02002582
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02002583 if (shell->child.client)
2584 wl_client_destroy(shell->child.client);
2585
Kristian Høgsberg88c16072012-05-16 08:04:19 -04002586 wl_list_remove(&shell->lock_listener.link);
2587 wl_list_remove(&shell->unlock_listener.link);
2588
Pekka Paalanen3c647232011-12-22 13:43:43 +02002589 free(shell->screensaver.path);
2590 free(shell);
2591}
2592
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002593static void
2594shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
2595{
2596 uint32_t mod;
2597
2598 /* fixed bindings */
2599 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
2600 MODIFIER_CTRL | MODIFIER_ALT,
2601 terminate_binding, ec);
2602 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
2603 click_to_activate_binding, shell);
2604 weston_compositor_add_binding(ec, 0, 0,
Daniel Stone37816df2012-05-16 18:45:18 +01002605 WL_POINTER_AXIS_VERTICAL_SCROLL,
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002606 MODIFIER_SUPER | MODIFIER_ALT,
2607 surface_opacity_binding, NULL);
2608 weston_compositor_add_binding(ec, 0, 0,
Daniel Stone37816df2012-05-16 18:45:18 +01002609 WL_POINTER_AXIS_VERTICAL_SCROLL,
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002610 MODIFIER_SUPER, zoom_binding, NULL);
2611
2612 /* configurable bindings */
2613 mod = shell->binding_modifier;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002614 weston_compositor_add_binding(ec, KEY_PAGEUP, 0, 0, mod,
2615 zoom_binding, NULL);
2616 weston_compositor_add_binding(ec, KEY_PAGEDOWN, 0, 0, mod,
2617 zoom_binding, NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002618 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod,
2619 move_binding, shell);
2620 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod,
2621 resize_binding, shell);
2622 weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod,
2623 rotate_binding, NULL);
2624 weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod,
2625 switcher_binding, shell);
2626 weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod,
2627 backlight_binding, ec);
2628 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
2629 backlight_binding, ec);
2630 weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod,
2631 backlight_binding, ec);
2632 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
2633 backlight_binding, ec);
2634 weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod,
2635 debug_repaint_binding, shell);
2636}
2637
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002638int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002639shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002640
Kristian Høgsberg1c562182011-05-02 22:09:20 -04002641WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002642shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002643{
Tiago Vignattibe143262012-04-16 17:31:41 +03002644 struct desktop_shell *shell;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002645
2646 shell = malloc(sizeof *shell);
2647 if (shell == NULL)
2648 return -1;
2649
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04002650 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002651 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002652
2653 shell->destroy_listener.notify = shell_destroy;
2654 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2655 shell->lock_listener.notify = lock;
2656 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2657 shell->unlock_listener.notify = unlock;
2658 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06002659 ec->ping_handler = ping_handler;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002660 ec->shell_interface.create_shell_surface = create_shell_surface;
2661 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04002662 ec->shell_interface.set_transient = set_transient;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002663 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04002664 ec->shell_interface.resize = surface_resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002665
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002666 wl_list_init(&shell->backgrounds);
2667 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002668 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002669
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002670 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2671 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2672 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2673 weston_layer_init(&shell->background_layer,
2674 &shell->toplevel_layer.link);
2675 wl_list_init(&shell->lock_layer.surface_list);
2676
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002677 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002678
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002679 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2680 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002681 return -1;
2682
Kristian Høgsberg75840622011-09-06 13:48:16 -04002683 if (wl_display_add_global(ec->wl_display,
2684 &desktop_shell_interface,
2685 shell, bind_desktop_shell) == NULL)
2686 return -1;
2687
Pekka Paalanen6e168112011-11-24 11:34:05 +02002688 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2689 shell, bind_screensaver) == NULL)
2690 return -1;
2691
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002692 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002693 if (launch_desktop_shell_process(shell) != 0)
2694 return -1;
2695
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002696 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002697
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002698 return 0;
2699}