blob: 40e84b6f96c28612644068d11c1f1e853dd2bb93 [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
Daniel Stone496ca172012-05-30 16:31:42 +0100245static enum weston_keyboard_modifier
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300246get_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 Stone4dbadb12012-05-30 16:31:51 +0100338 uint32_t time, uint32_t button, uint32_t state_w)
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;
Daniel Stone4dbadb12012-05-30 16:31:51 +0100343 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500344
Daniel Stone4dbadb12012-05-30 16:31:51 +0100345 if (pointer->button_count == 0 &&
346 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300347 shell_grab_finish(shell_grab);
Daniel Stone37816df2012-05-16 18:45:18 +0100348 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500349 free(grab);
350 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500351}
352
Scott Moreau447013d2012-02-18 05:05:29 -0700353static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500354 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500355 move_grab_motion,
356 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500357};
358
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600359static void
360unresponsive_surface_fade(struct shell_surface *shsurf, bool reverse)
361{
362 shsurf->unresponsive_animation.fading_in = reverse ? 0 : 1;
363
364 if(!shsurf->unresponsive_animation.exists) {
365 wl_list_insert(&shsurf->surface->compositor->animation_list,
366 &shsurf->unresponsive_animation.current.link);
367 shsurf->unresponsive_animation.exists = 1;
368 shsurf->unresponsive_animation.timestamp = weston_compositor_get_time();
369 weston_surface_damage(shsurf->surface);
370 }
371}
372
373static void
Scott Moreau9521d5e2012-04-19 13:06:17 -0600374unresponsive_fade_frame(struct weston_animation *animation,
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600375 struct weston_output *output, uint32_t msecs)
376{
377 struct shell_surface *shsurf =
378 container_of(animation, struct shell_surface, unresponsive_animation.current);
379 struct weston_surface *surface = shsurf->surface;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600380 unsigned int step = 8;
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600381
382 if (!surface || !shsurf)
383 return;
384
385 if (shsurf->unresponsive_animation.fading_in) {
386 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
387 if (surface->saturation > 1)
388 surface->saturation -= 5;
389 if (surface->brightness > 200)
390 surface->brightness--;
391
392 shsurf->unresponsive_animation.timestamp += step;
393 }
394
395 if (surface->saturation <= 1 && surface->brightness <= 200) {
396 wl_list_remove(&shsurf->unresponsive_animation.current.link);
397 shsurf->unresponsive_animation.exists = 0;
398 }
399 }
400 else {
401 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
402 if (surface->saturation < 255)
403 surface->saturation += 5;
404 if (surface->brightness < 255)
405 surface->brightness++;
406
407 shsurf->unresponsive_animation.timestamp += step;
408 }
409
410 if (surface->saturation >= 255 && surface->brightness >= 255) {
411 surface->saturation = surface->brightness = 255;
412 wl_list_remove(&shsurf->unresponsive_animation.current.link);
413 shsurf->unresponsive_animation.exists = 0;
414 }
415 }
416
417 surface->geometry.dirty = 1;
418 weston_surface_damage(surface);
419}
420
Scott Moreau9521d5e2012-04-19 13:06:17 -0600421static void
422ping_timer_destroy(struct shell_surface *shsurf)
423{
424 if (!shsurf || !shsurf->ping_timer)
425 return;
426
427 if (shsurf->ping_timer->source)
428 wl_event_source_remove(shsurf->ping_timer->source);
429
430 free(shsurf->ping_timer);
431 shsurf->ping_timer = NULL;
432}
433
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400434static int
Scott Moreauff1db4a2012-04-17 19:06:18 -0600435ping_timeout_handler(void *data)
436{
437 struct shell_surface *shsurf = data;
438
Scott Moreau9521d5e2012-04-19 13:06:17 -0600439 /* Client is not responding */
440 shsurf->unresponsive = 1;
441 unresponsive_surface_fade(shsurf, false);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600442
443 return 1;
444}
445
446static void
447ping_handler(struct weston_surface *surface, uint32_t serial)
448{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -0400449 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600450 struct wl_event_loop *loop;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600451 int ping_timeout = 2500;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600452
453 if (!shsurf)
454 return;
Kristian Høgsbergca535c12012-04-21 23:20:07 -0400455 if (!shsurf->resource.client)
456 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600457
458 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +0300459 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600460 if (!shsurf->ping_timer)
461 return;
462
463 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600464 loop = wl_display_get_event_loop(surface->compositor->wl_display);
465 shsurf->ping_timer->source =
466 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
467 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
468
469 wl_shell_surface_send_ping(&shsurf->resource, serial);
470 }
471}
472
473static void
474shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
475 uint32_t serial)
476{
477 struct shell_surface *shsurf = resource->data;
478
Scott Moreauff1db4a2012-04-17 19:06:18 -0600479 if (shsurf->ping_timer->serial == serial) {
Scott Moreauc3e54eb2012-04-17 19:06:20 -0600480 if (shsurf->unresponsive) {
481 /* Received pong from previously unresponsive client */
482 unresponsive_surface_fade(shsurf, true);
483 }
Scott Moreauff1db4a2012-04-17 19:06:18 -0600484 shsurf->unresponsive = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -0600485 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -0600486 }
487}
488
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400489static void
490shell_surface_set_title(struct wl_client *client,
491 struct wl_resource *resource, const char *title)
492{
493 struct shell_surface *shsurf = resource->data;
494
495 free(shsurf->title);
496 shsurf->title = strdup(title);
497}
498
499static void
500shell_surface_set_class(struct wl_client *client,
501 struct wl_resource *resource, const char *class)
502{
503 struct shell_surface *shsurf = resource->data;
504
505 free(shsurf->class);
506 shsurf->class = strdup(class);
507}
508
Scott Moreauff1db4a2012-04-17 19:06:18 -0600509static int
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400510surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500511{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500512 struct weston_move_grab *move;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300513
514 if (!shsurf)
515 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500516
517 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400518 if (!move)
519 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500520
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300521 shell_grab_init(&move->base, &move_grab_interface, shsurf);
522
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400523 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
Daniel Stone37816df2012-05-16 18:45:18 +0100524 ws->seat.pointer->grab_x;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400525 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
Daniel Stone37816df2012-05-16 18:45:18 +0100526 ws->seat.pointer->grab_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500527
Daniel Stone37816df2012-05-16 18:45:18 +0100528 wl_pointer_start_grab(ws->seat.pointer, &move->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500529
Daniel Stone37816df2012-05-16 18:45:18 +0100530 wl_pointer_set_focus(ws->seat.pointer, NULL,
531 wl_fixed_from_int(0),
532 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400533
534 return 0;
535}
536
537static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200538shell_surface_move(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100539 struct wl_resource *seat_resource, uint32_t serial)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400540{
Daniel Stone37816df2012-05-16 18:45:18 +0100541 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200542 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400543
Daniel Stone37816df2012-05-16 18:45:18 +0100544 if (ws->seat.pointer->button_count == 0 ||
545 ws->seat.pointer->grab_serial != serial ||
546 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500547 return;
548
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -0400549 if (surface_move(shsurf, ws) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400550 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500551}
552
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500553struct weston_resize_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300554 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500555 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200556 int32_t width, height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500557};
558
559static void
Scott Moreau447013d2012-02-18 05:05:29 -0700560resize_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +0100561 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500562{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500563 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100564 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400565 struct shell_surface *shsurf = resize->base.shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500566 int32_t width, height;
Daniel Stone103db7f2012-05-08 17:17:55 +0100567 wl_fixed_t from_x, from_y;
568 wl_fixed_t to_x, to_y;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200569
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400570 if (!shsurf)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300571 return;
572
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400573 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100574 pointer->grab_x, pointer->grab_y,
Daniel Stone103db7f2012-05-08 17:17:55 +0100575 &from_x, &from_y);
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400576 weston_surface_from_global_fixed(shsurf->surface,
Daniel Stone37816df2012-05-16 18:45:18 +0100577 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500578
Daniel Stone103db7f2012-05-08 17:17:55 +0100579 width = resize->width;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200580 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100581 width += wl_fixed_to_int(from_x - to_x);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200582 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100583 width += wl_fixed_to_int(to_x - from_x);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500584 }
585
Daniel Stone103db7f2012-05-08 17:17:55 +0100586 height = resize->height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200587 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100588 height += wl_fixed_to_int(from_y - to_y);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200589 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Daniel Stone103db7f2012-05-08 17:17:55 +0100590 height += wl_fixed_to_int(to_y - from_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500591 }
592
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400593 shsurf->client->send_configure(shsurf->surface,
594 resize->edges, width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500595}
596
597static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400598send_configure(struct weston_surface *surface,
599 uint32_t edges, int32_t width, int32_t height)
600{
601 struct shell_surface *shsurf = get_shell_surface(surface);
602
603 wl_shell_surface_send_configure(&shsurf->resource,
604 edges, width, height);
605}
606
607static const struct weston_shell_client shell_client = {
608 send_configure
609};
610
611static void
Scott Moreau447013d2012-02-18 05:05:29 -0700612resize_grab_button(struct wl_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100613 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500614{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300615 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100616 struct wl_pointer *pointer = grab->pointer;
Daniel Stone4dbadb12012-05-30 16:31:51 +0100617 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500618
Daniel Stone4dbadb12012-05-30 16:31:51 +0100619 if (pointer->button_count == 0 &&
620 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300621 shell_grab_finish(&resize->base);
Daniel Stone37816df2012-05-16 18:45:18 +0100622 wl_pointer_end_grab(pointer);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500623 free(grab);
624 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500625}
626
Scott Moreau447013d2012-02-18 05:05:29 -0700627static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500628 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500629 resize_grab_motion,
630 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500631};
632
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400633static int
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400634surface_resize(struct shell_surface *shsurf,
635 struct weston_seat *ws, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500636{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500637 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500638
Alex Wu4539b082012-03-01 12:57:46 +0800639 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
640 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500641
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200642 if (edges == 0 || edges > 15 ||
643 (edges & 3) == 3 || (edges & 12) == 12)
644 return 0;
645
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500646 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400647 if (!resize)
648 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500649
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300650 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
651
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500652 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200653 resize->width = shsurf->surface->geometry.width;
654 resize->height = shsurf->surface->geometry.height;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400655
Daniel Stone37816df2012-05-16 18:45:18 +0100656 wl_pointer_start_grab(ws->seat.pointer, &resize->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500657
Daniel Stone37816df2012-05-16 18:45:18 +0100658 wl_pointer_set_focus(ws->seat.pointer, NULL,
659 wl_fixed_from_int(0),
660 wl_fixed_from_int(0));
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400661
662 return 0;
663}
664
665static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200666shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +0100667 struct wl_resource *seat_resource, uint32_t serial,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200668 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400669{
Daniel Stone37816df2012-05-16 18:45:18 +0100670 struct weston_seat *ws = seat_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200671 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400672
Alex Wu4539b082012-03-01 12:57:46 +0800673 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
674 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400675
Daniel Stone37816df2012-05-16 18:45:18 +0100676 if (ws->seat.pointer->button_count == 0 ||
677 ws->seat.pointer->grab_serial != serial ||
678 ws->seat.pointer->focus != &shsurf->surface->surface)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500679 return;
680
Kristian Høgsbergc1693f22012-05-22 16:56:23 -0400681 if (surface_resize(shsurf, ws, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400682 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500683}
684
Juan Zhao96879df2012-02-07 08:45:41 +0800685static struct weston_output *
686get_default_output(struct weston_compositor *compositor)
687{
688 return container_of(compositor->output_list.next,
689 struct weston_output, link);
690}
691
Alex Wu4539b082012-03-01 12:57:46 +0800692static void
693shell_unset_fullscreen(struct shell_surface *shsurf)
694{
695 /* undo all fullscreen things here */
Alex Wubd3354b2012-04-17 17:20:49 +0800696 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
697 shell_surface_is_top_fullscreen(shsurf)) {
698 weston_output_switch_mode(shsurf->fullscreen_output,
699 shsurf->fullscreen_output->origin);
700 }
Alex Wu4539b082012-03-01 12:57:46 +0800701 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
702 shsurf->fullscreen.framerate = 0;
703 wl_list_remove(&shsurf->fullscreen.transform.link);
704 wl_list_init(&shsurf->fullscreen.transform.link);
Alex Wubd3354b2012-04-17 17:20:49 +0800705 if (shsurf->fullscreen.black_surface)
706 weston_surface_destroy(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800707 shsurf->fullscreen.black_surface = NULL;
708 shsurf->fullscreen_output = NULL;
Alex Wu4539b082012-03-01 12:57:46 +0800709 weston_surface_set_position(shsurf->surface,
710 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800711 if (shsurf->saved_rotation_valid) {
712 wl_list_insert(&shsurf->surface->geometry.transformation_list,
713 &shsurf->rotation.transform.link);
714 shsurf->saved_rotation_valid = false;
715 }
Alex Wu4539b082012-03-01 12:57:46 +0800716}
717
Pekka Paalanen98262232011-12-01 10:42:22 +0200718static int
719reset_shell_surface_type(struct shell_surface *surface)
720{
721 switch (surface->type) {
722 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800723 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200724 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800725 case SHELL_SURFACE_MAXIMIZED:
726 surface->output = get_default_output(surface->surface->compositor);
727 weston_surface_set_position(surface->surface,
728 surface->saved_x,
729 surface->saved_y);
730 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200731 case SHELL_SURFACE_PANEL:
732 case SHELL_SURFACE_BACKGROUND:
733 wl_list_remove(&surface->link);
734 wl_list_init(&surface->link);
735 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200736 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200737 case SHELL_SURFACE_LOCK:
738 wl_resource_post_error(&surface->resource,
739 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200740 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200741 return -1;
742 case SHELL_SURFACE_NONE:
743 case SHELL_SURFACE_TOPLEVEL:
744 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500745 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200746 break;
747 }
748
749 surface->type = SHELL_SURFACE_NONE;
750 return 0;
751}
752
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500753static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400754set_surface_type(struct shell_surface *shsurf)
755{
756 struct weston_surface *surface = shsurf->surface;
757 struct shell_surface *pshsurf = shsurf->parent;
758 struct weston_surface *pes;
759 struct shell_surface *priv;
760 struct desktop_shell *shell = shsurf->shell;
761
762 reset_shell_surface_type(shsurf);
763
764 shsurf->type = shsurf->next_type;
765 shsurf->next_type = SHELL_SURFACE_NONE;
766
767 switch (shsurf->type) {
768 case SHELL_SURFACE_TOPLEVEL:
769 break;
770 case SHELL_SURFACE_TRANSIENT:
771 pes = pshsurf->surface;
772 weston_surface_set_position(surface,
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300773 pes->geometry.x + shsurf->transient.x,
774 pes->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400775 break;
776
777 case SHELL_SURFACE_MAXIMIZED:
778 shsurf->saved_x = surface->geometry.x;
779 shsurf->saved_y = surface->geometry.y;
780 shsurf->saved_position_valid = true;
781 break;
782
783 case SHELL_SURFACE_FULLSCREEN:
784 shsurf->saved_x = surface->geometry.x;
785 shsurf->saved_y = surface->geometry.y;
786 shsurf->saved_position_valid = true;
787
788 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
789 wl_list_remove(&shsurf->rotation.transform.link);
790 wl_list_init(&shsurf->rotation.transform.link);
791 shsurf->surface->geometry.dirty = 1;
792 shsurf->saved_rotation_valid = true;
793 }
794 break;
795
796 case SHELL_SURFACE_BACKGROUND:
797 wl_list_for_each(priv, &shell->backgrounds, link) {
798 if (priv->output == shsurf->output) {
799 priv->surface->output = NULL;
800 wl_list_remove(&priv->surface->layer_link);
801 wl_list_remove(&priv->link);
802 break;
803 }
804 }
805
806 wl_list_insert(&shell->backgrounds, &shsurf->link);
807
808 weston_surface_set_position(surface, shsurf->output->x,
809 shsurf->output->y);
810 break;
811
812 case SHELL_SURFACE_PANEL:
813 wl_list_for_each(priv, &shell->panels, link) {
814 if (priv->output == shsurf->output) {
815 priv->surface->output = NULL;
816 wl_list_remove(&priv->surface->layer_link);
817 wl_list_remove(&priv->link);
818 break;
819 }
820 }
821
822 wl_list_insert(&shell->panels, &shsurf->link);
823
824 weston_surface_set_position(surface, shsurf->output->x,
825 shsurf->output->y);
826 break;
827
828 default:
829 break;
830 }
831}
832
833static void
Tiago Vignattibc052c92012-04-19 16:18:18 +0300834set_toplevel(struct shell_surface *shsurf)
835{
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400836 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Tiago Vignattibc052c92012-04-19 16:18:18 +0300837}
838
839static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200840shell_surface_set_toplevel(struct wl_client *client,
841 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400842{
Pekka Paalanen98262232011-12-01 10:42:22 +0200843 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400844
Tiago Vignattibc052c92012-04-19 16:18:18 +0300845 set_toplevel(surface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400846}
847
848static void
Tiago Vignatti491bac12012-05-18 16:37:43 -0400849set_transient(struct shell_surface *shsurf,
850 struct shell_surface *pshsurf, int x, int y, uint32_t flags)
851{
852 /* assign to parents output */
853 shsurf->parent = pshsurf;
854 shsurf->transient.x = x;
855 shsurf->transient.y = y;
856 shsurf->transient.flags = flags;
857 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
858}
859
860static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200861shell_surface_set_transient(struct wl_client *client,
862 struct wl_resource *resource,
863 struct wl_resource *parent_resource,
864 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400865{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200866 struct shell_surface *shsurf = resource->data;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400867 struct shell_surface *pshsurf = parent_resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +0200868
Tiago Vignatti491bac12012-05-18 16:37:43 -0400869 set_transient(shsurf, pshsurf, x, y, flags);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400870}
871
Tiago Vignattibe143262012-04-16 17:31:41 +0300872static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +0800873shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200874{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400875 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +0800876}
877
878static int
Tiago Vignattibe143262012-04-16 17:31:41 +0300879get_output_panel_height(struct desktop_shell *shell,
880 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +0800881{
882 struct shell_surface *priv;
883 int panel_height = 0;
884
885 if (!output)
886 return 0;
887
Tiago Vignattibe143262012-04-16 17:31:41 +0300888 wl_list_for_each(priv, &shell->panels, link) {
Juan Zhao96879df2012-02-07 08:45:41 +0800889 if (priv->output == output) {
890 panel_height = priv->surface->geometry.height;
891 break;
892 }
893 }
894 return panel_height;
895}
896
897static void
898shell_surface_set_maximized(struct wl_client *client,
899 struct wl_resource *resource,
900 struct wl_resource *output_resource )
901{
902 struct shell_surface *shsurf = resource->data;
903 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300904 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +0800905 uint32_t edges = 0, panel_height = 0;
906
907 /* get the default output, if the client set it as NULL
908 check whether the ouput is available */
909 if (output_resource)
910 shsurf->output = output_resource->data;
911 else
912 shsurf->output = get_default_output(es->compositor);
913
Tiago Vignattibe143262012-04-16 17:31:41 +0300914 shell = shell_surface_get_shell(shsurf);
915 panel_height = get_output_panel_height(shell, es->output);
Juan Zhao96879df2012-02-07 08:45:41 +0800916 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500917
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400918 shsurf->client->send_configure(shsurf->surface, edges,
919 es->output->current->width,
920 es->output->current->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +0800921
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400922 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200923}
924
Alex Wu21858432012-04-01 20:13:08 +0800925static void
926black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
927
Alex Wu4539b082012-03-01 12:57:46 +0800928static struct weston_surface *
929create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +0800930 struct weston_surface *fs_surface,
Alex Wu4539b082012-03-01 12:57:46 +0800931 GLfloat x, GLfloat y, int w, int h)
932{
933 struct weston_surface *surface = NULL;
934
935 surface = weston_surface_create(ec);
936 if (surface == NULL) {
937 fprintf(stderr, "no memory\n");
938 return NULL;
939 }
940
Alex Wu21858432012-04-01 20:13:08 +0800941 surface->configure = black_surface_configure;
942 surface->private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +0800943 weston_surface_configure(surface, x, y, w, h);
944 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
945 return surface;
946}
947
948/* Create black surface and append it to the associated fullscreen surface.
949 * Handle size dismatch and positioning according to the method. */
950static void
951shell_configure_fullscreen(struct shell_surface *shsurf)
952{
953 struct weston_output *output = shsurf->fullscreen_output;
954 struct weston_surface *surface = shsurf->surface;
955 struct weston_matrix *matrix;
956 float scale;
957
958 center_on_output(surface, output);
959
960 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500961 shsurf->fullscreen.black_surface =
962 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +0800963 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500964 output->x, output->y,
965 output->current->width,
966 output->current->height);
967
968 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
969 wl_list_insert(&surface->layer_link,
970 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800971 shsurf->fullscreen.black_surface->output = output;
972
973 switch (shsurf->fullscreen.type) {
974 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
975 break;
976 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
977 matrix = &shsurf->fullscreen.transform.matrix;
978 weston_matrix_init(matrix);
979 scale = (float)output->current->width/(float)surface->geometry.width;
980 weston_matrix_scale(matrix, scale, scale, 1);
981 wl_list_remove(&shsurf->fullscreen.transform.link);
982 wl_list_insert(surface->geometry.transformation_list.prev,
983 &shsurf->fullscreen.transform.link);
984 weston_surface_set_position(surface, output->x, output->y);
985 break;
986 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +0800987 if (shell_surface_is_top_fullscreen(shsurf)) {
988 struct weston_mode mode = {0,
989 surface->geometry.width,
990 surface->geometry.height,
991 shsurf->fullscreen.framerate};
992
993 if (weston_output_switch_mode(output, &mode) == 0) {
994 weston_surface_configure(shsurf->fullscreen.black_surface,
995 output->x, output->y,
996 output->current->width,
997 output->current->height);
998 weston_surface_set_position(surface, output->x, output->y);
999 break;
1000 }
1001 }
Alex Wu4539b082012-03-01 12:57:46 +08001002 break;
1003 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1004 break;
1005 default:
1006 break;
1007 }
1008}
1009
1010/* make the fullscreen and black surface at the top */
1011static void
1012shell_stack_fullscreen(struct shell_surface *shsurf)
1013{
Alex Wubd3354b2012-04-17 17:20:49 +08001014 struct weston_output *output = shsurf->fullscreen_output;
Alex Wu4539b082012-03-01 12:57:46 +08001015 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +03001016 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001017
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001018 wl_list_remove(&surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001019 wl_list_insert(&shell->fullscreen_layer.surface_list,
1020 &surface->layer_link);
Alex Wubd3354b2012-04-17 17:20:49 +08001021 weston_surface_damage(surface);
1022
1023 if (!shsurf->fullscreen.black_surface)
1024 shsurf->fullscreen.black_surface =
1025 create_black_surface(surface->compositor,
1026 surface,
1027 output->x, output->y,
1028 output->current->width,
1029 output->current->height);
1030
1031 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001032 wl_list_insert(&surface->layer_link,
1033 &shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001034 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +08001035}
1036
1037static void
1038shell_map_fullscreen(struct shell_surface *shsurf)
1039{
Alex Wu4539b082012-03-01 12:57:46 +08001040 shell_stack_fullscreen(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001041 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001042}
1043
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001044static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001045shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -05001046 struct wl_resource *resource,
1047 uint32_t method,
1048 uint32_t framerate,
1049 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001050{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001051 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001052 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +08001053
1054 if (output_resource)
1055 shsurf->output = output_resource->data;
1056 else
1057 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001058
Alex Wu4539b082012-03-01 12:57:46 +08001059 shsurf->fullscreen_output = shsurf->output;
1060 shsurf->fullscreen.type = method;
1061 shsurf->fullscreen.framerate = framerate;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001062 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
Alex Wu4539b082012-03-01 12:57:46 +08001063
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001064 shsurf->client->send_configure(shsurf->surface, 0,
1065 shsurf->output->current->width,
1066 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001067}
1068
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001069static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001070popup_grab_focus(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001071 struct wl_surface *surface,
1072 wl_fixed_t x,
1073 wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001074{
Daniel Stone37816df2012-05-16 18:45:18 +01001075 struct wl_pointer *pointer = grab->pointer;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001076 struct shell_surface *priv =
1077 container_of(grab, struct shell_surface, popup.grab);
1078 struct wl_client *client = priv->surface->surface.resource.client;
1079
Pekka Paalanencb108432012-01-19 16:25:40 +02001080 if (surface && surface->resource.client == client) {
Daniel Stone37816df2012-05-16 18:45:18 +01001081 wl_pointer_set_focus(pointer, surface, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001082 grab->focus = surface;
1083 } else {
Daniel Stone37816df2012-05-16 18:45:18 +01001084 wl_pointer_set_focus(pointer, NULL,
1085 wl_fixed_from_int(0),
1086 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001087 grab->focus = NULL;
1088 }
1089}
1090
1091static void
Scott Moreau447013d2012-02-18 05:05:29 -07001092popup_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001093 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001094{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001095 struct wl_resource *resource;
1096
Daniel Stone37816df2012-05-16 18:45:18 +01001097 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001098 if (resource)
Daniel Stone37816df2012-05-16 18:45:18 +01001099 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001100}
1101
1102static void
Scott Moreau447013d2012-02-18 05:05:29 -07001103popup_grab_button(struct wl_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001104 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001105{
1106 struct wl_resource *resource;
1107 struct shell_surface *shsurf =
1108 container_of(grab, struct shell_surface, popup.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001109 struct wl_display *display;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001110 enum wl_pointer_button_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001111 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001112
Daniel Stone37816df2012-05-16 18:45:18 +01001113 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001114 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001115 display = wl_client_get_display(resource->client);
1116 serial = wl_display_get_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +01001117 wl_pointer_send_button(resource, serial, time, button, state);
Daniel Stone4dbadb12012-05-30 16:31:51 +01001118 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001119 (shsurf->popup.initial_up ||
Daniel Stone37816df2012-05-16 18:45:18 +01001120 time - shsurf->popup.seat->pointer->grab_time > 500)) {
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001121 wl_shell_surface_send_popup_done(&shsurf->resource);
Daniel Stone37816df2012-05-16 18:45:18 +01001122 wl_pointer_end_grab(grab->pointer);
1123 shsurf->popup.grab.pointer = NULL;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001124 }
1125
Daniel Stone4dbadb12012-05-30 16:31:51 +01001126 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001127 shsurf->popup.initial_up = 1;
1128}
1129
Scott Moreau447013d2012-02-18 05:05:29 -07001130static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001131 popup_grab_focus,
1132 popup_grab_motion,
1133 popup_grab_button,
1134};
1135
1136static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001137shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001138{
Daniel Stone37816df2012-05-16 18:45:18 +01001139 struct wl_seat *seat = shsurf->popup.seat;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001140 struct weston_surface *es = shsurf->surface;
1141 struct weston_surface *parent = shsurf->parent->surface;
1142
1143 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001144 shsurf->popup.grab.interface = &popup_grab_interface;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001145
Pekka Paalanen938269a2012-02-07 14:19:01 +02001146 weston_surface_update_transform(parent);
1147 if (parent->transform.enabled) {
1148 shsurf->popup.parent_transform.matrix =
1149 parent->transform.matrix;
1150 } else {
1151 /* construct x, y translation matrix */
1152 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1153 shsurf->popup.parent_transform.matrix.d[12] =
1154 parent->geometry.x;
1155 shsurf->popup.parent_transform.matrix.d[13] =
1156 parent->geometry.y;
1157 }
1158 wl_list_insert(es->geometry.transformation_list.prev,
1159 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001160 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001161
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001162 shsurf->popup.initial_up = 0;
1163
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001164 /* We don't require the grab to still be active, but if another
1165 * grab has started in the meantime, we end the popup now. */
Daniel Stone37816df2012-05-16 18:45:18 +01001166 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1167 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001168 } else {
1169 wl_shell_surface_send_popup_done(&shsurf->resource);
1170 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001171}
1172
1173static void
1174shell_surface_set_popup(struct wl_client *client,
1175 struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +01001176 struct wl_resource *seat_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001177 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001178 struct wl_resource *parent_resource,
1179 int32_t x, int32_t y, uint32_t flags)
1180{
1181 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001182
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001183 shsurf->type = SHELL_SURFACE_POPUP;
1184 shsurf->parent = parent_resource->data;
Daniel Stone37816df2012-05-16 18:45:18 +01001185 shsurf->popup.seat = seat_resource->data;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001186 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001187 shsurf->popup.x = x;
1188 shsurf->popup.y = y;
1189}
1190
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001191static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06001192 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001193 shell_surface_move,
1194 shell_surface_resize,
1195 shell_surface_set_toplevel,
1196 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001197 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08001198 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001199 shell_surface_set_maximized,
1200 shell_surface_set_title,
1201 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001202};
1203
1204static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001205destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001206{
Daniel Stone37816df2012-05-16 18:45:18 +01001207 if (shsurf->popup.grab.pointer)
1208 wl_pointer_end_grab(shsurf->popup.grab.pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001209
Alex Wubd3354b2012-04-17 17:20:49 +08001210 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1211 shell_surface_is_top_fullscreen(shsurf)) {
1212 weston_output_switch_mode(shsurf->fullscreen_output,
1213 shsurf->fullscreen_output->origin);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001214 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001215
Alex Wuaa08e2d2012-03-05 11:01:40 +08001216 if (shsurf->fullscreen.black_surface)
1217 weston_surface_destroy(shsurf->fullscreen.black_surface);
1218
Alex Wubd3354b2012-04-17 17:20:49 +08001219 /* As destroy_resource() use wl_list_for_each_safe(),
1220 * we can always remove the listener.
1221 */
1222 wl_list_remove(&shsurf->surface_destroy_listener.link);
1223 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001224 ping_timer_destroy(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001225
Rob Bradford579f2932012-05-21 18:04:15 +01001226 if (shsurf->unresponsive_animation.exists)
1227 wl_list_remove(&shsurf->unresponsive_animation.current.link);
1228
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001229 wl_list_remove(&shsurf->link);
1230 free(shsurf);
1231}
1232
1233static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001234shell_destroy_shell_surface(struct wl_resource *resource)
1235{
1236 struct shell_surface *shsurf = resource->data;
1237
1238 destroy_shell_surface(shsurf);
1239}
1240
1241static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001242shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001243{
1244 struct shell_surface *shsurf = container_of(listener,
1245 struct shell_surface,
1246 surface_destroy_listener);
1247
Tiago Vignattibc052c92012-04-19 16:18:18 +03001248 /* tricky way to check if resource was in fact created */
1249 if (shsurf->resource.object.implementation != 0)
1250 wl_resource_destroy(&shsurf->resource);
1251 else
1252 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001253}
1254
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001255static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001256get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001257{
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001258 struct wl_listener *listener;
1259
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001260 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
1261 shell_handle_surface_destroy);
1262 if (listener)
1263 return container_of(listener, struct shell_surface,
1264 surface_destroy_listener);
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02001265
1266 return NULL;
1267}
1268
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001269static void
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001270shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1271
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001272static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001273create_shell_surface(void *shell, struct weston_surface *surface,
1274 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001275{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001276 struct shell_surface *shsurf;
1277
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001278 if (surface->configure) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001279 fprintf(stderr, "surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001280 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001281 }
1282
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001283 shsurf = calloc(1, sizeof *shsurf);
1284 if (!shsurf) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03001285 fprintf(stderr, "no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001286 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001287 }
1288
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001289 surface->configure = shell_surface_configure;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001290 surface->compositor->shell_interface.shell = shell;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001291
Tiago Vignattibc052c92012-04-19 16:18:18 +03001292 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001293 shsurf->unresponsive = 0;
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001294 shsurf->unresponsive_animation.exists = 0;
1295 shsurf->unresponsive_animation.fading_in = 0;
Scott Moreau9521d5e2012-04-19 13:06:17 -06001296 shsurf->unresponsive_animation.current.frame = unresponsive_fade_frame;
Alex Wu4539b082012-03-01 12:57:46 +08001297 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08001298 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001299 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08001300 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1301 shsurf->fullscreen.framerate = 0;
1302 shsurf->fullscreen.black_surface = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001303 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08001304 wl_list_init(&shsurf->fullscreen.transform.link);
1305
Tiago Vignattibc052c92012-04-19 16:18:18 +03001306 wl_signal_init(&shsurf->resource.destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001307 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1308 wl_signal_add(&surface->surface.resource.destroy_signal,
1309 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001310
1311 /* init link so its safe to always remove it in destroy_shell_surface */
1312 wl_list_init(&shsurf->link);
1313
Pekka Paalanen460099f2012-01-20 16:48:25 +02001314 /* empty when not in use */
1315 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001316 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001317
Pekka Paalanen98262232011-12-01 10:42:22 +02001318 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001319 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001320
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001321 shsurf->client = client;
1322
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04001323 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001324}
1325
1326static void
1327shell_get_shell_surface(struct wl_client *client,
1328 struct wl_resource *resource,
1329 uint32_t id,
1330 struct wl_resource *surface_resource)
1331{
1332 struct weston_surface *surface = surface_resource->data;
1333 struct desktop_shell *shell = resource->data;
1334 struct shell_surface *shsurf;
1335
1336 if (get_shell_surface(surface)) {
1337 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001338 WL_DISPLAY_ERROR_INVALID_OBJECT,
1339 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03001340 return;
1341 }
1342
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001343 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001344 if (!shsurf) {
1345 wl_resource_post_error(surface_resource,
1346 WL_DISPLAY_ERROR_INVALID_OBJECT,
1347 "surface->configure already set");
1348 return;
1349 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03001350
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001351 shsurf->resource.destroy = shell_destroy_shell_surface;
1352 shsurf->resource.object.id = id;
1353 shsurf->resource.object.interface = &wl_shell_surface_interface;
1354 shsurf->resource.object.implementation =
1355 (void (**)(void)) &shell_surface_implementation;
1356 shsurf->resource.data = shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001357
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04001358 wl_client_add_resource(client, &shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001359}
1360
1361static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02001362 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001363};
1364
Kristian Høgsberg07937562011-04-12 17:25:42 -04001365static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001366handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02001367{
1368 proc->pid = 0;
1369}
1370
1371static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001372launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001373{
1374 if (shell->screensaver.binding)
1375 return;
1376
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001377 if (!shell->screensaver.path)
1378 return;
1379
Kristian Høgsberg32bed572012-03-01 17:11:36 -05001380 if (shell->screensaver.process.pid != 0) {
1381 fprintf(stderr, "old screensaver still running\n");
1382 return;
1383 }
1384
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001385 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001386 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001387 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001388 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001389}
1390
1391static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001392terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001393{
Pekka Paalanen18027e52011-12-02 16:31:49 +02001394 if (shell->screensaver.process.pid == 0)
1395 return;
1396
1397 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001398}
1399
1400static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001401show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001402{
1403 struct wl_list *list;
1404
1405 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001406 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001407 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001408 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001409
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001410 wl_list_remove(&surface->surface->layer_link);
1411 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001412 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001413 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001414}
1415
1416static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001417hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001418{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001419 wl_list_remove(&surface->surface->layer_link);
1420 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001421 surface->surface->output = NULL;
1422}
1423
1424static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001425desktop_shell_set_background(struct wl_client *client,
1426 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001427 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001428 struct wl_resource *surface_resource)
1429{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001430 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001431
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001432 shsurf->next_type = SHELL_SURFACE_BACKGROUND;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001433 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001434
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001435 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001436 surface_resource,
1437 shsurf->output->current->width,
1438 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001439}
1440
1441static void
1442desktop_shell_set_panel(struct wl_client *client,
1443 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001444 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001445 struct wl_resource *surface_resource)
1446{
Pekka Paalanen068ae942011-11-28 14:11:15 +02001447 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001448
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001449 shsurf->next_type = SHELL_SURFACE_PANEL;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001450 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001451
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001452 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001453 surface_resource,
1454 shsurf->output->current->width,
1455 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001456}
1457
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001458static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001459handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001460{
Tiago Vignattibe143262012-04-16 17:31:41 +03001461 struct desktop_shell *shell =
1462 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001463
1464 fprintf(stderr, "lock surface gone\n");
1465 shell->lock_surface = NULL;
1466}
1467
1468static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001469desktop_shell_set_lock_surface(struct wl_client *client,
1470 struct wl_resource *resource,
1471 struct wl_resource *surface_resource)
1472{
Tiago Vignattibe143262012-04-16 17:31:41 +03001473 struct desktop_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001474 struct shell_surface *surface = surface_resource->data;
1475
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001476 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001477
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001478 if (!shell->locked)
1479 return;
1480
Pekka Paalanen98262232011-12-01 10:42:22 +02001481 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001482
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001483 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1484 wl_signal_add(&surface_resource->destroy_signal,
1485 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001486
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001487 shell->lock_surface->next_type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001488}
1489
1490static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001491resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001492{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001493 struct shell_surface *tmp;
1494
1495 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1496 hide_screensaver(shell, tmp);
1497
1498 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001499
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001500 wl_list_remove(&shell->lock_layer.link);
1501 wl_list_insert(&shell->compositor->cursor_layer.link,
1502 &shell->fullscreen_layer.link);
1503 wl_list_insert(&shell->fullscreen_layer.link,
1504 &shell->panel_layer.link);
1505 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001506
1507 shell->locked = false;
Pekka Paalanen7296e792011-12-07 16:22:00 +02001508 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001509 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001510 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001511}
1512
1513static void
1514desktop_shell_unlock(struct wl_client *client,
1515 struct wl_resource *resource)
1516{
Tiago Vignattibe143262012-04-16 17:31:41 +03001517 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001518
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001519 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001520
1521 if (shell->locked)
1522 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001523}
1524
Kristian Høgsberg75840622011-09-06 13:48:16 -04001525static const struct desktop_shell_interface desktop_shell_implementation = {
1526 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001527 desktop_shell_set_panel,
1528 desktop_shell_set_lock_surface,
1529 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001530};
1531
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001532static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001533get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001534{
1535 struct shell_surface *shsurf;
1536
1537 shsurf = get_shell_surface(surface);
1538 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001539 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001540 return shsurf->type;
1541}
1542
Kristian Høgsberg75840622011-09-06 13:48:16 -04001543static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001544move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001545{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001546 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001547 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001548 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001549
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001550 if (surface == NULL)
1551 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001552
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001553 shsurf = get_shell_surface(surface);
1554 if (shsurf == NULL)
1555 return;
1556
1557 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001558 case SHELL_SURFACE_PANEL:
1559 case SHELL_SURFACE_BACKGROUND:
1560 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001561 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001562 return;
1563 default:
1564 break;
1565 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001566
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04001567 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001568}
1569
1570static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001571resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001572{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001573 struct weston_surface *surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001574 (struct weston_surface *) seat->pointer->focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001575 uint32_t edges = 0;
1576 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001577 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001578
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001579 if (surface == NULL)
1580 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001581
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001582 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001583 if (!shsurf)
1584 return;
1585
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001586 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001587 case SHELL_SURFACE_PANEL:
1588 case SHELL_SURFACE_BACKGROUND:
1589 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001590 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001591 return;
1592 default:
1593 break;
1594 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001595
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001596 weston_surface_from_global(surface,
Daniel Stone37816df2012-05-16 18:45:18 +01001597 wl_fixed_to_int(seat->pointer->grab_x),
1598 wl_fixed_to_int(seat->pointer->grab_y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001599 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001600
Pekka Paalanen60921e52012-01-25 15:55:43 +02001601 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001602 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001603 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001604 edges |= 0;
1605 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001606 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001607
Pekka Paalanen60921e52012-01-25 15:55:43 +02001608 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001609 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001610 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001611 edges |= 0;
1612 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001613 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001614
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001615 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001616}
1617
1618static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001619surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01001620 wl_fixed_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
Daniel Stone0c1e46e2012-05-30 16:31:59 +01001642 surface->alpha += wl_fixed_to_double(value) * step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001643
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 Stone325fc2d2012-05-30 16:31:58 +01001654do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01001655 wl_fixed_t value)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001656{
Daniel Stone37816df2012-05-16 18:45:18 +01001657 struct weston_seat *ws = (struct weston_seat *) seat;
1658 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001659 struct weston_output *output;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001660 float maximum_level, increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001661
1662 wl_list_for_each(output, &compositor->output_list, link) {
1663 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01001664 wl_fixed_to_double(seat->pointer->x),
1665 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01001666 NULL)) {
Daniel Stone325fc2d2012-05-30 16:31:58 +01001667 if (key == KEY_PAGEUP)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001668 increment = output->zoom.increment;
Daniel Stone325fc2d2012-05-30 16:31:58 +01001669 else if (key == KEY_PAGEDOWN)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001670 increment = -output->zoom.increment;
1671 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
Daniel Stone0c1e46e2012-05-30 16:31:59 +01001672 increment = output->zoom.increment *
1673 wl_fixed_to_double(value);
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04001674 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,
Scott Moreau7a1b32a2012-05-27 14:25:02 -06001692 seat->pointer->y,
1693 ZOOM_POINTER);
Scott Moreauccbf29d2012-02-22 14:21:41 -07001694 }
1695 }
1696}
1697
Scott Moreauccbf29d2012-02-22 14:21:41 -07001698static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001699zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01001700 wl_fixed_t value, void *data)
Daniel Stone325fc2d2012-05-30 16:31:58 +01001701{
1702 do_zoom(seat, time, 0, axis, value);
1703}
1704
1705static void
1706zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
1707 void *data)
1708{
1709 do_zoom(seat, time, key, 0, 0);
1710}
1711
1712static void
1713terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
1714 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001715{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001716 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001717
Daniel Stone325fc2d2012-05-30 16:31:58 +01001718 wl_display_terminate(compositor->wl_display);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001719}
1720
1721static void
Scott Moreau447013d2012-02-18 05:05:29 -07001722rotate_grab_motion(struct wl_pointer_grab *grab,
Daniel Stone103db7f2012-05-08 17:17:55 +01001723 uint32_t time, wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001724{
1725 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001726 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001727 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001728 struct shell_surface *shsurf = rotate->base.shsurf;
1729 struct weston_surface *surface;
1730 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1731
1732 if (!shsurf)
1733 return;
1734
1735 surface = shsurf->surface;
1736
1737 cx = 0.5f * surface->geometry.width;
1738 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001739
Daniel Stone37816df2012-05-16 18:45:18 +01001740 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
1741 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001742 r = sqrtf(dx * dx + dy * dy);
1743
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001744 wl_list_remove(&shsurf->rotation.transform.link);
1745 shsurf->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001746
1747 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001748 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001749 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001750
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001751 weston_matrix_init(&rotate->rotation);
1752 rotate->rotation.d[0] = dx / r;
1753 rotate->rotation.d[4] = -dy / r;
1754 rotate->rotation.d[1] = -rotate->rotation.d[4];
1755 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001756
1757 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001758 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001759 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001760 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001761 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001762
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001763 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001764 &shsurf->surface->geometry.transformation_list,
1765 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001766 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001767 wl_list_init(&shsurf->rotation.transform.link);
1768 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001769 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001770 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001771
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001772 /* We need to adjust the position of the surface
1773 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001774 cposx = surface->geometry.x + cx;
1775 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001776 dposx = rotate->center.x - cposx;
1777 dposy = rotate->center.y - cposy;
1778 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001779 weston_surface_set_position(surface,
1780 surface->geometry.x + dposx,
1781 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001782 }
1783
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001784 /* Repaint implies weston_surface_update_transform(), which
1785 * lazily applies the damage due to rotation update.
1786 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001787 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001788}
1789
1790static void
Scott Moreau447013d2012-02-18 05:05:29 -07001791rotate_grab_button(struct wl_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001792 uint32_t time, uint32_t button, uint32_t state_w)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001793{
1794 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001795 container_of(grab, struct rotate_grab, base.grab);
Daniel Stone37816df2012-05-16 18:45:18 +01001796 struct wl_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001797 struct shell_surface *shsurf = rotate->base.shsurf;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001798 enum wl_pointer_button_state state = state_w;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001799
Daniel Stone4dbadb12012-05-30 16:31:51 +01001800 if (pointer->button_count == 0 &&
1801 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001802 if (shsurf)
1803 weston_matrix_multiply(&shsurf->rotation.rotation,
1804 &rotate->rotation);
1805 shell_grab_finish(&rotate->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001806 wl_pointer_end_grab(pointer);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001807 free(rotate);
1808 }
1809}
1810
Scott Moreau447013d2012-02-18 05:05:29 -07001811static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001812 noop_grab_focus,
1813 rotate_grab_motion,
1814 rotate_grab_button,
1815};
1816
1817static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001818rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
Daniel Stonee5a01202012-05-04 11:21:57 +01001819 void *data)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001820{
1821 struct weston_surface *base_surface =
Daniel Stone37816df2012-05-16 18:45:18 +01001822 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001823 struct shell_surface *surface;
1824 struct rotate_grab *rotate;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001825 GLfloat dx, dy;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001826 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001827
1828 if (base_surface == NULL)
1829 return;
1830
1831 surface = get_shell_surface(base_surface);
1832 if (!surface)
1833 return;
1834
1835 switch (surface->type) {
1836 case SHELL_SURFACE_PANEL:
1837 case SHELL_SURFACE_BACKGROUND:
1838 case SHELL_SURFACE_FULLSCREEN:
1839 case SHELL_SURFACE_SCREENSAVER:
1840 return;
1841 default:
1842 break;
1843 }
1844
Pekka Paalanen460099f2012-01-20 16:48:25 +02001845 rotate = malloc(sizeof *rotate);
1846 if (!rotate)
1847 return;
1848
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001849 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001850
1851 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001852 surface->surface->geometry.width / 2,
1853 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001854 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001855
Daniel Stone37816df2012-05-16 18:45:18 +01001856 wl_pointer_start_grab(seat->pointer, &rotate->base.grab);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001857
Daniel Stone37816df2012-05-16 18:45:18 +01001858 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
1859 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001860 r = sqrtf(dx * dx + dy * dy);
1861 if (r > 20.0f) {
1862 struct weston_matrix inverse;
1863
1864 weston_matrix_init(&inverse);
1865 inverse.d[0] = dx / r;
1866 inverse.d[4] = dy / r;
1867 inverse.d[1] = -inverse.d[4];
1868 inverse.d[5] = inverse.d[0];
1869 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001870
1871 weston_matrix_init(&rotate->rotation);
1872 rotate->rotation.d[0] = dx / r;
1873 rotate->rotation.d[4] = -dy / r;
1874 rotate->rotation.d[1] = -rotate->rotation.d[4];
1875 rotate->rotation.d[5] = rotate->rotation.d[0];
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001876 } else {
1877 weston_matrix_init(&surface->rotation.rotation);
1878 weston_matrix_init(&rotate->rotation);
1879 }
1880
Daniel Stone37816df2012-05-16 18:45:18 +01001881 wl_pointer_set_focus(seat->pointer, NULL,
1882 wl_fixed_from_int(0),
1883 wl_fixed_from_int(0));
Pekka Paalanen460099f2012-01-20 16:48:25 +02001884}
1885
1886static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001887activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01001888 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001889{
Alex Wu21858432012-04-01 20:13:08 +08001890 struct weston_surface *surf, *prev;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001891
Daniel Stone37816df2012-05-16 18:45:18 +01001892 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001893
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001894 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001895 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001896 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001897 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001898 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001899
Pekka Paalanen77346a62011-11-30 16:26:35 +02001900 case SHELL_SURFACE_SCREENSAVER:
1901 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001902 if (shell->lock_surface)
1903 weston_surface_restack(es,
1904 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001905 break;
Alex Wu4539b082012-03-01 12:57:46 +08001906 case SHELL_SURFACE_FULLSCREEN:
1907 /* should on top of panels */
Alex Wu21858432012-04-01 20:13:08 +08001908 shell_stack_fullscreen(get_shell_surface(es));
Alex Wubd3354b2012-04-17 17:20:49 +08001909 shell_configure_fullscreen(get_shell_surface(es));
Alex Wu4539b082012-03-01 12:57:46 +08001910 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001911 default:
Alex Wubd3354b2012-04-17 17:20:49 +08001912 /* move the fullscreen surfaces down into the toplevel layer */
Alex Wu21858432012-04-01 20:13:08 +08001913 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1914 wl_list_for_each_reverse_safe(surf,
1915 prev,
1916 &shell->fullscreen_layer.surface_list,
1917 layer_link)
1918 weston_surface_restack(surf,
1919 &shell->toplevel_layer.surface_list);
1920 }
1921
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001922 weston_surface_restack(es,
1923 &shell->toplevel_layer.surface_list);
1924 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001925 }
1926}
1927
Alex Wu21858432012-04-01 20:13:08 +08001928/* no-op func for checking black surface */
1929static void
1930black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1931{
1932}
1933
1934static bool
1935is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1936{
1937 if (es->configure == black_surface_configure) {
1938 if (fs_surface)
1939 *fs_surface = (struct weston_surface *)es->private;
1940 return true;
1941 }
1942 return false;
1943}
1944
Kristian Høgsberg75840622011-09-06 13:48:16 -04001945static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01001946click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001947 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001948{
Daniel Stone37816df2012-05-16 18:45:18 +01001949 struct weston_seat *ws = (struct weston_seat *) seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03001950 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001951 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001952 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001953
Daniel Stone37816df2012-05-16 18:45:18 +01001954 focus = (struct weston_surface *) seat->pointer->focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08001955 if (!focus)
1956 return;
1957
Alex Wu21858432012-04-01 20:13:08 +08001958 if (is_black_surface(focus, &upper))
Alex Wu4539b082012-03-01 12:57:46 +08001959 focus = upper;
Alex Wu4539b082012-03-01 12:57:46 +08001960
Daniel Stone325fc2d2012-05-30 16:31:58 +01001961 if (seat->pointer->grab == &seat->pointer->default_grab)
Daniel Stone37816df2012-05-16 18:45:18 +01001962 activate(shell, focus, ws);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001963}
1964
1965static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001966lock(struct wl_listener *listener, void *data)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001967{
Tiago Vignattibe143262012-04-16 17:31:41 +03001968 struct desktop_shell *shell =
1969 container_of(listener, struct desktop_shell, lock_listener);
Daniel Stone37816df2012-05-16 18:45:18 +01001970 struct weston_seat *seat;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001971 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001972 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001973
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001974 if (shell->locked) {
1975 wl_list_for_each(output, &shell->compositor->output_list, link)
1976 /* TODO: find a way to jump to other DPMS levels */
1977 if (output->set_dpms)
1978 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001979 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001980 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001981
1982 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001983
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001984 /* Hide all surfaces by removing the fullscreen, panel and
1985 * toplevel layers. This way nothing else can show or receive
1986 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001987
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001988 wl_list_remove(&shell->panel_layer.link);
1989 wl_list_remove(&shell->toplevel_layer.link);
1990 wl_list_remove(&shell->fullscreen_layer.link);
1991 wl_list_insert(&shell->compositor->cursor_layer.link,
1992 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001993
Pekka Paalanen77346a62011-11-30 16:26:35 +02001994 launch_screensaver(shell);
1995
1996 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1997 show_screensaver(shell, shsurf);
1998
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001999 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02002000 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002001 weston_compositor_wake(shell->compositor);
2002 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02002003 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002004
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002005 /* reset pointer foci */
Kristian Høgsbergaa6019e2012-03-11 16:35:16 -04002006 weston_compositor_schedule_repaint(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002007
2008 /* reset keyboard foci */
Daniel Stone37816df2012-05-16 18:45:18 +01002009 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
2010 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002011 }
2012
2013 /* TODO: disable bindings that should not work while locked. */
2014
2015 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002016}
2017
2018static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002019unlock(struct wl_listener *listener, void *data)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002020{
Tiago Vignattibe143262012-04-16 17:31:41 +03002021 struct desktop_shell *shell =
2022 container_of(listener, struct desktop_shell, unlock_listener);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002023
Pekka Paalanend81c2162011-11-16 13:47:34 +02002024 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002025 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002026 return;
2027 }
2028
2029 /* If desktop-shell client has gone away, unlock immediately. */
2030 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002031 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002032 return;
2033 }
2034
2035 if (shell->prepare_event_sent)
2036 return;
2037
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05002038 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002039 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002040}
2041
2042static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002043center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02002044{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002045 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002046 GLfloat x = (mode->width - surface->geometry.width) / 2;
2047 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002048
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002049 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002050}
2051
2052static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002053map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002054 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002055{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002056 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002057 struct shell_surface *shsurf;
2058 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002059 struct weston_surface *parent;
Daniel Stoneb2104682012-05-30 16:31:56 +01002060 struct weston_seat *seat;
Juan Zhao96879df2012-02-07 08:45:41 +08002061 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002062
Pekka Paalanen77346a62011-11-30 16:26:35 +02002063 shsurf = get_shell_surface(surface);
2064 if (shsurf)
2065 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002066
Pekka Paalanen60921e52012-01-25 15:55:43 +02002067 surface->geometry.width = width;
2068 surface->geometry.height = height;
2069 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002070
2071 /* initial positioning, see also configure() */
2072 switch (surface_type) {
2073 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02002074 weston_surface_set_position(surface, 10 + random() % 400,
2075 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002076 break;
2077 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002078 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002079 break;
Alex Wu4539b082012-03-01 12:57:46 +08002080 case SHELL_SURFACE_FULLSCREEN:
2081 shell_map_fullscreen(shsurf);
2082 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002083 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002084 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08002085 panel_height = get_output_panel_height(shell,surface->output);
2086 weston_surface_set_position(surface, surface->output->x,
2087 surface->output->y + panel_height);
2088 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002089 case SHELL_SURFACE_LOCK:
2090 center_on_output(surface, get_default_output(compositor));
2091 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02002092 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002093 shell_map_popup(shsurf);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02002094 case SHELL_SURFACE_NONE:
2095 weston_surface_set_position(surface,
2096 surface->geometry.x + sx,
2097 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02002098 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002099 default:
2100 ;
2101 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04002102
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002103 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002104 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002105 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002106 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002107 wl_list_insert(&shell->background_layer.surface_list,
2108 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002109 break;
2110 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002111 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002112 wl_list_insert(&shell->panel_layer.surface_list,
2113 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002114 break;
2115 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02002116 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002117 wl_list_insert(&shell->lock_layer.surface_list,
2118 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002119 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002120 break;
2121 case SHELL_SURFACE_SCREENSAVER:
2122 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002123 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02002124 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02002125 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002126 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02002127 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002128 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02002129 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002130 break;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05002131 case SHELL_SURFACE_POPUP:
2132 case SHELL_SURFACE_TRANSIENT:
2133 parent = shsurf->parent->surface;
2134 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2135 break;
Alex Wu4539b082012-03-01 12:57:46 +08002136 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02002137 case SHELL_SURFACE_NONE:
2138 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002139 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002140 wl_list_insert(&shell->toplevel_layer.surface_list,
2141 &surface->layer_link);
2142 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002143 }
2144
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002145 if (surface_type != SHELL_SURFACE_NONE) {
2146 weston_surface_assign_output(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02002147 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2148 surface->output = shsurf->output;
2149 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002150
Juan Zhao7bb92f02011-12-15 11:31:51 -05002151 switch (surface_type) {
Juan Zhao7bb92f02011-12-15 11:31:51 -05002152 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03002153 if (shsurf->transient.flags ==
2154 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2155 break;
2156 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05002157 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08002158 case SHELL_SURFACE_MAXIMIZED:
Daniel Stoneb2104682012-05-30 16:31:56 +01002159 if (!shell->locked) {
2160 wl_list_for_each(seat, &compositor->seat_list, link)
2161 activate(shell, surface, seat);
2162 }
Juan Zhao7bb92f02011-12-15 11:31:51 -05002163 break;
2164 default:
2165 break;
2166 }
2167
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05002168 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08002169 {
2170 switch (shell->win_animation_type) {
2171 case ANIMATION_FADE:
2172 weston_fade_run(surface, NULL, NULL);
2173 break;
2174 case ANIMATION_ZOOM:
2175 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2176 break;
2177 default:
2178 break;
2179 }
2180 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002181}
2182
2183static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002184configure(struct desktop_shell *shell, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02002185 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002186{
Pekka Paalanen77346a62011-11-30 16:26:35 +02002187 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2188 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002189
Pekka Paalanen77346a62011-11-30 16:26:35 +02002190 shsurf = get_shell_surface(surface);
2191 if (shsurf)
2192 surface_type = shsurf->type;
2193
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002194 surface->geometry.x = x;
2195 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02002196 surface->geometry.width = width;
2197 surface->geometry.height = height;
2198 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002199
2200 switch (surface_type) {
2201 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002202 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002203 break;
Alex Wu4539b082012-03-01 12:57:46 +08002204 case SHELL_SURFACE_FULLSCREEN:
Alex Wubd3354b2012-04-17 17:20:49 +08002205 shell_stack_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002206 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002207 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002208 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08002209 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002210 surface->geometry.x = surface->output->x;
2211 surface->geometry.y = surface->output->y +
2212 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08002213 break;
Alex Wu4539b082012-03-01 12:57:46 +08002214 case SHELL_SURFACE_TOPLEVEL:
2215 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002216 default:
2217 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002218 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002219
Alex Wu4539b082012-03-01 12:57:46 +08002220 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05002221 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02002222 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002223
2224 if (surface_type == SHELL_SURFACE_SCREENSAVER)
2225 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08002226 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
2227 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002228 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04002229}
2230
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002231static void
2232shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2233{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03002234 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03002235 struct desktop_shell *shell = shsurf->shell;
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03002236 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002237
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002238 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002239 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002240 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002241 type_changed = 1;
2242 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002243
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002244 if (!weston_surface_is_mapped(es)) {
2245 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04002246 } else if (type_changed || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002247 es->geometry.width != es->buffer->width ||
2248 es->geometry.height != es->buffer->height) {
2249 GLfloat from_x, from_y;
2250 GLfloat to_x, to_y;
2251
2252 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2253 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2254 configure(shell, es,
2255 es->geometry.x + to_x - from_x,
2256 es->geometry.y + to_y - from_y,
2257 es->buffer->width, es->buffer->height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002258 }
2259}
2260
Tiago Vignattibe143262012-04-16 17:31:41 +03002261static int launch_desktop_shell_process(struct desktop_shell *shell);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002262
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002263static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002264desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002265{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002266 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03002267 struct desktop_shell *shell =
2268 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002269
2270 shell->child.process.pid = 0;
2271 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002272
2273 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2274 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002275 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02002276 shell->child.deathstamp = time;
2277 shell->child.deathcount = 0;
2278 }
2279
2280 shell->child.deathcount++;
2281 if (shell->child.deathcount > 5) {
2282 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
2283 return;
2284 }
2285
2286 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
2287 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002288}
2289
2290static int
Tiago Vignattibe143262012-04-16 17:31:41 +03002291launch_desktop_shell_process(struct desktop_shell *shell)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002292{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05002293 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002294
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002295 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02002296 &shell->child.process,
2297 shell_exe,
2298 desktop_shell_sigchld);
2299
2300 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002301 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002302 return 0;
2303}
2304
2305static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002306bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2307{
Tiago Vignattibe143262012-04-16 17:31:41 +03002308 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002309
2310 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002311 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002312}
2313
Kristian Høgsberg75840622011-09-06 13:48:16 -04002314static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002315unbind_desktop_shell(struct wl_resource *resource)
2316{
Tiago Vignattibe143262012-04-16 17:31:41 +03002317 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002318
2319 if (shell->locked)
2320 resume_desktop(shell);
2321
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002322 shell->child.desktop_shell = NULL;
2323 shell->prepare_event_sent = false;
2324 free(resource);
2325}
2326
2327static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04002328bind_desktop_shell(struct wl_client *client,
2329 void *data, uint32_t version, uint32_t id)
2330{
Tiago Vignattibe143262012-04-16 17:31:41 +03002331 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002332 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002333
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002334 resource = wl_client_add_object(client, &desktop_shell_interface,
2335 &desktop_shell_implementation,
2336 id, shell);
2337
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002338 if (client == shell->child.client) {
2339 resource->destroy = unbind_desktop_shell;
2340 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002341 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002342 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02002343
2344 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2345 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002346 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002347}
2348
Pekka Paalanen6e168112011-11-24 11:34:05 +02002349static void
2350screensaver_set_surface(struct wl_client *client,
2351 struct wl_resource *resource,
2352 struct wl_resource *shell_surface_resource,
2353 struct wl_resource *output_resource)
2354{
Tiago Vignattibe143262012-04-16 17:31:41 +03002355 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002356 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002357 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002358
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002359 surface->next_type = SHELL_SURFACE_SCREENSAVER;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002360
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05002361 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002362 surface->output = output;
2363 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002364}
2365
2366static const struct screensaver_interface screensaver_implementation = {
2367 screensaver_set_surface
2368};
2369
2370static void
2371unbind_screensaver(struct wl_resource *resource)
2372{
Tiago Vignattibe143262012-04-16 17:31:41 +03002373 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002374
Pekka Paalanen77346a62011-11-30 16:26:35 +02002375 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002376 free(resource);
2377}
2378
2379static void
2380bind_screensaver(struct wl_client *client,
2381 void *data, uint32_t version, uint32_t id)
2382{
Tiago Vignattibe143262012-04-16 17:31:41 +03002383 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002384 struct wl_resource *resource;
2385
2386 resource = wl_client_add_object(client, &screensaver_interface,
2387 &screensaver_implementation,
2388 id, shell);
2389
Pekka Paalanen77346a62011-11-30 16:26:35 +02002390 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02002391 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002392 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002393 return;
2394 }
2395
2396 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2397 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002398 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002399}
2400
Kristian Høgsberg07045392012-02-19 18:52:44 -05002401struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03002402 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002403 struct weston_surface *current;
2404 struct wl_listener listener;
2405 struct wl_keyboard_grab grab;
2406};
2407
2408static void
2409switcher_next(struct switcher *switcher)
2410{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002411 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002412 struct weston_surface *surface;
2413 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002414 struct shell_surface *shsurf;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002415
2416 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002417 switch (get_shell_surface_type(surface)) {
2418 case SHELL_SURFACE_TOPLEVEL:
2419 case SHELL_SURFACE_FULLSCREEN:
2420 case SHELL_SURFACE_MAXIMIZED:
2421 if (first == NULL)
2422 first = surface;
2423 if (prev == switcher->current)
2424 next = surface;
2425 prev = surface;
Scott Moreau02709af2012-05-22 01:54:10 -06002426 surface->alpha = 0.25;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05002427 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002428 weston_surface_damage(surface);
2429 break;
2430 default:
2431 break;
2432 }
Alex Wu1659daa2012-04-01 20:13:09 +08002433
2434 if (is_black_surface(surface, NULL)) {
Scott Moreau02709af2012-05-22 01:54:10 -06002435 surface->alpha = 0.25;
Alex Wu1659daa2012-04-01 20:13:09 +08002436 surface->geometry.dirty = 1;
2437 weston_surface_damage(surface);
2438 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05002439 }
2440
2441 if (next == NULL)
2442 next = first;
2443
Alex Wu07b26062012-03-12 16:06:01 +08002444 if (next == NULL)
2445 return;
2446
Kristian Høgsberg07045392012-02-19 18:52:44 -05002447 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002448 wl_signal_add(&next->surface.resource.destroy_signal,
2449 &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002450
2451 switcher->current = next;
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002452 next->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08002453
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002454 shsurf = get_shell_surface(switcher->current);
2455 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002456 shsurf->fullscreen.black_surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002457}
2458
2459static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002460switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002461{
2462 struct switcher *switcher =
2463 container_of(listener, struct switcher, listener);
2464
2465 switcher_next(switcher);
2466}
2467
2468static void
Daniel Stone351eb612012-05-31 15:27:47 -04002469switcher_destroy(struct switcher *switcher)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002470{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002471 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002472 struct weston_surface *surface;
Daniel Stone37816df2012-05-16 18:45:18 +01002473 struct wl_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002474
2475 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberga416fa12012-05-21 14:06:52 -04002476 surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002477 weston_surface_damage(surface);
2478 }
2479
Alex Wu07b26062012-03-12 16:06:01 +08002480 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01002481 activate(switcher->shell, switcher->current,
2482 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002483 wl_list_remove(&switcher->listener.link);
Daniel Stone37816df2012-05-16 18:45:18 +01002484 wl_keyboard_end_grab(keyboard);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002485 free(switcher);
2486}
2487
2488static void
2489switcher_key(struct wl_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +01002490 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002491{
2492 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stonec9785ea2012-05-30 16:31:52 +01002493 enum wl_keyboard_key_state state = state_w;
Daniel Stone351eb612012-05-31 15:27:47 -04002494
Daniel Stonec9785ea2012-05-30 16:31:52 +01002495 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
Daniel Stone351eb612012-05-31 15:27:47 -04002496 switcher_next(switcher);
2497}
2498
2499static void
2500switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial,
2501 uint32_t mods_depressed, uint32_t mods_latched,
2502 uint32_t mods_locked, uint32_t group)
2503{
2504 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01002505 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002506
Daniel Stone351eb612012-05-31 15:27:47 -04002507 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
2508 switcher_destroy(switcher);
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04002509}
Kristian Høgsberg07045392012-02-19 18:52:44 -05002510
2511static const struct wl_keyboard_grab_interface switcher_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -04002512 switcher_key,
2513 switcher_modifier,
Kristian Høgsberg07045392012-02-19 18:52:44 -05002514};
2515
2516static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01002517switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2518 void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002519{
Tiago Vignattibe143262012-04-16 17:31:41 +03002520 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002521 struct switcher *switcher;
2522
2523 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002524 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002525 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002526 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002527 wl_list_init(&switcher->listener.link);
2528
2529 switcher->grab.interface = &switcher_grab;
Daniel Stone37816df2012-05-16 18:45:18 +01002530 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
2531 wl_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002532 switcher_next(switcher);
2533}
2534
Pekka Paalanen3c647232011-12-22 13:43:43 +02002535static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01002536backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2537 void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002538{
2539 struct weston_compositor *compositor = data;
2540 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002541 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002542
2543 /* TODO: we're limiting to simple use cases, where we assume just
2544 * control on the primary display. We'd have to extend later if we
2545 * ever get support for setting backlights on random desktop LCD
2546 * panels though */
2547 output = get_default_output(compositor);
2548 if (!output)
2549 return;
2550
2551 if (!output->set_backlight)
2552 return;
2553
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002554 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2555 backlight_new = output->backlight_current - 25;
2556 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2557 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002558
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002559 if (backlight_new < 5)
2560 backlight_new = 5;
2561 if (backlight_new > 255)
2562 backlight_new = 255;
2563
2564 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002565 output->set_backlight(output, output->backlight_current);
2566}
2567
2568static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01002569debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2570 void *data)
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002571{
Tiago Vignattibe143262012-04-16 17:31:41 +03002572 struct desktop_shell *shell = data;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002573 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002574 struct weston_surface *surface;
2575
2576 if (shell->debug_repaint_surface) {
2577 weston_surface_destroy(shell->debug_repaint_surface);
2578 shell->debug_repaint_surface = NULL;
2579 } else {
2580 surface = weston_surface_create(compositor);
2581 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2582 weston_surface_configure(surface, 0, 0, 8192, 8192);
2583 wl_list_insert(&compositor->fade_layer.surface_list,
2584 &surface->layer_link);
2585 weston_surface_assign_output(surface);
2586 pixman_region32_init(&surface->input);
2587
2588 /* Here's the dirty little trick that makes the
2589 * repaint debugging work: we force an
2590 * update_transform first to update dependent state
2591 * and clear the geometry.dirty bit. Then we clear
2592 * the surface damage so it only gets repainted
2593 * piecewise as we repaint other things. */
2594
2595 weston_surface_update_transform(surface);
2596 pixman_region32_fini(&surface->damage);
2597 pixman_region32_init(&surface->damage);
2598 shell->debug_repaint_surface = surface;
2599 }
2600}
2601
2602static void
Daniel Stone325fc2d2012-05-30 16:31:58 +01002603force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2604 void *data)
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04002605{
2606 struct wl_client *client;
2607 pid_t pid;
2608 uid_t uid;
2609 gid_t gid;
2610
Daniel Stone325fc2d2012-05-30 16:31:58 +01002611 client = seat->keyboard->focus->resource.client;
2612 wl_client_get_credentials(client, &pid, &uid, &gid);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04002613
Daniel Stone325fc2d2012-05-30 16:31:58 +01002614 kill(pid, SIGKILL);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04002615}
2616
2617static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002618shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02002619{
Tiago Vignattibe143262012-04-16 17:31:41 +03002620 struct desktop_shell *shell =
2621 container_of(listener, struct desktop_shell, destroy_listener);
Pekka Paalanen3c647232011-12-22 13:43:43 +02002622
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02002623 if (shell->child.client)
2624 wl_client_destroy(shell->child.client);
2625
Kristian Høgsberg88c16072012-05-16 08:04:19 -04002626 wl_list_remove(&shell->lock_listener.link);
2627 wl_list_remove(&shell->unlock_listener.link);
2628
Pekka Paalanen3c647232011-12-22 13:43:43 +02002629 free(shell->screensaver.path);
2630 free(shell);
2631}
2632
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002633static void
2634shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
2635{
2636 uint32_t mod;
2637
2638 /* fixed bindings */
Daniel Stone325fc2d2012-05-30 16:31:58 +01002639 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
2640 MODIFIER_CTRL | MODIFIER_ALT,
2641 terminate_binding, ec);
2642 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
2643 click_to_activate_binding,
2644 shell);
2645 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
2646 MODIFIER_SUPER | MODIFIER_ALT,
2647 surface_opacity_binding, NULL);
2648 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
2649 MODIFIER_SUPER, zoom_axis_binding,
2650 NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002651
2652 /* configurable bindings */
2653 mod = shell->binding_modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +01002654 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
2655 zoom_key_binding, NULL);
2656 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
2657 zoom_key_binding, NULL);
2658 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
2659 shell);
2660 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
2661 resize_binding, shell);
2662 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
2663 rotate_binding, NULL);
2664 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
2665 shell);
2666 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
2667 ec);
2668 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
2669 backlight_binding, ec);
2670 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
2671 ec);
2672 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
2673 backlight_binding, ec);
2674 weston_compositor_add_key_binding(ec, KEY_SPACE, mod,
2675 debug_repaint_binding, shell);
2676 weston_compositor_add_key_binding(ec, KEY_K, mod,
2677 force_kill_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002678}
2679
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002680int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002681shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002682
Kristian Høgsberg1c562182011-05-02 22:09:20 -04002683WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002684shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002685{
Tiago Vignattibe143262012-04-16 17:31:41 +03002686 struct desktop_shell *shell;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002687
2688 shell = malloc(sizeof *shell);
2689 if (shell == NULL)
2690 return -1;
2691
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04002692 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002693 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002694
2695 shell->destroy_listener.notify = shell_destroy;
2696 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2697 shell->lock_listener.notify = lock;
2698 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2699 shell->unlock_listener.notify = unlock;
2700 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06002701 ec->ping_handler = ping_handler;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002702 ec->shell_interface.create_shell_surface = create_shell_surface;
2703 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04002704 ec->shell_interface.set_transient = set_transient;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002705 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04002706 ec->shell_interface.resize = surface_resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002707
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002708 wl_list_init(&shell->backgrounds);
2709 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002710 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002711
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002712 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2713 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2714 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2715 weston_layer_init(&shell->background_layer,
2716 &shell->toplevel_layer.link);
2717 wl_list_init(&shell->lock_layer.surface_list);
2718
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002719 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002720
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002721 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2722 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002723 return -1;
2724
Kristian Høgsberg75840622011-09-06 13:48:16 -04002725 if (wl_display_add_global(ec->wl_display,
2726 &desktop_shell_interface,
2727 shell, bind_desktop_shell) == NULL)
2728 return -1;
2729
Pekka Paalanen6e168112011-11-24 11:34:05 +02002730 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2731 shell, bind_screensaver) == NULL)
2732 return -1;
2733
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002734 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002735 if (launch_desktop_shell_process(shell) != 0)
2736 return -1;
2737
Tiago Vignatti0b52d482012-04-20 18:54:25 +03002738 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002739
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002740 return 0;
2741}