blob: b412d8c5241c6570002fc7a27b0a73017bbd0dcc [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
Tiago Vignattibe143262012-04-16 17:31:41 +030041struct desktop_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050042 struct weston_compositor *compositor;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -040043
44 struct wl_listener lock_listener;
45 struct wl_listener unlock_listener;
46 struct wl_listener destroy_listener;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020047
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050048 struct weston_layer fullscreen_layer;
49 struct weston_layer panel_layer;
50 struct weston_layer toplevel_layer;
51 struct weston_layer background_layer;
52 struct weston_layer lock_layer;
53
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020054 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050055 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020056 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020057 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +020058
59 unsigned deathcount;
60 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020061 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020062
63 bool locked;
64 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020065
Pekka Paalanen068ae942011-11-28 14:11:15 +020066 struct shell_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -050067 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010068
69 struct wl_list backgrounds;
70 struct wl_list panels;
Pekka Paalanen6e168112011-11-24 11:34:05 +020071
Pekka Paalanen77346a62011-11-30 16:26:35 +020072 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +020073 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +020074 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +020075 struct wl_resource *binding;
76 struct wl_list surfaces;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050077 struct weston_process process;
Pekka Paalanen77346a62011-11-30 16:26:35 +020078 } screensaver;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -050079
80 struct weston_surface *debug_repaint_surface;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -040081};
82
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050083enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020084 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050085
Pekka Paalanen57da4a82011-11-23 16:42:16 +020086 SHELL_SURFACE_PANEL,
87 SHELL_SURFACE_BACKGROUND,
88 SHELL_SURFACE_LOCK,
Pekka Paalanen77346a62011-11-30 16:26:35 +020089 SHELL_SURFACE_SCREENSAVER,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050090
91 SHELL_SURFACE_TOPLEVEL,
92 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050093 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +080094 SHELL_SURFACE_MAXIMIZED,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -050095 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +020096};
97
Pekka Paalanen56cdea92011-11-23 16:14:12 +020098struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020099 struct wl_resource resource;
100
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500101 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200102 struct wl_listener surface_destroy_listener;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500103 struct shell_surface *parent;
Tiago Vignattibe143262012-04-16 17:31:41 +0300104 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200105
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500106 enum shell_surface_type type;
107 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800108 bool saved_position_valid;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100109
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500110 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200111 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500112 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200113 } rotation;
114
115 struct {
Scott Moreau447013d2012-02-18 05:05:29 -0700116 struct wl_pointer_grab grab;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500117 int32_t x, y;
Pekka Paalanen938269a2012-02-07 14:19:01 +0200118 struct weston_transform parent_transform;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500119 int32_t initial_up;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400120 struct wl_input_device *device;
121 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500122 } popup;
123
Alex Wu4539b082012-03-01 12:57:46 +0800124 struct {
125 enum wl_shell_surface_fullscreen_method type;
126 struct weston_transform transform; /* matrix from x, y */
127 uint32_t framerate;
128 struct weston_surface *black_surface;
129 } fullscreen;
130
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500131 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500132 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100133 struct wl_list link;
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +0300134
135 int force_configure;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200136};
137
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300138struct shell_grab {
Scott Moreau447013d2012-02-18 05:05:29 -0700139 struct wl_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300140 struct shell_surface *shsurf;
141 struct wl_listener shsurf_destroy_listener;
142};
143
144struct weston_move_grab {
145 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500146 int32_t dx, dy;
147};
148
Pekka Paalanen460099f2012-01-20 16:48:25 +0200149struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300150 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500151 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200152 struct {
153 int32_t x;
154 int32_t y;
155 } center;
156};
157
Alex Wubd3354b2012-04-17 17:20:49 +0800158static struct shell_surface *
159get_shell_surface(struct weston_surface *surface);
160
161static struct desktop_shell *
162shell_surface_get_shell(struct shell_surface *shsurf);
163
164static bool
165shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
166{
167 struct desktop_shell *shell;
168 struct weston_surface *top_fs_es;
169
170 shell = shell_surface_get_shell(shsurf);
171
172 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
173 return false;
174
175 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
176 struct weston_surface,
177 layer_link);
178 return (shsurf == get_shell_surface(top_fs_es));
179}
180
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500181static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400182destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300183{
184 struct shell_grab *grab;
185
186 grab = container_of(listener, struct shell_grab,
187 shsurf_destroy_listener);
188
189 grab->shsurf = NULL;
190}
191
192static void
193shell_grab_init(struct shell_grab *grab,
194 const struct wl_pointer_grab_interface *interface,
195 struct shell_surface *shsurf)
196{
197 grab->grab.interface = interface;
198 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400199 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
200 wl_signal_add(&shsurf->resource.destroy_signal,
201 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300202
203}
204
205static void
206shell_grab_finish(struct shell_grab *grab)
207{
208 wl_list_remove(&grab->shsurf_destroy_listener.link);
209}
210
211static void
Alex Wu4539b082012-03-01 12:57:46 +0800212center_on_output(struct weston_surface *surface,
213 struct weston_output *output);
214
215static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300216shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200217{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200218 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200219 char *path = NULL;
220 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200221
222 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200223 { "path", CONFIG_KEY_STRING, &path },
224 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200225 };
226
227 struct config_section cs[] = {
228 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
229 };
230
Tiago Vignatti9a206c42012-03-21 19:49:18 +0200231 config_file = config_file_path("weston.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500232 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200233 free(config_file);
234
Pekka Paalanen7296e792011-12-07 16:22:00 +0200235 shell->screensaver.path = path;
236 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200237}
238
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200239static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400240noop_grab_focus(struct wl_pointer_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500241 struct wl_surface *surface, int32_t x, int32_t y)
242{
243 grab->focus = NULL;
244}
245
246static void
Scott Moreau447013d2012-02-18 05:05:29 -0700247move_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500248 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500249{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500250 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500251 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300252 struct shell_surface *shsurf = move->base.shsurf;
253 struct weston_surface *es;
254
255 if (!shsurf)
256 return;
257
258 es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500259
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500260 weston_surface_configure(es,
261 device->x + move->dx,
262 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200263 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500264}
265
266static void
Scott Moreau447013d2012-02-18 05:05:29 -0700267move_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400268 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500269{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300270 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
271 grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500272 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500273
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500274 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300275 shell_grab_finish(shell_grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400276 wl_input_device_end_pointer_grab(device);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500277 free(grab);
278 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500279}
280
Scott Moreau447013d2012-02-18 05:05:29 -0700281static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500282 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500283 move_grab_motion,
284 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500285};
286
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400287static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500288weston_surface_move(struct weston_surface *es,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400289 struct weston_input_device *wd)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500290{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500291 struct weston_move_grab *move;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300292 struct shell_surface *shsurf = get_shell_surface(es);
293
294 if (!shsurf)
295 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500296
297 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400298 if (!move)
299 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500300
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300301 shell_grab_init(&move->base, &move_grab_interface, shsurf);
302
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200303 move->dx = es->geometry.x - wd->input_device.grab_x;
304 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500305
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300306 wl_input_device_start_pointer_grab(&wd->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400307 &move->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500308
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400309 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400310
311 return 0;
312}
313
314static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200315shell_surface_move(struct wl_client *client, struct wl_resource *resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400316 struct wl_resource *input_resource, uint32_t serial)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400317{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500318 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200319 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400320
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500321 if (wd->input_device.button_count == 0 ||
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400322 wd->input_device.grab_serial != serial ||
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500323 wd->input_device.pointer_focus != &shsurf->surface->surface)
324 return;
325
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400326 if (weston_surface_move(shsurf->surface, wd) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400327 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500328}
329
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500330struct weston_resize_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300331 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500332 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200333 int32_t width, height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500334};
335
336static void
Scott Moreau447013d2012-02-18 05:05:29 -0700337resize_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500338 uint32_t time, int32_t x, int32_t y)
339{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500340 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500341 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500342 int32_t width, height;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200343 int32_t from_x, from_y;
344 int32_t to_x, to_y;
345
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300346 if (!resize->base.shsurf)
347 return;
348
349 weston_surface_from_global(resize->base.shsurf->surface,
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200350 device->grab_x, device->grab_y,
351 &from_x, &from_y);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300352 weston_surface_from_global(resize->base.shsurf->surface,
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200353 device->x, device->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500354
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200355 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200356 width = resize->width + from_x - to_x;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200357 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200358 width = resize->width + to_x - from_x;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500359 } else {
360 width = resize->width;
361 }
362
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200363 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200364 height = resize->height + from_y - to_y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200365 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200366 height = resize->height + to_y - from_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500367 } else {
368 height = resize->height;
369 }
370
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300371 wl_shell_surface_send_configure(&resize->base.shsurf->resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400372 resize->edges, width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500373}
374
375static void
Scott Moreau447013d2012-02-18 05:05:29 -0700376resize_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400377 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500378{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300379 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500380 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500381
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500382 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300383 shell_grab_finish(&resize->base);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400384 wl_input_device_end_pointer_grab(device);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500385 free(grab);
386 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500387}
388
Scott Moreau447013d2012-02-18 05:05:29 -0700389static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500390 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500391 resize_grab_motion,
392 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500393};
394
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400395static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500396weston_surface_resize(struct shell_surface *shsurf,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400397 struct weston_input_device *wd, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500398{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500399 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500400
Alex Wu4539b082012-03-01 12:57:46 +0800401 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
402 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500403
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200404 if (edges == 0 || edges > 15 ||
405 (edges & 3) == 3 || (edges & 12) == 12)
406 return 0;
407
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500408 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400409 if (!resize)
410 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500411
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300412 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
413
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500414 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200415 resize->width = shsurf->surface->geometry.width;
416 resize->height = shsurf->surface->geometry.height;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400417
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300418 wl_input_device_start_pointer_grab(&wd->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400419 &resize->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500420
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400421 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400422
423 return 0;
424}
425
426static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200427shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400428 struct wl_resource *input_resource, uint32_t serial,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200429 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400430{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500431 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200432 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400433
Alex Wu4539b082012-03-01 12:57:46 +0800434 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
435 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400436
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500437 if (wd->input_device.button_count == 0 ||
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400438 wd->input_device.grab_serial != serial ||
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500439 wd->input_device.pointer_focus != &shsurf->surface->surface)
440 return;
441
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400442 if (weston_surface_resize(shsurf, wd, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400443 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500444}
445
Juan Zhao96879df2012-02-07 08:45:41 +0800446static struct weston_output *
447get_default_output(struct weston_compositor *compositor)
448{
449 return container_of(compositor->output_list.next,
450 struct weston_output, link);
451}
452
Alex Wu4539b082012-03-01 12:57:46 +0800453static void
454shell_unset_fullscreen(struct shell_surface *shsurf)
455{
456 /* undo all fullscreen things here */
Alex Wubd3354b2012-04-17 17:20:49 +0800457 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
458 shell_surface_is_top_fullscreen(shsurf)) {
459 weston_output_switch_mode(shsurf->fullscreen_output,
460 shsurf->fullscreen_output->origin);
461 }
Alex Wu4539b082012-03-01 12:57:46 +0800462 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
463 shsurf->fullscreen.framerate = 0;
464 wl_list_remove(&shsurf->fullscreen.transform.link);
465 wl_list_init(&shsurf->fullscreen.transform.link);
Alex Wubd3354b2012-04-17 17:20:49 +0800466 if (shsurf->fullscreen.black_surface)
467 weston_surface_destroy(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800468 shsurf->fullscreen.black_surface = NULL;
469 shsurf->fullscreen_output = NULL;
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +0300470 shsurf->force_configure = 1;
Alex Wu4539b082012-03-01 12:57:46 +0800471 weston_surface_set_position(shsurf->surface,
472 shsurf->saved_x, shsurf->saved_y);
473}
474
Pekka Paalanen98262232011-12-01 10:42:22 +0200475static int
476reset_shell_surface_type(struct shell_surface *surface)
477{
478 switch (surface->type) {
479 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800480 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200481 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800482 case SHELL_SURFACE_MAXIMIZED:
483 surface->output = get_default_output(surface->surface->compositor);
484 weston_surface_set_position(surface->surface,
485 surface->saved_x,
486 surface->saved_y);
487 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200488 case SHELL_SURFACE_PANEL:
489 case SHELL_SURFACE_BACKGROUND:
490 wl_list_remove(&surface->link);
491 wl_list_init(&surface->link);
492 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200493 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200494 case SHELL_SURFACE_LOCK:
495 wl_resource_post_error(&surface->resource,
496 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200497 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200498 return -1;
499 case SHELL_SURFACE_NONE:
500 case SHELL_SURFACE_TOPLEVEL:
501 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500502 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200503 break;
504 }
505
506 surface->type = SHELL_SURFACE_NONE;
507 return 0;
508}
509
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500510static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200511shell_surface_set_toplevel(struct wl_client *client,
512 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400513
514{
Pekka Paalanen98262232011-12-01 10:42:22 +0200515 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400516
Pekka Paalanen98262232011-12-01 10:42:22 +0200517 if (reset_shell_surface_type(surface))
518 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400519
Pekka Paalanen98262232011-12-01 10:42:22 +0200520 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400521}
522
523static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200524shell_surface_set_transient(struct wl_client *client,
525 struct wl_resource *resource,
526 struct wl_resource *parent_resource,
527 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400528{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200529 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500530 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200531 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500532 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400533
Pekka Paalanen98262232011-12-01 10:42:22 +0200534 if (reset_shell_surface_type(shsurf))
535 return;
536
Alex Wu4539b082012-03-01 12:57:46 +0800537 /* assign to parents output */
Alex Wu88277d12012-02-22 14:50:46 +0800538 shsurf->output = pes->output;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200539 weston_surface_set_position(es, pes->geometry.x + x,
540 pes->geometry.y + y);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400541
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200542 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400543}
544
Tiago Vignattibe143262012-04-16 17:31:41 +0300545static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +0800546shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200547{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400548 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +0800549}
550
551static int
Tiago Vignattibe143262012-04-16 17:31:41 +0300552get_output_panel_height(struct desktop_shell *shell,
553 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +0800554{
555 struct shell_surface *priv;
556 int panel_height = 0;
557
558 if (!output)
559 return 0;
560
Tiago Vignattibe143262012-04-16 17:31:41 +0300561 wl_list_for_each(priv, &shell->panels, link) {
Juan Zhao96879df2012-02-07 08:45:41 +0800562 if (priv->output == output) {
563 panel_height = priv->surface->geometry.height;
564 break;
565 }
566 }
567 return panel_height;
568}
569
570static void
571shell_surface_set_maximized(struct wl_client *client,
572 struct wl_resource *resource,
573 struct wl_resource *output_resource )
574{
575 struct shell_surface *shsurf = resource->data;
576 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300577 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +0800578 uint32_t edges = 0, panel_height = 0;
579
580 /* get the default output, if the client set it as NULL
581 check whether the ouput is available */
582 if (output_resource)
583 shsurf->output = output_resource->data;
584 else
585 shsurf->output = get_default_output(es->compositor);
586
587 if (reset_shell_surface_type(shsurf))
588 return;
589
590 shsurf->saved_x = es->geometry.x;
591 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800592 shsurf->saved_position_valid = true;
Juan Zhao96879df2012-02-07 08:45:41 +0800593
Tiago Vignattibe143262012-04-16 17:31:41 +0300594 shell = shell_surface_get_shell(shsurf);
595 panel_height = get_output_panel_height(shell, es->output);
Juan Zhao96879df2012-02-07 08:45:41 +0800596 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500597
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400598 wl_shell_surface_send_configure(&shsurf->resource, edges,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500599 es->output->current->width,
600 es->output->current->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +0800601
602 shsurf->type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200603}
604
Alex Wu21858432012-04-01 20:13:08 +0800605static void
606black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
607
Alex Wu4539b082012-03-01 12:57:46 +0800608static struct weston_surface *
609create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +0800610 struct weston_surface *fs_surface,
Alex Wu4539b082012-03-01 12:57:46 +0800611 GLfloat x, GLfloat y, int w, int h)
612{
613 struct weston_surface *surface = NULL;
614
615 surface = weston_surface_create(ec);
616 if (surface == NULL) {
617 fprintf(stderr, "no memory\n");
618 return NULL;
619 }
620
Alex Wu21858432012-04-01 20:13:08 +0800621 surface->configure = black_surface_configure;
622 surface->private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +0800623 weston_surface_configure(surface, x, y, w, h);
624 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
625 return surface;
626}
627
628/* Create black surface and append it to the associated fullscreen surface.
629 * Handle size dismatch and positioning according to the method. */
630static void
631shell_configure_fullscreen(struct shell_surface *shsurf)
632{
633 struct weston_output *output = shsurf->fullscreen_output;
634 struct weston_surface *surface = shsurf->surface;
635 struct weston_matrix *matrix;
636 float scale;
637
638 center_on_output(surface, output);
639
640 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500641 shsurf->fullscreen.black_surface =
642 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +0800643 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500644 output->x, output->y,
645 output->current->width,
646 output->current->height);
647
648 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
649 wl_list_insert(&surface->layer_link,
650 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800651 shsurf->fullscreen.black_surface->output = output;
652
653 switch (shsurf->fullscreen.type) {
654 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
655 break;
656 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
657 matrix = &shsurf->fullscreen.transform.matrix;
658 weston_matrix_init(matrix);
659 scale = (float)output->current->width/(float)surface->geometry.width;
660 weston_matrix_scale(matrix, scale, scale, 1);
661 wl_list_remove(&shsurf->fullscreen.transform.link);
662 wl_list_insert(surface->geometry.transformation_list.prev,
663 &shsurf->fullscreen.transform.link);
664 weston_surface_set_position(surface, output->x, output->y);
665 break;
666 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +0800667 if (shell_surface_is_top_fullscreen(shsurf)) {
668 struct weston_mode mode = {0,
669 surface->geometry.width,
670 surface->geometry.height,
671 shsurf->fullscreen.framerate};
672
673 if (weston_output_switch_mode(output, &mode) == 0) {
674 weston_surface_configure(shsurf->fullscreen.black_surface,
675 output->x, output->y,
676 output->current->width,
677 output->current->height);
678 weston_surface_set_position(surface, output->x, output->y);
679 break;
680 }
681 }
Alex Wu4539b082012-03-01 12:57:46 +0800682 break;
683 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
684 break;
685 default:
686 break;
687 }
688}
689
690/* make the fullscreen and black surface at the top */
691static void
692shell_stack_fullscreen(struct shell_surface *shsurf)
693{
Alex Wubd3354b2012-04-17 17:20:49 +0800694 struct weston_output *output = shsurf->fullscreen_output;
Alex Wu4539b082012-03-01 12:57:46 +0800695 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300696 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +0800697
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500698 wl_list_remove(&surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500699 wl_list_insert(&shell->fullscreen_layer.surface_list,
700 &surface->layer_link);
Alex Wubd3354b2012-04-17 17:20:49 +0800701 weston_surface_damage(surface);
702
703 if (!shsurf->fullscreen.black_surface)
704 shsurf->fullscreen.black_surface =
705 create_black_surface(surface->compositor,
706 surface,
707 output->x, output->y,
708 output->current->width,
709 output->current->height);
710
711 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500712 wl_list_insert(&surface->layer_link,
713 &shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500714 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800715}
716
717static void
718shell_map_fullscreen(struct shell_surface *shsurf)
719{
Alex Wu4539b082012-03-01 12:57:46 +0800720 shell_stack_fullscreen(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +0800721 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +0800722}
723
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400724static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200725shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -0500726 struct wl_resource *resource,
727 uint32_t method,
728 uint32_t framerate,
729 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400730{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200731 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500732 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +0800733
734 if (output_resource)
735 shsurf->output = output_resource->data;
736 else
737 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400738
Pekka Paalanen98262232011-12-01 10:42:22 +0200739 if (reset_shell_surface_type(shsurf))
740 return;
741
Alex Wu4539b082012-03-01 12:57:46 +0800742 shsurf->fullscreen_output = shsurf->output;
743 shsurf->fullscreen.type = method;
744 shsurf->fullscreen.framerate = framerate;
745 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400746
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200747 shsurf->saved_x = es->geometry.x;
748 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800749 shsurf->saved_position_valid = true;
750
Ander Conselvan de Oliveirab8ab14f2012-03-27 17:36:36 +0300751 if (weston_surface_is_mapped(es))
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +0300752 shsurf->force_configure = 1;
Kristian Høgsbergd5ae9f42012-02-16 23:38:14 -0500753
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400754 wl_shell_surface_send_configure(&shsurf->resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500755 shsurf->output->current->width,
756 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400757}
758
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500759static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400760popup_grab_focus(struct wl_pointer_grab *grab,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500761 struct wl_surface *surface, int32_t x, int32_t y)
762{
763 struct wl_input_device *device = grab->input_device;
764 struct shell_surface *priv =
765 container_of(grab, struct shell_surface, popup.grab);
766 struct wl_client *client = priv->surface->surface.resource.client;
767
Pekka Paalanencb108432012-01-19 16:25:40 +0200768 if (surface && surface->resource.client == client) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400769 wl_input_device_set_pointer_focus(device, surface, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500770 grab->focus = surface;
771 } else {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400772 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500773 grab->focus = NULL;
774 }
775}
776
777static void
Scott Moreau447013d2012-02-18 05:05:29 -0700778popup_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200779 uint32_t time, int32_t sx, int32_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500780{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500781 struct wl_resource *resource;
782
783 resource = grab->input_device->pointer_focus_resource;
784 if (resource)
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500785 wl_input_device_send_motion(resource, time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500786}
787
788static void
Scott Moreau447013d2012-02-18 05:05:29 -0700789popup_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400790 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500791{
792 struct wl_resource *resource;
793 struct shell_surface *shsurf =
794 container_of(grab, struct shell_surface, popup.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400795 struct wl_display *display;
796 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500797
798 resource = grab->input_device->pointer_focus_resource;
799 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400800 display = wl_client_get_display(resource->client);
801 serial = wl_display_get_serial(display);
802 wl_input_device_send_button(resource, serial,
803 time, button, state);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500804 } else if (state == 0 &&
805 (shsurf->popup.initial_up ||
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400806 time - shsurf->popup.device->grab_time > 500)) {
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500807 wl_shell_surface_send_popup_done(&shsurf->resource);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400808 wl_input_device_end_pointer_grab(grab->input_device);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500809 shsurf->popup.grab.input_device = NULL;
810 }
811
812 if (state == 0)
813 shsurf->popup.initial_up = 1;
814}
815
Scott Moreau447013d2012-02-18 05:05:29 -0700816static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500817 popup_grab_focus,
818 popup_grab_motion,
819 popup_grab_button,
820};
821
822static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400823shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500824{
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400825 struct wl_input_device *device = shsurf->popup.device;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500826 struct weston_surface *es = shsurf->surface;
827 struct weston_surface *parent = shsurf->parent->surface;
828
829 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500830 shsurf->popup.grab.interface = &popup_grab_interface;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500831
Pekka Paalanen938269a2012-02-07 14:19:01 +0200832 weston_surface_update_transform(parent);
833 if (parent->transform.enabled) {
834 shsurf->popup.parent_transform.matrix =
835 parent->transform.matrix;
836 } else {
837 /* construct x, y translation matrix */
838 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
839 shsurf->popup.parent_transform.matrix.d[12] =
840 parent->geometry.x;
841 shsurf->popup.parent_transform.matrix.d[13] =
842 parent->geometry.y;
843 }
844 wl_list_insert(es->geometry.transformation_list.prev,
845 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200846 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500847
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500848 shsurf->popup.initial_up = 0;
849
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400850 /* We don't require the grab to still be active, but if another
851 * grab has started in the meantime, we end the popup now. */
852 if (device->grab_serial == shsurf->popup.serial) {
853 wl_input_device_start_pointer_grab(device,
854 &shsurf->popup.grab);
855 } else {
856 wl_shell_surface_send_popup_done(&shsurf->resource);
857 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500858}
859
860static void
861shell_surface_set_popup(struct wl_client *client,
862 struct wl_resource *resource,
863 struct wl_resource *input_device_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400864 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500865 struct wl_resource *parent_resource,
866 int32_t x, int32_t y, uint32_t flags)
867{
868 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500869
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500870 shsurf->type = SHELL_SURFACE_POPUP;
871 shsurf->parent = parent_resource->data;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400872 shsurf->popup.device = input_device_resource->data;
873 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500874 shsurf->popup.x = x;
875 shsurf->popup.y = y;
876}
877
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200878static const struct wl_shell_surface_interface shell_surface_implementation = {
879 shell_surface_move,
880 shell_surface_resize,
881 shell_surface_set_toplevel,
882 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500883 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +0800884 shell_surface_set_popup,
885 shell_surface_set_maximized
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200886};
887
888static void
889destroy_shell_surface(struct wl_resource *resource)
890{
891 struct shell_surface *shsurf = resource->data;
892
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500893 if (shsurf->popup.grab.input_device)
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400894 wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500895
Alex Wubd3354b2012-04-17 17:20:49 +0800896 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
897 shell_surface_is_top_fullscreen(shsurf)) {
898 weston_output_switch_mode(shsurf->fullscreen_output,
899 shsurf->fullscreen_output->origin);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300900 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200901
Alex Wuaa08e2d2012-03-05 11:01:40 +0800902 if (shsurf->fullscreen.black_surface)
903 weston_surface_destroy(shsurf->fullscreen.black_surface);
904
Alex Wubd3354b2012-04-17 17:20:49 +0800905 /* As destroy_resource() use wl_list_for_each_safe(),
906 * we can always remove the listener.
907 */
908 wl_list_remove(&shsurf->surface_destroy_listener.link);
909 shsurf->surface->configure = NULL;
910
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200911 wl_list_remove(&shsurf->link);
912 free(shsurf);
913}
914
915static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400916shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200917{
918 struct shell_surface *shsurf = container_of(listener,
919 struct shell_surface,
920 surface_destroy_listener);
921
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400922 wl_resource_destroy(&shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200923}
924
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200925static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500926get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200927{
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200928 struct wl_listener *listener;
929
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400930 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
931 shell_handle_surface_destroy);
932 if (listener)
933 return container_of(listener, struct shell_surface,
934 surface_destroy_listener);
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200935
936 return NULL;
937}
938
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200939static void
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300940shell_surface_configure(struct weston_surface *, int32_t, int32_t);
941
942static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200943shell_get_shell_surface(struct wl_client *client,
944 struct wl_resource *resource,
945 uint32_t id,
946 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200947{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500948 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200949 struct shell_surface *shsurf;
950
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200951 if (get_shell_surface(surface)) {
952 wl_resource_post_error(surface_resource,
953 WL_DISPLAY_ERROR_INVALID_OBJECT,
Alex Wubd3354b2012-04-17 17:20:49 +0800954 "desktop_shell::get_shell_surface already requested");
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200955 return;
956 }
957
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300958 if (surface->configure) {
959 wl_resource_post_error(surface_resource,
960 WL_DISPLAY_ERROR_INVALID_OBJECT,
961 "surface->configure already set");
962 return;
963 }
964
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200965 shsurf = calloc(1, sizeof *shsurf);
966 if (!shsurf) {
967 wl_resource_post_no_memory(resource);
968 return;
969 }
970
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300971 surface->configure = shell_surface_configure;
972
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200973 shsurf->resource.destroy = destroy_shell_surface;
974 shsurf->resource.object.id = id;
975 shsurf->resource.object.interface = &wl_shell_surface_interface;
976 shsurf->resource.object.implementation =
977 (void (**)(void)) &shell_surface_implementation;
978 shsurf->resource.data = shsurf;
979
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400980 shsurf->shell = resource->data;
Alex Wu4539b082012-03-01 12:57:46 +0800981 shsurf->saved_position_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200982 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +0800983 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
984 shsurf->fullscreen.framerate = 0;
985 shsurf->fullscreen.black_surface = NULL;
986 wl_list_init(&shsurf->fullscreen.transform.link);
987
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400988 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
989 wl_signal_add(&surface->surface.resource.destroy_signal,
990 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200991
992 /* init link so its safe to always remove it in destroy_shell_surface */
993 wl_list_init(&shsurf->link);
994
Pekka Paalanen460099f2012-01-20 16:48:25 +0200995 /* empty when not in use */
996 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500997 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200998
Pekka Paalanen98262232011-12-01 10:42:22 +0200999 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001000
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001001 wl_client_add_resource(client, &shsurf->resource);
1002}
1003
1004static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02001005 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001006};
1007
Kristian Høgsberg07937562011-04-12 17:25:42 -04001008static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001009handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02001010{
1011 proc->pid = 0;
1012}
1013
1014static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001015launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001016{
1017 if (shell->screensaver.binding)
1018 return;
1019
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001020 if (!shell->screensaver.path)
1021 return;
1022
Kristian Høgsberg32bed572012-03-01 17:11:36 -05001023 if (shell->screensaver.process.pid != 0) {
1024 fprintf(stderr, "old screensaver still running\n");
1025 return;
1026 }
1027
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001028 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001029 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001030 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02001031 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001032}
1033
1034static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001035terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001036{
Pekka Paalanen18027e52011-12-02 16:31:49 +02001037 if (shell->screensaver.process.pid == 0)
1038 return;
1039
1040 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001041}
1042
1043static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001044show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001045{
1046 struct wl_list *list;
1047
1048 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001049 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001050 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001051 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001052
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001053 wl_list_remove(&surface->surface->layer_link);
1054 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001055 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001056 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001057}
1058
1059static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001060hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001061{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001062 wl_list_remove(&surface->surface->layer_link);
1063 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001064 surface->surface->output = NULL;
1065}
1066
1067static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001068desktop_shell_set_background(struct wl_client *client,
1069 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001070 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001071 struct wl_resource *surface_resource)
1072{
Tiago Vignattibe143262012-04-16 17:31:41 +03001073 struct desktop_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001074 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001075 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001076 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001077
Pekka Paalanen98262232011-12-01 10:42:22 +02001078 if (reset_shell_surface_type(shsurf))
1079 return;
1080
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001081 wl_list_for_each(priv, &shell->backgrounds, link) {
1082 if (priv->output == output_resource->data) {
1083 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001084 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001085 wl_list_remove(&priv->link);
1086 break;
1087 }
1088 }
1089
Pekka Paalanen068ae942011-11-28 14:11:15 +02001090 shsurf->type = SHELL_SURFACE_BACKGROUND;
1091 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001092
Pekka Paalanen068ae942011-11-28 14:11:15 +02001093 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001094
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001095 weston_surface_set_position(surface, shsurf->output->x,
1096 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001097
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001098 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001099 surface_resource,
1100 shsurf->output->current->width,
1101 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001102}
1103
1104static void
1105desktop_shell_set_panel(struct wl_client *client,
1106 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001107 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001108 struct wl_resource *surface_resource)
1109{
Tiago Vignattibe143262012-04-16 17:31:41 +03001110 struct desktop_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001111 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001112 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001113 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001114
Pekka Paalanen98262232011-12-01 10:42:22 +02001115 if (reset_shell_surface_type(shsurf))
1116 return;
1117
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001118 wl_list_for_each(priv, &shell->panels, link) {
1119 if (priv->output == output_resource->data) {
1120 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001121 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001122 wl_list_remove(&priv->link);
1123 break;
1124 }
1125 }
1126
Pekka Paalanen068ae942011-11-28 14:11:15 +02001127 shsurf->type = SHELL_SURFACE_PANEL;
1128 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001129
Pekka Paalanen068ae942011-11-28 14:11:15 +02001130 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001131
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001132 weston_surface_set_position(surface, shsurf->output->x,
1133 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001134
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001135 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001136 surface_resource,
1137 shsurf->output->current->width,
1138 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001139}
1140
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001141static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001142handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001143{
Tiago Vignattibe143262012-04-16 17:31:41 +03001144 struct desktop_shell *shell =
1145 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001146
1147 fprintf(stderr, "lock surface gone\n");
1148 shell->lock_surface = NULL;
1149}
1150
1151static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001152desktop_shell_set_lock_surface(struct wl_client *client,
1153 struct wl_resource *resource,
1154 struct wl_resource *surface_resource)
1155{
Tiago Vignattibe143262012-04-16 17:31:41 +03001156 struct desktop_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001157 struct shell_surface *surface = surface_resource->data;
1158
1159 if (reset_shell_surface_type(surface))
1160 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001161
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001162 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001163
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001164 if (!shell->locked)
1165 return;
1166
Pekka Paalanen98262232011-12-01 10:42:22 +02001167 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001168
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001169 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1170 wl_signal_add(&surface_resource->destroy_signal,
1171 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001172
Pekka Paalanen068ae942011-11-28 14:11:15 +02001173 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001174}
1175
1176static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001177resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001178{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001179 struct shell_surface *tmp;
1180
1181 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1182 hide_screensaver(shell, tmp);
1183
1184 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001185
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001186 wl_list_remove(&shell->lock_layer.link);
1187 wl_list_insert(&shell->compositor->cursor_layer.link,
1188 &shell->fullscreen_layer.link);
1189 wl_list_insert(&shell->fullscreen_layer.link,
1190 &shell->panel_layer.link);
1191 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001192
1193 shell->locked = false;
Pekka Paalanen7296e792011-12-07 16:22:00 +02001194 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001195 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001196 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001197}
1198
1199static void
1200desktop_shell_unlock(struct wl_client *client,
1201 struct wl_resource *resource)
1202{
Tiago Vignattibe143262012-04-16 17:31:41 +03001203 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001204
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001205 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001206
1207 if (shell->locked)
1208 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001209}
1210
Kristian Høgsberg75840622011-09-06 13:48:16 -04001211static const struct desktop_shell_interface desktop_shell_implementation = {
1212 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001213 desktop_shell_set_panel,
1214 desktop_shell_set_lock_surface,
1215 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001216};
1217
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001218static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001219get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001220{
1221 struct shell_surface *shsurf;
1222
1223 shsurf = get_shell_surface(surface);
1224 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001225 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001226 return shsurf->type;
1227}
1228
Kristian Høgsberg75840622011-09-06 13:48:16 -04001229static void
Kristian Høgsberg07937562011-04-12 17:25:42 -04001230move_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001231 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001232{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001233 struct weston_surface *surface =
1234 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001235
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001236 if (surface == NULL)
1237 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001238
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001239 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001240 case SHELL_SURFACE_PANEL:
1241 case SHELL_SURFACE_BACKGROUND:
1242 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001243 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001244 return;
1245 default:
1246 break;
1247 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001248
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001249 weston_surface_move(surface, (struct weston_input_device *) device);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001250}
1251
1252static void
1253resize_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001254 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001255{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001256 struct weston_surface *surface =
1257 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001258 uint32_t edges = 0;
1259 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001260 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001261
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001262 if (surface == NULL)
1263 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001264
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001265 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001266 if (!shsurf)
1267 return;
1268
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001269 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001270 case SHELL_SURFACE_PANEL:
1271 case SHELL_SURFACE_BACKGROUND:
1272 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001273 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001274 return;
1275 default:
1276 break;
1277 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001278
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001279 weston_surface_from_global(surface,
1280 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001281
Pekka Paalanen60921e52012-01-25 15:55:43 +02001282 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001283 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001284 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001285 edges |= 0;
1286 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001287 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001288
Pekka Paalanen60921e52012-01-25 15:55:43 +02001289 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001290 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001291 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001292 edges |= 0;
1293 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001294 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001295
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001296 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001297 edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001298}
1299
1300static void
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001301surface_opacity_binding(struct wl_input_device *device, uint32_t time,
1302 uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data)
1303{
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001304 uint32_t step = 15;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001305 struct shell_surface *shsurf;
1306 struct weston_surface *surface =
1307 (struct weston_surface *) device->pointer_focus;
1308
1309 if (surface == NULL)
1310 return;
1311
1312 shsurf = get_shell_surface(surface);
1313 if (!shsurf)
1314 return;
1315
1316 switch (shsurf->type) {
1317 case SHELL_SURFACE_BACKGROUND:
1318 case SHELL_SURFACE_SCREENSAVER:
1319 return;
1320 default:
1321 break;
1322 }
1323
1324 surface->alpha += value * step;
1325
1326 if (surface->alpha > 255)
1327 surface->alpha = 255;
1328 if (surface->alpha < step)
1329 surface->alpha = step;
1330
1331 surface->geometry.dirty = 1;
1332 weston_surface_damage(surface);
1333}
1334
1335static void
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -05001336zoom_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau1b45a792012-03-22 10:58:23 -06001337 uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001338{
1339 struct weston_input_device *wd = (struct weston_input_device *) device;
1340 struct weston_compositor *compositor = wd->compositor;
1341 struct weston_output *output;
1342
1343 wl_list_for_each(output, &compositor->output_list, link) {
1344 if (pixman_region32_contains_point(&output->region,
1345 device->x, device->y, NULL)) {
Scott Moreau1b45a792012-03-22 10:58:23 -06001346 output->zoom.active = 1;
1347 output->zoom.level += output->zoom.increment * -value;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001348
1349 if (output->zoom.level >= 1.0) {
1350 output->zoom.active = 0;
1351 output->zoom.level = 1.0;
1352 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001353
1354 if (output->zoom.level < output->zoom.increment)
1355 output->zoom.level = output->zoom.increment;
1356
1357 weston_output_update_zoom(output, device->x, device->y);
1358 }
1359 }
1360}
1361
Scott Moreauccbf29d2012-02-22 14:21:41 -07001362static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001363terminate_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001364 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001365{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001366 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001367
1368 if (state)
1369 wl_display_terminate(compositor->wl_display);
1370}
1371
1372static void
Scott Moreau447013d2012-02-18 05:05:29 -07001373rotate_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001374 uint32_t time, int32_t x, int32_t y)
1375{
1376 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001377 container_of(grab, struct rotate_grab, base.grab);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001378 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001379 struct shell_surface *shsurf = rotate->base.shsurf;
1380 struct weston_surface *surface;
1381 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1382
1383 if (!shsurf)
1384 return;
1385
1386 surface = shsurf->surface;
1387
1388 cx = 0.5f * surface->geometry.width;
1389 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001390
1391 dx = device->x - rotate->center.x;
1392 dy = device->y - rotate->center.y;
1393 r = sqrtf(dx * dx + dy * dy);
1394
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001395 wl_list_remove(&shsurf->rotation.transform.link);
1396 shsurf->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001397
1398 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001399 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001400 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001401
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001402 weston_matrix_init(&rotate->rotation);
1403 rotate->rotation.d[0] = dx / r;
1404 rotate->rotation.d[4] = -dy / r;
1405 rotate->rotation.d[1] = -rotate->rotation.d[4];
1406 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001407
1408 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001409 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001410 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001411 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001412 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001413
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001414 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001415 &shsurf->surface->geometry.transformation_list,
1416 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001417 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001418 wl_list_init(&shsurf->rotation.transform.link);
1419 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001420 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001421 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001422
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001423 /* We need to adjust the position of the surface
1424 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001425 cposx = surface->geometry.x + cx;
1426 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001427 dposx = rotate->center.x - cposx;
1428 dposy = rotate->center.y - cposy;
1429 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001430 weston_surface_set_position(surface,
1431 surface->geometry.x + dposx,
1432 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001433 }
1434
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001435 /* Repaint implies weston_surface_update_transform(), which
1436 * lazily applies the damage due to rotation update.
1437 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001438 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001439}
1440
1441static void
Scott Moreau447013d2012-02-18 05:05:29 -07001442rotate_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -04001443 uint32_t time, uint32_t button, int32_t state)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001444{
1445 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001446 container_of(grab, struct rotate_grab, base.grab);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001447 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001448 struct shell_surface *shsurf = rotate->base.shsurf;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001449
1450 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001451 if (shsurf)
1452 weston_matrix_multiply(&shsurf->rotation.rotation,
1453 &rotate->rotation);
1454 shell_grab_finish(&rotate->base);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001455 wl_input_device_end_pointer_grab(device);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001456 free(rotate);
1457 }
1458}
1459
Scott Moreau447013d2012-02-18 05:05:29 -07001460static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001461 noop_grab_focus,
1462 rotate_grab_motion,
1463 rotate_grab_button,
1464};
1465
1466static void
1467rotate_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001468 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001469{
1470 struct weston_surface *base_surface =
1471 (struct weston_surface *) device->pointer_focus;
1472 struct shell_surface *surface;
1473 struct rotate_grab *rotate;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001474 GLfloat dx, dy;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001475 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001476
1477 if (base_surface == NULL)
1478 return;
1479
1480 surface = get_shell_surface(base_surface);
1481 if (!surface)
1482 return;
1483
1484 switch (surface->type) {
1485 case SHELL_SURFACE_PANEL:
1486 case SHELL_SURFACE_BACKGROUND:
1487 case SHELL_SURFACE_FULLSCREEN:
1488 case SHELL_SURFACE_SCREENSAVER:
1489 return;
1490 default:
1491 break;
1492 }
1493
Pekka Paalanen460099f2012-01-20 16:48:25 +02001494 rotate = malloc(sizeof *rotate);
1495 if (!rotate)
1496 return;
1497
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001498 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001499
1500 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001501 surface->surface->geometry.width / 2,
1502 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001503 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001504
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001505 wl_input_device_start_pointer_grab(device, &rotate->base.grab);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001506
1507 dx = device->x - rotate->center.x;
1508 dy = device->y - rotate->center.y;
1509 r = sqrtf(dx * dx + dy * dy);
1510 if (r > 20.0f) {
1511 struct weston_matrix inverse;
1512
1513 weston_matrix_init(&inverse);
1514 inverse.d[0] = dx / r;
1515 inverse.d[4] = dy / r;
1516 inverse.d[1] = -inverse.d[4];
1517 inverse.d[5] = inverse.d[0];
1518 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001519
1520 weston_matrix_init(&rotate->rotation);
1521 rotate->rotation.d[0] = dx / r;
1522 rotate->rotation.d[4] = -dy / r;
1523 rotate->rotation.d[1] = -rotate->rotation.d[4];
1524 rotate->rotation.d[5] = rotate->rotation.d[0];
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001525 } else {
1526 weston_matrix_init(&surface->rotation.rotation);
1527 weston_matrix_init(&rotate->rotation);
1528 }
1529
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001530 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001531}
1532
1533static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001534activate(struct desktop_shell *shell, struct weston_surface *es,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001535 struct weston_input_device *device)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001536{
Alex Wu21858432012-04-01 20:13:08 +08001537 struct weston_surface *surf, *prev;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001538
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001539 weston_surface_activate(es, device);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001540
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001541 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001542 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001543 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001544 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001545 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001546
Pekka Paalanen77346a62011-11-30 16:26:35 +02001547 case SHELL_SURFACE_SCREENSAVER:
1548 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001549 if (shell->lock_surface)
1550 weston_surface_restack(es,
1551 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001552 break;
Alex Wu4539b082012-03-01 12:57:46 +08001553 case SHELL_SURFACE_FULLSCREEN:
1554 /* should on top of panels */
Alex Wu21858432012-04-01 20:13:08 +08001555 shell_stack_fullscreen(get_shell_surface(es));
Alex Wubd3354b2012-04-17 17:20:49 +08001556 shell_configure_fullscreen(get_shell_surface(es));
Alex Wu4539b082012-03-01 12:57:46 +08001557 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001558 default:
Alex Wubd3354b2012-04-17 17:20:49 +08001559 /* move the fullscreen surfaces down into the toplevel layer */
Alex Wu21858432012-04-01 20:13:08 +08001560 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1561 wl_list_for_each_reverse_safe(surf,
1562 prev,
1563 &shell->fullscreen_layer.surface_list,
1564 layer_link)
1565 weston_surface_restack(surf,
1566 &shell->toplevel_layer.surface_list);
1567 }
1568
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001569 weston_surface_restack(es,
1570 &shell->toplevel_layer.surface_list);
1571 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001572 }
1573}
1574
Alex Wu21858432012-04-01 20:13:08 +08001575/* no-op func for checking black surface */
1576static void
1577black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1578{
1579}
1580
1581static bool
1582is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1583{
1584 if (es->configure == black_surface_configure) {
1585 if (fs_surface)
1586 *fs_surface = (struct weston_surface *)es->private;
1587 return true;
1588 }
1589 return false;
1590}
1591
Kristian Høgsberg75840622011-09-06 13:48:16 -04001592static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001593click_to_activate_binding(struct wl_input_device *device,
Alex Wu4539b082012-03-01 12:57:46 +08001594 uint32_t time, uint32_t key,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001595 uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001596{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001597 struct weston_input_device *wd = (struct weston_input_device *) device;
Tiago Vignattibe143262012-04-16 17:31:41 +03001598 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001599 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001600 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001601
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001602 focus = (struct weston_surface *) device->pointer_focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08001603 if (!focus)
1604 return;
1605
Alex Wu21858432012-04-01 20:13:08 +08001606 if (is_black_surface(focus, &upper))
Alex Wu4539b082012-03-01 12:57:46 +08001607 focus = upper;
Alex Wu4539b082012-03-01 12:57:46 +08001608
Alex Wu9c35e6b2012-03-05 14:13:13 +08001609 if (state && device->pointer_grab == &device->default_pointer_grab)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001610 activate(shell, focus, wd);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001611}
1612
1613static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001614lock(struct wl_listener *listener, void *data)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001615{
Tiago Vignattibe143262012-04-16 17:31:41 +03001616 struct desktop_shell *shell =
1617 container_of(listener, struct desktop_shell, lock_listener);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001618 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001619 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001620 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001621
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001622 if (shell->locked) {
1623 wl_list_for_each(output, &shell->compositor->output_list, link)
1624 /* TODO: find a way to jump to other DPMS levels */
1625 if (output->set_dpms)
1626 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001627 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001628 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001629
1630 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001631
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001632 /* Hide all surfaces by removing the fullscreen, panel and
1633 * toplevel layers. This way nothing else can show or receive
1634 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001635
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001636 wl_list_remove(&shell->panel_layer.link);
1637 wl_list_remove(&shell->toplevel_layer.link);
1638 wl_list_remove(&shell->fullscreen_layer.link);
1639 wl_list_insert(&shell->compositor->cursor_layer.link,
1640 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001641
Pekka Paalanen77346a62011-11-30 16:26:35 +02001642 launch_screensaver(shell);
1643
1644 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1645 show_screensaver(shell, shsurf);
1646
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001647 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001648 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001649 weston_compositor_wake(shell->compositor);
1650 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001651 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001652
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001653 /* reset pointer foci */
Kristian Høgsbergaa6019e2012-03-11 16:35:16 -04001654 weston_compositor_schedule_repaint(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001655
1656 /* reset keyboard foci */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001657 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1658 wl_input_device_set_keyboard_focus(&device->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001659 NULL);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001660 }
1661
1662 /* TODO: disable bindings that should not work while locked. */
1663
1664 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001665}
1666
1667static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001668unlock(struct wl_listener *listener, void *data)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001669{
Tiago Vignattibe143262012-04-16 17:31:41 +03001670 struct desktop_shell *shell =
1671 container_of(listener, struct desktop_shell, unlock_listener);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001672
Pekka Paalanend81c2162011-11-16 13:47:34 +02001673 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001674 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001675 return;
1676 }
1677
1678 /* If desktop-shell client has gone away, unlock immediately. */
1679 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001680 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001681 return;
1682 }
1683
1684 if (shell->prepare_event_sent)
1685 return;
1686
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001687 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001688 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001689}
1690
1691static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001692center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001693{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001694 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001695 GLfloat x = (mode->width - surface->geometry.width) / 2;
1696 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001697
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001698 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001699}
1700
1701static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001702map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001703 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001704{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001705 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001706 struct shell_surface *shsurf;
1707 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05001708 struct weston_surface *parent;
Juan Zhao96879df2012-02-07 08:45:41 +08001709 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001710
Pekka Paalanen77346a62011-11-30 16:26:35 +02001711 shsurf = get_shell_surface(surface);
1712 if (shsurf)
1713 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001714
Pekka Paalanen60921e52012-01-25 15:55:43 +02001715 surface->geometry.width = width;
1716 surface->geometry.height = height;
1717 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001718
1719 /* initial positioning, see also configure() */
1720 switch (surface_type) {
1721 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001722 weston_surface_set_position(surface, 10 + random() % 400,
1723 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001724 break;
1725 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001726 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001727 break;
Alex Wu4539b082012-03-01 12:57:46 +08001728 case SHELL_SURFACE_FULLSCREEN:
1729 shell_map_fullscreen(shsurf);
1730 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001731 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001732 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08001733 panel_height = get_output_panel_height(shell,surface->output);
1734 weston_surface_set_position(surface, surface->output->x,
1735 surface->output->y + panel_height);
1736 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001737 case SHELL_SURFACE_LOCK:
1738 center_on_output(surface, get_default_output(compositor));
1739 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001740 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001741 shell_map_popup(shsurf);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001742 case SHELL_SURFACE_NONE:
1743 weston_surface_set_position(surface,
1744 surface->geometry.x + sx,
1745 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02001746 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001747 default:
1748 ;
1749 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001750
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001751 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001752 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001753 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001754 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001755 wl_list_insert(&shell->background_layer.surface_list,
1756 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001757 break;
1758 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001759 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001760 wl_list_insert(&shell->panel_layer.surface_list,
1761 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001762 break;
1763 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001764 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001765 wl_list_insert(&shell->lock_layer.surface_list,
1766 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001767 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001768 break;
1769 case SHELL_SURFACE_SCREENSAVER:
1770 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001771 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001772 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001773 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001774 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001775 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001776 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001777 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001778 break;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05001779 case SHELL_SURFACE_POPUP:
1780 case SHELL_SURFACE_TRANSIENT:
1781 parent = shsurf->parent->surface;
1782 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
1783 break;
Alex Wu4539b082012-03-01 12:57:46 +08001784 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02001785 case SHELL_SURFACE_NONE:
1786 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001787 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001788 wl_list_insert(&shell->toplevel_layer.surface_list,
1789 &surface->layer_link);
1790 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001791 }
1792
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02001793 if (surface_type != SHELL_SURFACE_NONE) {
1794 weston_surface_assign_output(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02001795 if (surface_type == SHELL_SURFACE_MAXIMIZED)
1796 surface->output = shsurf->output;
1797 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001798
Juan Zhao7bb92f02011-12-15 11:31:51 -05001799 switch (surface_type) {
1800 case SHELL_SURFACE_TOPLEVEL:
1801 case SHELL_SURFACE_TRANSIENT:
1802 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08001803 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05001804 if (!shell->locked)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001805 activate(shell, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001806 (struct weston_input_device *)
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001807 compositor->input_device);
Juan Zhao7bb92f02011-12-15 11:31:51 -05001808 break;
1809 default:
1810 break;
1811 }
1812
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001813 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001814 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001815}
1816
1817static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001818configure(struct desktop_shell *shell, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001819 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001820{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001821 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1822 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001823
Pekka Paalanen77346a62011-11-30 16:26:35 +02001824 shsurf = get_shell_surface(surface);
1825 if (shsurf)
1826 surface_type = shsurf->type;
1827
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001828 surface->geometry.x = x;
1829 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001830 surface->geometry.width = width;
1831 surface->geometry.height = height;
1832 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001833
1834 switch (surface_type) {
1835 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001836 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001837 break;
Alex Wu4539b082012-03-01 12:57:46 +08001838 case SHELL_SURFACE_FULLSCREEN:
Alex Wubd3354b2012-04-17 17:20:49 +08001839 shell_stack_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001840 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001841 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001842 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001843 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001844 surface->geometry.x = surface->output->x;
1845 surface->geometry.y = surface->output->y +
1846 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08001847 break;
Alex Wu4539b082012-03-01 12:57:46 +08001848 case SHELL_SURFACE_TOPLEVEL:
1849 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001850 default:
1851 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001852 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001853
Alex Wu4539b082012-03-01 12:57:46 +08001854 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001855 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001856 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001857
1858 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1859 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08001860 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
1861 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001862 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001863}
1864
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001865static void
1866shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1867{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001868 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03001869 struct desktop_shell *shell = shsurf->shell;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001870
1871 if (!weston_surface_is_mapped(es)) {
1872 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001873 } else if (shsurf->force_configure || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001874 es->geometry.width != es->buffer->width ||
1875 es->geometry.height != es->buffer->height) {
1876 GLfloat from_x, from_y;
1877 GLfloat to_x, to_y;
1878
1879 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
1880 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
1881 configure(shell, es,
1882 es->geometry.x + to_x - from_x,
1883 es->geometry.y + to_y - from_y,
1884 es->buffer->width, es->buffer->height);
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001885 shsurf->force_configure = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001886 }
1887}
1888
Tiago Vignattibe143262012-04-16 17:31:41 +03001889static int launch_desktop_shell_process(struct desktop_shell *shell);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001890
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001891static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001892desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001893{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001894 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03001895 struct desktop_shell *shell =
1896 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001897
1898 shell->child.process.pid = 0;
1899 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001900
1901 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1902 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001903 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001904 shell->child.deathstamp = time;
1905 shell->child.deathcount = 0;
1906 }
1907
1908 shell->child.deathcount++;
1909 if (shell->child.deathcount > 5) {
1910 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1911 return;
1912 }
1913
1914 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1915 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001916}
1917
1918static int
Tiago Vignattibe143262012-04-16 17:31:41 +03001919launch_desktop_shell_process(struct desktop_shell *shell)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001920{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001921 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001922
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001923 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001924 &shell->child.process,
1925 shell_exe,
1926 desktop_shell_sigchld);
1927
1928 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001929 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001930 return 0;
1931}
1932
1933static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001934bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1935{
Tiago Vignattibe143262012-04-16 17:31:41 +03001936 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001937
1938 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001939 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001940}
1941
Kristian Høgsberg75840622011-09-06 13:48:16 -04001942static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001943unbind_desktop_shell(struct wl_resource *resource)
1944{
Tiago Vignattibe143262012-04-16 17:31:41 +03001945 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001946
1947 if (shell->locked)
1948 resume_desktop(shell);
1949
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001950 shell->child.desktop_shell = NULL;
1951 shell->prepare_event_sent = false;
1952 free(resource);
1953}
1954
1955static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001956bind_desktop_shell(struct wl_client *client,
1957 void *data, uint32_t version, uint32_t id)
1958{
Tiago Vignattibe143262012-04-16 17:31:41 +03001959 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001960 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001961
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001962 resource = wl_client_add_object(client, &desktop_shell_interface,
1963 &desktop_shell_implementation,
1964 id, shell);
1965
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001966 if (client == shell->child.client) {
1967 resource->destroy = unbind_desktop_shell;
1968 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001969 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001970 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001971
1972 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1973 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001974 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001975}
1976
Pekka Paalanen6e168112011-11-24 11:34:05 +02001977static void
1978screensaver_set_surface(struct wl_client *client,
1979 struct wl_resource *resource,
1980 struct wl_resource *shell_surface_resource,
1981 struct wl_resource *output_resource)
1982{
Tiago Vignattibe143262012-04-16 17:31:41 +03001983 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001984 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001985 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001986
Pekka Paalanen98262232011-12-01 10:42:22 +02001987 if (reset_shell_surface_type(surface))
1988 return;
1989
Pekka Paalanen77346a62011-11-30 16:26:35 +02001990 surface->type = SHELL_SURFACE_SCREENSAVER;
1991
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001992 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001993 surface->output = output;
1994 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001995}
1996
1997static const struct screensaver_interface screensaver_implementation = {
1998 screensaver_set_surface
1999};
2000
2001static void
2002unbind_screensaver(struct wl_resource *resource)
2003{
Tiago Vignattibe143262012-04-16 17:31:41 +03002004 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002005
Pekka Paalanen77346a62011-11-30 16:26:35 +02002006 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002007 free(resource);
2008}
2009
2010static void
2011bind_screensaver(struct wl_client *client,
2012 void *data, uint32_t version, uint32_t id)
2013{
Tiago Vignattibe143262012-04-16 17:31:41 +03002014 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002015 struct wl_resource *resource;
2016
2017 resource = wl_client_add_object(client, &screensaver_interface,
2018 &screensaver_implementation,
2019 id, shell);
2020
Pekka Paalanen77346a62011-11-30 16:26:35 +02002021 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02002022 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02002023 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02002024 return;
2025 }
2026
2027 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2028 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002029 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02002030}
2031
Kristian Høgsberg07045392012-02-19 18:52:44 -05002032struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03002033 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002034 struct weston_surface *current;
2035 struct wl_listener listener;
2036 struct wl_keyboard_grab grab;
2037};
2038
2039static void
2040switcher_next(struct switcher *switcher)
2041{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002042 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002043 struct weston_surface *surface;
2044 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002045 struct shell_surface *shsurf;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002046
2047 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05002048 switch (get_shell_surface_type(surface)) {
2049 case SHELL_SURFACE_TOPLEVEL:
2050 case SHELL_SURFACE_FULLSCREEN:
2051 case SHELL_SURFACE_MAXIMIZED:
2052 if (first == NULL)
2053 first = surface;
2054 if (prev == switcher->current)
2055 next = surface;
2056 prev = surface;
2057 surface->alpha = 64;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05002058 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002059 weston_surface_damage(surface);
2060 break;
2061 default:
2062 break;
2063 }
Alex Wu1659daa2012-04-01 20:13:09 +08002064
2065 if (is_black_surface(surface, NULL)) {
2066 surface->alpha = 64;
2067 surface->geometry.dirty = 1;
2068 weston_surface_damage(surface);
2069 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05002070 }
2071
2072 if (next == NULL)
2073 next = first;
2074
Alex Wu07b26062012-03-12 16:06:01 +08002075 if (next == NULL)
2076 return;
2077
Kristian Høgsberg07045392012-02-19 18:52:44 -05002078 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002079 wl_signal_add(&next->surface.resource.destroy_signal,
2080 &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002081
2082 switcher->current = next;
2083 next->alpha = 255;
Alex Wu1659daa2012-04-01 20:13:09 +08002084
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002085 shsurf = get_shell_surface(switcher->current);
2086 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
2087 shsurf->fullscreen.black_surface->alpha = 255;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002088}
2089
2090static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002091switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002092{
2093 struct switcher *switcher =
2094 container_of(listener, struct switcher, listener);
2095
2096 switcher_next(switcher);
2097}
2098
2099static void
2100switcher_destroy(struct switcher *switcher, uint32_t time)
2101{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002102 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002103 struct weston_surface *surface;
2104 struct weston_input_device *device =
2105 (struct weston_input_device *) switcher->grab.input_device;
2106
2107 wl_list_for_each(surface, &compositor->surface_list, link) {
2108 surface->alpha = 255;
2109 weston_surface_damage(surface);
2110 }
2111
Alex Wu07b26062012-03-12 16:06:01 +08002112 if (switcher->current)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002113 activate(switcher->shell, switcher->current, device);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002114 wl_list_remove(&switcher->listener.link);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002115 wl_input_device_end_keyboard_grab(&device->input_device);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002116 free(switcher);
2117}
2118
2119static void
2120switcher_key(struct wl_keyboard_grab *grab,
2121 uint32_t time, uint32_t key, int32_t state)
2122{
2123 struct switcher *switcher = container_of(grab, struct switcher, grab);
2124 struct weston_input_device *device =
2125 (struct weston_input_device *) grab->input_device;
2126
2127 if ((device->modifier_state & MODIFIER_SUPER) == 0) {
2128 switcher_destroy(switcher, time);
2129 } else if (key == KEY_TAB && state) {
2130 switcher_next(switcher);
2131 }
2132};
2133
2134static const struct wl_keyboard_grab_interface switcher_grab = {
2135 switcher_key
2136};
2137
2138static void
2139switcher_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002140 uint32_t key, uint32_t button, uint32_t axis,
2141 int32_t state, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002142{
Tiago Vignattibe143262012-04-16 17:31:41 +03002143 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002144 struct switcher *switcher;
2145
2146 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002147 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002148 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002149 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002150 wl_list_init(&switcher->listener.link);
2151
2152 switcher->grab.interface = &switcher_grab;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002153 wl_input_device_start_keyboard_grab(device, &switcher->grab);
2154 wl_input_device_set_keyboard_focus(device, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002155 switcher_next(switcher);
2156}
2157
Pekka Paalanen3c647232011-12-22 13:43:43 +02002158static void
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002159backlight_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002160 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002161{
2162 struct weston_compositor *compositor = data;
2163 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002164 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002165
2166 /* TODO: we're limiting to simple use cases, where we assume just
2167 * control on the primary display. We'd have to extend later if we
2168 * ever get support for setting backlights on random desktop LCD
2169 * panels though */
2170 output = get_default_output(compositor);
2171 if (!output)
2172 return;
2173
2174 if (!output->set_backlight)
2175 return;
2176
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002177 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2178 backlight_new = output->backlight_current - 25;
2179 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2180 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002181
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002182 if (backlight_new < 5)
2183 backlight_new = 5;
2184 if (backlight_new > 255)
2185 backlight_new = 255;
2186
2187 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002188 output->set_backlight(output, output->backlight_current);
2189}
2190
2191static void
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002192debug_repaint_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002193 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002194{
Tiago Vignattibe143262012-04-16 17:31:41 +03002195 struct desktop_shell *shell = data;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002196 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002197 struct weston_surface *surface;
2198
2199 if (shell->debug_repaint_surface) {
2200 weston_surface_destroy(shell->debug_repaint_surface);
2201 shell->debug_repaint_surface = NULL;
2202 } else {
2203 surface = weston_surface_create(compositor);
2204 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2205 weston_surface_configure(surface, 0, 0, 8192, 8192);
2206 wl_list_insert(&compositor->fade_layer.surface_list,
2207 &surface->layer_link);
2208 weston_surface_assign_output(surface);
2209 pixman_region32_init(&surface->input);
2210
2211 /* Here's the dirty little trick that makes the
2212 * repaint debugging work: we force an
2213 * update_transform first to update dependent state
2214 * and clear the geometry.dirty bit. Then we clear
2215 * the surface damage so it only gets repainted
2216 * piecewise as we repaint other things. */
2217
2218 weston_surface_update_transform(surface);
2219 pixman_region32_fini(&surface->damage);
2220 pixman_region32_init(&surface->damage);
2221 shell->debug_repaint_surface = surface;
2222 }
2223}
2224
2225static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002226shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02002227{
Tiago Vignattibe143262012-04-16 17:31:41 +03002228 struct desktop_shell *shell =
2229 container_of(listener, struct desktop_shell, destroy_listener);
Pekka Paalanen3c647232011-12-22 13:43:43 +02002230
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02002231 if (shell->child.client)
2232 wl_client_destroy(shell->child.client);
2233
Pekka Paalanen3c647232011-12-22 13:43:43 +02002234 free(shell->screensaver.path);
2235 free(shell);
2236}
2237
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002238int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002239shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002240
Kristian Høgsberg1c562182011-05-02 22:09:20 -04002241WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002242shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002243{
Tiago Vignattibe143262012-04-16 17:31:41 +03002244 struct desktop_shell *shell;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002245
2246 shell = malloc(sizeof *shell);
2247 if (shell == NULL)
2248 return -1;
2249
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04002250 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002251 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002252
2253 shell->destroy_listener.notify = shell_destroy;
2254 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2255 shell->lock_listener.notify = lock;
2256 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2257 shell->unlock_listener.notify = unlock;
2258 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002259
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002260 wl_list_init(&shell->backgrounds);
2261 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002262 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002263
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002264 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2265 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2266 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2267 weston_layer_init(&shell->background_layer,
2268 &shell->toplevel_layer.link);
2269 wl_list_init(&shell->lock_layer.surface_list);
2270
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002271 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002272
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002273 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2274 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002275 return -1;
2276
Kristian Høgsberg75840622011-09-06 13:48:16 -04002277 if (wl_display_add_global(ec->wl_display,
2278 &desktop_shell_interface,
2279 shell, bind_desktop_shell) == NULL)
2280 return -1;
2281
Pekka Paalanen6e168112011-11-24 11:34:05 +02002282 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2283 shell, bind_screensaver) == NULL)
2284 return -1;
2285
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002286 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002287 if (launch_desktop_shell_process(shell) != 0)
2288 return -1;
2289
Scott Moreau6a3633d2012-03-20 08:47:59 -06002290 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, MODIFIER_SUPER,
2291 move_binding, shell);
2292 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, MODIFIER_SUPER,
2293 resize_binding, shell);
2294 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
2295 MODIFIER_CTRL | MODIFIER_ALT,
2296 terminate_binding, ec);
2297 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002298 click_to_activate_binding, shell);
Scott Moreau1b45a792012-03-22 10:58:23 -06002299 weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002300 MODIFIER_SUPER | MODIFIER_ALT,
2301 surface_opacity_binding, NULL);
2302 weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
Scott Moreau1b45a792012-03-22 10:58:23 -06002303 MODIFIER_SUPER, zoom_binding, NULL);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002304 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002305 MODIFIER_SUPER | MODIFIER_ALT,
2306 rotate_binding, NULL);
2307 weston_compositor_add_binding(ec, KEY_TAB, 0, 0, MODIFIER_SUPER,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002308 switcher_binding, shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002309
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002310 /* brightness */
Scott Moreau6a3633d2012-03-20 08:47:59 -06002311 weston_compositor_add_binding(ec, KEY_F9, 0, 0, MODIFIER_CTRL,
2312 backlight_binding, ec);
2313 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
2314 backlight_binding, ec);
2315 weston_compositor_add_binding(ec, KEY_F10, 0, 0, MODIFIER_CTRL,
2316 backlight_binding, ec);
2317 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
2318 backlight_binding, ec);
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002319
Scott Moreau6a3633d2012-03-20 08:47:59 -06002320 weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, MODIFIER_SUPER,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002321 debug_repaint_binding, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002322
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002323 return 0;
2324}