blob: 316cfdcc5718590da16c49e976725bc22ade42a6 [file] [log] [blame]
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001/*
Kristian Høgsberg07045392012-02-19 18:52:44 -05002 * Copyright © 2010-2012 Intel Corporation
Pekka Paalanend581a8f2012-01-27 16:25:16 +02003 * Copyright © 2011-2012 Collabora, Ltd.
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#include <stdlib.h>
Kristian Høgsberg75840622011-09-06 13:48:16 -040025#include <stdio.h>
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020026#include <stdbool.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050027#include <string.h>
28#include <unistd.h>
Kristian Høgsberg07937562011-04-12 17:25:42 -040029#include <linux/input.h>
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020030#include <assert.h>
Pekka Paalanen18027e52011-12-02 16:31:49 +020031#include <signal.h>
Pekka Paalanen460099f2012-01-20 16:48:25 +020032#include <math.h>
Kristian Høgsberg92a57db2012-05-26 13:41:06 -040033#include <sys/types.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050034
Pekka Paalanen50719bc2011-11-22 14:18:50 +020035#include <wayland-server.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050036#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040037#include "desktop-shell-server-protocol.h"
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +010038#include "input-method-server-protocol.h"
Jonas Ådahle9d22502012-08-29 22:13:01 +020039#include "workspaces-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020040#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050041
Jonas Ådahle3cddce2012-06-13 00:01:22 +020042#define DEFAULT_NUM_WORKSPACES 1
Jonas Ådahl62fcd042012-06-13 00:01:23 +020043#define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
Jonas Ådahle3cddce2012-06-13 00:01:22 +020044
Juan Zhaoe10d2792012-04-25 19:09:52 +080045enum animation_type {
46 ANIMATION_NONE,
47
48 ANIMATION_ZOOM,
49 ANIMATION_FADE
50};
51
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +020052enum fade_type {
53 FADE_IN,
54 FADE_OUT
55};
56
Jonas Ådahl04769742012-06-13 00:01:24 +020057struct focus_state {
58 struct weston_seat *seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -040059 struct workspace *ws;
Jonas Ådahl04769742012-06-13 00:01:24 +020060 struct weston_surface *keyboard_focus;
61 struct wl_list link;
62 struct wl_listener seat_destroy_listener;
63 struct wl_listener surface_destroy_listener;
64};
65
Jonas Ådahle3cddce2012-06-13 00:01:22 +020066struct workspace {
67 struct weston_layer layer;
Jonas Ådahl04769742012-06-13 00:01:24 +020068
69 struct wl_list focus_list;
70 struct wl_listener seat_destroyed_listener;
Jonas Ådahle3cddce2012-06-13 00:01:22 +020071};
72
Philipp Brüschweiler88013572012-08-06 13:44:42 +020073struct input_panel_surface {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +010074 struct wl_resource resource;
75
76 struct desktop_shell *shell;
77
Philipp Brüschweiler88013572012-08-06 13:44:42 +020078 struct wl_list link;
79 struct weston_surface *surface;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +010080 struct wl_listener surface_destroy_listener;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +020081
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +020082 struct weston_output *output;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +020083 uint32_t panel;
Philipp Brüschweiler88013572012-08-06 13:44:42 +020084};
85
Tiago Vignattibe143262012-04-16 17:31:41 +030086struct desktop_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050087 struct weston_compositor *compositor;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -040088
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +020089 struct wl_listener idle_listener;
90 struct wl_listener wake_listener;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -040091 struct wl_listener destroy_listener;
Jan Arne Petersen42feced2012-06-21 21:52:17 +020092 struct wl_listener show_input_panel_listener;
93 struct wl_listener hide_input_panel_listener;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +020094 struct wl_listener update_input_panel_listener;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +020095
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050096 struct weston_layer fullscreen_layer;
97 struct weston_layer panel_layer;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -050098 struct weston_layer background_layer;
99 struct weston_layer lock_layer;
Philipp Brüschweiler711fda82012-08-09 18:50:43 +0200100 struct weston_layer input_panel_layer;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500101
Kristian Høgsbergd56bd902012-06-05 09:58:51 -0400102 struct wl_listener pointer_focus_listener;
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300103 struct weston_surface *grab_surface;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -0400104
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200105 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500106 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200107 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200108 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +0200109
110 unsigned deathcount;
111 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200112 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200113
114 bool locked;
Philipp Brüschweiler711fda82012-08-09 18:50:43 +0200115 bool showing_input_panels;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200116 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200117
Jan Arne Petersen14da96b2013-04-18 16:47:28 +0200118 struct {
119 struct weston_surface *surface;
120 pixman_box32_t cursor_rectangle;
121 } text_input;
122
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400123 struct weston_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500124 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100125
Pekka Paalanen77346a62011-11-30 16:26:35 +0200126 struct {
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200127 struct wl_array array;
128 unsigned int current;
129 unsigned int num;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200130
Jonas Ådahle9d22502012-08-29 22:13:01 +0200131 struct wl_list client_list;
132
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200133 struct weston_animation animation;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200134 struct wl_list anim_sticky_list;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200135 int anim_dir;
136 uint32_t anim_timestamp;
137 double anim_current;
138 struct workspace *anim_from;
139 struct workspace *anim_to;
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200140 } workspaces;
141
142 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +0200143 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200144 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200145 struct wl_resource *binding;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500146 struct weston_process process;
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +0200147 struct wl_event_source *timer;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200148 } screensaver;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -0500149
Jan Arne Petersen42feced2012-06-21 21:52:17 +0200150 struct {
151 struct wl_resource *binding;
152 struct wl_list surfaces;
153 } input_panel;
154
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +0200155 struct {
156 struct weston_surface *surface;
157 struct weston_surface_animation *animation;
158 enum fade_type type;
159 } fade;
160
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300161 uint32_t binding_modifier;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800162 enum animation_type win_animation_type;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400163};
164
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500165enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +0200166 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500167 SHELL_SURFACE_TOPLEVEL,
168 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500169 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +0800170 SHELL_SURFACE_MAXIMIZED,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500171 SHELL_SURFACE_POPUP
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200172};
173
Scott Moreauff1db4a2012-04-17 19:06:18 -0600174struct ping_timer {
175 struct wl_event_source *source;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600176 uint32_t serial;
177};
178
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200179struct shell_surface {
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200180 struct wl_resource resource;
181
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500182 struct weston_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200183 struct wl_listener surface_destroy_listener;
Kristian Høgsberg8150b192012-06-27 10:22:58 -0400184 struct weston_surface *parent;
Tiago Vignattibe143262012-04-16 17:31:41 +0300185 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200186
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400187 enum shell_surface_type type, next_type;
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400188 char *title, *class;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500189 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800190 bool saved_position_valid;
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800191 bool saved_rotation_valid;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600192 int unresponsive;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100193
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500194 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200195 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500196 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200197 } rotation;
198
199 struct {
Giulio Camuffo5085a752013-03-25 21:42:45 +0100200 struct wl_list grab_link;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500201 int32_t x, y;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100202 struct shell_seat *shseat;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400203 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500204 } popup;
205
Alex Wu4539b082012-03-01 12:57:46 +0800206 struct {
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300207 int32_t x, y;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400208 uint32_t flags;
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300209 } transient;
210
211 struct {
Alex Wu4539b082012-03-01 12:57:46 +0800212 enum wl_shell_surface_fullscreen_method type;
213 struct weston_transform transform; /* matrix from x, y */
214 uint32_t framerate;
215 struct weston_surface *black_surface;
216 } fullscreen;
217
Scott Moreauff1db4a2012-04-17 19:06:18 -0600218 struct ping_timer *ping_timer;
219
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200220 struct weston_transform workspace_transform;
221
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500222 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500223 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100224 struct wl_list link;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400225
226 const struct weston_shell_client *client;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200227};
228
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300229struct shell_grab {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400230 struct weston_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300231 struct shell_surface *shsurf;
232 struct wl_listener shsurf_destroy_listener;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400233 struct weston_pointer *pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300234};
235
236struct weston_move_grab {
237 struct shell_grab base;
Daniel Stone103db7f2012-05-08 17:17:55 +0100238 wl_fixed_t dx, dy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500239};
240
Pekka Paalanen460099f2012-01-20 16:48:25 +0200241struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300242 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500243 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200244 struct {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200245 float x;
246 float y;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200247 } center;
248};
249
Giulio Camuffo5085a752013-03-25 21:42:45 +0100250struct shell_seat {
251 struct weston_seat *seat;
252 struct wl_listener seat_destroy_listener;
253
254 struct {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400255 struct weston_pointer_grab grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100256 struct wl_list surfaces_list;
257 struct wl_client *client;
258 int32_t initial_up;
259 } popup_grab;
260};
261
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400262static void
263activate(struct desktop_shell *shell, struct weston_surface *es,
264 struct weston_seat *seat);
265
266static struct workspace *
267get_current_workspace(struct desktop_shell *shell);
268
Alex Wubd3354b2012-04-17 17:20:49 +0800269static struct shell_surface *
270get_shell_surface(struct weston_surface *surface);
271
272static struct desktop_shell *
273shell_surface_get_shell(struct shell_surface *shsurf);
274
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500275static void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400276surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500277
Alex Wubd3354b2012-04-17 17:20:49 +0800278static bool
279shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
280{
281 struct desktop_shell *shell;
282 struct weston_surface *top_fs_es;
283
284 shell = shell_surface_get_shell(shsurf);
Quentin Glidicc0d79ce2013-01-29 14:16:13 +0100285
Alex Wubd3354b2012-04-17 17:20:49 +0800286 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
287 return false;
288
289 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
Quentin Glidicc0d79ce2013-01-29 14:16:13 +0100290 struct weston_surface,
Alex Wubd3354b2012-04-17 17:20:49 +0800291 layer_link);
292 return (shsurf == get_shell_surface(top_fs_es));
293}
294
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500295static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400296destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300297{
298 struct shell_grab *grab;
299
300 grab = container_of(listener, struct shell_grab,
301 shsurf_destroy_listener);
302
303 grab->shsurf = NULL;
304}
305
306static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400307popup_grab_end(struct weston_pointer *pointer);
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400308
309static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300310shell_grab_start(struct shell_grab *grab,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400311 const struct weston_pointer_grab_interface *interface,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300312 struct shell_surface *shsurf,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400313 struct weston_pointer *pointer,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300314 enum desktop_shell_cursor cursor)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300315{
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300316 struct desktop_shell *shell = shsurf->shell;
317
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400318 popup_grab_end(pointer);
319
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300320 grab->grab.interface = interface;
321 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400322 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
323 wl_signal_add(&shsurf->resource.destroy_signal,
324 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300325
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300326 grab->pointer = pointer;
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300327
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400328 weston_pointer_start_grab(pointer, &grab->grab);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300329 desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor);
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400330 weston_pointer_set_focus(pointer, shell->grab_surface,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400331 wl_fixed_from_int(0), wl_fixed_from_int(0));
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300332}
333
334static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300335shell_grab_end(struct shell_grab *grab)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300336{
Kristian Høgsberg47b5dca2012-06-07 18:08:04 -0400337 if (grab->shsurf)
338 wl_list_remove(&grab->shsurf_destroy_listener.link);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300339
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400340 weston_pointer_end_grab(grab->pointer);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300341}
342
343static void
Alex Wu4539b082012-03-01 12:57:46 +0800344center_on_output(struct weston_surface *surface,
345 struct weston_output *output);
346
Daniel Stone496ca172012-05-30 16:31:42 +0100347static enum weston_keyboard_modifier
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300348get_modifier(char *modifier)
349{
350 if (!modifier)
351 return MODIFIER_SUPER;
352
353 if (!strcmp("ctrl", modifier))
354 return MODIFIER_CTRL;
355 else if (!strcmp("alt", modifier))
356 return MODIFIER_ALT;
357 else if (!strcmp("super", modifier))
358 return MODIFIER_SUPER;
359 else
360 return MODIFIER_SUPER;
361}
362
Juan Zhaoe10d2792012-04-25 19:09:52 +0800363static enum animation_type
364get_animation_type(char *animation)
365{
366 if (!animation)
367 return ANIMATION_NONE;
368
369 if (!strcmp("zoom", animation))
370 return ANIMATION_ZOOM;
371 else if (!strcmp("fade", animation))
372 return ANIMATION_FADE;
373 else
374 return ANIMATION_NONE;
375}
376
Alex Wu4539b082012-03-01 12:57:46 +0800377static void
Ossama Othmana50e6e42013-05-14 09:48:26 -0700378shell_configuration(struct desktop_shell *shell, int config_fd)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200379{
Pekka Paalanen7296e792011-12-07 16:22:00 +0200380 char *path = NULL;
381 int duration = 60;
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200382 unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300383 char *modifier = NULL;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800384 char *win_animation = NULL;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200385
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400386 struct config_key shell_keys[] = {
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300387 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
Juan Zhaoe10d2792012-04-25 19:09:52 +0800388 { "animation", CONFIG_KEY_STRING, &win_animation},
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200389 { "num-workspaces",
390 CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200391 };
392
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400393 struct config_key saver_keys[] = {
394 { "path", CONFIG_KEY_STRING, &path },
395 { "duration", CONFIG_KEY_INTEGER, &duration },
396 };
397
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200398 struct config_section cs[] = {
Kristian Høgsberga4e8b332012-04-20 16:48:21 -0400399 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200400 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
401 };
402
Ossama Othmana50e6e42013-05-14 09:48:26 -0700403 parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200404
Pekka Paalanen7296e792011-12-07 16:22:00 +0200405 shell->screensaver.path = path;
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +0200406 shell->screensaver.duration = duration * 1000;
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300407 shell->binding_modifier = get_modifier(modifier);
Juan Zhaoe10d2792012-04-25 19:09:52 +0800408 shell->win_animation_type = get_animation_type(win_animation);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200409 shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1;
410}
411
412static void
Jonas Ådahl04769742012-06-13 00:01:24 +0200413focus_state_destroy(struct focus_state *state)
414{
415 wl_list_remove(&state->seat_destroy_listener.link);
416 wl_list_remove(&state->surface_destroy_listener.link);
417 free(state);
418}
419
420static void
421focus_state_seat_destroy(struct wl_listener *listener, void *data)
422{
423 struct focus_state *state = container_of(listener,
424 struct focus_state,
425 seat_destroy_listener);
426
427 wl_list_remove(&state->link);
428 focus_state_destroy(state);
429}
430
431static void
432focus_state_surface_destroy(struct wl_listener *listener, void *data)
433{
434 struct focus_state *state = container_of(listener,
435 struct focus_state,
Kristian Høgsbergb8e0d0f2012-07-31 10:30:26 -0400436 surface_destroy_listener);
Kristian Høgsberge3778222012-07-31 17:29:30 -0400437 struct desktop_shell *shell;
Pekka Paalanen01388e22013-04-25 13:57:44 +0300438 struct weston_surface *main_surface;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400439 struct weston_surface *surface, *next;
Jonas Ådahl04769742012-06-13 00:01:24 +0200440
Pekka Paalanen01388e22013-04-25 13:57:44 +0300441 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
442
Kristian Høgsberge3778222012-07-31 17:29:30 -0400443 next = NULL;
444 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
Pekka Paalanen01388e22013-04-25 13:57:44 +0300445 if (surface == main_surface)
Kristian Høgsberge3778222012-07-31 17:29:30 -0400446 continue;
447
448 next = surface;
449 break;
450 }
451
Pekka Paalanen01388e22013-04-25 13:57:44 +0300452 /* if the focus was a sub-surface, activate its main surface */
453 if (main_surface != state->keyboard_focus)
454 next = main_surface;
455
Kristian Høgsberge3778222012-07-31 17:29:30 -0400456 if (next) {
457 shell = state->seat->compositor->shell_interface.shell;
458 activate(shell, next, state->seat);
459 } else {
460 wl_list_remove(&state->link);
461 focus_state_destroy(state);
462 }
Jonas Ådahl04769742012-06-13 00:01:24 +0200463}
464
465static struct focus_state *
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400466focus_state_create(struct weston_seat *seat, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200467{
Jonas Ådahl04769742012-06-13 00:01:24 +0200468 struct focus_state *state;
Jonas Ådahl04769742012-06-13 00:01:24 +0200469
470 state = malloc(sizeof *state);
471 if (state == NULL)
472 return NULL;
473
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400474 state->ws = ws;
Jonas Ådahl04769742012-06-13 00:01:24 +0200475 state->seat = seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400476 wl_list_insert(&ws->focus_list, &state->link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200477
478 state->seat_destroy_listener.notify = focus_state_seat_destroy;
479 state->surface_destroy_listener.notify = focus_state_surface_destroy;
Kristian Høgsberg49124542013-05-06 22:27:40 -0400480 wl_signal_add(&seat->destroy_signal,
Jonas Ådahl04769742012-06-13 00:01:24 +0200481 &state->seat_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400482 wl_list_init(&state->surface_destroy_listener.link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200483
484 return state;
485}
486
Jonas Ådahl8538b222012-08-29 22:13:03 +0200487static struct focus_state *
488ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
489{
490 struct workspace *ws = get_current_workspace(shell);
491 struct focus_state *state;
492
493 wl_list_for_each(state, &ws->focus_list, link)
494 if (state->seat == seat)
495 break;
496
497 if (&state->link == &ws->focus_list)
498 state = focus_state_create(seat, ws);
499
500 return state;
501}
502
Jonas Ådahl04769742012-06-13 00:01:24 +0200503static void
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400504restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200505{
506 struct focus_state *state, *next;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400507 struct weston_surface *surface;
Jonas Ådahl04769742012-06-13 00:01:24 +0200508
509 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400510 surface = state->keyboard_focus;
Jonas Ådahl56899442012-08-29 22:12:59 +0200511
Kristian Høgsberge3148752013-05-06 23:19:49 -0400512 weston_keyboard_set_focus(state->seat->keyboard, surface);
Jonas Ådahl04769742012-06-13 00:01:24 +0200513 }
514}
515
516static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200517replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
518 struct weston_seat *seat)
519{
520 struct focus_state *state;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400521 struct weston_surface *surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200522
523 wl_list_for_each(state, &ws->focus_list, link) {
524 if (state->seat == seat) {
Kristian Høgsberge3148752013-05-06 23:19:49 -0400525 surface = seat->keyboard->focus;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200526 state->keyboard_focus =
527 (struct weston_surface *) surface;
528 return;
529 }
530 }
531}
532
533static void
534drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
535 struct weston_surface *surface)
536{
537 struct focus_state *state;
538
539 wl_list_for_each(state, &ws->focus_list, link)
540 if (state->keyboard_focus == surface)
541 state->keyboard_focus = NULL;
542}
543
544static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200545workspace_destroy(struct workspace *ws)
546{
Jonas Ådahl04769742012-06-13 00:01:24 +0200547 struct focus_state *state, *next;
548
549 wl_list_for_each_safe(state, next, &ws->focus_list, link)
550 focus_state_destroy(state);
551
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200552 free(ws);
553}
554
Jonas Ådahl04769742012-06-13 00:01:24 +0200555static void
556seat_destroyed(struct wl_listener *listener, void *data)
557{
558 struct weston_seat *seat = data;
559 struct focus_state *state, *next;
560 struct workspace *ws = container_of(listener,
561 struct workspace,
562 seat_destroyed_listener);
563
564 wl_list_for_each_safe(state, next, &ws->focus_list, link)
565 if (state->seat == seat)
566 wl_list_remove(&state->link);
567}
568
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200569static struct workspace *
570workspace_create(void)
571{
572 struct workspace *ws = malloc(sizeof *ws);
573 if (ws == NULL)
574 return NULL;
575
576 weston_layer_init(&ws->layer, NULL);
577
Jonas Ådahl04769742012-06-13 00:01:24 +0200578 wl_list_init(&ws->focus_list);
579 wl_list_init(&ws->seat_destroyed_listener.link);
580 ws->seat_destroyed_listener.notify = seat_destroyed;
581
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200582 return ws;
583}
584
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200585static int
586workspace_is_empty(struct workspace *ws)
587{
588 return wl_list_empty(&ws->layer.surface_list);
589}
590
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200591static struct workspace *
592get_workspace(struct desktop_shell *shell, unsigned int index)
593{
594 struct workspace **pws = shell->workspaces.array.data;
Philipp Brüschweiler067abf62012-09-01 16:03:05 +0200595 assert(index < shell->workspaces.num);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200596 pws += index;
597 return *pws;
598}
599
600static struct workspace *
601get_current_workspace(struct desktop_shell *shell)
602{
603 return get_workspace(shell, shell->workspaces.current);
604}
605
606static void
607activate_workspace(struct desktop_shell *shell, unsigned int index)
608{
609 struct workspace *ws;
610
611 ws = get_workspace(shell, index);
612 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
613
614 shell->workspaces.current = index;
615}
616
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200617static unsigned int
618get_output_height(struct weston_output *output)
619{
620 return abs(output->region.extents.y1 - output->region.extents.y2);
621}
622
623static void
624surface_translate(struct weston_surface *surface, double d)
625{
626 struct shell_surface *shsurf = get_shell_surface(surface);
627 struct weston_transform *transform;
628
629 transform = &shsurf->workspace_transform;
630 if (wl_list_empty(&transform->link))
631 wl_list_insert(surface->geometry.transformation_list.prev,
632 &shsurf->workspace_transform.link);
633
634 weston_matrix_init(&shsurf->workspace_transform.matrix);
635 weston_matrix_translate(&shsurf->workspace_transform.matrix,
636 0.0, d, 0.0);
Pekka Paalanenc3ce7382013-03-08 14:56:49 +0200637 weston_surface_geometry_dirty(surface);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200638}
639
640static void
641workspace_translate_out(struct workspace *ws, double fraction)
642{
643 struct weston_surface *surface;
644 unsigned int height;
645 double d;
646
647 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
648 height = get_output_height(surface->output);
649 d = height * fraction;
650
651 surface_translate(surface, d);
652 }
653}
654
655static void
656workspace_translate_in(struct workspace *ws, double fraction)
657{
658 struct weston_surface *surface;
659 unsigned int height;
660 double d;
661
662 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
663 height = get_output_height(surface->output);
664
665 if (fraction > 0)
666 d = -(height - height * fraction);
667 else
668 d = height + height * fraction;
669
670 surface_translate(surface, d);
671 }
672}
673
674static void
Jonas Ådahle9d22502012-08-29 22:13:01 +0200675broadcast_current_workspace_state(struct desktop_shell *shell)
676{
677 struct wl_resource *resource;
678
679 wl_list_for_each(resource, &shell->workspaces.client_list, link)
680 workspace_manager_send_state(resource,
681 shell->workspaces.current,
682 shell->workspaces.num);
683}
684
685static void
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200686reverse_workspace_change_animation(struct desktop_shell *shell,
687 unsigned int index,
688 struct workspace *from,
689 struct workspace *to)
690{
691 shell->workspaces.current = index;
692
693 shell->workspaces.anim_to = to;
694 shell->workspaces.anim_from = from;
695 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
696 shell->workspaces.anim_timestamp = 0;
697
Scott Moreau4272e632012-08-13 09:58:41 -0600698 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200699}
700
701static void
702workspace_deactivate_transforms(struct workspace *ws)
703{
704 struct weston_surface *surface;
705 struct shell_surface *shsurf;
706
707 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
708 shsurf = get_shell_surface(surface);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200709 if (!wl_list_empty(&shsurf->workspace_transform.link)) {
710 wl_list_remove(&shsurf->workspace_transform.link);
711 wl_list_init(&shsurf->workspace_transform.link);
712 }
Pekka Paalanenc3ce7382013-03-08 14:56:49 +0200713 weston_surface_geometry_dirty(surface);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200714 }
715}
716
717static void
718finish_workspace_change_animation(struct desktop_shell *shell,
719 struct workspace *from,
720 struct workspace *to)
721{
Scott Moreau4272e632012-08-13 09:58:41 -0600722 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200723
724 wl_list_remove(&shell->workspaces.animation.link);
725 workspace_deactivate_transforms(from);
726 workspace_deactivate_transforms(to);
727 shell->workspaces.anim_to = NULL;
728
729 wl_list_remove(&shell->workspaces.anim_from->layer.link);
730}
731
732static void
733animate_workspace_change_frame(struct weston_animation *animation,
734 struct weston_output *output, uint32_t msecs)
735{
736 struct desktop_shell *shell =
737 container_of(animation, struct desktop_shell,
738 workspaces.animation);
739 struct workspace *from = shell->workspaces.anim_from;
740 struct workspace *to = shell->workspaces.anim_to;
741 uint32_t t;
742 double x, y;
743
744 if (workspace_is_empty(from) && workspace_is_empty(to)) {
745 finish_workspace_change_animation(shell, from, to);
746 return;
747 }
748
749 if (shell->workspaces.anim_timestamp == 0) {
750 if (shell->workspaces.anim_current == 0.0)
751 shell->workspaces.anim_timestamp = msecs;
752 else
753 shell->workspaces.anim_timestamp =
754 msecs -
755 /* Invers of movement function 'y' below. */
756 (asin(1.0 - shell->workspaces.anim_current) *
757 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
758 M_2_PI);
759 }
760
761 t = msecs - shell->workspaces.anim_timestamp;
762
763 /*
764 * x = [0, π/2]
765 * y(x) = sin(x)
766 */
767 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
768 y = sin(x);
769
770 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
Scott Moreau4272e632012-08-13 09:58:41 -0600771 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200772
773 workspace_translate_out(from, shell->workspaces.anim_dir * y);
774 workspace_translate_in(to, shell->workspaces.anim_dir * y);
775 shell->workspaces.anim_current = y;
776
Scott Moreau4272e632012-08-13 09:58:41 -0600777 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200778 }
Jonas Ådahl04769742012-06-13 00:01:24 +0200779 else
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200780 finish_workspace_change_animation(shell, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200781}
782
783static void
784animate_workspace_change(struct desktop_shell *shell,
785 unsigned int index,
786 struct workspace *from,
787 struct workspace *to)
788{
789 struct weston_output *output;
790
791 int dir;
792
793 if (index > shell->workspaces.current)
794 dir = -1;
795 else
796 dir = 1;
797
798 shell->workspaces.current = index;
799
800 shell->workspaces.anim_dir = dir;
801 shell->workspaces.anim_from = from;
802 shell->workspaces.anim_to = to;
803 shell->workspaces.anim_current = 0.0;
804 shell->workspaces.anim_timestamp = 0;
805
806 output = container_of(shell->compositor->output_list.next,
807 struct weston_output, link);
808 wl_list_insert(&output->animation_list,
809 &shell->workspaces.animation.link);
810
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200811 wl_list_insert(from->layer.link.prev, &to->layer.link);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200812
813 workspace_translate_in(to, 0);
814
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400815 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +0200816
Scott Moreau4272e632012-08-13 09:58:41 -0600817 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200818}
819
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200820static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200821update_workspace(struct desktop_shell *shell, unsigned int index,
822 struct workspace *from, struct workspace *to)
823{
824 shell->workspaces.current = index;
825 wl_list_insert(&from->layer.link, &to->layer.link);
826 wl_list_remove(&from->layer.link);
827}
828
829static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200830change_workspace(struct desktop_shell *shell, unsigned int index)
831{
832 struct workspace *from;
833 struct workspace *to;
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200834
835 if (index == shell->workspaces.current)
836 return;
837
838 /* Don't change workspace when there is any fullscreen surfaces. */
839 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
840 return;
841
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200842 from = get_current_workspace(shell);
843 to = get_workspace(shell, index);
844
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200845 if (shell->workspaces.anim_from == to &&
846 shell->workspaces.anim_to == from) {
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200847 restore_focus_state(shell, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200848 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +0200849 broadcast_current_workspace_state(shell);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200850 return;
851 }
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200852
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200853 if (shell->workspaces.anim_to != NULL)
854 finish_workspace_change_animation(shell,
855 shell->workspaces.anim_from,
856 shell->workspaces.anim_to);
857
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200858 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +0200859
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200860 if (workspace_is_empty(to) && workspace_is_empty(from))
861 update_workspace(shell, index, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200862 else
863 animate_workspace_change(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +0200864
865 broadcast_current_workspace_state(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200866}
867
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200868static bool
869workspace_has_only(struct workspace *ws, struct weston_surface *surface)
870{
871 struct wl_list *list = &ws->layer.surface_list;
872 struct wl_list *e;
873
874 if (wl_list_empty(list))
875 return false;
876
877 e = list->next;
878
879 if (e->next != list)
880 return false;
881
882 return container_of(e, struct weston_surface, layer_link) == surface;
883}
884
885static void
Jonas Ådahle9d22502012-08-29 22:13:01 +0200886move_surface_to_workspace(struct desktop_shell *shell,
887 struct weston_surface *surface,
888 uint32_t workspace)
889{
890 struct workspace *from;
891 struct workspace *to;
892 struct weston_seat *seat;
Pekka Paalanen01388e22013-04-25 13:57:44 +0300893 struct weston_surface *focus;
894
895 assert(weston_surface_get_main_surface(surface) == surface);
Jonas Ådahle9d22502012-08-29 22:13:01 +0200896
897 if (workspace == shell->workspaces.current)
898 return;
899
Philipp Brüschweiler067abf62012-09-01 16:03:05 +0200900 if (workspace >= shell->workspaces.num)
901 workspace = shell->workspaces.num - 1;
902
Jonas Ådahle9d22502012-08-29 22:13:01 +0200903 from = get_current_workspace(shell);
904 to = get_workspace(shell, workspace);
905
906 wl_list_remove(&surface->layer_link);
907 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
908
909 drop_focus_state(shell, from, surface);
Pekka Paalanen01388e22013-04-25 13:57:44 +0300910 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
911 if (!seat->keyboard)
912 continue;
913
914 focus = weston_surface_get_main_surface(seat->keyboard->focus);
915 if (focus == surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -0400916 weston_keyboard_set_focus(seat->keyboard, NULL);
Pekka Paalanen01388e22013-04-25 13:57:44 +0300917 }
Jonas Ådahle9d22502012-08-29 22:13:01 +0200918
919 weston_surface_damage_below(surface);
920}
921
922static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200923take_surface_to_workspace_by_seat(struct desktop_shell *shell,
Kristian Høgsberge3148752013-05-06 23:19:49 -0400924 struct weston_seat *seat,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200925 unsigned int index)
926{
Pekka Paalanen01388e22013-04-25 13:57:44 +0300927 struct weston_surface *surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200928 struct shell_surface *shsurf;
929 struct workspace *from;
930 struct workspace *to;
Jonas Ådahl8538b222012-08-29 22:13:03 +0200931 struct focus_state *state;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200932
Pekka Paalanen01388e22013-04-25 13:57:44 +0300933 surface = weston_surface_get_main_surface(seat->keyboard->focus);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200934 if (surface == NULL ||
935 index == shell->workspaces.current)
936 return;
937
938 from = get_current_workspace(shell);
939 to = get_workspace(shell, index);
940
941 wl_list_remove(&surface->layer_link);
942 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
943
Jonas Ådahle9d22502012-08-29 22:13:01 +0200944 replace_focus_state(shell, to, seat);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200945 drop_focus_state(shell, from, surface);
946
947 if (shell->workspaces.anim_from == to &&
948 shell->workspaces.anim_to == from) {
Jonas Ådahle9d22502012-08-29 22:13:01 +0200949 wl_list_remove(&to->layer.link);
950 wl_list_insert(from->layer.link.prev, &to->layer.link);
951
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200952 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +0200953 broadcast_current_workspace_state(shell);
954
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200955 return;
956 }
957
958 if (shell->workspaces.anim_to != NULL)
959 finish_workspace_change_animation(shell,
960 shell->workspaces.anim_from,
961 shell->workspaces.anim_to);
962
963 if (workspace_is_empty(from) &&
964 workspace_has_only(to, surface))
965 update_workspace(shell, index, from, to);
966 else {
967 shsurf = get_shell_surface(surface);
968 if (wl_list_empty(&shsurf->workspace_transform.link))
969 wl_list_insert(&shell->workspaces.anim_sticky_list,
970 &shsurf->workspace_transform.link);
971
972 animate_workspace_change(shell, index, from, to);
973 }
Jonas Ådahle9d22502012-08-29 22:13:01 +0200974
975 broadcast_current_workspace_state(shell);
Jonas Ådahl8538b222012-08-29 22:13:03 +0200976
977 state = ensure_focus_state(shell, seat);
978 if (state != NULL)
979 state->keyboard_focus = surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +0200980}
981
982static void
983workspace_manager_move_surface(struct wl_client *client,
984 struct wl_resource *resource,
985 struct wl_resource *surface_resource,
986 uint32_t workspace)
987{
988 struct desktop_shell *shell = resource->data;
989 struct weston_surface *surface =
990 (struct weston_surface *) surface_resource;
Pekka Paalanen01388e22013-04-25 13:57:44 +0300991 struct weston_surface *main_surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +0200992
Pekka Paalanen01388e22013-04-25 13:57:44 +0300993 main_surface = weston_surface_get_main_surface(surface);
994 move_surface_to_workspace(shell, main_surface, workspace);
Jonas Ådahle9d22502012-08-29 22:13:01 +0200995}
996
997static const struct workspace_manager_interface workspace_manager_implementation = {
998 workspace_manager_move_surface,
999};
1000
1001static void
1002unbind_resource(struct wl_resource *resource)
1003{
1004 wl_list_remove(&resource->link);
1005 free(resource);
1006}
1007
1008static void
1009bind_workspace_manager(struct wl_client *client,
1010 void *data, uint32_t version, uint32_t id)
1011{
1012 struct desktop_shell *shell = data;
1013 struct wl_resource *resource;
1014
1015 resource = wl_client_add_object(client, &workspace_manager_interface,
1016 &workspace_manager_implementation,
1017 id, shell);
1018
1019 if (resource == NULL) {
1020 weston_log("couldn't add workspace manager object");
1021 return;
1022 }
1023
1024 resource->destroy = unbind_resource;
1025 wl_list_insert(&shell->workspaces.client_list, &resource->link);
1026
1027 workspace_manager_send_state(resource,
1028 shell->workspaces.current,
1029 shell->workspaces.num);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001030}
1031
Pekka Paalanen56cdea92011-11-23 16:14:12 +02001032static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001033noop_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001034{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001035}
1036
1037static void
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001038move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001039{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001040 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001041 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001042 struct shell_surface *shsurf = move->base.shsurf;
1043 struct weston_surface *es;
Daniel Stone37816df2012-05-16 18:45:18 +01001044 int dx = wl_fixed_to_int(pointer->x + move->dx);
1045 int dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001046
1047 if (!shsurf)
1048 return;
1049
1050 es = shsurf->surface;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001051
Daniel Stone103db7f2012-05-08 17:17:55 +01001052 weston_surface_configure(es, dx, dy,
Pekka Paalanen60921e52012-01-25 15:55:43 +02001053 es->geometry.width, es->geometry.height);
Kristian Høgsberg6c6fb992012-06-21 12:06:22 -04001054
1055 weston_compositor_schedule_repaint(es->compositor);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001056}
1057
1058static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001059move_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001060 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001061{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001062 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1063 grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001064 struct weston_pointer *pointer = grab->pointer;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001065 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001066
Daniel Stone4dbadb12012-05-30 16:31:51 +01001067 if (pointer->button_count == 0 &&
1068 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001069 shell_grab_end(shell_grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001070 free(grab);
1071 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001072}
1073
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001074static const struct weston_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001075 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001076 move_grab_motion,
1077 move_grab_button,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001078};
1079
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001080static int
Kristian Høgsberge3148752013-05-06 23:19:49 -04001081surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001082{
1083 struct weston_move_grab *move;
1084
1085 if (!shsurf)
1086 return -1;
1087
1088 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1089 return 0;
1090
1091 move = malloc(sizeof *move);
1092 if (!move)
1093 return -1;
1094
1095 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001096 seat->pointer->grab_x;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001097 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001098 seat->pointer->grab_y;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001099
1100 shell_grab_start(&move->base, &move_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001101 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001102
1103 return 0;
1104}
1105
1106static void
1107shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1108 struct wl_resource *seat_resource, uint32_t serial)
1109{
Kristian Høgsberge3148752013-05-06 23:19:49 -04001110 struct weston_seat *seat = seat_resource->data;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001111 struct shell_surface *shsurf = resource->data;
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001112 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001113
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001114 surface = weston_surface_get_main_surface(seat->pointer->focus);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001115 if (seat->pointer->button_count == 0 ||
1116 seat->pointer->grab_serial != serial ||
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001117 surface != shsurf->surface)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001118 return;
1119
Kristian Høgsberge3148752013-05-06 23:19:49 -04001120 if (surface_move(shsurf, seat) < 0)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001121 wl_resource_post_no_memory(resource);
1122}
1123
1124struct weston_resize_grab {
1125 struct shell_grab base;
1126 uint32_t edges;
1127 int32_t width, height;
1128};
1129
1130static void
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001131resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001132{
1133 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001134 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001135 struct shell_surface *shsurf = resize->base.shsurf;
1136 int32_t width, height;
1137 wl_fixed_t from_x, from_y;
1138 wl_fixed_t to_x, to_y;
1139
1140 if (!shsurf)
1141 return;
1142
1143 weston_surface_from_global_fixed(shsurf->surface,
1144 pointer->grab_x, pointer->grab_y,
1145 &from_x, &from_y);
1146 weston_surface_from_global_fixed(shsurf->surface,
1147 pointer->x, pointer->y, &to_x, &to_y);
1148
1149 width = resize->width;
1150 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1151 width += wl_fixed_to_int(from_x - to_x);
1152 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1153 width += wl_fixed_to_int(to_x - from_x);
1154 }
1155
1156 height = resize->height;
1157 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1158 height += wl_fixed_to_int(from_y - to_y);
1159 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1160 height += wl_fixed_to_int(to_y - from_y);
1161 }
1162
1163 shsurf->client->send_configure(shsurf->surface,
1164 resize->edges, width, height);
1165}
1166
1167static void
1168send_configure(struct weston_surface *surface,
1169 uint32_t edges, int32_t width, int32_t height)
1170{
1171 struct shell_surface *shsurf = get_shell_surface(surface);
1172
1173 wl_shell_surface_send_configure(&shsurf->resource,
1174 edges, width, height);
1175}
1176
1177static const struct weston_shell_client shell_client = {
1178 send_configure
1179};
1180
1181static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001182resize_grab_button(struct weston_pointer_grab *grab,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001183 uint32_t time, uint32_t button, uint32_t state_w)
1184{
1185 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001186 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001187 enum wl_pointer_button_state state = state_w;
1188
1189 if (pointer->button_count == 0 &&
1190 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1191 shell_grab_end(&resize->base);
1192 free(grab);
1193 }
1194}
1195
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001196static const struct weston_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001197 noop_grab_focus,
1198 resize_grab_motion,
1199 resize_grab_button,
1200};
1201
Giulio Camuffob8366642013-04-25 13:57:46 +03001202/*
1203 * Returns the bounding box of a surface and all its sub-surfaces,
1204 * in the surface coordinates system. */
1205static void
1206surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1207 int32_t *y, int32_t *w, int32_t *h) {
1208 pixman_region32_t region;
1209 pixman_box32_t *box;
1210 struct weston_subsurface *subsurface;
1211
1212 pixman_region32_init_rect(&region, 0, 0,
1213 surface->geometry.width,
1214 surface->geometry.height);
1215
1216 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1217 pixman_region32_union_rect(&region, &region,
1218 subsurface->position.x,
1219 subsurface->position.y,
1220 subsurface->surface->geometry.width,
1221 subsurface->surface->geometry.height);
1222 }
1223
1224 box = pixman_region32_extents(&region);
1225 if (x)
1226 *x = box->x1;
1227 if (y)
1228 *y = box->y1;
1229 if (w)
1230 *w = box->x2 - box->x1;
1231 if (h)
1232 *h = box->y2 - box->y1;
1233
1234 pixman_region32_fini(&region);
1235}
1236
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001237static int
1238surface_resize(struct shell_surface *shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001239 struct weston_seat *seat, uint32_t edges)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001240{
1241 struct weston_resize_grab *resize;
1242
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01001243 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1244 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001245 return 0;
1246
1247 if (edges == 0 || edges > 15 ||
1248 (edges & 3) == 3 || (edges & 12) == 12)
1249 return 0;
1250
1251 resize = malloc(sizeof *resize);
1252 if (!resize)
1253 return -1;
1254
1255 resize->edges = edges;
Giulio Camuffob8366642013-04-25 13:57:46 +03001256 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1257 &resize->width, &resize->height);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001258
1259 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001260 seat->pointer, edges);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001261
1262 return 0;
1263}
1264
1265static void
1266shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1267 struct wl_resource *seat_resource, uint32_t serial,
1268 uint32_t edges)
1269{
Kristian Høgsberge3148752013-05-06 23:19:49 -04001270 struct weston_seat *seat = seat_resource->data;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001271 struct shell_surface *shsurf = resource->data;
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001272 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001273
1274 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1275 return;
1276
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001277 surface = weston_surface_get_main_surface(seat->pointer->focus);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001278 if (seat->pointer->button_count == 0 ||
1279 seat->pointer->grab_serial != serial ||
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001280 surface != shsurf->surface)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001281 return;
1282
Kristian Høgsberge3148752013-05-06 23:19:49 -04001283 if (surface_resize(shsurf, seat, edges) < 0)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001284 wl_resource_post_no_memory(resource);
1285}
1286
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001287static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001288busy_cursor_grab_focus(struct weston_pointer_grab *base)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001289{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001290 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001291 struct weston_pointer *pointer = base->pointer;
1292 struct weston_surface *surface;
1293 wl_fixed_t sx, sy;
1294
1295 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1296 pointer->x, pointer->y,
1297 &sx, &sy);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001298
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001299 if (grab->shsurf->surface != surface) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001300 shell_grab_end(grab);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001301 free(grab);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001302 }
1303}
1304
1305static void
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001306busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001307{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001308}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001309
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001310static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001311busy_cursor_grab_button(struct weston_pointer_grab *base,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001312 uint32_t time, uint32_t button, uint32_t state)
1313{
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001314 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001315 struct shell_surface *shsurf = grab->shsurf;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001316 struct weston_seat *seat = grab->grab.pointer->seat;
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001317
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001318 if (shsurf && button == BTN_LEFT && state) {
1319 activate(shsurf->shell, shsurf->surface, seat);
1320 surface_move(shsurf, seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05001321 } else if (shsurf && button == BTN_RIGHT && state) {
1322 activate(shsurf->shell, shsurf->surface, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001323 surface_rotate(shsurf, seat);
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001324 }
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001325}
1326
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001327static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001328 busy_cursor_grab_focus,
1329 busy_cursor_grab_motion,
1330 busy_cursor_grab_button,
1331};
1332
1333static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001334set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001335{
1336 struct shell_grab *grab;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001337
1338 grab = malloc(sizeof *grab);
1339 if (!grab)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001340 return;
1341
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001342 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1343 DESKTOP_SHELL_CURSOR_BUSY);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001344}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001345
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001346static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001347end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001348{
1349 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1350
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001351 if (grab->grab.interface == &busy_cursor_grab_interface &&
1352 grab->shsurf == shsurf) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001353 shell_grab_end(grab);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001354 free(grab);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001355 }
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001356}
1357
Scott Moreau9521d5e2012-04-19 13:06:17 -06001358static void
1359ping_timer_destroy(struct shell_surface *shsurf)
1360{
1361 if (!shsurf || !shsurf->ping_timer)
1362 return;
1363
1364 if (shsurf->ping_timer->source)
1365 wl_event_source_remove(shsurf->ping_timer->source);
1366
1367 free(shsurf->ping_timer);
1368 shsurf->ping_timer = NULL;
1369}
1370
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001371static int
Scott Moreauff1db4a2012-04-17 19:06:18 -06001372ping_timeout_handler(void *data)
1373{
1374 struct shell_surface *shsurf = data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001375 struct weston_seat *seat;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001376
Scott Moreau9521d5e2012-04-19 13:06:17 -06001377 /* Client is not responding */
1378 shsurf->unresponsive = 1;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001379
1380 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04001381 if (seat->pointer->focus == shsurf->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001382 set_busy_cursor(shsurf, seat->pointer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001383
1384 return 1;
1385}
1386
1387static void
1388ping_handler(struct weston_surface *surface, uint32_t serial)
1389{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04001390 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001391 struct wl_event_loop *loop;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001392 int ping_timeout = 200;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001393
1394 if (!shsurf)
1395 return;
Kristian Høgsbergca535c12012-04-21 23:20:07 -04001396 if (!shsurf->resource.client)
1397 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001398
Ander Conselvan de Oliveiraeac9a462012-07-16 14:15:48 +03001399 if (shsurf->surface == shsurf->shell->grab_surface)
1400 return;
1401
Scott Moreauff1db4a2012-04-17 19:06:18 -06001402 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +03001403 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001404 if (!shsurf->ping_timer)
1405 return;
1406
1407 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001408 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1409 shsurf->ping_timer->source =
1410 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1411 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1412
1413 wl_shell_surface_send_ping(&shsurf->resource, serial);
1414 }
1415}
1416
1417static void
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001418handle_pointer_focus(struct wl_listener *listener, void *data)
1419{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001420 struct weston_pointer *pointer = data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001421 struct weston_surface *surface =
1422 (struct weston_surface *) pointer->focus;
1423 struct weston_compositor *compositor;
1424 struct shell_surface *shsurf;
1425 uint32_t serial;
1426
1427 if (!surface)
1428 return;
1429
1430 compositor = surface->compositor;
1431 shsurf = get_shell_surface(surface);
1432
Pekka Paalanen4e1f2ff2012-06-06 16:59:45 +03001433 if (shsurf && shsurf->unresponsive) {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001434 set_busy_cursor(shsurf, pointer);
1435 } else {
1436 serial = wl_display_next_serial(compositor->wl_display);
1437 ping_handler(surface, serial);
1438 }
1439}
1440
1441static void
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001442create_pointer_focus_listener(struct weston_seat *seat)
1443{
1444 struct wl_listener *listener;
1445
Kristian Høgsberge3148752013-05-06 23:19:49 -04001446 if (!seat->pointer)
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001447 return;
1448
1449 listener = malloc(sizeof *listener);
1450 listener->notify = handle_pointer_focus;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001451 wl_signal_add(&seat->pointer->focus_signal, listener);
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001452}
1453
1454static void
Scott Moreauff1db4a2012-04-17 19:06:18 -06001455shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1456 uint32_t serial)
1457{
1458 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001459 struct weston_seat *seat;
1460 struct weston_compositor *ec = shsurf->surface->compositor;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001461
Kristian Høgsberg92374e12012-08-11 22:39:12 -04001462 if (shsurf->ping_timer == NULL)
1463 /* Just ignore unsolicited pong. */
1464 return;
1465
Scott Moreauff1db4a2012-04-17 19:06:18 -06001466 if (shsurf->ping_timer->serial == serial) {
Scott Moreauff1db4a2012-04-17 19:06:18 -06001467 shsurf->unresponsive = 0;
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001468 wl_list_for_each(seat, &ec->seat_list, link)
1469 end_busy_cursor(shsurf, seat->pointer);
Scott Moreau9521d5e2012-04-19 13:06:17 -06001470 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001471 }
1472}
1473
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001474static void
1475shell_surface_set_title(struct wl_client *client,
1476 struct wl_resource *resource, const char *title)
1477{
1478 struct shell_surface *shsurf = resource->data;
1479
1480 free(shsurf->title);
1481 shsurf->title = strdup(title);
1482}
1483
1484static void
1485shell_surface_set_class(struct wl_client *client,
1486 struct wl_resource *resource, const char *class)
1487{
1488 struct shell_surface *shsurf = resource->data;
1489
1490 free(shsurf->class);
1491 shsurf->class = strdup(class);
1492}
1493
Juan Zhao96879df2012-02-07 08:45:41 +08001494static struct weston_output *
1495get_default_output(struct weston_compositor *compositor)
1496{
1497 return container_of(compositor->output_list.next,
1498 struct weston_output, link);
1499}
1500
Alex Wu4539b082012-03-01 12:57:46 +08001501static void
1502shell_unset_fullscreen(struct shell_surface *shsurf)
1503{
Rafal Mielniczuk3e3862c2012-10-07 20:25:36 +02001504 struct workspace *ws;
Alex Wu4539b082012-03-01 12:57:46 +08001505 /* undo all fullscreen things here */
Alex Wubd3354b2012-04-17 17:20:49 +08001506 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1507 shell_surface_is_top_fullscreen(shsurf)) {
1508 weston_output_switch_mode(shsurf->fullscreen_output,
1509 shsurf->fullscreen_output->origin);
1510 }
Alex Wu4539b082012-03-01 12:57:46 +08001511 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1512 shsurf->fullscreen.framerate = 0;
1513 wl_list_remove(&shsurf->fullscreen.transform.link);
1514 wl_list_init(&shsurf->fullscreen.transform.link);
Alex Wubd3354b2012-04-17 17:20:49 +08001515 if (shsurf->fullscreen.black_surface)
1516 weston_surface_destroy(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +08001517 shsurf->fullscreen.black_surface = NULL;
1518 shsurf->fullscreen_output = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08001519 weston_surface_set_position(shsurf->surface,
1520 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08001521 if (shsurf->saved_rotation_valid) {
1522 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1523 &shsurf->rotation.transform.link);
1524 shsurf->saved_rotation_valid = false;
1525 }
Rafal Mielniczuk3e3862c2012-10-07 20:25:36 +02001526
1527 ws = get_current_workspace(shsurf->shell);
1528 wl_list_remove(&shsurf->surface->layer_link);
1529 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +08001530}
1531
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01001532static void
1533shell_unset_maximized(struct shell_surface *shsurf)
1534{
1535 struct workspace *ws;
1536 /* undo all maximized things here */
1537 shsurf->output = get_default_output(shsurf->surface->compositor);
1538 weston_surface_set_position(shsurf->surface,
1539 shsurf->saved_x,
1540 shsurf->saved_y);
1541
1542 if (shsurf->saved_rotation_valid) {
1543 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1544 &shsurf->rotation.transform.link);
1545 shsurf->saved_rotation_valid = false;
1546 }
1547
1548 ws = get_current_workspace(shsurf->shell);
1549 wl_list_remove(&shsurf->surface->layer_link);
1550 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1551}
1552
Pekka Paalanen98262232011-12-01 10:42:22 +02001553static int
1554reset_shell_surface_type(struct shell_surface *surface)
1555{
1556 switch (surface->type) {
1557 case SHELL_SURFACE_FULLSCREEN:
Alex Wu4539b082012-03-01 12:57:46 +08001558 shell_unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +02001559 break;
Juan Zhao96879df2012-02-07 08:45:41 +08001560 case SHELL_SURFACE_MAXIMIZED:
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01001561 shell_unset_maximized(surface);
Juan Zhao96879df2012-02-07 08:45:41 +08001562 break;
Pekka Paalanen98262232011-12-01 10:42:22 +02001563 case SHELL_SURFACE_NONE:
1564 case SHELL_SURFACE_TOPLEVEL:
1565 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001566 case SHELL_SURFACE_POPUP:
Pekka Paalanen98262232011-12-01 10:42:22 +02001567 break;
1568 }
1569
1570 surface->type = SHELL_SURFACE_NONE;
1571 return 0;
1572}
1573
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001574static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001575set_surface_type(struct shell_surface *shsurf)
1576{
1577 struct weston_surface *surface = shsurf->surface;
Kristian Høgsberg8150b192012-06-27 10:22:58 -04001578 struct weston_surface *pes = shsurf->parent;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001579
1580 reset_shell_surface_type(shsurf);
1581
1582 shsurf->type = shsurf->next_type;
1583 shsurf->next_type = SHELL_SURFACE_NONE;
1584
1585 switch (shsurf->type) {
1586 case SHELL_SURFACE_TOPLEVEL:
1587 break;
1588 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001589 weston_surface_set_position(surface,
Tiago Vignatti52e598c2012-05-07 15:23:08 +03001590 pes->geometry.x + shsurf->transient.x,
1591 pes->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001592 break;
1593
1594 case SHELL_SURFACE_MAXIMIZED:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001595 case SHELL_SURFACE_FULLSCREEN:
1596 shsurf->saved_x = surface->geometry.x;
1597 shsurf->saved_y = surface->geometry.y;
1598 shsurf->saved_position_valid = true;
1599
1600 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1601 wl_list_remove(&shsurf->rotation.transform.link);
1602 wl_list_init(&shsurf->rotation.transform.link);
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02001603 weston_surface_geometry_dirty(shsurf->surface);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001604 shsurf->saved_rotation_valid = true;
1605 }
1606 break;
1607
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001608 default:
1609 break;
1610 }
1611}
1612
1613static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03001614set_toplevel(struct shell_surface *shsurf)
1615{
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001616 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Tiago Vignattibc052c92012-04-19 16:18:18 +03001617}
1618
1619static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001620shell_surface_set_toplevel(struct wl_client *client,
1621 struct wl_resource *resource)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001622{
Pekka Paalanen98262232011-12-01 10:42:22 +02001623 struct shell_surface *surface = resource->data;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001624
Tiago Vignattibc052c92012-04-19 16:18:18 +03001625 set_toplevel(surface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001626}
1627
1628static void
Tiago Vignatti491bac12012-05-18 16:37:43 -04001629set_transient(struct shell_surface *shsurf,
Kristian Høgsberg8150b192012-06-27 10:22:58 -04001630 struct weston_surface *parent, int x, int y, uint32_t flags)
Tiago Vignatti491bac12012-05-18 16:37:43 -04001631{
1632 /* assign to parents output */
Kristian Høgsberg8150b192012-06-27 10:22:58 -04001633 shsurf->parent = parent;
Tiago Vignatti491bac12012-05-18 16:37:43 -04001634 shsurf->transient.x = x;
1635 shsurf->transient.y = y;
1636 shsurf->transient.flags = flags;
1637 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1638}
1639
1640static void
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001641shell_surface_set_transient(struct wl_client *client,
1642 struct wl_resource *resource,
1643 struct wl_resource *parent_resource,
1644 int x, int y, uint32_t flags)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001645{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02001646 struct shell_surface *shsurf = resource->data;
Kristian Høgsberg8150b192012-06-27 10:22:58 -04001647 struct weston_surface *parent = parent_resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02001648
Kristian Høgsberg8150b192012-06-27 10:22:58 -04001649 set_transient(shsurf, parent, x, y, flags);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001650}
1651
Tiago Vignattibe143262012-04-16 17:31:41 +03001652static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +08001653shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001654{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04001655 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +08001656}
1657
1658static int
Tiago Vignattibe143262012-04-16 17:31:41 +03001659get_output_panel_height(struct desktop_shell *shell,
1660 struct weston_output *output)
Juan Zhao96879df2012-02-07 08:45:41 +08001661{
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04001662 struct weston_surface *surface;
Juan Zhao96879df2012-02-07 08:45:41 +08001663 int panel_height = 0;
1664
1665 if (!output)
1666 return 0;
1667
Juan Zhao4ab94682012-07-09 22:24:09 -07001668 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04001669 if (surface->output == output) {
1670 panel_height = surface->geometry.height;
Juan Zhao96879df2012-02-07 08:45:41 +08001671 break;
1672 }
1673 }
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04001674
Juan Zhao96879df2012-02-07 08:45:41 +08001675 return panel_height;
1676}
1677
1678static void
1679shell_surface_set_maximized(struct wl_client *client,
1680 struct wl_resource *resource,
1681 struct wl_resource *output_resource )
1682{
1683 struct shell_surface *shsurf = resource->data;
1684 struct weston_surface *es = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +03001685 struct desktop_shell *shell = NULL;
Juan Zhao96879df2012-02-07 08:45:41 +08001686 uint32_t edges = 0, panel_height = 0;
1687
1688 /* get the default output, if the client set it as NULL
1689 check whether the ouput is available */
1690 if (output_resource)
1691 shsurf->output = output_resource->data;
Kristian Høgsberg94de6802012-07-18 09:54:04 -04001692 else if (es->output)
1693 shsurf->output = es->output;
Juan Zhao96879df2012-02-07 08:45:41 +08001694 else
1695 shsurf->output = get_default_output(es->compositor);
1696
Tiago Vignattibe143262012-04-16 17:31:41 +03001697 shell = shell_surface_get_shell(shsurf);
Rob Bradford31b68622012-07-02 19:00:19 +01001698 panel_height = get_output_panel_height(shell, shsurf->output);
Juan Zhao96879df2012-02-07 08:45:41 +08001699 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05001700
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001701 shsurf->client->send_configure(shsurf->surface, edges,
Scott Moreau1bad5db2012-08-18 01:04:05 -06001702 shsurf->output->width,
1703 shsurf->output->height - panel_height);
Juan Zhao96879df2012-02-07 08:45:41 +08001704
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001705 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02001706}
1707
Alex Wu21858432012-04-01 20:13:08 +08001708static void
Giulio Camuffo184df502013-02-21 11:29:21 +01001709black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
Alex Wu21858432012-04-01 20:13:08 +08001710
Alex Wu4539b082012-03-01 12:57:46 +08001711static struct weston_surface *
1712create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +08001713 struct weston_surface *fs_surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02001714 float x, float y, int w, int h)
Alex Wu4539b082012-03-01 12:57:46 +08001715{
1716 struct weston_surface *surface = NULL;
1717
1718 surface = weston_surface_create(ec);
1719 if (surface == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02001720 weston_log("no memory\n");
Alex Wu4539b082012-03-01 12:57:46 +08001721 return NULL;
1722 }
1723
Alex Wu21858432012-04-01 20:13:08 +08001724 surface->configure = black_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01001725 surface->configure_private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +08001726 weston_surface_configure(surface, x, y, w, h);
1727 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
Pekka Paalanen71f6f3b2012-10-10 12:49:26 +03001728 pixman_region32_fini(&surface->opaque);
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04001729 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
Jonas Ådahl33619a42013-01-15 21:25:55 +01001730 pixman_region32_fini(&surface->input);
1731 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04001732
Alex Wu4539b082012-03-01 12:57:46 +08001733 return surface;
1734}
1735
1736/* Create black surface and append it to the associated fullscreen surface.
1737 * Handle size dismatch and positioning according to the method. */
1738static void
1739shell_configure_fullscreen(struct shell_surface *shsurf)
1740{
1741 struct weston_output *output = shsurf->fullscreen_output;
1742 struct weston_surface *surface = shsurf->surface;
1743 struct weston_matrix *matrix;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001744 float scale, output_aspect, surface_aspect, x, y;
Giulio Camuffob8366642013-04-25 13:57:46 +03001745 int32_t surf_x, surf_y, surf_width, surf_height;
Alex Wu4539b082012-03-01 12:57:46 +08001746
Alex Wu4539b082012-03-01 12:57:46 +08001747 if (!shsurf->fullscreen.black_surface)
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001748 shsurf->fullscreen.black_surface =
1749 create_black_surface(surface->compositor,
Alex Wu21858432012-04-01 20:13:08 +08001750 surface,
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001751 output->x, output->y,
Scott Moreau1bad5db2012-08-18 01:04:05 -06001752 output->width,
1753 output->height);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001754
1755 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1756 wl_list_insert(&surface->layer_link,
1757 &shsurf->fullscreen.black_surface->layer_link);
Alex Wu4539b082012-03-01 12:57:46 +08001758 shsurf->fullscreen.black_surface->output = output;
1759
Giulio Camuffob8366642013-04-25 13:57:46 +03001760 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y,
1761 &surf_width, &surf_height);
1762
Alex Wu4539b082012-03-01 12:57:46 +08001763 switch (shsurf->fullscreen.type) {
1764 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
Pekka Paalanende685b82012-12-04 15:58:12 +02001765 if (surface->buffer_ref.buffer)
Kristian Høgsberga08b5282012-07-20 15:30:36 -04001766 center_on_output(surface, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08001767 break;
1768 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
Rob Bradford9f3dd152013-02-12 11:53:47 +00001769 /* 1:1 mapping between surface and output dimensions */
Giulio Camuffob8366642013-04-25 13:57:46 +03001770 if (output->width == surf_width &&
1771 output->height == surf_height) {
1772 weston_surface_set_position(surface, output->x - surf_x,
1773 output->y - surf_y);
Rob Bradford9f3dd152013-02-12 11:53:47 +00001774 break;
1775 }
1776
Alex Wu4539b082012-03-01 12:57:46 +08001777 matrix = &shsurf->fullscreen.transform.matrix;
1778 weston_matrix_init(matrix);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001779
Scott Moreau1bad5db2012-08-18 01:04:05 -06001780 output_aspect = (float) output->width /
1781 (float) output->height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001782 surface_aspect = (float) surface->geometry.width /
1783 (float) surface->geometry.height;
1784 if (output_aspect < surface_aspect)
Scott Moreau1bad5db2012-08-18 01:04:05 -06001785 scale = (float) output->width /
Giulio Camuffob8366642013-04-25 13:57:46 +03001786 (float) surf_width;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001787 else
Scott Moreau1bad5db2012-08-18 01:04:05 -06001788 scale = (float) output->height /
Giulio Camuffob8366642013-04-25 13:57:46 +03001789 (float) surf_height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001790
Alex Wu4539b082012-03-01 12:57:46 +08001791 weston_matrix_scale(matrix, scale, scale, 1);
1792 wl_list_remove(&shsurf->fullscreen.transform.link);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001793 wl_list_insert(&surface->geometry.transformation_list,
Alex Wu4539b082012-03-01 12:57:46 +08001794 &shsurf->fullscreen.transform.link);
Giulio Camuffob8366642013-04-25 13:57:46 +03001795 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
1796 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04001797 weston_surface_set_position(surface, x, y);
1798
Alex Wu4539b082012-03-01 12:57:46 +08001799 break;
1800 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +08001801 if (shell_surface_is_top_fullscreen(shsurf)) {
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01001802 struct weston_mode mode = {0,
Giulio Camuffob8366642013-04-25 13:57:46 +03001803 surf_width,
1804 surf_height,
Alex Wubd3354b2012-04-17 17:20:49 +08001805 shsurf->fullscreen.framerate};
1806
1807 if (weston_output_switch_mode(output, &mode) == 0) {
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01001808 weston_surface_configure(shsurf->fullscreen.black_surface,
Giulio Camuffob8366642013-04-25 13:57:46 +03001809 output->x - surf_x,
1810 output->y - surf_y,
Scott Moreau1bad5db2012-08-18 01:04:05 -06001811 output->width,
1812 output->height);
Alex Wubd3354b2012-04-17 17:20:49 +08001813 break;
1814 }
1815 }
Alex Wu4539b082012-03-01 12:57:46 +08001816 break;
1817 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1818 break;
1819 default:
1820 break;
1821 }
1822}
1823
1824/* make the fullscreen and black surface at the top */
1825static void
1826shell_stack_fullscreen(struct shell_surface *shsurf)
1827{
Alex Wubd3354b2012-04-17 17:20:49 +08001828 struct weston_output *output = shsurf->fullscreen_output;
Alex Wu4539b082012-03-01 12:57:46 +08001829 struct weston_surface *surface = shsurf->surface;
Tiago Vignattibe143262012-04-16 17:31:41 +03001830 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001831
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001832 wl_list_remove(&surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001833 wl_list_insert(&shell->fullscreen_layer.surface_list,
1834 &surface->layer_link);
Alex Wubd3354b2012-04-17 17:20:49 +08001835 weston_surface_damage(surface);
1836
1837 if (!shsurf->fullscreen.black_surface)
1838 shsurf->fullscreen.black_surface =
1839 create_black_surface(surface->compositor,
1840 surface,
1841 output->x, output->y,
Scott Moreau1bad5db2012-08-18 01:04:05 -06001842 output->width,
1843 output->height);
Alex Wubd3354b2012-04-17 17:20:49 +08001844
1845 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001846 wl_list_insert(&surface->layer_link,
1847 &shsurf->fullscreen.black_surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05001848 weston_surface_damage(shsurf->fullscreen.black_surface);
Alex Wu4539b082012-03-01 12:57:46 +08001849}
1850
1851static void
1852shell_map_fullscreen(struct shell_surface *shsurf)
1853{
Alex Wu4539b082012-03-01 12:57:46 +08001854 shell_stack_fullscreen(shsurf);
Alex Wubd3354b2012-04-17 17:20:49 +08001855 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08001856}
1857
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001858static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001859set_fullscreen(struct shell_surface *shsurf,
1860 uint32_t method,
1861 uint32_t framerate,
1862 struct weston_output *output)
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001863{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001864 struct weston_surface *es = shsurf->surface;
Alex Wu4539b082012-03-01 12:57:46 +08001865
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001866 if (output)
1867 shsurf->output = output;
Kristian Høgsberg94de6802012-07-18 09:54:04 -04001868 else if (es->output)
1869 shsurf->output = es->output;
Alex Wu4539b082012-03-01 12:57:46 +08001870 else
1871 shsurf->output = get_default_output(es->compositor);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001872
Alex Wu4539b082012-03-01 12:57:46 +08001873 shsurf->fullscreen_output = shsurf->output;
1874 shsurf->fullscreen.type = method;
1875 shsurf->fullscreen.framerate = framerate;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04001876 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
Alex Wu4539b082012-03-01 12:57:46 +08001877
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001878 shsurf->client->send_configure(shsurf->surface, 0,
Scott Moreau1bad5db2012-08-18 01:04:05 -06001879 shsurf->output->width,
1880 shsurf->output->height);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04001881}
1882
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001883static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001884shell_surface_set_fullscreen(struct wl_client *client,
1885 struct wl_resource *resource,
1886 uint32_t method,
1887 uint32_t framerate,
1888 struct wl_resource *output_resource)
1889{
1890 struct shell_surface *shsurf = resource->data;
1891 struct weston_output *output;
1892
1893 if (output_resource)
1894 output = output_resource->data;
1895 else
1896 output = NULL;
1897
1898 set_fullscreen(shsurf, method, framerate, output);
1899}
1900
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001901static const struct weston_pointer_grab_interface popup_grab_interface;
Giulio Camuffo5085a752013-03-25 21:42:45 +01001902
1903static void
1904destroy_shell_seat(struct wl_listener *listener, void *data)
1905{
1906 struct shell_seat *shseat =
1907 container_of(listener,
1908 struct shell_seat, seat_destroy_listener);
1909 struct shell_surface *shsurf, *prev = NULL;
1910
1911 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001912 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01001913 shseat->popup_grab.client = NULL;
1914
1915 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
1916 shsurf->popup.shseat = NULL;
1917 if (prev) {
1918 wl_list_init(&prev->popup.grab_link);
1919 }
1920 prev = shsurf;
1921 }
1922 wl_list_init(&prev->popup.grab_link);
1923 }
1924
1925 wl_list_remove(&shseat->seat_destroy_listener.link);
1926 free(shseat);
1927}
1928
1929static struct shell_seat *
1930create_shell_seat(struct weston_seat *seat)
1931{
1932 struct shell_seat *shseat;
1933
1934 shseat = calloc(1, sizeof *shseat);
1935 if (!shseat) {
1936 weston_log("no memory to allocate shell seat\n");
1937 return NULL;
1938 }
1939
1940 shseat->seat = seat;
1941 wl_list_init(&shseat->popup_grab.surfaces_list);
1942
1943 shseat->seat_destroy_listener.notify = destroy_shell_seat;
1944 wl_signal_add(&seat->destroy_signal,
1945 &shseat->seat_destroy_listener);
1946
1947 return shseat;
1948}
1949
1950static struct shell_seat *
1951get_shell_seat(struct weston_seat *seat)
1952{
1953 struct wl_listener *listener;
1954
1955 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
1956 if (listener == NULL)
1957 return create_shell_seat(seat);
1958
1959 return container_of(listener,
1960 struct shell_seat, seat_destroy_listener);
1961}
1962
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001963static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001964popup_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001965{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001966 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001967 struct weston_surface *surface;
Giulio Camuffo5085a752013-03-25 21:42:45 +01001968 struct shell_seat *shseat =
1969 container_of(grab, struct shell_seat, popup_grab.grab);
1970 struct wl_client *client = shseat->popup_grab.client;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001971 wl_fixed_t sx, sy;
1972
1973 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1974 pointer->x, pointer->y,
1975 &sx, &sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001976
Pekka Paalanencb108432012-01-19 16:25:40 +02001977 if (surface && surface->resource.client == client) {
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001978 weston_pointer_set_focus(pointer, surface, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001979 } else {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001980 weston_pointer_set_focus(pointer, NULL,
1981 wl_fixed_from_int(0),
1982 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001983 }
1984}
1985
1986static void
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001987popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001988{
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001989 struct weston_pointer *pointer = grab->pointer;
1990 wl_fixed_t sx, sy;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001991
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04001992 if (pointer->focus_resource) {
1993 weston_surface_from_global_fixed(pointer->focus,
1994 pointer->x, pointer->y,
1995 &sx, &sy);
1996 wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
1997 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05001998}
1999
2000static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002001popup_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01002002 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002003{
2004 struct wl_resource *resource;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002005 struct shell_seat *shseat =
2006 container_of(grab, struct shell_seat, popup_grab.grab);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002007 struct wl_display *display;
Daniel Stone4dbadb12012-05-30 16:31:51 +01002008 enum wl_pointer_button_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002009 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002010
Daniel Stone37816df2012-05-16 18:45:18 +01002011 resource = grab->pointer->focus_resource;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002012 if (resource) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002013 display = wl_client_get_display(resource->client);
2014 serial = wl_display_get_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +01002015 wl_pointer_send_button(resource, serial, time, button, state);
Daniel Stone4dbadb12012-05-30 16:31:51 +01002016 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
Giulio Camuffo5085a752013-03-25 21:42:45 +01002017 (shseat->popup_grab.initial_up ||
Kristian Høgsberge3148752013-05-06 23:19:49 -04002018 time - shseat->seat->pointer->grab_time > 500)) {
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002019 popup_grab_end(grab->pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002020 }
2021
Daniel Stone4dbadb12012-05-30 16:31:51 +01002022 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Giulio Camuffo5085a752013-03-25 21:42:45 +01002023 shseat->popup_grab.initial_up = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002024}
2025
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002026static const struct weston_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002027 popup_grab_focus,
2028 popup_grab_motion,
2029 popup_grab_button,
2030};
2031
2032static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002033popup_grab_end(struct weston_pointer *pointer)
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002034{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002035 struct weston_pointer_grab *grab = pointer->grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002036 struct shell_seat *shseat =
2037 container_of(grab, struct shell_seat, popup_grab.grab);
2038 struct shell_surface *shsurf;
2039 struct shell_surface *prev = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002040
2041 if (pointer->grab->interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002042 weston_pointer_end_grab(grab->pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002043 shseat->popup_grab.client = NULL;
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002044 shseat->popup_grab.grab.interface = NULL;
2045 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
Giulio Camuffo5085a752013-03-25 21:42:45 +01002046 /* Send the popup_done event to all the popups open */
2047 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2048 wl_shell_surface_send_popup_done(&shsurf->resource);
2049 shsurf->popup.shseat = NULL;
2050 if (prev) {
2051 wl_list_init(&prev->popup.grab_link);
2052 }
2053 prev = shsurf;
2054 }
2055 wl_list_init(&prev->popup.grab_link);
2056 wl_list_init(&shseat->popup_grab.surfaces_list);
2057 }
2058}
2059
2060static void
2061add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2062{
Kristian Høgsberge3148752013-05-06 23:19:49 -04002063 struct weston_seat *seat = shseat->seat;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002064
2065 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04002066 shseat->popup_grab.client = shsurf->resource.client;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002067 shseat->popup_grab.grab.interface = &popup_grab_interface;
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002068 /* We must make sure here that this popup was opened after
2069 * a mouse press, and not just by moving around with other
2070 * popups already open. */
Kristian Høgsberge3148752013-05-06 23:19:49 -04002071 if (shseat->seat->pointer->button_count > 0)
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002072 shseat->popup_grab.initial_up = 0;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002073
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002074 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002075 }
2076 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2077}
2078
2079static void
2080remove_popup_grab(struct shell_surface *shsurf)
2081{
2082 struct shell_seat *shseat = shsurf->popup.shseat;
2083
2084 wl_list_remove(&shsurf->popup.grab_link);
2085 wl_list_init(&shsurf->popup.grab_link);
2086 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002087 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002088 shseat->popup_grab.grab.interface = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002089 }
2090}
2091
2092static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002093shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002094{
Giulio Camuffo5085a752013-03-25 21:42:45 +01002095 struct shell_seat *shseat = shsurf->popup.shseat;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002096 struct weston_surface *es = shsurf->surface;
Kristian Høgsberg8150b192012-06-27 10:22:58 -04002097 struct weston_surface *parent = shsurf->parent;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002098
2099 es->output = parent->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002100
Pekka Paalanen483243f2013-03-08 14:56:50 +02002101 weston_surface_set_transform_parent(es, parent);
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02002102 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
2103 weston_surface_update_transform(es);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002104
Kristian Høgsberge3148752013-05-06 23:19:49 -04002105 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01002106 add_popup_grab(shsurf, shseat);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002107 } else {
2108 wl_shell_surface_send_popup_done(&shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002109 shseat->popup_grab.client = NULL;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002110 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002111}
2112
2113static void
2114shell_surface_set_popup(struct wl_client *client,
2115 struct wl_resource *resource,
Daniel Stone37816df2012-05-16 18:45:18 +01002116 struct wl_resource *seat_resource,
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002117 uint32_t serial,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002118 struct wl_resource *parent_resource,
2119 int32_t x, int32_t y, uint32_t flags)
2120{
2121 struct shell_surface *shsurf = resource->data;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002122
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002123 shsurf->type = SHELL_SURFACE_POPUP;
2124 shsurf->parent = parent_resource->data;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002125 shsurf->popup.shseat = get_shell_seat(seat_resource->data);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002126 shsurf->popup.serial = serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002127 shsurf->popup.x = x;
2128 shsurf->popup.y = y;
2129}
2130
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002131static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002132 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002133 shell_surface_move,
2134 shell_surface_resize,
2135 shell_surface_set_toplevel,
2136 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002137 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08002138 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002139 shell_surface_set_maximized,
2140 shell_surface_set_title,
2141 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002142};
2143
2144static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002145destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002146{
Giulio Camuffo5085a752013-03-25 21:42:45 +01002147 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2148 remove_popup_grab(shsurf);
2149 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002150
Alex Wubd3354b2012-04-17 17:20:49 +08002151 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2152 shell_surface_is_top_fullscreen(shsurf)) {
2153 weston_output_switch_mode(shsurf->fullscreen_output,
2154 shsurf->fullscreen_output->origin);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002155 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002156
Alex Wuaa08e2d2012-03-05 11:01:40 +08002157 if (shsurf->fullscreen.black_surface)
2158 weston_surface_destroy(shsurf->fullscreen.black_surface);
2159
Alex Wubd3354b2012-04-17 17:20:49 +08002160 /* As destroy_resource() use wl_list_for_each_safe(),
2161 * we can always remove the listener.
2162 */
2163 wl_list_remove(&shsurf->surface_destroy_listener.link);
2164 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06002165 ping_timer_destroy(shsurf);
Scott Moreau976a0502013-03-07 10:15:17 -07002166 free(shsurf->title);
Alex Wubd3354b2012-04-17 17:20:49 +08002167
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002168 wl_list_remove(&shsurf->link);
2169 free(shsurf);
2170}
2171
2172static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002173shell_destroy_shell_surface(struct wl_resource *resource)
2174{
2175 struct shell_surface *shsurf = resource->data;
2176
2177 destroy_shell_surface(shsurf);
2178}
2179
2180static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002181shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002182{
2183 struct shell_surface *shsurf = container_of(listener,
2184 struct shell_surface,
2185 surface_destroy_listener);
2186
Kristian Høgsberg633b1452012-06-07 18:08:47 -04002187 if (shsurf->resource.client) {
Tiago Vignattibc052c92012-04-19 16:18:18 +03002188 wl_resource_destroy(&shsurf->resource);
Kristian Høgsberg633b1452012-06-07 18:08:47 -04002189 } else {
2190 wl_signal_emit(&shsurf->resource.destroy_signal,
2191 &shsurf->resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03002192 destroy_shell_surface(shsurf);
Kristian Høgsberg633b1452012-06-07 18:08:47 -04002193 }
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002194}
2195
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002196static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002197shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002198
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002199static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002200get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002201{
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002202 if (surface->configure == shell_surface_configure)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002203 return surface->configure_private;
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002204 else
2205 return NULL;
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002206}
2207
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002208static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002209create_shell_surface(void *shell, struct weston_surface *surface,
2210 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002211{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002212 struct shell_surface *shsurf;
2213
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002214 if (surface->configure) {
Martin Minarik6d118362012-06-07 18:01:59 +02002215 weston_log("surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002216 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002217 }
2218
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002219 shsurf = calloc(1, sizeof *shsurf);
2220 if (!shsurf) {
Martin Minarik6d118362012-06-07 18:01:59 +02002221 weston_log("no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002222 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002223 }
2224
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002225 surface->configure = shell_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002226 surface->configure_private = shsurf;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002227
Tiago Vignattibc052c92012-04-19 16:18:18 +03002228 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002229 shsurf->unresponsive = 0;
Alex Wu4539b082012-03-01 12:57:46 +08002230 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002231 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002232 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08002233 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2234 shsurf->fullscreen.framerate = 0;
2235 shsurf->fullscreen.black_surface = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002236 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08002237 wl_list_init(&shsurf->fullscreen.transform.link);
2238
Tiago Vignattibc052c92012-04-19 16:18:18 +03002239 wl_signal_init(&shsurf->resource.destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002240 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04002241 wl_signal_add(&surface->resource.destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002242 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002243
2244 /* init link so its safe to always remove it in destroy_shell_surface */
2245 wl_list_init(&shsurf->link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002246 wl_list_init(&shsurf->popup.grab_link);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002247
Pekka Paalanen460099f2012-01-20 16:48:25 +02002248 /* empty when not in use */
2249 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002250 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002251
Jonas Ådahl62fcd042012-06-13 00:01:23 +02002252 wl_list_init(&shsurf->workspace_transform.link);
2253
Pekka Paalanen98262232011-12-01 10:42:22 +02002254 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002255 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002256
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002257 shsurf->client = client;
2258
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002259 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002260}
2261
2262static void
2263shell_get_shell_surface(struct wl_client *client,
2264 struct wl_resource *resource,
2265 uint32_t id,
2266 struct wl_resource *surface_resource)
2267{
2268 struct weston_surface *surface = surface_resource->data;
2269 struct desktop_shell *shell = resource->data;
2270 struct shell_surface *shsurf;
2271
2272 if (get_shell_surface(surface)) {
2273 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04002274 WL_DISPLAY_ERROR_INVALID_OBJECT,
2275 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03002276 return;
2277 }
2278
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002279 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04002280 if (!shsurf) {
2281 wl_resource_post_error(surface_resource,
2282 WL_DISPLAY_ERROR_INVALID_OBJECT,
2283 "surface->configure already set");
2284 return;
2285 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03002286
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04002287 shsurf->resource.destroy = shell_destroy_shell_surface;
2288 shsurf->resource.object.id = id;
2289 shsurf->resource.object.interface = &wl_shell_surface_interface;
2290 shsurf->resource.object.implementation =
2291 (void (**)(void)) &shell_surface_implementation;
2292 shsurf->resource.data = shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002293
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04002294 wl_client_add_resource(client, &shsurf->resource);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002295}
2296
2297static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02002298 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002299};
2300
Kristian Høgsberg07937562011-04-12 17:25:42 -04002301static void
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02002302shell_fade(struct desktop_shell *shell, enum fade_type type);
2303
2304static int
2305screensaver_timeout(void *data)
2306{
2307 struct desktop_shell *shell = data;
2308
2309 shell_fade(shell, FADE_OUT);
2310
2311 return 1;
2312}
2313
2314static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002315handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02002316{
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02002317 struct desktop_shell *shell =
2318 container_of(proc, struct desktop_shell, screensaver.process);
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02002319
Pekka Paalanen18027e52011-12-02 16:31:49 +02002320 proc->pid = 0;
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02002321
2322 if (shell->locked)
Ander Conselvan de Oliveirab17537e2013-02-22 14:16:18 +02002323 weston_compositor_sleep(shell->compositor);
Pekka Paalanen18027e52011-12-02 16:31:49 +02002324}
2325
2326static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002327launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02002328{
2329 if (shell->screensaver.binding)
2330 return;
2331
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02002332 if (!shell->screensaver.path) {
2333 weston_compositor_sleep(shell->compositor);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002334 return;
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02002335 }
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002336
Kristian Høgsberg32bed572012-03-01 17:11:36 -05002337 if (shell->screensaver.process.pid != 0) {
Martin Minarik6d118362012-06-07 18:01:59 +02002338 weston_log("old screensaver still running\n");
Kristian Høgsberg32bed572012-03-01 17:11:36 -05002339 return;
2340 }
2341
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002342 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02002343 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02002344 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02002345 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002346}
2347
2348static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002349terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02002350{
Pekka Paalanen18027e52011-12-02 16:31:49 +02002351 if (shell->screensaver.process.pid == 0)
2352 return;
2353
2354 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002355}
2356
2357static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002358configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height)
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002359{
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002360 struct weston_surface *s, *next;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002361
Giulio Camuffo184df502013-02-21 11:29:21 +01002362 if (width == 0)
2363 return;
2364
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002365 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
2366 if (s->output == es->output && s != es) {
2367 weston_surface_unmap(s);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002368 s->configure = NULL;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002369 }
2370 }
2371
Giulio Camuffo184df502013-02-21 11:29:21 +01002372 weston_surface_configure(es, es->output->x, es->output->y, width, height);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002373
2374 if (wl_list_empty(&es->layer_link)) {
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002375 wl_list_insert(&layer->surface_list, &es->layer_link);
Kristian Høgsbergc7cd6262012-06-28 13:46:09 -04002376 weston_compositor_schedule_repaint(es->compositor);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002377 }
2378}
2379
2380static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002381background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002382{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002383 struct desktop_shell *shell = es->configure_private;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002384
Giulio Camuffo184df502013-02-21 11:29:21 +01002385 configure_static_surface(es, &shell->background_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002386}
2387
2388static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04002389desktop_shell_set_background(struct wl_client *client,
2390 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002391 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04002392 struct wl_resource *surface_resource)
2393{
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002394 struct desktop_shell *shell = resource->data;
2395 struct weston_surface *surface = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002396
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002397 if (surface->configure) {
2398 wl_resource_post_error(surface_resource,
2399 WL_DISPLAY_ERROR_INVALID_OBJECT,
2400 "surface role already assigned");
2401 return;
2402 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002403
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002404 surface->configure = background_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002405 surface->configure_private = shell;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04002406 surface->output = output_resource->data;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002407 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05002408 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06002409 surface->output->width,
2410 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002411}
2412
2413static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002414panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002415{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002416 struct desktop_shell *shell = es->configure_private;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002417
Giulio Camuffo184df502013-02-21 11:29:21 +01002418 configure_static_surface(es, &shell->panel_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002419}
2420
2421static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04002422desktop_shell_set_panel(struct wl_client *client,
2423 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002424 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04002425 struct wl_resource *surface_resource)
2426{
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002427 struct desktop_shell *shell = resource->data;
2428 struct weston_surface *surface = surface_resource->data;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002429
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002430 if (surface->configure) {
2431 wl_resource_post_error(surface_resource,
2432 WL_DISPLAY_ERROR_INVALID_OBJECT,
2433 "surface role already assigned");
2434 return;
2435 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002436
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002437 surface->configure = panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002438 surface->configure_private = shell;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002439 surface->output = output_resource->data;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002440 desktop_shell_send_configure(resource, 0,
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04002441 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06002442 surface->output->width,
2443 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002444}
2445
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002446static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002447lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002448{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002449 struct desktop_shell *shell = surface->configure_private;
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002450
Giulio Camuffo184df502013-02-21 11:29:21 +01002451 if (width == 0)
2452 return;
2453
Kristian Høgsbergb9f1c522013-05-14 20:59:02 -04002454 surface->geometry.width = width;
2455 surface->geometry.height = height;
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002456 center_on_output(surface, get_default_output(shell->compositor));
2457
2458 if (!weston_surface_is_mapped(surface)) {
2459 wl_list_insert(&shell->lock_layer.surface_list,
2460 &surface->layer_link);
Ander Conselvan de Oliveira231ba172012-09-14 16:12:04 +03002461 weston_surface_update_transform(surface);
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02002462 shell_fade(shell, FADE_IN);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002463 }
2464}
2465
2466static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002467handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002468{
Tiago Vignattibe143262012-04-16 17:31:41 +03002469 struct desktop_shell *shell =
2470 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002471
Martin Minarik6d118362012-06-07 18:01:59 +02002472 weston_log("lock surface gone\n");
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05002473 shell->lock_surface = NULL;
2474}
2475
2476static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002477desktop_shell_set_lock_surface(struct wl_client *client,
2478 struct wl_resource *resource,
2479 struct wl_resource *surface_resource)
2480{
Tiago Vignattibe143262012-04-16 17:31:41 +03002481 struct desktop_shell *shell = resource->data;
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002482 struct weston_surface *surface = surface_resource->data;
Pekka Paalanen98262232011-12-01 10:42:22 +02002483
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002484 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02002485
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002486 if (!shell->locked)
2487 return;
2488
Pekka Paalanen98262232011-12-01 10:42:22 +02002489 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002490
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002491 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2492 wl_signal_add(&surface_resource->destroy_signal,
2493 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002494
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04002495 surface->configure = lock_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002496 surface->configure_private = shell;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002497}
2498
2499static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002500resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002501{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04002502 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02002503
Pekka Paalanen77346a62011-11-30 16:26:35 +02002504 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002505
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002506 wl_list_remove(&shell->lock_layer.link);
2507 wl_list_insert(&shell->compositor->cursor_layer.link,
2508 &shell->fullscreen_layer.link);
2509 wl_list_insert(&shell->fullscreen_layer.link,
2510 &shell->panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02002511 if (shell->showing_input_panels) {
2512 wl_list_insert(&shell->panel_layer.link,
2513 &shell->input_panel_layer.link);
2514 wl_list_insert(&shell->input_panel_layer.link,
2515 &ws->layer.link);
2516 } else {
2517 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2518 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002519
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04002520 restore_focus_state(shell, get_current_workspace(shell));
Jonas Ådahl04769742012-06-13 00:01:24 +02002521
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002522 shell->locked = false;
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02002523 shell_fade(shell, FADE_IN);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02002524 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002525}
2526
2527static void
2528desktop_shell_unlock(struct wl_client *client,
2529 struct wl_resource *resource)
2530{
Tiago Vignattibe143262012-04-16 17:31:41 +03002531 struct desktop_shell *shell = resource->data;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002532
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002533 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002534
2535 if (shell->locked)
2536 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002537}
2538
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002539static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03002540desktop_shell_set_grab_surface(struct wl_client *client,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002541 struct wl_resource *resource,
2542 struct wl_resource *surface_resource)
2543{
2544 struct desktop_shell *shell = resource->data;
2545
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03002546 shell->grab_surface = surface_resource->data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002547}
2548
Kristian Høgsberg75840622011-09-06 13:48:16 -04002549static const struct desktop_shell_interface desktop_shell_implementation = {
2550 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002551 desktop_shell_set_panel,
2552 desktop_shell_set_lock_surface,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002553 desktop_shell_unlock,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03002554 desktop_shell_set_grab_surface
Kristian Høgsberg75840622011-09-06 13:48:16 -04002555};
2556
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002557static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002558get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002559{
2560 struct shell_surface *shsurf;
2561
2562 shsurf = get_shell_surface(surface);
2563 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02002564 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002565 return shsurf->type;
2566}
2567
Kristian Høgsberg75840622011-09-06 13:48:16 -04002568static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002569move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04002570{
Pekka Paalanen01388e22013-04-25 13:57:44 +03002571 struct weston_surface *focus =
Daniel Stone37816df2012-05-16 18:45:18 +01002572 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002573 struct weston_surface *surface;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002574 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002575
Pekka Paalanen01388e22013-04-25 13:57:44 +03002576 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002577 if (surface == NULL)
2578 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002579
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002580 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01002581 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2582 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002583 return;
2584
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04002585 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002586}
2587
2588static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002589resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04002590{
Pekka Paalanen01388e22013-04-25 13:57:44 +03002591 struct weston_surface *focus =
Daniel Stone37816df2012-05-16 18:45:18 +01002592 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002593 struct weston_surface *surface;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002594 uint32_t edges = 0;
2595 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002596 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05002597
Pekka Paalanen01388e22013-04-25 13:57:44 +03002598 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01002599 if (surface == NULL)
2600 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002601
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002602 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01002603 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2604 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02002605 return;
2606
Pekka Paalanen5c97ae72012-01-30 16:19:47 +02002607 weston_surface_from_global(surface,
Daniel Stone37816df2012-05-16 18:45:18 +01002608 wl_fixed_to_int(seat->pointer->grab_x),
2609 wl_fixed_to_int(seat->pointer->grab_y),
Daniel Stone103db7f2012-05-08 17:17:55 +01002610 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04002611
Pekka Paalanen60921e52012-01-25 15:55:43 +02002612 if (x < surface->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002613 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Pekka Paalanen60921e52012-01-25 15:55:43 +02002614 else if (x < 2 * surface->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04002615 edges |= 0;
2616 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002617 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002618
Pekka Paalanen60921e52012-01-25 15:55:43 +02002619 if (y < surface->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002620 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Pekka Paalanen60921e52012-01-25 15:55:43 +02002621 else if (y < 2 * surface->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04002622 edges |= 0;
2623 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002624 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04002625
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04002626 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002627}
2628
2629static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002630surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01002631 wl_fixed_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002632{
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02002633 float step = 0.005;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002634 struct shell_surface *shsurf;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002635 struct weston_surface *focus =
Daniel Stone37816df2012-05-16 18:45:18 +01002636 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002637 struct weston_surface *surface;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002638
Pekka Paalanen01388e22013-04-25 13:57:44 +03002639 /* XXX: broken for windows containing sub-surfaces */
2640 surface = weston_surface_get_main_surface(focus);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002641 if (surface == NULL)
2642 return;
2643
2644 shsurf = get_shell_surface(surface);
2645 if (!shsurf)
2646 return;
2647
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02002648 surface->alpha -= wl_fixed_to_double(value) * step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002649
Scott Moreau02709af2012-05-22 01:54:10 -06002650 if (surface->alpha > 1.0)
2651 surface->alpha = 1.0;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002652 if (surface->alpha < step)
2653 surface->alpha = step;
2654
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02002655 weston_surface_geometry_dirty(surface);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06002656 weston_surface_damage(surface);
2657}
2658
2659static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002660do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01002661 wl_fixed_t value)
Scott Moreauccbf29d2012-02-22 14:21:41 -07002662{
Daniel Stone37816df2012-05-16 18:45:18 +01002663 struct weston_seat *ws = (struct weston_seat *) seat;
2664 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07002665 struct weston_output *output;
Scott Moreaue6603982012-06-11 13:07:51 -06002666 float increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07002667
2668 wl_list_for_each(output, &compositor->output_list, link) {
2669 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01002670 wl_fixed_to_double(seat->pointer->x),
2671 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01002672 NULL)) {
Daniel Stone325fc2d2012-05-30 16:31:58 +01002673 if (key == KEY_PAGEUP)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002674 increment = output->zoom.increment;
Daniel Stone325fc2d2012-05-30 16:31:58 +01002675 else if (key == KEY_PAGEDOWN)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002676 increment = -output->zoom.increment;
2677 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02002678 /* For every pixel zoom 20th of a step */
Daniel Stone0c1e46e2012-05-30 16:31:59 +01002679 increment = output->zoom.increment *
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02002680 -wl_fixed_to_double(value) / 20.0;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002681 else
2682 increment = 0;
2683
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04002684 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07002685
Scott Moreaue6603982012-06-11 13:07:51 -06002686 if (output->zoom.level < 0.0)
Scott Moreau850ca422012-05-21 15:21:25 -06002687 output->zoom.level = 0.0;
Scott Moreaue6603982012-06-11 13:07:51 -06002688 else if (output->zoom.level > output->zoom.max_level)
2689 output->zoom.level = output->zoom.max_level;
Ville Syrjäläaa628d02012-11-16 11:48:47 +02002690 else if (!output->zoom.active) {
Scott Moreaue6603982012-06-11 13:07:51 -06002691 output->zoom.active = 1;
Kristian Høgsberg79af73e2012-08-03 15:45:23 -04002692 output->disable_planes++;
2693 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07002694
Scott Moreaue6603982012-06-11 13:07:51 -06002695 output->zoom.spring_z.target = output->zoom.level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07002696
Scott Moreau8dacaab2012-06-17 18:10:58 -06002697 weston_output_update_zoom(output, output->zoom.type);
Scott Moreauccbf29d2012-02-22 14:21:41 -07002698 }
2699 }
2700}
2701
Scott Moreauccbf29d2012-02-22 14:21:41 -07002702static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002703zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01002704 wl_fixed_t value, void *data)
Daniel Stone325fc2d2012-05-30 16:31:58 +01002705{
2706 do_zoom(seat, time, 0, axis, value);
2707}
2708
2709static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002710zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01002711 void *data)
2712{
2713 do_zoom(seat, time, key, 0, 0);
2714}
2715
2716static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002717terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01002718 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002719{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002720 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002721
Daniel Stone325fc2d2012-05-30 16:31:58 +01002722 wl_display_terminate(compositor->wl_display);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002723}
2724
2725static void
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002726rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
Pekka Paalanen460099f2012-01-20 16:48:25 +02002727{
2728 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002729 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002730 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002731 struct shell_surface *shsurf = rotate->base.shsurf;
2732 struct weston_surface *surface;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02002733 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002734
2735 if (!shsurf)
2736 return;
2737
2738 surface = shsurf->surface;
2739
2740 cx = 0.5f * surface->geometry.width;
2741 cy = 0.5f * surface->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02002742
Daniel Stone37816df2012-05-16 18:45:18 +01002743 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2744 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02002745 r = sqrtf(dx * dx + dy * dy);
2746
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002747 wl_list_remove(&shsurf->rotation.transform.link);
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02002748 weston_surface_geometry_dirty(shsurf->surface);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002749
2750 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02002751 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002752 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02002753
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002754 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03002755 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002756
2757 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02002758 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002759 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002760 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02002761 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002762
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02002763 wl_list_insert(
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002764 &shsurf->surface->geometry.transformation_list,
2765 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002766 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002767 wl_list_init(&shsurf->rotation.transform.link);
2768 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002769 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002770 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02002771
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01002772 /* We need to adjust the position of the surface
2773 * in case it was resized in a rotated state before */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002774 cposx = surface->geometry.x + cx;
2775 cposy = surface->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01002776 dposx = rotate->center.x - cposx;
2777 dposy = rotate->center.y - cposy;
2778 if (dposx != 0.0f || dposy != 0.0f) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002779 weston_surface_set_position(surface,
2780 surface->geometry.x + dposx,
2781 surface->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01002782 }
2783
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02002784 /* Repaint implies weston_surface_update_transform(), which
2785 * lazily applies the damage due to rotation update.
2786 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002787 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002788}
2789
2790static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002791rotate_grab_button(struct weston_pointer_grab *grab,
2792 uint32_t time, uint32_t button, uint32_t state_w)
Pekka Paalanen460099f2012-01-20 16:48:25 +02002793{
2794 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002795 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002796 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002797 struct shell_surface *shsurf = rotate->base.shsurf;
Daniel Stone4dbadb12012-05-30 16:31:51 +01002798 enum wl_pointer_button_state state = state_w;
Pekka Paalanen460099f2012-01-20 16:48:25 +02002799
Daniel Stone4dbadb12012-05-30 16:31:51 +01002800 if (pointer->button_count == 0 &&
2801 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03002802 if (shsurf)
2803 weston_matrix_multiply(&shsurf->rotation.rotation,
2804 &rotate->rotation);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03002805 shell_grab_end(&rotate->base);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002806 free(rotate);
2807 }
2808}
2809
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002810static const struct weston_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02002811 noop_grab_focus,
2812 rotate_grab_motion,
2813 rotate_grab_button,
2814};
2815
2816static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002817surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
Pekka Paalanen460099f2012-01-20 16:48:25 +02002818{
Pekka Paalanen460099f2012-01-20 16:48:25 +02002819 struct rotate_grab *rotate;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02002820 float dx, dy;
2821 float r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02002822
Pekka Paalanen460099f2012-01-20 16:48:25 +02002823 rotate = malloc(sizeof *rotate);
2824 if (!rotate)
2825 return;
2826
Kristian Høgsbergb2af93e2012-06-07 20:10:23 -04002827 weston_surface_to_global_float(surface->surface,
2828 surface->surface->geometry.width / 2,
2829 surface->surface->geometry.height / 2,
2830 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002831
Daniel Stone37816df2012-05-16 18:45:18 +01002832 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2833 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002834 r = sqrtf(dx * dx + dy * dy);
2835 if (r > 20.0f) {
2836 struct weston_matrix inverse;
2837
2838 weston_matrix_init(&inverse);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03002839 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002840 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01002841
2842 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03002843 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002844 } else {
2845 weston_matrix_init(&surface->rotation.rotation);
2846 weston_matrix_init(&rotate->rotation);
2847 }
2848
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03002849 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2850 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002851}
2852
2853static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002854rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
Kristian Høgsberg0c369032013-02-14 21:31:44 -05002855 void *data)
2856{
Pekka Paalanen01388e22013-04-25 13:57:44 +03002857 struct weston_surface *focus =
Kristian Høgsberg0c369032013-02-14 21:31:44 -05002858 (struct weston_surface *) seat->pointer->focus;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002859 struct weston_surface *base_surface;
Kristian Høgsberg0c369032013-02-14 21:31:44 -05002860 struct shell_surface *surface;
2861
Pekka Paalanen01388e22013-04-25 13:57:44 +03002862 base_surface = weston_surface_get_main_surface(focus);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05002863 if (base_surface == NULL)
2864 return;
2865
2866 surface = get_shell_surface(base_surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01002867 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
2868 surface->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg0c369032013-02-14 21:31:44 -05002869 return;
2870
2871 surface_rotate(surface, seat);
2872}
2873
2874static void
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04002875lower_fullscreen_layer(struct desktop_shell *shell)
2876{
2877 struct workspace *ws;
2878 struct weston_surface *surface, *prev;
2879
2880 ws = get_current_workspace(shell);
2881 wl_list_for_each_reverse_safe(surface, prev,
2882 &shell->fullscreen_layer.surface_list,
2883 layer_link)
2884 weston_surface_restack(surface, &ws->layer.surface_list);
2885}
2886
2887static void
Tiago Vignattibe143262012-04-16 17:31:41 +03002888activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01002889 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04002890{
Pekka Paalanen01388e22013-04-25 13:57:44 +03002891 struct weston_surface *main_surface;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04002892 struct focus_state *state;
Jonas Ådahl8538b222012-08-29 22:13:03 +02002893 struct workspace *ws;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002894
Pekka Paalanen01388e22013-04-25 13:57:44 +03002895 main_surface = weston_surface_get_main_surface(es);
2896
Daniel Stone37816df2012-05-16 18:45:18 +01002897 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04002898
Jonas Ådahl8538b222012-08-29 22:13:03 +02002899 state = ensure_focus_state(shell, seat);
2900 if (state == NULL)
2901 return;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04002902
2903 state->keyboard_focus = es;
2904 wl_list_remove(&state->surface_destroy_listener.link);
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04002905 wl_signal_add(&es->resource.destroy_signal,
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04002906 &state->surface_destroy_listener);
2907
Pekka Paalanen01388e22013-04-25 13:57:44 +03002908 switch (get_shell_surface_type(main_surface)) {
Alex Wu4539b082012-03-01 12:57:46 +08002909 case SHELL_SURFACE_FULLSCREEN:
2910 /* should on top of panels */
Pekka Paalanen01388e22013-04-25 13:57:44 +03002911 shell_stack_fullscreen(get_shell_surface(main_surface));
2912 shell_configure_fullscreen(get_shell_surface(main_surface));
Alex Wu4539b082012-03-01 12:57:46 +08002913 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02002914 default:
Jonas Ådahle3cddce2012-06-13 00:01:22 +02002915 ws = get_current_workspace(shell);
Pekka Paalanen01388e22013-04-25 13:57:44 +03002916 weston_surface_restack(main_surface, &ws->layer.surface_list);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002917 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04002918 }
2919}
2920
Alex Wu21858432012-04-01 20:13:08 +08002921/* no-op func for checking black surface */
2922static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002923black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
Alex Wu21858432012-04-01 20:13:08 +08002924{
2925}
2926
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01002927static bool
Alex Wu21858432012-04-01 20:13:08 +08002928is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2929{
2930 if (es->configure == black_surface_configure) {
2931 if (fs_surface)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002932 *fs_surface = (struct weston_surface *)es->configure_private;
Alex Wu21858432012-04-01 20:13:08 +08002933 return true;
2934 }
2935 return false;
2936}
2937
Kristian Høgsberg75840622011-09-06 13:48:16 -04002938static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04002939click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
Daniel Stone4dbadb12012-05-30 16:31:51 +01002940 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002941{
Daniel Stone37816df2012-05-16 18:45:18 +01002942 struct weston_seat *ws = (struct weston_seat *) seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03002943 struct desktop_shell *shell = data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002944 struct weston_surface *focus;
Pekka Paalanen01388e22013-04-25 13:57:44 +03002945 struct weston_surface *main_surface;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002946
Daniel Stone37816df2012-05-16 18:45:18 +01002947 focus = (struct weston_surface *) seat->pointer->focus;
Alex Wu9c35e6b2012-03-05 14:13:13 +08002948 if (!focus)
2949 return;
2950
Pekka Paalanen01388e22013-04-25 13:57:44 +03002951 if (is_black_surface(focus, &main_surface))
2952 focus = main_surface;
Alex Wu4539b082012-03-01 12:57:46 +08002953
Pekka Paalanen01388e22013-04-25 13:57:44 +03002954 main_surface = weston_surface_get_main_surface(focus);
2955 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04002956 return;
Kristian Høgsberg85b2e4b2012-06-21 16:49:42 -04002957
Daniel Stone325fc2d2012-05-30 16:31:58 +01002958 if (seat->pointer->grab == &seat->pointer->default_grab)
Daniel Stone37816df2012-05-16 18:45:18 +01002959 activate(shell, focus, ws);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05002960}
2961
2962static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02002963lock(struct desktop_shell *shell)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04002964{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04002965 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002966
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002967 if (shell->locked) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02002968 weston_compositor_sleep(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002969 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02002970 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002971
2972 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002973
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002974 /* Hide all surfaces by removing the fullscreen, panel and
2975 * toplevel layers. This way nothing else can show or receive
2976 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002977
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002978 wl_list_remove(&shell->panel_layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002979 wl_list_remove(&shell->fullscreen_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02002980 if (shell->showing_input_panels)
2981 wl_list_remove(&shell->input_panel_layer.link);
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04002982 wl_list_remove(&ws->layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05002983 wl_list_insert(&shell->compositor->cursor_layer.link,
2984 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002985
Pekka Paalanen77346a62011-11-30 16:26:35 +02002986 launch_screensaver(shell);
2987
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02002988 /* TODO: disable bindings that should not work while locked. */
2989
2990 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002991}
2992
2993static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02002994unlock(struct desktop_shell *shell)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002995{
Pekka Paalanend81c2162011-11-16 13:47:34 +02002996 if (!shell->locked || shell->lock_surface) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02002997 shell_fade(shell, FADE_IN);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02002998 return;
2999 }
3000
3001 /* If desktop-shell client has gone away, unlock immediately. */
3002 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003003 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003004 return;
3005 }
3006
3007 if (shell->prepare_event_sent)
3008 return;
3009
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05003010 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003011 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04003012}
3013
3014static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003015shell_fade_done(struct weston_surface_animation *animation, void *data)
3016{
3017 struct desktop_shell *shell = data;
3018
3019 shell->fade.animation = NULL;
3020
3021 switch (shell->fade.type) {
3022 case FADE_IN:
3023 weston_surface_destroy(shell->fade.surface);
3024 shell->fade.surface = NULL;
3025 break;
3026 case FADE_OUT:
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003027 lock(shell);
3028 break;
3029 }
3030}
3031
3032static void
3033shell_fade(struct desktop_shell *shell, enum fade_type type)
3034{
3035 struct weston_compositor *compositor = shell->compositor;
3036 struct weston_surface *surface;
3037 float tint;
3038
3039 switch (type) {
3040 case FADE_IN:
3041 tint = 0.0;
3042 break;
3043 case FADE_OUT:
3044 tint = 1.0;
3045 break;
3046 default:
3047 weston_log("shell: invalid fade type\n");
3048 return;
3049 }
3050
3051 shell->fade.type = type;
3052
3053 if (shell->fade.surface == NULL) {
3054 surface = weston_surface_create(compositor);
3055 if (!surface)
3056 return;
3057
3058 weston_surface_configure(surface, 0, 0, 8192, 8192);
3059 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
3060 surface->alpha = 1.0 - tint;
3061 wl_list_insert(&compositor->fade_layer.surface_list,
3062 &surface->layer_link);
3063 weston_surface_update_transform(surface);
3064 shell->fade.surface = surface;
3065 pixman_region32_init(&surface->input);
3066 }
3067
3068 if (shell->fade.animation)
3069 weston_fade_update(shell->fade.animation,
3070 shell->fade.surface->alpha, tint, 30.0);
3071 else
3072 shell->fade.animation =
3073 weston_fade_run(shell->fade.surface,
3074 1.0 - tint, tint, 30.0,
3075 shell_fade_done, shell);
3076}
3077
3078static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02003079idle_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003080{
3081 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02003082 container_of(listener, struct desktop_shell, idle_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003083
3084 shell_fade(shell, FADE_OUT);
3085 /* lock() is called from shell_fade_done() */
3086}
3087
3088static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02003089wake_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003090{
3091 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02003092 container_of(listener, struct desktop_shell, wake_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003093
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003094 unlock(shell);
3095}
3096
3097static void
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003098show_input_panels(struct wl_listener *listener, void *data)
3099{
3100 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003101 container_of(listener, struct desktop_shell,
3102 show_input_panel_listener);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003103 struct input_panel_surface *surface, *next;
3104 struct weston_surface *ws;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003105
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003106 shell->text_input.surface = (struct weston_surface*)data;
3107
Jan Arne Petersen451a9712013-02-11 15:10:11 +01003108 if (shell->showing_input_panels)
3109 return;
3110
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003111 shell->showing_input_panels = true;
3112
Jan Arne Petersencf18a322012-11-07 15:32:54 +01003113 if (!shell->locked)
3114 wl_list_insert(&shell->panel_layer.link,
3115 &shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003116
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003117 wl_list_for_each_safe(surface, next,
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003118 &shell->input_panel.surfaces, link) {
3119 ws = surface->surface;
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003120 if (!ws->buffer_ref.buffer)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003121 continue;
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003122 wl_list_insert(&shell->input_panel_layer.surface_list,
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003123 &ws->layer_link);
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02003124 weston_surface_geometry_dirty(ws);
Ander Conselvan de Oliveira231ba172012-09-14 16:12:04 +03003125 weston_surface_update_transform(ws);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003126 weston_surface_damage(ws);
3127 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003128 }
3129}
3130
3131static void
3132hide_input_panels(struct wl_listener *listener, void *data)
3133{
3134 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003135 container_of(listener, struct desktop_shell,
3136 hide_input_panel_listener);
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003137 struct weston_surface *surface, *next;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003138
Jan Arne Petersen61381972013-01-31 15:52:21 +01003139 if (!shell->showing_input_panels)
3140 return;
3141
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003142 shell->showing_input_panels = false;
3143
Jan Arne Petersen82ec9092012-12-03 15:36:02 +01003144 if (!shell->locked)
3145 wl_list_remove(&shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003146
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003147 wl_list_for_each_safe(surface, next,
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003148 &shell->input_panel_layer.surface_list, layer_link)
3149 weston_surface_unmap(surface);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003150}
3151
3152static void
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003153update_input_panels(struct wl_listener *listener, void *data)
3154{
3155 struct desktop_shell *shell =
3156 container_of(listener, struct desktop_shell,
3157 update_input_panel_listener);
3158
3159 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
3160}
3161
3162static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003163center_on_output(struct weston_surface *surface, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003164{
Giulio Camuffob8366642013-04-25 13:57:46 +03003165 int32_t surf_x, surf_y, width, height;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003166 float x, y;
Pekka Paalanen77346a62011-11-30 16:26:35 +02003167
Giulio Camuffob8366642013-04-25 13:57:46 +03003168 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height);
3169
3170 x = output->x + (output->width - width) / 2 - surf_x / 2;
3171 y = output->y + (output->height - height) / 2 - surf_y / 2;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003172
3173 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003174}
3175
3176static void
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003177weston_surface_set_initial_position (struct weston_surface *surface,
3178 struct desktop_shell *shell)
3179{
3180 struct weston_compositor *compositor = shell->compositor;
3181 int ix = 0, iy = 0;
3182 int range_x, range_y;
3183 int dx, dy, x, y, panel_height;
3184 struct weston_output *output, *target_output = NULL;
3185 struct weston_seat *seat;
3186
3187 /* As a heuristic place the new window on the same output as the
3188 * pointer. Falling back to the output containing 0, 0.
3189 *
3190 * TODO: Do something clever for touch too?
3191 */
3192 wl_list_for_each(seat, &compositor->seat_list, link) {
Kristian Høgsberg2bf87622013-05-07 23:17:41 -04003193 if (seat->pointer) {
Kristian Høgsberge3148752013-05-06 23:19:49 -04003194 ix = wl_fixed_to_int(seat->pointer->x);
3195 iy = wl_fixed_to_int(seat->pointer->y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003196 break;
3197 }
3198 }
3199
3200 wl_list_for_each(output, &compositor->output_list, link) {
3201 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
3202 target_output = output;
3203 break;
3204 }
3205 }
3206
3207 if (!target_output) {
3208 weston_surface_set_position(surface, 10 + random() % 400,
3209 10 + random() % 400);
3210 return;
3211 }
3212
3213 /* Valid range within output where the surface will still be onscreen.
3214 * If this is negative it means that the surface is bigger than
3215 * output.
3216 */
3217 panel_height = get_output_panel_height(shell, target_output);
Scott Moreau1bad5db2012-08-18 01:04:05 -06003218 range_x = target_output->width - surface->geometry.width;
3219 range_y = (target_output->height - panel_height) -
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003220 surface->geometry.height;
3221
Rob Bradford4cb88c72012-08-13 15:18:44 +01003222 if (range_x > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003223 dx = random() % range_x;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003224 else
Rob Bradford4cb88c72012-08-13 15:18:44 +01003225 dx = 0;
3226
3227 if (range_y > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003228 dy = panel_height + random() % range_y;
Rob Bradford4cb88c72012-08-13 15:18:44 +01003229 else
3230 dy = panel_height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003231
3232 x = target_output->x + dx;
3233 y = target_output->y + dy;
3234
3235 weston_surface_set_position (surface, x, y);
3236}
3237
3238static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003239map(struct desktop_shell *shell, struct weston_surface *surface,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02003240 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04003241{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003242 struct weston_compositor *compositor = shell->compositor;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02003243 struct shell_surface *shsurf = get_shell_surface(surface);
3244 enum shell_surface_type surface_type = shsurf->type;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05003245 struct weston_surface *parent;
Daniel Stoneb2104682012-05-30 16:31:56 +01003246 struct weston_seat *seat;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02003247 struct workspace *ws;
Juan Zhao96879df2012-02-07 08:45:41 +08003248 int panel_height = 0;
Giulio Camuffob8366642013-04-25 13:57:46 +03003249 int32_t surf_x, surf_y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02003250
Pekka Paalanen60921e52012-01-25 15:55:43 +02003251 surface->geometry.width = width;
3252 surface->geometry.height = height;
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02003253 weston_surface_geometry_dirty(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003254
3255 /* initial positioning, see also configure() */
3256 switch (surface_type) {
3257 case SHELL_SURFACE_TOPLEVEL:
Rob Bradfordac63e5b2012-08-13 14:07:52 +01003258 weston_surface_set_initial_position(surface, shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003259 break;
Alex Wu4539b082012-03-01 12:57:46 +08003260 case SHELL_SURFACE_FULLSCREEN:
Kristian Høgsberge4d3a2b2012-07-09 21:43:22 -04003261 center_on_output(surface, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08003262 shell_map_fullscreen(shsurf);
3263 break;
Juan Zhao96879df2012-02-07 08:45:41 +08003264 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08003265 /* use surface configure to set the geometry */
Juan Zhao96879df2012-02-07 08:45:41 +08003266 panel_height = get_output_panel_height(shell,surface->output);
Giulio Camuffob8366642013-04-25 13:57:46 +03003267 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3268 NULL, NULL);
3269 weston_surface_set_position(surface, shsurf->output->x - surf_x,
3270 shsurf->output->y + panel_height - surf_y);
Juan Zhao96879df2012-02-07 08:45:41 +08003271 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02003272 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04003273 shell_map_popup(shsurf);
Rob Bradforddb999382012-12-06 12:07:48 +00003274 break;
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02003275 case SHELL_SURFACE_NONE:
3276 weston_surface_set_position(surface,
3277 surface->geometry.x + sx,
3278 surface->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02003279 break;
Pekka Paalanen77346a62011-11-30 16:26:35 +02003280 default:
3281 ;
3282 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04003283
Pekka Paalanend3dd6e12011-11-16 13:47:33 +02003284 /* surface stacking order, see also activate() */
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003285 switch (surface_type) {
Kristian Høgsberg60c49542012-03-05 20:51:34 -05003286 case SHELL_SURFACE_POPUP:
3287 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsberg8150b192012-06-27 10:22:58 -04003288 parent = shsurf->parent;
Kristian Høgsberg60c49542012-03-05 20:51:34 -05003289 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
3290 break;
Alex Wu4539b082012-03-01 12:57:46 +08003291 case SHELL_SURFACE_FULLSCREEN:
Ander Conselvan de Oliveiraa1ff53b2012-02-15 17:02:54 +02003292 case SHELL_SURFACE_NONE:
3293 break;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02003294 default:
Jonas Ådahle3cddce2012-06-13 00:01:22 +02003295 ws = get_current_workspace(shell);
3296 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05003297 break;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003298 }
3299
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02003300 if (surface_type != SHELL_SURFACE_NONE) {
Ander Conselvan de Oliveira231ba172012-09-14 16:12:04 +03003301 weston_surface_update_transform(surface);
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02003302 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3303 surface->output = shsurf->output;
3304 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05003305
Juan Zhao7bb92f02011-12-15 11:31:51 -05003306 switch (surface_type) {
Juan Zhao7bb92f02011-12-15 11:31:51 -05003307 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03003308 if (shsurf->transient.flags ==
3309 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
3310 break;
3311 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05003312 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08003313 case SHELL_SURFACE_MAXIMIZED:
Daniel Stoneb2104682012-05-30 16:31:56 +01003314 if (!shell->locked) {
3315 wl_list_for_each(seat, &compositor->seat_list, link)
3316 activate(shell, surface, seat);
3317 }
Juan Zhao7bb92f02011-12-15 11:31:51 -05003318 break;
3319 default:
3320 break;
3321 }
3322
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05003323 if (surface_type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08003324 {
3325 switch (shell->win_animation_type) {
3326 case ANIMATION_FADE:
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +02003327 weston_fade_run(surface, 0.0, 1.0, 200.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08003328 break;
3329 case ANIMATION_ZOOM:
3330 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
3331 break;
3332 default:
3333 break;
3334 }
3335 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05003336}
3337
3338static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003339configure(struct desktop_shell *shell, struct weston_surface *surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003340 float x, float y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05003341{
Pekka Paalanen77346a62011-11-30 16:26:35 +02003342 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
3343 struct shell_surface *shsurf;
Giulio Camuffob8366642013-04-25 13:57:46 +03003344 int32_t surf_x, surf_y;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05003345
Pekka Paalanen77346a62011-11-30 16:26:35 +02003346 shsurf = get_shell_surface(surface);
3347 if (shsurf)
3348 surface_type = shsurf->type;
3349
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02003350 weston_surface_configure(surface, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003351
3352 switch (surface_type) {
Alex Wu4539b082012-03-01 12:57:46 +08003353 case SHELL_SURFACE_FULLSCREEN:
Alex Wubd3354b2012-04-17 17:20:49 +08003354 shell_stack_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08003355 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08003356 break;
Juan Zhao96879df2012-02-07 08:45:41 +08003357 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08003358 /* setting x, y and using configure to change that geometry */
Giulio Camuffob8366642013-04-25 13:57:46 +03003359 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3360 NULL, NULL);
3361 surface->geometry.x = surface->output->x - surf_x;
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05003362 surface->geometry.y = surface->output->y +
Giulio Camuffob8366642013-04-25 13:57:46 +03003363 get_output_panel_height(shell,surface->output) - surf_y;
Juan Zhao96879df2012-02-07 08:45:41 +08003364 break;
Alex Wu4539b082012-03-01 12:57:46 +08003365 case SHELL_SURFACE_TOPLEVEL:
3366 break;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003367 default:
3368 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04003369 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05003370
Alex Wu4539b082012-03-01 12:57:46 +08003371 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05003372 if (surface->output) {
Ander Conselvan de Oliveira231ba172012-09-14 16:12:04 +03003373 weston_surface_update_transform(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003374
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003375 if (surface_type == SHELL_SURFACE_MAXIMIZED)
Juan Zhao96879df2012-02-07 08:45:41 +08003376 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02003377 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04003378}
3379
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003380static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003381shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003382{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03003383 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03003384 struct desktop_shell *shell = shsurf->shell;
Giulio Camuffo184df502013-02-21 11:29:21 +01003385
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03003386 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003387
Giulio Camuffo5085a752013-03-25 21:42:45 +01003388 if (!weston_surface_is_mapped(es) && !wl_list_empty(&shsurf->popup.grab_link)) {
3389 remove_popup_grab(shsurf);
3390 }
3391
Giulio Camuffo184df502013-02-21 11:29:21 +01003392 if (width == 0)
3393 return;
3394
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04003395 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04003396 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04003397 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04003398 type_changed = 1;
3399 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04003400
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003401 if (!weston_surface_is_mapped(es)) {
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003402 map(shell, es, width, height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04003403 } else if (type_changed || sx != 0 || sy != 0 ||
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003404 es->geometry.width != width ||
3405 es->geometry.height != height) {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003406 float from_x, from_y;
3407 float to_x, to_y;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003408
3409 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
3410 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
3411 configure(shell, es,
3412 es->geometry.x + to_x - from_x,
3413 es->geometry.y + to_y - from_y,
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003414 width, height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003415 }
3416}
3417
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03003418static void launch_desktop_shell_process(void *data);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003419
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04003420static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003421desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003422{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003423 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03003424 struct desktop_shell *shell =
3425 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003426
3427 shell->child.process.pid = 0;
3428 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003429
3430 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
3431 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05003432 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003433 shell->child.deathstamp = time;
3434 shell->child.deathcount = 0;
3435 }
3436
3437 shell->child.deathcount++;
3438 if (shell->child.deathcount > 5) {
Martin Minarik6d118362012-06-07 18:01:59 +02003439 weston_log("weston-desktop-shell died, giving up.\n");
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003440 return;
3441 }
3442
Martin Minarik6d118362012-06-07 18:01:59 +02003443 weston_log("weston-desktop-shell died, respawning...\n");
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02003444 launch_desktop_shell_process(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003445}
3446
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03003447static void
3448launch_desktop_shell_process(void *data)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003449{
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03003450 struct desktop_shell *shell = data;
Kristian Høgsberg9724b512012-01-03 14:35:49 -05003451 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003452
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003453 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02003454 &shell->child.process,
3455 shell_exe,
3456 desktop_shell_sigchld);
3457
3458 if (!shell->child.client)
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03003459 weston_log("not able to start %s\n", shell_exe);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02003460}
3461
3462static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04003463bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3464{
Tiago Vignattibe143262012-04-16 17:31:41 +03003465 struct desktop_shell *shell = data;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04003466
3467 wl_client_add_object(client, &wl_shell_interface,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003468 &shell_implementation, id, shell);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04003469}
3470
Kristian Høgsberg75840622011-09-06 13:48:16 -04003471static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003472unbind_desktop_shell(struct wl_resource *resource)
3473{
Tiago Vignattibe143262012-04-16 17:31:41 +03003474 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003475
3476 if (shell->locked)
3477 resume_desktop(shell);
3478
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003479 shell->child.desktop_shell = NULL;
3480 shell->prepare_event_sent = false;
3481 free(resource);
3482}
3483
3484static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003485bind_desktop_shell(struct wl_client *client,
3486 void *data, uint32_t version, uint32_t id)
3487{
Tiago Vignattibe143262012-04-16 17:31:41 +03003488 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02003489 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003490
Pekka Paalanenbbe60522011-11-03 14:11:33 +02003491 resource = wl_client_add_object(client, &desktop_shell_interface,
3492 &desktop_shell_implementation,
3493 id, shell);
3494
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003495 if (client == shell->child.client) {
3496 resource->destroy = unbind_desktop_shell;
3497 shell->child.desktop_shell = resource;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02003498 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003499 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02003500
3501 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3502 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003503 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003504}
3505
Pekka Paalanen6e168112011-11-24 11:34:05 +02003506static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003507screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003508{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003509 struct desktop_shell *shell = surface->configure_private;
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003510
Giulio Camuffo184df502013-02-21 11:29:21 +01003511 if (width == 0)
3512 return;
3513
Pekka Paalanen3a1d07d2012-12-20 14:02:13 +02003514 /* XXX: starting weston-screensaver beforehand does not work */
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003515 if (!shell->locked)
3516 return;
3517
3518 center_on_output(surface, surface->output);
3519
3520 if (wl_list_empty(&surface->layer_link)) {
3521 wl_list_insert(shell->lock_layer.surface_list.prev,
3522 &surface->layer_link);
Ander Conselvan de Oliveira231ba172012-09-14 16:12:04 +03003523 weston_surface_update_transform(surface);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02003524 wl_event_source_timer_update(shell->screensaver.timer,
3525 shell->screensaver.duration);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02003526 shell_fade(shell, FADE_IN);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003527 }
3528}
3529
3530static void
Pekka Paalanen6e168112011-11-24 11:34:05 +02003531screensaver_set_surface(struct wl_client *client,
3532 struct wl_resource *resource,
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003533 struct wl_resource *surface_resource,
Pekka Paalanen6e168112011-11-24 11:34:05 +02003534 struct wl_resource *output_resource)
3535{
Tiago Vignattibe143262012-04-16 17:31:41 +03003536 struct desktop_shell *shell = resource->data;
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003537 struct weston_surface *surface = surface_resource->data;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003538 struct weston_output *output = output_resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003539
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04003540 surface->configure = screensaver_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003541 surface->configure_private = shell;
Pekka Paalanen77346a62011-11-30 16:26:35 +02003542 surface->output = output;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003543}
3544
3545static const struct screensaver_interface screensaver_implementation = {
3546 screensaver_set_surface
3547};
3548
3549static void
3550unbind_screensaver(struct wl_resource *resource)
3551{
Tiago Vignattibe143262012-04-16 17:31:41 +03003552 struct desktop_shell *shell = resource->data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003553
Pekka Paalanen77346a62011-11-30 16:26:35 +02003554 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003555 free(resource);
3556}
3557
3558static void
3559bind_screensaver(struct wl_client *client,
3560 void *data, uint32_t version, uint32_t id)
3561{
Tiago Vignattibe143262012-04-16 17:31:41 +03003562 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003563 struct wl_resource *resource;
3564
3565 resource = wl_client_add_object(client, &screensaver_interface,
3566 &screensaver_implementation,
3567 id, shell);
3568
Pekka Paalanen77346a62011-11-30 16:26:35 +02003569 if (shell->screensaver.binding == NULL) {
Pekka Paalanen6e168112011-11-24 11:34:05 +02003570 resource->destroy = unbind_screensaver;
Pekka Paalanen77346a62011-11-30 16:26:35 +02003571 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02003572 return;
3573 }
3574
3575 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3576 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003577 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02003578}
3579
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003580static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003581input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003582{
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003583 struct input_panel_surface *ip_surface = surface->configure_private;
3584 struct desktop_shell *shell = ip_surface->shell;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01003585 struct weston_mode *mode;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01003586 float x, y;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003587 uint32_t show_surface = 0;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01003588
Giulio Camuffo184df502013-02-21 11:29:21 +01003589 if (width == 0)
3590 return;
3591
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003592 if (!weston_surface_is_mapped(surface)) {
3593 if (!shell->showing_input_panels)
3594 return;
3595
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003596 show_surface = 1;
3597 }
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01003598
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003599 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003600
3601 if (ip_surface->panel) {
3602 x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2;
3603 y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2;
3604 } else {
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003605 mode = ip_surface->output->current;
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003606
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003607 x = ip_surface->output->x + (mode->width - width) / 2;
3608 y = ip_surface->output->y + mode->height - height;
3609 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003610
3611 weston_surface_configure(surface,
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003612 x, y,
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02003613 width, height);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003614
3615 if (show_surface) {
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003616 wl_list_insert(&shell->input_panel_layer.surface_list,
3617 &surface->layer_link);
3618 weston_surface_update_transform(surface);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003619 weston_surface_damage(surface);
3620 weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL);
3621 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003622}
3623
3624static void
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003625destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003626{
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003627 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003628 wl_list_remove(&input_panel_surface->link);
3629
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003630 input_panel_surface->surface->configure = NULL;
3631
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003632 free(input_panel_surface);
3633}
3634
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003635static struct input_panel_surface *
3636get_input_panel_surface(struct weston_surface *surface)
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003637{
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003638 if (surface->configure == input_panel_configure) {
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003639 return surface->configure_private;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003640 } else {
3641 return NULL;
3642 }
3643}
3644
3645static void
3646input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
3647{
3648 struct input_panel_surface *ipsurface = container_of(listener,
3649 struct input_panel_surface,
3650 surface_destroy_listener);
3651
3652 if (ipsurface->resource.client) {
3653 wl_resource_destroy(&ipsurface->resource);
3654 } else {
3655 wl_signal_emit(&ipsurface->resource.destroy_signal,
3656 &ipsurface->resource);
3657 destroy_input_panel_surface(ipsurface);
3658 }
3659}
3660static struct input_panel_surface *
3661create_input_panel_surface(struct desktop_shell *shell,
3662 struct weston_surface *surface)
3663{
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003664 struct input_panel_surface *input_panel_surface;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003665
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003666 input_panel_surface = calloc(1, sizeof *input_panel_surface);
3667 if (!input_panel_surface)
3668 return NULL;
3669
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04003670 surface->configure = input_panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003671 surface->configure_private = input_panel_surface;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003672
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003673 input_panel_surface->shell = shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003674
3675 input_panel_surface->surface = surface;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003676
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003677 wl_signal_init(&input_panel_surface->resource.destroy_signal);
3678 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04003679 wl_signal_add(&surface->resource.destroy_signal,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003680 &input_panel_surface->surface_destroy_listener);
3681
3682 wl_list_init(&input_panel_surface->link);
3683
3684 return input_panel_surface;
3685}
3686
3687static void
3688input_panel_surface_set_toplevel(struct wl_client *client,
3689 struct wl_resource *resource,
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003690 struct wl_resource *output_resource,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003691 uint32_t position)
3692{
3693 struct input_panel_surface *input_panel_surface = resource->data;
3694 struct desktop_shell *shell = input_panel_surface->shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02003695
3696 wl_list_insert(&shell->input_panel.surfaces,
3697 &input_panel_surface->link);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003698
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003699 input_panel_surface->output = output_resource->data;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003700 input_panel_surface->panel = 0;
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02003701
3702 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__,
3703 input_panel_surface->panel,
3704 input_panel_surface->output);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003705}
3706
3707static void
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02003708input_panel_surface_set_overlay_panel(struct wl_client *client,
3709 struct wl_resource *resource)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003710{
3711 struct input_panel_surface *input_panel_surface = resource->data;
3712 struct desktop_shell *shell = input_panel_surface->shell;
3713
3714 wl_list_insert(&shell->input_panel.surfaces,
3715 &input_panel_surface->link);
3716
3717 input_panel_surface->panel = 1;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003718}
3719
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02003720static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02003721 input_panel_surface_set_toplevel,
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02003722 input_panel_surface_set_overlay_panel
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003723};
3724
3725static void
3726destroy_input_panel_surface_resource(struct wl_resource *resource)
3727{
3728 struct input_panel_surface *ipsurf = resource->data;
3729
3730 destroy_input_panel_surface(ipsurf);
3731}
3732
3733static void
3734input_panel_get_input_panel_surface(struct wl_client *client,
3735 struct wl_resource *resource,
3736 uint32_t id,
3737 struct wl_resource *surface_resource)
3738{
3739 struct weston_surface *surface = surface_resource->data;
3740 struct desktop_shell *shell = resource->data;
3741 struct input_panel_surface *ipsurf;
3742
3743 if (get_input_panel_surface(surface)) {
3744 wl_resource_post_error(surface_resource,
3745 WL_DISPLAY_ERROR_INVALID_OBJECT,
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02003746 "wl_input_panel::get_input_panel_surface already requested");
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003747 return;
3748 }
3749
3750 ipsurf = create_input_panel_surface(shell, surface);
3751 if (!ipsurf) {
3752 wl_resource_post_error(surface_resource,
3753 WL_DISPLAY_ERROR_INVALID_OBJECT,
3754 "surface->configure already set");
3755 return;
3756 }
3757
3758 ipsurf->resource.destroy = destroy_input_panel_surface_resource;
3759 ipsurf->resource.object.id = id;
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02003760 ipsurf->resource.object.interface = &wl_input_panel_surface_interface;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003761 ipsurf->resource.object.implementation =
3762 (void (**)(void)) &input_panel_surface_implementation;
3763 ipsurf->resource.data = ipsurf;
3764
3765 wl_client_add_resource(client, &ipsurf->resource);
3766}
3767
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02003768static const struct wl_input_panel_interface input_panel_implementation = {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01003769 input_panel_get_input_panel_surface
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003770};
3771
3772static void
3773unbind_input_panel(struct wl_resource *resource)
3774{
3775 struct desktop_shell *shell = resource->data;
3776
3777 shell->input_panel.binding = NULL;
3778 free(resource);
3779}
3780
3781static void
3782bind_input_panel(struct wl_client *client,
3783 void *data, uint32_t version, uint32_t id)
3784{
3785 struct desktop_shell *shell = data;
3786 struct wl_resource *resource;
3787
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02003788 resource = wl_client_add_object(client, &wl_input_panel_interface,
Jan Arne Petersen42feced2012-06-21 21:52:17 +02003789 &input_panel_implementation,
3790 id, shell);
3791
3792 if (shell->input_panel.binding == NULL) {
3793 resource->destroy = unbind_input_panel;
3794 shell->input_panel.binding = resource;
3795 return;
3796 }
3797
3798 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3799 "interface object already bound");
3800 wl_resource_destroy(resource);
3801}
3802
Kristian Høgsberg07045392012-02-19 18:52:44 -05003803struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03003804 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003805 struct weston_surface *current;
3806 struct wl_listener listener;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003807 struct weston_keyboard_grab grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003808};
3809
3810static void
3811switcher_next(struct switcher *switcher)
3812{
Kristian Høgsberg07045392012-02-19 18:52:44 -05003813 struct weston_surface *surface;
3814 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04003815 struct shell_surface *shsurf;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003816 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003817
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003818 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05003819 switch (get_shell_surface_type(surface)) {
3820 case SHELL_SURFACE_TOPLEVEL:
3821 case SHELL_SURFACE_FULLSCREEN:
3822 case SHELL_SURFACE_MAXIMIZED:
3823 if (first == NULL)
3824 first = surface;
3825 if (prev == switcher->current)
3826 next = surface;
3827 prev = surface;
Scott Moreau02709af2012-05-22 01:54:10 -06003828 surface->alpha = 0.25;
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02003829 weston_surface_geometry_dirty(surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003830 weston_surface_damage(surface);
3831 break;
3832 default:
3833 break;
3834 }
Alex Wu1659daa2012-04-01 20:13:09 +08003835
3836 if (is_black_surface(surface, NULL)) {
Scott Moreau02709af2012-05-22 01:54:10 -06003837 surface->alpha = 0.25;
Pekka Paalanenc3ce7382013-03-08 14:56:49 +02003838 weston_surface_geometry_dirty(surface);
Alex Wu1659daa2012-04-01 20:13:09 +08003839 weston_surface_damage(surface);
3840 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05003841 }
3842
3843 if (next == NULL)
3844 next = first;
3845
Alex Wu07b26062012-03-12 16:06:01 +08003846 if (next == NULL)
3847 return;
3848
Kristian Høgsberg07045392012-02-19 18:52:44 -05003849 wl_list_remove(&switcher->listener.link);
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04003850 wl_signal_add(&next->resource.destroy_signal, &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003851
3852 switcher->current = next;
Kristian Høgsberga416fa12012-05-21 14:06:52 -04003853 next->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08003854
Kristian Høgsberg32e56862012-04-02 22:18:58 -04003855 shsurf = get_shell_surface(switcher->current);
3856 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Kristian Høgsberga416fa12012-05-21 14:06:52 -04003857 shsurf->fullscreen.black_surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003858}
3859
3860static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003861switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05003862{
3863 struct switcher *switcher =
3864 container_of(listener, struct switcher, listener);
3865
3866 switcher_next(switcher);
3867}
3868
3869static void
Daniel Stone351eb612012-05-31 15:27:47 -04003870switcher_destroy(struct switcher *switcher)
Kristian Høgsberg07045392012-02-19 18:52:44 -05003871{
Kristian Høgsberg07045392012-02-19 18:52:44 -05003872 struct weston_surface *surface;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003873 struct weston_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003874 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003875
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003876 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
Kristian Høgsberga416fa12012-05-21 14:06:52 -04003877 surface->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003878 weston_surface_damage(surface);
3879 }
3880
Alex Wu07b26062012-03-12 16:06:01 +08003881 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01003882 activate(switcher->shell, switcher->current,
3883 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003884 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003885 weston_keyboard_end_grab(keyboard);
3886 if (keyboard->input_method_resource)
3887 keyboard->grab = &keyboard->input_method_grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003888 free(switcher);
3889}
3890
3891static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003892switcher_key(struct weston_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +01003893 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsberg07045392012-02-19 18:52:44 -05003894{
3895 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stonec9785ea2012-05-30 16:31:52 +01003896 enum wl_keyboard_key_state state = state_w;
Daniel Stone351eb612012-05-31 15:27:47 -04003897
Daniel Stonec9785ea2012-05-30 16:31:52 +01003898 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
Daniel Stone351eb612012-05-31 15:27:47 -04003899 switcher_next(switcher);
3900}
3901
3902static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003903switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
Daniel Stone351eb612012-05-31 15:27:47 -04003904 uint32_t mods_depressed, uint32_t mods_latched,
3905 uint32_t mods_locked, uint32_t group)
3906{
3907 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01003908 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003909
Daniel Stone351eb612012-05-31 15:27:47 -04003910 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
3911 switcher_destroy(switcher);
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04003912}
Kristian Høgsberg07045392012-02-19 18:52:44 -05003913
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003914static const struct weston_keyboard_grab_interface switcher_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -04003915 switcher_key,
3916 switcher_modifier,
Kristian Høgsberg07045392012-02-19 18:52:44 -05003917};
3918
3919static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003920switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003921 void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05003922{
Tiago Vignattibe143262012-04-16 17:31:41 +03003923 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003924 struct switcher *switcher;
3925
3926 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04003927 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003928 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003929 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05003930 wl_list_init(&switcher->listener.link);
3931
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003932 lower_fullscreen_layer(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003933 switcher->grab.interface = &switcher_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003934 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
3935 weston_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05003936 switcher_next(switcher);
3937}
3938
Pekka Paalanen3c647232011-12-22 13:43:43 +02003939static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003940backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003941 void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02003942{
3943 struct weston_compositor *compositor = data;
3944 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03003945 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02003946
3947 /* TODO: we're limiting to simple use cases, where we assume just
3948 * control on the primary display. We'd have to extend later if we
3949 * ever get support for setting backlights on random desktop LCD
3950 * panels though */
3951 output = get_default_output(compositor);
3952 if (!output)
3953 return;
3954
3955 if (!output->set_backlight)
3956 return;
3957
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03003958 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
3959 backlight_new = output->backlight_current - 25;
3960 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
3961 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02003962
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03003963 if (backlight_new < 5)
3964 backlight_new = 5;
3965 if (backlight_new > 255)
3966 backlight_new = 255;
3967
3968 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02003969 output->set_backlight(output, output->backlight_current);
3970}
3971
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02003972struct debug_binding_grab {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003973 struct weston_keyboard_grab grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02003974 struct weston_seat *seat;
3975 uint32_t key[2];
3976 int key_released[2];
3977};
3978
3979static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04003980debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02003981 uint32_t key, uint32_t state)
3982{
3983 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
3984 struct wl_resource *resource;
3985 struct wl_display *display;
3986 uint32_t serial;
3987 int send = 0, terminate = 0;
3988 int check_binding = 1;
3989 int i;
3990
3991 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
3992 /* Do not run bindings on key releases */
3993 check_binding = 0;
3994
3995 for (i = 0; i < 2; i++)
3996 if (key == db->key[i])
3997 db->key_released[i] = 1;
3998
3999 if (db->key_released[0] && db->key_released[1]) {
4000 /* All key releases been swalled so end the grab */
4001 terminate = 1;
4002 } else if (key != db->key[0] && key != db->key[1]) {
4003 /* Should not swallow release of other keys */
4004 send = 1;
4005 }
4006 } else if (key == db->key[0] && !db->key_released[0]) {
4007 /* Do not check bindings for the first press of the binding
4008 * key. This allows it to be used as a debug shortcut.
4009 * We still need to swallow this event. */
4010 check_binding = 0;
4011 } else if (db->key[1]) {
4012 /* If we already ran a binding don't process another one since
4013 * we can't keep track of all the binding keys that were
4014 * pressed in order to swallow the release events. */
4015 send = 1;
4016 check_binding = 0;
4017 }
4018
4019 if (check_binding) {
4020 struct weston_compositor *ec = db->seat->compositor;
4021
4022 if (weston_compositor_run_debug_binding(ec, db->seat, time,
4023 key, state)) {
4024 /* We ran a binding so swallow the press and keep the
4025 * grab to swallow the released too. */
4026 send = 0;
4027 terminate = 0;
4028 db->key[1] = key;
4029 } else {
4030 /* Terminate the grab since the key pressed is not a
4031 * debug binding key. */
4032 send = 1;
4033 terminate = 1;
4034 }
4035 }
4036
4037 if (send) {
4038 resource = grab->keyboard->focus_resource;
4039
4040 if (resource) {
4041 display = wl_client_get_display(resource->client);
4042 serial = wl_display_next_serial(display);
4043 wl_keyboard_send_key(resource, serial, time, key, state);
4044 }
4045 }
4046
4047 if (terminate) {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04004048 weston_keyboard_end_grab(grab->keyboard);
4049 if (grab->keyboard->input_method_resource)
4050 grab->keyboard->grab = &grab->keyboard->input_method_grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004051 free(db);
4052 }
4053}
4054
4055static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04004056debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004057 uint32_t mods_depressed, uint32_t mods_latched,
4058 uint32_t mods_locked, uint32_t group)
4059{
4060 struct wl_resource *resource;
4061
4062 resource = grab->keyboard->focus_resource;
4063 if (!resource)
4064 return;
4065
4066 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
4067 mods_latched, mods_locked, group);
4068}
4069
Kristian Høgsberg29139d42013-04-18 15:25:39 -04004070struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004071 debug_binding_key,
4072 debug_binding_modifiers
4073};
4074
4075static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004076debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004077{
4078 struct debug_binding_grab *grab;
4079
4080 grab = calloc(1, sizeof *grab);
4081 if (!grab)
4082 return;
4083
4084 grab->seat = (struct weston_seat *) seat;
4085 grab->key[0] = key;
4086 grab->grab.interface = &debug_binding_keyboard_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04004087 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004088}
4089
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05004090static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004091force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01004092 void *data)
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004093{
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04004094 struct weston_surface *focus_surface;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004095 struct wl_client *client;
Tiago Vignatti1d01b012012-09-27 17:48:36 +03004096 struct desktop_shell *shell = data;
4097 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004098 pid_t pid;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004099
Philipp Brüschweiler6cef0092012-08-13 21:27:27 +02004100 focus_surface = seat->keyboard->focus;
4101 if (!focus_surface)
4102 return;
4103
Tiago Vignatti1d01b012012-09-27 17:48:36 +03004104 wl_signal_emit(&compositor->kill_signal, focus_surface);
4105
Philipp Brüschweiler6cef0092012-08-13 21:27:27 +02004106 client = focus_surface->resource.client;
Tiago Vignatti920f1972012-09-27 17:48:35 +03004107 wl_client_get_credentials(client, &pid, NULL, NULL);
4108
4109 /* Skip clients that we launched ourselves (the credentials of
4110 * the socketpair is ours) */
4111 if (pid == getpid())
4112 return;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004113
Daniel Stone325fc2d2012-05-30 16:31:58 +01004114 kill(pid, SIGKILL);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04004115}
4116
4117static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004118workspace_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004119 uint32_t key, void *data)
4120{
4121 struct desktop_shell *shell = data;
4122 unsigned int new_index = shell->workspaces.current;
4123
Kristian Høgsbergce345b02012-06-25 21:35:29 -04004124 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004125 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004126 if (new_index != 0)
4127 new_index--;
4128
4129 change_workspace(shell, new_index);
4130}
4131
4132static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004133workspace_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004134 uint32_t key, void *data)
4135{
4136 struct desktop_shell *shell = data;
4137 unsigned int new_index = shell->workspaces.current;
4138
Kristian Høgsbergce345b02012-06-25 21:35:29 -04004139 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004140 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004141 if (new_index < shell->workspaces.num - 1)
4142 new_index++;
4143
4144 change_workspace(shell, new_index);
4145}
4146
4147static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004148workspace_f_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004149 uint32_t key, void *data)
4150{
4151 struct desktop_shell *shell = data;
4152 unsigned int new_index;
4153
Kristian Høgsbergce345b02012-06-25 21:35:29 -04004154 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004155 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004156 new_index = key - KEY_F1;
4157 if (new_index >= shell->workspaces.num)
4158 new_index = shell->workspaces.num - 1;
4159
4160 change_workspace(shell, new_index);
4161}
4162
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02004163static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004164workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02004165 uint32_t key, void *data)
4166{
4167 struct desktop_shell *shell = data;
4168 unsigned int new_index = shell->workspaces.current;
4169
4170 if (shell->locked)
4171 return;
4172
4173 if (new_index != 0)
4174 new_index--;
4175
4176 take_surface_to_workspace_by_seat(shell, seat, new_index);
4177}
4178
4179static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004180workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02004181 uint32_t key, void *data)
4182{
4183 struct desktop_shell *shell = data;
4184 unsigned int new_index = shell->workspaces.current;
4185
4186 if (shell->locked)
4187 return;
4188
4189 if (new_index < shell->workspaces.num - 1)
4190 new_index++;
4191
4192 take_surface_to_workspace_by_seat(shell, seat, new_index);
4193}
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004194
4195static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04004196shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02004197{
Tiago Vignattibe143262012-04-16 17:31:41 +03004198 struct desktop_shell *shell =
4199 container_of(listener, struct desktop_shell, destroy_listener);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004200 struct workspace **ws;
Pekka Paalanen3c647232011-12-22 13:43:43 +02004201
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02004202 if (shell->child.client)
4203 wl_client_destroy(shell->child.client);
4204
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004205 wl_list_remove(&shell->idle_listener.link);
4206 wl_list_remove(&shell->wake_listener.link);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004207 wl_list_remove(&shell->show_input_panel_listener.link);
4208 wl_list_remove(&shell->hide_input_panel_listener.link);
Kristian Høgsberg88c16072012-05-16 08:04:19 -04004209
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004210 wl_array_for_each(ws, &shell->workspaces.array)
4211 workspace_destroy(*ws);
4212 wl_array_release(&shell->workspaces.array);
4213
Pekka Paalanen3c647232011-12-22 13:43:43 +02004214 free(shell->screensaver.path);
4215 free(shell);
4216}
4217
Tiago Vignatti0b52d482012-04-20 18:54:25 +03004218static void
4219shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
4220{
4221 uint32_t mod;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004222 int i, num_workspace_bindings;
Tiago Vignatti0b52d482012-04-20 18:54:25 +03004223
4224 /* fixed bindings */
Daniel Stone325fc2d2012-05-30 16:31:58 +01004225 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
4226 MODIFIER_CTRL | MODIFIER_ALT,
4227 terminate_binding, ec);
4228 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
4229 click_to_activate_binding,
4230 shell);
4231 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4232 MODIFIER_SUPER | MODIFIER_ALT,
4233 surface_opacity_binding, NULL);
4234 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4235 MODIFIER_SUPER, zoom_axis_binding,
4236 NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03004237
4238 /* configurable bindings */
4239 mod = shell->binding_modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +01004240 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
4241 zoom_key_binding, NULL);
4242 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
4243 zoom_key_binding, NULL);
4244 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
4245 shell);
4246 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
4247 resize_binding, shell);
4248 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
4249 rotate_binding, NULL);
4250 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
4251 shell);
4252 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
4253 ec);
4254 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
4255 backlight_binding, ec);
4256 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
4257 ec);
4258 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
4259 backlight_binding, ec);
Daniel Stone325fc2d2012-05-30 16:31:58 +01004260 weston_compositor_add_key_binding(ec, KEY_K, mod,
4261 force_kill_binding, shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004262 weston_compositor_add_key_binding(ec, KEY_UP, mod,
4263 workspace_up_binding, shell);
4264 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
4265 workspace_down_binding, shell);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02004266 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
4267 workspace_move_surface_up_binding,
4268 shell);
4269 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
4270 workspace_move_surface_down_binding,
4271 shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004272
4273 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
4274 if (shell->workspaces.num > 1) {
4275 num_workspace_bindings = shell->workspaces.num;
4276 if (num_workspace_bindings > 6)
4277 num_workspace_bindings = 6;
4278 for (i = 0; i < num_workspace_bindings; i++)
4279 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
4280 workspace_f_binding,
4281 shell);
4282 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02004283
4284 /* Debug bindings */
4285 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
4286 debug_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03004287}
4288
Kristian Høgsberg1c562182011-05-02 22:09:20 -04004289WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -05004290module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -07004291 int *argc, char *argv[])
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004292{
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04004293 struct weston_seat *seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03004294 struct desktop_shell *shell;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004295 struct workspace **pws;
4296 unsigned int i;
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004297 struct wl_event_loop *loop;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004298
4299 shell = malloc(sizeof *shell);
4300 if (shell == NULL)
4301 return -1;
4302
Kristian Høgsbergf0d91162011-10-11 22:44:23 -04004303 memset(shell, 0, sizeof *shell);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004304 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04004305
4306 shell->destroy_listener.notify = shell_destroy;
4307 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004308 shell->idle_listener.notify = idle_handler;
4309 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
4310 shell->wake_listener.notify = wake_handler;
4311 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004312 shell->show_input_panel_listener.notify = show_input_panels;
4313 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
4314 shell->hide_input_panel_listener.notify = hide_input_panels;
4315 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004316 shell->update_input_panel_listener.notify = update_input_panels;
4317 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06004318 ec->ping_handler = ping_handler;
Kristian Høgsberg82a1d112012-07-19 14:02:00 -04004319 ec->shell_interface.shell = shell;
Tiago Vignattibc052c92012-04-19 16:18:18 +03004320 ec->shell_interface.create_shell_surface = create_shell_surface;
4321 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04004322 ec->shell_interface.set_transient = set_transient;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05004323 ec->shell_interface.set_fullscreen = set_fullscreen;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04004324 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04004325 ec->shell_interface.resize = surface_resize;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004326
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004327 wl_list_init(&shell->input_panel.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004328
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004329 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
4330 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004331 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
4332 weston_layer_init(&shell->lock_layer, NULL);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004333 weston_layer_init(&shell->input_panel_layer, NULL);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004334
4335 wl_array_init(&shell->workspaces.array);
Jonas Ådahle9d22502012-08-29 22:13:01 +02004336 wl_list_init(&shell->workspaces.client_list);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004337
Ossama Othmana50e6e42013-05-14 09:48:26 -07004338 shell_configuration(shell, ec->config_fd);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02004339
Jonas Ådahle3cddce2012-06-13 00:01:22 +02004340 for (i = 0; i < shell->workspaces.num; i++) {
4341 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
4342 if (pws == NULL)
4343 return -1;
4344
4345 *pws = workspace_create();
4346 if (*pws == NULL)
4347 return -1;
4348 }
4349 activate_workspace(shell, 0);
4350
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02004351 wl_list_init(&shell->workspaces.anim_sticky_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02004352 wl_list_init(&shell->workspaces.animation.link);
4353 shell->workspaces.animation.frame = animate_workspace_change_frame;
4354
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004355 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
4356 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004357 return -1;
4358
Kristian Høgsberg75840622011-09-06 13:48:16 -04004359 if (wl_display_add_global(ec->wl_display,
4360 &desktop_shell_interface,
4361 shell, bind_desktop_shell) == NULL)
4362 return -1;
4363
Pekka Paalanen6e168112011-11-24 11:34:05 +02004364 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
4365 shell, bind_screensaver) == NULL)
4366 return -1;
4367
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02004368 if (wl_display_add_global(ec->wl_display, &wl_input_panel_interface,
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004369 shell, bind_input_panel) == NULL)
4370 return -1;
4371
Jonas Ådahle9d22502012-08-29 22:13:01 +02004372 if (wl_display_add_global(ec->wl_display, &workspace_manager_interface,
4373 shell, bind_workspace_manager) == NULL)
4374 return -1;
4375
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05004376 shell->child.deathstamp = weston_compositor_get_time();
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004377
4378 loop = wl_display_get_event_loop(ec->wl_display);
4379 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004380
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02004381 shell->screensaver.timer =
4382 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
4383
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04004384 wl_list_for_each(seat, &ec->seat_list, link)
4385 create_pointer_focus_listener(seat);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04004386
Tiago Vignatti0b52d482012-04-20 18:54:25 +03004387 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04004388
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004389 shell_fade(shell, FADE_IN);
4390
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05004391 return 0;
4392}