blob: e1f3a04968f8e33a1e64f09d47810b55ed574500 [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øgsberg92a57db2012-05-26 13:41:06 -040033#include <sys/types.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050034
Pekka Paalanen50719bc2011-11-22 14:18:50 +020035#include <wayland-server.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050036#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040037#include "desktop-shell-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020038#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050039
Juan Zhaoe10d2792012-04-25 19:09:52 +080040enum animation_type {
41 ANIMATION_NONE,
42
43 ANIMATION_ZOOM,
44 ANIMATION_FADE
45};
46
Tiago Vignattibe143262012-04-16 17:31:41 +030047struct desktop_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050048 struct weston_compositor *compositor;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -040049
50 struct wl_listener lock_listener;
51 struct wl_listener unlock_listener;
52 struct wl_listener destroy_listener;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020053
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050054 struct weston_layer fullscreen_layer;
55 struct weston_layer panel_layer;
56 struct weston_layer toplevel_layer;
57 struct weston_layer background_layer;
58 struct weston_layer lock_layer;
59
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020060 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050061 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020062 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020063 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +020064
65 unsigned deathcount;
66 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020067 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020068
69 bool locked;
70 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020071
Pekka Paalanen068ae942011-11-28 14:11:15 +020072 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050073 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010074
75 struct wl_list backgrounds;
76 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020077
Pekka Paalanen77346a62011-11-30 16:26:35 +020078 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +020079 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020080 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020081 struct wl_resource *binding;
82 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050083 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020084 } screensaver;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -050085
Tiago Vignatti0b52d482012-04-20 18:54:25 +030086 uint32_t binding_modifier;
Juan Zhaoe10d2792012-04-25 19:09:52 +080087 enum animation_type win_animation_type;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -050088 struct weston_surface *debug_repaint_surface;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040089};
90
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050091enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020092 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050093
Pekka Paalanen57da4a82011-11-23 16:42:16 +020094 SHELL_SURFACE_PANEL,
95 SHELL_SURFACE_BACKGROUND,
96 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020097 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050098
99 SHELL_SURFACE_TOPLEVEL,
100 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500101 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +0800102 SHELL_SURFACE_MAXIMIZED,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500103 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200104};
105
Scott Moreauff1db4a2012-04-17 19:06:18 -0600106struct ping_timer {
107 struct wl_event_source *source;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600108 uint32_t serial;
109};
110
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200111struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200112 struct wl_resource resource;
113
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500114 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200115 struct wl_listener surface_destroy_listener;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500116 struct shell_surface *parent;
Tiago Vignattibe143262012-04-16 17:31:41 +0300117 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200118
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400119 enum shell_surface_type type, next_type;
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400120 char *title, *class;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500121 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800122 bool saved_position_valid;
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800123 bool saved_rotation_valid;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600124 int unresponsive;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100125
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500126 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200127 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500128 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200129 } rotation;
130
131 struct {
Scott Moreau447013d2012-02-18 05:05:29 -0700132 struct wl_pointer_grab grab;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500133 int32_t x, y;
Pekka Paalanen938269a2012-02-07 14:19:01 +0200134 struct weston_transform parent_transform;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500135 int32_t initial_up;
Daniel Stone37816df2012-05-16 18:45:18 +0100136 struct wl_seat *seat;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400137 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500138 } popup;
139
Alex Wu4539b082012-03-01 12:57:46 +0800140 struct {
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300141 int32_t x, y;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400142 uint32_t flags;
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300143 } transient;
144
145 struct {
Alex Wu4539b082012-03-01 12:57:46 +0800146 enum wl_shell_surface_fullscreen_method type;
147 struct weston_transform transform; /* matrix from x, y */
148 uint32_t framerate;
149 struct weston_surface *black_surface;
150 } fullscreen;
151
Scott Moreauff1db4a2012-04-17 19:06:18 -0600152 struct ping_timer *ping_timer;
153
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600154 struct {
155 struct weston_animation current;
156 int exists;
157 int fading_in;
158 uint32_t timestamp;
159 } unresponsive_animation;
160
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500161 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500162 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100163 struct wl_list link;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400164
165 const struct weston_shell_client *client;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200166};
167
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300168struct shell_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700169 struct wl_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300170 struct shell_surface *shsurf;
171 struct wl_listener shsurf_destroy_listener;
172};
173
174struct weston_move_grab {
175 struct shell_grab base;
Daniel Stone103db7f2012-05-08 17:17:55 +0100176 wl_fixed_t dx, dy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500177};
178
Pekka Paalanen460099f2012-01-20 16:48:25 +0200179struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300180 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500181 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200182 struct {
183 int32_t x;
184 int32_t y;
185 } center;
186};
187
Alex Wubd3354b2012-04-17 17:20:49 +0800188static struct shell_surface *
189get_shell_surface(struct weston_surface *surface);
190
191static struct desktop_shell *
192shell_surface_get_shell(struct shell_surface *shsurf);
193
194static bool
195shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
196{
197 struct desktop_shell *shell;
198 struct weston_surface *top_fs_es;
199
200 shell = shell_surface_get_shell(shsurf);
201
202 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
203 return false;
204
205 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
206 struct weston_surface,
207 layer_link);
208 return (shsurf == get_shell_surface(top_fs_es));
209}
210
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500211static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400212destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300213{
214 struct shell_grab *grab;
215
216 grab = container_of(listener, struct shell_grab,
217 shsurf_destroy_listener);
218
219 grab->shsurf = NULL;
220}
221
222static void
223shell_grab_init(struct shell_grab *grab,
224 const struct wl_pointer_grab_interface *interface,
225 struct shell_surface *shsurf)
226{
227 grab->grab.interface = interface;
228 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400229 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
230 wl_signal_add(&shsurf->resource.destroy_signal,
231 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300232
233}
234
235static void
236shell_grab_finish(struct shell_grab *grab)
237{
238 wl_list_remove(&grab->shsurf_destroy_listener.link);
239}
240
241static void
Alex Wu4539b082012-03-01 12:57:46 +0800242center_on_output(struct weston_surface *surface,
243 struct weston_output *output);
244
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300245static uint32_t
246get_modifier(char *modifier)
247{
248 if (!modifier)
249 return MODIFIER_SUPER;
250
251 if (!strcmp("ctrl", modifier))
252 return MODIFIER_CTRL;
253 else if (!strcmp("alt", modifier))
254 return MODIFIER_ALT;
255 else if (!strcmp("super", modifier))
256 return MODIFIER_SUPER;
257 else
258 return MODIFIER_SUPER;
259}
260
Juan Zhaoe10d2792012-04-25 19:09:52 +0800261static enum animation_type
262get_animation_type(char *animation)
263{
264 if (!animation)
265 return ANIMATION_NONE;
266
267 if (!strcmp("zoom", animation))
268 return ANIMATION_ZOOM;
269 else if (!strcmp("fade", animation))
270 return ANIMATION_FADE;
271 else
272 return ANIMATION_NONE;
273}
274
Alex Wu4539b082012-03-01 12:57:46 +0800275static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300276shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200277{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200278 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200279 char *path = NULL;
280 int duration = 60;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300281 char *modifier = NULL;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800282 char *win_animation = NULL;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200283
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400284 struct config_key shell_keys[] = {
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300285 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
Juan Zhaoe10d2792012-04-25 19:09:52 +0800286 { "animation", CONFIG_KEY_STRING, &win_animation},
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200287 };
288
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400289 struct config_key saver_keys[] = {
290 { "path", CONFIG_KEY_STRING, &path },
291 { "duration", CONFIG_KEY_INTEGER, &duration },
292 };
293
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200294 struct config_section cs[] = {
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400295 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200296 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
297 };
298
Tiago Vignatti9a206c42012-03-21 19:49:18 +0200299 config_file = config_file_path("weston.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500300 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200301 free(config_file);
302
Pekka Paalanen7296e792011-12-07 16:22:00 +0200303 shell->screensaver.path = path;
304 shell->screensaver.duration = duration;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300305 shell->binding_modifier = get_modifier(modifier);
Juan Zhaoe10d2792012-04-25 19:09:52 +0800306 shell->win_animation_type = get_animation_type(win_animation);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200307}
308
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200309static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400310noop_grab_focus(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100311 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500312{
313 grab->focus = NULL;
314}
315
316static void
Scott Moreau447013d2012-02-18 05:05:29 -0700317move_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100318 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500319{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500320 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100321 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300322 struct shell_surface *shsurf = move->base.shsurf;
323 struct weston_surface *es;
Daniel Stone37816df2012-05-16 18:45:18 +0100324 int dx = wl_fixed_to_int(pointer->x + move->dx);
325 int dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300326
327 if (!shsurf)
328 return;
329
330 es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500331
Daniel Stone103db7f2012-05-08 17:17:55 +0100332 weston_surface_configure(es, dx, dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200333 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500334}
335
336static void
Scott Moreau447013d2012-02-18 05:05:29 -0700337move_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +0100338 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500339{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300340 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
341 grab);
Daniel Stone37816df2012-05-16 18:45:18 +0100342 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500343
Daniel Stone37816df2012-05-16 18:45:18 +0100344 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300345 shell_grab_finish(shell_grab);
Daniel Stone37816df2012-05-16 18:45:18 +0100346 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500347 free(grab);
348 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500349}
350
Scott Moreau447013d2012-02-18 05:05:29 -0700351static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500352 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500353 move_grab_motion,
354 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500355};
356
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600357static void
358unresponsive_surface_fade(struct shell_surface *shsurf, bool reverse)
359{
360 shsurf->unresponsive_animation.fading_in = reverse ? 0 : 1;
361
362 if(!shsurf->unresponsive_animation.exists) {
363 wl_list_insert(&shsurf->surface->compositor->animation_list,
364 &shsurf->unresponsive_animation.current.link);
365 shsurf->unresponsive_animation.exists = 1;
366 shsurf->unresponsive_animation.timestamp = weston_compositor_get_time();
367 weston_surface_damage(shsurf->surface);
368 }
369}
370
371static void
Scott Moreau9521d5e2012-04-19 13:06:17 -0600372unresponsive_fade_frame(struct weston_animation *animation,
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600373 struct weston_output *output, uint32_t msecs)
374{
375 struct shell_surface *shsurf =
376 container_of(animation, struct shell_surface, unresponsive_animation.current);
377 struct weston_surface *surface = shsurf->surface;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600378 unsigned int step = 8;
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600379
380 if (!surface || !shsurf)
381 return;
382
383 if (shsurf->unresponsive_animation.fading_in) {
384 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
385 if (surface->saturation > 1)
386 surface->saturation -= 5;
387 if (surface->brightness > 200)
388 surface->brightness--;
389
390 shsurf->unresponsive_animation.timestamp += step;
391 }
392
393 if (surface->saturation <= 1 && surface->brightness <= 200) {
394 wl_list_remove(&shsurf->unresponsive_animation.current.link);
395 shsurf->unresponsive_animation.exists = 0;
396 }
397 }
398 else {
399 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
400 if (surface->saturation < 255)
401 surface->saturation += 5;
402 if (surface->brightness < 255)
403 surface->brightness++;
404
405 shsurf->unresponsive_animation.timestamp += step;
406 }
407
408 if (surface->saturation >= 255 && surface->brightness >= 255) {
409 surface->saturation = surface->brightness = 255;
410 wl_list_remove(&shsurf->unresponsive_animation.current.link);
411 shsurf->unresponsive_animation.exists = 0;
412 }
413 }
414
415 surface->geometry.dirty = 1;
416 weston_surface_damage(surface);
417}
418
Scott Moreau9521d5e2012-04-19 13:06:17 -0600419static void
420ping_timer_destroy(struct shell_surface *shsurf)
421{
422 if (!shsurf || !shsurf->ping_timer)
423 return;
424
425 if (shsurf->ping_timer->source)
426 wl_event_source_remove(shsurf->ping_timer->source);
427
428 free(shsurf->ping_timer);
429 shsurf->ping_timer = NULL;
430}
431
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400432static int
Scott Moreauff1db4a2012-04-17 19:06:18 -0600433ping_timeout_handler(void *data)
434{
435 struct shell_surface *shsurf = data;
436
Scott Moreau9521d5e2012-04-19 13:06:17 -0600437 /* Client is not responding */
438 shsurf->unresponsive = 1;
439 unresponsive_surface_fade(shsurf, false);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600440
441 return 1;
442}
443
444static void
445ping_handler(struct weston_surface *surface, uint32_t serial)
446{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -0400447 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600448 struct wl_event_loop *loop;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600449 int ping_timeout = 2500;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600450
451 if (!shsurf)
452 return;
Kristian Høgsbergca535c12012-04-21 23:20:07 -0400453 if (!shsurf->resource.client)
454 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600455
456 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +0300457 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600458 if (!shsurf->ping_timer)
459 return;
460
461 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600462 loop = wl_display_get_event_loop(surface->compositor->wl_display);
463 shsurf->ping_timer->source =
464 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
465 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
466
467 wl_shell_surface_send_ping(&shsurf->resource, serial);
468 }
469}
470
471static void
472shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
473 uint32_t serial)
474{
475 struct shell_surface *shsurf = resource->data;
476
Scott Moreauff1db4a2012-04-17 19:06:18 -0600477 if (shsurf->ping_timer->serial == serial) {
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600478 if (shsurf->unresponsive) {
479 /* Received pong from previously unresponsive client */
480 unresponsive_surface_fade(shsurf, true);
481 }
Scott Moreauff1db4a2012-04-17 19:06:18 -0600482 shsurf->unresponsive = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600483 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600484 }
485}
486
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400487static void
488shell_surface_set_title(struct wl_client *client,
489 struct wl_resource *resource, const char *title)
490{
491 struct shell_surface *shsurf = resource->data;
492
493 free(shsurf->title);
494 shsurf->title = strdup(title);
495}
496
497static void
498shell_surface_set_class(struct wl_client *client,
499 struct wl_resource *resource, const char *class)
500{
501 struct shell_surface *shsurf = resource->data;
502
503 free(shsurf->class);
504 shsurf->class = strdup(class);
505}
506
Scott Moreauff1db4a2012-04-17 19:06:18 -0600507static int
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400508surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500509{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500510 struct weston_move_grab *move;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300511
512 if (!shsurf)
513 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500514
515 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400516 if (!move)
517 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500518
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300519 shell_grab_init(&move->base, &move_grab_interface, shsurf);
520
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400521 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
Daniel Stone37816df2012-05-16 18:45:18 +0100522 ws->seat.pointer->grab_x;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400523 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
Daniel Stone37816df2012-05-16 18:45:18 +0100524 ws->seat.pointer->grab_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500525
Daniel Stone37816df2012-05-16 18:45:18 +0100526 wl_pointer_start_grab(ws->seat.pointer, &move->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500527
Daniel Stone37816df2012-05-16 18:45:18 +0100528 wl_pointer_set_focus(ws->seat.pointer, NULL,
529 wl_fixed_from_int(0),
530 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400531
532 return 0;
533}
534
535static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200536shell_surface_move(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100537 struct wl_resource *seat_resource, uint32_t serial)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400538{
Daniel Stone37816df2012-05-16 18:45:18 +0100539 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200540 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400541
Daniel Stone37816df2012-05-16 18:45:18 +0100542 if (ws->seat.pointer->button_count == 0 ||
543 ws->seat.pointer->grab_serial != serial ||
544 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500545 return;
546
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400547 if (surface_move(shsurf, ws) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400548 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500549}
550
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500551struct weston_resize_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300552 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500553 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200554 int32_t width, height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500555};
556
557static void
Scott Moreau447013d2012-02-18 05:05:29 -0700558resize_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100559 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500560{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500561 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100562 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400563 struct shell_surface *shsurf = resize->base.shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500564 int32_t width, height;
Daniel Stone103db7f2012-05-08 17:17:55 +0100565 wl_fixed_t from_x, from_y;
566 wl_fixed_t to_x, to_y;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200567
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400568 if (!shsurf)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300569 return;
570
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400571 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100572 pointer->grab_x, pointer->grab_y,
Daniel Stone103db7f2012-05-08 17:17:55 +0100573 &from_x, &from_y);
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400574 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100575 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500576
Daniel Stone103db7f2012-05-08 17:17:55 +0100577 width = resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200578 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100579 width += wl_fixed_to_int(from_x - to_x);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200580 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100581 width += wl_fixed_to_int(to_x - from_x);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500582 }
583
Daniel Stone103db7f2012-05-08 17:17:55 +0100584 height = resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200585 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100586 height += wl_fixed_to_int(from_y - to_y);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200587 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100588 height += wl_fixed_to_int(to_y - from_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500589 }
590
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400591 shsurf->client->send_configure(shsurf->surface,
592 resize->edges, width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500593}
594
595static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400596send_configure(struct weston_surface *surface,
597 uint32_t edges, int32_t width, int32_t height)
598{
599 struct shell_surface *shsurf = get_shell_surface(surface);
600
601 wl_shell_surface_send_configure(&shsurf->resource,
602 edges, width, height);
603}
604
605static const struct weston_shell_client shell_client = {
606 send_configure
607};
608
609static void
Scott Moreau447013d2012-02-18 05:05:29 -0700610resize_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +0100611 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500612{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300613 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100614 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500615
Daniel Stone37816df2012-05-16 18:45:18 +0100616 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300617 shell_grab_finish(&resize->base);
Daniel Stone37816df2012-05-16 18:45:18 +0100618 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500619 free(grab);
620 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500621}
622
Scott Moreau447013d2012-02-18 05:05:29 -0700623static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500624 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500625 resize_grab_motion,
626 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500627};
628
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400629static int
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400630surface_resize(struct shell_surface *shsurf,
631 struct weston_seat *ws, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500632{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500633 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500634
Alex Wu4539b082012-03-01 12:57:46 +0800635 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
636 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500637
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200638 if (edges == 0 || edges > 15 ||
639 (edges & 3) == 3 || (edges & 12) == 12)
640 return 0;
641
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500642 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400643 if (!resize)
644 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500645
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300646 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
647
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500648 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200649 resize->width = shsurf->surface->geometry.width;
650 resize->height = shsurf->surface->geometry.height;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400651
Daniel Stone37816df2012-05-16 18:45:18 +0100652 wl_pointer_start_grab(ws->seat.pointer, &resize->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500653
Daniel Stone37816df2012-05-16 18:45:18 +0100654 wl_pointer_set_focus(ws->seat.pointer, NULL,
655 wl_fixed_from_int(0),
656 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400657
658 return 0;
659}
660
661static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200662shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100663 struct wl_resource *seat_resource, uint32_t serial,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200664 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400665{
Daniel Stone37816df2012-05-16 18:45:18 +0100666 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200667 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400668
Alex Wu4539b082012-03-01 12:57:46 +0800669 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
670 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400671
Daniel Stone37816df2012-05-16 18:45:18 +0100672 if (ws->seat.pointer->button_count == 0 ||
673 ws->seat.pointer->grab_serial != serial ||
674 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500675 return;
676
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400677 if (surface_resize(shsurf, ws, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400678 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500679}
680
Juan Zhao96879df2012-02-07 08:45:41 +0800681static struct weston_output *
682get_default_output(struct weston_compositor *compositor)
683{
684 return container_of(compositor->output_list.next,
685 struct weston_output, link);
686}
687
Alex Wu4539b082012-03-01 12:57:46 +0800688static void
689shell_unset_fullscreen(struct shell_surface *shsurf)
690{
691 /* undo all fullscreen things here */
Alex Wubd3354b2012-04-17 17:20:49 +0800692 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
693 shell_surface_is_top_fullscreen(shsurf)) {
694 weston_output_switch_mode(shsurf->fullscreen_output,
695 shsurf->fullscreen_output->origin);
696 }
Alex Wu4539b082012-03-01 12:57:46 +0800697 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
698 shsurf->fullscreen.framerate = 0;
699 wl_list_remove(&shsurf->fullscreen.transform.link);
700 wl_list_init(&shsurf->fullscreen.transform.link);
Alex Wubd3354b2012-04-17 17:20:49 +0800701 if (shsurf->fullscreen.black_surface)
702 weston_surface_destroy(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800703 shsurf->fullscreen.black_surface = NULL;
704 shsurf->fullscreen_output = NULL;
Alex Wu4539b082012-03-01 12:57:46 +0800705 weston_surface_set_position(shsurf->surface,
706 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800707 if (shsurf->saved_rotation_valid) {
708 wl_list_insert(&shsurf->surface->geometry.transformation_list,
709 &shsurf->rotation.transform.link);
710 shsurf->saved_rotation_valid = false;
711 }
Alex Wu4539b082012-03-01 12:57:46 +0800712}
713
Pekka Paalanen98262232011-12-01 10:42:22 +0200714static int
715reset_shell_surface_type(struct shell_surface *surface)
716{
717 switch (surface->type) {
718 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800719 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200720 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800721 case SHELL_SURFACE_MAXIMIZED:
722 surface->output = get_default_output(surface->surface->compositor);
723 weston_surface_set_position(surface->surface,
724 surface->saved_x,
725 surface->saved_y);
726 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200727 case SHELL_SURFACE_PANEL:
728 case SHELL_SURFACE_BACKGROUND:
729 wl_list_remove(&surface->link);
730 wl_list_init(&surface->link);
731 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200732 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200733 case SHELL_SURFACE_LOCK:
734 wl_resource_post_error(&surface->resource,
735 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200736 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200737 return -1;
738 case SHELL_SURFACE_NONE:
739 case SHELL_SURFACE_TOPLEVEL:
740 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500741 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200742 break;
743 }
744
745 surface->type = SHELL_SURFACE_NONE;
746 return 0;
747}
748
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500749static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400750set_surface_type(struct shell_surface *shsurf)
751{
752 struct weston_surface *surface = shsurf->surface;
753 struct shell_surface *pshsurf = shsurf->parent;
754 struct weston_surface *pes;
755 struct shell_surface *priv;
756 struct desktop_shell *shell = shsurf->shell;
757
758 reset_shell_surface_type(shsurf);
759
760 shsurf->type = shsurf->next_type;
761 shsurf->next_type = SHELL_SURFACE_NONE;
762
763 switch (shsurf->type) {
764 case SHELL_SURFACE_TOPLEVEL:
765 break;
766 case SHELL_SURFACE_TRANSIENT:
767 pes = pshsurf->surface;
768 weston_surface_set_position(surface,
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300769 pes->geometry.x + shsurf->transient.x,
770 pes->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400771 break;
772
773 case SHELL_SURFACE_MAXIMIZED:
774 shsurf->saved_x = surface->geometry.x;
775 shsurf->saved_y = surface->geometry.y;
776 shsurf->saved_position_valid = true;
777 break;
778
779 case SHELL_SURFACE_FULLSCREEN:
780 shsurf->saved_x = surface->geometry.x;
781 shsurf->saved_y = surface->geometry.y;
782 shsurf->saved_position_valid = true;
783
784 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
785 wl_list_remove(&shsurf->rotation.transform.link);
786 wl_list_init(&shsurf->rotation.transform.link);
787 shsurf->surface->geometry.dirty = 1;
788 shsurf->saved_rotation_valid = true;
789 }
790 break;
791
792 case SHELL_SURFACE_BACKGROUND:
793 wl_list_for_each(priv, &shell->backgrounds, link) {
794 if (priv->output == shsurf->output) {
795 priv->surface->output = NULL;
796 wl_list_remove(&priv->surface->layer_link);
797 wl_list_remove(&priv->link);
798 break;
799 }
800 }
801
802 wl_list_insert(&shell->backgrounds, &shsurf->link);
803
804 weston_surface_set_position(surface, shsurf->output->x,
805 shsurf->output->y);
806 break;
807
808 case SHELL_SURFACE_PANEL:
809 wl_list_for_each(priv, &shell->panels, link) {
810 if (priv->output == shsurf->output) {
811 priv->surface->output = NULL;
812 wl_list_remove(&priv->surface->layer_link);
813 wl_list_remove(&priv->link);
814 break;
815 }
816 }
817
818 wl_list_insert(&shell->panels, &shsurf->link);
819
820 weston_surface_set_position(surface, shsurf->output->x,
821 shsurf->output->y);
822 break;
823
824 default:
825 break;
826 }
827}
828
829static void
Tiago Vignattibc052c92012-04-19 16:18:18 +0300830set_toplevel(struct shell_surface *shsurf)
831{
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400832 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Tiago Vignattibc052c92012-04-19 16:18:18 +0300833}
834
835static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200836shell_surface_set_toplevel(struct wl_client *client,
837 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400838{
Pekka Paalanen98262232011-12-01 10:42:22 +0200839 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400840
Tiago Vignattibc052c92012-04-19 16:18:18 +0300841 set_toplevel(surface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400842}
843
844static void
Tiago Vignatti491bac12012-05-18 16:37:43 -0400845set_transient(struct shell_surface *shsurf,
846 struct shell_surface *pshsurf, int x, int y, uint32_t flags)
847{
848 /* assign to parents output */
849 shsurf->parent = pshsurf;
850 shsurf->transient.x = x;
851 shsurf->transient.y = y;
852 shsurf->transient.flags = flags;
853 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
854}
855
856static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200857shell_surface_set_transient(struct wl_client *client,
858 struct wl_resource *resource,
859 struct wl_resource *parent_resource,
860 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400861{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200862 struct shell_surface *shsurf = resource->data;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400863 struct shell_surface *pshsurf = parent_resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200864
Tiago Vignatti491bac12012-05-18 16:37:43 -0400865 set_transient(shsurf, pshsurf, x, y, flags);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400866}
867
Tiago Vignattibe143262012-04-16 17:31:41 +0300868static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +0800869shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200870{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400871 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +0800872}
873
874static int
Tiago Vignattibe143262012-04-16 17:31:41 +0300875get_output_panel_height(struct desktop_shell *shell,
876 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +0800877{
878 struct shell_surface *priv;
879 int panel_height = 0;
880
881 if (!output)
882 return 0;
883
Tiago Vignattibe143262012-04-16 17:31:41 +0300884 wl_list_for_each(priv, &shell->panels, link) {
Juan Zhao96879df2012-02-07 08:45:41 +0800885 if (priv->output == output) {
886 panel_height = priv->surface->geometry.height;
887 break;
888 }
889 }
890 return panel_height;
891}
892
893static void
894shell_surface_set_maximized(struct wl_client *client,
895 struct wl_resource *resource,
896 struct wl_resource *output_resource )
897{
898 struct shell_surface *shsurf = resource->data;
899 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300900 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +0800901 uint32_t edges = 0, panel_height = 0;
902
903 /* get the default output, if the client set it as NULL
904 check whether the ouput is available */
905 if (output_resource)
906 shsurf->output = output_resource->data;
907 else
908 shsurf->output = get_default_output(es->compositor);
909
Tiago Vignattibe143262012-04-16 17:31:41 +0300910 shell = shell_surface_get_shell(shsurf);
911 panel_height = get_output_panel_height(shell, es->output);
Juan Zhao96879df2012-02-07 08:45:41 +0800912 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500913
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400914 shsurf->client->send_configure(shsurf->surface, edges,
915 es->output->current->width,
916 es->output->current->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +0800917
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400918 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200919}
920
Alex Wu21858432012-04-01 20:13:08 +0800921static void
922black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
923
Alex Wu4539b082012-03-01 12:57:46 +0800924static struct weston_surface *
925create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +0800926 struct weston_surface *fs_surface,
Alex Wu4539b082012-03-01 12:57:46 +0800927 GLfloat x, GLfloat y, int w, int h)
928{
929 struct weston_surface *surface = NULL;
930
931 surface = weston_surface_create(ec);
932 if (surface == NULL) {
933 fprintf(stderr, "no memory\n");
934 return NULL;
935 }
936
Alex Wu21858432012-04-01 20:13:08 +0800937 surface->configure = black_surface_configure;
938 surface->private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +0800939 weston_surface_configure(surface, x, y, w, h);
940 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
941 return surface;
942}
943
944/* Create black surface and append it to the associated fullscreen surface.
945 * Handle size dismatch and positioning according to the method. */
946static void
947shell_configure_fullscreen(struct shell_surface *shsurf)
948{
949 struct weston_output *output = shsurf->fullscreen_output;
950 struct weston_surface *surface = shsurf->surface;
951 struct weston_matrix *matrix;
952 float scale;
953
954 center_on_output(surface, output);
955
956 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500957 shsurf->fullscreen.black_surface =
958 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +0800959 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500960 output->x, output->y,
961 output->current->width,
962 output->current->height);
963
964 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
965 wl_list_insert(&surface->layer_link,
966 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800967 shsurf->fullscreen.black_surface->output = output;
968
969 switch (shsurf->fullscreen.type) {
970 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
971 break;
972 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
973 matrix = &shsurf->fullscreen.transform.matrix;
974 weston_matrix_init(matrix);
975 scale = (float)output->current->width/(float)surface->geometry.width;
976 weston_matrix_scale(matrix, scale, scale, 1);
977 wl_list_remove(&shsurf->fullscreen.transform.link);
978 wl_list_insert(surface->geometry.transformation_list.prev,
979 &shsurf->fullscreen.transform.link);
980 weston_surface_set_position(surface, output->x, output->y);
981 break;
982 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +0800983 if (shell_surface_is_top_fullscreen(shsurf)) {
984 struct weston_mode mode = {0,
985 surface->geometry.width,
986 surface->geometry.height,
987 shsurf->fullscreen.framerate};
988
989 if (weston_output_switch_mode(output, &mode) == 0) {
990 weston_surface_configure(shsurf->fullscreen.black_surface,
991 output->x, output->y,
992 output->current->width,
993 output->current->height);
994 weston_surface_set_position(surface, output->x, output->y);
995 break;
996 }
997 }
Alex Wu4539b082012-03-01 12:57:46 +0800998 break;
999 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1000 break;
1001 default:
1002 break;
1003 }
1004}
1005
1006/* make the fullscreen and black surface at the top */
1007static void
1008shell_stack_fullscreen(struct shell_surface *shsurf)
1009{
Alex Wubd3354b2012-04-17 17:20:49 +08001010 struct weston_output *output = shsurf->fullscreen_output;
Alex Wu4539b082012-03-01 12:57:46 +08001011 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +03001012 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001013
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001014 wl_list_remove(&surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001015 wl_list_insert(&shell->fullscreen_layer.surface_list,
1016 &surface->layer_link);
Alex Wubd3354b2012-04-17 17:20:49 +08001017 weston_surface_damage(surface);
1018
1019 if (!shsurf->fullscreen.black_surface)
1020 shsurf->fullscreen.black_surface =
1021 create_black_surface(surface->compositor,
1022 surface,
1023 output->x, output->y,
1024 output->current->width,
1025 output->current->height);
1026
1027 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001028 wl_list_insert(&surface->layer_link,
1029 &shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001030 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +08001031}
1032
1033static void
1034shell_map_fullscreen(struct shell_surface *shsurf)
1035{
Alex Wu4539b082012-03-01 12:57:46 +08001036 shell_stack_fullscreen(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001037 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001038}
1039
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001040static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001041shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -05001042 struct wl_resource *resource,
1043 uint32_t method,
1044 uint32_t framerate,
1045 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001046{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001047 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001048 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +08001049
1050 if (output_resource)
1051 shsurf->output = output_resource->data;
1052 else
1053 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001054
Alex Wu4539b082012-03-01 12:57:46 +08001055 shsurf->fullscreen_output = shsurf->output;
1056 shsurf->fullscreen.type = method;
1057 shsurf->fullscreen.framerate = framerate;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001058 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
Alex Wu4539b082012-03-01 12:57:46 +08001059
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001060 shsurf->client->send_configure(shsurf->surface, 0,
1061 shsurf->output->current->width,
1062 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001063}
1064
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001065static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001066popup_grab_focus(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001067 struct wl_surface *surface,
1068 wl_fixed_t x,
1069 wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001070{
Daniel Stone37816df2012-05-16 18:45:18 +01001071 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001072 struct shell_surface *priv =
1073 container_of(grab, struct shell_surface, popup.grab);
1074 struct wl_client *client = priv->surface->surface.resource.client;
1075
Pekka Paalanencb108432012-01-19 16:25:40 +02001076 if (surface && surface->resource.client == client) {
Daniel Stone37816df2012-05-16 18:45:18 +01001077 wl_pointer_set_focus(pointer, surface, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001078 grab->focus = surface;
1079 } else {
Daniel Stone37816df2012-05-16 18:45:18 +01001080 wl_pointer_set_focus(pointer, NULL,
1081 wl_fixed_from_int(0),
1082 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001083 grab->focus = NULL;
1084 }
1085}
1086
1087static void
Scott Moreau447013d2012-02-18 05:05:29 -07001088popup_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001089 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001090{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001091 struct wl_resource *resource;
1092
Daniel Stone37816df2012-05-16 18:45:18 +01001093 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001094 if (resource)
Daniel Stone37816df2012-05-16 18:45:18 +01001095 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001096}
1097
1098static void
Scott Moreau447013d2012-02-18 05:05:29 -07001099popup_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01001100 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001101{
1102 struct wl_resource *resource;
1103 struct shell_surface *shsurf =
1104 container_of(grab, struct shell_surface, popup.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001105 struct wl_display *display;
1106 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001107
Daniel Stone37816df2012-05-16 18:45:18 +01001108 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001109 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001110 display = wl_client_get_display(resource->client);
1111 serial = wl_display_get_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +01001112 wl_pointer_send_button(resource, serial, time, button, state);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001113 } else if (state == 0 &&
1114 (shsurf->popup.initial_up ||
Daniel Stone37816df2012-05-16 18:45:18 +01001115 time - shsurf->popup.seat->pointer->grab_time > 500)) {
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001116 wl_shell_surface_send_popup_done(&shsurf->resource);
Daniel Stone37816df2012-05-16 18:45:18 +01001117 wl_pointer_end_grab(grab->pointer);
1118 shsurf->popup.grab.pointer = NULL;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001119 }
1120
1121 if (state == 0)
1122 shsurf->popup.initial_up = 1;
1123}
1124
Scott Moreau447013d2012-02-18 05:05:29 -07001125static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001126 popup_grab_focus,
1127 popup_grab_motion,
1128 popup_grab_button,
1129};
1130
1131static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001132shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001133{
Daniel Stone37816df2012-05-16 18:45:18 +01001134 struct wl_seat *seat = shsurf->popup.seat;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001135 struct weston_surface *es = shsurf->surface;
1136 struct weston_surface *parent = shsurf->parent->surface;
1137
1138 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001139 shsurf->popup.grab.interface = &popup_grab_interface;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001140
Pekka Paalanen938269a2012-02-07 14:19:01 +02001141 weston_surface_update_transform(parent);
1142 if (parent->transform.enabled) {
1143 shsurf->popup.parent_transform.matrix =
1144 parent->transform.matrix;
1145 } else {
1146 /* construct x, y translation matrix */
1147 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1148 shsurf->popup.parent_transform.matrix.d[12] =
1149 parent->geometry.x;
1150 shsurf->popup.parent_transform.matrix.d[13] =
1151 parent->geometry.y;
1152 }
1153 wl_list_insert(es->geometry.transformation_list.prev,
1154 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001155 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001156
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001157 shsurf->popup.initial_up = 0;
1158
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001159 /* We don't require the grab to still be active, but if another
1160 * grab has started in the meantime, we end the popup now. */
Daniel Stone37816df2012-05-16 18:45:18 +01001161 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1162 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001163 } else {
1164 wl_shell_surface_send_popup_done(&shsurf->resource);
1165 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001166}
1167
1168static void
1169shell_surface_set_popup(struct wl_client *client,
1170 struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +01001171 struct wl_resource *seat_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001172 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001173 struct wl_resource *parent_resource,
1174 int32_t x, int32_t y, uint32_t flags)
1175{
1176 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001177
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001178 shsurf->type = SHELL_SURFACE_POPUP;
1179 shsurf->parent = parent_resource->data;
Daniel Stone37816df2012-05-16 18:45:18 +01001180 shsurf->popup.seat = seat_resource->data;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001181 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001182 shsurf->popup.x = x;
1183 shsurf->popup.y = y;
1184}
1185
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001186static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06001187 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001188 shell_surface_move,
1189 shell_surface_resize,
1190 shell_surface_set_toplevel,
1191 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001192 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08001193 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001194 shell_surface_set_maximized,
1195 shell_surface_set_title,
1196 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001197};
1198
1199static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001200destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001201{
Daniel Stone37816df2012-05-16 18:45:18 +01001202 if (shsurf->popup.grab.pointer)
1203 wl_pointer_end_grab(shsurf->popup.grab.pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001204
Alex Wubd3354b2012-04-17 17:20:49 +08001205 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1206 shell_surface_is_top_fullscreen(shsurf)) {
1207 weston_output_switch_mode(shsurf->fullscreen_output,
1208 shsurf->fullscreen_output->origin);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001209 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001210
Alex Wuaa08e2d2012-03-05 11:01:40 +08001211 if (shsurf->fullscreen.black_surface)
1212 weston_surface_destroy(shsurf->fullscreen.black_surface);
1213
Alex Wubd3354b2012-04-17 17:20:49 +08001214 /* As destroy_resource() use wl_list_for_each_safe(),
1215 * we can always remove the listener.
1216 */
1217 wl_list_remove(&shsurf->surface_destroy_listener.link);
1218 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001219 ping_timer_destroy(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001220
Rob Bradford579f2932012-05-21 18:04:15 +01001221 if (shsurf->unresponsive_animation.exists)
1222 wl_list_remove(&shsurf->unresponsive_animation.current.link);
1223
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001224 wl_list_remove(&shsurf->link);
1225 free(shsurf);
1226}
1227
1228static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001229shell_destroy_shell_surface(struct wl_resource *resource)
1230{
1231 struct shell_surface *shsurf = resource->data;
1232
1233 destroy_shell_surface(shsurf);
1234}
1235
1236static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001237shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001238{
1239 struct shell_surface *shsurf = container_of(listener,
1240 struct shell_surface,
1241 surface_destroy_listener);
1242
Tiago Vignattibc052c92012-04-19 16:18:18 +03001243 /* tricky way to check if resource was in fact created */
1244 if (shsurf->resource.object.implementation != 0)
1245 wl_resource_destroy(&shsurf->resource);
1246 else
1247 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001248}
1249
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001250static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001251get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001252{
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001253 struct wl_listener *listener;
1254
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001255 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
1256 shell_handle_surface_destroy);
1257 if (listener)
1258 return container_of(listener, struct shell_surface,
1259 surface_destroy_listener);
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001260
1261 return NULL;
1262}
1263
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001264static void
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001265shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1266
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001267static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001268create_shell_surface(void *shell, struct weston_surface *surface,
1269 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001270{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001271 struct shell_surface *shsurf;
1272
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001273 if (surface->configure) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001274 fprintf(stderr, "surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001275 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001276 }
1277
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001278 shsurf = calloc(1, sizeof *shsurf);
1279 if (!shsurf) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001280 fprintf(stderr, "no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001281 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001282 }
1283
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001284 surface->configure = shell_surface_configure;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001285 surface->compositor->shell_interface.shell = shell;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001286
Tiago Vignattibc052c92012-04-19 16:18:18 +03001287 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001288 shsurf->unresponsive = 0;
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001289 shsurf->unresponsive_animation.exists = 0;
1290 shsurf->unresponsive_animation.fading_in = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001291 shsurf->unresponsive_animation.current.frame = unresponsive_fade_frame;
Alex Wu4539b082012-03-01 12:57:46 +08001292 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08001293 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001294 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08001295 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1296 shsurf->fullscreen.framerate = 0;
1297 shsurf->fullscreen.black_surface = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001298 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08001299 wl_list_init(&shsurf->fullscreen.transform.link);
1300
Tiago Vignattibc052c92012-04-19 16:18:18 +03001301 wl_signal_init(&shsurf->resource.destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001302 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1303 wl_signal_add(&surface->surface.resource.destroy_signal,
1304 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001305
1306 /* init link so its safe to always remove it in destroy_shell_surface */
1307 wl_list_init(&shsurf->link);
1308
Pekka Paalanen460099f2012-01-20 16:48:25 +02001309 /* empty when not in use */
1310 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001311 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001312
Pekka Paalanen98262232011-12-01 10:42:22 +02001313 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001314 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001315
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001316 shsurf->client = client;
1317
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001318 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001319}
1320
1321static void
1322shell_get_shell_surface(struct wl_client *client,
1323 struct wl_resource *resource,
1324 uint32_t id,
1325 struct wl_resource *surface_resource)
1326{
1327 struct weston_surface *surface = surface_resource->data;
1328 struct desktop_shell *shell = resource->data;
1329 struct shell_surface *shsurf;
1330
1331 if (get_shell_surface(surface)) {
1332 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001333 WL_DISPLAY_ERROR_INVALID_OBJECT,
1334 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03001335 return;
1336 }
1337
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001338 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001339 if (!shsurf) {
1340 wl_resource_post_error(surface_resource,
1341 WL_DISPLAY_ERROR_INVALID_OBJECT,
1342 "surface->configure already set");
1343 return;
1344 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03001345
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001346 shsurf->resource.destroy = shell_destroy_shell_surface;
1347 shsurf->resource.object.id = id;
1348 shsurf->resource.object.interface = &wl_shell_surface_interface;
1349 shsurf->resource.object.implementation =
1350 (void (**)(void)) &shell_surface_implementation;
1351 shsurf->resource.data = shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001352
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001353 wl_client_add_resource(client, &shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001354}
1355
1356static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02001357 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001358};
1359
Kristian Høgsberg07937562011-04-12 17:25:42 -04001360static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001361handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02001362{
1363 proc->pid = 0;
1364}
1365
1366static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001367launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001368{
1369 if (shell->screensaver.binding)
1370 return;
1371
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001372 if (!shell->screensaver.path)
1373 return;
1374
Kristian Høgsberg32bed572012-03-01 17:11:36 -05001375 if (shell->screensaver.process.pid != 0) {
1376 fprintf(stderr, "old screensaver still running\n");
1377 return;
1378 }
1379
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001380 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001381 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001382 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001383 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001384}
1385
1386static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001387terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001388{
Pekka Paalanen18027e52011-12-02 16:31:49 +02001389 if (shell->screensaver.process.pid == 0)
1390 return;
1391
1392 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001393}
1394
1395static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001396show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001397{
1398 struct wl_list *list;
1399
1400 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001401 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001402 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001403 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001404
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001405 wl_list_remove(&surface->surface->layer_link);
1406 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001407 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001408 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001409}
1410
1411static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001412hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001413{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001414 wl_list_remove(&surface->surface->layer_link);
1415 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001416 surface->surface->output = NULL;
1417}
1418
1419static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001420desktop_shell_set_background(struct wl_client *client,
1421 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001422 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001423 struct wl_resource *surface_resource)
1424{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001425 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001426
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001427 shsurf->next_type = SHELL_SURFACE_BACKGROUND;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001428 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001429
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001430 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001431 surface_resource,
1432 shsurf->output->current->width,
1433 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001434}
1435
1436static void
1437desktop_shell_set_panel(struct wl_client *client,
1438 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001439 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001440 struct wl_resource *surface_resource)
1441{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001442 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001443
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001444 shsurf->next_type = SHELL_SURFACE_PANEL;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001445 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001446
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001447 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001448 surface_resource,
1449 shsurf->output->current->width,
1450 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001451}
1452
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001453static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001454handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001455{
Tiago Vignattibe143262012-04-16 17:31:41 +03001456 struct desktop_shell *shell =
1457 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001458
1459 fprintf(stderr, "lock surface gone\n");
1460 shell->lock_surface = NULL;
1461}
1462
1463static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001464desktop_shell_set_lock_surface(struct wl_client *client,
1465 struct wl_resource *resource,
1466 struct wl_resource *surface_resource)
1467{
Tiago Vignattibe143262012-04-16 17:31:41 +03001468 struct desktop_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001469 struct shell_surface *surface = surface_resource->data;
1470
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001471 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001472
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001473 if (!shell->locked)
1474 return;
1475
Pekka Paalanen98262232011-12-01 10:42:22 +02001476 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001477
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001478 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1479 wl_signal_add(&surface_resource->destroy_signal,
1480 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001481
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001482 shell->lock_surface->next_type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001483}
1484
1485static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001486resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001487{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001488 struct shell_surface *tmp;
1489
1490 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1491 hide_screensaver(shell, tmp);
1492
1493 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001494
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001495 wl_list_remove(&shell->lock_layer.link);
1496 wl_list_insert(&shell->compositor->cursor_layer.link,
1497 &shell->fullscreen_layer.link);
1498 wl_list_insert(&shell->fullscreen_layer.link,
1499 &shell->panel_layer.link);
1500 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001501
1502 shell->locked = false;
Pekka Paalanen7296e792011-12-07 16:22:00 +02001503 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001504 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001505 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001506}
1507
1508static void
1509desktop_shell_unlock(struct wl_client *client,
1510 struct wl_resource *resource)
1511{
Tiago Vignattibe143262012-04-16 17:31:41 +03001512 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001513
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001514 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001515
1516 if (shell->locked)
1517 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001518}
1519
Kristian Høgsberg75840622011-09-06 13:48:16 -04001520static const struct desktop_shell_interface desktop_shell_implementation = {
1521 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001522 desktop_shell_set_panel,
1523 desktop_shell_set_lock_surface,
1524 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001525};
1526
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001527static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001528get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001529{
1530 struct shell_surface *shsurf;
1531
1532 shsurf = get_shell_surface(surface);
1533 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001534 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001535 return shsurf->type;
1536}
1537
Kristian Høgsberg75840622011-09-06 13:48:16 -04001538static void
Daniel Stone37816df2012-05-16 18:45:18 +01001539move_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001540 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1541 void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001542{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001543 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001544 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001545 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001546
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001547 if (surface == NULL)
1548 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001549
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001550 shsurf = get_shell_surface(surface);
1551 if (shsurf == NULL)
1552 return;
1553
1554 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001555 case SHELL_SURFACE_PANEL:
1556 case SHELL_SURFACE_BACKGROUND:
1557 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001558 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001559 return;
1560 default:
1561 break;
1562 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001563
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001564 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001565}
1566
1567static void
Daniel Stone37816df2012-05-16 18:45:18 +01001568resize_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001569 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1570 void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001571{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001572 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001573 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001574 uint32_t edges = 0;
1575 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001576 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001577
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001578 if (surface == NULL)
1579 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001580
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001581 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001582 if (!shsurf)
1583 return;
1584
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001585 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001586 case SHELL_SURFACE_PANEL:
1587 case SHELL_SURFACE_BACKGROUND:
1588 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001589 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001590 return;
1591 default:
1592 break;
1593 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001594
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001595 weston_surface_from_global(surface,
Daniel Stone37816df2012-05-16 18:45:18 +01001596 wl_fixed_to_int(seat->pointer->grab_x),
1597 wl_fixed_to_int(seat->pointer->grab_y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001598 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001599
Pekka Paalanen60921e52012-01-25 15:55:43 +02001600 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001601 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001602 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001603 edges |= 0;
1604 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001605 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001606
Pekka Paalanen60921e52012-01-25 15:55:43 +02001607 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001608 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001609 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001610 edges |= 0;
1611 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001612 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001613
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001614 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001615}
1616
1617static void
Daniel Stone37816df2012-05-16 18:45:18 +01001618surface_opacity_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001619 uint32_t key, uint32_t button, uint32_t axis,
1620 int32_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001621{
Scott Moreau02709af2012-05-22 01:54:10 -06001622 float step = 0.05;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001623 struct shell_surface *shsurf;
1624 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001625 (struct weston_surface *) seat->pointer->focus;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001626
1627 if (surface == NULL)
1628 return;
1629
1630 shsurf = get_shell_surface(surface);
1631 if (!shsurf)
1632 return;
1633
1634 switch (shsurf->type) {
1635 case SHELL_SURFACE_BACKGROUND:
1636 case SHELL_SURFACE_SCREENSAVER:
1637 return;
1638 default:
1639 break;
1640 }
1641
1642 surface->alpha += value * step;
1643
Scott Moreau02709af2012-05-22 01:54:10 -06001644 if (surface->alpha > 1.0)
1645 surface->alpha = 1.0;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001646 if (surface->alpha < step)
1647 surface->alpha = step;
1648
1649 surface->geometry.dirty = 1;
1650 weston_surface_damage(surface);
1651}
1652
1653static void
Daniel Stone37816df2012-05-16 18:45:18 +01001654zoom_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001655 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1656 void *data)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001657{
Daniel Stone37816df2012-05-16 18:45:18 +01001658 struct weston_seat *ws = (struct weston_seat *) seat;
1659 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001660 struct weston_output *output;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001661 float maximum_level, increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001662
1663 wl_list_for_each(output, &compositor->output_list, link) {
1664 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01001665 wl_fixed_to_double(seat->pointer->x),
1666 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001667 NULL)) {
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001668 if (key == KEY_PAGEUP && value)
1669 increment = output->zoom.increment;
1670 else if (key == KEY_PAGEDOWN && value)
1671 increment = -output->zoom.increment;
1672 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
1673 increment = output->zoom.increment * value;
1674 else
1675 increment = 0;
1676
Scott Moreau1b45a792012-03-22 10:58:23 -06001677 output->zoom.active = 1;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001678 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001679
Scott Moreau850ca422012-05-21 15:21:25 -06001680 if (output->zoom.level <= 0.0) {
Scott Moreauc6d7f602012-02-23 22:28:37 -07001681 output->zoom.active = 0;
Scott Moreau850ca422012-05-21 15:21:25 -06001682 output->zoom.level = 0.0;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001683 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001684
Scott Moreau850ca422012-05-21 15:21:25 -06001685 maximum_level = 1 - output->zoom.increment;
1686
1687 if (output->zoom.level > maximum_level)
1688 output->zoom.level = maximum_level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001689
Daniel Stone37816df2012-05-16 18:45:18 +01001690 weston_output_update_zoom(output,
1691 seat->pointer->x,
1692 seat->pointer->y);
Scott Moreauccbf29d2012-02-22 14:21:41 -07001693 }
1694 }
1695}
1696
Scott Moreauccbf29d2012-02-22 14:21:41 -07001697static void
Daniel Stone37816df2012-05-16 18:45:18 +01001698terminate_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001699 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001700{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001701 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001702
1703 if (state)
1704 wl_display_terminate(compositor->wl_display);
1705}
1706
1707static void
Scott Moreau447013d2012-02-18 05:05:29 -07001708rotate_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001709 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001710{
1711 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001712 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001713 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001714 struct shell_surface *shsurf = rotate->base.shsurf;
1715 struct weston_surface *surface;
1716 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1717
1718 if (!shsurf)
1719 return;
1720
1721 surface = shsurf->surface;
1722
1723 cx = 0.5f * surface->geometry.width;
1724 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001725
Daniel Stone37816df2012-05-16 18:45:18 +01001726 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
1727 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001728 r = sqrtf(dx * dx + dy * dy);
1729
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001730 wl_list_remove(&shsurf->rotation.transform.link);
1731 shsurf->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001732
1733 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001734 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001735 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001736
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001737 weston_matrix_init(&rotate->rotation);
1738 rotate->rotation.d[0] = dx / r;
1739 rotate->rotation.d[4] = -dy / r;
1740 rotate->rotation.d[1] = -rotate->rotation.d[4];
1741 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001742
1743 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001744 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001745 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001746 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001747 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001748
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001749 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001750 &shsurf->surface->geometry.transformation_list,
1751 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001752 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001753 wl_list_init(&shsurf->rotation.transform.link);
1754 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001755 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001756 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001757
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001758 /* We need to adjust the position of the surface
1759 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001760 cposx = surface->geometry.x + cx;
1761 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001762 dposx = rotate->center.x - cposx;
1763 dposy = rotate->center.y - cposy;
1764 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001765 weston_surface_set_position(surface,
1766 surface->geometry.x + dposx,
1767 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001768 }
1769
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001770 /* Repaint implies weston_surface_update_transform(), which
1771 * lazily applies the damage due to rotation update.
1772 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001773 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001774}
1775
1776static void
Scott Moreau447013d2012-02-18 05:05:29 -07001777rotate_grab_button(struct wl_pointer_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01001778 uint32_t time, uint32_t button, uint32_t state)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001779{
1780 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001781 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001782 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001783 struct shell_surface *shsurf = rotate->base.shsurf;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001784
Daniel Stone37816df2012-05-16 18:45:18 +01001785 if (pointer->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001786 if (shsurf)
1787 weston_matrix_multiply(&shsurf->rotation.rotation,
1788 &rotate->rotation);
1789 shell_grab_finish(&rotate->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001790 wl_pointer_end_grab(pointer);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001791 free(rotate);
1792 }
1793}
1794
Scott Moreau447013d2012-02-18 05:05:29 -07001795static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001796 noop_grab_focus,
1797 rotate_grab_motion,
1798 rotate_grab_button,
1799};
1800
1801static void
Daniel Stone37816df2012-05-16 18:45:18 +01001802rotate_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01001803 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1804 void *data)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001805{
1806 struct weston_surface *base_surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001807 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001808 struct shell_surface *surface;
1809 struct rotate_grab *rotate;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001810 GLfloat dx, dy;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001811 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001812
1813 if (base_surface == NULL)
1814 return;
1815
1816 surface = get_shell_surface(base_surface);
1817 if (!surface)
1818 return;
1819
1820 switch (surface->type) {
1821 case SHELL_SURFACE_PANEL:
1822 case SHELL_SURFACE_BACKGROUND:
1823 case SHELL_SURFACE_FULLSCREEN:
1824 case SHELL_SURFACE_SCREENSAVER:
1825 return;
1826 default:
1827 break;
1828 }
1829
Pekka Paalanen460099f2012-01-20 16:48:25 +02001830 rotate = malloc(sizeof *rotate);
1831 if (!rotate)
1832 return;
1833
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001834 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001835
1836 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001837 surface->surface->geometry.width / 2,
1838 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001839 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001840
Daniel Stone37816df2012-05-16 18:45:18 +01001841 wl_pointer_start_grab(seat->pointer, &rotate->base.grab);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001842
Daniel Stone37816df2012-05-16 18:45:18 +01001843 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
1844 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001845 r = sqrtf(dx * dx + dy * dy);
1846 if (r > 20.0f) {
1847 struct weston_matrix inverse;
1848
1849 weston_matrix_init(&inverse);
1850 inverse.d[0] = dx / r;
1851 inverse.d[4] = dy / r;
1852 inverse.d[1] = -inverse.d[4];
1853 inverse.d[5] = inverse.d[0];
1854 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001855
1856 weston_matrix_init(&rotate->rotation);
1857 rotate->rotation.d[0] = dx / r;
1858 rotate->rotation.d[4] = -dy / r;
1859 rotate->rotation.d[1] = -rotate->rotation.d[4];
1860 rotate->rotation.d[5] = rotate->rotation.d[0];
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001861 } else {
1862 weston_matrix_init(&surface->rotation.rotation);
1863 weston_matrix_init(&rotate->rotation);
1864 }
1865
Daniel Stone37816df2012-05-16 18:45:18 +01001866 wl_pointer_set_focus(seat->pointer, NULL,
1867 wl_fixed_from_int(0),
1868 wl_fixed_from_int(0));
Pekka Paalanen460099f2012-01-20 16:48:25 +02001869}
1870
1871static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001872activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01001873 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001874{
Alex Wu21858432012-04-01 20:13:08 +08001875 struct weston_surface *surf, *prev;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001876
Daniel Stone37816df2012-05-16 18:45:18 +01001877 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001878
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001879 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001880 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001881 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001882 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001883 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001884
Pekka Paalanen77346a62011-11-30 16:26:35 +02001885 case SHELL_SURFACE_SCREENSAVER:
1886 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001887 if (shell->lock_surface)
1888 weston_surface_restack(es,
1889 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001890 break;
Alex Wu4539b082012-03-01 12:57:46 +08001891 case SHELL_SURFACE_FULLSCREEN:
1892 /* should on top of panels */
Alex Wu21858432012-04-01 20:13:08 +08001893 shell_stack_fullscreen(get_shell_surface(es));
Alex Wubd3354b2012-04-17 17:20:49 +08001894 shell_configure_fullscreen(get_shell_surface(es));
Alex Wu4539b082012-03-01 12:57:46 +08001895 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001896 default:
Alex Wubd3354b2012-04-17 17:20:49 +08001897 /* move the fullscreen surfaces down into the toplevel layer */
Alex Wu21858432012-04-01 20:13:08 +08001898 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1899 wl_list_for_each_reverse_safe(surf,
1900 prev,
1901 &shell->fullscreen_layer.surface_list,
1902 layer_link)
1903 weston_surface_restack(surf,
1904 &shell->toplevel_layer.surface_list);
1905 }
1906
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001907 weston_surface_restack(es,
1908 &shell->toplevel_layer.surface_list);
1909 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001910 }
1911}
1912
Alex Wu21858432012-04-01 20:13:08 +08001913/* no-op func for checking black surface */
1914static void
1915black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1916{
1917}
1918
1919static bool
1920is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1921{
1922 if (es->configure == black_surface_configure) {
1923 if (fs_surface)
1924 *fs_surface = (struct weston_surface *)es->private;
1925 return true;
1926 }
1927 return false;
1928}
1929
Kristian Høgsberg75840622011-09-06 13:48:16 -04001930static void
Daniel Stone37816df2012-05-16 18:45:18 +01001931click_to_activate_binding(struct wl_seat *seat,
Alex Wu4539b082012-03-01 12:57:46 +08001932 uint32_t time, uint32_t key,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001933 uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001934{
Daniel Stone37816df2012-05-16 18:45:18 +01001935 struct weston_seat *ws = (struct weston_seat *) seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03001936 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001937 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001938 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001939
Daniel Stone37816df2012-05-16 18:45:18 +01001940 focus = (struct weston_surface *) seat->pointer->focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08001941 if (!focus)
1942 return;
1943
Alex Wu21858432012-04-01 20:13:08 +08001944 if (is_black_surface(focus, &upper))
Alex Wu4539b082012-03-01 12:57:46 +08001945 focus = upper;
Alex Wu4539b082012-03-01 12:57:46 +08001946
Daniel Stone37816df2012-05-16 18:45:18 +01001947 if (state && seat->pointer->grab == &seat->pointer->default_grab)
1948 activate(shell, focus, ws);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001949}
1950
1951static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001952lock(struct wl_listener *listener, void *data)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001953{
Tiago Vignattibe143262012-04-16 17:31:41 +03001954 struct desktop_shell *shell =
1955 container_of(listener, struct desktop_shell, lock_listener);
Daniel Stone37816df2012-05-16 18:45:18 +01001956 struct weston_seat *seat;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001957 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001958 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001959
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001960 if (shell->locked) {
1961 wl_list_for_each(output, &shell->compositor->output_list, link)
1962 /* TODO: find a way to jump to other DPMS levels */
1963 if (output->set_dpms)
1964 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001965 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001966 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001967
1968 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001969
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001970 /* Hide all surfaces by removing the fullscreen, panel and
1971 * toplevel layers. This way nothing else can show or receive
1972 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001973
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001974 wl_list_remove(&shell->panel_layer.link);
1975 wl_list_remove(&shell->toplevel_layer.link);
1976 wl_list_remove(&shell->fullscreen_layer.link);
1977 wl_list_insert(&shell->compositor->cursor_layer.link,
1978 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001979
Pekka Paalanen77346a62011-11-30 16:26:35 +02001980 launch_screensaver(shell);
1981
1982 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1983 show_screensaver(shell, shsurf);
1984
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001985 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001986 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001987 weston_compositor_wake(shell->compositor);
1988 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001989 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001990
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001991 /* reset pointer foci */
Kristian Høgsbergaa6019e2012-03-11 16:35:16 -04001992 weston_compositor_schedule_repaint(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001993
1994 /* reset keyboard foci */
Daniel Stone37816df2012-05-16 18:45:18 +01001995 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1996 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001997 }
1998
1999 /* TODO: disable bindings that should not work while locked. */
2000
2001 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002002}
2003
2004static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002005unlock(struct wl_listener *listener, void *data)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002006{
Tiago Vignattibe143262012-04-16 17:31:41 +03002007 struct desktop_shell *shell =
2008 container_of(listener, struct desktop_shell, unlock_listener);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002009
Pekka Paalanend81c2162011-11-16 13:47:34 +02002010 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002011 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002012 return;
2013 }
2014
2015 /* If desktop-shell client has gone away, unlock immediately. */
2016 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002017 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002018 return;
2019 }
2020
2021 if (shell->prepare_event_sent)
2022 return;
2023
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05002024 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002025 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002026}
2027
2028static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002029center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02002030{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002031 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002032 GLfloat x = (mode->width - surface->geometry.width) / 2;
2033 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002034
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002035 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002036}
2037
2038static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002039map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002040 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002041{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002042 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002043 struct shell_surface *shsurf;
2044 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002045 struct weston_surface *parent;
Juan Zhao96879df2012-02-07 08:45:41 +08002046 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002047
Pekka Paalanen77346a62011-11-30 16:26:35 +02002048 shsurf = get_shell_surface(surface);
2049 if (shsurf)
2050 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002051
Pekka Paalanen60921e52012-01-25 15:55:43 +02002052 surface->geometry.width = width;
2053 surface->geometry.height = height;
2054 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002055
2056 /* initial positioning, see also configure() */
2057 switch (surface_type) {
2058 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002059 weston_surface_set_position(surface, 10 + random() % 400,
2060 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002061 break;
2062 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002063 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002064 break;
Alex Wu4539b082012-03-01 12:57:46 +08002065 case SHELL_SURFACE_FULLSCREEN:
2066 shell_map_fullscreen(shsurf);
2067 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002068 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002069 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08002070 panel_height = get_output_panel_height(shell,surface->output);
2071 weston_surface_set_position(surface, surface->output->x,
2072 surface->output->y + panel_height);
2073 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002074 case SHELL_SURFACE_LOCK:
2075 center_on_output(surface, get_default_output(compositor));
2076 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02002077 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002078 shell_map_popup(shsurf);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002079 case SHELL_SURFACE_NONE:
2080 weston_surface_set_position(surface,
2081 surface->geometry.x + sx,
2082 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02002083 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002084 default:
2085 ;
2086 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04002087
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002088 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002089 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002090 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002091 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002092 wl_list_insert(&shell->background_layer.surface_list,
2093 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002094 break;
2095 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002096 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002097 wl_list_insert(&shell->panel_layer.surface_list,
2098 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002099 break;
2100 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002101 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002102 wl_list_insert(&shell->lock_layer.surface_list,
2103 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002104 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002105 break;
2106 case SHELL_SURFACE_SCREENSAVER:
2107 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002108 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02002109 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02002110 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002111 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02002112 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002113 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002114 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002115 break;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002116 case SHELL_SURFACE_POPUP:
2117 case SHELL_SURFACE_TRANSIENT:
2118 parent = shsurf->parent->surface;
2119 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2120 break;
Alex Wu4539b082012-03-01 12:57:46 +08002121 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02002122 case SHELL_SURFACE_NONE:
2123 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002124 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002125 wl_list_insert(&shell->toplevel_layer.surface_list,
2126 &surface->layer_link);
2127 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002128 }
2129
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002130 if (surface_type != SHELL_SURFACE_NONE) {
2131 weston_surface_assign_output(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002132 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2133 surface->output = shsurf->output;
2134 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002135
Juan Zhao7bb92f02011-12-15 11:31:51 -05002136 switch (surface_type) {
Juan Zhao7bb92f02011-12-15 11:31:51 -05002137 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03002138 if (shsurf->transient.flags ==
2139 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2140 break;
2141 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05002142 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08002143 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05002144 if (!shell->locked)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002145 activate(shell, surface,
Daniel Stone37816df2012-05-16 18:45:18 +01002146 (struct weston_seat *) compositor->seat);
Juan Zhao7bb92f02011-12-15 11:31:51 -05002147 break;
2148 default:
2149 break;
2150 }
2151
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002152 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08002153 {
2154 switch (shell->win_animation_type) {
2155 case ANIMATION_FADE:
2156 weston_fade_run(surface, NULL, NULL);
2157 break;
2158 case ANIMATION_ZOOM:
2159 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2160 break;
2161 default:
2162 break;
2163 }
2164 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002165}
2166
2167static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002168configure(struct desktop_shell *shell, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02002169 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002170{
Pekka Paalanen77346a62011-11-30 16:26:35 +02002171 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2172 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002173
Pekka Paalanen77346a62011-11-30 16:26:35 +02002174 shsurf = get_shell_surface(surface);
2175 if (shsurf)
2176 surface_type = shsurf->type;
2177
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002178 surface->geometry.x = x;
2179 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02002180 surface->geometry.width = width;
2181 surface->geometry.height = height;
2182 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002183
2184 switch (surface_type) {
2185 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002186 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002187 break;
Alex Wu4539b082012-03-01 12:57:46 +08002188 case SHELL_SURFACE_FULLSCREEN:
Alex Wubd3354b2012-04-17 17:20:49 +08002189 shell_stack_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002190 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002191 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002192 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002193 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002194 surface->geometry.x = surface->output->x;
2195 surface->geometry.y = surface->output->y +
2196 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08002197 break;
Alex Wu4539b082012-03-01 12:57:46 +08002198 case SHELL_SURFACE_TOPLEVEL:
2199 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002200 default:
2201 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002202 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002203
Alex Wu4539b082012-03-01 12:57:46 +08002204 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002205 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02002206 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002207
2208 if (surface_type == SHELL_SURFACE_SCREENSAVER)
2209 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08002210 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
2211 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002212 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04002213}
2214
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002215static void
2216shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2217{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03002218 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03002219 struct desktop_shell *shell = shsurf->shell;
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03002220 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002221
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002222 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002223 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002224 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002225 type_changed = 1;
2226 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002227
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002228 if (!weston_surface_is_mapped(es)) {
2229 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002230 } else if (type_changed || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002231 es->geometry.width != es->buffer->width ||
2232 es->geometry.height != es->buffer->height) {
2233 GLfloat from_x, from_y;
2234 GLfloat to_x, to_y;
2235
2236 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2237 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2238 configure(shell, es,
2239 es->geometry.x + to_x - from_x,
2240 es->geometry.y + to_y - from_y,
2241 es->buffer->width, es->buffer->height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002242 }
2243}
2244
Tiago Vignattibe143262012-04-16 17:31:41 +03002245static int launch_desktop_shell_process(struct desktop_shell *shell);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002246
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002247static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002248desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002249{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002250 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03002251 struct desktop_shell *shell =
2252 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002253
2254 shell->child.process.pid = 0;
2255 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002256
2257 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2258 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002259 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002260 shell->child.deathstamp = time;
2261 shell->child.deathcount = 0;
2262 }
2263
2264 shell->child.deathcount++;
2265 if (shell->child.deathcount > 5) {
2266 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
2267 return;
2268 }
2269
2270 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
2271 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002272}
2273
2274static int
Tiago Vignattibe143262012-04-16 17:31:41 +03002275launch_desktop_shell_process(struct desktop_shell *shell)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002276{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05002277 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002278
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002279 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02002280 &shell->child.process,
2281 shell_exe,
2282 desktop_shell_sigchld);
2283
2284 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002285 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002286 return 0;
2287}
2288
2289static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002290bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2291{
Tiago Vignattibe143262012-04-16 17:31:41 +03002292 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002293
2294 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002295 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002296}
2297
Kristian Høgsberg75840622011-09-06 13:48:16 -04002298static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002299unbind_desktop_shell(struct wl_resource *resource)
2300{
Tiago Vignattibe143262012-04-16 17:31:41 +03002301 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002302
2303 if (shell->locked)
2304 resume_desktop(shell);
2305
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002306 shell->child.desktop_shell = NULL;
2307 shell->prepare_event_sent = false;
2308 free(resource);
2309}
2310
2311static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04002312bind_desktop_shell(struct wl_client *client,
2313 void *data, uint32_t version, uint32_t id)
2314{
Tiago Vignattibe143262012-04-16 17:31:41 +03002315 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002316 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002317
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002318 resource = wl_client_add_object(client, &desktop_shell_interface,
2319 &desktop_shell_implementation,
2320 id, shell);
2321
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002322 if (client == shell->child.client) {
2323 resource->destroy = unbind_desktop_shell;
2324 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002325 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002326 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002327
2328 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2329 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002330 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002331}
2332
Pekka Paalanen6e168112011-11-24 11:34:05 +02002333static void
2334screensaver_set_surface(struct wl_client *client,
2335 struct wl_resource *resource,
2336 struct wl_resource *shell_surface_resource,
2337 struct wl_resource *output_resource)
2338{
Tiago Vignattibe143262012-04-16 17:31:41 +03002339 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002340 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002341 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002342
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002343 surface->next_type = SHELL_SURFACE_SCREENSAVER;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002344
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002345 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002346 surface->output = output;
2347 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002348}
2349
2350static const struct screensaver_interface screensaver_implementation = {
2351 screensaver_set_surface
2352};
2353
2354static void
2355unbind_screensaver(struct wl_resource *resource)
2356{
Tiago Vignattibe143262012-04-16 17:31:41 +03002357 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002358
Pekka Paalanen77346a62011-11-30 16:26:35 +02002359 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002360 free(resource);
2361}
2362
2363static void
2364bind_screensaver(struct wl_client *client,
2365 void *data, uint32_t version, uint32_t id)
2366{
Tiago Vignattibe143262012-04-16 17:31:41 +03002367 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002368 struct wl_resource *resource;
2369
2370 resource = wl_client_add_object(client, &screensaver_interface,
2371 &screensaver_implementation,
2372 id, shell);
2373
Pekka Paalanen77346a62011-11-30 16:26:35 +02002374 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02002375 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002376 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002377 return;
2378 }
2379
2380 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2381 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002382 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002383}
2384
Kristian Høgsberg07045392012-02-19 18:52:44 -05002385struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03002386 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002387 struct weston_surface *current;
2388 struct wl_listener listener;
2389 struct wl_keyboard_grab grab;
2390};
2391
2392static void
2393switcher_next(struct switcher *switcher)
2394{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002395 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002396 struct weston_surface *surface;
2397 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002398 struct shell_surface *shsurf;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002399
2400 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002401 switch (get_shell_surface_type(surface)) {
2402 case SHELL_SURFACE_TOPLEVEL:
2403 case SHELL_SURFACE_FULLSCREEN:
2404 case SHELL_SURFACE_MAXIMIZED:
2405 if (first == NULL)
2406 first = surface;
2407 if (prev == switcher->current)
2408 next = surface;
2409 prev = surface;
Scott Moreau02709af2012-05-22 01:54:10 -06002410 surface->alpha = 0.25;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05002411 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002412 weston_surface_damage(surface);
2413 break;
2414 default:
2415 break;
2416 }
Alex Wu1659daa2012-04-01 20:13:09 +08002417
2418 if (is_black_surface(surface, NULL)) {
Scott Moreau02709af2012-05-22 01:54:10 -06002419 surface->alpha = 0.25;
Alex Wu1659daa2012-04-01 20:13:09 +08002420 surface->geometry.dirty = 1;
2421 weston_surface_damage(surface);
2422 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05002423 }
2424
2425 if (next == NULL)
2426 next = first;
2427
Alex Wu07b26062012-03-12 16:06:01 +08002428 if (next == NULL)
2429 return;
2430
Kristian Høgsberg07045392012-02-19 18:52:44 -05002431 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002432 wl_signal_add(&next->surface.resource.destroy_signal,
2433 &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002434
2435 switcher->current = next;
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002436 next->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08002437
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002438 shsurf = get_shell_surface(switcher->current);
2439 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002440 shsurf->fullscreen.black_surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002441}
2442
2443static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002444switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002445{
2446 struct switcher *switcher =
2447 container_of(listener, struct switcher, listener);
2448
2449 switcher_next(switcher);
2450}
2451
2452static void
2453switcher_destroy(struct switcher *switcher, uint32_t time)
2454{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002455 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002456 struct weston_surface *surface;
Daniel Stone37816df2012-05-16 18:45:18 +01002457 struct wl_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002458
2459 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002460 surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002461 weston_surface_damage(surface);
2462 }
2463
Alex Wu07b26062012-03-12 16:06:01 +08002464 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01002465 activate(switcher->shell, switcher->current,
2466 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002467 wl_list_remove(&switcher->listener.link);
Daniel Stone37816df2012-05-16 18:45:18 +01002468 wl_keyboard_end_grab(keyboard);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002469 free(switcher);
2470}
2471
2472static void
2473switcher_key(struct wl_keyboard_grab *grab,
Daniel Stoneda5b93c2012-05-04 11:21:54 +01002474 uint32_t time, uint32_t key, uint32_t state)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002475{
2476 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01002477 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002478
Daniel Stone37816df2012-05-16 18:45:18 +01002479 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002480 switcher_destroy(switcher, time);
2481 } else if (key == KEY_TAB && state) {
2482 switcher_next(switcher);
2483 }
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04002484}
Kristian Høgsberg07045392012-02-19 18:52:44 -05002485
2486static const struct wl_keyboard_grab_interface switcher_grab = {
2487 switcher_key
2488};
2489
2490static void
Daniel Stone37816df2012-05-16 18:45:18 +01002491switcher_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002492 uint32_t key, uint32_t button, uint32_t axis,
Daniel Stonee5a01202012-05-04 11:21:57 +01002493 int32_t value, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002494{
Tiago Vignattibe143262012-04-16 17:31:41 +03002495 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002496 struct switcher *switcher;
2497
2498 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002499 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002500 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002501 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002502 wl_list_init(&switcher->listener.link);
2503
2504 switcher->grab.interface = &switcher_grab;
Daniel Stone37816df2012-05-16 18:45:18 +01002505 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
2506 wl_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002507 switcher_next(switcher);
2508}
2509
Pekka Paalanen3c647232011-12-22 13:43:43 +02002510static void
Daniel Stone37816df2012-05-16 18:45:18 +01002511backlight_binding(struct wl_seat *seat, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002512 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002513{
2514 struct weston_compositor *compositor = data;
2515 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002516 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002517
2518 /* TODO: we're limiting to simple use cases, where we assume just
2519 * control on the primary display. We'd have to extend later if we
2520 * ever get support for setting backlights on random desktop LCD
2521 * panels though */
2522 output = get_default_output(compositor);
2523 if (!output)
2524 return;
2525
2526 if (!output->set_backlight)
2527 return;
2528
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002529 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2530 backlight_new = output->backlight_current - 25;
2531 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2532 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002533
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002534 if (backlight_new < 5)
2535 backlight_new = 5;
2536 if (backlight_new > 255)
2537 backlight_new = 255;
2538
2539 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002540 output->set_backlight(output, output->backlight_current);
2541}
2542
2543static void
Daniel Stone37816df2012-05-16 18:45:18 +01002544debug_repaint_binding(struct wl_seat *seat, uint32_t time,
Daniel Stonee5a01202012-05-04 11:21:57 +01002545 uint32_t key, uint32_t button, uint32_t axis,
2546 int32_t value, void *data)
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002547{
Tiago Vignattibe143262012-04-16 17:31:41 +03002548 struct desktop_shell *shell = data;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002549 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002550 struct weston_surface *surface;
2551
2552 if (shell->debug_repaint_surface) {
2553 weston_surface_destroy(shell->debug_repaint_surface);
2554 shell->debug_repaint_surface = NULL;
2555 } else {
2556 surface = weston_surface_create(compositor);
2557 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2558 weston_surface_configure(surface, 0, 0, 8192, 8192);
2559 wl_list_insert(&compositor->fade_layer.surface_list,
2560 &surface->layer_link);
2561 weston_surface_assign_output(surface);
2562 pixman_region32_init(&surface->input);
2563
2564 /* Here's the dirty little trick that makes the
2565 * repaint debugging work: we force an
2566 * update_transform first to update dependent state
2567 * and clear the geometry.dirty bit. Then we clear
2568 * the surface damage so it only gets repainted
2569 * piecewise as we repaint other things. */
2570
2571 weston_surface_update_transform(surface);
2572 pixman_region32_fini(&surface->damage);
2573 pixman_region32_init(&surface->damage);
2574 shell->debug_repaint_surface = surface;
2575 }
2576}
2577
2578static void
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04002579force_kill_binding(struct wl_seat *seat, uint32_t time,
2580 uint32_t key, uint32_t button, uint32_t axis,
2581 int32_t value, void *data)
2582{
2583 struct wl_client *client;
2584 pid_t pid;
2585 uid_t uid;
2586 gid_t gid;
2587
2588 if (value == 1) {
2589 client = seat->keyboard->focus->resource.client;
2590 wl_client_get_credentials(client, &pid, &uid, &gid);
2591
2592 kill(pid, SIGKILL);
2593 }
2594}
2595
2596static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002597shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02002598{
Tiago Vignattibe143262012-04-16 17:31:41 +03002599 struct desktop_shell *shell =
2600 container_of(listener, struct desktop_shell, destroy_listener);
Pekka Paalanen3c647232011-12-22 13:43:43 +02002601
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02002602 if (shell->child.client)
2603 wl_client_destroy(shell->child.client);
2604
Kristian Høgsberg88c16072012-05-16 08:04:19 -04002605 wl_list_remove(&shell->lock_listener.link);
2606 wl_list_remove(&shell->unlock_listener.link);
2607
Pekka Paalanen3c647232011-12-22 13:43:43 +02002608 free(shell->screensaver.path);
2609 free(shell);
2610}
2611
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002612static void
2613shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
2614{
2615 uint32_t mod;
2616
2617 /* fixed bindings */
2618 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
2619 MODIFIER_CTRL | MODIFIER_ALT,
2620 terminate_binding, ec);
2621 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
2622 click_to_activate_binding, shell);
2623 weston_compositor_add_binding(ec, 0, 0,
Daniel Stone37816df2012-05-16 18:45:18 +01002624 WL_POINTER_AXIS_VERTICAL_SCROLL,
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002625 MODIFIER_SUPER | MODIFIER_ALT,
2626 surface_opacity_binding, NULL);
2627 weston_compositor_add_binding(ec, 0, 0,
Daniel Stone37816df2012-05-16 18:45:18 +01002628 WL_POINTER_AXIS_VERTICAL_SCROLL,
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002629 MODIFIER_SUPER, zoom_binding, NULL);
2630
2631 /* configurable bindings */
2632 mod = shell->binding_modifier;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002633 weston_compositor_add_binding(ec, KEY_PAGEUP, 0, 0, mod,
2634 zoom_binding, NULL);
2635 weston_compositor_add_binding(ec, KEY_PAGEDOWN, 0, 0, mod,
2636 zoom_binding, NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002637 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod,
2638 move_binding, shell);
2639 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod,
2640 resize_binding, shell);
2641 weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod,
2642 rotate_binding, NULL);
2643 weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod,
2644 switcher_binding, shell);
2645 weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod,
2646 backlight_binding, ec);
2647 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
2648 backlight_binding, ec);
2649 weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod,
2650 backlight_binding, ec);
2651 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
2652 backlight_binding, ec);
2653 weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod,
2654 debug_repaint_binding, shell);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04002655 weston_compositor_add_binding(ec, KEY_K, 0, 0, mod,
2656 force_kill_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002657}
2658
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002659int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002660shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002661
Kristian Høgsberg1c562182011-05-02 22:09:20 -04002662WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002663shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002664{
Tiago Vignattibe143262012-04-16 17:31:41 +03002665 struct desktop_shell *shell;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002666
2667 shell = malloc(sizeof *shell);
2668 if (shell == NULL)
2669 return -1;
2670
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04002671 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002672 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002673
2674 shell->destroy_listener.notify = shell_destroy;
2675 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2676 shell->lock_listener.notify = lock;
2677 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2678 shell->unlock_listener.notify = unlock;
2679 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06002680 ec->ping_handler = ping_handler;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002681 ec->shell_interface.create_shell_surface = create_shell_surface;
2682 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04002683 ec->shell_interface.set_transient = set_transient;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002684 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04002685 ec->shell_interface.resize = surface_resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002686
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002687 wl_list_init(&shell->backgrounds);
2688 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002689 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002690
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002691 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2692 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2693 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2694 weston_layer_init(&shell->background_layer,
2695 &shell->toplevel_layer.link);
2696 wl_list_init(&shell->lock_layer.surface_list);
2697
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002698 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002699
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002700 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2701 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002702 return -1;
2703
Kristian Høgsberg75840622011-09-06 13:48:16 -04002704 if (wl_display_add_global(ec->wl_display,
2705 &desktop_shell_interface,
2706 shell, bind_desktop_shell) == NULL)
2707 return -1;
2708
Pekka Paalanen6e168112011-11-24 11:34:05 +02002709 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2710 shell, bind_screensaver) == NULL)
2711 return -1;
2712
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002713 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002714 if (launch_desktop_shell_process(shell) != 0)
2715 return -1;
2716
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002717 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002718
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002719 return 0;
2720}