blob: 2b61202ccc75b844690735eb4d3a86ad624150ce [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øgsberg32bed572012-03-01 17:11:36 -0500888 if (shell->screensaver.process.pid != 0) {
889 fprintf(stderr, "old screensaver still running\n");
890 return;
891 }
892
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500893 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200894 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200895 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200896 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200897}
898
899static void
900terminate_screensaver(struct wl_shell *shell)
901{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200902 if (shell->screensaver.process.pid == 0)
903 return;
904
905 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200906}
907
908static void
909show_screensaver(struct wl_shell *shell, struct shell_surface *surface)
910{
911 struct wl_list *list;
912
913 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500914 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200915 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500916 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200917
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500918 wl_list_remove(&surface->surface->layer_link);
919 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200920 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +0200921 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200922}
923
924static void
925hide_screensaver(struct wl_shell *shell, struct shell_surface *surface)
926{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500927 wl_list_remove(&surface->surface->layer_link);
928 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200929 surface->surface->output = NULL;
930}
931
932static void
Kristian Høgsberg75840622011-09-06 13:48:16 -0400933desktop_shell_set_background(struct wl_client *client,
934 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100935 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400936 struct wl_resource *surface_resource)
937{
938 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200939 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500940 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200941 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400942
Pekka Paalanen98262232011-12-01 10:42:22 +0200943 if (reset_shell_surface_type(shsurf))
944 return;
945
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100946 wl_list_for_each(priv, &shell->backgrounds, link) {
947 if (priv->output == output_resource->data) {
948 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500949 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100950 wl_list_remove(&priv->link);
951 break;
952 }
953 }
954
Pekka Paalanen068ae942011-11-28 14:11:15 +0200955 shsurf->type = SHELL_SURFACE_BACKGROUND;
956 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100957
Pekka Paalanen068ae942011-11-28 14:11:15 +0200958 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100959
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200960 weston_surface_set_position(surface, shsurf->output->x,
961 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200962
Kristian Høgsberg75840622011-09-06 13:48:16 -0400963 wl_resource_post_event(resource,
964 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500965 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +0200966 shsurf->output->current->width,
967 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -0400968}
969
970static void
971desktop_shell_set_panel(struct wl_client *client,
972 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100973 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -0400974 struct wl_resource *surface_resource)
975{
976 struct wl_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +0200977 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500978 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200979 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -0400980
Pekka Paalanen98262232011-12-01 10:42:22 +0200981 if (reset_shell_surface_type(shsurf))
982 return;
983
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100984 wl_list_for_each(priv, &shell->panels, link) {
985 if (priv->output == output_resource->data) {
986 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500987 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +0100988 wl_list_remove(&priv->link);
989 break;
990 }
991 }
992
Pekka Paalanen068ae942011-11-28 14:11:15 +0200993 shsurf->type = SHELL_SURFACE_PANEL;
994 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100995
Pekka Paalanen068ae942011-11-28 14:11:15 +0200996 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100997
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200998 weston_surface_set_position(surface, shsurf->output->x,
999 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001000
Kristian Høgsberg75840622011-09-06 13:48:16 -04001001 wl_resource_post_event(resource,
1002 DESKTOP_SHELL_CONFIGURE,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001003 weston_compositor_get_time(), 0, surface_resource,
Pekka Paalanen068ae942011-11-28 14:11:15 +02001004 shsurf->output->current->width,
1005 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001006}
1007
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001008static void
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001009handle_lock_surface_destroy(struct wl_listener *listener,
1010 struct wl_resource *resource, uint32_t time)
1011{
1012 struct wl_shell *shell =
Pekka Paalanen2ca86302011-11-16 13:47:35 +02001013 container_of(listener, struct wl_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001014
1015 fprintf(stderr, "lock surface gone\n");
1016 shell->lock_surface = NULL;
1017}
1018
1019static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001020desktop_shell_set_lock_surface(struct wl_client *client,
1021 struct wl_resource *resource,
1022 struct wl_resource *surface_resource)
1023{
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001024 struct wl_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001025 struct shell_surface *surface = surface_resource->data;
1026
1027 if (reset_shell_surface_type(surface))
1028 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001029
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001030 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001031
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001032 if (!shell->locked)
1033 return;
1034
Pekka Paalanen98262232011-12-01 10:42:22 +02001035 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001036
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001037 shell->lock_surface_listener.func = handle_lock_surface_destroy;
1038 wl_list_insert(&surface_resource->destroy_listener_list,
1039 &shell->lock_surface_listener.link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001040
Pekka Paalanen068ae942011-11-28 14:11:15 +02001041 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001042}
1043
1044static void
1045resume_desktop(struct wl_shell *shell)
1046{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001047 struct shell_surface *tmp;
1048
1049 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1050 hide_screensaver(shell, tmp);
1051
1052 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001053
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001054 wl_list_remove(&shell->lock_layer.link);
1055 wl_list_insert(&shell->compositor->cursor_layer.link,
1056 &shell->fullscreen_layer.link);
1057 wl_list_insert(&shell->fullscreen_layer.link,
1058 &shell->panel_layer.link);
1059 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001060
1061 shell->locked = false;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001062 weston_compositor_repick(shell->compositor);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001063 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001064 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001065 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001066}
1067
1068static void
1069desktop_shell_unlock(struct wl_client *client,
1070 struct wl_resource *resource)
1071{
1072 struct wl_shell *shell = resource->data;
1073
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001074 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001075
1076 if (shell->locked)
1077 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001078}
1079
Kristian Høgsberg75840622011-09-06 13:48:16 -04001080static const struct desktop_shell_interface desktop_shell_implementation = {
1081 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001082 desktop_shell_set_panel,
1083 desktop_shell_set_lock_surface,
1084 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001085};
1086
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001087static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001088get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001089{
1090 struct shell_surface *shsurf;
1091
1092 shsurf = get_shell_surface(surface);
1093 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001094 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001095 return shsurf->type;
1096}
1097
Kristian Høgsberg75840622011-09-06 13:48:16 -04001098static void
Kristian Høgsberg07937562011-04-12 17:25:42 -04001099move_binding(struct wl_input_device *device, uint32_t time,
1100 uint32_t key, uint32_t button, uint32_t state, void *data)
1101{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001102 struct weston_surface *surface =
1103 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001104
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001105 if (surface == NULL)
1106 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001107
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001108 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001109 case SHELL_SURFACE_PANEL:
1110 case SHELL_SURFACE_BACKGROUND:
1111 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001112 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001113 return;
1114 default:
1115 break;
1116 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001117
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001118 weston_surface_move(surface, (struct weston_input_device *) device, time);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001119}
1120
1121static void
1122resize_binding(struct wl_input_device *device, uint32_t time,
1123 uint32_t key, uint32_t button, uint32_t state, void *data)
1124{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001125 struct weston_surface *surface =
1126 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001127 uint32_t edges = 0;
1128 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001129 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001130
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001131 if (surface == NULL)
1132 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001133
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001134 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001135 if (!shsurf)
1136 return;
1137
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001138 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001139 case SHELL_SURFACE_PANEL:
1140 case SHELL_SURFACE_BACKGROUND:
1141 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001142 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001143 return;
1144 default:
1145 break;
1146 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001147
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001148 weston_surface_from_global(surface,
1149 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001150
Pekka Paalanen60921e52012-01-25 15:55:43 +02001151 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001152 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001153 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001154 edges |= 0;
1155 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001156 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001157
Pekka Paalanen60921e52012-01-25 15:55:43 +02001158 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001159 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001160 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001161 edges |= 0;
1162 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001163 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001164
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001165 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001166 time, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001167}
1168
1169static void
Scott Moreauc6d7f602012-02-23 22:28:37 -07001170zoom_grab_key(struct wl_keyboard_grab *grab,
1171 uint32_t time, uint32_t key, int32_t state)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001172{
Scott Moreauc6d7f602012-02-23 22:28:37 -07001173 struct wl_input_device *device = grab->input_device;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001174 struct weston_input_device *wd = (struct weston_input_device *) device;
1175 struct weston_compositor *compositor = wd->compositor;
1176 struct weston_output *output;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001177 struct weston_zoom_grab *zoom;
1178
1179 if (!(wd->modifier_state & MODIFIER_SUPER)) {
1180 zoom = container_of(grab, struct weston_zoom_grab, grab);
1181 wl_input_device_end_keyboard_grab(device, time);
1182 free(zoom);
1183 return;
1184 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001185
1186 wl_list_for_each(output, &compositor->output_list, link) {
1187 if (pixman_region32_contains_point(&output->region,
1188 device->x, device->y, NULL)) {
Scott Moreauc6d7f602012-02-23 22:28:37 -07001189 if (state && key == KEY_UP) {
1190 output->zoom.active = 1;
1191 output->zoom.level -= output->zoom.increment;
1192 }
1193 if (state && key == KEY_DOWN)
1194 output->zoom.level += output->zoom.increment;
1195
1196 if (output->zoom.level >= 1.0) {
1197 output->zoom.active = 0;
1198 output->zoom.level = 1.0;
1199 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001200
1201 if (output->zoom.level < output->zoom.increment)
1202 output->zoom.level = output->zoom.increment;
1203
1204 weston_output_update_zoom(output, device->x, device->y);
1205 }
1206 }
1207}
1208
Scott Moreauc6d7f602012-02-23 22:28:37 -07001209static const struct wl_keyboard_grab_interface zoom_grab = {
1210 zoom_grab_key,
1211};
1212
Scott Moreauccbf29d2012-02-22 14:21:41 -07001213static void
Scott Moreauc6d7f602012-02-23 22:28:37 -07001214zoom_binding(struct wl_input_device *device, uint32_t time,
Scott Moreauccbf29d2012-02-22 14:21:41 -07001215 uint32_t key, uint32_t button, uint32_t state, void *data)
1216{
1217 struct weston_input_device *wd = (struct weston_input_device *) device;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001218 struct weston_zoom_grab *zoom;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001219
Scott Moreauc6d7f602012-02-23 22:28:37 -07001220 zoom = malloc(sizeof *zoom);
1221 if (!zoom)
1222 return;
Scott Moreauccbf29d2012-02-22 14:21:41 -07001223
Scott Moreauc6d7f602012-02-23 22:28:37 -07001224 zoom->grab.interface = &zoom_grab;
1225
1226 wl_input_device_start_keyboard_grab(&wd->input_device, &zoom->grab, time);
Scott Moreauccbf29d2012-02-22 14:21:41 -07001227}
1228
1229static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001230terminate_binding(struct wl_input_device *device, uint32_t time,
1231 uint32_t key, uint32_t button, uint32_t state, void *data)
1232{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001233 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001234
1235 if (state)
1236 wl_display_terminate(compositor->wl_display);
1237}
1238
1239static void
Scott Moreau447013d2012-02-18 05:05:29 -07001240rotate_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001241 uint32_t time, int32_t x, int32_t y)
1242{
1243 struct rotate_grab *rotate =
1244 container_of(grab, struct rotate_grab, grab);
1245 struct wl_input_device *device = grab->input_device;
1246 struct shell_surface *surface = rotate->surface;
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001247 GLfloat cx = 0.5f * surface->surface->geometry.width;
1248 GLfloat cy = 0.5f * surface->surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001249 GLfloat dx, dy;
1250 GLfloat r;
1251
1252 dx = device->x - rotate->center.x;
1253 dy = device->y - rotate->center.y;
1254 r = sqrtf(dx * dx + dy * dy);
1255
1256 wl_list_remove(&surface->rotation.transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001257 surface->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001258
1259 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001260 struct weston_matrix *matrix =
1261 &surface->rotation.transform.matrix;
1262
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001263 weston_matrix_init(&rotate->rotation);
1264 rotate->rotation.d[0] = dx / r;
1265 rotate->rotation.d[4] = -dy / r;
1266 rotate->rotation.d[1] = -rotate->rotation.d[4];
1267 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001268
1269 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001270 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001271 weston_matrix_multiply(matrix, &surface->rotation.rotation);
1272 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001273 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001274
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001275 wl_list_insert(
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001276 &surface->surface->geometry.transformation_list,
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001277 &surface->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001278 } else {
1279 wl_list_init(&surface->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001280 weston_matrix_init(&surface->rotation.rotation);
1281 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001282 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001283
1284 /* Repaint implies weston_surface_update_transform(), which
1285 * lazily applies the damage due to rotation update.
1286 */
1287 weston_compositor_schedule_repaint(surface->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001288}
1289
1290static void
Scott Moreau447013d2012-02-18 05:05:29 -07001291rotate_grab_button(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001292 uint32_t time, int32_t button, int32_t state)
1293{
1294 struct rotate_grab *rotate =
1295 container_of(grab, struct rotate_grab, grab);
1296 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001297 struct shell_surface *surface = rotate->surface;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001298
1299 if (device->button_count == 0 && state == 0) {
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001300 weston_matrix_multiply(&surface->rotation.rotation,
1301 &rotate->rotation);
Scott Moreau447013d2012-02-18 05:05:29 -07001302 wl_input_device_end_pointer_grab(device, time);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001303 free(rotate);
1304 }
1305}
1306
Scott Moreau447013d2012-02-18 05:05:29 -07001307static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001308 noop_grab_focus,
1309 rotate_grab_motion,
1310 rotate_grab_button,
1311};
1312
1313static void
1314rotate_binding(struct wl_input_device *device, uint32_t time,
1315 uint32_t key, uint32_t button, uint32_t state, void *data)
1316{
1317 struct weston_surface *base_surface =
1318 (struct weston_surface *) device->pointer_focus;
1319 struct shell_surface *surface;
1320 struct rotate_grab *rotate;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001321 GLfloat dx, dy;
1322 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001323
1324 if (base_surface == NULL)
1325 return;
1326
1327 surface = get_shell_surface(base_surface);
1328 if (!surface)
1329 return;
1330
1331 switch (surface->type) {
1332 case SHELL_SURFACE_PANEL:
1333 case SHELL_SURFACE_BACKGROUND:
1334 case SHELL_SURFACE_FULLSCREEN:
1335 case SHELL_SURFACE_SCREENSAVER:
1336 return;
1337 default:
1338 break;
1339 }
1340
Pekka Paalanen460099f2012-01-20 16:48:25 +02001341 rotate = malloc(sizeof *rotate);
1342 if (!rotate)
1343 return;
1344
1345 rotate->grab.interface = &rotate_grab_interface;
1346 rotate->surface = surface;
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001347
1348 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001349 surface->surface->geometry.width / 2,
1350 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001351 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001352
Scott Moreau447013d2012-02-18 05:05:29 -07001353 wl_input_device_start_pointer_grab(device, &rotate->grab, time);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001354
1355 dx = device->x - rotate->center.x;
1356 dy = device->y - rotate->center.y;
1357 r = sqrtf(dx * dx + dy * dy);
1358 if (r > 20.0f) {
1359 struct weston_matrix inverse;
1360
1361 weston_matrix_init(&inverse);
1362 inverse.d[0] = dx / r;
1363 inverse.d[4] = dy / r;
1364 inverse.d[1] = -inverse.d[4];
1365 inverse.d[5] = inverse.d[0];
1366 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1367 } else {
1368 weston_matrix_init(&surface->rotation.rotation);
1369 weston_matrix_init(&rotate->rotation);
1370 }
1371
Pekka Paalanenb29f4122012-02-14 14:59:18 +02001372 wl_input_device_set_pointer_focus(device, NULL, time, 0, 0);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001373}
1374
1375static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001376activate(struct weston_shell *base, struct weston_surface *es,
1377 struct weston_input_device *device, uint32_t time)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001378{
1379 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001380 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001381
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001382 weston_surface_activate(es, device, time);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001383
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001384 if (compositor->wxs)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001385 weston_xserver_surface_activate(es);
Kristian Høgsbergd6e55252011-10-11 23:41:17 -04001386
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001387 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001388 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001389 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001390 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001391 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001392
Pekka Paalanen77346a62011-11-30 16:26:35 +02001393 case SHELL_SURFACE_SCREENSAVER:
1394 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001395 if (shell->lock_surface)
1396 weston_surface_restack(es,
1397 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001398 break;
Alex Wu4539b082012-03-01 12:57:46 +08001399 case SHELL_SURFACE_FULLSCREEN:
1400 /* should on top of panels */
1401 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001402 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001403 weston_surface_restack(es,
1404 &shell->toplevel_layer.surface_list);
1405 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001406 }
1407}
1408
1409static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001410click_to_activate_binding(struct wl_input_device *device,
Alex Wu4539b082012-03-01 12:57:46 +08001411 uint32_t time, uint32_t key,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001412 uint32_t button, uint32_t state, void *data)
1413{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001414 struct weston_input_device *wd = (struct weston_input_device *) device;
1415 struct weston_compositor *compositor = data;
1416 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001417 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001418
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001419 focus = (struct weston_surface *) device->pointer_focus;
Alex Wu4539b082012-03-01 12:57:46 +08001420 upper = container_of(focus->link.prev, struct weston_surface, link);
1421 if (focus->link.prev != &compositor->surface_list &&
1422 get_shell_surface_type(upper) == SHELL_SURFACE_FULLSCREEN) {
1423 printf("%s: focus is black surface, raise its fullscreen surface\n", __func__);
1424 shell_stack_fullscreen(get_shell_surface(upper));
1425 focus = upper;
1426 }
1427
Scott Moreau447013d2012-02-18 05:05:29 -07001428 if (state && focus && device->pointer_grab == &device->default_pointer_grab)
Kristian Høgsberg2a25cd42011-12-19 15:19:54 -05001429 activate(compositor->shell, focus, wd, time);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001430}
1431
1432static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001433lock(struct weston_shell *base)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001434{
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001435 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001436 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001437 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001438 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001439 uint32_t time;
1440
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001441 if (shell->locked) {
1442 wl_list_for_each(output, &shell->compositor->output_list, link)
1443 /* TODO: find a way to jump to other DPMS levels */
1444 if (output->set_dpms)
1445 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001446 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001447 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001448
1449 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001450
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001451 /* Hide all surfaces by removing the fullscreen, panel and
1452 * toplevel layers. This way nothing else can show or receive
1453 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001454
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001455 wl_list_remove(&shell->panel_layer.link);
1456 wl_list_remove(&shell->toplevel_layer.link);
1457 wl_list_remove(&shell->fullscreen_layer.link);
1458 wl_list_insert(&shell->compositor->cursor_layer.link,
1459 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001460
Pekka Paalanen77346a62011-11-30 16:26:35 +02001461 launch_screensaver(shell);
1462
1463 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1464 show_screensaver(shell, shsurf);
1465
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001466 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001467 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001468 weston_compositor_wake(shell->compositor);
1469 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001470 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001471
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001472 /* reset pointer foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001473 weston_compositor_repick(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001474
1475 /* reset keyboard foci */
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001476 time = weston_compositor_get_time();
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001477 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1478 wl_input_device_set_keyboard_focus(&device->input_device,
1479 NULL, time);
1480 }
1481
1482 /* TODO: disable bindings that should not work while locked. */
1483
1484 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001485}
1486
1487static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001488unlock(struct weston_shell *base)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001489{
1490 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1491
Pekka Paalanend81c2162011-11-16 13:47:34 +02001492 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001493 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001494 return;
1495 }
1496
1497 /* If desktop-shell client has gone away, unlock immediately. */
1498 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001499 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001500 return;
1501 }
1502
1503 if (shell->prepare_event_sent)
1504 return;
1505
1506 wl_resource_post_event(shell->child.desktop_shell,
1507 DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
1508 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001509}
1510
1511static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001512center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001513{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001514 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001515 GLfloat x = (mode->width - surface->geometry.width) / 2;
1516 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001517
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001518 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001519}
1520
1521static void
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001522map(struct weston_shell *base, struct weston_surface *surface,
1523 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001524{
Kristian Høgsberg75840622011-09-06 13:48:16 -04001525 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001526 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001527 struct shell_surface *shsurf;
1528 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Juan Zhao96879df2012-02-07 08:45:41 +08001529 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001530
Pekka Paalanen77346a62011-11-30 16:26:35 +02001531 shsurf = get_shell_surface(surface);
1532 if (shsurf)
1533 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001534
Pekka Paalanen60921e52012-01-25 15:55:43 +02001535 surface->geometry.width = width;
1536 surface->geometry.height = height;
1537 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001538
Ander Conselvan de Oliveira30eebc72012-02-15 17:02:57 +02001539 weston_compositor_update_drag_surfaces(compositor);
1540
Pekka Paalanen77346a62011-11-30 16:26:35 +02001541 /* initial positioning, see also configure() */
1542 switch (surface_type) {
1543 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001544 weston_surface_set_position(surface, 10 + random() % 400,
1545 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001546 break;
1547 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001548 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001549 break;
Alex Wu4539b082012-03-01 12:57:46 +08001550 case SHELL_SURFACE_FULLSCREEN:
1551 shell_map_fullscreen(shsurf);
1552 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001553 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001554 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08001555 panel_height = get_output_panel_height(shell,surface->output);
1556 weston_surface_set_position(surface, surface->output->x,
1557 surface->output->y + panel_height);
1558 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001559 case SHELL_SURFACE_LOCK:
1560 center_on_output(surface, get_default_output(compositor));
1561 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001562 case SHELL_SURFACE_POPUP:
1563 shell_map_popup(shsurf, shsurf->popup.time);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001564 case SHELL_SURFACE_NONE:
1565 weston_surface_set_position(surface,
1566 surface->geometry.x + sx,
1567 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02001568 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001569 default:
1570 ;
1571 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001572
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001573 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001574 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001575 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001576 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001577 wl_list_insert(&shell->background_layer.surface_list,
1578 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001579 break;
1580 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001581 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001582 wl_list_insert(&shell->panel_layer.surface_list,
1583 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001584 break;
1585 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001586 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001587 wl_list_insert(&shell->lock_layer.surface_list,
1588 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001589 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001590 break;
1591 case SHELL_SURFACE_SCREENSAVER:
1592 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001593 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001594 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001595 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001596 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001597 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001598 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001599 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001600 break;
Alex Wu4539b082012-03-01 12:57:46 +08001601 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02001602 case SHELL_SURFACE_NONE:
1603 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001604 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001605 wl_list_insert(&shell->toplevel_layer.surface_list,
1606 &surface->layer_link);
1607 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001608 }
1609
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001610 weston_surface_assign_output(surface);
1611 weston_compositor_repick(compositor);
1612 if (surface_type == SHELL_SURFACE_MAXIMIZED)
1613 surface->output = shsurf->output;
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001614
Juan Zhao7bb92f02011-12-15 11:31:51 -05001615 switch (surface_type) {
1616 case SHELL_SURFACE_TOPLEVEL:
1617 case SHELL_SURFACE_TRANSIENT:
1618 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08001619 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05001620 if (!shell->locked)
1621 activate(base, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001622 (struct weston_input_device *)
Alex Wu4539b082012-03-01 12:57:46 +08001623 compositor->input_device,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001624 weston_compositor_get_time());
Juan Zhao7bb92f02011-12-15 11:31:51 -05001625 break;
1626 default:
1627 break;
1628 }
1629
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001630 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001631 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001632}
1633
1634static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001635configure(struct weston_shell *base, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001636 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001637{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001638 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001639 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Alex Wu4539b082012-03-01 12:57:46 +08001640 enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001641 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001642
Pekka Paalanen77346a62011-11-30 16:26:35 +02001643 shsurf = get_shell_surface(surface);
1644 if (shsurf)
1645 surface_type = shsurf->type;
1646
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001647 surface->geometry.x = x;
1648 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001649 surface->geometry.width = width;
1650 surface->geometry.height = height;
1651 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001652
1653 switch (surface_type) {
1654 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001655 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001656 break;
Alex Wu4539b082012-03-01 12:57:46 +08001657 case SHELL_SURFACE_FULLSCREEN:
1658 shell_configure_fullscreen(shsurf);
1659 if (prev_surface_type != SHELL_SURFACE_FULLSCREEN)
1660 shell_stack_fullscreen(shsurf);
1661 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001662 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001663 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001664 surface->geometry.x = surface->output->x;
1665 surface->geometry.y = surface->output->y +
1666 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08001667 break;
Alex Wu4539b082012-03-01 12:57:46 +08001668 case SHELL_SURFACE_TOPLEVEL:
1669 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001670 default:
1671 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001672 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001673
Alex Wu4539b082012-03-01 12:57:46 +08001674 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001675 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001676 weston_surface_assign_output(surface);
Alex Wu4539b082012-03-01 12:57:46 +08001677 weston_compositor_repick(surface->compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001678
1679 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1680 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08001681 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
1682 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001683 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001684}
1685
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001686static int launch_desktop_shell_process(struct wl_shell *shell);
1687
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001688static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001689desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001690{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001691 uint32_t time;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001692 struct wl_shell *shell =
1693 container_of(process, struct wl_shell, child.process);
1694
1695 shell->child.process.pid = 0;
1696 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001697
1698 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1699 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001700 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001701 shell->child.deathstamp = time;
1702 shell->child.deathcount = 0;
1703 }
1704
1705 shell->child.deathcount++;
1706 if (shell->child.deathcount > 5) {
1707 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1708 return;
1709 }
1710
1711 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1712 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001713}
1714
1715static int
1716launch_desktop_shell_process(struct wl_shell *shell)
1717{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001718 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001719
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001720 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001721 &shell->child.process,
1722 shell_exe,
1723 desktop_shell_sigchld);
1724
1725 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001726 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001727 return 0;
1728}
1729
1730static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001731bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1732{
1733 struct wl_shell *shell = data;
1734
1735 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001736 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001737}
1738
Kristian Høgsberg75840622011-09-06 13:48:16 -04001739static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001740unbind_desktop_shell(struct wl_resource *resource)
1741{
1742 struct wl_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001743
1744 if (shell->locked)
1745 resume_desktop(shell);
1746
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001747 shell->child.desktop_shell = NULL;
1748 shell->prepare_event_sent = false;
1749 free(resource);
1750}
1751
1752static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001753bind_desktop_shell(struct wl_client *client,
1754 void *data, uint32_t version, uint32_t id)
1755{
1756 struct wl_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001757 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001758
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001759 resource = wl_client_add_object(client, &desktop_shell_interface,
1760 &desktop_shell_implementation,
1761 id, shell);
1762
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001763 if (client == shell->child.client) {
1764 resource->destroy = unbind_desktop_shell;
1765 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001766 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001767 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001768
1769 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1770 "permission to bind desktop_shell denied");
1771 wl_resource_destroy(resource, 0);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001772}
1773
Pekka Paalanen6e168112011-11-24 11:34:05 +02001774static void
1775screensaver_set_surface(struct wl_client *client,
1776 struct wl_resource *resource,
1777 struct wl_resource *shell_surface_resource,
1778 struct wl_resource *output_resource)
1779{
1780 struct wl_shell *shell = resource->data;
1781 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001782 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001783
Pekka Paalanen98262232011-12-01 10:42:22 +02001784 if (reset_shell_surface_type(surface))
1785 return;
1786
Pekka Paalanen77346a62011-11-30 16:26:35 +02001787 surface->type = SHELL_SURFACE_SCREENSAVER;
1788
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001789 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001790 surface->output = output;
1791 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001792}
1793
1794static const struct screensaver_interface screensaver_implementation = {
1795 screensaver_set_surface
1796};
1797
1798static void
1799unbind_screensaver(struct wl_resource *resource)
1800{
1801 struct wl_shell *shell = resource->data;
1802
Pekka Paalanen77346a62011-11-30 16:26:35 +02001803 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001804 free(resource);
1805}
1806
1807static void
1808bind_screensaver(struct wl_client *client,
1809 void *data, uint32_t version, uint32_t id)
1810{
1811 struct wl_shell *shell = data;
1812 struct wl_resource *resource;
1813
1814 resource = wl_client_add_object(client, &screensaver_interface,
1815 &screensaver_implementation,
1816 id, shell);
1817
Pekka Paalanen77346a62011-11-30 16:26:35 +02001818 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001819 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001820 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001821 return;
1822 }
1823
1824 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1825 "interface object already bound");
1826 wl_resource_destroy(resource, 0);
1827}
1828
Kristian Høgsberg07045392012-02-19 18:52:44 -05001829struct switcher {
1830 struct weston_compositor *compositor;
1831 struct weston_surface *current;
1832 struct wl_listener listener;
1833 struct wl_keyboard_grab grab;
1834};
1835
1836static void
1837switcher_next(struct switcher *switcher)
1838{
1839 struct weston_compositor *compositor = switcher->compositor;
1840 struct weston_surface *surface;
1841 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
1842
1843 wl_list_for_each(surface, &compositor->surface_list, link) {
1844 /* Workaround for cursor surfaces. */
1845 if (surface->surface.resource.destroy_listener_list.next == NULL)
1846 continue;
1847
1848 switch (get_shell_surface_type(surface)) {
1849 case SHELL_SURFACE_TOPLEVEL:
1850 case SHELL_SURFACE_FULLSCREEN:
1851 case SHELL_SURFACE_MAXIMIZED:
1852 if (first == NULL)
1853 first = surface;
1854 if (prev == switcher->current)
1855 next = surface;
1856 prev = surface;
1857 surface->alpha = 64;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05001858 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05001859 weston_surface_damage(surface);
1860 break;
1861 default:
1862 break;
1863 }
1864 }
1865
1866 if (next == NULL)
1867 next = first;
1868
1869 wl_list_remove(&switcher->listener.link);
1870 wl_list_insert(next->surface.resource.destroy_listener_list.prev,
1871 &switcher->listener.link);
1872
1873 switcher->current = next;
1874 next->alpha = 255;
1875}
1876
1877static void
1878switcher_handle_surface_destroy(struct wl_listener *listener,
1879 struct wl_resource *resource, uint32_t time)
1880{
1881 struct switcher *switcher =
1882 container_of(listener, struct switcher, listener);
1883
1884 switcher_next(switcher);
1885}
1886
1887static void
1888switcher_destroy(struct switcher *switcher, uint32_t time)
1889{
1890 struct weston_compositor *compositor = switcher->compositor;
1891 struct weston_surface *surface;
1892 struct weston_input_device *device =
1893 (struct weston_input_device *) switcher->grab.input_device;
1894
1895 wl_list_for_each(surface, &compositor->surface_list, link) {
1896 surface->alpha = 255;
1897 weston_surface_damage(surface);
1898 }
1899
1900 activate(compositor->shell, switcher->current, device, time);
1901 wl_list_remove(&switcher->listener.link);
1902 wl_input_device_end_keyboard_grab(&device->input_device, time);
1903 free(switcher);
1904}
1905
1906static void
1907switcher_key(struct wl_keyboard_grab *grab,
1908 uint32_t time, uint32_t key, int32_t state)
1909{
1910 struct switcher *switcher = container_of(grab, struct switcher, grab);
1911 struct weston_input_device *device =
1912 (struct weston_input_device *) grab->input_device;
1913
1914 if ((device->modifier_state & MODIFIER_SUPER) == 0) {
1915 switcher_destroy(switcher, time);
1916 } else if (key == KEY_TAB && state) {
1917 switcher_next(switcher);
1918 }
1919};
1920
1921static const struct wl_keyboard_grab_interface switcher_grab = {
1922 switcher_key
1923};
1924
1925static void
1926switcher_binding(struct wl_input_device *device, uint32_t time,
1927 uint32_t key, uint32_t button,
1928 uint32_t state, void *data)
1929{
1930 struct weston_compositor *compositor = data;
1931 struct switcher *switcher;
1932
1933 switcher = malloc(sizeof *switcher);
1934 switcher->compositor = compositor;
1935 switcher->current = NULL;
1936 switcher->listener.func = switcher_handle_surface_destroy;
1937 wl_list_init(&switcher->listener.link);
1938
1939 switcher->grab.interface = &switcher_grab;
1940 wl_input_device_start_keyboard_grab(device, &switcher->grab, time);
1941 switcher_next(switcher);
1942}
1943
Pekka Paalanen3c647232011-12-22 13:43:43 +02001944static void
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001945backlight_binding(struct wl_input_device *device, uint32_t time,
1946 uint32_t key, uint32_t button, uint32_t state, void *data)
1947{
1948 struct weston_compositor *compositor = data;
1949 struct weston_output *output;
1950
1951 /* TODO: we're limiting to simple use cases, where we assume just
1952 * control on the primary display. We'd have to extend later if we
1953 * ever get support for setting backlights on random desktop LCD
1954 * panels though */
1955 output = get_default_output(compositor);
1956 if (!output)
1957 return;
1958
1959 if (!output->set_backlight)
1960 return;
1961
1962 if ((key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) &&
1963 output->backlight_current > 1)
1964 output->backlight_current--;
1965 else if ((key == KEY_F10 || key == KEY_BRIGHTNESSUP) &&
1966 output->backlight_current < 10)
1967 output->backlight_current++;
1968
1969 output->set_backlight(output, output->backlight_current);
1970}
1971
1972static void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001973shell_destroy(struct weston_shell *base)
Pekka Paalanen3c647232011-12-22 13:43:43 +02001974{
1975 struct wl_shell *shell = container_of(base, struct wl_shell, shell);
1976
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02001977 if (shell->child.client)
1978 wl_client_destroy(shell->child.client);
1979
Pekka Paalanen3c647232011-12-22 13:43:43 +02001980 free(shell->screensaver.path);
1981 free(shell);
1982}
1983
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001984int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001985shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04001986
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001987WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001988shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001989{
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001990 struct wl_shell *shell;
1991
1992 shell = malloc(sizeof *shell);
1993 if (shell == NULL)
1994 return -1;
1995
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04001996 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001997 shell->compositor = ec;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001998 shell->shell.lock = lock;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001999 shell->shell.unlock = unlock;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05002000 shell->shell.map = map;
2001 shell->shell.configure = configure;
Pekka Paalanen3c647232011-12-22 13:43:43 +02002002 shell->shell.destroy = shell_destroy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002003
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002004 wl_list_init(&shell->backgrounds);
2005 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002006 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002007
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002008 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2009 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2010 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2011 weston_layer_init(&shell->background_layer,
2012 &shell->toplevel_layer.link);
2013 wl_list_init(&shell->lock_layer.surface_list);
2014
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002015 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002016
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002017 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2018 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002019 return -1;
2020
Kristian Høgsberg75840622011-09-06 13:48:16 -04002021 if (wl_display_add_global(ec->wl_display,
2022 &desktop_shell_interface,
2023 shell, bind_desktop_shell) == NULL)
2024 return -1;
2025
Pekka Paalanen6e168112011-11-24 11:34:05 +02002026 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2027 shell, bind_screensaver) == NULL)
2028 return -1;
2029
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002030 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002031 if (launch_desktop_shell_process(shell) != 0)
2032 return -1;
2033
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002034 weston_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002035 move_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002036 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002037 resize_binding, shell);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002038 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002039 MODIFIER_CTRL | MODIFIER_ALT,
2040 terminate_binding, ec);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002041 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002042 click_to_activate_binding, ec);
Scott Moreauccbf29d2012-02-22 14:21:41 -07002043 weston_compositor_add_binding(ec, KEY_UP, 0, MODIFIER_SUPER,
Scott Moreauc6d7f602012-02-23 22:28:37 -07002044 zoom_binding, shell);
Scott Moreauccbf29d2012-02-22 14:21:41 -07002045 weston_compositor_add_binding(ec, KEY_DOWN, 0, MODIFIER_SUPER,
Scott Moreauc6d7f602012-02-23 22:28:37 -07002046 zoom_binding, shell);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002047 weston_compositor_add_binding(ec, 0, BTN_LEFT,
2048 MODIFIER_SUPER | MODIFIER_ALT,
2049 rotate_binding, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002050 weston_compositor_add_binding(ec, KEY_TAB, 0, MODIFIER_SUPER,
2051 switcher_binding, ec);
2052
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002053 /* brightness */
2054 weston_compositor_add_binding(ec, KEY_F9, 0, MODIFIER_CTRL,
2055 backlight_binding, ec);
2056 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0,
2057 backlight_binding, ec);
2058 weston_compositor_add_binding(ec, KEY_F10, 0, MODIFIER_CTRL,
2059 backlight_binding, ec);
2060 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0,
2061 backlight_binding, ec);
2062
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002063 ec->shell = &shell->shell;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002064
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002065 return 0;
2066}