blob: 02061c6a53b176d283d1d47d86abbb7e74489d2c [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
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500158static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400159destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300160{
161 struct shell_grab *grab;
162
163 grab = container_of(listener, struct shell_grab,
164 shsurf_destroy_listener);
165
166 grab->shsurf = NULL;
167}
168
169static void
170shell_grab_init(struct shell_grab *grab,
171 const struct wl_pointer_grab_interface *interface,
172 struct shell_surface *shsurf)
173{
174 grab->grab.interface = interface;
175 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400176 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
177 wl_signal_add(&shsurf->resource.destroy_signal,
178 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300179
180}
181
182static void
183shell_grab_finish(struct shell_grab *grab)
184{
185 wl_list_remove(&grab->shsurf_destroy_listener.link);
186}
187
188static void
Alex Wu4539b082012-03-01 12:57:46 +0800189center_on_output(struct weston_surface *surface,
190 struct weston_output *output);
191
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300192static struct shell_surface *
193get_shell_surface(struct weston_surface *surface);
194
Alex Wu4539b082012-03-01 12:57:46 +0800195static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300196shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200197{
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200198 char *config_file;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200199 char *path = NULL;
200 int duration = 60;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200201
202 struct config_key saver_keys[] = {
Pekka Paalanen7296e792011-12-07 16:22:00 +0200203 { "path", CONFIG_KEY_STRING, &path },
204 { "duration", CONFIG_KEY_INTEGER, &duration },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200205 };
206
207 struct config_section cs[] = {
208 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
209 };
210
Tiago Vignatti9a206c42012-03-21 19:49:18 +0200211 config_file = config_file_path("weston.ini");
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500212 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200213 free(config_file);
214
Pekka Paalanen7296e792011-12-07 16:22:00 +0200215 shell->screensaver.path = path;
216 shell->screensaver.duration = duration;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200217}
218
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200219static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400220noop_grab_focus(struct wl_pointer_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500221 struct wl_surface *surface, int32_t x, int32_t y)
222{
223 grab->focus = NULL;
224}
225
226static void
Scott Moreau447013d2012-02-18 05:05:29 -0700227move_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500228 uint32_t time, int32_t x, int32_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500229{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500230 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500231 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300232 struct shell_surface *shsurf = move->base.shsurf;
233 struct weston_surface *es;
234
235 if (!shsurf)
236 return;
237
238 es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500239
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500240 weston_surface_configure(es,
241 device->x + move->dx,
242 device->y + move->dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200243 es->geometry.width, es->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500244}
245
246static void
Scott Moreau447013d2012-02-18 05:05:29 -0700247move_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400248 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500249{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300250 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
251 grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500252 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500253
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500254 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300255 shell_grab_finish(shell_grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400256 wl_input_device_end_pointer_grab(device);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500257 free(grab);
258 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500259}
260
Scott Moreau447013d2012-02-18 05:05:29 -0700261static const struct wl_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500262 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500263 move_grab_motion,
264 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500265};
266
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400267static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500268weston_surface_move(struct weston_surface *es,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400269 struct weston_input_device *wd)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500270{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500271 struct weston_move_grab *move;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300272 struct shell_surface *shsurf = get_shell_surface(es);
273
274 if (!shsurf)
275 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500276
277 move = malloc(sizeof *move);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400278 if (!move)
279 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500280
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300281 shell_grab_init(&move->base, &move_grab_interface, shsurf);
282
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200283 move->dx = es->geometry.x - wd->input_device.grab_x;
284 move->dy = es->geometry.y - wd->input_device.grab_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500285
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300286 wl_input_device_start_pointer_grab(&wd->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400287 &move->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500288
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400289 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400290
291 return 0;
292}
293
294static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200295shell_surface_move(struct wl_client *client, struct wl_resource *resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400296 struct wl_resource *input_resource, uint32_t serial)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400297{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500298 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200299 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400300
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500301 if (wd->input_device.button_count == 0 ||
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400302 wd->input_device.grab_serial != serial ||
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500303 wd->input_device.pointer_focus != &shsurf->surface->surface)
304 return;
305
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400306 if (weston_surface_move(shsurf->surface, wd) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400307 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500308}
309
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500310struct weston_resize_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300311 struct shell_grab base;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500312 uint32_t edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200313 int32_t width, height;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500314};
315
316static void
Scott Moreau447013d2012-02-18 05:05:29 -0700317resize_grab_motion(struct wl_pointer_grab *grab,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500318 uint32_t time, int32_t x, int32_t y)
319{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500320 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500321 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500322 int32_t width, height;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200323 int32_t from_x, from_y;
324 int32_t to_x, to_y;
325
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300326 if (!resize->base.shsurf)
327 return;
328
329 weston_surface_from_global(resize->base.shsurf->surface,
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200330 device->grab_x, device->grab_y,
331 &from_x, &from_y);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300332 weston_surface_from_global(resize->base.shsurf->surface,
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200333 device->x, device->y, &to_x, &to_y);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500334
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200335 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200336 width = resize->width + from_x - to_x;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200337 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200338 width = resize->width + to_x - from_x;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500339 } else {
340 width = resize->width;
341 }
342
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200343 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200344 height = resize->height + from_y - to_y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200345 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200346 height = resize->height + to_y - from_y;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500347 } else {
348 height = resize->height;
349 }
350
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300351 wl_shell_surface_send_configure(&resize->base.shsurf->resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400352 resize->edges, width, height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500353}
354
355static void
Scott Moreau447013d2012-02-18 05:05:29 -0700356resize_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400357 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500358{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300359 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500360 struct wl_input_device *device = grab->input_device;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500361
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500362 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300363 shell_grab_finish(&resize->base);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400364 wl_input_device_end_pointer_grab(device);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500365 free(grab);
366 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500367}
368
Scott Moreau447013d2012-02-18 05:05:29 -0700369static const struct wl_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500370 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500371 resize_grab_motion,
372 resize_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500373};
374
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400375static int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500376weston_surface_resize(struct shell_surface *shsurf,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400377 struct weston_input_device *wd, uint32_t edges)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500378{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500379 struct weston_resize_grab *resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500380
Alex Wu4539b082012-03-01 12:57:46 +0800381 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
382 return 0;
Kristian Høgsberg0ce24572011-01-28 15:18:33 -0500383
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200384 if (edges == 0 || edges > 15 ||
385 (edges & 3) == 3 || (edges & 12) == 12)
386 return 0;
387
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500388 resize = malloc(sizeof *resize);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400389 if (!resize)
390 return -1;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500391
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300392 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
393
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500394 resize->edges = edges;
Pekka Paalanen5c97ae72012-01-30 16:19:47 +0200395 resize->width = shsurf->surface->geometry.width;
396 resize->height = shsurf->surface->geometry.height;
Kristian Høgsberg904055a2011-08-18 17:55:30 -0400397
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300398 wl_input_device_start_pointer_grab(&wd->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400399 &resize->base.grab);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500400
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400401 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400402
403 return 0;
404}
405
406static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200407shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400408 struct wl_resource *input_resource, uint32_t serial,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200409 uint32_t edges)
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400410{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500411 struct weston_input_device *wd = input_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200412 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400413
Alex Wu4539b082012-03-01 12:57:46 +0800414 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
415 return;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -0400416
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500417 if (wd->input_device.button_count == 0 ||
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400418 wd->input_device.grab_serial != serial ||
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -0500419 wd->input_device.pointer_focus != &shsurf->surface->surface)
420 return;
421
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400422 if (weston_surface_resize(shsurf, wd, edges) < 0)
Kristian Høgsberg9ebcf942011-09-01 09:54:57 -0400423 wl_resource_post_no_memory(resource);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500424}
425
Juan Zhao96879df2012-02-07 08:45:41 +0800426static struct weston_output *
427get_default_output(struct weston_compositor *compositor)
428{
429 return container_of(compositor->output_list.next,
430 struct weston_output, link);
431}
432
Alex Wu4539b082012-03-01 12:57:46 +0800433static void
434shell_unset_fullscreen(struct shell_surface *shsurf)
435{
436 /* undo all fullscreen things here */
437 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
438 shsurf->fullscreen.framerate = 0;
439 wl_list_remove(&shsurf->fullscreen.transform.link);
440 wl_list_init(&shsurf->fullscreen.transform.link);
441 weston_surface_destroy(shsurf->fullscreen.black_surface);
442 shsurf->fullscreen.black_surface = NULL;
443 shsurf->fullscreen_output = NULL;
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +0300444 shsurf->force_configure = 1;
Alex Wu4539b082012-03-01 12:57:46 +0800445 weston_surface_set_position(shsurf->surface,
446 shsurf->saved_x, shsurf->saved_y);
447}
448
Pekka Paalanen98262232011-12-01 10:42:22 +0200449static int
450reset_shell_surface_type(struct shell_surface *surface)
451{
452 switch (surface->type) {
453 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +0800454 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +0200455 break;
Juan Zhao96879df2012-02-07 08:45:41 +0800456 case SHELL_SURFACE_MAXIMIZED:
457 surface->output = get_default_output(surface->surface->compositor);
458 weston_surface_set_position(surface->surface,
459 surface->saved_x,
460 surface->saved_y);
461 break;
Pekka Paalanen98262232011-12-01 10:42:22 +0200462 case SHELL_SURFACE_PANEL:
463 case SHELL_SURFACE_BACKGROUND:
464 wl_list_remove(&surface->link);
465 wl_list_init(&surface->link);
466 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200467 case SHELL_SURFACE_SCREENSAVER:
Pekka Paalanen98262232011-12-01 10:42:22 +0200468 case SHELL_SURFACE_LOCK:
469 wl_resource_post_error(&surface->resource,
470 WL_DISPLAY_ERROR_INVALID_METHOD,
Pekka Paalanen77346a62011-11-30 16:26:35 +0200471 "cannot reassign surface type");
Pekka Paalanen98262232011-12-01 10:42:22 +0200472 return -1;
473 case SHELL_SURFACE_NONE:
474 case SHELL_SURFACE_TOPLEVEL:
475 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500476 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +0200477 break;
478 }
479
480 surface->type = SHELL_SURFACE_NONE;
481 return 0;
482}
483
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500484static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200485shell_surface_set_toplevel(struct wl_client *client,
486 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400487
488{
Pekka Paalanen98262232011-12-01 10:42:22 +0200489 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400490
Pekka Paalanen98262232011-12-01 10:42:22 +0200491 if (reset_shell_surface_type(surface))
492 return;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400493
Pekka Paalanen98262232011-12-01 10:42:22 +0200494 surface->type = SHELL_SURFACE_TOPLEVEL;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400495}
496
497static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200498shell_surface_set_transient(struct wl_client *client,
499 struct wl_resource *resource,
500 struct wl_resource *parent_resource,
501 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400502{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200503 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500504 struct weston_surface *es = shsurf->surface;
Pekka Paalanen01e7b002011-12-08 16:42:33 +0200505 struct shell_surface *pshsurf = parent_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500506 struct weston_surface *pes = pshsurf->surface;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400507
Pekka Paalanen98262232011-12-01 10:42:22 +0200508 if (reset_shell_surface_type(shsurf))
509 return;
510
Alex Wu4539b082012-03-01 12:57:46 +0800511 /* assign to parents output */
Alex Wu88277d12012-02-22 14:50:46 +0800512 shsurf->output = pes->output;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200513 weston_surface_set_position(es, pes->geometry.x + x,
514 pes->geometry.y + y);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400515
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200516 shsurf->type = SHELL_SURFACE_TRANSIENT;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400517}
518
Tiago Vignattibe143262012-04-16 17:31:41 +0300519static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +0800520shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200521{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400522 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +0800523}
524
525static int
Tiago Vignattibe143262012-04-16 17:31:41 +0300526get_output_panel_height(struct desktop_shell *shell,
527 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +0800528{
529 struct shell_surface *priv;
530 int panel_height = 0;
531
532 if (!output)
533 return 0;
534
Tiago Vignattibe143262012-04-16 17:31:41 +0300535 wl_list_for_each(priv, &shell->panels, link) {
Juan Zhao96879df2012-02-07 08:45:41 +0800536 if (priv->output == output) {
537 panel_height = priv->surface->geometry.height;
538 break;
539 }
540 }
541 return panel_height;
542}
543
544static void
545shell_surface_set_maximized(struct wl_client *client,
546 struct wl_resource *resource,
547 struct wl_resource *output_resource )
548{
549 struct shell_surface *shsurf = resource->data;
550 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300551 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +0800552 uint32_t edges = 0, panel_height = 0;
553
554 /* get the default output, if the client set it as NULL
555 check whether the ouput is available */
556 if (output_resource)
557 shsurf->output = output_resource->data;
558 else
559 shsurf->output = get_default_output(es->compositor);
560
561 if (reset_shell_surface_type(shsurf))
562 return;
563
564 shsurf->saved_x = es->geometry.x;
565 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800566 shsurf->saved_position_valid = true;
Juan Zhao96879df2012-02-07 08:45:41 +0800567
Tiago Vignattibe143262012-04-16 17:31:41 +0300568 shell = shell_surface_get_shell(shsurf);
569 panel_height = get_output_panel_height(shell, es->output);
Juan Zhao96879df2012-02-07 08:45:41 +0800570 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500571
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400572 wl_shell_surface_send_configure(&shsurf->resource, edges,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500573 es->output->current->width,
574 es->output->current->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +0800575
576 shsurf->type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +0200577}
578
Alex Wu21858432012-04-01 20:13:08 +0800579static void
580black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
581
Alex Wu4539b082012-03-01 12:57:46 +0800582static struct weston_surface *
583create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +0800584 struct weston_surface *fs_surface,
Alex Wu4539b082012-03-01 12:57:46 +0800585 GLfloat x, GLfloat y, int w, int h)
586{
587 struct weston_surface *surface = NULL;
588
589 surface = weston_surface_create(ec);
590 if (surface == NULL) {
591 fprintf(stderr, "no memory\n");
592 return NULL;
593 }
594
Alex Wu21858432012-04-01 20:13:08 +0800595 surface->configure = black_surface_configure;
596 surface->private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +0800597 weston_surface_configure(surface, x, y, w, h);
598 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
599 return surface;
600}
601
602/* Create black surface and append it to the associated fullscreen surface.
603 * Handle size dismatch and positioning according to the method. */
604static void
605shell_configure_fullscreen(struct shell_surface *shsurf)
606{
607 struct weston_output *output = shsurf->fullscreen_output;
608 struct weston_surface *surface = shsurf->surface;
609 struct weston_matrix *matrix;
610 float scale;
611
612 center_on_output(surface, output);
613
614 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500615 shsurf->fullscreen.black_surface =
616 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +0800617 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500618 output->x, output->y,
619 output->current->width,
620 output->current->height);
621
622 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
623 wl_list_insert(&surface->layer_link,
624 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800625 shsurf->fullscreen.black_surface->output = output;
626
627 switch (shsurf->fullscreen.type) {
628 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
629 break;
630 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
631 matrix = &shsurf->fullscreen.transform.matrix;
632 weston_matrix_init(matrix);
633 scale = (float)output->current->width/(float)surface->geometry.width;
634 weston_matrix_scale(matrix, scale, scale, 1);
635 wl_list_remove(&shsurf->fullscreen.transform.link);
636 wl_list_insert(surface->geometry.transformation_list.prev,
637 &shsurf->fullscreen.transform.link);
638 weston_surface_set_position(surface, output->x, output->y);
639 break;
640 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
641 break;
642 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
643 break;
644 default:
645 break;
646 }
647}
648
649/* make the fullscreen and black surface at the top */
650static void
651shell_stack_fullscreen(struct shell_surface *shsurf)
652{
653 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +0300654 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +0800655
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500656 wl_list_remove(&surface->layer_link);
657 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800658
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500659 wl_list_insert(&shell->fullscreen_layer.surface_list,
660 &surface->layer_link);
661 wl_list_insert(&surface->layer_link,
662 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +0800663
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500664 weston_surface_damage(surface);
665 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +0800666}
667
668static void
669shell_map_fullscreen(struct shell_surface *shsurf)
670{
671 shell_configure_fullscreen(shsurf);
672 shell_stack_fullscreen(shsurf);
673}
674
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400675static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200676shell_surface_set_fullscreen(struct wl_client *client,
Kristian Høgsbergf856fd22012-02-16 15:58:14 -0500677 struct wl_resource *resource,
678 uint32_t method,
679 uint32_t framerate,
680 struct wl_resource *output_resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400681{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200682 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500683 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +0800684
685 if (output_resource)
686 shsurf->output = output_resource->data;
687 else
688 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400689
Pekka Paalanen98262232011-12-01 10:42:22 +0200690 if (reset_shell_surface_type(shsurf))
691 return;
692
Alex Wu4539b082012-03-01 12:57:46 +0800693 shsurf->fullscreen_output = shsurf->output;
694 shsurf->fullscreen.type = method;
695 shsurf->fullscreen.framerate = framerate;
696 shsurf->type = SHELL_SURFACE_FULLSCREEN;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400697
Pekka Paalanenba3cf952012-01-25 16:22:05 +0200698 shsurf->saved_x = es->geometry.x;
699 shsurf->saved_y = es->geometry.y;
Alex Wu4539b082012-03-01 12:57:46 +0800700 shsurf->saved_position_valid = true;
701
Ander Conselvan de Oliveirab8ab14f2012-03-27 17:36:36 +0300702 if (weston_surface_is_mapped(es))
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +0300703 shsurf->force_configure = 1;
Kristian Høgsbergd5ae9f42012-02-16 23:38:14 -0500704
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400705 wl_shell_surface_send_configure(&shsurf->resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500706 shsurf->output->current->width,
707 shsurf->output->current->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400708}
709
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500710static void
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400711popup_grab_focus(struct wl_pointer_grab *grab,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500712 struct wl_surface *surface, int32_t x, int32_t y)
713{
714 struct wl_input_device *device = grab->input_device;
715 struct shell_surface *priv =
716 container_of(grab, struct shell_surface, popup.grab);
717 struct wl_client *client = priv->surface->surface.resource.client;
718
Pekka Paalanencb108432012-01-19 16:25:40 +0200719 if (surface && surface->resource.client == client) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400720 wl_input_device_set_pointer_focus(device, surface, x, y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500721 grab->focus = surface;
722 } else {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400723 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500724 grab->focus = NULL;
725 }
726}
727
728static void
Scott Moreau447013d2012-02-18 05:05:29 -0700729popup_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanenb29f4122012-02-14 14:59:18 +0200730 uint32_t time, int32_t sx, int32_t sy)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500731{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500732 struct wl_resource *resource;
733
734 resource = grab->input_device->pointer_focus_resource;
735 if (resource)
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500736 wl_input_device_send_motion(resource, time, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500737}
738
739static void
Scott Moreau447013d2012-02-18 05:05:29 -0700740popup_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -0400741 uint32_t time, uint32_t button, int32_t state)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500742{
743 struct wl_resource *resource;
744 struct shell_surface *shsurf =
745 container_of(grab, struct shell_surface, popup.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400746 struct wl_display *display;
747 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500748
749 resource = grab->input_device->pointer_focus_resource;
750 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400751 display = wl_client_get_display(resource->client);
752 serial = wl_display_get_serial(display);
753 wl_input_device_send_button(resource, serial,
754 time, button, state);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500755 } else if (state == 0 &&
756 (shsurf->popup.initial_up ||
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400757 time - shsurf->popup.device->grab_time > 500)) {
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -0500758 wl_shell_surface_send_popup_done(&shsurf->resource);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400759 wl_input_device_end_pointer_grab(grab->input_device);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500760 shsurf->popup.grab.input_device = NULL;
761 }
762
763 if (state == 0)
764 shsurf->popup.initial_up = 1;
765}
766
Scott Moreau447013d2012-02-18 05:05:29 -0700767static const struct wl_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500768 popup_grab_focus,
769 popup_grab_motion,
770 popup_grab_button,
771};
772
773static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400774shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500775{
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400776 struct wl_input_device *device = shsurf->popup.device;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500777 struct weston_surface *es = shsurf->surface;
778 struct weston_surface *parent = shsurf->parent->surface;
779
780 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500781 shsurf->popup.grab.interface = &popup_grab_interface;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500782
Pekka Paalanen938269a2012-02-07 14:19:01 +0200783 weston_surface_update_transform(parent);
784 if (parent->transform.enabled) {
785 shsurf->popup.parent_transform.matrix =
786 parent->transform.matrix;
787 } else {
788 /* construct x, y translation matrix */
789 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
790 shsurf->popup.parent_transform.matrix.d[12] =
791 parent->geometry.x;
792 shsurf->popup.parent_transform.matrix.d[13] =
793 parent->geometry.y;
794 }
795 wl_list_insert(es->geometry.transformation_list.prev,
796 &shsurf->popup.parent_transform.link);
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +0200797 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500798
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500799 shsurf->popup.initial_up = 0;
800
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400801 /* We don't require the grab to still be active, but if another
802 * grab has started in the meantime, we end the popup now. */
803 if (device->grab_serial == shsurf->popup.serial) {
804 wl_input_device_start_pointer_grab(device,
805 &shsurf->popup.grab);
806 } else {
807 wl_shell_surface_send_popup_done(&shsurf->resource);
808 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500809}
810
811static void
812shell_surface_set_popup(struct wl_client *client,
813 struct wl_resource *resource,
814 struct wl_resource *input_device_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400815 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500816 struct wl_resource *parent_resource,
817 int32_t x, int32_t y, uint32_t flags)
818{
819 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500820
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500821 shsurf->type = SHELL_SURFACE_POPUP;
822 shsurf->parent = parent_resource->data;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400823 shsurf->popup.device = input_device_resource->data;
824 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500825 shsurf->popup.x = x;
826 shsurf->popup.y = y;
827}
828
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200829static const struct wl_shell_surface_interface shell_surface_implementation = {
830 shell_surface_move,
831 shell_surface_resize,
832 shell_surface_set_toplevel,
833 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500834 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +0800835 shell_surface_set_popup,
836 shell_surface_set_maximized
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200837};
838
839static void
840destroy_shell_surface(struct wl_resource *resource)
841{
842 struct shell_surface *shsurf = resource->data;
843
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500844 if (shsurf->popup.grab.input_device)
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400845 wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500846
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200847 /* in case cleaning up a dead client destroys shell_surface first */
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300848 if (shsurf->surface) {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200849 wl_list_remove(&shsurf->surface_destroy_listener.link);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300850 shsurf->surface->configure = NULL;
851 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200852
Alex Wuaa08e2d2012-03-05 11:01:40 +0800853 if (shsurf->fullscreen.black_surface)
854 weston_surface_destroy(shsurf->fullscreen.black_surface);
855
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200856 wl_list_remove(&shsurf->link);
857 free(shsurf);
858}
859
860static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400861shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200862{
863 struct shell_surface *shsurf = container_of(listener,
864 struct shell_surface,
865 surface_destroy_listener);
866
867 shsurf->surface = NULL;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400868 wl_resource_destroy(&shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200869}
870
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200871static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500872get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200873{
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200874 struct wl_listener *listener;
875
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400876 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
877 shell_handle_surface_destroy);
878 if (listener)
879 return container_of(listener, struct shell_surface,
880 surface_destroy_listener);
Pekka Paalanenec2b32f2011-11-28 15:12:34 +0200881
882 return NULL;
883}
884
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200885static void
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300886shell_surface_configure(struct weston_surface *, int32_t, int32_t);
887
888static void
Pekka Paalanen46229672011-11-29 15:49:31 +0200889shell_get_shell_surface(struct wl_client *client,
890 struct wl_resource *resource,
891 uint32_t id,
892 struct wl_resource *surface_resource)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200893{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500894 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200895 struct shell_surface *shsurf;
896
Pekka Paalanenf32f1fc2011-11-29 16:05:28 +0200897 if (get_shell_surface(surface)) {
898 wl_resource_post_error(surface_resource,
899 WL_DISPLAY_ERROR_INVALID_OBJECT,
900 "wl_shell::get_shell_surface already requested");
901 return;
902 }
903
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300904 if (surface->configure) {
905 wl_resource_post_error(surface_resource,
906 WL_DISPLAY_ERROR_INVALID_OBJECT,
907 "surface->configure already set");
908 return;
909 }
910
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200911 shsurf = calloc(1, sizeof *shsurf);
912 if (!shsurf) {
913 wl_resource_post_no_memory(resource);
914 return;
915 }
916
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +0300917 surface->configure = shell_surface_configure;
918
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200919 shsurf->resource.destroy = destroy_shell_surface;
920 shsurf->resource.object.id = id;
921 shsurf->resource.object.interface = &wl_shell_surface_interface;
922 shsurf->resource.object.implementation =
923 (void (**)(void)) &shell_surface_implementation;
924 shsurf->resource.data = shsurf;
925
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400926 shsurf->shell = resource->data;
Alex Wu4539b082012-03-01 12:57:46 +0800927 shsurf->saved_position_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200928 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +0800929 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
930 shsurf->fullscreen.framerate = 0;
931 shsurf->fullscreen.black_surface = NULL;
932 wl_list_init(&shsurf->fullscreen.transform.link);
933
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400934 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
935 wl_signal_add(&surface->surface.resource.destroy_signal,
936 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200937
938 /* init link so its safe to always remove it in destroy_shell_surface */
939 wl_list_init(&shsurf->link);
940
Pekka Paalanen460099f2012-01-20 16:48:25 +0200941 /* empty when not in use */
942 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500943 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +0200944
Pekka Paalanen98262232011-12-01 10:42:22 +0200945 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200946
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200947 wl_client_add_resource(client, &shsurf->resource);
948}
949
950static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +0200951 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500952};
953
Kristian Høgsberg07937562011-04-12 17:25:42 -0400954static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500955handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +0200956{
957 proc->pid = 0;
958}
959
960static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300961launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +0200962{
963 if (shell->screensaver.binding)
964 return;
965
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200966 if (!shell->screensaver.path)
967 return;
968
Kristian Høgsberg32bed572012-03-01 17:11:36 -0500969 if (shell->screensaver.process.pid != 0) {
970 fprintf(stderr, "old screensaver still running\n");
971 return;
972 }
973
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500974 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200975 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200976 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +0200977 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200978}
979
980static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300981terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +0200982{
Pekka Paalanen18027e52011-12-02 16:31:49 +0200983 if (shell->screensaver.process.pid == 0)
984 return;
985
986 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +0200987}
988
989static void
Tiago Vignattibe143262012-04-16 17:31:41 +0300990show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +0200991{
992 struct wl_list *list;
993
994 if (shell->lock_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500995 list = &shell->lock_surface->surface->layer_link;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200996 else
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500997 list = &shell->lock_layer.surface_list;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200998
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500999 wl_list_remove(&surface->surface->layer_link);
1000 wl_list_insert(list, &surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001001 surface->surface->output = surface->output;
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001002 weston_surface_damage(surface->surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001003}
1004
1005static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001006hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001007{
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001008 wl_list_remove(&surface->surface->layer_link);
1009 wl_list_init(&surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001010 surface->surface->output = NULL;
1011}
1012
1013static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001014desktop_shell_set_background(struct wl_client *client,
1015 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001016 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001017 struct wl_resource *surface_resource)
1018{
Tiago Vignattibe143262012-04-16 17:31:41 +03001019 struct desktop_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001020 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001021 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001022 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001023
Pekka Paalanen98262232011-12-01 10:42:22 +02001024 if (reset_shell_surface_type(shsurf))
1025 return;
1026
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001027 wl_list_for_each(priv, &shell->backgrounds, link) {
1028 if (priv->output == output_resource->data) {
1029 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001030 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001031 wl_list_remove(&priv->link);
1032 break;
1033 }
1034 }
1035
Pekka Paalanen068ae942011-11-28 14:11:15 +02001036 shsurf->type = SHELL_SURFACE_BACKGROUND;
1037 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001038
Pekka Paalanen068ae942011-11-28 14:11:15 +02001039 wl_list_insert(&shell->backgrounds, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001040
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001041 weston_surface_set_position(surface, shsurf->output->x,
1042 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001043
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001044 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001045 surface_resource,
1046 shsurf->output->current->width,
1047 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001048}
1049
1050static void
1051desktop_shell_set_panel(struct wl_client *client,
1052 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001053 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04001054 struct wl_resource *surface_resource)
1055{
Tiago Vignattibe143262012-04-16 17:31:41 +03001056 struct desktop_shell *shell = resource->data;
Pekka Paalanen068ae942011-11-28 14:11:15 +02001057 struct shell_surface *shsurf = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001058 struct weston_surface *surface = shsurf->surface;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001059 struct shell_surface *priv;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001060
Pekka Paalanen98262232011-12-01 10:42:22 +02001061 if (reset_shell_surface_type(shsurf))
1062 return;
1063
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001064 wl_list_for_each(priv, &shell->panels, link) {
1065 if (priv->output == output_resource->data) {
1066 priv->surface->output = NULL;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001067 wl_list_remove(&priv->surface->layer_link);
Benjamin Franzkef02bb642011-11-23 20:46:40 +01001068 wl_list_remove(&priv->link);
1069 break;
1070 }
1071 }
1072
Pekka Paalanen068ae942011-11-28 14:11:15 +02001073 shsurf->type = SHELL_SURFACE_PANEL;
1074 shsurf->output = output_resource->data;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001075
Pekka Paalanen068ae942011-11-28 14:11:15 +02001076 wl_list_insert(&shell->panels, &shsurf->link);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001077
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001078 weston_surface_set_position(surface, shsurf->output->x,
1079 shsurf->output->y);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001080
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001081 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001082 surface_resource,
1083 shsurf->output->current->width,
1084 shsurf->output->current->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001085}
1086
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001087static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001088handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001089{
Tiago Vignattibe143262012-04-16 17:31:41 +03001090 struct desktop_shell *shell =
1091 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001092
1093 fprintf(stderr, "lock surface gone\n");
1094 shell->lock_surface = NULL;
1095}
1096
1097static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001098desktop_shell_set_lock_surface(struct wl_client *client,
1099 struct wl_resource *resource,
1100 struct wl_resource *surface_resource)
1101{
Tiago Vignattibe143262012-04-16 17:31:41 +03001102 struct desktop_shell *shell = resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001103 struct shell_surface *surface = surface_resource->data;
1104
1105 if (reset_shell_surface_type(surface))
1106 return;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001107
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001108 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02001109
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001110 if (!shell->locked)
1111 return;
1112
Pekka Paalanen98262232011-12-01 10:42:22 +02001113 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001114
Kristian Høgsberg27e30522012-04-11 23:18:23 -04001115 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1116 wl_signal_add(&surface_resource->destroy_signal,
1117 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001118
Pekka Paalanen068ae942011-11-28 14:11:15 +02001119 shell->lock_surface->type = SHELL_SURFACE_LOCK;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001120}
1121
1122static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001123resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001124{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001125 struct shell_surface *tmp;
1126
1127 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1128 hide_screensaver(shell, tmp);
1129
1130 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001131
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001132 wl_list_remove(&shell->lock_layer.link);
1133 wl_list_insert(&shell->compositor->cursor_layer.link,
1134 &shell->fullscreen_layer.link);
1135 wl_list_insert(&shell->fullscreen_layer.link,
1136 &shell->panel_layer.link);
1137 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001138
1139 shell->locked = false;
Pekka Paalanen7296e792011-12-07 16:22:00 +02001140 shell->compositor->idle_time = shell->compositor->option_idle_time;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001141 weston_compositor_wake(shell->compositor);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02001142 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001143}
1144
1145static void
1146desktop_shell_unlock(struct wl_client *client,
1147 struct wl_resource *resource)
1148{
Tiago Vignattibe143262012-04-16 17:31:41 +03001149 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001150
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001151 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001152
1153 if (shell->locked)
1154 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001155}
1156
Kristian Høgsberg75840622011-09-06 13:48:16 -04001157static const struct desktop_shell_interface desktop_shell_implementation = {
1158 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001159 desktop_shell_set_panel,
1160 desktop_shell_set_lock_surface,
1161 desktop_shell_unlock
Kristian Høgsberg75840622011-09-06 13:48:16 -04001162};
1163
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001164static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001165get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001166{
1167 struct shell_surface *shsurf;
1168
1169 shsurf = get_shell_surface(surface);
1170 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02001171 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001172 return shsurf->type;
1173}
1174
Kristian Høgsberg75840622011-09-06 13:48:16 -04001175static void
Kristian Høgsberg07937562011-04-12 17:25:42 -04001176move_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001177 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001178{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001179 struct weston_surface *surface =
1180 (struct weston_surface *) device->pointer_focus;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001181
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001182 if (surface == NULL)
1183 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001184
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001185 switch (get_shell_surface_type(surface)) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001186 case SHELL_SURFACE_PANEL:
1187 case SHELL_SURFACE_BACKGROUND:
1188 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001189 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001190 return;
1191 default:
1192 break;
1193 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001194
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001195 weston_surface_move(surface, (struct weston_input_device *) device);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001196}
1197
1198static void
1199resize_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001200 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001201{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001202 struct weston_surface *surface =
1203 (struct weston_surface *) device->pointer_focus;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001204 uint32_t edges = 0;
1205 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001206 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001207
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001208 if (surface == NULL)
1209 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001210
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001211 shsurf = get_shell_surface(surface);
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001212 if (!shsurf)
1213 return;
1214
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001215 switch (shsurf->type) {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001216 case SHELL_SURFACE_PANEL:
1217 case SHELL_SURFACE_BACKGROUND:
1218 case SHELL_SURFACE_FULLSCREEN:
Pekka Paalanen77346a62011-11-30 16:26:35 +02001219 case SHELL_SURFACE_SCREENSAVER:
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001220 return;
1221 default:
1222 break;
1223 }
Kristian Høgsberg10f097e2011-04-13 11:52:54 -04001224
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02001225 weston_surface_from_global(surface,
1226 device->grab_x, device->grab_y, &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04001227
Pekka Paalanen60921e52012-01-25 15:55:43 +02001228 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001229 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001230 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001231 edges |= 0;
1232 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001233 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001234
Pekka Paalanen60921e52012-01-25 15:55:43 +02001235 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001236 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001237 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04001238 edges |= 0;
1239 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001240 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04001241
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001242 weston_surface_resize(shsurf, (struct weston_input_device *) device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001243 edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001244}
1245
1246static void
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001247surface_opacity_binding(struct wl_input_device *device, uint32_t time,
1248 uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data)
1249{
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001250 uint32_t step = 15;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06001251 struct shell_surface *shsurf;
1252 struct weston_surface *surface =
1253 (struct weston_surface *) device->pointer_focus;
1254
1255 if (surface == NULL)
1256 return;
1257
1258 shsurf = get_shell_surface(surface);
1259 if (!shsurf)
1260 return;
1261
1262 switch (shsurf->type) {
1263 case SHELL_SURFACE_BACKGROUND:
1264 case SHELL_SURFACE_SCREENSAVER:
1265 return;
1266 default:
1267 break;
1268 }
1269
1270 surface->alpha += value * step;
1271
1272 if (surface->alpha > 255)
1273 surface->alpha = 255;
1274 if (surface->alpha < step)
1275 surface->alpha = step;
1276
1277 surface->geometry.dirty = 1;
1278 weston_surface_damage(surface);
1279}
1280
1281static void
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -05001282zoom_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau1b45a792012-03-22 10:58:23 -06001283 uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data)
Scott Moreauccbf29d2012-02-22 14:21:41 -07001284{
1285 struct weston_input_device *wd = (struct weston_input_device *) device;
1286 struct weston_compositor *compositor = wd->compositor;
1287 struct weston_output *output;
1288
1289 wl_list_for_each(output, &compositor->output_list, link) {
1290 if (pixman_region32_contains_point(&output->region,
1291 device->x, device->y, NULL)) {
Scott Moreau1b45a792012-03-22 10:58:23 -06001292 output->zoom.active = 1;
1293 output->zoom.level += output->zoom.increment * -value;
Scott Moreauc6d7f602012-02-23 22:28:37 -07001294
1295 if (output->zoom.level >= 1.0) {
1296 output->zoom.active = 0;
1297 output->zoom.level = 1.0;
1298 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07001299
1300 if (output->zoom.level < output->zoom.increment)
1301 output->zoom.level = output->zoom.increment;
1302
1303 weston_output_update_zoom(output, device->x, device->y);
1304 }
1305 }
1306}
1307
Scott Moreauccbf29d2012-02-22 14:21:41 -07001308static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001309terminate_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001310 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001311{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001312 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001313
1314 if (state)
1315 wl_display_terminate(compositor->wl_display);
1316}
1317
1318static void
Scott Moreau447013d2012-02-18 05:05:29 -07001319rotate_grab_motion(struct wl_pointer_grab *grab,
Pekka Paalanen460099f2012-01-20 16:48:25 +02001320 uint32_t time, int32_t x, int32_t y)
1321{
1322 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001323 container_of(grab, struct rotate_grab, base.grab);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001324 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001325 struct shell_surface *shsurf = rotate->base.shsurf;
1326 struct weston_surface *surface;
1327 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1328
1329 if (!shsurf)
1330 return;
1331
1332 surface = shsurf->surface;
1333
1334 cx = 0.5f * surface->geometry.width;
1335 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001336
1337 dx = device->x - rotate->center.x;
1338 dy = device->y - rotate->center.y;
1339 r = sqrtf(dx * dx + dy * dy);
1340
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001341 wl_list_remove(&shsurf->rotation.transform.link);
1342 shsurf->surface->geometry.dirty = 1;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001343
1344 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001345 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001346 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001347
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001348 weston_matrix_init(&rotate->rotation);
1349 rotate->rotation.d[0] = dx / r;
1350 rotate->rotation.d[4] = -dy / r;
1351 rotate->rotation.d[1] = -rotate->rotation.d[4];
1352 rotate->rotation.d[5] = rotate->rotation.d[0];
Pekka Paalanen460099f2012-01-20 16:48:25 +02001353
1354 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001355 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001356 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001357 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02001358 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001359
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02001360 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001361 &shsurf->surface->geometry.transformation_list,
1362 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001363 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001364 wl_list_init(&shsurf->rotation.transform.link);
1365 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001366 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001367 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001368
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001369 /* We need to adjust the position of the surface
1370 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001371 cposx = surface->geometry.x + cx;
1372 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001373 dposx = rotate->center.x - cposx;
1374 dposy = rotate->center.y - cposy;
1375 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001376 weston_surface_set_position(surface,
1377 surface->geometry.x + dposx,
1378 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001379 }
1380
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02001381 /* Repaint implies weston_surface_update_transform(), which
1382 * lazily applies the damage due to rotation update.
1383 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001384 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001385}
1386
1387static void
Scott Moreau447013d2012-02-18 05:05:29 -07001388rotate_grab_button(struct wl_pointer_grab *grab,
Kristian Høgsberged92f792012-03-30 11:31:25 -04001389 uint32_t time, uint32_t button, int32_t state)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001390{
1391 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001392 container_of(grab, struct rotate_grab, base.grab);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001393 struct wl_input_device *device = grab->input_device;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001394 struct shell_surface *shsurf = rotate->base.shsurf;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001395
1396 if (device->button_count == 0 && state == 0) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001397 if (shsurf)
1398 weston_matrix_multiply(&shsurf->rotation.rotation,
1399 &rotate->rotation);
1400 shell_grab_finish(&rotate->base);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001401 wl_input_device_end_pointer_grab(device);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001402 free(rotate);
1403 }
1404}
1405
Scott Moreau447013d2012-02-18 05:05:29 -07001406static const struct wl_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02001407 noop_grab_focus,
1408 rotate_grab_motion,
1409 rotate_grab_button,
1410};
1411
1412static void
1413rotate_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001414 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Pekka Paalanen460099f2012-01-20 16:48:25 +02001415{
1416 struct weston_surface *base_surface =
1417 (struct weston_surface *) device->pointer_focus;
1418 struct shell_surface *surface;
1419 struct rotate_grab *rotate;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001420 GLfloat dx, dy;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001421 GLfloat r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02001422
1423 if (base_surface == NULL)
1424 return;
1425
1426 surface = get_shell_surface(base_surface);
1427 if (!surface)
1428 return;
1429
1430 switch (surface->type) {
1431 case SHELL_SURFACE_PANEL:
1432 case SHELL_SURFACE_BACKGROUND:
1433 case SHELL_SURFACE_FULLSCREEN:
1434 case SHELL_SURFACE_SCREENSAVER:
1435 return;
1436 default:
1437 break;
1438 }
1439
Pekka Paalanen460099f2012-01-20 16:48:25 +02001440 rotate = malloc(sizeof *rotate);
1441 if (!rotate)
1442 return;
1443
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001444 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001445
1446 weston_surface_to_global(surface->surface,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001447 surface->surface->geometry.width / 2,
1448 surface->surface->geometry.height / 2,
Pekka Paalanene0f3cb22012-01-24 09:59:29 +02001449 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001450
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001451 wl_input_device_start_pointer_grab(device, &rotate->base.grab);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001452
1453 dx = device->x - rotate->center.x;
1454 dy = device->y - rotate->center.y;
1455 r = sqrtf(dx * dx + dy * dy);
1456 if (r > 20.0f) {
1457 struct weston_matrix inverse;
1458
1459 weston_matrix_init(&inverse);
1460 inverse.d[0] = dx / r;
1461 inverse.d[4] = dy / r;
1462 inverse.d[1] = -inverse.d[4];
1463 inverse.d[5] = inverse.d[0];
1464 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01001465
1466 weston_matrix_init(&rotate->rotation);
1467 rotate->rotation.d[0] = dx / r;
1468 rotate->rotation.d[4] = -dy / r;
1469 rotate->rotation.d[1] = -rotate->rotation.d[4];
1470 rotate->rotation.d[5] = rotate->rotation.d[0];
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05001471 } else {
1472 weston_matrix_init(&surface->rotation.rotation);
1473 weston_matrix_init(&rotate->rotation);
1474 }
1475
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001476 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
Pekka Paalanen460099f2012-01-20 16:48:25 +02001477}
1478
1479static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001480activate(struct desktop_shell *shell, struct weston_surface *es,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001481 struct weston_input_device *device)
Kristian Høgsberg75840622011-09-06 13:48:16 -04001482{
Alex Wu21858432012-04-01 20:13:08 +08001483 struct weston_surface *surf, *prev;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001484
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001485 weston_surface_activate(es, device);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001486
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001487 switch (get_shell_surface_type(es)) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001488 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001489 case SHELL_SURFACE_PANEL:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001490 case SHELL_SURFACE_LOCK:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001491 break;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001492
Pekka Paalanen77346a62011-11-30 16:26:35 +02001493 case SHELL_SURFACE_SCREENSAVER:
1494 /* always below lock surface */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001495 if (shell->lock_surface)
1496 weston_surface_restack(es,
1497 &shell->lock_surface->surface->layer_link);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001498 break;
Alex Wu4539b082012-03-01 12:57:46 +08001499 case SHELL_SURFACE_FULLSCREEN:
1500 /* should on top of panels */
Alex Wu21858432012-04-01 20:13:08 +08001501 shell_stack_fullscreen(get_shell_surface(es));
Alex Wu4539b082012-03-01 12:57:46 +08001502 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001503 default:
Alex Wu21858432012-04-01 20:13:08 +08001504 /* move the fullscreen surfaces down into the toplevel layer */
1505 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1506 wl_list_for_each_reverse_safe(surf,
1507 prev,
1508 &shell->fullscreen_layer.surface_list,
1509 layer_link)
1510 weston_surface_restack(surf,
1511 &shell->toplevel_layer.surface_list);
1512 }
1513
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001514 weston_surface_restack(es,
1515 &shell->toplevel_layer.surface_list);
1516 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001517 }
1518}
1519
Alex Wu21858432012-04-01 20:13:08 +08001520/* no-op func for checking black surface */
1521static void
1522black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1523{
1524}
1525
1526static bool
1527is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1528{
1529 if (es->configure == black_surface_configure) {
1530 if (fs_surface)
1531 *fs_surface = (struct weston_surface *)es->private;
1532 return true;
1533 }
1534 return false;
1535}
1536
Kristian Høgsberg75840622011-09-06 13:48:16 -04001537static void
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001538click_to_activate_binding(struct wl_input_device *device,
Alex Wu4539b082012-03-01 12:57:46 +08001539 uint32_t time, uint32_t key,
Scott Moreau6a3633d2012-03-20 08:47:59 -06001540 uint32_t button, uint32_t axis, int32_t state, void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001541{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001542 struct weston_input_device *wd = (struct weston_input_device *) device;
Tiago Vignattibe143262012-04-16 17:31:41 +03001543 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001544 struct weston_surface *focus;
Alex Wu4539b082012-03-01 12:57:46 +08001545 struct weston_surface *upper;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001546
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001547 focus = (struct weston_surface *) device->pointer_focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08001548 if (!focus)
1549 return;
1550
Alex Wu21858432012-04-01 20:13:08 +08001551 if (is_black_surface(focus, &upper))
Alex Wu4539b082012-03-01 12:57:46 +08001552 focus = upper;
Alex Wu4539b082012-03-01 12:57:46 +08001553
Alex Wu9c35e6b2012-03-05 14:13:13 +08001554 if (state && device->pointer_grab == &device->default_pointer_grab)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001555 activate(shell, focus, wd);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05001556}
1557
1558static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001559lock(struct wl_listener *listener, void *data)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001560{
Tiago Vignattibe143262012-04-16 17:31:41 +03001561 struct desktop_shell *shell =
1562 container_of(listener, struct desktop_shell, lock_listener);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001563 struct weston_input_device *device;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001564 struct shell_surface *shsurf;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001565 struct weston_output *output;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001566
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001567 if (shell->locked) {
1568 wl_list_for_each(output, &shell->compositor->output_list, link)
1569 /* TODO: find a way to jump to other DPMS levels */
1570 if (output->set_dpms)
1571 output->set_dpms(output, WESTON_DPMS_STANDBY);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001572 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001573 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001574
1575 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001576
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001577 /* Hide all surfaces by removing the fullscreen, panel and
1578 * toplevel layers. This way nothing else can show or receive
1579 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001580
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001581 wl_list_remove(&shell->panel_layer.link);
1582 wl_list_remove(&shell->toplevel_layer.link);
1583 wl_list_remove(&shell->fullscreen_layer.link);
1584 wl_list_insert(&shell->compositor->cursor_layer.link,
1585 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001586
Pekka Paalanen77346a62011-11-30 16:26:35 +02001587 launch_screensaver(shell);
1588
1589 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1590 show_screensaver(shell, shsurf);
1591
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001592 if (!wl_list_empty(&shell->screensaver.surfaces)) {
Pekka Paalanen7296e792011-12-07 16:22:00 +02001593 shell->compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001594 weston_compositor_wake(shell->compositor);
1595 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001596 }
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001597
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001598 /* reset pointer foci */
Kristian Høgsbergaa6019e2012-03-11 16:35:16 -04001599 weston_compositor_schedule_repaint(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001600
1601 /* reset keyboard foci */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001602 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1603 wl_input_device_set_keyboard_focus(&device->input_device,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001604 NULL);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001605 }
1606
1607 /* TODO: disable bindings that should not work while locked. */
1608
1609 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001610}
1611
1612static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001613unlock(struct wl_listener *listener, void *data)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001614{
Tiago Vignattibe143262012-04-16 17:31:41 +03001615 struct desktop_shell *shell =
1616 container_of(listener, struct desktop_shell, unlock_listener);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001617
Pekka Paalanend81c2162011-11-16 13:47:34 +02001618 if (!shell->locked || shell->lock_surface) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001619 weston_compositor_wake(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001620 return;
1621 }
1622
1623 /* If desktop-shell client has gone away, unlock immediately. */
1624 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001625 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001626 return;
1627 }
1628
1629 if (shell->prepare_event_sent)
1630 return;
1631
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001632 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001633 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001634}
1635
1636static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001637center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02001638{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001639 struct weston_mode *mode = output->current;
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001640 GLfloat x = (mode->width - surface->geometry.width) / 2;
1641 GLfloat y = (mode->height - surface->geometry.height) / 2;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001642
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001643 weston_surface_set_position(surface, output->x + x, output->y + y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001644}
1645
1646static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001647map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001648 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04001649{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001650 struct weston_compositor *compositor = shell->compositor;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001651 struct shell_surface *shsurf;
1652 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05001653 struct weston_surface *parent;
Juan Zhao96879df2012-02-07 08:45:41 +08001654 int panel_height = 0;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001655
Pekka Paalanen77346a62011-11-30 16:26:35 +02001656 shsurf = get_shell_surface(surface);
1657 if (shsurf)
1658 surface_type = shsurf->type;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001659
Pekka Paalanen60921e52012-01-25 15:55:43 +02001660 surface->geometry.width = width;
1661 surface->geometry.height = height;
1662 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001663
1664 /* initial positioning, see also configure() */
1665 switch (surface_type) {
1666 case SHELL_SURFACE_TOPLEVEL:
Pekka Paalanen8fb8d3b2012-02-13 13:03:59 +02001667 weston_surface_set_position(surface, 10 + random() % 400,
1668 10 + random() % 400);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001669 break;
1670 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001671 center_on_output(surface, shsurf->fullscreen_output);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001672 break;
Alex Wu4539b082012-03-01 12:57:46 +08001673 case SHELL_SURFACE_FULLSCREEN:
1674 shell_map_fullscreen(shsurf);
1675 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001676 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001677 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08001678 panel_height = get_output_panel_height(shell,surface->output);
1679 weston_surface_set_position(surface, surface->output->x,
1680 surface->output->y + panel_height);
1681 break;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001682 case SHELL_SURFACE_LOCK:
1683 center_on_output(surface, get_default_output(compositor));
1684 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02001685 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04001686 shell_map_popup(shsurf);
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02001687 case SHELL_SURFACE_NONE:
1688 weston_surface_set_position(surface,
1689 surface->geometry.x + sx,
1690 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02001691 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001692 default:
1693 ;
1694 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04001695
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001696 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02001697 switch (surface_type) {
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001698 case SHELL_SURFACE_BACKGROUND:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001699 /* background always visible, at the bottom */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001700 wl_list_insert(&shell->background_layer.surface_list,
1701 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001702 break;
1703 case SHELL_SURFACE_PANEL:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001704 /* panel always on top, hidden while locked */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001705 wl_list_insert(&shell->panel_layer.surface_list,
1706 &surface->layer_link);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001707 break;
1708 case SHELL_SURFACE_LOCK:
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02001709 /* lock surface always visible, on top */
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001710 wl_list_insert(&shell->lock_layer.surface_list,
1711 &surface->layer_link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001712 weston_compositor_wake(compositor);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001713 break;
1714 case SHELL_SURFACE_SCREENSAVER:
1715 /* If locked, show it. */
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001716 if (shell->locked) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02001717 show_screensaver(shell, shsurf);
Pekka Paalanen7296e792011-12-07 16:22:00 +02001718 compositor->idle_time = shell->screensaver.duration;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001719 weston_compositor_wake(compositor);
Pekka Paalanenbce2d3f2011-12-02 13:07:27 +02001720 if (!shell->lock_surface)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001721 compositor->state = WESTON_COMPOSITOR_IDLE;
Pekka Paalanenbaeb6a12011-12-01 16:23:57 +02001722 }
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001723 break;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05001724 case SHELL_SURFACE_POPUP:
1725 case SHELL_SURFACE_TRANSIENT:
1726 parent = shsurf->parent->surface;
1727 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
1728 break;
Alex Wu4539b082012-03-01 12:57:46 +08001729 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02001730 case SHELL_SURFACE_NONE:
1731 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02001732 default:
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001733 wl_list_insert(&shell->toplevel_layer.surface_list,
1734 &surface->layer_link);
1735 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02001736 }
1737
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02001738 if (surface_type != SHELL_SURFACE_NONE) {
1739 weston_surface_assign_output(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02001740 if (surface_type == SHELL_SURFACE_MAXIMIZED)
1741 surface->output = shsurf->output;
1742 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001743
Juan Zhao7bb92f02011-12-15 11:31:51 -05001744 switch (surface_type) {
1745 case SHELL_SURFACE_TOPLEVEL:
1746 case SHELL_SURFACE_TRANSIENT:
1747 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08001748 case SHELL_SURFACE_MAXIMIZED:
Juan Zhao7bb92f02011-12-15 11:31:51 -05001749 if (!shell->locked)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001750 activate(shell, surface,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001751 (struct weston_input_device *)
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001752 compositor->input_device);
Juan Zhao7bb92f02011-12-15 11:31:51 -05001753 break;
1754 default:
1755 break;
1756 }
1757
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05001758 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001759 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001760}
1761
1762static void
Tiago Vignattibe143262012-04-16 17:31:41 +03001763configure(struct desktop_shell *shell, struct weston_surface *surface,
Pekka Paalanenddae03c2012-02-06 14:54:20 +02001764 GLfloat x, GLfloat y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001765{
Pekka Paalanen77346a62011-11-30 16:26:35 +02001766 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
Alex Wu4539b082012-03-01 12:57:46 +08001767 enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001768 struct shell_surface *shsurf;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001769
Pekka Paalanen77346a62011-11-30 16:26:35 +02001770 shsurf = get_shell_surface(surface);
1771 if (shsurf)
1772 surface_type = shsurf->type;
1773
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001774 surface->geometry.x = x;
1775 surface->geometry.y = y;
Pekka Paalanen60921e52012-01-25 15:55:43 +02001776 surface->geometry.width = width;
1777 surface->geometry.height = height;
1778 surface->geometry.dirty = 1;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001779
1780 switch (surface_type) {
1781 case SHELL_SURFACE_SCREENSAVER:
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001782 center_on_output(surface, shsurf->fullscreen_output);
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001783 break;
Alex Wu4539b082012-03-01 12:57:46 +08001784 case SHELL_SURFACE_FULLSCREEN:
1785 shell_configure_fullscreen(shsurf);
1786 if (prev_surface_type != SHELL_SURFACE_FULLSCREEN)
1787 shell_stack_fullscreen(shsurf);
1788 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001789 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08001790 /* setting x, y and using configure to change that geometry */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001791 surface->geometry.x = surface->output->x;
1792 surface->geometry.y = surface->output->y +
1793 get_output_panel_height(shell,surface->output);
Juan Zhao96879df2012-02-07 08:45:41 +08001794 break;
Alex Wu4539b082012-03-01 12:57:46 +08001795 case SHELL_SURFACE_TOPLEVEL:
1796 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05001797 default:
1798 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001799 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05001800
Alex Wu4539b082012-03-01 12:57:46 +08001801 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05001802 if (surface->output) {
Pekka Paalanenf07cb5d2012-02-10 13:34:36 +02001803 weston_surface_assign_output(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02001804
1805 if (surface_type == SHELL_SURFACE_SCREENSAVER)
1806 surface->output = shsurf->output;
Juan Zhao96879df2012-02-07 08:45:41 +08001807 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
1808 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001809 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04001810}
1811
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001812static void
1813shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1814{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001815 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03001816 struct desktop_shell *shell = shsurf->shell;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001817
1818 if (!weston_surface_is_mapped(es)) {
1819 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001820 } else if (shsurf->force_configure || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001821 es->geometry.width != es->buffer->width ||
1822 es->geometry.height != es->buffer->height) {
1823 GLfloat from_x, from_y;
1824 GLfloat to_x, to_y;
1825
1826 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
1827 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
1828 configure(shell, es,
1829 es->geometry.x + to_x - from_x,
1830 es->geometry.y + to_y - from_y,
1831 es->buffer->width, es->buffer->height);
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03001832 shsurf->force_configure = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03001833 }
1834}
1835
Tiago Vignattibe143262012-04-16 17:31:41 +03001836static int launch_desktop_shell_process(struct desktop_shell *shell);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001837
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001838static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001839desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001840{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001841 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03001842 struct desktop_shell *shell =
1843 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001844
1845 shell->child.process.pid = 0;
1846 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001847
1848 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
1849 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05001850 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02001851 shell->child.deathstamp = time;
1852 shell->child.deathcount = 0;
1853 }
1854
1855 shell->child.deathcount++;
1856 if (shell->child.deathcount > 5) {
1857 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
1858 return;
1859 }
1860
1861 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
1862 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001863}
1864
1865static int
Tiago Vignattibe143262012-04-16 17:31:41 +03001866launch_desktop_shell_process(struct desktop_shell *shell)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001867{
Kristian Høgsberg9724b512012-01-03 14:35:49 -05001868 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001869
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001870 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02001871 &shell->child.process,
1872 shell_exe,
1873 desktop_shell_sigchld);
1874
1875 if (!shell->child.client)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001876 return -1;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02001877 return 0;
1878}
1879
1880static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001881bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1882{
Tiago Vignattibe143262012-04-16 17:31:41 +03001883 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001884
1885 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001886 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001887}
1888
Kristian Høgsberg75840622011-09-06 13:48:16 -04001889static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001890unbind_desktop_shell(struct wl_resource *resource)
1891{
Tiago Vignattibe143262012-04-16 17:31:41 +03001892 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001893
1894 if (shell->locked)
1895 resume_desktop(shell);
1896
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001897 shell->child.desktop_shell = NULL;
1898 shell->prepare_event_sent = false;
1899 free(resource);
1900}
1901
1902static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04001903bind_desktop_shell(struct wl_client *client,
1904 void *data, uint32_t version, uint32_t id)
1905{
Tiago Vignattibe143262012-04-16 17:31:41 +03001906 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001907 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04001908
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001909 resource = wl_client_add_object(client, &desktop_shell_interface,
1910 &desktop_shell_implementation,
1911 id, shell);
1912
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001913 if (client == shell->child.client) {
1914 resource->destroy = unbind_desktop_shell;
1915 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001916 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001917 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02001918
1919 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1920 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001921 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04001922}
1923
Pekka Paalanen6e168112011-11-24 11:34:05 +02001924static void
1925screensaver_set_surface(struct wl_client *client,
1926 struct wl_resource *resource,
1927 struct wl_resource *shell_surface_resource,
1928 struct wl_resource *output_resource)
1929{
Tiago Vignattibe143262012-04-16 17:31:41 +03001930 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001931 struct shell_surface *surface = shell_surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001932 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001933
Pekka Paalanen98262232011-12-01 10:42:22 +02001934 if (reset_shell_surface_type(surface))
1935 return;
1936
Pekka Paalanen77346a62011-11-30 16:26:35 +02001937 surface->type = SHELL_SURFACE_SCREENSAVER;
1938
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -05001939 surface->fullscreen_output = output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001940 surface->output = output;
1941 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001942}
1943
1944static const struct screensaver_interface screensaver_implementation = {
1945 screensaver_set_surface
1946};
1947
1948static void
1949unbind_screensaver(struct wl_resource *resource)
1950{
Tiago Vignattibe143262012-04-16 17:31:41 +03001951 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001952
Pekka Paalanen77346a62011-11-30 16:26:35 +02001953 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001954 free(resource);
1955}
1956
1957static void
1958bind_screensaver(struct wl_client *client,
1959 void *data, uint32_t version, uint32_t id)
1960{
Tiago Vignattibe143262012-04-16 17:31:41 +03001961 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001962 struct wl_resource *resource;
1963
1964 resource = wl_client_add_object(client, &screensaver_interface,
1965 &screensaver_implementation,
1966 id, shell);
1967
Pekka Paalanen77346a62011-11-30 16:26:35 +02001968 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02001969 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02001970 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02001971 return;
1972 }
1973
1974 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1975 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001976 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02001977}
1978
Kristian Høgsberg07045392012-02-19 18:52:44 -05001979struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03001980 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05001981 struct weston_surface *current;
1982 struct wl_listener listener;
1983 struct wl_keyboard_grab grab;
1984};
1985
1986static void
1987switcher_next(struct switcher *switcher)
1988{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001989 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05001990 struct weston_surface *surface;
1991 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04001992 struct shell_surface *shsurf;
Kristian Høgsberg07045392012-02-19 18:52:44 -05001993
1994 wl_list_for_each(surface, &compositor->surface_list, link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05001995 switch (get_shell_surface_type(surface)) {
1996 case SHELL_SURFACE_TOPLEVEL:
1997 case SHELL_SURFACE_FULLSCREEN:
1998 case SHELL_SURFACE_MAXIMIZED:
1999 if (first == NULL)
2000 first = surface;
2001 if (prev == switcher->current)
2002 next = surface;
2003 prev = surface;
2004 surface->alpha = 64;
Kristian Høgsbergcacb7cd2012-02-28 09:20:21 -05002005 surface->geometry.dirty = 1;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002006 weston_surface_damage(surface);
2007 break;
2008 default:
2009 break;
2010 }
Alex Wu1659daa2012-04-01 20:13:09 +08002011
2012 if (is_black_surface(surface, NULL)) {
2013 surface->alpha = 64;
2014 surface->geometry.dirty = 1;
2015 weston_surface_damage(surface);
2016 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05002017 }
2018
2019 if (next == NULL)
2020 next = first;
2021
Alex Wu07b26062012-03-12 16:06:01 +08002022 if (next == NULL)
2023 return;
2024
Kristian Høgsberg07045392012-02-19 18:52:44 -05002025 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002026 wl_signal_add(&next->surface.resource.destroy_signal,
2027 &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002028
2029 switcher->current = next;
2030 next->alpha = 255;
Alex Wu1659daa2012-04-01 20:13:09 +08002031
Kristian Høgsberg32e56862012-04-02 22:18:58 -04002032 shsurf = get_shell_surface(switcher->current);
2033 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
2034 shsurf->fullscreen.black_surface->alpha = 255;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002035}
2036
2037static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002038switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002039{
2040 struct switcher *switcher =
2041 container_of(listener, struct switcher, listener);
2042
2043 switcher_next(switcher);
2044}
2045
2046static void
2047switcher_destroy(struct switcher *switcher, uint32_t time)
2048{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002049 struct weston_compositor *compositor = switcher->shell->compositor;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002050 struct weston_surface *surface;
2051 struct weston_input_device *device =
2052 (struct weston_input_device *) switcher->grab.input_device;
2053
2054 wl_list_for_each(surface, &compositor->surface_list, link) {
2055 surface->alpha = 255;
2056 weston_surface_damage(surface);
2057 }
2058
Alex Wu07b26062012-03-12 16:06:01 +08002059 if (switcher->current)
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002060 activate(switcher->shell, switcher->current, device);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002061 wl_list_remove(&switcher->listener.link);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002062 wl_input_device_end_keyboard_grab(&device->input_device);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002063 free(switcher);
2064}
2065
2066static void
2067switcher_key(struct wl_keyboard_grab *grab,
2068 uint32_t time, uint32_t key, int32_t state)
2069{
2070 struct switcher *switcher = container_of(grab, struct switcher, grab);
2071 struct weston_input_device *device =
2072 (struct weston_input_device *) grab->input_device;
2073
2074 if ((device->modifier_state & MODIFIER_SUPER) == 0) {
2075 switcher_destroy(switcher, time);
2076 } else if (key == KEY_TAB && state) {
2077 switcher_next(switcher);
2078 }
2079};
2080
2081static const struct wl_keyboard_grab_interface switcher_grab = {
2082 switcher_key
2083};
2084
2085static void
2086switcher_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002087 uint32_t key, uint32_t button, uint32_t axis,
2088 int32_t state, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05002089{
Tiago Vignattibe143262012-04-16 17:31:41 +03002090 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002091 struct switcher *switcher;
2092
2093 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002094 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002095 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002096 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05002097 wl_list_init(&switcher->listener.link);
2098
2099 switcher->grab.interface = &switcher_grab;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002100 wl_input_device_start_keyboard_grab(device, &switcher->grab);
2101 wl_input_device_set_keyboard_focus(device, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002102 switcher_next(switcher);
2103}
2104
Pekka Paalanen3c647232011-12-22 13:43:43 +02002105static void
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002106backlight_binding(struct wl_input_device *device, uint32_t time,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002107 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002108{
2109 struct weston_compositor *compositor = data;
2110 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002111 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002112
2113 /* TODO: we're limiting to simple use cases, where we assume just
2114 * control on the primary display. We'd have to extend later if we
2115 * ever get support for setting backlights on random desktop LCD
2116 * panels though */
2117 output = get_default_output(compositor);
2118 if (!output)
2119 return;
2120
2121 if (!output->set_backlight)
2122 return;
2123
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002124 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2125 backlight_new = output->backlight_current - 25;
2126 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2127 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002128
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03002129 if (backlight_new < 5)
2130 backlight_new = 5;
2131 if (backlight_new > 255)
2132 backlight_new = 255;
2133
2134 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002135 output->set_backlight(output, output->backlight_current);
2136}
2137
2138static void
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002139debug_repaint_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, int32_t state, void *data)
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002141{
Tiago Vignattibe143262012-04-16 17:31:41 +03002142 struct desktop_shell *shell = data;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002143 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05002144 struct weston_surface *surface;
2145
2146 if (shell->debug_repaint_surface) {
2147 weston_surface_destroy(shell->debug_repaint_surface);
2148 shell->debug_repaint_surface = NULL;
2149 } else {
2150 surface = weston_surface_create(compositor);
2151 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2152 weston_surface_configure(surface, 0, 0, 8192, 8192);
2153 wl_list_insert(&compositor->fade_layer.surface_list,
2154 &surface->layer_link);
2155 weston_surface_assign_output(surface);
2156 pixman_region32_init(&surface->input);
2157
2158 /* Here's the dirty little trick that makes the
2159 * repaint debugging work: we force an
2160 * update_transform first to update dependent state
2161 * and clear the geometry.dirty bit. Then we clear
2162 * the surface damage so it only gets repainted
2163 * piecewise as we repaint other things. */
2164
2165 weston_surface_update_transform(surface);
2166 pixman_region32_fini(&surface->damage);
2167 pixman_region32_init(&surface->damage);
2168 shell->debug_repaint_surface = surface;
2169 }
2170}
2171
2172static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002173shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02002174{
Tiago Vignattibe143262012-04-16 17:31:41 +03002175 struct desktop_shell *shell =
2176 container_of(listener, struct desktop_shell, destroy_listener);
Pekka Paalanen3c647232011-12-22 13:43:43 +02002177
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02002178 if (shell->child.client)
2179 wl_client_destroy(shell->child.client);
2180
Pekka Paalanen3c647232011-12-22 13:43:43 +02002181 free(shell->screensaver.path);
2182 free(shell);
2183}
2184
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002185int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002186shell_init(struct weston_compositor *ec);
Kristian Høgsberg6c709a32011-05-06 14:52:41 -04002187
Kristian Høgsberg1c562182011-05-02 22:09:20 -04002188WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002189shell_init(struct weston_compositor *ec)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002190{
Tiago Vignattibe143262012-04-16 17:31:41 +03002191 struct desktop_shell *shell;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002192
2193 shell = malloc(sizeof *shell);
2194 if (shell == NULL)
2195 return -1;
2196
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04002197 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002198 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002199
2200 shell->destroy_listener.notify = shell_destroy;
2201 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2202 shell->lock_listener.notify = lock;
2203 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2204 shell->unlock_listener.notify = unlock;
2205 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002206
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002207 wl_list_init(&shell->backgrounds);
2208 wl_list_init(&shell->panels);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002209 wl_list_init(&shell->screensaver.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002210
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002211 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2212 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2213 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2214 weston_layer_init(&shell->background_layer,
2215 &shell->toplevel_layer.link);
2216 wl_list_init(&shell->lock_layer.surface_list);
2217
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05002218 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002219
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04002220 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2221 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002222 return -1;
2223
Kristian Høgsberg75840622011-09-06 13:48:16 -04002224 if (wl_display_add_global(ec->wl_display,
2225 &desktop_shell_interface,
2226 shell, bind_desktop_shell) == NULL)
2227 return -1;
2228
Pekka Paalanen6e168112011-11-24 11:34:05 +02002229 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2230 shell, bind_screensaver) == NULL)
2231 return -1;
2232
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05002233 shell->child.deathstamp = weston_compositor_get_time();
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02002234 if (launch_desktop_shell_process(shell) != 0)
2235 return -1;
2236
Scott Moreau6a3633d2012-03-20 08:47:59 -06002237 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, MODIFIER_SUPER,
2238 move_binding, shell);
2239 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, MODIFIER_SUPER,
2240 resize_binding, shell);
2241 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
2242 MODIFIER_CTRL | MODIFIER_ALT,
2243 terminate_binding, ec);
2244 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002245 click_to_activate_binding, shell);
Scott Moreau1b45a792012-03-22 10:58:23 -06002246 weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002247 MODIFIER_SUPER | MODIFIER_ALT,
2248 surface_opacity_binding, NULL);
2249 weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
Scott Moreau1b45a792012-03-22 10:58:23 -06002250 MODIFIER_SUPER, zoom_binding, NULL);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002251 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0,
Scott Moreau6a3633d2012-03-20 08:47:59 -06002252 MODIFIER_SUPER | MODIFIER_ALT,
2253 rotate_binding, NULL);
2254 weston_compositor_add_binding(ec, KEY_TAB, 0, 0, MODIFIER_SUPER,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002255 switcher_binding, shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05002256
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002257 /* brightness */
Scott Moreau6a3633d2012-03-20 08:47:59 -06002258 weston_compositor_add_binding(ec, KEY_F9, 0, 0, MODIFIER_CTRL,
2259 backlight_binding, ec);
2260 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
2261 backlight_binding, ec);
2262 weston_compositor_add_binding(ec, KEY_F10, 0, 0, MODIFIER_CTRL,
2263 backlight_binding, ec);
2264 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
2265 backlight_binding, ec);
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002266
Scott Moreau6a3633d2012-03-20 08:47:59 -06002267 weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, MODIFIER_SUPER,
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002268 debug_repaint_binding, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002269
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002270 return 0;
2271}