blob: 6afdf3aed5f1a56dfda2e5ebee7693e20243ecb7 [file] [log] [blame]
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001/*
Kristian Høgsberg07045392012-02-19 18:52:44 -05002 * Copyright © 2010-2012 Intel Corporation
Pekka Paalanend581a8f2012-01-27 16:25:16 +02003 * Copyright © 2011-2012 Collabora, Ltd.
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#include <stdlib.h>
Kristian Høgsberg75840622011-09-06 13:48:16 -040025#include <stdio.h>
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020026#include <stdbool.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050027#include <string.h>
28#include <unistd.h>
Kristian Høgsberg07937562011-04-12 17:25:42 -040029#include <linux/input.h>
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020030#include <assert.h>
Pekka Paalanen18027e52011-12-02 16:31:49 +020031#include <signal.h>
Pekka Paalanen460099f2012-01-20 16:48:25 +020032#include <math.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050033
Pekka Paalanen50719bc2011-11-22 14:18:50 +020034#include <wayland-server.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050035#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040036#include "desktop-shell-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020037#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050038
Pekka Paalanen068ae942011-11-28 14:11:15 +020039struct shell_surface;
40
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040041struct wl_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050042 struct weston_compositor *compositor;
43 struct weston_shell shell;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020044
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050045 struct weston_layer fullscreen_layer;
46 struct weston_layer panel_layer;
47 struct weston_layer toplevel_layer;
48 struct weston_layer background_layer;
49 struct weston_layer lock_layer;
50
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020051 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050052 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020053 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020054 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +020055
56 unsigned deathcount;
57 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020058 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020059
60 bool locked;
61 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020062
Pekka Paalanen068ae942011-11-28 14:11:15 +020063 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050064 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010065
66 struct wl_list backgrounds;
67 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020068
Pekka Paalanen77346a62011-11-30 16:26:35 +020069 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +020070 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020071 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020072 struct wl_resource *binding;
73 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050074 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020075 } screensaver;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040076};
77
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050078enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020079 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050080
Pekka Paalanen57da4a82011-11-23 16:42:16 +020081 SHELL_SURFACE_PANEL,
82 SHELL_SURFACE_BACKGROUND,
83 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020084 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050085
86 SHELL_SURFACE_TOPLEVEL,
87 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050088 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +080089 SHELL_SURFACE_MAXIMIZED,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050090 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +020091};
92
Pekka Paalanen56cdea92011-11-23 16:14:12 +020093struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020094 struct wl_resource resource;
95
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050096 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020097 struct wl_listener surface_destroy_listener;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050098 struct shell_surface *parent;
Pekka Paalanen57da4a82011-11-23 16:42:16 +020099
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500100 enum shell_surface_type type;
101 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800102 bool saved_position_valid;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100103
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500104 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200105 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500106 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200107 } rotation;
108
109 struct {
Scott Moreau447013d2012-02-18 05:05:29 -0700110 struct wl_pointer_grab grab;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500111 uint32_t time;
112 int32_t x, y;
Pekka Paalanen938269a2012-02-07 14:19:01 +0200113 struct weston_transform parent_transform;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500114 int32_t initial_up;
115 } popup;
116
Alex Wu4539b082012-03-01 12:57:46 +0800117 struct {
118 enum wl_shell_surface_fullscreen_method type;
119 struct weston_transform transform; /* matrix from x, y */
120 uint32_t framerate;
121 struct weston_surface *black_surface;
122 } fullscreen;
123
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500124 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500125 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100126 struct wl_list link;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200127};
128
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500129struct weston_move_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700130 struct wl_pointer_grab grab;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500131 struct weston_surface *surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500132 int32_t dx, dy;
133};
134
Scott Moreauc6d7f602012-02-23 22:28:37 -0700135struct weston_zoom_grab {
136 struct wl_keyboard_grab grab;
137};
138
Pekka Paalanen460099f2012-01-20 16:48:25 +0200139struct rotate_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700140 struct wl_pointer_grab grab;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200141 struct shell_surface *surface;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500142 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200143 struct {
144 int32_t x;
145 int32_t y;
146 } center;
147};
148
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500149static void
Alex Wu4539b082012-03-01 12:57:46 +0800150center_on_output(struct weston_surface *surface,
151 struct weston_output *output);
152
153static void
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200154shell_configuration(struct wl_shell *shell)
155{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200156 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200157 char *path = NULL;
158 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200159
160 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200161 { "path", CONFIG_KEY_STRING, &path },
162 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200163 };
164
165 struct config_section cs[] = {
166 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
167 };
168
Kristian Høgsberg9724b512012-01-03 14:35:49 -0500169 config_file = config_file_path("weston-desktop-shell.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500170 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200171 free(config_file);
172
Pekka Paalanen7296e792011-12-07 16:22:00 +0200173 shell->screensaver.path = path;
174 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200175}
176
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200177static void
Scott Moreau447013d2012-02-18 05:05:29 -0700178noop_grab_focus(struct wl_pointer_grab *grab, uint32_t time,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500179 struct wl_surface *surface, int32_t x, int32_t y)
180{
181 grab->focus = NULL;
182}
183
184static void
Scott Moreau447013d2012-02-18 05:05:29 -0700185move_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500186 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500187{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500188 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500189 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500190 struct weston_surface *es = move->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500191
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500192 weston_surface_configure(es,
193 device->x + move->dx,
194 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200195 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500196}
197
198static void
Scott Moreau447013d2012-02-18 05:05:29 -0700199move_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500200 uint32_t time, int32_t button, int32_t state)
201{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500202 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500203
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500204 if (device->button_count == 0 && state == 0) {
Scott Moreau447013d2012-02-18 05:05:29 -0700205 wl_input_device_end_pointer_grab(device, time);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500206 free(grab);
207 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500208}
209
Scott Moreau447013d2012-02-18 05:05:29 -0700210static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500211 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500212 move_grab_motion,
213 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500214};
215
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400216static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500217weston_surface_move(struct weston_surface *es,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500218 struct weston_input_device *wd, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500219{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500220 struct weston_move_grab *move;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500221
222 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400223 if (!move)
224 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500225
226 move->grab.interface = &move_grab_interface;
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200227 move->dx = es->geometry.x - wd->input_device.grab_x;
228 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsbergdd4046a2011-01-21 17:00:09 -0500229 move->surface = es;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500230
Scott Moreau447013d2012-02-18 05:05:29 -0700231 wl_input_device_start_pointer_grab(&wd->input_device, &move->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500232
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200233 wl_input_device_set_pointer_focus(&wd->input_device, NULL, time, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400234
235 return 0;
236}
237
238static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200239shell_surface_move(struct wl_client *client, struct wl_resource *resource,
240 struct wl_resource *input_resource, uint32_t time)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400241{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500242 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200243 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400244
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500245 if (wd->input_device.button_count == 0 ||
246 wd->input_device.grab_time != time ||
247 wd->input_device.pointer_focus != &shsurf->surface->surface)
248 return;
249
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500250 if (weston_surface_move(shsurf->surface, wd, time) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400251 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500252}
253
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500254struct weston_resize_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700255 struct wl_pointer_grab grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500256 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200257 int32_t width, height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200258 struct shell_surface *shsurf;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500259};
260
261static void
Scott Moreau447013d2012-02-18 05:05:29 -0700262resize_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500263 uint32_t time, int32_t x, int32_t y)
264{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500265 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500266 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500267 int32_t width, height;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200268 int32_t from_x, from_y;
269 int32_t to_x, to_y;
270
271 weston_surface_from_global(resize->shsurf->surface,
272 device->grab_x, device->grab_y,
273 &from_x, &from_y);
274 weston_surface_from_global(resize->shsurf->surface,
275 device->x, device->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500276
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200277 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200278 width = resize->width + from_x - to_x;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200279 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200280 width = resize->width + to_x - from_x;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500281 } else {
282 width = resize->width;
283 }
284
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200285 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200286 height = resize->height + from_y - to_y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200287 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200288 height = resize->height + to_y - from_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500289 } else {
290 height = resize->height;
291 }
292
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200293 wl_resource_post_event(&resize->shsurf->resource,
294 WL_SHELL_SURFACE_CONFIGURE, time, resize->edges,
295 width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500296}
297
298static void
Scott Moreau447013d2012-02-18 05:05:29 -0700299resize_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500300 uint32_t time, int32_t button, int32_t state)
301{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500302 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500303
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500304 if (device->button_count == 0 && state == 0) {
Scott Moreau447013d2012-02-18 05:05:29 -0700305 wl_input_device_end_pointer_grab(device, time);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500306 free(grab);
307 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500308}
309
Scott Moreau447013d2012-02-18 05:05:29 -0700310static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500311 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500312 resize_grab_motion,
313 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500314};
315
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400316static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500317weston_surface_resize(struct shell_surface *shsurf,
318 struct weston_input_device *wd,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200319 uint32_t time, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500320{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500321 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500322
Alex Wu4539b082012-03-01 12:57:46 +0800323 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
324 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500325
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200326 if (edges == 0 || edges > 15 ||
327 (edges & 3) == 3 || (edges & 12) == 12)
328 return 0;
329
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500330 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400331 if (!resize)
332 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500333
334 resize->grab.interface = &resize_grab_interface;
335 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200336 resize->width = shsurf->surface->geometry.width;
337 resize->height = shsurf->surface->geometry.height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200338 resize->shsurf = shsurf;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400339
Scott Moreau447013d2012-02-18 05:05:29 -0700340 wl_input_device_start_pointer_grab(&wd->input_device, &resize->grab, time);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500341
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200342 wl_input_device_set_pointer_focus(&wd->input_device, NULL, time, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400343
344 return 0;
345}
346
347static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200348shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
349 struct wl_resource *input_resource, uint32_t time,
350 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400351{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500352 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200353 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400354
Alex Wu4539b082012-03-01 12:57:46 +0800355 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
356 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400357
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500358 if (wd->input_device.button_count == 0 ||
359 wd->input_device.grab_time != time ||
360 wd->input_device.pointer_focus != &shsurf->surface->surface)
361 return;
362
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500363 if (weston_surface_resize(shsurf, wd, time, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400364 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500365}
366
Juan Zhao96879df2012-02-07 08:45:41 +0800367static struct weston_output *
368get_default_output(struct weston_compositor *compositor)
369{
370 return container_of(compositor->output_list.next,
371 struct weston_output, link);
372}
373
Alex Wu4539b082012-03-01 12:57:46 +0800374static void
375shell_unset_fullscreen(struct shell_surface *shsurf)
376{
377 /* undo all fullscreen things here */
378 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
379 shsurf->fullscreen.framerate = 0;
380 wl_list_remove(&shsurf->fullscreen.transform.link);
381 wl_list_init(&shsurf->fullscreen.transform.link);
382 weston_surface_destroy(shsurf->fullscreen.black_surface);
383 shsurf->fullscreen.black_surface = NULL;
384 shsurf->fullscreen_output = NULL;
385 shsurf->surface->force_configure = 1;
386 weston_surface_set_position(shsurf->surface,
387 shsurf->saved_x, shsurf->saved_y);
388}
389
Pekka Paalanen98262232011-12-01 10:42:22 +0200390static int
391reset_shell_surface_type(struct shell_surface *surface)
392{
393 switch (surface->type) {
394 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800395 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200396 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800397 case SHELL_SURFACE_MAXIMIZED:
398 surface->output = get_default_output(surface->surface->compositor);
399 weston_surface_set_position(surface->surface,
400 surface->saved_x,
401 surface->saved_y);
402 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200403 case SHELL_SURFACE_PANEL:
404 case SHELL_SURFACE_BACKGROUND:
405 wl_list_remove(&surface->link);
406 wl_list_init(&surface->link);
407 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200408 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200409 case SHELL_SURFACE_LOCK:
410 wl_resource_post_error(&surface->resource,
411 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200412 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200413 return -1;
414 case SHELL_SURFACE_NONE:
415 case SHELL_SURFACE_TOPLEVEL:
416 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500417 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200418 break;
419 }
420
421 surface->type = SHELL_SURFACE_NONE;
422 return 0;
423}
424
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500425static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200426shell_surface_set_toplevel(struct wl_client *client,
427 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400428
429{
Pekka Paalanen98262232011-12-01 10:42:22 +0200430 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400431
Pekka Paalanen98262232011-12-01 10:42:22 +0200432 if (reset_shell_surface_type(surface))
433 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400434
Pekka Paalanen98262232011-12-01 10:42:22 +0200435 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400436}
437
438static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200439shell_surface_set_transient(struct wl_client *client,
440 struct wl_resource *resource,
441 struct wl_resource *parent_resource,
442 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400443{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200444 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500445 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200446 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500447 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400448
Pekka Paalanen98262232011-12-01 10:42:22 +0200449 if (reset_shell_surface_type(shsurf))
450 return;
451
Alex Wu4539b082012-03-01 12:57:46 +0800452 /* assign to parents output */
Alex Wu88277d12012-02-22 14:50:46 +0800453 shsurf->output = pes->output;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200454 weston_surface_set_position(es, pes->geometry.x + x,
455 pes->geometry.y + y);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400456
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200457 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400458}
459
Juan Zhao96879df2012-02-07 08:45:41 +0800460static struct wl_shell *
461shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200462{
Juan Zhao96879df2012-02-07 08:45:41 +0800463 struct weston_surface *es = shsurf->surface;
464 struct weston_shell *shell = es->compositor->shell;
465
466 return (struct wl_shell *)container_of(shell, struct wl_shell, shell);
467}
468
469static int
470get_output_panel_height(struct wl_shell *wlshell,struct weston_output *output)
471{
472 struct shell_surface *priv;
473 int panel_height = 0;
474
475 if (!output)
476 return 0;
477
478 wl_list_for_each(priv, &wlshell->panels, link) {
479 if (priv->output == output) {
480 panel_height = priv->surface->geometry.height;
481 break;
482 }
483 }
484 return panel_height;
485}
486
487static void
488shell_surface_set_maximized(struct wl_client *client,
489 struct wl_resource *resource,
490 struct wl_resource *output_resource )
491{
492 struct shell_surface *shsurf = resource->data;
493 struct weston_surface *es = shsurf->surface;
494 struct wl_shell *wlshell = NULL;
495 uint32_t edges = 0, panel_height = 0;
496
497 /* get the default output, if the client set it as NULL
498 check whether the ouput is available */
499 if (output_resource)
500 shsurf->output = output_resource->data;
501 else
502 shsurf->output = get_default_output(es->compositor);
503
504 if (reset_shell_surface_type(shsurf))
505 return;
506
507 shsurf->saved_x = es->geometry.x;
508 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800509 shsurf->saved_position_valid = true;
Juan Zhao96879df2012-02-07 08:45:41 +0800510
511 wlshell = shell_surface_get_shell(shsurf);
512 panel_height = get_output_panel_height(wlshell, es->output);
513 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
514 wl_resource_post_event(&shsurf->resource,
515 WL_SHELL_SURFACE_CONFIGURE,
516 weston_compositor_get_time(), edges,
517 es->output->current->width,
518 es->output->current->height - panel_height);
519
520 shsurf->type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200521}
522
Alex Wu4539b082012-03-01 12:57:46 +0800523static struct weston_surface *
524create_black_surface(struct weston_compositor *ec,
525 GLfloat x, GLfloat y, int w, int h)
526{
527 struct weston_surface *surface = NULL;
528
529 surface = weston_surface_create(ec);
530 if (surface == NULL) {
531 fprintf(stderr, "no memory\n");
532 return NULL;
533 }
534
535 weston_surface_configure(surface, x, y, w, h);
536 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
537 return surface;
538}
539
540/* Create black surface and append it to the associated fullscreen surface.
541 * Handle size dismatch and positioning according to the method. */
542static void
543shell_configure_fullscreen(struct shell_surface *shsurf)
544{
545 struct weston_output *output = shsurf->fullscreen_output;
546 struct weston_surface *surface = shsurf->surface;
547 struct weston_matrix *matrix;
548 float scale;
549
550 center_on_output(surface, output);
551
552 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500553 shsurf->fullscreen.black_surface =
554 create_black_surface(surface->compositor,
555 output->x, output->y,
556 output->current->width,
557 output->current->height);
558
559 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
560 wl_list_insert(&surface->layer_link,
561 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800562 shsurf->fullscreen.black_surface->output = output;
563
564 switch (shsurf->fullscreen.type) {
565 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
566 break;
567 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
568 matrix = &shsurf->fullscreen.transform.matrix;
569 weston_matrix_init(matrix);
570 scale = (float)output->current->width/(float)surface->geometry.width;
571 weston_matrix_scale(matrix, scale, scale, 1);
572 wl_list_remove(&shsurf->fullscreen.transform.link);
573 wl_list_insert(surface->geometry.transformation_list.prev,
574 &shsurf->fullscreen.transform.link);
575 weston_surface_set_position(surface, output->x, output->y);
576 break;
577 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
578 break;
579 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
580 break;
581 default:
582 break;
583 }
584}
585
586/* make the fullscreen and black surface at the top */
587static void
588shell_stack_fullscreen(struct shell_surface *shsurf)
589{
590 struct weston_surface *surface = shsurf->surface;
591 struct wl_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +0800592
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500593 wl_list_remove(&surface->layer_link);
594 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800595
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500596 wl_list_insert(&shell->fullscreen_layer.surface_list,
597 &surface->layer_link);
598 wl_list_insert(&surface->layer_link,
599 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800600
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500601 weston_surface_damage(surface);
602 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800603}
604
605static void
606shell_map_fullscreen(struct shell_surface *shsurf)
607{
608 shell_configure_fullscreen(shsurf);
609 shell_stack_fullscreen(shsurf);
610}
611
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400612static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200613shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -0500614 struct wl_resource *resource,
615 uint32_t method,
616 uint32_t framerate,
617 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400618{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200619 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500620 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +0800621
622 if (output_resource)
623 shsurf->output = output_resource->data;
624 else
625 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400626
Pekka Paalanen98262232011-12-01 10:42:22 +0200627 if (reset_shell_surface_type(shsurf))
628 return;
629
Alex Wu4539b082012-03-01 12:57:46 +0800630 shsurf->fullscreen_output = shsurf->output;
631 shsurf->fullscreen.type = method;
632 shsurf->fullscreen.framerate = framerate;
633 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400634
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200635 shsurf->saved_x = es->geometry.x;
636 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800637 shsurf->saved_position_valid = true;
638
639 if (es->output)
640 shsurf->surface->force_configure = 1;
Kristian Høgsbergd5ae9f42012-02-16 23:38:14 -0500641
642 wl_resource_post_event(resource,
643 WL_SHELL_SURFACE_CONFIGURE,
644 weston_compositor_get_time(), 0,
Alex Wu88277d12012-02-22 14:50:46 +0800645 shsurf->output->current->width,
646 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400647}
648
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500649static void
Scott Moreau447013d2012-02-18 05:05:29 -0700650popup_grab_focus(struct wl_pointer_grab *grab, uint32_t time,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500651 struct wl_surface *surface, int32_t x, int32_t y)
652{
653 struct wl_input_device *device = grab->input_device;
654 struct shell_surface *priv =
655 container_of(grab, struct shell_surface, popup.grab);
656 struct wl_client *client = priv->surface->surface.resource.client;
657
Pekka Paalanencb108432012-01-19 16:25:40 +0200658 if (surface && surface->resource.client == client) {
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200659 wl_input_device_set_pointer_focus(device, surface, time, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500660 grab->focus = surface;
661 } else {
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200662 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500663 grab->focus = NULL;
664 }
665}
666
667static void
Scott Moreau447013d2012-02-18 05:05:29 -0700668popup_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200669 uint32_t time, int32_t sx, int32_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500670{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500671 struct wl_resource *resource;
672
673 resource = grab->input_device->pointer_focus_resource;
674 if (resource)
675 wl_resource_post_event(resource, WL_INPUT_DEVICE_MOTION,
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200676 time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500677}
678
679static void
Scott Moreau447013d2012-02-18 05:05:29 -0700680popup_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500681 uint32_t time, int32_t button, int32_t state)
682{
683 struct wl_resource *resource;
684 struct shell_surface *shsurf =
685 container_of(grab, struct shell_surface, popup.grab);
686
687 resource = grab->input_device->pointer_focus_resource;
688 if (resource) {
689 wl_resource_post_event(resource, WL_INPUT_DEVICE_BUTTON,
690 time, button, state);
691 } else if (state == 0 &&
692 (shsurf->popup.initial_up ||
693 time - shsurf->popup.time > 500)) {
694 wl_resource_post_event(&shsurf->resource,
695 WL_SHELL_SURFACE_POPUP_DONE);
Scott Moreau447013d2012-02-18 05:05:29 -0700696 wl_input_device_end_pointer_grab(grab->input_device, time);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500697 shsurf->popup.grab.input_device = NULL;
698 }
699
700 if (state == 0)
701 shsurf->popup.initial_up = 1;
702}
703
Scott Moreau447013d2012-02-18 05:05:29 -0700704static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500705 popup_grab_focus,
706 popup_grab_motion,
707 popup_grab_button,
708};
709
710static void
711shell_map_popup(struct shell_surface *shsurf, uint32_t time)
712{
713 struct wl_input_device *device;
714 struct weston_surface *es = shsurf->surface;
715 struct weston_surface *parent = shsurf->parent->surface;
716
717 es->output = parent->output;
718
719 shsurf->popup.grab.interface = &popup_grab_interface;
720 device = es->compositor->input_device;
721
Pekka Paalanen938269a2012-02-07 14:19:01 +0200722 weston_surface_update_transform(parent);
723 if (parent->transform.enabled) {
724 shsurf->popup.parent_transform.matrix =
725 parent->transform.matrix;
726 } else {
727 /* construct x, y translation matrix */
728 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
729 shsurf->popup.parent_transform.matrix.d[12] =
730 parent->geometry.x;
731 shsurf->popup.parent_transform.matrix.d[13] =
732 parent->geometry.y;
733 }
734 wl_list_insert(es->geometry.transformation_list.prev,
735 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200736 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500737
738 shsurf->popup.grab.input_device = device;
739 shsurf->popup.time = device->grab_time;
740 shsurf->popup.initial_up = 0;
741
Scott Moreau447013d2012-02-18 05:05:29 -0700742 wl_input_device_start_pointer_grab(shsurf->popup.grab.input_device,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500743 &shsurf->popup.grab, shsurf->popup.time);
744}
745
746static void
747shell_surface_set_popup(struct wl_client *client,
748 struct wl_resource *resource,
749 struct wl_resource *input_device_resource,
750 uint32_t time,
751 struct wl_resource *parent_resource,
752 int32_t x, int32_t y, uint32_t flags)
753{
754 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500755
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500756 shsurf->type = SHELL_SURFACE_POPUP;
757 shsurf->parent = parent_resource->data;
758 shsurf->popup.x = x;
759 shsurf->popup.y = y;
760}
761
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200762static const struct wl_shell_surface_interface shell_surface_implementation = {
763 shell_surface_move,
764 shell_surface_resize,
765 shell_surface_set_toplevel,
766 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500767 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +0800768 shell_surface_set_popup,
769 shell_surface_set_maximized
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200770};
771
772static void
773destroy_shell_surface(struct wl_resource *resource)
774{
775 struct shell_surface *shsurf = resource->data;
776
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500777 if (shsurf->popup.grab.input_device)
Scott Moreau447013d2012-02-18 05:05:29 -0700778 wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device, 0);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500779
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200780 /* in case cleaning up a dead client destroys shell_surface first */
781 if (shsurf->surface)
782 wl_list_remove(&shsurf->surface_destroy_listener.link);
783
784 wl_list_remove(&shsurf->link);
785 free(shsurf);
786}
787
788static void
789shell_handle_surface_destroy(struct wl_listener *listener,
790 struct wl_resource *resource, uint32_t time)
791{
792 struct shell_surface *shsurf = container_of(listener,
793 struct shell_surface,
794 surface_destroy_listener);
795
796 shsurf->surface = NULL;
797 wl_resource_destroy(&shsurf->resource, time);
798}
799
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200800static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500801get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200802{
803 struct wl_list *lst = &surface->surface.resource.destroy_listener_list;
804 struct wl_listener *listener;
805
806 /* search the destroy listener list for our callback */
807 wl_list_for_each(listener, lst, link) {
808 if (listener->func == shell_handle_surface_destroy) {
809 return container_of(listener, struct shell_surface,
810 surface_destroy_listener);
811 }
812 }
813
814 return NULL;
815}
816
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200817static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200818shell_get_shell_surface(struct wl_client *client,
819 struct wl_resource *resource,
820 uint32_t id,
821 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200822{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500823 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200824 struct shell_surface *shsurf;
825
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200826 if (get_shell_surface(surface)) {
827 wl_resource_post_error(surface_resource,
828 WL_DISPLAY_ERROR_INVALID_OBJECT,
829 "wl_shell::get_shell_surface already requested");
830 return;
831 }
832
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200833 shsurf = calloc(1, sizeof *shsurf);
834 if (!shsurf) {
835 wl_resource_post_no_memory(resource);
836 return;
837 }
838
839 shsurf->resource.destroy = destroy_shell_surface;
840 shsurf->resource.object.id = id;
841 shsurf->resource.object.interface = &wl_shell_surface_interface;
842 shsurf->resource.object.implementation =
843 (void (**)(void)) &shell_surface_implementation;
844 shsurf->resource.data = shsurf;
845
Alex Wu4539b082012-03-01 12:57:46 +0800846 shsurf->saved_position_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200847 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +0800848 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
849 shsurf->fullscreen.framerate = 0;
850 shsurf->fullscreen.black_surface = NULL;
851 wl_list_init(&shsurf->fullscreen.transform.link);
852
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200853 shsurf->surface_destroy_listener.func = shell_handle_surface_destroy;
854 wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
855 &shsurf->surface_destroy_listener.link);
856
857 /* init link so its safe to always remove it in destroy_shell_surface */
858 wl_list_init(&shsurf->link);
859
Pekka Paalanen460099f2012-01-20 16:48:25 +0200860 /* empty when not in use */
861 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500862 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200863
Pekka Paalanen98262232011-12-01 10:42:22 +0200864 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200865
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200866 wl_client_add_resource(client, &shsurf->resource);
867}
868
869static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200870 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500871};
872
Kristian Høgsberg07937562011-04-12 17:25:42 -0400873static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500874handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200875{
876 proc->pid = 0;
877}
878
879static void
Pekka Paalanen77346a62011-11-30 16:26:35 +0200880launch_screensaver(struct wl_shell *shell)
881{
882 if (shell->screensaver.binding)
883 return;
884
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200885 if (!shell->screensaver.path)
886 return;
887
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500888 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200889 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200890 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200891 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200892}
893
894static void
895terminate_screensaver(struct wl_shell *shell)
896{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200897 if (shell->screensaver.process.pid == 0)
898 return;
899
900 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200901}
902
903static void
904show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
905{
906 struct wl_list *list;
907
908 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500909 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200910 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500911 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200912
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500913 wl_list_remove(&surface->surface->layer_link);
914 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200915 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200916 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200917}
918
919static void
920hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
921{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500922 wl_list_remove(&surface->surface->layer_link);
923 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200924 surface->surface->output = NULL;
925}
926
927static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400928desktop_shell_set_background(struct wl_client *client,
929 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100930 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400931 struct wl_resource *surface_resource)
932{
933 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200934 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500935 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200936 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400937
Pekka Paalanen98262232011-12-01 10:42:22 +0200938 if (reset_shell_surface_type(shsurf))
939 return;
940
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100941 wl_list_for_each(priv, &shell->backgrounds, link) {
942 if (priv->output == output_resource->data) {
943 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500944 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100945 wl_list_remove(&priv->link);
946 break;
947 }
948 }
949
Pekka Paalanen068ae942011-11-28 14:11:15 +0200950 shsurf->type = SHELL_SURFACE_BACKGROUND;
951 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100952
Pekka Paalanen068ae942011-11-28 14:11:15 +0200953 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100954
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200955 weston_surface_set_position(surface, shsurf->output->x,
956 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200957
Kristian Høgsberg75840622011-09-06 13:48:16 -0400958 wl_resource_post_event(resource,
959 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500960 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200961 shsurf->output->current->width,
962 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400963}
964
965static void
966desktop_shell_set_panel(struct wl_client *client,
967 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100968 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400969 struct wl_resource *surface_resource)
970{
971 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200972 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500973 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200974 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400975
Pekka Paalanen98262232011-12-01 10:42:22 +0200976 if (reset_shell_surface_type(shsurf))
977 return;
978
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100979 wl_list_for_each(priv, &shell->panels, link) {
980 if (priv->output == output_resource->data) {
981 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500982 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100983 wl_list_remove(&priv->link);
984 break;
985 }
986 }
987
Pekka Paalanen068ae942011-11-28 14:11:15 +0200988 shsurf->type = SHELL_SURFACE_PANEL;
989 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100990
Pekka Paalanen068ae942011-11-28 14:11:15 +0200991 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100992
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200993 weston_surface_set_position(surface, shsurf->output->x,
994 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200995
Kristian Høgsberg75840622011-09-06 13:48:16 -0400996 wl_resource_post_event(resource,
997 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500998 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200999 shsurf->output->current->width,
1000 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001001}
1002
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001003static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001004handle_lock_surface_destroy(struct wl_listener *listener,
1005 struct wl_resource *resource, uint32_t time)
1006{
1007 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +02001008 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001009
1010 fprintf(stderr, "lock surface gone\n");
1011 shell->lock_surface = NULL;
1012}
1013
1014static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001015desktop_shell_set_lock_surface(struct wl_client *client,
1016 struct wl_resource *resource,
1017 struct wl_resource *surface_resource)
1018{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001019 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001020 struct shell_surface *surface = surface_resource->data;
1021
1022 if (reset_shell_surface_type(surface))
1023 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001024
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001025 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001026
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001027 if (!shell->locked)
1028 return;
1029
Pekka Paalanen98262232011-12-01 10:42:22 +02001030 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001031
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001032 shell->lock_surface_listener.func = handle_lock_surface_destroy;
1033 wl_list_insert(&surface_resource->destroy_listener_list,
1034 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001035
Pekka Paalanen068ae942011-11-28 14:11:15 +02001036 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001037}
1038
1039static void
1040resume_desktop(struct wl_shell *shell)
1041{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001042 struct shell_surface *tmp;
1043
1044 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1045 hide_screensaver(shell, tmp);
1046
1047 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001048
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001049 wl_list_remove(&shell->lock_layer.link);
1050 wl_list_insert(&shell->compositor->cursor_layer.link,
1051 &shell->fullscreen_layer.link);
1052 wl_list_insert(&shell->fullscreen_layer.link,
1053 &shell->panel_layer.link);
1054 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001055
1056 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001057 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001058 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001059 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001060 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001061}
1062
1063static void
1064desktop_shell_unlock(struct wl_client *client,
1065 struct wl_resource *resource)
1066{
1067 struct wl_shell *shell = resource->data;
1068
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001069 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001070
1071 if (shell->locked)
1072 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001073}
1074
Kristian Høgsberg75840622011-09-06 13:48:16 -04001075static const struct desktop_shell_interface desktop_shell_implementation = {
1076 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001077 desktop_shell_set_panel,
1078 desktop_shell_set_lock_surface,
1079 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001080};
1081
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001082static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001083get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001084{
1085 struct shell_surface *shsurf;
1086
1087 shsurf = get_shell_surface(surface);
1088 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001089 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001090 return shsurf->type;
1091}
1092
Kristian Høgsberg75840622011-09-06 13:48:16 -04001093static void
Kristian Høgsberg07937562011-04-12 17:25:42 -04001094move_binding(struct wl_input_device *device, uint32_t time,
1095 uint32_t key, uint32_t button, uint32_t state, void *data)
1096{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001097 struct weston_surface *surface =
1098 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001099
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001100 if (surface == NULL)
1101 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001102
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001103 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001104 case SHELL_SURFACE_PANEL:
1105 case SHELL_SURFACE_BACKGROUND:
1106 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001107 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001108 return;
1109 default:
1110 break;
1111 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001112
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001113 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001114}
1115
1116static void
1117resize_binding(struct wl_input_device *device, uint32_t time,
1118 uint32_t key, uint32_t button, uint32_t state, void *data)
1119{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001120 struct weston_surface *surface =
1121 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001122 uint32_t edges = 0;
1123 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001124 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001125
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001126 if (surface == NULL)
1127 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001128
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001129 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001130 if (!shsurf)
1131 return;
1132
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001133 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001134 case SHELL_SURFACE_PANEL:
1135 case SHELL_SURFACE_BACKGROUND:
1136 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001137 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001138 return;
1139 default:
1140 break;
1141 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001142
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001143 weston_surface_from_global(surface,
1144 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001145
Pekka Paalanen60921e52012-01-25 15:55:43 +02001146 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001147 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001148 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001149 edges |= 0;
1150 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001151 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001152
Pekka Paalanen60921e52012-01-25 15:55:43 +02001153 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001154 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001155 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001156 edges |= 0;
1157 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001158 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001159
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001160 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001161 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001162}
1163
1164static void
Scott Moreauc6d7f602012-02-23 22:28:37 -07001165zoom_grab_key(struct wl_keyboard_grab *grab,
1166 uint32_t time, uint32_t key, int32_t state)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001167{
Scott Moreauc6d7f602012-02-23 22:28:37 -07001168 struct wl_input_device *device = grab->input_device;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001169 struct weston_input_device *wd = (struct weston_input_device *) device;
1170 struct weston_compositor *compositor = wd->compositor;
1171 struct weston_output *output;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001172 struct weston_zoom_grab *zoom;
1173
1174 if (!(wd->modifier_state & MODIFIER_SUPER)) {
1175 zoom = container_of(grab, struct weston_zoom_grab, grab);
1176 wl_input_device_end_keyboard_grab(device, time);
1177 free(zoom);
1178 return;
1179 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001180
1181 wl_list_for_each(output, &compositor->output_list, link) {
1182 if (pixman_region32_contains_point(&output->region,
1183 device->x, device->y, NULL)) {
Scott Moreauc6d7f602012-02-23 22:28:37 -07001184 if (state && key == KEY_UP) {
1185 output->zoom.active = 1;
1186 output->zoom.level -= output->zoom.increment;
1187 }
1188 if (state && key == KEY_DOWN)
1189 output->zoom.level += output->zoom.increment;
1190
1191 if (output->zoom.level >= 1.0) {
1192 output->zoom.active = 0;
1193 output->zoom.level = 1.0;
1194 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001195
1196 if (output->zoom.level < output->zoom.increment)
1197 output->zoom.level = output->zoom.increment;
1198
1199 weston_output_update_zoom(output, device->x, device->y);
1200 }
1201 }
1202}
1203
Scott Moreauc6d7f602012-02-23 22:28:37 -07001204static const struct wl_keyboard_grab_interface zoom_grab = {
1205 zoom_grab_key,
1206};
1207
Scott Moreauccbf29d2012-02-22 14:21:41 -07001208static void
Scott Moreauc6d7f602012-02-23 22:28:37 -07001209zoom_binding(struct wl_input_device *device, uint32_t time,
Scott Moreauccbf29d2012-02-22 14:21:41 -07001210 uint32_t key, uint32_t button, uint32_t state, void *data)
1211{
1212 struct weston_input_device *wd = (struct weston_input_device *) device;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001213 struct weston_zoom_grab *zoom;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001214
Scott Moreauc6d7f602012-02-23 22:28:37 -07001215 zoom = malloc(sizeof *zoom);
1216 if (!zoom)
1217 return;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001218
Scott Moreauc6d7f602012-02-23 22:28:37 -07001219 zoom->grab.interface = &zoom_grab;
1220
1221 wl_input_device_start_keyboard_grab(&wd->input_device, &zoom->grab, time);
Scott Moreauccbf29d2012-02-22 14:21:41 -07001222}
1223
1224static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001225terminate_binding(struct wl_input_device *device, uint32_t time,
1226 uint32_t key, uint32_t button, uint32_t state, void *data)
1227{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001228 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001229
1230 if (state)
1231 wl_display_terminate(compositor->wl_display);
1232}
1233
1234static void
Scott Moreau447013d2012-02-18 05:05:29 -07001235rotate_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001236 uint32_t time, int32_t x, int32_t y)
1237{
1238 struct rotate_grab *rotate =
1239 container_of(grab, struct rotate_grab, grab);
1240 struct wl_input_device *device = grab->input_device;
1241 struct shell_surface *surface = rotate->surface;
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001242 GLfloat cx = 0.5f * surface->surface->geometry.width;
1243 GLfloat cy = 0.5f * surface->surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001244 GLfloat dx, dy;
1245 GLfloat r;
1246
1247 dx = device->x - rotate->center.x;
1248 dy = device->y - rotate->center.y;
1249 r = sqrtf(dx * dx + dy * dy);
1250
1251 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001252 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001253
1254 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001255 struct weston_matrix *matrix =
1256 &surface->rotation.transform.matrix;
1257
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001258 weston_matrix_init(&rotate->rotation);
1259 rotate->rotation.d[0] = dx / r;
1260 rotate->rotation.d[4] = -dy / r;
1261 rotate->rotation.d[1] = -rotate->rotation.d[4];
1262 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001263
1264 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001265 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001266 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1267 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001268 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001269
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001270 wl_list_insert(
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001271 &surface->surface->geometry.transformation_list,
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001272 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001273 } else {
1274 wl_list_init(&surface->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001275 weston_matrix_init(&surface->rotation.rotation);
1276 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001277 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001278
1279 /* Repaint implies weston_surface_update_transform(), which
1280 * lazily applies the damage due to rotation update.
1281 */
1282 weston_compositor_schedule_repaint(surface->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001283}
1284
1285static void
Scott Moreau447013d2012-02-18 05:05:29 -07001286rotate_grab_button(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001287 uint32_t time, int32_t button, int32_t state)
1288{
1289 struct rotate_grab *rotate =
1290 container_of(grab, struct rotate_grab, grab);
1291 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001292 struct shell_surface *surface = rotate->surface;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001293
1294 if (device->button_count == 0 && state == 0) {
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001295 weston_matrix_multiply(&surface->rotation.rotation,
1296 &rotate->rotation);
Scott Moreau447013d2012-02-18 05:05:29 -07001297 wl_input_device_end_pointer_grab(device, time);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001298 free(rotate);
1299 }
1300}
1301
Scott Moreau447013d2012-02-18 05:05:29 -07001302static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001303 noop_grab_focus,
1304 rotate_grab_motion,
1305 rotate_grab_button,
1306};
1307
1308static void
1309rotate_binding(struct wl_input_device *device, uint32_t time,
1310 uint32_t key, uint32_t button, uint32_t state, void *data)
1311{
1312 struct weston_surface *base_surface =
1313 (struct weston_surface *) device->pointer_focus;
1314 struct shell_surface *surface;
1315 struct rotate_grab *rotate;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001316 GLfloat dx, dy;
1317 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001318
1319 if (base_surface == NULL)
1320 return;
1321
1322 surface = get_shell_surface(base_surface);
1323 if (!surface)
1324 return;
1325
1326 switch (surface->type) {
1327 case SHELL_SURFACE_PANEL:
1328 case SHELL_SURFACE_BACKGROUND:
1329 case SHELL_SURFACE_FULLSCREEN:
1330 case SHELL_SURFACE_SCREENSAVER:
1331 return;
1332 default:
1333 break;
1334 }
1335
Pekka Paalanen460099f2012-01-20 16:48:25 +02001336 rotate = malloc(sizeof *rotate);
1337 if (!rotate)
1338 return;
1339
1340 rotate->grab.interface = &rotate_grab_interface;
1341 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001342
1343 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001344 surface->surface->geometry.width / 2,
1345 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001346 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001347
Scott Moreau447013d2012-02-18 05:05:29 -07001348 wl_input_device_start_pointer_grab(device, &rotate->grab, time);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001349
1350 dx = device->x - rotate->center.x;
1351 dy = device->y - rotate->center.y;
1352 r = sqrtf(dx * dx + dy * dy);
1353 if (r > 20.0f) {
1354 struct weston_matrix inverse;
1355
1356 weston_matrix_init(&inverse);
1357 inverse.d[0] = dx / r;
1358 inverse.d[4] = dy / r;
1359 inverse.d[1] = -inverse.d[4];
1360 inverse.d[5] = inverse.d[0];
1361 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1362 } else {
1363 weston_matrix_init(&surface->rotation.rotation);
1364 weston_matrix_init(&rotate->rotation);
1365 }
1366
Pekka Paalanenb29f4122012-02-14 14:59:18 +02001367 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001368}
1369
1370static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001371activate(struct weston_shell *base, struct weston_surface *es,
1372 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001373{
1374 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001375 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001376
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001377 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001378
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001379 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001380 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001381
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001382 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001383 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001384 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001385 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001386 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001387
Pekka Paalanen77346a62011-11-30 16:26:35 +02001388 case SHELL_SURFACE_SCREENSAVER:
1389 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001390 if (shell->lock_surface)
1391 weston_surface_restack(es,
1392 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001393 break;
Alex Wu4539b082012-03-01 12:57:46 +08001394 case SHELL_SURFACE_FULLSCREEN:
1395 /* should on top of panels */
1396 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001397 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001398 weston_surface_restack(es,
1399 &shell->toplevel_layer.surface_list);
1400 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001401 }
1402}
1403
1404static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001405click_to_activate_binding(struct wl_input_device *device,
Alex Wu4539b082012-03-01 12:57:46 +08001406 uint32_t time, uint32_t key,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001407 uint32_t button, uint32_t state, void *data)
1408{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001409 struct weston_input_device *wd = (struct weston_input_device *) device;
1410 struct weston_compositor *compositor = data;
1411 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001412 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001413
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001414 focus = (struct weston_surface *) device->pointer_focus;
Alex Wu4539b082012-03-01 12:57:46 +08001415 upper = container_of(focus->link.prev, struct weston_surface, link);
1416 if (focus->link.prev != &compositor->surface_list &&
1417 get_shell_surface_type(upper) == SHELL_SURFACE_FULLSCREEN) {
1418 printf("%s: focus is black surface, raise its fullscreen surface\n", __func__);
1419 shell_stack_fullscreen(get_shell_surface(upper));
1420 focus = upper;
1421 }
1422
Scott Moreau447013d2012-02-18 05:05:29 -07001423 if (state && focus && device->pointer_grab == &device->default_pointer_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001424 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001425}
1426
1427static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001428lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001429{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001430 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001431 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001432 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001433 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001434 uint32_t time;
1435
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001436 if (shell->locked) {
1437 wl_list_for_each(output, &shell->compositor->output_list, link)
1438 /* TODO: find a way to jump to other DPMS levels */
1439 if (output->set_dpms)
1440 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001441 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001442 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001443
1444 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001445
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001446 /* Hide all surfaces by removing the fullscreen, panel and
1447 * toplevel layers. This way nothing else can show or receive
1448 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001449
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001450 wl_list_remove(&shell->panel_layer.link);
1451 wl_list_remove(&shell->toplevel_layer.link);
1452 wl_list_remove(&shell->fullscreen_layer.link);
1453 wl_list_insert(&shell->compositor->cursor_layer.link,
1454 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001455
Pekka Paalanen77346a62011-11-30 16:26:35 +02001456 launch_screensaver(shell);
1457
1458 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1459 show_screensaver(shell, shsurf);
1460
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001461 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001462 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001463 weston_compositor_wake(shell->compositor);
1464 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001465 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001466
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001467 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001468 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001469
1470 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001471 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001472 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1473 wl_input_device_set_keyboard_focus(&device->input_device,
1474 NULL, time);
1475 }
1476
1477 /* TODO: disable bindings that should not work while locked. */
1478
1479 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001480}
1481
1482static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001483unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001484{
1485 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1486
Pekka Paalanend81c2162011-11-16 13:47:34 +02001487 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001488 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001489 return;
1490 }
1491
1492 /* If desktop-shell client has gone away, unlock immediately. */
1493 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001494 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001495 return;
1496 }
1497
1498 if (shell->prepare_event_sent)
1499 return;
1500
1501 wl_resource_post_event(shell->child.desktop_shell,
1502 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1503 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001504}
1505
1506static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001507center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001508{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001509 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001510 GLfloat x = (mode->width - surface->geometry.width) / 2;
1511 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001512
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001513 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001514}
1515
1516static void
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001517map(struct weston_shell *base, struct weston_surface *surface,
1518 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001519{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001520 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001521 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001522 struct shell_surface *shsurf;
1523 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Juan Zhao96879df2012-02-07 08:45:41 +08001524 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001525
Pekka Paalanen77346a62011-11-30 16:26:35 +02001526 shsurf = get_shell_surface(surface);
1527 if (shsurf)
1528 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001529
Pekka Paalanen60921e52012-01-25 15:55:43 +02001530 surface->geometry.width = width;
1531 surface->geometry.height = height;
1532 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001533
Ander Conselvan de Oliveira30eebc72012-02-15 17:02:57 +02001534 weston_compositor_update_drag_surfaces(compositor);
1535
Pekka Paalanen77346a62011-11-30 16:26:35 +02001536 /* initial positioning, see also configure() */
1537 switch (surface_type) {
1538 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001539 weston_surface_set_position(surface, 10 + random() % 400,
1540 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001541 break;
1542 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001543 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001544 break;
Alex Wu4539b082012-03-01 12:57:46 +08001545 case SHELL_SURFACE_FULLSCREEN:
1546 shell_map_fullscreen(shsurf);
1547 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001548 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001549 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08001550 panel_height = get_output_panel_height(shell,surface->output);
1551 weston_surface_set_position(surface, surface->output->x,
1552 surface->output->y + panel_height);
1553 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001554 case SHELL_SURFACE_LOCK:
1555 center_on_output(surface, get_default_output(compositor));
1556 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001557 case SHELL_SURFACE_POPUP:
1558 shell_map_popup(shsurf, shsurf->popup.time);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001559 case SHELL_SURFACE_NONE:
1560 weston_surface_set_position(surface,
1561 surface->geometry.x + sx,
1562 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02001563 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001564 default:
1565 ;
1566 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001567
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001568 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001569 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001570 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001571 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001572 wl_list_insert(&shell->background_layer.surface_list,
1573 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001574 break;
1575 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001576 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001577 wl_list_insert(&shell->panel_layer.surface_list,
1578 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001579 break;
1580 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001581 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001582 wl_list_insert(&shell->lock_layer.surface_list,
1583 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001584 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001585 break;
1586 case SHELL_SURFACE_SCREENSAVER:
1587 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001588 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001589 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001590 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001591 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001592 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001593 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001594 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001595 break;
Alex Wu4539b082012-03-01 12:57:46 +08001596 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02001597 case SHELL_SURFACE_NONE:
1598 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001599 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001600 wl_list_insert(&shell->toplevel_layer.surface_list,
1601 &surface->layer_link);
1602 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001603 }
1604
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001605 weston_surface_assign_output(surface);
1606 weston_compositor_repick(compositor);
1607 if (surface_type == SHELL_SURFACE_MAXIMIZED)
1608 surface->output = shsurf->output;
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001609
Juan Zhao7bb92f02011-12-15 11:31:51 -05001610 switch (surface_type) {
1611 case SHELL_SURFACE_TOPLEVEL:
1612 case SHELL_SURFACE_TRANSIENT:
1613 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08001614 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05001615 if (!shell->locked)
1616 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001617 (struct weston_input_device *)
Alex Wu4539b082012-03-01 12:57:46 +08001618 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001619 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001620 break;
1621 default:
1622 break;
1623 }
1624
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001625 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001626 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001627}
1628
1629static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001630configure(struct weston_shell *base, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001631 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001632{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001633 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001634 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Alex Wu4539b082012-03-01 12:57:46 +08001635 enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001636 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001637
Pekka Paalanen77346a62011-11-30 16:26:35 +02001638 shsurf = get_shell_surface(surface);
1639 if (shsurf)
1640 surface_type = shsurf->type;
1641
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001642 surface->geometry.x = x;
1643 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001644 surface->geometry.width = width;
1645 surface->geometry.height = height;
1646 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001647
1648 switch (surface_type) {
1649 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001650 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001651 break;
Alex Wu4539b082012-03-01 12:57:46 +08001652 case SHELL_SURFACE_FULLSCREEN:
1653 shell_configure_fullscreen(shsurf);
1654 if (prev_surface_type != SHELL_SURFACE_FULLSCREEN)
1655 shell_stack_fullscreen(shsurf);
1656 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001657 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001658 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001659 surface->geometry.x = surface->output->x;
1660 surface->geometry.y = surface->output->y +
1661 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08001662 break;
Alex Wu4539b082012-03-01 12:57:46 +08001663 case SHELL_SURFACE_TOPLEVEL:
1664 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001665 default:
1666 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001667 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001668
Alex Wu4539b082012-03-01 12:57:46 +08001669 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001670 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001671 weston_surface_assign_output(surface);
Alex Wu4539b082012-03-01 12:57:46 +08001672 weston_compositor_repick(surface->compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001673
1674 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1675 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08001676 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
1677 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001678 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001679}
1680
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001681static int launch_desktop_shell_process(struct wl_shell *shell);
1682
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001683static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001684desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001685{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001686 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001687 struct wl_shell *shell =
1688 container_of(process, struct wl_shell, child.process);
1689
1690 shell->child.process.pid = 0;
1691 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001692
1693 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1694 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001695 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001696 shell->child.deathstamp = time;
1697 shell->child.deathcount = 0;
1698 }
1699
1700 shell->child.deathcount++;
1701 if (shell->child.deathcount > 5) {
1702 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1703 return;
1704 }
1705
1706 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1707 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001708}
1709
1710static int
1711launch_desktop_shell_process(struct wl_shell *shell)
1712{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001713 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001714
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001715 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001716 &shell->child.process,
1717 shell_exe,
1718 desktop_shell_sigchld);
1719
1720 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001721 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001722 return 0;
1723}
1724
1725static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001726bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1727{
1728 struct wl_shell *shell = data;
1729
1730 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001731 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001732}
1733
Kristian Høgsberg75840622011-09-06 13:48:16 -04001734static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001735unbind_desktop_shell(struct wl_resource *resource)
1736{
1737 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001738
1739 if (shell->locked)
1740 resume_desktop(shell);
1741
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001742 shell->child.desktop_shell = NULL;
1743 shell->prepare_event_sent = false;
1744 free(resource);
1745}
1746
1747static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001748bind_desktop_shell(struct wl_client *client,
1749 void *data, uint32_t version, uint32_t id)
1750{
1751 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001752 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001753
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001754 resource = wl_client_add_object(client, &desktop_shell_interface,
1755 &desktop_shell_implementation,
1756 id, shell);
1757
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001758 if (client == shell->child.client) {
1759 resource->destroy = unbind_desktop_shell;
1760 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001761 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001762 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001763
1764 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1765 "permission to bind desktop_shell denied");
1766 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001767}
1768
Pekka Paalanen6e168112011-11-24 11:34:05 +02001769static void
1770screensaver_set_surface(struct wl_client *client,
1771 struct wl_resource *resource,
1772 struct wl_resource *shell_surface_resource,
1773 struct wl_resource *output_resource)
1774{
1775 struct wl_shell *shell = resource->data;
1776 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001777 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001778
Pekka Paalanen98262232011-12-01 10:42:22 +02001779 if (reset_shell_surface_type(surface))
1780 return;
1781
Pekka Paalanen77346a62011-11-30 16:26:35 +02001782 surface->type = SHELL_SURFACE_SCREENSAVER;
1783
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001784 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001785 surface->output = output;
1786 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001787}
1788
1789static const struct screensaver_interface screensaver_implementation = {
1790 screensaver_set_surface
1791};
1792
1793static void
1794unbind_screensaver(struct wl_resource *resource)
1795{
1796 struct wl_shell *shell = resource->data;
1797
Pekka Paalanen77346a62011-11-30 16:26:35 +02001798 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001799 free(resource);
1800}
1801
1802static void
1803bind_screensaver(struct wl_client *client,
1804 void *data, uint32_t version, uint32_t id)
1805{
1806 struct wl_shell *shell = data;
1807 struct wl_resource *resource;
1808
1809 resource = wl_client_add_object(client, &screensaver_interface,
1810 &screensaver_implementation,
1811 id, shell);
1812
Pekka Paalanen77346a62011-11-30 16:26:35 +02001813 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001814 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001815 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001816 return;
1817 }
1818
1819 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1820 "interface object already bound");
1821 wl_resource_destroy(resource, 0);
1822}
1823
Kristian Høgsberg07045392012-02-19 18:52:44 -05001824struct switcher {
1825 struct weston_compositor *compositor;
1826 struct weston_surface *current;
1827 struct wl_listener listener;
1828 struct wl_keyboard_grab grab;
1829};
1830
1831static void
1832switcher_next(struct switcher *switcher)
1833{
1834 struct weston_compositor *compositor = switcher->compositor;
1835 struct weston_surface *surface;
1836 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
1837
1838 wl_list_for_each(surface, &compositor->surface_list, link) {
1839 /* Workaround for cursor surfaces. */
1840 if (surface->surface.resource.destroy_listener_list.next == NULL)
1841 continue;
1842
1843 switch (get_shell_surface_type(surface)) {
1844 case SHELL_SURFACE_TOPLEVEL:
1845 case SHELL_SURFACE_FULLSCREEN:
1846 case SHELL_SURFACE_MAXIMIZED:
1847 if (first == NULL)
1848 first = surface;
1849 if (prev == switcher->current)
1850 next = surface;
1851 prev = surface;
1852 surface->alpha = 64;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05001853 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05001854 weston_surface_damage(surface);
1855 break;
1856 default:
1857 break;
1858 }
1859 }
1860
1861 if (next == NULL)
1862 next = first;
1863
1864 wl_list_remove(&switcher->listener.link);
1865 wl_list_insert(next->surface.resource.destroy_listener_list.prev,
1866 &switcher->listener.link);
1867
1868 switcher->current = next;
1869 next->alpha = 255;
1870}
1871
1872static void
1873switcher_handle_surface_destroy(struct wl_listener *listener,
1874 struct wl_resource *resource, uint32_t time)
1875{
1876 struct switcher *switcher =
1877 container_of(listener, struct switcher, listener);
1878
1879 switcher_next(switcher);
1880}
1881
1882static void
1883switcher_destroy(struct switcher *switcher, uint32_t time)
1884{
1885 struct weston_compositor *compositor = switcher->compositor;
1886 struct weston_surface *surface;
1887 struct weston_input_device *device =
1888 (struct weston_input_device *) switcher->grab.input_device;
1889
1890 wl_list_for_each(surface, &compositor->surface_list, link) {
1891 surface->alpha = 255;
1892 weston_surface_damage(surface);
1893 }
1894
1895 activate(compositor->shell, switcher->current, device, time);
1896 wl_list_remove(&switcher->listener.link);
1897 wl_input_device_end_keyboard_grab(&device->input_device, time);
1898 free(switcher);
1899}
1900
1901static void
1902switcher_key(struct wl_keyboard_grab *grab,
1903 uint32_t time, uint32_t key, int32_t state)
1904{
1905 struct switcher *switcher = container_of(grab, struct switcher, grab);
1906 struct weston_input_device *device =
1907 (struct weston_input_device *) grab->input_device;
1908
1909 if ((device->modifier_state & MODIFIER_SUPER) == 0) {
1910 switcher_destroy(switcher, time);
1911 } else if (key == KEY_TAB && state) {
1912 switcher_next(switcher);
1913 }
1914};
1915
1916static const struct wl_keyboard_grab_interface switcher_grab = {
1917 switcher_key
1918};
1919
1920static void
1921switcher_binding(struct wl_input_device *device, uint32_t time,
1922 uint32_t key, uint32_t button,
1923 uint32_t state, void *data)
1924{
1925 struct weston_compositor *compositor = data;
1926 struct switcher *switcher;
1927
1928 switcher = malloc(sizeof *switcher);
1929 switcher->compositor = compositor;
1930 switcher->current = NULL;
1931 switcher->listener.func = switcher_handle_surface_destroy;
1932 wl_list_init(&switcher->listener.link);
1933
1934 switcher->grab.interface = &switcher_grab;
1935 wl_input_device_start_keyboard_grab(device, &switcher->grab, time);
1936 switcher_next(switcher);
1937}
1938
Pekka Paalanen3c647232011-12-22 13:43:43 +02001939static void
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001940backlight_binding(struct wl_input_device *device, uint32_t time,
1941 uint32_t key, uint32_t button, uint32_t state, void *data)
1942{
1943 struct weston_compositor *compositor = data;
1944 struct weston_output *output;
1945
1946 /* TODO: we're limiting to simple use cases, where we assume just
1947 * control on the primary display. We'd have to extend later if we
1948 * ever get support for setting backlights on random desktop LCD
1949 * panels though */
1950 output = get_default_output(compositor);
1951 if (!output)
1952 return;
1953
1954 if (!output->set_backlight)
1955 return;
1956
1957 if ((key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) &&
1958 output->backlight_current > 1)
1959 output->backlight_current--;
1960 else if ((key == KEY_F10 || key == KEY_BRIGHTNESSUP) &&
1961 output->backlight_current < 10)
1962 output->backlight_current++;
1963
1964 output->set_backlight(output, output->backlight_current);
1965}
1966
1967static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001968shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001969{
1970 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1971
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001972 if (shell->child.client)
1973 wl_client_destroy(shell->child.client);
1974
Pekka Paalanen3c647232011-12-22 13:43:43 +02001975 free(shell->screensaver.path);
1976 free(shell);
1977}
1978
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001979int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001980shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001981
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001982WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001983shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001984{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001985 struct wl_shell *shell;
1986
1987 shell = malloc(sizeof *shell);
1988 if (shell == NULL)
1989 return -1;
1990
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001991 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001992 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001993 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001994 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001995 shell->shell.map = map;
1996 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02001997 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001998
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001999 wl_list_init(&shell->backgrounds);
2000 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002001 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002002
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002003 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2004 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2005 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2006 weston_layer_init(&shell->background_layer,
2007 &shell->toplevel_layer.link);
2008 wl_list_init(&shell->lock_layer.surface_list);
2009
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002010 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002011
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002012 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2013 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002014 return -1;
2015
Kristian Høgsberg75840622011-09-06 13:48:16 -04002016 if (wl_display_add_global(ec->wl_display,
2017 &desktop_shell_interface,
2018 shell, bind_desktop_shell) == NULL)
2019 return -1;
2020
Pekka Paalanen6e168112011-11-24 11:34:05 +02002021 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2022 shell, bind_screensaver) == NULL)
2023 return -1;
2024
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002025 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002026 if (launch_desktop_shell_process(shell) != 0)
2027 return -1;
2028
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002029 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002030 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002031 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002032 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002033 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002034 MODIFIER_CTRL | MODIFIER_ALT,
2035 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002036 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002037 click_to_activate_binding, ec);
Scott Moreauccbf29d2012-02-22 14:21:41 -07002038 weston_compositor_add_binding(ec, KEY_UP, 0, MODIFIER_SUPER,
Scott Moreauc6d7f602012-02-23 22:28:37 -07002039 zoom_binding, shell);
Scott Moreauccbf29d2012-02-22 14:21:41 -07002040 weston_compositor_add_binding(ec, KEY_DOWN, 0, MODIFIER_SUPER,
Scott Moreauc6d7f602012-02-23 22:28:37 -07002041 zoom_binding, shell);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002042 weston_compositor_add_binding(ec, 0, BTN_LEFT,
2043 MODIFIER_SUPER | MODIFIER_ALT,
2044 rotate_binding, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002045 weston_compositor_add_binding(ec, KEY_TAB, 0, MODIFIER_SUPER,
2046 switcher_binding, ec);
2047
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002048 /* brightness */
2049 weston_compositor_add_binding(ec, KEY_F9, 0, MODIFIER_CTRL,
2050 backlight_binding, ec);
2051 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0,
2052 backlight_binding, ec);
2053 weston_compositor_add_binding(ec, KEY_F10, 0, MODIFIER_CTRL,
2054 backlight_binding, ec);
2055 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0,
2056 backlight_binding, ec);
2057
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002058 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002059
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002060 return 0;
2061}