blob: 804a57e6caf985d5323752ddb192985e2cb15902 [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.
Daniel Stonedf8133b2013-11-19 11:37:14 +01004 * Copyright © 2013 Raspberry Pi Foundation
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05005 *
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
15 *
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 */
24
Daniel Stonec228e232013-05-22 18:03:19 +030025#include "config.h"
26
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050027#include <stdlib.h>
Kristian Høgsberg75840622011-09-06 13:48:16 -040028#include <stdio.h>
Pekka Paalanen9ef3e012011-11-15 13:34:48 +020029#include <stdbool.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050030#include <string.h>
31#include <unistd.h>
Kristian Høgsberg07937562011-04-12 17:25:42 -040032#include <linux/input.h>
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020033#include <assert.h>
Pekka Paalanen18027e52011-12-02 16:31:49 +020034#include <signal.h>
Pekka Paalanen460099f2012-01-20 16:48:25 +020035#include <math.h>
Kristian Høgsberg92a57db2012-05-26 13:41:06 -040036#include <sys/types.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050037
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050038#include "compositor.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040039#include "desktop-shell-server-protocol.h"
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +010040#include "input-method-server-protocol.h"
Jonas Ådahle9d22502012-08-29 22:13:01 +020041#include "workspaces-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020042#include "../shared/config-parser.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050043
Jonas Ådahle3cddce2012-06-13 00:01:22 +020044#define DEFAULT_NUM_WORKSPACES 1
Jonas Ådahl62fcd042012-06-13 00:01:23 +020045#define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
Jonas Ådahle3cddce2012-06-13 00:01:22 +020046
Juan Zhaoe10d2792012-04-25 19:09:52 +080047enum animation_type {
48 ANIMATION_NONE,
49
50 ANIMATION_ZOOM,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +010051 ANIMATION_FADE,
52 ANIMATION_DIM_LAYER,
Juan Zhaoe10d2792012-04-25 19:09:52 +080053};
54
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +020055enum fade_type {
56 FADE_IN,
57 FADE_OUT
58};
59
Daniel Stonedf8133b2013-11-19 11:37:14 +010060enum exposay_target_state {
61 EXPOSAY_TARGET_OVERVIEW, /* show all windows */
62 EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */
63 EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */
64};
65
66enum exposay_layout_state {
67 EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */
68 EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */
69 EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */
70 EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */
71};
72
Jonas Ådahl04769742012-06-13 00:01:24 +020073struct focus_state {
74 struct weston_seat *seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -040075 struct workspace *ws;
Jonas Ådahl04769742012-06-13 00:01:24 +020076 struct weston_surface *keyboard_focus;
77 struct wl_list link;
78 struct wl_listener seat_destroy_listener;
79 struct wl_listener surface_destroy_listener;
80};
81
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +010082struct focus_surface {
83 struct weston_surface *surface;
84 struct weston_view *view;
85 struct weston_transform workspace_transform;
86};
87
Jonas Ådahle3cddce2012-06-13 00:01:22 +020088struct workspace {
89 struct weston_layer layer;
Jonas Ådahl04769742012-06-13 00:01:24 +020090
91 struct wl_list focus_list;
92 struct wl_listener seat_destroyed_listener;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +010093
94 struct focus_surface *fsurf_front;
95 struct focus_surface *fsurf_back;
96 struct weston_view_animation *focus_animation;
Jonas Ådahle3cddce2012-06-13 00:01:22 +020097};
98
Philipp Brüschweiler88013572012-08-06 13:44:42 +020099struct input_panel_surface {
Jason Ekstrand51e5b142013-06-14 10:07:58 -0500100 struct wl_resource *resource;
101 struct wl_signal destroy_signal;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +0100102
103 struct desktop_shell *shell;
104
Philipp Brüschweiler88013572012-08-06 13:44:42 +0200105 struct wl_list link;
106 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500107 struct weston_view *view;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +0100108 struct wl_listener surface_destroy_listener;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +0200109
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +0200110 struct weston_output *output;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +0200111 uint32_t panel;
Philipp Brüschweiler88013572012-08-06 13:44:42 +0200112};
113
Xiong Zhang6b481422013-10-23 13:58:32 +0800114struct shell_output {
115 struct desktop_shell *shell;
116 struct weston_output *output;
117 struct wl_listener destroy_listener;
118 struct wl_list link;
119};
120
Tiago Vignattibe143262012-04-16 17:31:41 +0300121struct desktop_shell {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500122 struct weston_compositor *compositor;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400123
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +0200124 struct wl_listener idle_listener;
125 struct wl_listener wake_listener;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -0400126 struct wl_listener destroy_listener;
Jan Arne Petersen42feced2012-06-21 21:52:17 +0200127 struct wl_listener show_input_panel_listener;
128 struct wl_listener hide_input_panel_listener;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +0200129 struct wl_listener update_input_panel_listener;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200130
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500131 struct weston_layer fullscreen_layer;
132 struct weston_layer panel_layer;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500133 struct weston_layer background_layer;
134 struct weston_layer lock_layer;
Philipp Brüschweiler711fda82012-08-09 18:50:43 +0200135 struct weston_layer input_panel_layer;
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -0500136
Kristian Høgsbergd56bd902012-06-05 09:58:51 -0400137 struct wl_listener pointer_focus_listener;
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300138 struct weston_surface *grab_surface;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -0400139
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200140 struct {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500141 struct weston_process process;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200142 struct wl_client *client;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200143 struct wl_resource *desktop_shell;
Pekka Paalanen4d733ee2012-01-17 14:36:27 +0200144
145 unsigned deathcount;
146 uint32_t deathstamp;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +0200147 } child;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200148
149 bool locked;
Philipp Brüschweiler711fda82012-08-09 18:50:43 +0200150 bool showing_input_panels;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200151 bool prepare_event_sent;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +0200152
Jan Arne Petersen14da96b2013-04-18 16:47:28 +0200153 struct {
154 struct weston_surface *surface;
155 pixman_box32_t cursor_rectangle;
156 } text_input;
157
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400158 struct weston_surface *lock_surface;
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500159 struct wl_listener lock_surface_listener;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100160
Pekka Paalanen77346a62011-11-30 16:26:35 +0200161 struct {
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200162 struct wl_array array;
163 unsigned int current;
164 unsigned int num;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200165
Jonas Ådahle9d22502012-08-29 22:13:01 +0200166 struct wl_list client_list;
167
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200168 struct weston_animation animation;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200169 struct wl_list anim_sticky_list;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200170 int anim_dir;
171 uint32_t anim_timestamp;
172 double anim_current;
173 struct workspace *anim_from;
174 struct workspace *anim_to;
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200175 } workspaces;
176
177 struct {
Pekka Paalanen3c647232011-12-22 13:43:43 +0200178 char *path;
Pekka Paalanen7296e792011-12-07 16:22:00 +0200179 int duration;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200180 struct wl_resource *binding;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500181 struct weston_process process;
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +0200182 struct wl_event_source *timer;
Pekka Paalanen77346a62011-11-30 16:26:35 +0200183 } screensaver;
Kristian Høgsbergb41c0812012-03-04 14:53:40 -0500184
Jan Arne Petersen42feced2012-06-21 21:52:17 +0200185 struct {
186 struct wl_resource *binding;
187 struct wl_list surfaces;
188 } input_panel;
189
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +0200190 struct {
Jason Ekstranda7af7042013-10-12 22:38:11 -0500191 struct weston_view *view;
192 struct weston_view_animation *animation;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +0200193 enum fade_type type;
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300194 struct wl_event_source *startup_timer;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +0200195 } fade;
196
Daniel Stonedf8133b2013-11-19 11:37:14 +0100197 struct exposay {
198 /* XXX: Make these exposay_surfaces. */
199 struct weston_view *focus_prev;
200 struct weston_view *focus_current;
201 struct weston_view *clicked;
202 struct workspace *workspace;
203 struct weston_seat *seat;
204 struct wl_list surface_list;
205
206 struct weston_keyboard_grab grab_kbd;
207 struct weston_pointer_grab grab_ptr;
208
209 enum exposay_target_state state_target;
210 enum exposay_layout_state state_cur;
211 int in_flight; /* number of animations still running */
212
213 int num_surfaces;
214 int grid_size;
215 int surface_size;
216
217 int hpadding_outer;
218 int vpadding_outer;
219 int padding_inner;
220
221 int row_current;
222 int column_current;
Emilio Pozuelo Monforteed93442013-11-27 10:49:08 +0100223
224 bool mod_pressed;
225 bool mod_invalid;
Daniel Stonedf8133b2013-11-19 11:37:14 +0100226 } exposay;
227
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300228 uint32_t binding_modifier;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800229 enum animation_type win_animation_type;
Kristian Høgsberg724c8d92013-10-16 11:38:24 -0700230 enum animation_type startup_animation_type;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100231 enum animation_type focus_animation_type;
Xiong Zhang6b481422013-10-23 13:58:32 +0800232
233 struct wl_listener output_create_listener;
234 struct wl_list output_list;
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +0100235
236 char *client;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -0400237};
238
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500239enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +0200240 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500241 SHELL_SURFACE_TOPLEVEL,
242 SHELL_SURFACE_TRANSIENT,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500243 SHELL_SURFACE_FULLSCREEN,
Juan Zhao96879df2012-02-07 08:45:41 +0800244 SHELL_SURFACE_MAXIMIZED,
Tiago Vignattifb2adba2013-06-12 15:43:21 -0300245 SHELL_SURFACE_POPUP,
246 SHELL_SURFACE_XWAYLAND
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200247};
248
Scott Moreauff1db4a2012-04-17 19:06:18 -0600249struct ping_timer {
250 struct wl_event_source *source;
Scott Moreauff1db4a2012-04-17 19:06:18 -0600251 uint32_t serial;
252};
253
Philip Withnall648a4dd2013-11-25 18:01:44 +0000254/*
255 * Surface stacking and ordering.
256 *
257 * This is handled using several linked lists of surfaces, organised into
258 * ‘layers’. The layers are ordered, and each of the surfaces in one layer are
259 * above all of the surfaces in the layer below. The set of layers is static and
260 * in the following order (top-most first):
261 * • Lock layer (only ever displayed on its own)
262 * • Cursor layer
263 * • Fullscreen layer
264 * • Panel layer
265 * • Input panel layer
266 * • Workspace layers
267 * • Background layer
268 *
269 * The list of layers may be manipulated to remove whole layers of surfaces from
270 * display. For example, when locking the screen, all layers except the lock
271 * layer are removed.
272 *
273 * A surface’s layer is modified on configuring the surface, in
274 * set_surface_type() (which is only called when the surface’s type change is
275 * _committed_). If a surface’s type changes (e.g. when making a window
276 * fullscreen) its layer changes too.
277 *
278 * In order to allow popup and transient surfaces to be correctly stacked above
279 * their parent surfaces, each surface tracks both its parent surface, and a
280 * linked list of its children. When a surface’s layer is updated, so are the
281 * layers of its children. Note that child surfaces are *not* the same as
282 * subsurfaces — child/parent surfaces are purely for maintaining stacking
283 * order.
284 *
285 * The children_link list of siblings of a surface (i.e. those surfaces which
286 * have the same parent) only contains weston_surfaces which have a
287 * shell_surface. Stacking is not implemented for non-shell_surface
288 * weston_surfaces. This means that the following implication does *not* hold:
289 * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link)
290 */
291
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200292struct shell_surface {
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500293 struct wl_resource *resource;
294 struct wl_signal destroy_signal;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200295
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500296 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500297 struct weston_view *view;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200298 struct wl_listener surface_destroy_listener;
Kristian Høgsberg8150b192012-06-27 10:22:58 -0400299 struct weston_surface *parent;
Philip Withnall648a4dd2013-11-25 18:01:44 +0000300 struct wl_list children_list; /* child surfaces of this one */
301 struct wl_list children_link; /* sibling surfaces of this one */
Tiago Vignattibe143262012-04-16 17:31:41 +0300302 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200303
Kristian Høgsberg7f366e72012-04-27 17:20:01 -0400304 enum shell_surface_type type, next_type;
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400305 char *title, *class;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500306 int32_t saved_x, saved_y;
Alex Wu4539b082012-03-01 12:57:46 +0800307 bool saved_position_valid;
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800308 bool saved_rotation_valid;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700309 int unresponsive, grabbed;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100310
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500311 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200312 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500313 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200314 } rotation;
315
316 struct {
Giulio Camuffo5085a752013-03-25 21:42:45 +0100317 struct wl_list grab_link;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500318 int32_t x, y;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100319 struct shell_seat *shseat;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400320 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500321 } popup;
322
Alex Wu4539b082012-03-01 12:57:46 +0800323 struct {
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300324 int32_t x, y;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400325 uint32_t flags;
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300326 } transient;
327
328 struct {
Alex Wu4539b082012-03-01 12:57:46 +0800329 enum wl_shell_surface_fullscreen_method type;
330 struct weston_transform transform; /* matrix from x, y */
331 uint32_t framerate;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500332 struct weston_view *black_view;
Alex Wu4539b082012-03-01 12:57:46 +0800333 } fullscreen;
334
Scott Moreauff1db4a2012-04-17 19:06:18 -0600335 struct ping_timer *ping_timer;
336
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200337 struct weston_transform workspace_transform;
338
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500339 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500340 struct weston_output *output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100341 struct wl_list link;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400342
343 const struct weston_shell_client *client;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200344};
345
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300346struct shell_grab {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400347 struct weston_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300348 struct shell_surface *shsurf;
349 struct wl_listener shsurf_destroy_listener;
350};
351
Rusty Lynch1084da52013-08-15 09:10:08 -0700352struct shell_touch_grab {
353 struct weston_touch_grab grab;
354 struct shell_surface *shsurf;
355 struct wl_listener shsurf_destroy_listener;
356 struct weston_touch *touch;
357};
358
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300359struct weston_move_grab {
360 struct shell_grab base;
Daniel Stone103db7f2012-05-08 17:17:55 +0100361 wl_fixed_t dx, dy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500362};
363
Rusty Lynch1084da52013-08-15 09:10:08 -0700364struct weston_touch_move_grab {
365 struct shell_touch_grab base;
366 wl_fixed_t dx, dy;
367};
368
Pekka Paalanen460099f2012-01-20 16:48:25 +0200369struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300370 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500371 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200372 struct {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200373 float x;
374 float y;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200375 } center;
376};
377
Giulio Camuffo5085a752013-03-25 21:42:45 +0100378struct shell_seat {
379 struct weston_seat *seat;
380 struct wl_listener seat_destroy_listener;
381
382 struct {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400383 struct weston_pointer_grab grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100384 struct wl_list surfaces_list;
385 struct wl_client *client;
386 int32_t initial_up;
387 } popup_grab;
388};
389
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400390static void
391activate(struct desktop_shell *shell, struct weston_surface *es,
392 struct weston_seat *seat);
393
394static struct workspace *
395get_current_workspace(struct desktop_shell *shell);
396
Alex Wubd3354b2012-04-17 17:20:49 +0800397static struct shell_surface *
398get_shell_surface(struct weston_surface *surface);
399
400static struct desktop_shell *
401shell_surface_get_shell(struct shell_surface *shsurf);
402
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500403static void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400404surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500405
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300406static void
407shell_fade_startup(struct desktop_shell *shell);
408
Philip Withnallbecb77e2013-11-25 18:01:30 +0000409static struct shell_seat *
410get_shell_seat(struct weston_seat *seat);
411
Philip Withnall648a4dd2013-11-25 18:01:44 +0000412static void
413shell_surface_update_child_surface_layers(struct shell_surface *shsurf);
414
Alex Wubd3354b2012-04-17 17:20:49 +0800415static bool
416shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
417{
418 struct desktop_shell *shell;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500419 struct weston_view *top_fs_ev;
Alex Wubd3354b2012-04-17 17:20:49 +0800420
421 shell = shell_surface_get_shell(shsurf);
Quentin Glidicc0d79ce2013-01-29 14:16:13 +0100422
Jason Ekstranda7af7042013-10-12 22:38:11 -0500423 if (wl_list_empty(&shell->fullscreen_layer.view_list))
Alex Wubd3354b2012-04-17 17:20:49 +0800424 return false;
425
Jason Ekstranda7af7042013-10-12 22:38:11 -0500426 top_fs_ev = container_of(shell->fullscreen_layer.view_list.next,
427 struct weston_view,
Alex Wubd3354b2012-04-17 17:20:49 +0800428 layer_link);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500429 return (shsurf == get_shell_surface(top_fs_ev->surface));
Alex Wubd3354b2012-04-17 17:20:49 +0800430}
431
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500432static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400433destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300434{
435 struct shell_grab *grab;
436
437 grab = container_of(listener, struct shell_grab,
438 shsurf_destroy_listener);
439
440 grab->shsurf = NULL;
441}
442
Jason Ekstranda7af7042013-10-12 22:38:11 -0500443static struct weston_view *
444get_default_view(struct weston_surface *surface)
445{
446 struct shell_surface *shsurf;
447 struct weston_view *view;
448
449 if (!surface || wl_list_empty(&surface->views))
450 return NULL;
451
452 shsurf = get_shell_surface(surface);
453 if (shsurf)
454 return shsurf->view;
455
456 wl_list_for_each(view, &surface->views, surface_link)
457 if (weston_view_is_mapped(view))
458 return view;
459
460 return container_of(surface->views.next, struct weston_view, surface_link);
461}
462
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300463static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400464popup_grab_end(struct weston_pointer *pointer);
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400465
466static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300467shell_grab_start(struct shell_grab *grab,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400468 const struct weston_pointer_grab_interface *interface,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300469 struct shell_surface *shsurf,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400470 struct weston_pointer *pointer,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300471 enum desktop_shell_cursor cursor)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300472{
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300473 struct desktop_shell *shell = shsurf->shell;
474
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400475 popup_grab_end(pointer);
476
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300477 grab->grab.interface = interface;
478 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400479 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500480 wl_signal_add(&shsurf->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400481 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300482
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700483 shsurf->grabbed = 1;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400484 weston_pointer_start_grab(pointer, &grab->grab);
Kristian Høgsbergc9974a02013-07-03 19:24:57 -0400485 if (shell->child.desktop_shell) {
486 desktop_shell_send_grab_cursor(shell->child.desktop_shell,
487 cursor);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500488 weston_pointer_set_focus(pointer,
489 get_default_view(shell->grab_surface),
Kristian Høgsbergc9974a02013-07-03 19:24:57 -0400490 wl_fixed_from_int(0),
491 wl_fixed_from_int(0));
492 }
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300493}
494
495static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300496shell_grab_end(struct shell_grab *grab)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300497{
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700498 if (grab->shsurf) {
Kristian Høgsberg47b5dca2012-06-07 18:08:04 -0400499 wl_list_remove(&grab->shsurf_destroy_listener.link);
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700500 grab->shsurf->grabbed = 0;
501 }
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300502
Kristian Høgsberg9e5d7d12013-07-22 16:31:53 -0700503 weston_pointer_end_grab(grab->grab.pointer);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300504}
505
506static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700507shell_touch_grab_start(struct shell_touch_grab *grab,
508 const struct weston_touch_grab_interface *interface,
509 struct shell_surface *shsurf,
510 struct weston_touch *touch)
511{
512 struct desktop_shell *shell = shsurf->shell;
513
514 grab->grab.interface = interface;
515 grab->shsurf = shsurf;
516 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
517 wl_signal_add(&shsurf->destroy_signal,
518 &grab->shsurf_destroy_listener);
519
520 grab->touch = touch;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700521 shsurf->grabbed = 1;
Rusty Lynch1084da52013-08-15 09:10:08 -0700522
523 weston_touch_start_grab(touch, &grab->grab);
524 if (shell->child.desktop_shell)
Jason Ekstranda7af7042013-10-12 22:38:11 -0500525 weston_touch_set_focus(touch->seat,
526 get_default_view(shell->grab_surface));
Rusty Lynch1084da52013-08-15 09:10:08 -0700527}
528
529static void
530shell_touch_grab_end(struct shell_touch_grab *grab)
531{
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700532 if (grab->shsurf) {
Rusty Lynch1084da52013-08-15 09:10:08 -0700533 wl_list_remove(&grab->shsurf_destroy_listener.link);
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700534 grab->shsurf->grabbed = 0;
535 }
Rusty Lynch1084da52013-08-15 09:10:08 -0700536
537 weston_touch_end_grab(grab->touch);
538}
539
540static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500541center_on_output(struct weston_view *view,
Alex Wu4539b082012-03-01 12:57:46 +0800542 struct weston_output *output);
543
Daniel Stone496ca172012-05-30 16:31:42 +0100544static enum weston_keyboard_modifier
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300545get_modifier(char *modifier)
546{
547 if (!modifier)
548 return MODIFIER_SUPER;
549
550 if (!strcmp("ctrl", modifier))
551 return MODIFIER_CTRL;
552 else if (!strcmp("alt", modifier))
553 return MODIFIER_ALT;
554 else if (!strcmp("super", modifier))
555 return MODIFIER_SUPER;
556 else
557 return MODIFIER_SUPER;
558}
559
Juan Zhaoe10d2792012-04-25 19:09:52 +0800560static enum animation_type
561get_animation_type(char *animation)
562{
Juan Zhaoe10d2792012-04-25 19:09:52 +0800563 if (!strcmp("zoom", animation))
564 return ANIMATION_ZOOM;
565 else if (!strcmp("fade", animation))
566 return ANIMATION_FADE;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100567 else if (!strcmp("dim-layer", animation))
568 return ANIMATION_DIM_LAYER;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800569 else
570 return ANIMATION_NONE;
571}
572
Alex Wu4539b082012-03-01 12:57:46 +0800573static void
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400574shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200575{
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400576 struct weston_config_section *section;
577 int duration;
578 char *s;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200579
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400580 section = weston_config_get_section(shell->compositor->config,
581 "screensaver", NULL, NULL);
582 weston_config_section_get_string(section,
583 "path", &shell->screensaver.path, NULL);
584 weston_config_section_get_int(section, "duration", &duration, 60);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +0200585 shell->screensaver.duration = duration * 1000;
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400586
587 section = weston_config_get_section(shell->compositor->config,
588 "shell", NULL, NULL);
589 weston_config_section_get_string(section,
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +0100590 "client", &s, LIBEXECDIR "/weston-desktop-shell");
591 shell->client = s;
592 weston_config_section_get_string(section,
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400593 "binding-modifier", &s, "super");
594 shell->binding_modifier = get_modifier(s);
Quentin Glidic8418c292013-06-18 09:11:03 +0200595 free(s);
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400596 weston_config_section_get_string(section, "animation", &s, "none");
597 shell->win_animation_type = get_animation_type(s);
Quentin Glidic8418c292013-06-18 09:11:03 +0200598 free(s);
Kristian Høgsberg724c8d92013-10-16 11:38:24 -0700599 weston_config_section_get_string(section,
600 "startup-animation", &s, "fade");
601 shell->startup_animation_type = get_animation_type(s);
602 free(s);
Kristian Høgsberg912e0a12013-10-30 08:59:55 -0700603 if (shell->startup_animation_type == ANIMATION_ZOOM)
604 shell->startup_animation_type = ANIMATION_NONE;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100605 weston_config_section_get_string(section, "focus-animation", &s, "none");
606 shell->focus_animation_type = get_animation_type(s);
607 free(s);
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400608 weston_config_section_get_uint(section, "num-workspaces",
609 &shell->workspaces.num,
610 DEFAULT_NUM_WORKSPACES);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200611}
612
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100613static struct weston_output *
614get_default_output(struct weston_compositor *compositor)
615{
616 return container_of(compositor->output_list.next,
617 struct weston_output, link);
618}
619
620
621/* no-op func for checking focus surface */
622static void
623focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy,
624 int32_t width, int32_t height)
625{
626}
627
628static struct focus_surface *
629get_focus_surface(struct weston_surface *surface)
630{
631 if (surface->configure == focus_surface_configure)
632 return surface->configure_private;
633 else
634 return NULL;
635}
636
637static bool
638is_focus_surface (struct weston_surface *es)
639{
640 return (es->configure == focus_surface_configure);
641}
642
643static bool
644is_focus_view (struct weston_view *view)
645{
646 return is_focus_surface (view->surface);
647}
648
649static struct focus_surface *
650create_focus_surface(struct weston_compositor *ec,
651 struct weston_output *output)
652{
653 struct focus_surface *fsurf = NULL;
654 struct weston_surface *surface = NULL;
655
656 fsurf = malloc(sizeof *fsurf);
657 if (!fsurf)
658 return NULL;
659
660 fsurf->surface = weston_surface_create(ec);
661 surface = fsurf->surface;
662 if (surface == NULL) {
663 free(fsurf);
664 return NULL;
665 }
666
667 surface->configure = focus_surface_configure;
668 surface->output = output;
669 surface->configure_private = fsurf;
670
671 fsurf->view = weston_view_create (surface);
Emilio Pozuelo Monfortda644262013-11-19 11:37:19 +0100672 fsurf->view->output = output;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100673
674 weston_view_configure(fsurf->view, output->x, output->y,
675 output->width, output->height);
676 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
677 pixman_region32_fini(&surface->opaque);
678 pixman_region32_init_rect(&surface->opaque, output->x, output->y,
679 output->width, output->height);
680 pixman_region32_fini(&surface->input);
681 pixman_region32_init(&surface->input);
682
683 wl_list_init(&fsurf->workspace_transform.link);
684
685 return fsurf;
686}
687
688static void
689focus_surface_destroy(struct focus_surface *fsurf)
690{
691 weston_surface_destroy(fsurf->surface);
692 free(fsurf);
693}
694
695static void
696focus_animation_done(struct weston_view_animation *animation, void *data)
697{
698 struct workspace *ws = data;
699
700 ws->focus_animation = NULL;
701}
702
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200703static void
Jonas Ådahl04769742012-06-13 00:01:24 +0200704focus_state_destroy(struct focus_state *state)
705{
706 wl_list_remove(&state->seat_destroy_listener.link);
707 wl_list_remove(&state->surface_destroy_listener.link);
708 free(state);
709}
710
711static void
712focus_state_seat_destroy(struct wl_listener *listener, void *data)
713{
714 struct focus_state *state = container_of(listener,
715 struct focus_state,
716 seat_destroy_listener);
717
718 wl_list_remove(&state->link);
719 focus_state_destroy(state);
720}
721
722static void
723focus_state_surface_destroy(struct wl_listener *listener, void *data)
724{
725 struct focus_state *state = container_of(listener,
726 struct focus_state,
Kristian Høgsbergb8e0d0f2012-07-31 10:30:26 -0400727 surface_destroy_listener);
Kristian Høgsberge3778222012-07-31 17:29:30 -0400728 struct desktop_shell *shell;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500729 struct weston_surface *main_surface, *next;
730 struct weston_view *view;
Jonas Ådahl04769742012-06-13 00:01:24 +0200731
Pekka Paalanen01388e22013-04-25 13:57:44 +0300732 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
733
Kristian Høgsberge3778222012-07-31 17:29:30 -0400734 next = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500735 wl_list_for_each(view, &state->ws->layer.view_list, layer_link) {
736 if (view->surface == main_surface)
Kristian Høgsberge3778222012-07-31 17:29:30 -0400737 continue;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100738 if (is_focus_view(view))
739 continue;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400740
Jason Ekstranda7af7042013-10-12 22:38:11 -0500741 next = view->surface;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400742 break;
743 }
744
Pekka Paalanen01388e22013-04-25 13:57:44 +0300745 /* if the focus was a sub-surface, activate its main surface */
746 if (main_surface != state->keyboard_focus)
747 next = main_surface;
748
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100749 shell = state->seat->compositor->shell_interface.shell;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400750 if (next) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100751 state->keyboard_focus = NULL;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400752 activate(shell, next, state->seat);
753 } else {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100754 if (shell->focus_animation_type == ANIMATION_DIM_LAYER) {
755 if (state->ws->focus_animation)
756 weston_view_animation_destroy(state->ws->focus_animation);
757
758 state->ws->focus_animation = weston_fade_run(
759 state->ws->fsurf_front->view,
760 state->ws->fsurf_front->view->alpha, 0.0, 300,
761 focus_animation_done, state->ws);
762 }
763
Kristian Høgsberge3778222012-07-31 17:29:30 -0400764 wl_list_remove(&state->link);
765 focus_state_destroy(state);
766 }
Jonas Ådahl04769742012-06-13 00:01:24 +0200767}
768
769static struct focus_state *
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400770focus_state_create(struct weston_seat *seat, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200771{
Jonas Ådahl04769742012-06-13 00:01:24 +0200772 struct focus_state *state;
Jonas Ådahl04769742012-06-13 00:01:24 +0200773
774 state = malloc(sizeof *state);
775 if (state == NULL)
776 return NULL;
777
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100778 state->keyboard_focus = NULL;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400779 state->ws = ws;
Jonas Ådahl04769742012-06-13 00:01:24 +0200780 state->seat = seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400781 wl_list_insert(&ws->focus_list, &state->link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200782
783 state->seat_destroy_listener.notify = focus_state_seat_destroy;
784 state->surface_destroy_listener.notify = focus_state_surface_destroy;
Kristian Høgsberg49124542013-05-06 22:27:40 -0400785 wl_signal_add(&seat->destroy_signal,
Jonas Ådahl04769742012-06-13 00:01:24 +0200786 &state->seat_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400787 wl_list_init(&state->surface_destroy_listener.link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200788
789 return state;
790}
791
Jonas Ådahl8538b222012-08-29 22:13:03 +0200792static struct focus_state *
793ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
794{
795 struct workspace *ws = get_current_workspace(shell);
796 struct focus_state *state;
797
798 wl_list_for_each(state, &ws->focus_list, link)
799 if (state->seat == seat)
800 break;
801
802 if (&state->link == &ws->focus_list)
803 state = focus_state_create(seat, ws);
804
805 return state;
806}
807
Jonas Ådahl04769742012-06-13 00:01:24 +0200808static void
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400809restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200810{
811 struct focus_state *state, *next;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400812 struct weston_surface *surface;
Jonas Ådahl04769742012-06-13 00:01:24 +0200813
814 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400815 surface = state->keyboard_focus;
Jonas Ådahl56899442012-08-29 22:12:59 +0200816
Kristian Høgsberge3148752013-05-06 23:19:49 -0400817 weston_keyboard_set_focus(state->seat->keyboard, surface);
Jonas Ådahl04769742012-06-13 00:01:24 +0200818 }
819}
820
821static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200822replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
823 struct weston_seat *seat)
824{
825 struct focus_state *state;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400826 struct weston_surface *surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200827
828 wl_list_for_each(state, &ws->focus_list, link) {
829 if (state->seat == seat) {
Kristian Høgsberge3148752013-05-06 23:19:49 -0400830 surface = seat->keyboard->focus;
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500831 state->keyboard_focus = surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200832 return;
833 }
834 }
835}
836
837static void
838drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
839 struct weston_surface *surface)
840{
841 struct focus_state *state;
842
843 wl_list_for_each(state, &ws->focus_list, link)
844 if (state->keyboard_focus == surface)
845 state->keyboard_focus = NULL;
846}
847
848static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100849animate_focus_change(struct desktop_shell *shell, struct workspace *ws,
850 struct weston_view *from, struct weston_view *to)
851{
852 struct weston_output *output;
853 bool focus_surface_created = false;
854
855 /* FIXME: Only support dim animation using two layers */
856 if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER)
857 return;
858
859 output = get_default_output(shell->compositor);
860 if (ws->fsurf_front == NULL && (from || to)) {
861 ws->fsurf_front = create_focus_surface(shell->compositor, output);
862 ws->fsurf_back = create_focus_surface(shell->compositor, output);
863 ws->fsurf_front->view->alpha = 0.0;
864 ws->fsurf_back->view->alpha = 0.0;
865 focus_surface_created = true;
866 } else {
867 wl_list_remove(&ws->fsurf_front->view->layer_link);
868 wl_list_remove(&ws->fsurf_back->view->layer_link);
869 }
870
871 if (ws->focus_animation) {
872 weston_view_animation_destroy(ws->focus_animation);
873 ws->focus_animation = NULL;
874 }
875
876 if (to)
877 wl_list_insert(&to->layer_link,
878 &ws->fsurf_front->view->layer_link);
879 else if (from)
880 wl_list_insert(&ws->layer.view_list,
881 &ws->fsurf_front->view->layer_link);
882
883 if (focus_surface_created) {
884 ws->focus_animation = weston_fade_run(
885 ws->fsurf_front->view,
886 ws->fsurf_front->view->alpha, 0.6, 300,
887 focus_animation_done, ws);
888 } else if (from) {
889 wl_list_insert(&from->layer_link,
890 &ws->fsurf_back->view->layer_link);
891 ws->focus_animation = weston_stable_fade_run(
892 ws->fsurf_front->view, 0.0,
893 ws->fsurf_back->view, 0.6,
894 focus_animation_done, ws);
895 } else if (to) {
896 wl_list_insert(&ws->layer.view_list,
897 &ws->fsurf_back->view->layer_link);
898 ws->focus_animation = weston_stable_fade_run(
899 ws->fsurf_front->view, 0.0,
900 ws->fsurf_back->view, 0.6,
901 focus_animation_done, ws);
902 }
903}
904
905static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200906workspace_destroy(struct workspace *ws)
907{
Jonas Ådahl04769742012-06-13 00:01:24 +0200908 struct focus_state *state, *next;
909
910 wl_list_for_each_safe(state, next, &ws->focus_list, link)
911 focus_state_destroy(state);
912
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100913 if (ws->fsurf_front)
914 focus_surface_destroy(ws->fsurf_front);
915 if (ws->fsurf_back)
916 focus_surface_destroy(ws->fsurf_back);
917
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200918 free(ws);
919}
920
Jonas Ådahl04769742012-06-13 00:01:24 +0200921static void
922seat_destroyed(struct wl_listener *listener, void *data)
923{
924 struct weston_seat *seat = data;
925 struct focus_state *state, *next;
926 struct workspace *ws = container_of(listener,
927 struct workspace,
928 seat_destroyed_listener);
929
930 wl_list_for_each_safe(state, next, &ws->focus_list, link)
931 if (state->seat == seat)
932 wl_list_remove(&state->link);
933}
934
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200935static struct workspace *
936workspace_create(void)
937{
938 struct workspace *ws = malloc(sizeof *ws);
939 if (ws == NULL)
940 return NULL;
941
942 weston_layer_init(&ws->layer, NULL);
943
Jonas Ådahl04769742012-06-13 00:01:24 +0200944 wl_list_init(&ws->focus_list);
945 wl_list_init(&ws->seat_destroyed_listener.link);
946 ws->seat_destroyed_listener.notify = seat_destroyed;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100947 ws->fsurf_front = NULL;
948 ws->fsurf_back = NULL;
949 ws->focus_animation = NULL;
Jonas Ådahl04769742012-06-13 00:01:24 +0200950
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200951 return ws;
952}
953
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200954static int
955workspace_is_empty(struct workspace *ws)
956{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500957 return wl_list_empty(&ws->layer.view_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200958}
959
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200960static struct workspace *
961get_workspace(struct desktop_shell *shell, unsigned int index)
962{
963 struct workspace **pws = shell->workspaces.array.data;
Philipp Brüschweiler067abf62012-09-01 16:03:05 +0200964 assert(index < shell->workspaces.num);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200965 pws += index;
966 return *pws;
967}
968
969static struct workspace *
970get_current_workspace(struct desktop_shell *shell)
971{
972 return get_workspace(shell, shell->workspaces.current);
973}
974
975static void
976activate_workspace(struct desktop_shell *shell, unsigned int index)
977{
978 struct workspace *ws;
979
980 ws = get_workspace(shell, index);
981 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
982
983 shell->workspaces.current = index;
984}
985
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200986static unsigned int
987get_output_height(struct weston_output *output)
988{
989 return abs(output->region.extents.y1 - output->region.extents.y2);
990}
991
992static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100993view_translate(struct workspace *ws, struct weston_view *view, double d)
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200994{
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200995 struct weston_transform *transform;
996
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100997 if (is_focus_view(view)) {
998 struct focus_surface *fsurf = get_focus_surface(view->surface);
999 transform = &fsurf->workspace_transform;
1000 } else {
1001 struct shell_surface *shsurf = get_shell_surface(view->surface);
1002 transform = &shsurf->workspace_transform;
1003 }
1004
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001005 if (wl_list_empty(&transform->link))
Jason Ekstranda7af7042013-10-12 22:38:11 -05001006 wl_list_insert(view->geometry.transformation_list.prev,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001007 &transform->link);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001008
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001009 weston_matrix_init(&transform->matrix);
1010 weston_matrix_translate(&transform->matrix,
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001011 0.0, d, 0.0);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001012 weston_view_geometry_dirty(view);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001013}
1014
1015static void
1016workspace_translate_out(struct workspace *ws, double fraction)
1017{
Jason Ekstranda7af7042013-10-12 22:38:11 -05001018 struct weston_view *view;
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001019 unsigned int height;
1020 double d;
1021
Jason Ekstranda7af7042013-10-12 22:38:11 -05001022 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
1023 height = get_output_height(view->surface->output);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001024 d = height * fraction;
1025
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001026 view_translate(ws, view, d);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001027 }
1028}
1029
1030static void
1031workspace_translate_in(struct workspace *ws, double fraction)
1032{
Jason Ekstranda7af7042013-10-12 22:38:11 -05001033 struct weston_view *view;
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001034 unsigned int height;
1035 double d;
1036
Jason Ekstranda7af7042013-10-12 22:38:11 -05001037 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
1038 height = get_output_height(view->surface->output);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001039
1040 if (fraction > 0)
1041 d = -(height - height * fraction);
1042 else
1043 d = height + height * fraction;
1044
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001045 view_translate(ws, view, d);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001046 }
1047}
1048
1049static void
Jonas Ådahle9d22502012-08-29 22:13:01 +02001050broadcast_current_workspace_state(struct desktop_shell *shell)
1051{
Kristian Høgsberg2e3c3962013-09-11 12:00:47 -07001052 struct wl_resource *resource;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001053
Kristian Høgsberg2e3c3962013-09-11 12:00:47 -07001054 wl_resource_for_each(resource, &shell->workspaces.client_list)
1055 workspace_manager_send_state(resource,
Jonas Ådahle9d22502012-08-29 22:13:01 +02001056 shell->workspaces.current,
1057 shell->workspaces.num);
1058}
1059
1060static void
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001061reverse_workspace_change_animation(struct desktop_shell *shell,
1062 unsigned int index,
1063 struct workspace *from,
1064 struct workspace *to)
1065{
1066 shell->workspaces.current = index;
1067
1068 shell->workspaces.anim_to = to;
1069 shell->workspaces.anim_from = from;
1070 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
1071 shell->workspaces.anim_timestamp = 0;
1072
Scott Moreau4272e632012-08-13 09:58:41 -06001073 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001074}
1075
1076static void
1077workspace_deactivate_transforms(struct workspace *ws)
1078{
Jason Ekstranda7af7042013-10-12 22:38:11 -05001079 struct weston_view *view;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001080 struct weston_transform *transform;
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001081
Jason Ekstranda7af7042013-10-12 22:38:11 -05001082 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001083 if (is_focus_view(view)) {
1084 struct focus_surface *fsurf = get_focus_surface(view->surface);
1085 transform = &fsurf->workspace_transform;
1086 } else {
1087 struct shell_surface *shsurf = get_shell_surface(view->surface);
1088 transform = &shsurf->workspace_transform;
1089 }
1090
1091 if (!wl_list_empty(&transform->link)) {
1092 wl_list_remove(&transform->link);
1093 wl_list_init(&transform->link);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001094 }
Jason Ekstranda7af7042013-10-12 22:38:11 -05001095 weston_view_geometry_dirty(view);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001096 }
1097}
1098
1099static void
1100finish_workspace_change_animation(struct desktop_shell *shell,
1101 struct workspace *from,
1102 struct workspace *to)
1103{
Scott Moreau4272e632012-08-13 09:58:41 -06001104 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001105
1106 wl_list_remove(&shell->workspaces.animation.link);
1107 workspace_deactivate_transforms(from);
1108 workspace_deactivate_transforms(to);
1109 shell->workspaces.anim_to = NULL;
1110
1111 wl_list_remove(&shell->workspaces.anim_from->layer.link);
1112}
1113
1114static void
1115animate_workspace_change_frame(struct weston_animation *animation,
1116 struct weston_output *output, uint32_t msecs)
1117{
1118 struct desktop_shell *shell =
1119 container_of(animation, struct desktop_shell,
1120 workspaces.animation);
1121 struct workspace *from = shell->workspaces.anim_from;
1122 struct workspace *to = shell->workspaces.anim_to;
1123 uint32_t t;
1124 double x, y;
1125
1126 if (workspace_is_empty(from) && workspace_is_empty(to)) {
1127 finish_workspace_change_animation(shell, from, to);
1128 return;
1129 }
1130
1131 if (shell->workspaces.anim_timestamp == 0) {
1132 if (shell->workspaces.anim_current == 0.0)
1133 shell->workspaces.anim_timestamp = msecs;
1134 else
1135 shell->workspaces.anim_timestamp =
1136 msecs -
1137 /* Invers of movement function 'y' below. */
1138 (asin(1.0 - shell->workspaces.anim_current) *
1139 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
1140 M_2_PI);
1141 }
1142
1143 t = msecs - shell->workspaces.anim_timestamp;
1144
1145 /*
1146 * x = [0, π/2]
1147 * y(x) = sin(x)
1148 */
1149 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
1150 y = sin(x);
1151
1152 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
Scott Moreau4272e632012-08-13 09:58:41 -06001153 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001154
1155 workspace_translate_out(from, shell->workspaces.anim_dir * y);
1156 workspace_translate_in(to, shell->workspaces.anim_dir * y);
1157 shell->workspaces.anim_current = y;
1158
Scott Moreau4272e632012-08-13 09:58:41 -06001159 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001160 }
Jonas Ådahl04769742012-06-13 00:01:24 +02001161 else
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001162 finish_workspace_change_animation(shell, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001163}
1164
1165static void
1166animate_workspace_change(struct desktop_shell *shell,
1167 unsigned int index,
1168 struct workspace *from,
1169 struct workspace *to)
1170{
1171 struct weston_output *output;
1172
1173 int dir;
1174
1175 if (index > shell->workspaces.current)
1176 dir = -1;
1177 else
1178 dir = 1;
1179
1180 shell->workspaces.current = index;
1181
1182 shell->workspaces.anim_dir = dir;
1183 shell->workspaces.anim_from = from;
1184 shell->workspaces.anim_to = to;
1185 shell->workspaces.anim_current = 0.0;
1186 shell->workspaces.anim_timestamp = 0;
1187
1188 output = container_of(shell->compositor->output_list.next,
1189 struct weston_output, link);
1190 wl_list_insert(&output->animation_list,
1191 &shell->workspaces.animation.link);
1192
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001193 wl_list_insert(from->layer.link.prev, &to->layer.link);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001194
1195 workspace_translate_in(to, 0);
1196
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04001197 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +02001198
Scott Moreau4272e632012-08-13 09:58:41 -06001199 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001200}
1201
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001202static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001203update_workspace(struct desktop_shell *shell, unsigned int index,
1204 struct workspace *from, struct workspace *to)
1205{
1206 shell->workspaces.current = index;
1207 wl_list_insert(&from->layer.link, &to->layer.link);
1208 wl_list_remove(&from->layer.link);
1209}
1210
1211static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001212change_workspace(struct desktop_shell *shell, unsigned int index)
1213{
1214 struct workspace *from;
1215 struct workspace *to;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001216 struct focus_state *state;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001217
1218 if (index == shell->workspaces.current)
1219 return;
1220
1221 /* Don't change workspace when there is any fullscreen surfaces. */
Jason Ekstranda7af7042013-10-12 22:38:11 -05001222 if (!wl_list_empty(&shell->fullscreen_layer.view_list))
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001223 return;
1224
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001225 from = get_current_workspace(shell);
1226 to = get_workspace(shell, index);
1227
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001228 if (shell->workspaces.anim_from == to &&
1229 shell->workspaces.anim_to == from) {
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001230 restore_focus_state(shell, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001231 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001232 broadcast_current_workspace_state(shell);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001233 return;
1234 }
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001235
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001236 if (shell->workspaces.anim_to != NULL)
1237 finish_workspace_change_animation(shell,
1238 shell->workspaces.anim_from,
1239 shell->workspaces.anim_to);
1240
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001241 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +02001242
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001243 if (shell->focus_animation_type != ANIMATION_NONE) {
1244 wl_list_for_each(state, &from->focus_list, link)
1245 if (state->keyboard_focus)
1246 animate_focus_change(shell, from,
1247 get_default_view(state->keyboard_focus), NULL);
1248
1249 wl_list_for_each(state, &to->focus_list, link)
1250 if (state->keyboard_focus)
1251 animate_focus_change(shell, to,
1252 NULL, get_default_view(state->keyboard_focus));
1253 }
1254
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001255 if (workspace_is_empty(to) && workspace_is_empty(from))
1256 update_workspace(shell, index, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001257 else
1258 animate_workspace_change(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001259
1260 broadcast_current_workspace_state(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001261}
1262
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001263static bool
1264workspace_has_only(struct workspace *ws, struct weston_surface *surface)
1265{
Jason Ekstranda7af7042013-10-12 22:38:11 -05001266 struct wl_list *list = &ws->layer.view_list;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001267 struct wl_list *e;
1268
1269 if (wl_list_empty(list))
1270 return false;
1271
1272 e = list->next;
1273
1274 if (e->next != list)
1275 return false;
1276
Jason Ekstranda7af7042013-10-12 22:38:11 -05001277 return container_of(e, struct weston_view, layer_link)->surface == surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001278}
1279
1280static void
Philip Withnall659163d2013-11-25 18:01:36 +00001281move_surface_to_workspace(struct desktop_shell *shell,
1282 struct shell_surface *shsurf,
1283 uint32_t workspace)
Jonas Ådahle9d22502012-08-29 22:13:01 +02001284{
1285 struct workspace *from;
1286 struct workspace *to;
1287 struct weston_seat *seat;
Pekka Paalanen01388e22013-04-25 13:57:44 +03001288 struct weston_surface *focus;
Philip Withnall659163d2013-11-25 18:01:36 +00001289 struct weston_view *view;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001290
1291 if (workspace == shell->workspaces.current)
1292 return;
1293
Philip Withnall659163d2013-11-25 18:01:36 +00001294 view = get_default_view(shsurf->surface);
1295 if (!view)
1296 return;
1297
1298 assert(weston_surface_get_main_surface(view->surface) == view->surface);
1299
Philipp Brüschweiler067abf62012-09-01 16:03:05 +02001300 if (workspace >= shell->workspaces.num)
1301 workspace = shell->workspaces.num - 1;
1302
Jonas Ådahle9d22502012-08-29 22:13:01 +02001303 from = get_current_workspace(shell);
1304 to = get_workspace(shell, workspace);
1305
Jason Ekstranda7af7042013-10-12 22:38:11 -05001306 wl_list_remove(&view->layer_link);
1307 wl_list_insert(&to->layer.view_list, &view->layer_link);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001308
Philip Withnall648a4dd2013-11-25 18:01:44 +00001309 shell_surface_update_child_surface_layers(shsurf);
1310
Jason Ekstranda7af7042013-10-12 22:38:11 -05001311 drop_focus_state(shell, from, view->surface);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001312 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1313 if (!seat->keyboard)
1314 continue;
1315
1316 focus = weston_surface_get_main_surface(seat->keyboard->focus);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001317 if (focus == view->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001318 weston_keyboard_set_focus(seat->keyboard, NULL);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001319 }
Jonas Ådahle9d22502012-08-29 22:13:01 +02001320
Jason Ekstranda7af7042013-10-12 22:38:11 -05001321 weston_view_damage_below(view);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001322}
1323
1324static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001325take_surface_to_workspace_by_seat(struct desktop_shell *shell,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001326 struct weston_seat *seat,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001327 unsigned int index)
1328{
Pekka Paalanen01388e22013-04-25 13:57:44 +03001329 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001330 struct weston_view *view;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001331 struct shell_surface *shsurf;
1332 struct workspace *from;
1333 struct workspace *to;
Jonas Ådahl8538b222012-08-29 22:13:03 +02001334 struct focus_state *state;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001335
Pekka Paalanen01388e22013-04-25 13:57:44 +03001336 surface = weston_surface_get_main_surface(seat->keyboard->focus);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001337 view = get_default_view(surface);
1338 if (view == NULL ||
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001339 index == shell->workspaces.current ||
1340 is_focus_view(view))
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001341 return;
1342
1343 from = get_current_workspace(shell);
1344 to = get_workspace(shell, index);
1345
Jason Ekstranda7af7042013-10-12 22:38:11 -05001346 wl_list_remove(&view->layer_link);
1347 wl_list_insert(&to->layer.view_list, &view->layer_link);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001348
Philip Withnall659163d2013-11-25 18:01:36 +00001349 shsurf = get_shell_surface(surface);
Philip Withnall648a4dd2013-11-25 18:01:44 +00001350 if (shsurf != NULL)
1351 shell_surface_update_child_surface_layers(shsurf);
Philip Withnall659163d2013-11-25 18:01:36 +00001352
Jonas Ådahle9d22502012-08-29 22:13:01 +02001353 replace_focus_state(shell, to, seat);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001354 drop_focus_state(shell, from, surface);
1355
1356 if (shell->workspaces.anim_from == to &&
1357 shell->workspaces.anim_to == from) {
Jonas Ådahle9d22502012-08-29 22:13:01 +02001358 wl_list_remove(&to->layer.link);
1359 wl_list_insert(from->layer.link.prev, &to->layer.link);
1360
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001361 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001362 broadcast_current_workspace_state(shell);
1363
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001364 return;
1365 }
1366
1367 if (shell->workspaces.anim_to != NULL)
1368 finish_workspace_change_animation(shell,
1369 shell->workspaces.anim_from,
1370 shell->workspaces.anim_to);
1371
1372 if (workspace_is_empty(from) &&
1373 workspace_has_only(to, surface))
1374 update_workspace(shell, index, from, to);
1375 else {
Philip Withnall2c3849b2013-11-25 18:01:45 +00001376 if (shsurf != NULL &&
1377 wl_list_empty(&shsurf->workspace_transform.link))
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001378 wl_list_insert(&shell->workspaces.anim_sticky_list,
1379 &shsurf->workspace_transform.link);
1380
1381 animate_workspace_change(shell, index, from, to);
1382 }
Jonas Ådahle9d22502012-08-29 22:13:01 +02001383
1384 broadcast_current_workspace_state(shell);
Jonas Ådahl8538b222012-08-29 22:13:03 +02001385
1386 state = ensure_focus_state(shell, seat);
1387 if (state != NULL)
1388 state->keyboard_focus = surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001389}
1390
1391static void
1392workspace_manager_move_surface(struct wl_client *client,
1393 struct wl_resource *resource,
1394 struct wl_resource *surface_resource,
1395 uint32_t workspace)
1396{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001397 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001398 struct weston_surface *surface =
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05001399 wl_resource_get_user_data(surface_resource);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001400 struct weston_surface *main_surface;
Philip Withnall659163d2013-11-25 18:01:36 +00001401 struct shell_surface *shell_surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001402
Pekka Paalanen01388e22013-04-25 13:57:44 +03001403 main_surface = weston_surface_get_main_surface(surface);
Philip Withnall659163d2013-11-25 18:01:36 +00001404 shell_surface = get_shell_surface(main_surface);
1405 if (shell_surface == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05001406 return;
Philip Withnall659163d2013-11-25 18:01:36 +00001407
1408 move_surface_to_workspace(shell, shell_surface, workspace);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001409}
1410
1411static const struct workspace_manager_interface workspace_manager_implementation = {
1412 workspace_manager_move_surface,
1413};
1414
1415static void
1416unbind_resource(struct wl_resource *resource)
1417{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001418 wl_list_remove(wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001419}
1420
1421static void
1422bind_workspace_manager(struct wl_client *client,
1423 void *data, uint32_t version, uint32_t id)
1424{
1425 struct desktop_shell *shell = data;
1426 struct wl_resource *resource;
1427
Jason Ekstranda85118c2013-06-27 20:17:02 -05001428 resource = wl_resource_create(client,
1429 &workspace_manager_interface, 1, id);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001430
1431 if (resource == NULL) {
1432 weston_log("couldn't add workspace manager object");
1433 return;
1434 }
1435
Jason Ekstranda85118c2013-06-27 20:17:02 -05001436 wl_resource_set_implementation(resource,
1437 &workspace_manager_implementation,
1438 shell, unbind_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001439 wl_list_insert(&shell->workspaces.client_list,
1440 wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001441
1442 workspace_manager_send_state(resource,
1443 shell->workspaces.current,
1444 shell->workspaces.num);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001445}
1446
Pekka Paalanen56cdea92011-11-23 16:14:12 +02001447static void
Rusty Lynch1084da52013-08-15 09:10:08 -07001448touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1449 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1450{
1451}
1452
1453static void
1454touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1455{
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001456 struct weston_touch_move_grab *move =
1457 (struct weston_touch_move_grab *) container_of(
1458 grab, struct shell_touch_grab, grab);
Neil Robertse14aa4f2013-10-03 16:43:07 +01001459
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001460 if (grab->touch->seat->num_tp == 0) {
1461 shell_touch_grab_end(&move->base);
1462 free(move);
1463 }
Rusty Lynch1084da52013-08-15 09:10:08 -07001464}
1465
1466static void
1467touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1468 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1469{
1470 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1471 struct shell_surface *shsurf = move->base.shsurf;
1472 struct weston_surface *es;
1473 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1474 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1475
1476 if (!shsurf)
1477 return;
1478
1479 es = shsurf->surface;
1480
Jason Ekstranda7af7042013-10-12 22:38:11 -05001481 weston_view_configure(shsurf->view, dx, dy,
1482 shsurf->view->geometry.width,
1483 shsurf->view->geometry.height);
Rusty Lynch1084da52013-08-15 09:10:08 -07001484
1485 weston_compositor_schedule_repaint(es->compositor);
1486}
1487
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001488static void
1489touch_move_grab_cancel(struct weston_touch_grab *grab)
1490{
1491 struct weston_touch_move_grab *move =
1492 (struct weston_touch_move_grab *) container_of(
1493 grab, struct shell_touch_grab, grab);
1494
1495 shell_touch_grab_end(&move->base);
1496 free(move);
1497}
1498
Rusty Lynch1084da52013-08-15 09:10:08 -07001499static const struct weston_touch_grab_interface touch_move_grab_interface = {
1500 touch_move_grab_down,
1501 touch_move_grab_up,
1502 touch_move_grab_motion,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001503 touch_move_grab_cancel,
Rusty Lynch1084da52013-08-15 09:10:08 -07001504};
1505
1506static int
1507surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1508{
1509 struct weston_touch_move_grab *move;
1510
1511 if (!shsurf)
1512 return -1;
1513
1514 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1515 return 0;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001516 if (shsurf->grabbed)
1517 return 0;
Rusty Lynch1084da52013-08-15 09:10:08 -07001518
1519 move = malloc(sizeof *move);
1520 if (!move)
1521 return -1;
1522
Jason Ekstranda7af7042013-10-12 22:38:11 -05001523 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001524 seat->touch->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001525 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001526 seat->touch->grab_y;
1527
1528 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1529 seat->touch);
1530
1531 return 0;
1532}
1533
1534static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001535noop_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001536{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001537}
1538
1539static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001540move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1541 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001542{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001543 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001544 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001545 struct shell_surface *shsurf = move->base.shsurf;
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001546 int dx, dy;
1547
1548 weston_pointer_move(pointer, x, y);
1549 dx = wl_fixed_to_int(pointer->x + move->dx);
1550 dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001551
1552 if (!shsurf)
1553 return;
1554
Jason Ekstranda7af7042013-10-12 22:38:11 -05001555 weston_view_configure(shsurf->view, dx, dy,
1556 shsurf->view->geometry.width,
1557 shsurf->view->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001558
Jason Ekstranda7af7042013-10-12 22:38:11 -05001559 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001560}
1561
1562static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001563move_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001564 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001565{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001566 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1567 grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001568 struct weston_pointer *pointer = grab->pointer;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001569 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001570
Daniel Stone4dbadb12012-05-30 16:31:51 +01001571 if (pointer->button_count == 0 &&
1572 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001573 shell_grab_end(shell_grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001574 free(grab);
1575 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001576}
1577
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001578static void
1579move_grab_cancel(struct weston_pointer_grab *grab)
1580{
1581 struct shell_grab *shell_grab =
1582 container_of(grab, struct shell_grab, grab);
1583
1584 shell_grab_end(shell_grab);
1585 free(grab);
1586}
1587
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001588static const struct weston_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001589 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001590 move_grab_motion,
1591 move_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001592 move_grab_cancel,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001593};
1594
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001595static int
Kristian Høgsberge3148752013-05-06 23:19:49 -04001596surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001597{
1598 struct weston_move_grab *move;
1599
1600 if (!shsurf)
1601 return -1;
1602
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001603 if (shsurf->grabbed)
1604 return 0;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001605 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1606 return 0;
1607
1608 move = malloc(sizeof *move);
1609 if (!move)
1610 return -1;
1611
Jason Ekstranda7af7042013-10-12 22:38:11 -05001612 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001613 seat->pointer->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001614 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001615 seat->pointer->grab_y;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001616
1617 shell_grab_start(&move->base, &move_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001618 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001619
1620 return 0;
1621}
1622
1623static void
1624shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1625 struct wl_resource *seat_resource, uint32_t serial)
1626{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001627 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001628 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001629 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001630
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001631 if (seat->pointer &&
1632 seat->pointer->button_count > 0 &&
1633 seat->pointer->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001634 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001635 if ((surface == shsurf->surface) &&
1636 (surface_move(shsurf, seat) < 0))
1637 wl_resource_post_no_memory(resource);
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001638 } else if (seat->touch &&
1639 seat->touch->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001640 surface = weston_surface_get_main_surface(seat->touch->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001641 if ((surface == shsurf->surface) &&
1642 (surface_touch_move(shsurf, seat) < 0))
1643 wl_resource_post_no_memory(resource);
1644 }
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001645}
1646
1647struct weston_resize_grab {
1648 struct shell_grab base;
1649 uint32_t edges;
1650 int32_t width, height;
1651};
1652
1653static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001654resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1655 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001656{
1657 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001658 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001659 struct shell_surface *shsurf = resize->base.shsurf;
1660 int32_t width, height;
1661 wl_fixed_t from_x, from_y;
1662 wl_fixed_t to_x, to_y;
1663
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001664 weston_pointer_move(pointer, x, y);
1665
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001666 if (!shsurf)
1667 return;
1668
Jason Ekstranda7af7042013-10-12 22:38:11 -05001669 weston_view_from_global_fixed(shsurf->view,
1670 pointer->grab_x, pointer->grab_y,
1671 &from_x, &from_y);
1672 weston_view_from_global_fixed(shsurf->view,
1673 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001674
1675 width = resize->width;
1676 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1677 width += wl_fixed_to_int(from_x - to_x);
1678 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1679 width += wl_fixed_to_int(to_x - from_x);
1680 }
1681
1682 height = resize->height;
1683 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1684 height += wl_fixed_to_int(from_y - to_y);
1685 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1686 height += wl_fixed_to_int(to_y - from_y);
1687 }
1688
1689 shsurf->client->send_configure(shsurf->surface,
1690 resize->edges, width, height);
1691}
1692
1693static void
1694send_configure(struct weston_surface *surface,
1695 uint32_t edges, int32_t width, int32_t height)
1696{
1697 struct shell_surface *shsurf = get_shell_surface(surface);
1698
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001699 wl_shell_surface_send_configure(shsurf->resource,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001700 edges, width, height);
1701}
1702
1703static const struct weston_shell_client shell_client = {
1704 send_configure
1705};
1706
1707static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001708resize_grab_button(struct weston_pointer_grab *grab,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001709 uint32_t time, uint32_t button, uint32_t state_w)
1710{
1711 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001712 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001713 enum wl_pointer_button_state state = state_w;
1714
1715 if (pointer->button_count == 0 &&
1716 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1717 shell_grab_end(&resize->base);
1718 free(grab);
1719 }
1720}
1721
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001722static void
1723resize_grab_cancel(struct weston_pointer_grab *grab)
1724{
1725 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1726
1727 shell_grab_end(&resize->base);
1728 free(grab);
1729}
1730
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001731static const struct weston_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001732 noop_grab_focus,
1733 resize_grab_motion,
1734 resize_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001735 resize_grab_cancel,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001736};
1737
Giulio Camuffob8366642013-04-25 13:57:46 +03001738/*
1739 * Returns the bounding box of a surface and all its sub-surfaces,
1740 * in the surface coordinates system. */
1741static void
1742surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1743 int32_t *y, int32_t *w, int32_t *h) {
1744 pixman_region32_t region;
1745 pixman_box32_t *box;
1746 struct weston_subsurface *subsurface;
1747
1748 pixman_region32_init_rect(&region, 0, 0,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001749 surface->width,
1750 surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001751
1752 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1753 pixman_region32_union_rect(&region, &region,
1754 subsurface->position.x,
1755 subsurface->position.y,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001756 subsurface->surface->width,
1757 subsurface->surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001758 }
1759
1760 box = pixman_region32_extents(&region);
1761 if (x)
1762 *x = box->x1;
1763 if (y)
1764 *y = box->y1;
1765 if (w)
1766 *w = box->x2 - box->x1;
1767 if (h)
1768 *h = box->y2 - box->y1;
1769
1770 pixman_region32_fini(&region);
1771}
1772
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001773static int
1774surface_resize(struct shell_surface *shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001775 struct weston_seat *seat, uint32_t edges)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001776{
1777 struct weston_resize_grab *resize;
1778
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01001779 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1780 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001781 return 0;
1782
1783 if (edges == 0 || edges > 15 ||
1784 (edges & 3) == 3 || (edges & 12) == 12)
1785 return 0;
1786
1787 resize = malloc(sizeof *resize);
1788 if (!resize)
1789 return -1;
1790
1791 resize->edges = edges;
Giulio Camuffob8366642013-04-25 13:57:46 +03001792 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1793 &resize->width, &resize->height);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001794
1795 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001796 seat->pointer, edges);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001797
1798 return 0;
1799}
1800
1801static void
1802shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1803 struct wl_resource *seat_resource, uint32_t serial,
1804 uint32_t edges)
1805{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001806 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001807 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001808 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001809
1810 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1811 return;
1812
Jason Ekstranda7af7042013-10-12 22:38:11 -05001813 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001814 if (seat->pointer->button_count == 0 ||
1815 seat->pointer->grab_serial != serial ||
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001816 surface != shsurf->surface)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001817 return;
1818
Kristian Høgsberge3148752013-05-06 23:19:49 -04001819 if (surface_resize(shsurf, seat, edges) < 0)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001820 wl_resource_post_no_memory(resource);
1821}
1822
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001823static void
Kristian Høgsberg67800732013-07-04 01:12:17 -04001824end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1825
1826static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001827busy_cursor_grab_focus(struct weston_pointer_grab *base)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001828{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001829 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001830 struct weston_pointer *pointer = base->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001831 struct weston_view *view;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001832 wl_fixed_t sx, sy;
1833
Jason Ekstranda7af7042013-10-12 22:38:11 -05001834 view = weston_compositor_pick_view(pointer->seat->compositor,
1835 pointer->x, pointer->y,
1836 &sx, &sy);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001837
Jason Ekstranda7af7042013-10-12 22:38:11 -05001838 if (!grab->shsurf || grab->shsurf->surface != view->surface)
Kristian Høgsberg67800732013-07-04 01:12:17 -04001839 end_busy_cursor(grab->shsurf, pointer);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001840}
1841
1842static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001843busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1844 wl_fixed_t x, wl_fixed_t y)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001845{
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001846 weston_pointer_move(grab->pointer, x, y);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001847}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001848
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001849static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001850busy_cursor_grab_button(struct weston_pointer_grab *base,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001851 uint32_t time, uint32_t button, uint32_t state)
1852{
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001853 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001854 struct shell_surface *shsurf = grab->shsurf;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001855 struct weston_seat *seat = grab->grab.pointer->seat;
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001856
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001857 if (shsurf && button == BTN_LEFT && state) {
1858 activate(shsurf->shell, shsurf->surface, seat);
1859 surface_move(shsurf, seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05001860 } else if (shsurf && button == BTN_RIGHT && state) {
1861 activate(shsurf->shell, shsurf->surface, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001862 surface_rotate(shsurf, seat);
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001863 }
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001864}
1865
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001866static void
1867busy_cursor_grab_cancel(struct weston_pointer_grab *base)
1868{
1869 struct shell_grab *grab = (struct shell_grab *) base;
1870
1871 shell_grab_end(grab);
1872 free(grab);
1873}
1874
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001875static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001876 busy_cursor_grab_focus,
1877 busy_cursor_grab_motion,
1878 busy_cursor_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001879 busy_cursor_grab_cancel,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001880};
1881
1882static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001883set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001884{
1885 struct shell_grab *grab;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001886
1887 grab = malloc(sizeof *grab);
1888 if (!grab)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001889 return;
1890
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001891 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1892 DESKTOP_SHELL_CURSOR_BUSY);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001893}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001894
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001895static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001896end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001897{
1898 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1899
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001900 if (grab->grab.interface == &busy_cursor_grab_interface &&
1901 grab->shsurf == shsurf) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001902 shell_grab_end(grab);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001903 free(grab);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001904 }
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001905}
1906
Scott Moreau9521d5e2012-04-19 13:06:17 -06001907static void
1908ping_timer_destroy(struct shell_surface *shsurf)
1909{
1910 if (!shsurf || !shsurf->ping_timer)
1911 return;
1912
1913 if (shsurf->ping_timer->source)
1914 wl_event_source_remove(shsurf->ping_timer->source);
1915
1916 free(shsurf->ping_timer);
1917 shsurf->ping_timer = NULL;
1918}
1919
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001920static int
Scott Moreauff1db4a2012-04-17 19:06:18 -06001921ping_timeout_handler(void *data)
1922{
1923 struct shell_surface *shsurf = data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001924 struct weston_seat *seat;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001925
Scott Moreau9521d5e2012-04-19 13:06:17 -06001926 /* Client is not responding */
1927 shsurf->unresponsive = 1;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001928
1929 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
Emilio Pozuelo Monfort3d0fc762013-11-22 16:21:20 +01001930 if (seat->pointer->focus &&
1931 seat->pointer->focus->surface == shsurf->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001932 set_busy_cursor(shsurf, seat->pointer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001933
1934 return 1;
1935}
1936
1937static void
1938ping_handler(struct weston_surface *surface, uint32_t serial)
1939{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04001940 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001941 struct wl_event_loop *loop;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001942 int ping_timeout = 200;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001943
1944 if (!shsurf)
1945 return;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001946 if (!shsurf->resource)
Kristian Høgsbergca535c12012-04-21 23:20:07 -04001947 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001948
Ander Conselvan de Oliveiraeac9a462012-07-16 14:15:48 +03001949 if (shsurf->surface == shsurf->shell->grab_surface)
1950 return;
1951
Scott Moreauff1db4a2012-04-17 19:06:18 -06001952 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +03001953 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001954 if (!shsurf->ping_timer)
1955 return;
1956
1957 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001958 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1959 shsurf->ping_timer->source =
1960 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1961 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1962
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001963 wl_shell_surface_send_ping(shsurf->resource, serial);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001964 }
1965}
1966
1967static void
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001968handle_pointer_focus(struct wl_listener *listener, void *data)
1969{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001970 struct weston_pointer *pointer = data;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001971 struct weston_view *view = pointer->focus;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001972 struct weston_compositor *compositor;
1973 struct shell_surface *shsurf;
1974 uint32_t serial;
1975
Jason Ekstranda7af7042013-10-12 22:38:11 -05001976 if (!view)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001977 return;
1978
Jason Ekstranda7af7042013-10-12 22:38:11 -05001979 compositor = view->surface->compositor;
1980 shsurf = get_shell_surface(view->surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001981
Pekka Paalanen4e1f2ff2012-06-06 16:59:45 +03001982 if (shsurf && shsurf->unresponsive) {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001983 set_busy_cursor(shsurf, pointer);
1984 } else {
1985 serial = wl_display_next_serial(compositor->wl_display);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001986 ping_handler(view->surface, serial);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001987 }
1988}
1989
1990static void
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001991create_pointer_focus_listener(struct weston_seat *seat)
1992{
1993 struct wl_listener *listener;
1994
Kristian Høgsberge3148752013-05-06 23:19:49 -04001995 if (!seat->pointer)
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001996 return;
1997
1998 listener = malloc(sizeof *listener);
1999 listener->notify = handle_pointer_focus;
Kristian Høgsberge3148752013-05-06 23:19:49 -04002000 wl_signal_add(&seat->pointer->focus_signal, listener);
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04002001}
2002
2003static void
Scott Moreauff1db4a2012-04-17 19:06:18 -06002004shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
2005 uint32_t serial)
2006{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002007 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002008 struct weston_seat *seat;
2009 struct weston_compositor *ec = shsurf->surface->compositor;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002010
Kristian Høgsberg92374e12012-08-11 22:39:12 -04002011 if (shsurf->ping_timer == NULL)
2012 /* Just ignore unsolicited pong. */
2013 return;
2014
Scott Moreauff1db4a2012-04-17 19:06:18 -06002015 if (shsurf->ping_timer->serial == serial) {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002016 shsurf->unresponsive = 0;
Hardeningeb1e1302013-05-17 18:07:41 +02002017 wl_list_for_each(seat, &ec->seat_list, link) {
2018 if(seat->pointer)
2019 end_busy_cursor(shsurf, seat->pointer);
2020 }
Scott Moreau9521d5e2012-04-19 13:06:17 -06002021 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -06002022 }
2023}
2024
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002025static void
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002026set_title(struct shell_surface *shsurf, const char *title)
2027{
2028 free(shsurf->title);
2029 shsurf->title = strdup(title);
2030}
2031
2032static void
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002033shell_surface_set_title(struct wl_client *client,
2034 struct wl_resource *resource, const char *title)
2035{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002036 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002037
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002038 set_title(shsurf, title);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002039}
2040
2041static void
2042shell_surface_set_class(struct wl_client *client,
2043 struct wl_resource *resource, const char *class)
2044{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002045 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002046
2047 free(shsurf->class);
2048 shsurf->class = strdup(class);
2049}
2050
Alex Wu4539b082012-03-01 12:57:46 +08002051static void
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002052restore_output_mode(struct weston_output *output)
2053{
Hardening57388e42013-09-18 23:56:36 +02002054 if (output->current_mode != output->original_mode ||
2055 (int32_t)output->current_scale != output->original_scale)
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002056 weston_output_switch_mode(output,
Hardening57388e42013-09-18 23:56:36 +02002057 output->original_mode,
2058 output->original_scale,
2059 WESTON_MODE_SWITCH_RESTORE_NATIVE);
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002060}
2061
2062static void
2063restore_all_output_modes(struct weston_compositor *compositor)
2064{
2065 struct weston_output *output;
2066
2067 wl_list_for_each(output, &compositor->output_list, link)
2068 restore_output_mode(output);
2069}
2070
Philip Withnallbecb77e2013-11-25 18:01:30 +00002071static int
2072get_output_panel_height(struct desktop_shell *shell,
2073 struct weston_output *output)
2074{
2075 struct weston_view *view;
2076 int panel_height = 0;
2077
2078 if (!output)
2079 return 0;
2080
2081 wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
2082 if (view->surface->output == output) {
2083 panel_height = view->geometry.height;
2084 break;
2085 }
2086 }
2087
2088 return panel_height;
2089}
2090
Philip Withnall07926d92013-11-25 18:01:40 +00002091/* The surface will be inserted into the list immediately after the link
2092 * returned by this function (i.e. will be stacked immediately above the
2093 * returned link). */
2094static struct wl_list *
2095shell_surface_calculate_layer_link (struct shell_surface *shsurf)
2096{
2097 struct workspace *ws;
2098
2099 switch (shsurf->type) {
2100 case SHELL_SURFACE_POPUP:
2101 case SHELL_SURFACE_TRANSIENT: {
2102 /* Move the surface to its parent layer so that surfaces which
2103 * are transient for fullscreen surfaces don't get hidden by the
2104 * fullscreen surfaces. */
2105 struct weston_view *parent;
2106
2107 /* TODO: Handle a parent with multiple views */
2108 parent = get_default_view(shsurf->parent);
2109 if (parent)
2110 return parent->layer_link.prev;
2111
2112 break;
2113 }
2114
2115 case SHELL_SURFACE_FULLSCREEN:
2116 return &shsurf->shell->fullscreen_layer.view_list;
2117
2118 case SHELL_SURFACE_XWAYLAND:
2119 case SHELL_SURFACE_TOPLEVEL:
2120 case SHELL_SURFACE_MAXIMIZED:
2121 case SHELL_SURFACE_NONE:
2122 default:
2123 /* Go to the fallback, below. */
2124 break;
2125 }
2126
2127 /* Move the surface to a normal workspace layer so that surfaces
2128 * which were previously fullscreen or transient are no longer
2129 * rendered on top. */
2130 ws = get_current_workspace(shsurf->shell);
2131 return &ws->layer.view_list;
2132}
2133
Philip Withnall648a4dd2013-11-25 18:01:44 +00002134static void
2135shell_surface_update_child_surface_layers (struct shell_surface *shsurf)
2136{
2137 struct shell_surface *child;
2138
2139 /* Move the child layers to the same workspace as shsurf. They will be
2140 * stacked above shsurf. */
2141 wl_list_for_each_reverse(child, &shsurf->children_list, children_link) {
2142 if (shsurf->view->layer_link.prev != &child->view->layer_link) {
2143 weston_view_geometry_dirty(child->view);
2144 wl_list_remove(&child->view->layer_link);
2145 wl_list_insert(shsurf->view->layer_link.prev,
2146 &child->view->layer_link);
2147 weston_view_geometry_dirty(child->view);
2148 weston_surface_damage(child->surface);
2149
2150 /* Recurse. We don’t expect this to recurse very far (if
2151 * at all) because that would imply we have transient
2152 * (or popup) children of transient surfaces, which
2153 * would be unusual. */
2154 shell_surface_update_child_surface_layers(child);
2155 }
2156 }
2157}
2158
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002159/* Update the surface’s layer. Mark both the old and new views as having dirty
Philip Withnall648a4dd2013-11-25 18:01:44 +00002160 * geometry to ensure the changes are redrawn.
2161 *
2162 * If any child surfaces exist and are mapped, ensure they’re in the same layer
2163 * as this surface. */
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002164static void
2165shell_surface_update_layer(struct shell_surface *shsurf)
2166{
2167 struct wl_list *new_layer_link;
2168
2169 new_layer_link = shell_surface_calculate_layer_link(shsurf);
2170
2171 if (new_layer_link == &shsurf->view->layer_link)
2172 return;
2173
2174 weston_view_geometry_dirty(shsurf->view);
2175 wl_list_remove(&shsurf->view->layer_link);
2176 wl_list_insert(new_layer_link, &shsurf->view->layer_link);
2177 weston_view_geometry_dirty(shsurf->view);
2178 weston_surface_damage(shsurf->surface);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002179
2180 shell_surface_update_child_surface_layers(shsurf);
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002181}
2182
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002183static void
Philip Withnalldc4332f2013-11-25 18:01:38 +00002184shell_surface_set_parent(struct shell_surface *shsurf,
2185 struct weston_surface *parent)
2186{
2187 shsurf->parent = parent;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002188
2189 wl_list_remove(&shsurf->children_link);
2190 wl_list_init(&shsurf->children_link);
2191
2192 /* Insert into the parent surface’s child list. */
2193 if (parent != NULL) {
2194 struct shell_surface *parent_shsurf = get_shell_surface(parent);
2195 if (parent_shsurf != NULL)
2196 wl_list_insert(&parent_shsurf->children_list,
2197 &shsurf->children_link);
2198 }
Philip Withnalldc4332f2013-11-25 18:01:38 +00002199}
2200
2201static void
Philip Withnall352e7ed2013-11-25 18:01:35 +00002202shell_surface_set_output(struct shell_surface *shsurf,
2203 struct weston_output *output)
2204{
2205 struct weston_surface *es = shsurf->surface;
2206
2207 /* get the default output, if the client set it as NULL
2208 check whether the ouput is available */
2209 if (output)
2210 shsurf->output = output;
2211 else if (es->output)
2212 shsurf->output = es->output;
2213 else
2214 shsurf->output = get_default_output(es->compositor);
2215}
2216
2217static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002218set_toplevel(struct shell_surface *shsurf)
2219{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002220 shell_surface_set_parent(shsurf, NULL);
2221
Philip Withnallbecb77e2013-11-25 18:01:30 +00002222 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002223
2224 /* The layer_link is updated in set_surface_type(),
2225 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002226}
2227
2228static void
2229shell_surface_set_toplevel(struct wl_client *client,
2230 struct wl_resource *resource)
2231{
2232 struct shell_surface *surface = wl_resource_get_user_data(resource);
2233
2234 set_toplevel(surface);
2235}
2236
2237static void
2238set_transient(struct shell_surface *shsurf,
2239 struct weston_surface *parent, int x, int y, uint32_t flags)
2240{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002241 assert(parent != NULL);
2242
Philip Withnallbecb77e2013-11-25 18:01:30 +00002243 shsurf->transient.x = x;
2244 shsurf->transient.y = y;
2245 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002246
2247 shell_surface_set_parent(shsurf, parent);
2248
Philip Withnallbecb77e2013-11-25 18:01:30 +00002249 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002250
2251 /* The layer_link is updated in set_surface_type(),
2252 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002253}
2254
2255static void
2256shell_surface_set_transient(struct wl_client *client,
2257 struct wl_resource *resource,
2258 struct wl_resource *parent_resource,
2259 int x, int y, uint32_t flags)
2260{
2261 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2262 struct weston_surface *parent =
2263 wl_resource_get_user_data(parent_resource);
2264
2265 set_transient(shsurf, parent, x, y, flags);
2266}
2267
2268static void
2269set_fullscreen(struct shell_surface *shsurf,
2270 uint32_t method,
2271 uint32_t framerate,
2272 struct weston_output *output)
2273{
Philip Withnall352e7ed2013-11-25 18:01:35 +00002274 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002275
2276 shsurf->fullscreen_output = shsurf->output;
2277 shsurf->fullscreen.type = method;
2278 shsurf->fullscreen.framerate = framerate;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002279
2280 shell_surface_set_parent(shsurf, NULL);
2281
Philip Withnallbecb77e2013-11-25 18:01:30 +00002282 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
2283
2284 shsurf->client->send_configure(shsurf->surface, 0,
2285 shsurf->output->width,
2286 shsurf->output->height);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002287
2288 /* The layer_link is updated in set_surface_type(),
2289 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002290}
2291
2292static void
2293unset_fullscreen(struct shell_surface *shsurf)
Alex Wu4539b082012-03-01 12:57:46 +08002294{
Philip Withnallf85fe842013-11-25 18:01:37 +00002295 /* Unset the fullscreen output, driver configuration and transforms. */
Alex Wubd3354b2012-04-17 17:20:49 +08002296 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2297 shell_surface_is_top_fullscreen(shsurf)) {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002298 restore_output_mode(shsurf->fullscreen_output);
Alex Wubd3354b2012-04-17 17:20:49 +08002299 }
Philip Withnallf85fe842013-11-25 18:01:37 +00002300 shsurf->fullscreen_output = NULL;
2301
Alex Wu4539b082012-03-01 12:57:46 +08002302 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2303 shsurf->fullscreen.framerate = 0;
Philip Withnallf85fe842013-11-25 18:01:37 +00002304
Alex Wu4539b082012-03-01 12:57:46 +08002305 wl_list_remove(&shsurf->fullscreen.transform.link);
2306 wl_list_init(&shsurf->fullscreen.transform.link);
Philip Withnallf85fe842013-11-25 18:01:37 +00002307
Jason Ekstranda7af7042013-10-12 22:38:11 -05002308 if (shsurf->fullscreen.black_view)
2309 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
2310 shsurf->fullscreen.black_view = NULL;
Philip Withnallf85fe842013-11-25 18:01:37 +00002311
Jason Ekstranda7af7042013-10-12 22:38:11 -05002312 weston_view_set_position(shsurf->view,
2313 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002314 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002315 wl_list_insert(&shsurf->view->geometry.transformation_list,
Philip Withnallbecb77e2013-11-25 18:01:30 +00002316 &shsurf->rotation.transform.link);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002317 shsurf->saved_rotation_valid = false;
2318 }
Rafal Mielniczuk3e3862c2012-10-07 20:25:36 +02002319
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002320 /* Layer is updated in set_surface_type(). */
Alex Wu4539b082012-03-01 12:57:46 +08002321}
2322
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002323static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002324shell_surface_set_fullscreen(struct wl_client *client,
2325 struct wl_resource *resource,
2326 uint32_t method,
2327 uint32_t framerate,
2328 struct wl_resource *output_resource)
2329{
2330 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2331 struct weston_output *output;
2332
2333 if (output_resource)
2334 output = wl_resource_get_user_data(output_resource);
2335 else
2336 output = NULL;
2337
2338 set_fullscreen(shsurf, method, framerate, output);
2339}
2340
2341static void
2342set_popup(struct shell_surface *shsurf,
2343 struct weston_surface *parent,
2344 struct weston_seat *seat,
2345 uint32_t serial,
2346 int32_t x,
2347 int32_t y)
2348{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002349 assert(parent != NULL);
2350
Philip Withnallbecb77e2013-11-25 18:01:30 +00002351 shsurf->popup.shseat = get_shell_seat(seat);
2352 shsurf->popup.serial = serial;
2353 shsurf->popup.x = x;
2354 shsurf->popup.y = y;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002355
2356 shell_surface_set_parent(shsurf, parent);
Philip Withnallb995e1d2013-11-25 18:01:39 +00002357
2358 shsurf->next_type = SHELL_SURFACE_POPUP;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002359}
2360
2361static void
2362shell_surface_set_popup(struct wl_client *client,
2363 struct wl_resource *resource,
2364 struct wl_resource *seat_resource,
2365 uint32_t serial,
2366 struct wl_resource *parent_resource,
2367 int32_t x, int32_t y, uint32_t flags)
2368{
2369 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2370
2371 set_popup(shsurf,
2372 wl_resource_get_user_data(parent_resource),
2373 wl_resource_get_user_data(seat_resource),
2374 serial, x, y);
2375}
2376
2377static void
2378set_maximized(struct shell_surface *shsurf,
2379 struct weston_output *output)
2380{
2381 struct desktop_shell *shell;
2382 uint32_t edges = 0, panel_height = 0;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002383
Philip Withnall352e7ed2013-11-25 18:01:35 +00002384 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002385
2386 shell = shell_surface_get_shell(shsurf);
2387 panel_height = get_output_panel_height(shell, shsurf->output);
2388 edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT;
2389
2390 shsurf->client->send_configure(shsurf->surface, edges,
2391 shsurf->output->width,
2392 shsurf->output->height - panel_height);
2393
Philip Withnalldc4332f2013-11-25 18:01:38 +00002394 shell_surface_set_parent(shsurf, NULL);
2395
Philip Withnallbecb77e2013-11-25 18:01:30 +00002396 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
2397}
2398
2399static void
2400unset_maximized(struct shell_surface *shsurf)
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002401{
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002402 /* undo all maximized things here */
2403 shsurf->output = get_default_output(shsurf->surface->compositor);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002404 weston_view_set_position(shsurf->view,
2405 shsurf->saved_x,
2406 shsurf->saved_y);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002407
2408 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002409 wl_list_insert(&shsurf->view->geometry.transformation_list,
2410 &shsurf->rotation.transform.link);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002411 shsurf->saved_rotation_valid = false;
2412 }
2413
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002414 /* Layer is updated in set_surface_type(). */
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002415}
2416
Philip Withnallbecb77e2013-11-25 18:01:30 +00002417static void
2418shell_surface_set_maximized(struct wl_client *client,
2419 struct wl_resource *resource,
2420 struct wl_resource *output_resource)
2421{
2422 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2423 struct weston_output *output;
2424
2425 if (output_resource)
2426 output = wl_resource_get_user_data(output_resource);
2427 else
2428 output = NULL;
2429
2430 set_maximized(shsurf, output);
2431}
2432
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002433/* This is only ever called from set_surface_type(), so there’s no need to
2434 * update layer_links here, since they’ll be updated when we return. */
Pekka Paalanen98262232011-12-01 10:42:22 +02002435static int
Philip Withnallbecb77e2013-11-25 18:01:30 +00002436reset_surface_type(struct shell_surface *surface)
Pekka Paalanen98262232011-12-01 10:42:22 +02002437{
2438 switch (surface->type) {
2439 case SHELL_SURFACE_FULLSCREEN:
Philip Withnallbecb77e2013-11-25 18:01:30 +00002440 unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +02002441 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002442 case SHELL_SURFACE_MAXIMIZED:
Philip Withnallbecb77e2013-11-25 18:01:30 +00002443 unset_maximized(surface);
Juan Zhao96879df2012-02-07 08:45:41 +08002444 break;
Pekka Paalanen98262232011-12-01 10:42:22 +02002445 case SHELL_SURFACE_NONE:
2446 case SHELL_SURFACE_TOPLEVEL:
2447 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002448 case SHELL_SURFACE_POPUP:
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002449 case SHELL_SURFACE_XWAYLAND:
Philip Withnall0f640e22013-11-25 18:01:31 +00002450 default:
Pekka Paalanen98262232011-12-01 10:42:22 +02002451 break;
2452 }
2453
2454 surface->type = SHELL_SURFACE_NONE;
2455 return 0;
2456}
2457
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002458static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002459set_surface_type(struct shell_surface *shsurf)
2460{
Kristian Høgsberg8150b192012-06-27 10:22:58 -04002461 struct weston_surface *pes = shsurf->parent;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002462 struct weston_view *pev = get_default_view(pes);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002463
Philip Withnallbecb77e2013-11-25 18:01:30 +00002464 reset_surface_type(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002465
2466 shsurf->type = shsurf->next_type;
2467 shsurf->next_type = SHELL_SURFACE_NONE;
2468
2469 switch (shsurf->type) {
2470 case SHELL_SURFACE_TOPLEVEL:
2471 break;
2472 case SHELL_SURFACE_TRANSIENT:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002473 if (pev)
2474 weston_view_set_position(shsurf->view,
2475 pev->geometry.x + shsurf->transient.x,
2476 pev->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002477 break;
2478
2479 case SHELL_SURFACE_MAXIMIZED:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002480 case SHELL_SURFACE_FULLSCREEN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002481 shsurf->saved_x = shsurf->view->geometry.x;
2482 shsurf->saved_y = shsurf->view->geometry.y;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002483 shsurf->saved_position_valid = true;
2484
2485 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
2486 wl_list_remove(&shsurf->rotation.transform.link);
2487 wl_list_init(&shsurf->rotation.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002488 weston_view_geometry_dirty(shsurf->view);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002489 shsurf->saved_rotation_valid = true;
2490 }
2491 break;
2492
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002493 case SHELL_SURFACE_XWAYLAND:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002494 weston_view_set_position(shsurf->view, shsurf->transient.x,
2495 shsurf->transient.y);
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002496 break;
2497
Philip Withnall0f640e22013-11-25 18:01:31 +00002498 case SHELL_SURFACE_POPUP:
2499 case SHELL_SURFACE_NONE:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002500 default:
2501 break;
2502 }
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002503
2504 /* Update the surface’s layer. */
2505 shell_surface_update_layer(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002506}
2507
Tiago Vignattibe143262012-04-16 17:31:41 +03002508static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +08002509shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002510{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002511 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +08002512}
2513
Alex Wu21858432012-04-01 20:13:08 +08002514static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002515black_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 +08002516
Jason Ekstranda7af7042013-10-12 22:38:11 -05002517static struct weston_view *
Alex Wu4539b082012-03-01 12:57:46 +08002518create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +08002519 struct weston_surface *fs_surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02002520 float x, float y, int w, int h)
Alex Wu4539b082012-03-01 12:57:46 +08002521{
2522 struct weston_surface *surface = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002523 struct weston_view *view;
Alex Wu4539b082012-03-01 12:57:46 +08002524
2525 surface = weston_surface_create(ec);
2526 if (surface == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02002527 weston_log("no memory\n");
Alex Wu4539b082012-03-01 12:57:46 +08002528 return NULL;
2529 }
Jason Ekstranda7af7042013-10-12 22:38:11 -05002530 view = weston_view_create(surface);
2531 if (surface == NULL) {
2532 weston_log("no memory\n");
2533 weston_surface_destroy(surface);
2534 return NULL;
2535 }
Alex Wu4539b082012-03-01 12:57:46 +08002536
Alex Wu21858432012-04-01 20:13:08 +08002537 surface->configure = black_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002538 surface->configure_private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +08002539 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
Pekka Paalanen71f6f3b2012-10-10 12:49:26 +03002540 pixman_region32_fini(&surface->opaque);
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04002541 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
Jonas Ådahl33619a42013-01-15 21:25:55 +01002542 pixman_region32_fini(&surface->input);
2543 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
Xiong Zhangbecf5a32013-11-29 11:18:14 +08002544 surface->width = w;
2545 surface->height = h;
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04002546
Jason Ekstranda7af7042013-10-12 22:38:11 -05002547 weston_view_configure(view, x, y, w, h);
2548
2549 return view;
Alex Wu4539b082012-03-01 12:57:46 +08002550}
2551
Philip Withnalled8f1a92013-11-25 18:01:43 +00002552static void
2553shell_ensure_fullscreen_black_view(struct shell_surface *shsurf)
2554{
2555 struct weston_output *output = shsurf->fullscreen_output;
2556
2557 assert(shsurf->type == SHELL_SURFACE_FULLSCREEN);
2558
2559 if (!shsurf->fullscreen.black_view)
2560 shsurf->fullscreen.black_view =
2561 create_black_surface(shsurf->surface->compositor,
2562 shsurf->surface,
2563 output->x, output->y,
2564 output->width,
2565 output->height);
2566
2567 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2568 wl_list_remove(&shsurf->fullscreen.black_view->layer_link);
2569 wl_list_insert(&shsurf->view->layer_link,
2570 &shsurf->fullscreen.black_view->layer_link);
2571 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2572 weston_surface_damage(shsurf->surface);
2573}
2574
Alex Wu4539b082012-03-01 12:57:46 +08002575/* Create black surface and append it to the associated fullscreen surface.
2576 * Handle size dismatch and positioning according to the method. */
2577static void
2578shell_configure_fullscreen(struct shell_surface *shsurf)
2579{
2580 struct weston_output *output = shsurf->fullscreen_output;
2581 struct weston_surface *surface = shsurf->surface;
2582 struct weston_matrix *matrix;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002583 float scale, output_aspect, surface_aspect, x, y;
Giulio Camuffob8366642013-04-25 13:57:46 +03002584 int32_t surf_x, surf_y, surf_width, surf_height;
Alex Wu4539b082012-03-01 12:57:46 +08002585
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002586 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
2587 restore_output_mode(output);
2588
Philip Withnalled8f1a92013-11-25 18:01:43 +00002589 shell_ensure_fullscreen_black_view(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002590
Jason Ekstranda7af7042013-10-12 22:38:11 -05002591 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
Giulio Camuffob8366642013-04-25 13:57:46 +03002592 &surf_width, &surf_height);
2593
Alex Wu4539b082012-03-01 12:57:46 +08002594 switch (shsurf->fullscreen.type) {
2595 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
Pekka Paalanende685b82012-12-04 15:58:12 +02002596 if (surface->buffer_ref.buffer)
Jason Ekstranda7af7042013-10-12 22:38:11 -05002597 center_on_output(shsurf->view, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08002598 break;
2599 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
Rob Bradford9f3dd152013-02-12 11:53:47 +00002600 /* 1:1 mapping between surface and output dimensions */
Giulio Camuffob8366642013-04-25 13:57:46 +03002601 if (output->width == surf_width &&
2602 output->height == surf_height) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002603 weston_view_set_position(shsurf->view,
2604 output->x - surf_x,
2605 output->y - surf_y);
Rob Bradford9f3dd152013-02-12 11:53:47 +00002606 break;
2607 }
2608
Alex Wu4539b082012-03-01 12:57:46 +08002609 matrix = &shsurf->fullscreen.transform.matrix;
2610 weston_matrix_init(matrix);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002611
Scott Moreau1bad5db2012-08-18 01:04:05 -06002612 output_aspect = (float) output->width /
2613 (float) output->height;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002614 /* XXX: Use surf_width and surf_height here? */
2615 surface_aspect = (float) surface->width /
2616 (float) surface->height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002617 if (output_aspect < surface_aspect)
Scott Moreau1bad5db2012-08-18 01:04:05 -06002618 scale = (float) output->width /
Giulio Camuffob8366642013-04-25 13:57:46 +03002619 (float) surf_width;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002620 else
Scott Moreau1bad5db2012-08-18 01:04:05 -06002621 scale = (float) output->height /
Giulio Camuffob8366642013-04-25 13:57:46 +03002622 (float) surf_height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002623
Alex Wu4539b082012-03-01 12:57:46 +08002624 weston_matrix_scale(matrix, scale, scale, 1);
2625 wl_list_remove(&shsurf->fullscreen.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002626 wl_list_insert(&shsurf->view->geometry.transformation_list,
Alex Wu4539b082012-03-01 12:57:46 +08002627 &shsurf->fullscreen.transform.link);
Giulio Camuffob8366642013-04-25 13:57:46 +03002628 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2629 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002630 weston_view_set_position(shsurf->view, x, y);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002631
Alex Wu4539b082012-03-01 12:57:46 +08002632 break;
2633 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +08002634 if (shell_surface_is_top_fullscreen(shsurf)) {
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01002635 struct weston_mode mode = {0,
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002636 surf_width * surface->buffer_viewport.scale,
2637 surf_height * surface->buffer_viewport.scale,
Alex Wubd3354b2012-04-17 17:20:49 +08002638 shsurf->fullscreen.framerate};
2639
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002640 if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
Hardening57388e42013-09-18 23:56:36 +02002641 WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002642 weston_view_set_position(shsurf->view,
2643 output->x - surf_x,
2644 output->y - surf_y);
2645 weston_view_configure(shsurf->fullscreen.black_view,
2646 output->x - surf_x,
2647 output->y - surf_y,
2648 output->width,
2649 output->height);
Alex Wubd3354b2012-04-17 17:20:49 +08002650 break;
Alexander Larssond622ed32013-05-28 16:23:40 +02002651 } else {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002652 restore_output_mode(output);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002653 center_on_output(shsurf->view, output);
Alexander Larssond622ed32013-05-28 16:23:40 +02002654 }
Alex Wubd3354b2012-04-17 17:20:49 +08002655 }
Alex Wu4539b082012-03-01 12:57:46 +08002656 break;
2657 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002658 center_on_output(shsurf->view, output);
Alex Wu4539b082012-03-01 12:57:46 +08002659 break;
2660 default:
2661 break;
2662 }
2663}
2664
Alex Wu4539b082012-03-01 12:57:46 +08002665static void
2666shell_map_fullscreen(struct shell_surface *shsurf)
2667{
Alex Wubd3354b2012-04-17 17:20:49 +08002668 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002669}
2670
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002671static void
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002672set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2673{
2674 /* XXX: using the same fields for transient type */
2675 shsurf->transient.x = x;
2676 shsurf->transient.y = y;
2677 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002678
2679 shell_surface_set_parent(shsurf, NULL);
2680
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002681 shsurf->next_type = SHELL_SURFACE_XWAYLAND;
2682}
2683
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002684static const struct weston_pointer_grab_interface popup_grab_interface;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002685
2686static void
2687destroy_shell_seat(struct wl_listener *listener, void *data)
2688{
2689 struct shell_seat *shseat =
2690 container_of(listener,
2691 struct shell_seat, seat_destroy_listener);
2692 struct shell_surface *shsurf, *prev = NULL;
2693
2694 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002695 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002696 shseat->popup_grab.client = NULL;
2697
2698 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2699 shsurf->popup.shseat = NULL;
2700 if (prev) {
2701 wl_list_init(&prev->popup.grab_link);
2702 }
2703 prev = shsurf;
2704 }
2705 wl_list_init(&prev->popup.grab_link);
2706 }
2707
2708 wl_list_remove(&shseat->seat_destroy_listener.link);
2709 free(shseat);
2710}
2711
2712static struct shell_seat *
2713create_shell_seat(struct weston_seat *seat)
2714{
2715 struct shell_seat *shseat;
2716
2717 shseat = calloc(1, sizeof *shseat);
2718 if (!shseat) {
2719 weston_log("no memory to allocate shell seat\n");
2720 return NULL;
2721 }
2722
2723 shseat->seat = seat;
2724 wl_list_init(&shseat->popup_grab.surfaces_list);
2725
2726 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2727 wl_signal_add(&seat->destroy_signal,
2728 &shseat->seat_destroy_listener);
2729
2730 return shseat;
2731}
2732
2733static struct shell_seat *
2734get_shell_seat(struct weston_seat *seat)
2735{
2736 struct wl_listener *listener;
2737
2738 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2739 if (listener == NULL)
2740 return create_shell_seat(seat);
2741
2742 return container_of(listener,
2743 struct shell_seat, seat_destroy_listener);
2744}
2745
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002746static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002747popup_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002748{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002749 struct weston_pointer *pointer = grab->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002750 struct weston_view *view;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002751 struct shell_seat *shseat =
2752 container_of(grab, struct shell_seat, popup_grab.grab);
2753 struct wl_client *client = shseat->popup_grab.client;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002754 wl_fixed_t sx, sy;
2755
Jason Ekstranda7af7042013-10-12 22:38:11 -05002756 view = weston_compositor_pick_view(pointer->seat->compositor,
2757 pointer->x, pointer->y,
2758 &sx, &sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002759
Jason Ekstranda7af7042013-10-12 22:38:11 -05002760 if (view && view->surface->resource &&
2761 wl_resource_get_client(view->surface->resource) == client) {
2762 weston_pointer_set_focus(pointer, view, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002763 } else {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002764 weston_pointer_set_focus(pointer, NULL,
2765 wl_fixed_from_int(0),
2766 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002767 }
2768}
2769
2770static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002771popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
2772 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002773{
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002774 struct weston_pointer *pointer = grab->pointer;
Neil Roberts96d790e2013-09-19 17:32:00 +01002775 struct wl_resource *resource;
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002776 wl_fixed_t sx, sy;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002777
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002778 weston_pointer_move(pointer, x, y);
2779
Neil Roberts96d790e2013-09-19 17:32:00 +01002780 wl_resource_for_each(resource, &pointer->focus_resource_list) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002781 weston_view_from_global_fixed(pointer->focus,
2782 pointer->x, pointer->y,
2783 &sx, &sy);
Neil Roberts96d790e2013-09-19 17:32:00 +01002784 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002785 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002786}
2787
2788static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002789popup_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01002790 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002791{
2792 struct wl_resource *resource;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002793 struct shell_seat *shseat =
2794 container_of(grab, struct shell_seat, popup_grab.grab);
Rob Bradford880ebc72013-07-22 17:31:38 +01002795 struct wl_display *display = shseat->seat->compositor->wl_display;
Daniel Stone4dbadb12012-05-30 16:31:51 +01002796 enum wl_pointer_button_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002797 uint32_t serial;
Neil Roberts96d790e2013-09-19 17:32:00 +01002798 struct wl_list *resource_list;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002799
Neil Roberts96d790e2013-09-19 17:32:00 +01002800 resource_list = &grab->pointer->focus_resource_list;
2801 if (!wl_list_empty(resource_list)) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002802 serial = wl_display_get_serial(display);
Neil Roberts96d790e2013-09-19 17:32:00 +01002803 wl_resource_for_each(resource, resource_list) {
2804 wl_pointer_send_button(resource, serial,
2805 time, button, state);
2806 }
Daniel Stone4dbadb12012-05-30 16:31:51 +01002807 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
Giulio Camuffo5085a752013-03-25 21:42:45 +01002808 (shseat->popup_grab.initial_up ||
Kristian Høgsberge3148752013-05-06 23:19:49 -04002809 time - shseat->seat->pointer->grab_time > 500)) {
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002810 popup_grab_end(grab->pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002811 }
2812
Daniel Stone4dbadb12012-05-30 16:31:51 +01002813 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Giulio Camuffo5085a752013-03-25 21:42:45 +01002814 shseat->popup_grab.initial_up = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002815}
2816
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002817static void
2818popup_grab_cancel(struct weston_pointer_grab *grab)
2819{
2820 popup_grab_end(grab->pointer);
2821}
2822
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002823static const struct weston_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002824 popup_grab_focus,
2825 popup_grab_motion,
2826 popup_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002827 popup_grab_cancel,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002828};
2829
2830static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002831popup_grab_end(struct weston_pointer *pointer)
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002832{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002833 struct weston_pointer_grab *grab = pointer->grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002834 struct shell_seat *shseat =
2835 container_of(grab, struct shell_seat, popup_grab.grab);
2836 struct shell_surface *shsurf;
2837 struct shell_surface *prev = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002838
2839 if (pointer->grab->interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002840 weston_pointer_end_grab(grab->pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002841 shseat->popup_grab.client = NULL;
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002842 shseat->popup_grab.grab.interface = NULL;
2843 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
Giulio Camuffo5085a752013-03-25 21:42:45 +01002844 /* Send the popup_done event to all the popups open */
2845 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002846 wl_shell_surface_send_popup_done(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002847 shsurf->popup.shseat = NULL;
2848 if (prev) {
2849 wl_list_init(&prev->popup.grab_link);
2850 }
2851 prev = shsurf;
2852 }
2853 wl_list_init(&prev->popup.grab_link);
2854 wl_list_init(&shseat->popup_grab.surfaces_list);
2855 }
2856}
2857
2858static void
2859add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2860{
Kristian Høgsberge3148752013-05-06 23:19:49 -04002861 struct weston_seat *seat = shseat->seat;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002862
2863 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002864 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002865 shseat->popup_grab.grab.interface = &popup_grab_interface;
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002866 /* We must make sure here that this popup was opened after
2867 * a mouse press, and not just by moving around with other
2868 * popups already open. */
Kristian Høgsberge3148752013-05-06 23:19:49 -04002869 if (shseat->seat->pointer->button_count > 0)
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002870 shseat->popup_grab.initial_up = 0;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002871
Rob Bradforddfe31052013-06-26 19:49:11 +01002872 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002873 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
Rob Bradforddfe31052013-06-26 19:49:11 +01002874 } else {
2875 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002876 }
Giulio Camuffo5085a752013-03-25 21:42:45 +01002877}
2878
2879static void
2880remove_popup_grab(struct shell_surface *shsurf)
2881{
2882 struct shell_seat *shseat = shsurf->popup.shseat;
2883
2884 wl_list_remove(&shsurf->popup.grab_link);
2885 wl_list_init(&shsurf->popup.grab_link);
2886 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002887 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002888 shseat->popup_grab.grab.interface = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002889 }
2890}
2891
2892static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002893shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002894{
Giulio Camuffo5085a752013-03-25 21:42:45 +01002895 struct shell_seat *shseat = shsurf->popup.shseat;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002896 struct weston_view *parent_view = get_default_view(shsurf->parent);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002897
Jason Ekstranda7af7042013-10-12 22:38:11 -05002898 shsurf->surface->output = parent_view->output;
2899 shsurf->view->output = parent_view->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002900
Jason Ekstranda7af7042013-10-12 22:38:11 -05002901 weston_view_set_transform_parent(shsurf->view, parent_view);
2902 weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y);
2903 weston_view_update_transform(shsurf->view);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002904
Kristian Høgsberge3148752013-05-06 23:19:49 -04002905 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01002906 add_popup_grab(shsurf, shseat);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002907 } else {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002908 wl_shell_surface_send_popup_done(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002909 shseat->popup_grab.client = NULL;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002910 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002911}
2912
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002913static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002914 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002915 shell_surface_move,
2916 shell_surface_resize,
2917 shell_surface_set_toplevel,
2918 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002919 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08002920 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002921 shell_surface_set_maximized,
2922 shell_surface_set_title,
2923 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002924};
2925
2926static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002927destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002928{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002929 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2930
Giulio Camuffo5085a752013-03-25 21:42:45 +01002931 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2932 remove_popup_grab(shsurf);
2933 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002934
Alex Wubd3354b2012-04-17 17:20:49 +08002935 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002936 shell_surface_is_top_fullscreen(shsurf))
2937 restore_output_mode (shsurf->fullscreen_output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002938
Jason Ekstranda7af7042013-10-12 22:38:11 -05002939 if (shsurf->fullscreen.black_view)
2940 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
Alex Wuaa08e2d2012-03-05 11:01:40 +08002941
Alex Wubd3354b2012-04-17 17:20:49 +08002942 /* As destroy_resource() use wl_list_for_each_safe(),
2943 * we can always remove the listener.
2944 */
2945 wl_list_remove(&shsurf->surface_destroy_listener.link);
2946 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06002947 ping_timer_destroy(shsurf);
Scott Moreau976a0502013-03-07 10:15:17 -07002948 free(shsurf->title);
Alex Wubd3354b2012-04-17 17:20:49 +08002949
Jason Ekstranda7af7042013-10-12 22:38:11 -05002950 weston_view_destroy(shsurf->view);
2951
Philip Withnall648a4dd2013-11-25 18:01:44 +00002952 wl_list_remove(&shsurf->children_link);
2953
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002954 wl_list_remove(&shsurf->link);
2955 free(shsurf);
2956}
2957
2958static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002959shell_destroy_shell_surface(struct wl_resource *resource)
2960{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002961 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03002962
2963 destroy_shell_surface(shsurf);
2964}
2965
2966static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002967shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002968{
2969 struct shell_surface *shsurf = container_of(listener,
2970 struct shell_surface,
2971 surface_destroy_listener);
2972
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002973 if (shsurf->resource)
2974 wl_resource_destroy(shsurf->resource);
2975 else
Tiago Vignattibc052c92012-04-19 16:18:18 +03002976 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002977}
2978
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002979static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002980shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002981
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002982static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002983get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002984{
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002985 if (surface->configure == shell_surface_configure)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002986 return surface->configure_private;
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002987 else
2988 return NULL;
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002989}
2990
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002991static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002992create_shell_surface(void *shell, struct weston_surface *surface,
2993 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002994{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002995 struct shell_surface *shsurf;
2996
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002997 if (surface->configure) {
Martin Minarik6d118362012-06-07 18:01:59 +02002998 weston_log("surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002999 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003000 }
3001
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003002 shsurf = calloc(1, sizeof *shsurf);
3003 if (!shsurf) {
Martin Minarik6d118362012-06-07 18:01:59 +02003004 weston_log("no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04003005 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003006 }
3007
Jason Ekstranda7af7042013-10-12 22:38:11 -05003008 shsurf->view = weston_view_create(surface);
3009 if (!shsurf->view) {
3010 weston_log("no memory to allocate shell surface\n");
3011 free(shsurf);
3012 return NULL;
3013 }
3014
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003015 surface->configure = shell_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003016 surface->configure_private = shsurf;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003017
Tiago Vignattibc052c92012-04-19 16:18:18 +03003018 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06003019 shsurf->unresponsive = 0;
Alex Wu4539b082012-03-01 12:57:46 +08003020 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08003021 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003022 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08003023 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
3024 shsurf->fullscreen.framerate = 0;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003025 shsurf->fullscreen.black_view = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06003026 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08003027 wl_list_init(&shsurf->fullscreen.transform.link);
3028
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003029 wl_signal_init(&shsurf->destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003030 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05003031 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003032 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003033
3034 /* init link so its safe to always remove it in destroy_shell_surface */
3035 wl_list_init(&shsurf->link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01003036 wl_list_init(&shsurf->popup.grab_link);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003037
Pekka Paalanen460099f2012-01-20 16:48:25 +02003038 /* empty when not in use */
3039 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003040 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003041
Jonas Ådahl62fcd042012-06-13 00:01:23 +02003042 wl_list_init(&shsurf->workspace_transform.link);
3043
Philip Withnall648a4dd2013-11-25 18:01:44 +00003044 wl_list_init(&shsurf->children_link);
3045 wl_list_init(&shsurf->children_list);
3046 shsurf->parent = NULL;
3047
Pekka Paalanen98262232011-12-01 10:42:22 +02003048 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04003049 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003050
Kristian Høgsberga61ca062012-05-22 16:05:52 -04003051 shsurf->client = client;
3052
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04003053 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03003054}
3055
Jason Ekstranda7af7042013-10-12 22:38:11 -05003056static struct weston_view *
3057get_primary_view(void *shell, struct shell_surface *shsurf)
3058{
3059 return shsurf->view;
3060}
3061
Tiago Vignattibc052c92012-04-19 16:18:18 +03003062static void
3063shell_get_shell_surface(struct wl_client *client,
3064 struct wl_resource *resource,
3065 uint32_t id,
3066 struct wl_resource *surface_resource)
3067{
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003068 struct weston_surface *surface =
3069 wl_resource_get_user_data(surface_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003070 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03003071 struct shell_surface *shsurf;
3072
3073 if (get_shell_surface(surface)) {
3074 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003075 WL_DISPLAY_ERROR_INVALID_OBJECT,
3076 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03003077 return;
3078 }
3079
Kristian Høgsberga61ca062012-05-22 16:05:52 -04003080 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003081 if (!shsurf) {
3082 wl_resource_post_error(surface_resource,
3083 WL_DISPLAY_ERROR_INVALID_OBJECT,
3084 "surface->configure already set");
3085 return;
3086 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03003087
Jason Ekstranda85118c2013-06-27 20:17:02 -05003088 shsurf->resource =
3089 wl_resource_create(client,
3090 &wl_shell_surface_interface, 1, id);
3091 wl_resource_set_implementation(shsurf->resource,
3092 &shell_surface_implementation,
3093 shsurf, shell_destroy_shell_surface);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003094}
3095
3096static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02003097 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05003098};
3099
Kristian Høgsberg07937562011-04-12 17:25:42 -04003100static void
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02003101shell_fade(struct desktop_shell *shell, enum fade_type type);
3102
3103static int
3104screensaver_timeout(void *data)
3105{
3106 struct desktop_shell *shell = data;
3107
3108 shell_fade(shell, FADE_OUT);
3109
3110 return 1;
3111}
3112
3113static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003114handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02003115{
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003116 struct desktop_shell *shell =
3117 container_of(proc, struct desktop_shell, screensaver.process);
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003118
Pekka Paalanen18027e52011-12-02 16:31:49 +02003119 proc->pid = 0;
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003120
3121 if (shell->locked)
Ander Conselvan de Oliveirab17537e2013-02-22 14:16:18 +02003122 weston_compositor_sleep(shell->compositor);
Pekka Paalanen18027e52011-12-02 16:31:49 +02003123}
3124
3125static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003126launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003127{
3128 if (shell->screensaver.binding)
3129 return;
3130
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003131 if (!shell->screensaver.path) {
3132 weston_compositor_sleep(shell->compositor);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003133 return;
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003134 }
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003135
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003136 if (shell->screensaver.process.pid != 0) {
Martin Minarik6d118362012-06-07 18:01:59 +02003137 weston_log("old screensaver still running\n");
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003138 return;
3139 }
3140
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003141 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003142 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003143 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003144 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003145}
3146
3147static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003148terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003149{
Pekka Paalanen18027e52011-12-02 16:31:49 +02003150 if (shell->screensaver.process.pid == 0)
3151 return;
3152
3153 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003154}
3155
3156static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05003157configure_static_view(struct weston_view *ev, struct weston_layer *layer, int32_t width, int32_t height)
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003158{
Jason Ekstranda7af7042013-10-12 22:38:11 -05003159 struct weston_view *v, *next;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003160
Giulio Camuffo184df502013-02-21 11:29:21 +01003161 if (width == 0)
3162 return;
3163
Jason Ekstranda7af7042013-10-12 22:38:11 -05003164 wl_list_for_each_safe(v, next, &layer->view_list, layer_link) {
3165 if (v->output == ev->output && v != ev) {
3166 weston_view_unmap(v);
3167 v->surface->configure = NULL;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003168 }
3169 }
3170
Jason Ekstranda7af7042013-10-12 22:38:11 -05003171 weston_view_configure(ev, ev->output->x, ev->output->y, width, height);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003172
Jason Ekstranda7af7042013-10-12 22:38:11 -05003173 if (wl_list_empty(&ev->layer_link)) {
3174 wl_list_insert(&layer->view_list, &ev->layer_link);
3175 weston_compositor_schedule_repaint(ev->surface->compositor);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003176 }
3177}
3178
3179static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003180background_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 -04003181{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003182 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003183 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003184
Jason Ekstranda7af7042013-10-12 22:38:11 -05003185 view = container_of(es->views.next, struct weston_view, surface_link);
3186
3187 configure_static_view(view, &shell->background_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003188}
3189
3190static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003191desktop_shell_set_background(struct wl_client *client,
3192 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003193 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003194 struct wl_resource *surface_resource)
3195{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003196 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003197 struct weston_surface *surface =
3198 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003199 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003200
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003201 if (surface->configure) {
3202 wl_resource_post_error(surface_resource,
3203 WL_DISPLAY_ERROR_INVALID_OBJECT,
3204 "surface role already assigned");
3205 return;
3206 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003207
Jason Ekstranda7af7042013-10-12 22:38:11 -05003208 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3209 weston_view_destroy(view);
3210 view = weston_view_create(surface);
3211
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003212 surface->configure = background_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003213 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003214 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003215 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003216 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05003217 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003218 surface->output->width,
3219 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003220}
3221
3222static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003223panel_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 -04003224{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003225 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003226 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003227
Jason Ekstranda7af7042013-10-12 22:38:11 -05003228 view = container_of(es->views.next, struct weston_view, surface_link);
3229
3230 configure_static_view(view, &shell->panel_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003231}
3232
3233static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003234desktop_shell_set_panel(struct wl_client *client,
3235 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003236 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003237 struct wl_resource *surface_resource)
3238{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003239 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003240 struct weston_surface *surface =
3241 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003242 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003243
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003244 if (surface->configure) {
3245 wl_resource_post_error(surface_resource,
3246 WL_DISPLAY_ERROR_INVALID_OBJECT,
3247 "surface role already assigned");
3248 return;
3249 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003250
Jason Ekstranda7af7042013-10-12 22:38:11 -05003251 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3252 weston_view_destroy(view);
3253 view = weston_view_create(surface);
3254
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003255 surface->configure = panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003256 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003257 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003258 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003259 desktop_shell_send_configure(resource, 0,
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003260 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003261 surface->output->width,
3262 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003263}
3264
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003265static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003266lock_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 -04003267{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003268 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003269 struct weston_view *view;
3270
3271 view = container_of(surface->views.next, struct weston_view, surface_link);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003272
Giulio Camuffo184df502013-02-21 11:29:21 +01003273 if (width == 0)
3274 return;
3275
Jason Ekstranda7af7042013-10-12 22:38:11 -05003276 surface->width = width;
3277 surface->height = height;
3278 view->geometry.width = width;
3279 view->geometry.height = height;
3280 center_on_output(view, get_default_output(shell->compositor));
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003281
3282 if (!weston_surface_is_mapped(surface)) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05003283 wl_list_insert(&shell->lock_layer.view_list,
3284 &view->layer_link);
3285 weston_view_update_transform(view);
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003286 shell_fade(shell, FADE_IN);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003287 }
3288}
3289
3290static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003291handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003292{
Tiago Vignattibe143262012-04-16 17:31:41 +03003293 struct desktop_shell *shell =
3294 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003295
Martin Minarik6d118362012-06-07 18:01:59 +02003296 weston_log("lock surface gone\n");
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003297 shell->lock_surface = NULL;
3298}
3299
3300static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003301desktop_shell_set_lock_surface(struct wl_client *client,
3302 struct wl_resource *resource,
3303 struct wl_resource *surface_resource)
3304{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003305 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003306 struct weston_surface *surface =
3307 wl_resource_get_user_data(surface_resource);
Pekka Paalanen98262232011-12-01 10:42:22 +02003308
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003309 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02003310
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003311 if (!shell->locked)
3312 return;
3313
Pekka Paalanen98262232011-12-01 10:42:22 +02003314 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003315
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003316 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003317 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003318 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02003319
Kristian Høgsbergaa2ee8b2013-10-30 15:49:45 -07003320 weston_view_create(surface);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003321 surface->configure = lock_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003322 surface->configure_private = shell;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003323}
3324
3325static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003326resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003327{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04003328 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003329
Pekka Paalanen77346a62011-11-30 16:26:35 +02003330 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003331
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05003332 wl_list_remove(&shell->lock_layer.link);
3333 wl_list_insert(&shell->compositor->cursor_layer.link,
3334 &shell->fullscreen_layer.link);
3335 wl_list_insert(&shell->fullscreen_layer.link,
3336 &shell->panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003337 if (shell->showing_input_panels) {
3338 wl_list_insert(&shell->panel_layer.link,
3339 &shell->input_panel_layer.link);
3340 wl_list_insert(&shell->input_panel_layer.link,
3341 &ws->layer.link);
3342 } else {
3343 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
3344 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003345
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04003346 restore_focus_state(shell, get_current_workspace(shell));
Jonas Ådahl04769742012-06-13 00:01:24 +02003347
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003348 shell->locked = false;
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003349 shell_fade(shell, FADE_IN);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02003350 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003351}
3352
3353static void
3354desktop_shell_unlock(struct wl_client *client,
3355 struct wl_resource *resource)
3356{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003357 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003358
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003359 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003360
3361 if (shell->locked)
3362 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003363}
3364
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003365static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003366desktop_shell_set_grab_surface(struct wl_client *client,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003367 struct wl_resource *resource,
3368 struct wl_resource *surface_resource)
3369{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003370 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003371
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003372 shell->grab_surface = wl_resource_get_user_data(surface_resource);
Kristian Høgsberg48588f82013-10-24 15:51:35 -07003373 weston_view_create(shell->grab_surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003374}
3375
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003376static void
3377desktop_shell_desktop_ready(struct wl_client *client,
3378 struct wl_resource *resource)
3379{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003380 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003381
3382 shell_fade_startup(shell);
3383}
3384
Kristian Høgsberg75840622011-09-06 13:48:16 -04003385static const struct desktop_shell_interface desktop_shell_implementation = {
3386 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003387 desktop_shell_set_panel,
3388 desktop_shell_set_lock_surface,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003389 desktop_shell_unlock,
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003390 desktop_shell_set_grab_surface,
3391 desktop_shell_desktop_ready
Kristian Høgsberg75840622011-09-06 13:48:16 -04003392};
3393
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003394static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003395get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003396{
3397 struct shell_surface *shsurf;
3398
3399 shsurf = get_shell_surface(surface);
3400 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02003401 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003402 return shsurf->type;
3403}
3404
Kristian Høgsberg75840622011-09-06 13:48:16 -04003405static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003406move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003407{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003408 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003409 struct weston_surface *surface;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003410 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003411
Pekka Paalanen01388e22013-04-25 13:57:44 +03003412 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003413 if (surface == NULL)
3414 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003415
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003416 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003417 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3418 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003419 return;
3420
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003421 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003422}
3423
3424static void
Neil Robertsaba0f252013-10-03 16:43:05 +01003425touch_move_binding(struct weston_seat *seat, uint32_t time, void *data)
3426{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003427 struct weston_surface *focus = seat->touch->focus->surface;
Neil Robertsaba0f252013-10-03 16:43:05 +01003428 struct weston_surface *surface;
3429 struct shell_surface *shsurf;
3430
3431 surface = weston_surface_get_main_surface(focus);
3432 if (surface == NULL)
3433 return;
3434
3435 shsurf = get_shell_surface(surface);
3436 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3437 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3438 return;
3439
3440 surface_touch_move(shsurf, (struct weston_seat *) seat);
3441}
3442
3443static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003444resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003445{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003446 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003447 struct weston_surface *surface;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003448 uint32_t edges = 0;
3449 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003450 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003451
Pekka Paalanen01388e22013-04-25 13:57:44 +03003452 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003453 if (surface == NULL)
3454 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003455
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003456 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003457 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3458 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003459 return;
3460
Jason Ekstranda7af7042013-10-12 22:38:11 -05003461 weston_view_from_global(shsurf->view,
3462 wl_fixed_to_int(seat->pointer->grab_x),
3463 wl_fixed_to_int(seat->pointer->grab_y),
3464 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003465
Jason Ekstranda7af7042013-10-12 22:38:11 -05003466 if (x < shsurf->view->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003467 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003468 else if (x < 2 * shsurf->view->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003469 edges |= 0;
3470 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003471 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003472
Jason Ekstranda7af7042013-10-12 22:38:11 -05003473 if (y < shsurf->view->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003474 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003475 else if (y < 2 * shsurf->view->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003476 edges |= 0;
3477 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003478 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003479
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04003480 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04003481}
3482
3483static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003484surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003485 wl_fixed_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003486{
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003487 float step = 0.005;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003488 struct shell_surface *shsurf;
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003489 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003490 struct weston_surface *surface;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003491
Pekka Paalanen01388e22013-04-25 13:57:44 +03003492 /* XXX: broken for windows containing sub-surfaces */
3493 surface = weston_surface_get_main_surface(focus);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003494 if (surface == NULL)
3495 return;
3496
3497 shsurf = get_shell_surface(surface);
3498 if (!shsurf)
3499 return;
3500
Jason Ekstranda7af7042013-10-12 22:38:11 -05003501 shsurf->view->alpha -= wl_fixed_to_double(value) * step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003502
Jason Ekstranda7af7042013-10-12 22:38:11 -05003503 if (shsurf->view->alpha > 1.0)
3504 shsurf->view->alpha = 1.0;
3505 if (shsurf->view->alpha < step)
3506 shsurf->view->alpha = step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003507
Jason Ekstranda7af7042013-10-12 22:38:11 -05003508 weston_view_geometry_dirty(shsurf->view);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003509 weston_surface_damage(surface);
3510}
3511
3512static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003513do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003514 wl_fixed_t value)
Scott Moreauccbf29d2012-02-22 14:21:41 -07003515{
Daniel Stone37816df2012-05-16 18:45:18 +01003516 struct weston_seat *ws = (struct weston_seat *) seat;
3517 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003518 struct weston_output *output;
Scott Moreaue6603982012-06-11 13:07:51 -06003519 float increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003520
3521 wl_list_for_each(output, &compositor->output_list, link) {
3522 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01003523 wl_fixed_to_double(seat->pointer->x),
3524 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01003525 NULL)) {
Daniel Stone325fc2d2012-05-30 16:31:58 +01003526 if (key == KEY_PAGEUP)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003527 increment = output->zoom.increment;
Daniel Stone325fc2d2012-05-30 16:31:58 +01003528 else if (key == KEY_PAGEDOWN)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003529 increment = -output->zoom.increment;
3530 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003531 /* For every pixel zoom 20th of a step */
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003532 increment = output->zoom.increment *
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003533 -wl_fixed_to_double(value) / 20.0;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003534 else
3535 increment = 0;
3536
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003537 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07003538
Scott Moreaue6603982012-06-11 13:07:51 -06003539 if (output->zoom.level < 0.0)
Scott Moreau850ca422012-05-21 15:21:25 -06003540 output->zoom.level = 0.0;
Scott Moreaue6603982012-06-11 13:07:51 -06003541 else if (output->zoom.level > output->zoom.max_level)
3542 output->zoom.level = output->zoom.max_level;
Ville Syrjäläaa628d02012-11-16 11:48:47 +02003543 else if (!output->zoom.active) {
Giulio Camuffo412b0242013-11-14 23:42:51 +01003544 weston_output_activate_zoom(output);
Kristian Høgsberg79af73e2012-08-03 15:45:23 -04003545 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07003546
Scott Moreaue6603982012-06-11 13:07:51 -06003547 output->zoom.spring_z.target = output->zoom.level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003548
Jason Ekstranda7af7042013-10-12 22:38:11 -05003549 weston_output_update_zoom(output);
Scott Moreauccbf29d2012-02-22 14:21:41 -07003550 }
3551 }
3552}
3553
Scott Moreauccbf29d2012-02-22 14:21:41 -07003554static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003555zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003556 wl_fixed_t value, void *data)
Daniel Stone325fc2d2012-05-30 16:31:58 +01003557{
3558 do_zoom(seat, time, 0, axis, value);
3559}
3560
3561static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003562zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003563 void *data)
3564{
3565 do_zoom(seat, time, key, 0, 0);
3566}
3567
3568static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003569terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003570 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003571{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003572 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003573
Daniel Stone325fc2d2012-05-30 16:31:58 +01003574 wl_display_terminate(compositor->wl_display);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003575}
3576
3577static void
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01003578lower_fullscreen_layer(struct desktop_shell *shell);
3579
3580struct alt_tab {
3581 struct desktop_shell *shell;
3582 struct weston_keyboard_grab grab;
3583
3584 struct wl_list *current;
3585
3586 struct wl_list preview_list;
3587};
3588
3589struct alt_tab_preview {
3590 struct alt_tab *alt_tab;
3591
3592 struct weston_view *view;
3593 struct weston_transform transform;
3594
3595 struct wl_listener listener;
3596
3597 struct wl_list link;
3598};
3599
3600static void
3601alt_tab_next(struct alt_tab *alt_tab)
3602{
3603 alt_tab->current = alt_tab->current->next;
3604
3605 /* Make sure we're not pointing to the list header e.g. after
3606 * cycling through the whole list. */
3607 if (alt_tab->current->next == alt_tab->preview_list.next)
3608 alt_tab->current = alt_tab->current->next;
3609}
3610
3611static void
3612alt_tab_destroy(struct alt_tab *alt_tab)
3613{
3614 struct alt_tab_preview *preview, *next;
3615 struct weston_keyboard *keyboard = alt_tab->grab.keyboard;
3616
3617 if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) {
3618 preview = wl_container_of(alt_tab->current, preview, link);
3619
3620 activate(alt_tab->shell, preview->view->surface,
3621 (struct weston_seat *) keyboard->seat);
3622 }
3623
3624 wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) {
3625 wl_list_remove(&preview->link);
3626 wl_list_remove(&preview->listener.link);
3627 weston_view_destroy(preview->view);
3628 free(preview);
3629 }
3630
3631 weston_keyboard_end_grab(keyboard);
3632 if (keyboard->input_method_resource)
3633 keyboard->grab = &keyboard->input_method_grab;
3634
3635 free(alt_tab);
3636}
3637
3638static void
3639alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data)
3640{
3641 struct alt_tab_preview *preview =
3642 container_of(listener, struct alt_tab_preview, listener);
3643 struct alt_tab *alt_tab = preview->alt_tab;
3644 int advance = 0;
3645
3646 /* If the preview that we're removing is the currently selected one,
3647 * we want to move to the next one. So we move to ->prev and then
3648 * call _next() after removing the preview. */
3649 if (alt_tab->current == &preview->link) {
3650 alt_tab->current = alt_tab->current->prev;
3651 advance = 1;
3652 }
3653
3654 wl_list_remove(&preview->listener.link);
3655 wl_list_remove(&preview->link);
3656
3657 free(preview);
3658
3659 if (advance)
3660 alt_tab_next(alt_tab);
3661
3662 /* If the last preview goes away, stop the alt-tab */
3663 if (wl_list_empty(alt_tab->current))
3664 alt_tab_destroy(alt_tab);
3665}
3666
3667static void
3668alt_tab_key(struct weston_keyboard_grab *grab,
3669 uint32_t time, uint32_t key, uint32_t state_w)
3670{
3671 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3672 enum wl_keyboard_key_state state = state_w;
3673
3674 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3675 alt_tab_next(alt_tab);
3676}
3677
3678static void
3679alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
3680 uint32_t mods_depressed, uint32_t mods_latched,
3681 uint32_t mods_locked, uint32_t group)
3682{
3683 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3684 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3685
3686 if ((seat->modifier_state & MODIFIER_ALT) == 0)
3687 alt_tab_destroy(alt_tab);
3688}
3689
3690static void
3691alt_tab_cancel(struct weston_keyboard_grab *grab)
3692{
3693 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3694
3695 alt_tab_destroy(alt_tab);
3696}
3697
3698static const struct weston_keyboard_grab_interface alt_tab_grab = {
3699 alt_tab_key,
3700 alt_tab_modifier,
3701 alt_tab_cancel,
3702};
3703
3704static int
3705view_for_alt_tab(struct weston_view *view)
3706{
3707 if (!get_shell_surface(view->surface))
3708 return 0;
3709
3710 if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT)
3711 return 0;
3712
3713 if (view != get_default_view(view->surface))
3714 return 0;
3715
3716 return 1;
3717}
3718
3719static void
3720alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3721 void *data)
3722{
3723 struct alt_tab *alt_tab;
3724 struct desktop_shell *shell = data;
3725 struct weston_output *output = get_default_output(shell->compositor);
3726 struct workspace *ws;
3727 struct weston_view *view;
3728 int num_surfaces = 0;
3729 int x, y, side, margin;
3730
3731 wl_list_for_each(view, &shell->compositor->view_list, link) {
3732
3733 if (view_for_alt_tab(view))
3734 num_surfaces++;
3735 }
3736
3737 if (!num_surfaces)
3738 return;
3739
3740 alt_tab = malloc(sizeof *alt_tab);
3741 if (!alt_tab)
3742 return;
3743
3744 alt_tab->shell = shell;
3745 wl_list_init(&alt_tab->preview_list);
3746 alt_tab->current = &alt_tab->preview_list;
3747
3748 restore_all_output_modes(shell->compositor);
3749 lower_fullscreen_layer(alt_tab->shell);
3750
3751 alt_tab->grab.interface = &alt_tab_grab;
3752 weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab);
3753 weston_keyboard_set_focus(seat->keyboard, NULL);
3754
3755 ws = get_current_workspace(shell);
3756
3757 /* FIXME: add some visual candy e.g. prelight the selected view
3758 * and/or add a black surrounding background à la gnome-shell */
3759
3760 /* Determine the size for each preview */
3761 side = output->width / num_surfaces;
3762 if (side > 200)
3763 side = 200;
3764 margin = side / 4;
3765 side -= margin;
3766
3767 x = margin;
3768 y = (output->height - side) / 2;
3769
3770 /* Create a view for each surface */
3771 wl_list_for_each(view, &shell->compositor->view_list, link) {
3772 struct alt_tab_preview *preview;
3773 struct weston_view *v;
3774 float scale;
3775
3776 if (!view_for_alt_tab(view))
3777 continue;
3778
3779 preview = malloc(sizeof *preview);
3780 if (!preview) {
3781 alt_tab_destroy(alt_tab);
3782 return;
3783 }
3784
3785 preview->alt_tab = alt_tab;
3786
3787 preview->view = v = weston_view_create(view->surface);
3788 v->output = view->output;
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003789
3790 wl_list_remove(&v->layer_link);
3791 wl_list_insert(&ws->layer.view_list, &v->layer_link);
3792 weston_view_damage_below(v);
3793 weston_surface_damage(v->surface);
3794
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01003795 weston_view_configure(v, x, y, view->geometry.width, view->geometry.height);
3796
3797 preview->listener.notify = alt_tab_handle_surface_destroy;
3798 wl_signal_add(&v->destroy_signal, &preview->listener);
3799
3800 if (view->geometry.width > view->geometry.height)
3801 scale = side / (float) view->geometry.width;
3802 else
3803 scale = side / (float) view->geometry.height;
3804
3805 wl_list_insert(&v->geometry.transformation_list,
3806 &preview->transform.link);
3807 weston_matrix_init(&preview->transform.matrix);
3808 weston_matrix_scale(&preview->transform.matrix,
3809 scale, scale, 1.0f);
3810
3811 weston_view_geometry_dirty(v);
3812 weston_compositor_schedule_repaint(v->surface->compositor);
3813
3814 /* Insert at the end of the list */
3815 wl_list_insert(alt_tab->preview_list.prev, &preview->link);
3816
3817 x += side + margin;
3818 }
3819
3820 /* Start at the second preview so a simple <alt>tab changes window.
3821 * We set `current' to the first preview and not the second because
3822 * we're going to receive a key press callback for the initial
3823 * <alt>tab which will make `current' point to the second element. */
3824 alt_tab_next(alt_tab);
3825}
3826
3827static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01003828rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
3829 wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003830{
3831 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003832 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003833 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003834 struct shell_surface *shsurf = rotate->base.shsurf;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003835 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003836
Giulio Camuffo1959ab82013-11-14 23:42:52 +01003837 weston_pointer_move(pointer, x, y);
3838
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003839 if (!shsurf)
3840 return;
3841
Jason Ekstranda7af7042013-10-12 22:38:11 -05003842 cx = 0.5f * shsurf->view->geometry.width;
3843 cy = 0.5f * shsurf->view->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003844
Daniel Stone37816df2012-05-16 18:45:18 +01003845 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
3846 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003847 r = sqrtf(dx * dx + dy * dy);
3848
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003849 wl_list_remove(&shsurf->rotation.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003850 weston_view_geometry_dirty(shsurf->view);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003851
3852 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02003853 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003854 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003855
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003856 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003857 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003858
3859 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02003860 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003861 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003862 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02003863 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003864
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02003865 wl_list_insert(
Jason Ekstranda7af7042013-10-12 22:38:11 -05003866 &shsurf->view->geometry.transformation_list,
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003867 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003868 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003869 wl_list_init(&shsurf->rotation.transform.link);
3870 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003871 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003872 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02003873
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003874 /* We need to adjust the position of the surface
3875 * in case it was resized in a rotated state before */
Jason Ekstranda7af7042013-10-12 22:38:11 -05003876 cposx = shsurf->view->geometry.x + cx;
3877 cposy = shsurf->view->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003878 dposx = rotate->center.x - cposx;
3879 dposy = rotate->center.y - cposy;
3880 if (dposx != 0.0f || dposy != 0.0f) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05003881 weston_view_set_position(shsurf->view,
3882 shsurf->view->geometry.x + dposx,
3883 shsurf->view->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003884 }
3885
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02003886 /* Repaint implies weston_surface_update_transform(), which
3887 * lazily applies the damage due to rotation update.
3888 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003889 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003890}
3891
3892static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003893rotate_grab_button(struct weston_pointer_grab *grab,
3894 uint32_t time, uint32_t button, uint32_t state_w)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003895{
3896 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003897 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003898 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003899 struct shell_surface *shsurf = rotate->base.shsurf;
Daniel Stone4dbadb12012-05-30 16:31:51 +01003900 enum wl_pointer_button_state state = state_w;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003901
Daniel Stone4dbadb12012-05-30 16:31:51 +01003902 if (pointer->button_count == 0 &&
3903 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003904 if (shsurf)
3905 weston_matrix_multiply(&shsurf->rotation.rotation,
3906 &rotate->rotation);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003907 shell_grab_end(&rotate->base);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003908 free(rotate);
3909 }
3910}
3911
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02003912static void
3913rotate_grab_cancel(struct weston_pointer_grab *grab)
3914{
3915 struct rotate_grab *rotate =
3916 container_of(grab, struct rotate_grab, base.grab);
3917
3918 shell_grab_end(&rotate->base);
3919 free(rotate);
3920}
3921
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003922static const struct weston_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02003923 noop_grab_focus,
3924 rotate_grab_motion,
3925 rotate_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02003926 rotate_grab_cancel,
Pekka Paalanen460099f2012-01-20 16:48:25 +02003927};
3928
3929static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003930surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003931{
Pekka Paalanen460099f2012-01-20 16:48:25 +02003932 struct rotate_grab *rotate;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003933 float dx, dy;
3934 float r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003935
Pekka Paalanen460099f2012-01-20 16:48:25 +02003936 rotate = malloc(sizeof *rotate);
3937 if (!rotate)
3938 return;
3939
Jason Ekstranda7af7042013-10-12 22:38:11 -05003940 weston_view_to_global_float(surface->view,
3941 surface->view->geometry.width * 0.5f,
3942 surface->view->geometry.height * 0.5f,
3943 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003944
Daniel Stone37816df2012-05-16 18:45:18 +01003945 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
3946 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003947 r = sqrtf(dx * dx + dy * dy);
3948 if (r > 20.0f) {
3949 struct weston_matrix inverse;
3950
3951 weston_matrix_init(&inverse);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003952 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003953 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003954
3955 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003956 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003957 } else {
3958 weston_matrix_init(&surface->rotation.rotation);
3959 weston_matrix_init(&rotate->rotation);
3960 }
3961
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003962 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
3963 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003964}
3965
3966static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003967rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003968 void *data)
3969{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003970 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003971 struct weston_surface *base_surface;
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003972 struct shell_surface *surface;
3973
Pekka Paalanen01388e22013-04-25 13:57:44 +03003974 base_surface = weston_surface_get_main_surface(focus);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003975 if (base_surface == NULL)
3976 return;
3977
3978 surface = get_shell_surface(base_surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003979 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
3980 surface->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003981 return;
3982
3983 surface_rotate(surface, seat);
3984}
3985
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003986/* Move all fullscreen layers down to the current workspace in a non-reversible
3987 * manner. This should be used when implementing shell-wide overlays, such as
3988 * the alt-tab switcher, which need to de-promote fullscreen layers. */
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003989static void
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003990lower_fullscreen_layer(struct desktop_shell *shell)
3991{
3992 struct workspace *ws;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003993 struct weston_view *view, *prev;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003994
3995 ws = get_current_workspace(shell);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003996 wl_list_for_each_reverse_safe(view, prev,
3997 &shell->fullscreen_layer.view_list,
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003998 layer_link) {
3999 wl_list_remove(&view->layer_link);
4000 wl_list_insert(&ws->layer.view_list, &view->layer_link);
4001 weston_view_damage_below(view);
4002 weston_surface_damage(view->surface);
4003 }
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04004004}
4005
4006static void
Tiago Vignattibe143262012-04-16 17:31:41 +03004007activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01004008 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04004009{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004010 struct weston_surface *main_surface;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004011 struct focus_state *state;
Jonas Ådahl8538b222012-08-29 22:13:03 +02004012 struct workspace *ws;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004013 struct weston_surface *old_es;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004014
Pekka Paalanen01388e22013-04-25 13:57:44 +03004015 main_surface = weston_surface_get_main_surface(es);
4016
Daniel Stone37816df2012-05-16 18:45:18 +01004017 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004018
Jonas Ådahl8538b222012-08-29 22:13:03 +02004019 state = ensure_focus_state(shell, seat);
4020 if (state == NULL)
4021 return;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004022
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004023 old_es = state->keyboard_focus;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004024 state->keyboard_focus = es;
4025 wl_list_remove(&state->surface_destroy_listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05004026 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004027
Pekka Paalanen01388e22013-04-25 13:57:44 +03004028 switch (get_shell_surface_type(main_surface)) {
Alex Wu4539b082012-03-01 12:57:46 +08004029 case SHELL_SURFACE_FULLSCREEN:
4030 /* should on top of panels */
Pekka Paalanen01388e22013-04-25 13:57:44 +03004031 shell_configure_fullscreen(get_shell_surface(main_surface));
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004032 return;
Philip Withnall0f640e22013-11-25 18:01:31 +00004033 case SHELL_SURFACE_TOPLEVEL:
4034 case SHELL_SURFACE_TRANSIENT:
4035 case SHELL_SURFACE_MAXIMIZED:
4036 case SHELL_SURFACE_POPUP:
4037 case SHELL_SURFACE_XWAYLAND:
4038 case SHELL_SURFACE_NONE:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02004039 default:
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02004040 restore_all_output_modes(shell->compositor);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004041 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004042 }
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004043
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004044 if (shell->focus_animation_type != ANIMATION_NONE) {
4045 ws = get_current_workspace(shell);
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004046 animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es));
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004047 }
4048
4049 /* Update the surface’s layer. This brings it to the top of the stacking
4050 * order as appropriate. */
4051 shell_surface_update_layer(get_shell_surface(main_surface));
Kristian Høgsberg75840622011-09-06 13:48:16 -04004052}
4053
Alex Wu21858432012-04-01 20:13:08 +08004054/* no-op func for checking black surface */
4055static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004056black_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 +08004057{
4058}
4059
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01004060static bool
Alex Wu21858432012-04-01 20:13:08 +08004061is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
4062{
4063 if (es->configure == black_surface_configure) {
4064 if (fs_surface)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004065 *fs_surface = (struct weston_surface *)es->configure_private;
Alex Wu21858432012-04-01 20:13:08 +08004066 return true;
4067 }
4068 return false;
4069}
4070
Kristian Høgsberg75840622011-09-06 13:48:16 -04004071static void
Neil Robertsa28c6932013-10-03 16:43:04 +01004072activate_binding(struct weston_seat *seat,
4073 struct desktop_shell *shell,
4074 struct weston_surface *focus)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004075{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004076 struct weston_surface *main_surface;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004077
Alex Wu9c35e6b2012-03-05 14:13:13 +08004078 if (!focus)
4079 return;
4080
Pekka Paalanen01388e22013-04-25 13:57:44 +03004081 if (is_black_surface(focus, &main_surface))
4082 focus = main_surface;
Alex Wu4539b082012-03-01 12:57:46 +08004083
Pekka Paalanen01388e22013-04-25 13:57:44 +03004084 main_surface = weston_surface_get_main_surface(focus);
4085 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004086 return;
Kristian Høgsberg85b2e4b2012-06-21 16:49:42 -04004087
Neil Robertsa28c6932013-10-03 16:43:04 +01004088 activate(shell, focus, seat);
4089}
4090
4091static void
4092click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
4093 void *data)
4094{
4095 if (seat->pointer->grab != &seat->pointer->default_grab)
4096 return;
4097
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004098 activate_binding(seat, data, seat->pointer->focus->surface);
Neil Robertsa28c6932013-10-03 16:43:04 +01004099}
4100
4101static void
4102touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
4103{
4104 if (seat->touch->grab != &seat->touch->default_grab)
4105 return;
4106
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004107 activate_binding(seat, data, seat->touch->focus->surface);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004108}
4109
4110static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004111lock(struct desktop_shell *shell)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004112{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004113 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004114
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004115 if (shell->locked) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004116 weston_compositor_sleep(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004117 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004118 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004119
4120 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004121
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004122 /* Hide all surfaces by removing the fullscreen, panel and
4123 * toplevel layers. This way nothing else can show or receive
4124 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004125
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004126 wl_list_remove(&shell->panel_layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004127 wl_list_remove(&shell->fullscreen_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004128 if (shell->showing_input_panels)
4129 wl_list_remove(&shell->input_panel_layer.link);
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004130 wl_list_remove(&ws->layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004131 wl_list_insert(&shell->compositor->cursor_layer.link,
4132 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004133
Pekka Paalanen77346a62011-11-30 16:26:35 +02004134 launch_screensaver(shell);
4135
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004136 /* TODO: disable bindings that should not work while locked. */
4137
4138 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004139}
4140
4141static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004142unlock(struct desktop_shell *shell)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004143{
Pekka Paalanend81c2162011-11-16 13:47:34 +02004144 if (!shell->locked || shell->lock_surface) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004145 shell_fade(shell, FADE_IN);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004146 return;
4147 }
4148
4149 /* If desktop-shell client has gone away, unlock immediately. */
4150 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004151 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004152 return;
4153 }
4154
4155 if (shell->prepare_event_sent)
4156 return;
4157
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05004158 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004159 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004160}
4161
4162static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004163shell_fade_done(struct weston_view_animation *animation, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004164{
4165 struct desktop_shell *shell = data;
4166
4167 shell->fade.animation = NULL;
4168
4169 switch (shell->fade.type) {
4170 case FADE_IN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004171 weston_surface_destroy(shell->fade.view->surface);
4172 shell->fade.view = NULL;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004173 break;
4174 case FADE_OUT:
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004175 lock(shell);
4176 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004177 default:
4178 break;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004179 }
4180}
4181
Jason Ekstranda7af7042013-10-12 22:38:11 -05004182static struct weston_view *
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004183shell_fade_create_surface(struct desktop_shell *shell)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004184{
4185 struct weston_compositor *compositor = shell->compositor;
4186 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004187 struct weston_view *view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004188
4189 surface = weston_surface_create(compositor);
4190 if (!surface)
4191 return NULL;
4192
Jason Ekstranda7af7042013-10-12 22:38:11 -05004193 view = weston_view_create(surface);
4194 if (!view) {
4195 weston_surface_destroy(surface);
4196 return NULL;
4197 }
4198
4199 weston_view_configure(view, 0, 0, 8192, 8192);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004200 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004201 wl_list_insert(&compositor->fade_layer.view_list,
4202 &view->layer_link);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004203 pixman_region32_init(&surface->input);
4204
Jason Ekstranda7af7042013-10-12 22:38:11 -05004205 return view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004206}
4207
4208static void
4209shell_fade(struct desktop_shell *shell, enum fade_type type)
4210{
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004211 float tint;
4212
4213 switch (type) {
4214 case FADE_IN:
4215 tint = 0.0;
4216 break;
4217 case FADE_OUT:
4218 tint = 1.0;
4219 break;
4220 default:
4221 weston_log("shell: invalid fade type\n");
4222 return;
4223 }
4224
4225 shell->fade.type = type;
4226
Jason Ekstranda7af7042013-10-12 22:38:11 -05004227 if (shell->fade.view == NULL) {
4228 shell->fade.view = shell_fade_create_surface(shell);
4229 if (!shell->fade.view)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004230 return;
4231
Jason Ekstranda7af7042013-10-12 22:38:11 -05004232 shell->fade.view->alpha = 1.0 - tint;
4233 weston_view_update_transform(shell->fade.view);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004234 }
4235
4236 if (shell->fade.animation)
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004237 weston_fade_update(shell->fade.animation, tint);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004238 else
4239 shell->fade.animation =
Jason Ekstranda7af7042013-10-12 22:38:11 -05004240 weston_fade_run(shell->fade.view,
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004241 1.0 - tint, tint, 300.0,
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004242 shell_fade_done, shell);
4243}
4244
4245static void
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004246do_shell_fade_startup(void *data)
4247{
4248 struct desktop_shell *shell = data;
4249
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004250 if (shell->startup_animation_type == ANIMATION_FADE)
4251 shell_fade(shell, FADE_IN);
4252 else if (shell->startup_animation_type == ANIMATION_NONE) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004253 weston_surface_destroy(shell->fade.view->surface);
4254 shell->fade.view = NULL;
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004255 }
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004256}
4257
4258static void
4259shell_fade_startup(struct desktop_shell *shell)
4260{
4261 struct wl_event_loop *loop;
4262
4263 if (!shell->fade.startup_timer)
4264 return;
4265
4266 wl_event_source_remove(shell->fade.startup_timer);
4267 shell->fade.startup_timer = NULL;
4268
4269 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4270 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
4271}
4272
4273static int
4274fade_startup_timeout(void *data)
4275{
4276 struct desktop_shell *shell = data;
4277
4278 shell_fade_startup(shell);
4279 return 0;
4280}
4281
4282static void
4283shell_fade_init(struct desktop_shell *shell)
4284{
4285 /* Make compositor output all black, and wait for the desktop-shell
4286 * client to signal it is ready, then fade in. The timer triggers a
4287 * fade-in, in case the desktop-shell client takes too long.
4288 */
4289
4290 struct wl_event_loop *loop;
4291
Jason Ekstranda7af7042013-10-12 22:38:11 -05004292 if (shell->fade.view != NULL) {
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004293 weston_log("%s: warning: fade surface already exists\n",
4294 __func__);
4295 return;
4296 }
4297
Jason Ekstranda7af7042013-10-12 22:38:11 -05004298 shell->fade.view = shell_fade_create_surface(shell);
4299 if (!shell->fade.view)
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004300 return;
4301
Jason Ekstranda7af7042013-10-12 22:38:11 -05004302 weston_view_update_transform(shell->fade.view);
4303 weston_surface_damage(shell->fade.view->surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004304
4305 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4306 shell->fade.startup_timer =
4307 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
4308 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
4309}
4310
4311static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004312idle_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004313{
4314 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004315 container_of(listener, struct desktop_shell, idle_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004316
4317 shell_fade(shell, FADE_OUT);
4318 /* lock() is called from shell_fade_done() */
4319}
4320
4321static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004322wake_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004323{
4324 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004325 container_of(listener, struct desktop_shell, wake_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004326
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004327 unlock(shell);
4328}
4329
4330static void
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004331show_input_panels(struct wl_listener *listener, void *data)
4332{
4333 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004334 container_of(listener, struct desktop_shell,
4335 show_input_panel_listener);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004336 struct input_panel_surface *ipsurf, *next;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004337
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004338 shell->text_input.surface = (struct weston_surface*)data;
4339
Jan Arne Petersen451a9712013-02-11 15:10:11 +01004340 if (shell->showing_input_panels)
4341 return;
4342
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004343 shell->showing_input_panels = true;
4344
Jan Arne Petersencf18a322012-11-07 15:32:54 +01004345 if (!shell->locked)
4346 wl_list_insert(&shell->panel_layer.link,
4347 &shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004348
Jason Ekstranda7af7042013-10-12 22:38:11 -05004349 wl_list_for_each_safe(ipsurf, next,
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004350 &shell->input_panel.surfaces, link) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004351 if (!ipsurf->surface->buffer_ref.buffer)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004352 continue;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004353 wl_list_insert(&shell->input_panel_layer.view_list,
4354 &ipsurf->view->layer_link);
4355 weston_view_geometry_dirty(ipsurf->view);
4356 weston_view_update_transform(ipsurf->view);
4357 weston_surface_damage(ipsurf->surface);
4358 weston_slide_run(ipsurf->view, ipsurf->view->geometry.height,
4359 0, NULL, NULL);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004360 }
4361}
4362
4363static void
4364hide_input_panels(struct wl_listener *listener, void *data)
4365{
4366 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004367 container_of(listener, struct desktop_shell,
4368 hide_input_panel_listener);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004369 struct weston_view *view, *next;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004370
Jan Arne Petersen61381972013-01-31 15:52:21 +01004371 if (!shell->showing_input_panels)
4372 return;
4373
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004374 shell->showing_input_panels = false;
4375
Jan Arne Petersen82ec9092012-12-03 15:36:02 +01004376 if (!shell->locked)
4377 wl_list_remove(&shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004378
Jason Ekstranda7af7042013-10-12 22:38:11 -05004379 wl_list_for_each_safe(view, next,
4380 &shell->input_panel_layer.view_list, layer_link)
4381 weston_view_unmap(view);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004382}
4383
4384static void
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004385update_input_panels(struct wl_listener *listener, void *data)
4386{
4387 struct desktop_shell *shell =
4388 container_of(listener, struct desktop_shell,
4389 update_input_panel_listener);
4390
4391 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
4392}
4393
4394static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004395center_on_output(struct weston_view *view, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02004396{
Giulio Camuffob8366642013-04-25 13:57:46 +03004397 int32_t surf_x, surf_y, width, height;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004398 float x, y;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004399
Jason Ekstranda7af7042013-10-12 22:38:11 -05004400 surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height);
Giulio Camuffob8366642013-04-25 13:57:46 +03004401
4402 x = output->x + (output->width - width) / 2 - surf_x / 2;
4403 y = output->y + (output->height - height) / 2 - surf_y / 2;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004404
Jason Ekstranda7af7042013-10-12 22:38:11 -05004405 weston_view_configure(view, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004406}
4407
4408static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004409weston_view_set_initial_position(struct weston_view *view,
4410 struct desktop_shell *shell)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004411{
4412 struct weston_compositor *compositor = shell->compositor;
4413 int ix = 0, iy = 0;
4414 int range_x, range_y;
4415 int dx, dy, x, y, panel_height;
4416 struct weston_output *output, *target_output = NULL;
4417 struct weston_seat *seat;
4418
4419 /* As a heuristic place the new window on the same output as the
4420 * pointer. Falling back to the output containing 0, 0.
4421 *
4422 * TODO: Do something clever for touch too?
4423 */
4424 wl_list_for_each(seat, &compositor->seat_list, link) {
Kristian Høgsberg2bf87622013-05-07 23:17:41 -04004425 if (seat->pointer) {
Kristian Høgsberge3148752013-05-06 23:19:49 -04004426 ix = wl_fixed_to_int(seat->pointer->x);
4427 iy = wl_fixed_to_int(seat->pointer->y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004428 break;
4429 }
4430 }
4431
4432 wl_list_for_each(output, &compositor->output_list, link) {
4433 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
4434 target_output = output;
4435 break;
4436 }
4437 }
4438
4439 if (!target_output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004440 weston_view_set_position(view, 10 + random() % 400,
4441 10 + random() % 400);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004442 return;
4443 }
4444
4445 /* Valid range within output where the surface will still be onscreen.
4446 * If this is negative it means that the surface is bigger than
4447 * output.
4448 */
4449 panel_height = get_output_panel_height(shell, target_output);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004450 range_x = target_output->width - view->geometry.width;
Scott Moreau1bad5db2012-08-18 01:04:05 -06004451 range_y = (target_output->height - panel_height) -
Jason Ekstranda7af7042013-10-12 22:38:11 -05004452 view->geometry.height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004453
Rob Bradford4cb88c72012-08-13 15:18:44 +01004454 if (range_x > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004455 dx = random() % range_x;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004456 else
Rob Bradford4cb88c72012-08-13 15:18:44 +01004457 dx = 0;
4458
4459 if (range_y > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004460 dy = panel_height + random() % range_y;
Rob Bradford4cb88c72012-08-13 15:18:44 +01004461 else
4462 dy = panel_height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004463
4464 x = target_output->x + dx;
4465 y = target_output->y + dy;
4466
Jason Ekstranda7af7042013-10-12 22:38:11 -05004467 weston_view_set_position(view, x, y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004468}
4469
4470static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004471map(struct desktop_shell *shell, struct shell_surface *shsurf,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02004472 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004473{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004474 struct weston_compositor *compositor = shell->compositor;
Daniel Stoneb2104682012-05-30 16:31:56 +01004475 struct weston_seat *seat;
Juan Zhao96879df2012-02-07 08:45:41 +08004476 int panel_height = 0;
Giulio Camuffob8366642013-04-25 13:57:46 +03004477 int32_t surf_x, surf_y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02004478
Jason Ekstranda7af7042013-10-12 22:38:11 -05004479 shsurf->view->geometry.width = width;
4480 shsurf->view->geometry.height = height;
4481 weston_view_geometry_dirty(shsurf->view);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004482
4483 /* initial positioning, see also configure() */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004484 switch (shsurf->type) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02004485 case SHELL_SURFACE_TOPLEVEL:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004486 weston_view_set_initial_position(shsurf->view, shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004487 break;
Alex Wu4539b082012-03-01 12:57:46 +08004488 case SHELL_SURFACE_FULLSCREEN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004489 center_on_output(shsurf->view, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08004490 shell_map_fullscreen(shsurf);
4491 break;
Juan Zhao96879df2012-02-07 08:45:41 +08004492 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08004493 /* use surface configure to set the geometry */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004494 panel_height = get_output_panel_height(shell, shsurf->output);
4495 surface_subsurfaces_boundingbox(shsurf->surface,
4496 &surf_x, &surf_y, NULL, NULL);
4497 weston_view_set_position(shsurf->view,
4498 shsurf->output->x - surf_x,
4499 shsurf->output->y + panel_height - surf_y);
Juan Zhao96879df2012-02-07 08:45:41 +08004500 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02004501 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04004502 shell_map_popup(shsurf);
Rob Bradforddb999382012-12-06 12:07:48 +00004503 break;
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02004504 case SHELL_SURFACE_NONE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004505 weston_view_set_position(shsurf->view,
4506 shsurf->view->geometry.x + sx,
4507 shsurf->view->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02004508 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004509 case SHELL_SURFACE_TRANSIENT:
4510 case SHELL_SURFACE_XWAYLAND:
Pekka Paalanen77346a62011-11-30 16:26:35 +02004511 default:
4512 ;
4513 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04004514
Philip Withnalle1d75ae2013-11-25 18:01:41 +00004515 /* Surface stacking order, see also activate(). */
4516 shell_surface_update_layer(shsurf);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004517
Jason Ekstranda7af7042013-10-12 22:38:11 -05004518 if (shsurf->type != SHELL_SURFACE_NONE) {
4519 weston_view_update_transform(shsurf->view);
4520 if (shsurf->type == SHELL_SURFACE_MAXIMIZED) {
4521 shsurf->surface->output = shsurf->output;
4522 shsurf->view->output = shsurf->output;
4523 }
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02004524 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05004525
Jason Ekstranda7af7042013-10-12 22:38:11 -05004526 switch (shsurf->type) {
Tiago Vignattifb2adba2013-06-12 15:43:21 -03004527 /* XXX: xwayland's using the same fields for transient type */
4528 case SHELL_SURFACE_XWAYLAND:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004529 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03004530 if (shsurf->transient.flags ==
4531 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
4532 break;
4533 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004534 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08004535 case SHELL_SURFACE_MAXIMIZED:
Daniel Stoneb2104682012-05-30 16:31:56 +01004536 if (!shell->locked) {
4537 wl_list_for_each(seat, &compositor->seat_list, link)
Jason Ekstranda7af7042013-10-12 22:38:11 -05004538 activate(shell, shsurf->surface, seat);
Daniel Stoneb2104682012-05-30 16:31:56 +01004539 }
Juan Zhao7bb92f02011-12-15 11:31:51 -05004540 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004541 case SHELL_SURFACE_POPUP:
4542 case SHELL_SURFACE_NONE:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004543 default:
4544 break;
4545 }
4546
Jason Ekstranda7af7042013-10-12 22:38:11 -05004547 if (shsurf->type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08004548 {
4549 switch (shell->win_animation_type) {
4550 case ANIMATION_FADE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004551 weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004552 break;
4553 case ANIMATION_ZOOM:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004554 weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004555 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004556 case ANIMATION_NONE:
Juan Zhaoe10d2792012-04-25 19:09:52 +08004557 default:
4558 break;
4559 }
4560 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004561}
4562
4563static void
Tiago Vignattibe143262012-04-16 17:31:41 +03004564configure(struct desktop_shell *shell, struct weston_surface *surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004565 float x, float y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004566{
Pekka Paalanen77346a62011-11-30 16:26:35 +02004567 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
4568 struct shell_surface *shsurf;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004569 struct weston_view *view;
Giulio Camuffob8366642013-04-25 13:57:46 +03004570 int32_t surf_x, surf_y;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004571
Pekka Paalanen77346a62011-11-30 16:26:35 +02004572 shsurf = get_shell_surface(surface);
4573 if (shsurf)
4574 surface_type = shsurf->type;
4575
Jason Ekstranda7af7042013-10-12 22:38:11 -05004576 /* TODO:
4577 * This should probably be changed to be more shell_surface
4578 * dependent
4579 */
4580 wl_list_for_each(view, &surface->views, surface_link)
4581 weston_view_configure(view, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004582
4583 switch (surface_type) {
Alex Wu4539b082012-03-01 12:57:46 +08004584 case SHELL_SURFACE_FULLSCREEN:
4585 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08004586 break;
Juan Zhao96879df2012-02-07 08:45:41 +08004587 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08004588 /* setting x, y and using configure to change that geometry */
Giulio Camuffob8366642013-04-25 13:57:46 +03004589 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
4590 NULL, NULL);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004591 shsurf->view->geometry.x = shsurf->output->x - surf_x;
4592 shsurf->view->geometry.y = shsurf->output->y +
4593 get_output_panel_height(shell,shsurf->output) - surf_y;
Juan Zhao96879df2012-02-07 08:45:41 +08004594 break;
Alex Wu4539b082012-03-01 12:57:46 +08004595 case SHELL_SURFACE_TOPLEVEL:
Philip Withnall0f640e22013-11-25 18:01:31 +00004596 case SHELL_SURFACE_TRANSIENT:
4597 case SHELL_SURFACE_POPUP:
4598 case SHELL_SURFACE_XWAYLAND:
4599 case SHELL_SURFACE_NONE:
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05004600 default:
4601 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04004602 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004603
Alex Wu4539b082012-03-01 12:57:46 +08004604 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05004605 if (surface->output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004606 wl_list_for_each(view, &surface->views, surface_link)
4607 weston_view_update_transform(view);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004608
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004609 if (surface_type == SHELL_SURFACE_MAXIMIZED)
Juan Zhao96879df2012-02-07 08:45:41 +08004610 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004611 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04004612}
4613
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004614static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004615shell_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 +03004616{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03004617 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03004618 struct desktop_shell *shell = shsurf->shell;
Giulio Camuffo184df502013-02-21 11:29:21 +01004619
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03004620 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004621
Kristian Høgsberg8eb0f4f2013-06-17 10:33:14 -04004622 if (!weston_surface_is_mapped(es) &&
4623 !wl_list_empty(&shsurf->popup.grab_link)) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01004624 remove_popup_grab(shsurf);
4625 }
4626
Giulio Camuffo184df502013-02-21 11:29:21 +01004627 if (width == 0)
4628 return;
4629
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004630 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004631 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004632 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004633 type_changed = 1;
4634 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004635
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004636 if (!weston_surface_is_mapped(es)) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004637 map(shell, shsurf, width, height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004638 } else if (type_changed || sx != 0 || sy != 0 ||
Jason Ekstranda7af7042013-10-12 22:38:11 -05004639 shsurf->view->geometry.width != width ||
4640 shsurf->view->geometry.height != height) {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004641 float from_x, from_y;
4642 float to_x, to_y;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004643
Jason Ekstranda7af7042013-10-12 22:38:11 -05004644 weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y);
4645 weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004646 configure(shell, es,
Jason Ekstranda7af7042013-10-12 22:38:11 -05004647 shsurf->view->geometry.x + to_x - from_x,
4648 shsurf->view->geometry.y + to_y - from_y,
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004649 width, height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004650 }
4651}
4652
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004653static void launch_desktop_shell_process(void *data);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004654
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004655static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004656desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004657{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004658 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03004659 struct desktop_shell *shell =
4660 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004661
4662 shell->child.process.pid = 0;
4663 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004664
4665 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
4666 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05004667 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004668 shell->child.deathstamp = time;
4669 shell->child.deathcount = 0;
4670 }
4671
4672 shell->child.deathcount++;
4673 if (shell->child.deathcount > 5) {
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004674 weston_log("%s died, giving up.\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004675 return;
4676 }
4677
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004678 weston_log("%s died, respawning...\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004679 launch_desktop_shell_process(shell);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004680 shell_fade_startup(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004681}
4682
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004683static void
4684launch_desktop_shell_process(void *data)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004685{
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004686 struct desktop_shell *shell = data;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004687
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004688 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02004689 &shell->child.process,
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004690 shell->client,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02004691 desktop_shell_sigchld);
4692
4693 if (!shell->child.client)
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004694 weston_log("not able to start %s\n", shell->client);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004695}
4696
4697static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004698bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
4699{
Tiago Vignattibe143262012-04-16 17:31:41 +03004700 struct desktop_shell *shell = data;
Jason Ekstranda85118c2013-06-27 20:17:02 -05004701 struct wl_resource *resource;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004702
Jason Ekstranda85118c2013-06-27 20:17:02 -05004703 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
4704 if (resource)
4705 wl_resource_set_implementation(resource, &shell_implementation,
4706 shell, NULL);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004707}
4708
Kristian Høgsberg75840622011-09-06 13:48:16 -04004709static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004710unbind_desktop_shell(struct wl_resource *resource)
4711{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004712 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05004713
4714 if (shell->locked)
4715 resume_desktop(shell);
4716
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004717 shell->child.desktop_shell = NULL;
4718 shell->prepare_event_sent = false;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004719}
4720
4721static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04004722bind_desktop_shell(struct wl_client *client,
4723 void *data, uint32_t version, uint32_t id)
4724{
Tiago Vignattibe143262012-04-16 17:31:41 +03004725 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004726 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004727
Jason Ekstranda85118c2013-06-27 20:17:02 -05004728 resource = wl_resource_create(client, &desktop_shell_interface,
4729 MIN(version, 2), id);
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004730
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004731 if (client == shell->child.client) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05004732 wl_resource_set_implementation(resource,
4733 &desktop_shell_implementation,
4734 shell, unbind_desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004735 shell->child.desktop_shell = resource;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004736
4737 if (version < 2)
4738 shell_fade_startup(shell);
4739
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004740 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004741 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004742
4743 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4744 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04004745 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004746}
4747
Pekka Paalanen6e168112011-11-24 11:34:05 +02004748static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004749screensaver_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 -04004750{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004751 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004752 struct weston_view *view;
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004753
Giulio Camuffo184df502013-02-21 11:29:21 +01004754 if (width == 0)
4755 return;
4756
Pekka Paalanen3a1d07d2012-12-20 14:02:13 +02004757 /* XXX: starting weston-screensaver beforehand does not work */
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004758 if (!shell->locked)
4759 return;
4760
Jason Ekstranda7af7042013-10-12 22:38:11 -05004761 view = container_of(surface->views.next, struct weston_view, surface_link);
4762 center_on_output(view, surface->output);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004763
Jason Ekstranda7af7042013-10-12 22:38:11 -05004764 if (wl_list_empty(&view->layer_link)) {
4765 wl_list_insert(shell->lock_layer.view_list.prev,
4766 &view->layer_link);
4767 weston_view_update_transform(view);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02004768 wl_event_source_timer_update(shell->screensaver.timer,
4769 shell->screensaver.duration);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004770 shell_fade(shell, FADE_IN);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004771 }
4772}
4773
4774static void
Pekka Paalanen6e168112011-11-24 11:34:05 +02004775screensaver_set_surface(struct wl_client *client,
4776 struct wl_resource *resource,
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004777 struct wl_resource *surface_resource,
Pekka Paalanen6e168112011-11-24 11:34:05 +02004778 struct wl_resource *output_resource)
4779{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004780 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05004781 struct weston_surface *surface =
4782 wl_resource_get_user_data(surface_resource);
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05004783 struct weston_output *output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004784 struct weston_view *view, *next;
4785
4786 /* Make sure we only have one view */
4787 wl_list_for_each_safe(view, next, &surface->views, surface_link)
4788 weston_view_destroy(view);
4789 weston_view_create(surface);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004790
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004791 surface->configure = screensaver_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004792 surface->configure_private = shell;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004793 surface->output = output;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004794}
4795
4796static const struct screensaver_interface screensaver_implementation = {
4797 screensaver_set_surface
4798};
4799
4800static void
4801unbind_screensaver(struct wl_resource *resource)
4802{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004803 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004804
Pekka Paalanen77346a62011-11-30 16:26:35 +02004805 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004806}
4807
4808static void
4809bind_screensaver(struct wl_client *client,
4810 void *data, uint32_t version, uint32_t id)
4811{
Tiago Vignattibe143262012-04-16 17:31:41 +03004812 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004813 struct wl_resource *resource;
4814
Jason Ekstranda85118c2013-06-27 20:17:02 -05004815 resource = wl_resource_create(client, &screensaver_interface, 1, id);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004816
Pekka Paalanen77346a62011-11-30 16:26:35 +02004817 if (shell->screensaver.binding == NULL) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05004818 wl_resource_set_implementation(resource,
4819 &screensaver_implementation,
4820 shell, unbind_screensaver);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004821 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004822 return;
4823 }
4824
4825 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4826 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04004827 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004828}
4829
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004830static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004831input_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 -04004832{
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004833 struct input_panel_surface *ip_surface = surface->configure_private;
4834 struct desktop_shell *shell = ip_surface->shell;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004835 float x, y;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004836 uint32_t show_surface = 0;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004837
Giulio Camuffo184df502013-02-21 11:29:21 +01004838 if (width == 0)
4839 return;
4840
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004841 if (!weston_surface_is_mapped(surface)) {
4842 if (!shell->showing_input_panels)
4843 return;
4844
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004845 show_surface = 1;
4846 }
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004847
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004848 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004849
4850 if (ip_surface->panel) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004851 x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2;
4852 y = get_default_view(shell->text_input.surface)->geometry.y + shell->text_input.cursor_rectangle.y2;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004853 } else {
Rob Bradfordbdeb5d22013-07-11 13:20:53 +01004854 x = ip_surface->output->x + (ip_surface->output->width - width) / 2;
4855 y = ip_surface->output->y + ip_surface->output->height - height;
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004856 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004857
Jason Ekstranda7af7042013-10-12 22:38:11 -05004858 weston_view_configure(ip_surface->view, x, y, width, height);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004859
4860 if (show_surface) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004861 wl_list_insert(&shell->input_panel_layer.view_list,
4862 &ip_surface->view->layer_link);
4863 weston_view_update_transform(ip_surface->view);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004864 weston_surface_damage(surface);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004865 weston_slide_run(ip_surface->view, ip_surface->view->geometry.height, 0, NULL, NULL);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004866 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004867}
4868
4869static void
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004870destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004871{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004872 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
4873
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004874 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004875 wl_list_remove(&input_panel_surface->link);
4876
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004877 input_panel_surface->surface->configure = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004878 weston_view_destroy(input_panel_surface->view);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004879
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004880 free(input_panel_surface);
4881}
4882
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004883static struct input_panel_surface *
4884get_input_panel_surface(struct weston_surface *surface)
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004885{
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004886 if (surface->configure == input_panel_configure) {
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004887 return surface->configure_private;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004888 } else {
4889 return NULL;
4890 }
4891}
4892
4893static void
4894input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
4895{
4896 struct input_panel_surface *ipsurface = container_of(listener,
4897 struct input_panel_surface,
4898 surface_destroy_listener);
4899
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004900 if (ipsurface->resource) {
4901 wl_resource_destroy(ipsurface->resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004902 } else {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004903 destroy_input_panel_surface(ipsurface);
4904 }
4905}
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004906
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004907static struct input_panel_surface *
4908create_input_panel_surface(struct desktop_shell *shell,
4909 struct weston_surface *surface)
4910{
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004911 struct input_panel_surface *input_panel_surface;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004912
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004913 input_panel_surface = calloc(1, sizeof *input_panel_surface);
4914 if (!input_panel_surface)
4915 return NULL;
4916
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004917 surface->configure = input_panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004918 surface->configure_private = input_panel_surface;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004919
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004920 input_panel_surface->shell = shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004921
4922 input_panel_surface->surface = surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004923 input_panel_surface->view = weston_view_create(surface);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004924
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004925 wl_signal_init(&input_panel_surface->destroy_signal);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004926 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05004927 wl_signal_add(&surface->destroy_signal,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004928 &input_panel_surface->surface_destroy_listener);
4929
4930 wl_list_init(&input_panel_surface->link);
4931
4932 return input_panel_surface;
4933}
4934
4935static void
4936input_panel_surface_set_toplevel(struct wl_client *client,
4937 struct wl_resource *resource,
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004938 struct wl_resource *output_resource,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004939 uint32_t position)
4940{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004941 struct input_panel_surface *input_panel_surface =
4942 wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004943 struct desktop_shell *shell = input_panel_surface->shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004944
4945 wl_list_insert(&shell->input_panel.surfaces,
4946 &input_panel_surface->link);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004947
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05004948 input_panel_surface->output = wl_resource_get_user_data(output_resource);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004949 input_panel_surface->panel = 0;
4950}
4951
4952static void
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02004953input_panel_surface_set_overlay_panel(struct wl_client *client,
4954 struct wl_resource *resource)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004955{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004956 struct input_panel_surface *input_panel_surface =
4957 wl_resource_get_user_data(resource);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004958 struct desktop_shell *shell = input_panel_surface->shell;
4959
4960 wl_list_insert(&shell->input_panel.surfaces,
4961 &input_panel_surface->link);
4962
4963 input_panel_surface->panel = 1;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004964}
4965
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02004966static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004967 input_panel_surface_set_toplevel,
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02004968 input_panel_surface_set_overlay_panel
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004969};
4970
4971static void
4972destroy_input_panel_surface_resource(struct wl_resource *resource)
4973{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004974 struct input_panel_surface *ipsurf =
4975 wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004976
4977 destroy_input_panel_surface(ipsurf);
4978}
4979
4980static void
4981input_panel_get_input_panel_surface(struct wl_client *client,
4982 struct wl_resource *resource,
4983 uint32_t id,
4984 struct wl_resource *surface_resource)
4985{
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05004986 struct weston_surface *surface =
4987 wl_resource_get_user_data(surface_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004988 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004989 struct input_panel_surface *ipsurf;
4990
4991 if (get_input_panel_surface(surface)) {
4992 wl_resource_post_error(surface_resource,
4993 WL_DISPLAY_ERROR_INVALID_OBJECT,
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02004994 "wl_input_panel::get_input_panel_surface already requested");
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004995 return;
4996 }
4997
4998 ipsurf = create_input_panel_surface(shell, surface);
4999 if (!ipsurf) {
5000 wl_resource_post_error(surface_resource,
5001 WL_DISPLAY_ERROR_INVALID_OBJECT,
5002 "surface->configure already set");
5003 return;
5004 }
5005
Jason Ekstranda85118c2013-06-27 20:17:02 -05005006 ipsurf->resource =
5007 wl_resource_create(client,
5008 &wl_input_panel_surface_interface, 1, id);
5009 wl_resource_set_implementation(ipsurf->resource,
5010 &input_panel_surface_implementation,
5011 ipsurf,
5012 destroy_input_panel_surface_resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01005013}
5014
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02005015static const struct wl_input_panel_interface input_panel_implementation = {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01005016 input_panel_get_input_panel_surface
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005017};
5018
5019static void
5020unbind_input_panel(struct wl_resource *resource)
5021{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05005022 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005023
5024 shell->input_panel.binding = NULL;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005025}
5026
5027static void
5028bind_input_panel(struct wl_client *client,
5029 void *data, uint32_t version, uint32_t id)
5030{
5031 struct desktop_shell *shell = data;
5032 struct wl_resource *resource;
5033
Jason Ekstranda85118c2013-06-27 20:17:02 -05005034 resource = wl_resource_create(client,
5035 &wl_input_panel_interface, 1, id);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005036
5037 if (shell->input_panel.binding == NULL) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05005038 wl_resource_set_implementation(resource,
5039 &input_panel_implementation,
5040 shell, unbind_input_panel);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005041 shell->input_panel.binding = resource;
5042 return;
5043 }
5044
5045 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
5046 "interface object already bound");
5047 wl_resource_destroy(resource);
5048}
5049
Kristian Høgsberg07045392012-02-19 18:52:44 -05005050struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03005051 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005052 struct weston_surface *current;
5053 struct wl_listener listener;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005054 struct weston_keyboard_grab grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005055};
5056
5057static void
5058switcher_next(struct switcher *switcher)
5059{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005060 struct weston_view *view;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005061 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005062 struct shell_surface *shsurf;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005063 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005064
Jason Ekstranda7af7042013-10-12 22:38:11 -05005065 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
5066 switch (get_shell_surface_type(view->surface)) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05005067 case SHELL_SURFACE_TOPLEVEL:
5068 case SHELL_SURFACE_FULLSCREEN:
5069 case SHELL_SURFACE_MAXIMIZED:
5070 if (first == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005071 first = view->surface;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005072 if (prev == switcher->current)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005073 next = view->surface;
5074 prev = view->surface;
5075 view->alpha = 0.25;
5076 weston_view_geometry_dirty(view);
5077 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005078 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00005079 case SHELL_SURFACE_TRANSIENT:
5080 case SHELL_SURFACE_POPUP:
5081 case SHELL_SURFACE_XWAYLAND:
5082 case SHELL_SURFACE_NONE:
Kristian Høgsberg07045392012-02-19 18:52:44 -05005083 default:
5084 break;
5085 }
Alex Wu1659daa2012-04-01 20:13:09 +08005086
Jason Ekstranda7af7042013-10-12 22:38:11 -05005087 if (is_black_surface(view->surface, NULL)) {
5088 view->alpha = 0.25;
5089 weston_view_geometry_dirty(view);
5090 weston_surface_damage(view->surface);
Alex Wu1659daa2012-04-01 20:13:09 +08005091 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05005092 }
5093
5094 if (next == NULL)
5095 next = first;
5096
Alex Wu07b26062012-03-12 16:06:01 +08005097 if (next == NULL)
5098 return;
5099
Kristian Høgsberg07045392012-02-19 18:52:44 -05005100 wl_list_remove(&switcher->listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005101 wl_signal_add(&next->destroy_signal, &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005102
5103 switcher->current = next;
Jason Ekstranda7af7042013-10-12 22:38:11 -05005104 wl_list_for_each(view, &next->views, surface_link)
5105 view->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08005106
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005107 shsurf = get_shell_surface(switcher->current);
5108 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005109 shsurf->fullscreen.black_view->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005110}
5111
5112static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005113switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005114{
5115 struct switcher *switcher =
5116 container_of(listener, struct switcher, listener);
5117
5118 switcher_next(switcher);
5119}
5120
5121static void
Daniel Stone351eb612012-05-31 15:27:47 -04005122switcher_destroy(struct switcher *switcher)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005123{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005124 struct weston_view *view;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005125 struct weston_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005126 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005127
Jason Ekstranda7af7042013-10-12 22:38:11 -05005128 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01005129 if (is_focus_view(view))
5130 continue;
5131
Jason Ekstranda7af7042013-10-12 22:38:11 -05005132 view->alpha = 1.0;
5133 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005134 }
5135
Alex Wu07b26062012-03-12 16:06:01 +08005136 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01005137 activate(switcher->shell, switcher->current,
5138 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005139 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005140 weston_keyboard_end_grab(keyboard);
5141 if (keyboard->input_method_resource)
5142 keyboard->grab = &keyboard->input_method_grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005143 free(switcher);
5144}
5145
5146static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005147switcher_key(struct weston_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +01005148 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005149{
5150 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stonec9785ea2012-05-30 16:31:52 +01005151 enum wl_keyboard_key_state state = state_w;
Daniel Stone351eb612012-05-31 15:27:47 -04005152
Daniel Stonec9785ea2012-05-30 16:31:52 +01005153 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
Daniel Stone351eb612012-05-31 15:27:47 -04005154 switcher_next(switcher);
5155}
5156
5157static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005158switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
Daniel Stone351eb612012-05-31 15:27:47 -04005159 uint32_t mods_depressed, uint32_t mods_latched,
5160 uint32_t mods_locked, uint32_t group)
5161{
5162 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01005163 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005164
Daniel Stone351eb612012-05-31 15:27:47 -04005165 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
5166 switcher_destroy(switcher);
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04005167}
Kristian Høgsberg07045392012-02-19 18:52:44 -05005168
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005169static void
5170switcher_cancel(struct weston_keyboard_grab *grab)
5171{
5172 struct switcher *switcher = container_of(grab, struct switcher, grab);
5173
5174 switcher_destroy(switcher);
5175}
5176
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005177static const struct weston_keyboard_grab_interface switcher_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -04005178 switcher_key,
5179 switcher_modifier,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005180 switcher_cancel,
Kristian Høgsberg07045392012-02-19 18:52:44 -05005181};
5182
5183static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005184switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005185 void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005186{
Tiago Vignattibe143262012-04-16 17:31:41 +03005187 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005188 struct switcher *switcher;
5189
5190 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04005191 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005192 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005193 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005194 wl_list_init(&switcher->listener.link);
5195
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02005196 restore_all_output_modes(shell->compositor);
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005197 lower_fullscreen_layer(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005198 switcher->grab.interface = &switcher_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005199 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
5200 weston_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005201 switcher_next(switcher);
5202}
5203
Daniel Stonedf8133b2013-11-19 11:37:14 +01005204struct exposay_surface {
5205 struct desktop_shell *shell;
5206 struct weston_surface *surface;
5207 struct weston_view *view;
5208 struct wl_list link;
5209
5210 int x;
5211 int y;
5212 int width;
5213 int height;
5214 double scale;
5215
5216 int row;
5217 int column;
5218
5219 /* The animations only apply a transformation for their own lifetime,
5220 * and don't have an option to indefinitely maintain the
5221 * transformation in a steady state - so, we apply our own once the
5222 * animation has finished. */
5223 struct weston_transform transform;
5224};
5225
5226static void exposay_set_state(struct desktop_shell *shell,
5227 enum exposay_target_state state,
5228 struct weston_seat *seat);
5229static void exposay_check_state(struct desktop_shell *shell);
5230
5231static void
5232exposay_in_flight_inc(struct desktop_shell *shell)
5233{
5234 shell->exposay.in_flight++;
5235}
5236
5237static void
5238exposay_in_flight_dec(struct desktop_shell *shell)
5239{
5240 if (--shell->exposay.in_flight > 0)
5241 return;
5242
5243 exposay_check_state(shell);
5244}
5245
5246static void
5247exposay_animate_in_done(struct weston_view_animation *animation, void *data)
5248{
5249 struct exposay_surface *esurface = data;
5250
5251 wl_list_insert(&esurface->view->geometry.transformation_list,
5252 &esurface->transform.link);
5253 weston_matrix_init(&esurface->transform.matrix);
5254 weston_matrix_scale(&esurface->transform.matrix,
5255 esurface->scale, esurface->scale, 1.0f);
5256 weston_matrix_translate(&esurface->transform.matrix,
5257 esurface->x - esurface->view->geometry.x,
5258 esurface->y - esurface->view->geometry.y,
5259 0);
5260
5261 weston_view_geometry_dirty(esurface->view);
5262 weston_compositor_schedule_repaint(esurface->view->surface->compositor);
5263
5264 exposay_in_flight_dec(esurface->shell);
5265}
5266
5267static void
5268exposay_animate_in(struct exposay_surface *esurface)
5269{
5270 exposay_in_flight_inc(esurface->shell);
5271
5272 weston_move_scale_run(esurface->view,
5273 esurface->x - esurface->view->geometry.x,
5274 esurface->y - esurface->view->geometry.y,
5275 1.0, esurface->scale, 0,
5276 exposay_animate_in_done, esurface);
5277}
5278
5279static void
5280exposay_animate_out_done(struct weston_view_animation *animation, void *data)
5281{
5282 struct exposay_surface *esurface = data;
5283 struct desktop_shell *shell = esurface->shell;
5284
5285 wl_list_remove(&esurface->link);
5286 free(esurface);
5287
5288 exposay_in_flight_dec(shell);
5289}
5290
5291static void
5292exposay_animate_out(struct exposay_surface *esurface)
5293{
5294 exposay_in_flight_inc(esurface->shell);
5295
5296 /* Remove the static transformation set up by
5297 * exposay_transform_in_done(). */
5298 wl_list_remove(&esurface->transform.link);
5299 weston_view_geometry_dirty(esurface->view);
5300
5301 weston_move_scale_run(esurface->view,
5302 esurface->x - esurface->view->geometry.x,
5303 esurface->y - esurface->view->geometry.y,
5304 1.0, esurface->scale, 1,
5305 exposay_animate_out_done, esurface);
5306}
5307
5308static void
5309exposay_highlight_surface(struct desktop_shell *shell,
5310 struct exposay_surface *esurface)
5311{
5312 struct weston_view *view = NULL;
5313
5314 if (esurface) {
5315 shell->exposay.row_current = esurface->row;
5316 shell->exposay.column_current = esurface->column;
5317 view = esurface->view;
5318 }
5319
Emilio Pozuelo Monfort5c22ce62013-11-19 11:37:18 +01005320 activate(shell, view->surface, shell->exposay.seat);
Daniel Stonedf8133b2013-11-19 11:37:14 +01005321 shell->exposay.focus_current = view;
5322}
5323
5324static int
5325exposay_is_animating(struct desktop_shell *shell)
5326{
5327 if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE ||
5328 shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW)
5329 return 0;
5330
5331 return (shell->exposay.in_flight > 0);
5332}
5333
5334static void
5335exposay_pick(struct desktop_shell *shell, int x, int y)
5336{
5337 struct exposay_surface *esurface;
5338
5339 if (exposay_is_animating(shell))
5340 return;
5341
5342 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5343 if (x < esurface->x || x > esurface->x + esurface->width)
5344 continue;
5345 if (y < esurface->y || y > esurface->y + esurface->height)
5346 continue;
5347
5348 exposay_highlight_surface(shell, esurface);
5349 return;
5350 }
5351}
5352
5353/* Pretty lame layout for now; just tries to make a square. Should take
5354 * aspect ratio into account really. Also needs to be notified of surface
5355 * addition and removal and adjust layout/animate accordingly. */
5356static enum exposay_layout_state
5357exposay_layout(struct desktop_shell *shell)
5358{
5359 struct workspace *workspace = shell->exposay.workspace;
5360 struct weston_compositor *compositor = shell->compositor;
5361 struct weston_output *output = get_default_output(compositor);
5362 struct weston_view *view;
5363 struct exposay_surface *esurface;
5364 int w, h;
5365 int i;
5366 int last_row_removed = 0;
5367
5368 wl_list_init(&shell->exposay.surface_list);
5369
5370 shell->exposay.num_surfaces = 0;
5371 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5372 if (!get_shell_surface(view->surface))
5373 continue;
5374 shell->exposay.num_surfaces++;
5375 }
5376
5377 if (shell->exposay.num_surfaces == 0) {
5378 shell->exposay.grid_size = 0;
5379 shell->exposay.hpadding_outer = 0;
5380 shell->exposay.vpadding_outer = 0;
5381 shell->exposay.padding_inner = 0;
5382 shell->exposay.surface_size = 0;
5383 return EXPOSAY_LAYOUT_OVERVIEW;
5384 }
5385
5386 /* Lay the grid out as square as possible, losing surfaces from the
5387 * bottom row if required. Start with fixed padding of a 10% margin
5388 * around the outside and 80px internal padding between surfaces, and
5389 * maximise the area made available to surfaces after this, but only
5390 * to a maximum of 1/3rd the total output size.
5391 *
5392 * If we can't make a square grid, add one extra row at the bottom
5393 * which will have a smaller number of columns.
5394 *
5395 * XXX: Surely there has to be a better way to express this maths,
5396 * right?!
5397 */
5398 shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces));
5399 if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces)
5400 shell->exposay.grid_size++;
5401 last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces;
5402
5403 shell->exposay.hpadding_outer = (output->width / 10);
5404 shell->exposay.vpadding_outer = (output->height / 10);
5405 shell->exposay.padding_inner = 80;
5406
5407 w = output->width - (shell->exposay.hpadding_outer * 2);
5408 w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5409 w /= shell->exposay.grid_size;
5410
5411 h = output->height - (shell->exposay.vpadding_outer * 2);
5412 h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5413 h /= shell->exposay.grid_size;
5414
5415 shell->exposay.surface_size = (w < h) ? w : h;
5416 if (shell->exposay.surface_size > (output->width / 2))
5417 shell->exposay.surface_size = output->width / 2;
5418 if (shell->exposay.surface_size > (output->height / 2))
5419 shell->exposay.surface_size = output->height / 2;
5420
5421 i = 0;
5422 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5423 int pad;
5424
5425 pad = shell->exposay.surface_size + shell->exposay.padding_inner;
5426
5427 if (!get_shell_surface(view->surface))
5428 continue;
5429
5430 esurface = malloc(sizeof(*esurface));
5431 if (!esurface) {
5432 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL,
5433 shell->exposay.seat);
5434 break;
5435 }
5436
5437 wl_list_insert(&shell->exposay.surface_list, &esurface->link);
5438 esurface->shell = shell;
5439 esurface->view = view;
5440
5441 esurface->row = i / shell->exposay.grid_size;
5442 esurface->column = i % shell->exposay.grid_size;
5443
5444 esurface->x = shell->exposay.hpadding_outer;
5445 esurface->x += pad * esurface->column;
5446 esurface->y = shell->exposay.vpadding_outer;
5447 esurface->y += pad * esurface->row;
5448
5449 if (esurface->row == shell->exposay.grid_size - 1)
5450 esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2;
5451
5452 if (view->geometry.width > view->geometry.height)
5453 esurface->scale = shell->exposay.surface_size / (float) view->geometry.width;
5454 else
5455 esurface->scale = shell->exposay.surface_size / (float) view->geometry.height;
5456 esurface->width = view->geometry.width * esurface->scale;
5457 esurface->height = view->geometry.height * esurface->scale;
5458
5459 if (shell->exposay.focus_current == esurface->view)
5460 exposay_highlight_surface(shell, esurface);
5461
5462 exposay_animate_in(esurface);
5463
5464 i++;
5465 }
5466
5467 weston_compositor_schedule_repaint(shell->compositor);
5468
5469 return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW;
5470}
5471
5472static void
Emilio Pozuelo Monfort17467d62013-11-19 12:14:53 +01005473exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
5474 wl_fixed_t x, wl_fixed_t y)
Daniel Stonedf8133b2013-11-19 11:37:14 +01005475{
5476 struct desktop_shell *shell =
5477 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5478
Emilio Pozuelo Monfort17467d62013-11-19 12:14:53 +01005479 weston_pointer_move(grab->pointer, x, y);
5480
Daniel Stonedf8133b2013-11-19 11:37:14 +01005481 exposay_pick(shell,
5482 wl_fixed_to_int(grab->pointer->x),
5483 wl_fixed_to_int(grab->pointer->y));
5484}
5485
5486static void
5487exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button,
5488 uint32_t state_w)
5489{
5490 struct desktop_shell *shell =
5491 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5492 struct weston_seat *seat = grab->pointer->seat;
5493 enum wl_pointer_button_state state = state_w;
5494
5495 if (button != BTN_LEFT)
5496 return;
5497
5498 /* Store the surface we clicked on, and don't do anything if we end up
5499 * releasing on a different surface. */
5500 if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
5501 shell->exposay.clicked = shell->exposay.focus_current;
5502 return;
5503 }
5504
5505 if (shell->exposay.focus_current == shell->exposay.clicked)
5506 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5507 else
5508 shell->exposay.clicked = NULL;
5509}
5510
Emilio Pozuelo Monfort234c5242013-11-26 13:32:08 +01005511static void
5512exposay_pointer_grab_cancel(struct weston_pointer_grab *grab)
5513{
5514 struct desktop_shell *shell =
5515 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5516
5517 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5518}
5519
Daniel Stonedf8133b2013-11-19 11:37:14 +01005520static const struct weston_pointer_grab_interface exposay_ptr_grab = {
5521 noop_grab_focus,
5522 exposay_motion,
5523 exposay_button,
Emilio Pozuelo Monfort234c5242013-11-26 13:32:08 +01005524 exposay_pointer_grab_cancel,
Daniel Stonedf8133b2013-11-19 11:37:14 +01005525};
5526
5527static int
5528exposay_maybe_move(struct desktop_shell *shell, int row, int column)
5529{
5530 struct exposay_surface *esurface;
5531
5532 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5533 if (esurface->row != row || esurface->column != column)
5534 continue;
5535
5536 exposay_highlight_surface(shell, esurface);
5537 return 1;
5538 }
5539
5540 return 0;
5541}
5542
5543static void
5544exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key,
5545 uint32_t state_w)
5546{
5547 struct weston_seat *seat = grab->keyboard->seat;
5548 struct desktop_shell *shell =
5549 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5550 enum wl_keyboard_key_state state = state_w;
5551
5552 if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
5553 return;
5554
5555 switch (key) {
5556 case KEY_ESC:
5557 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5558 break;
5559 case KEY_ENTER:
5560 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5561 break;
5562 case KEY_UP:
5563 exposay_maybe_move(shell, shell->exposay.row_current - 1,
5564 shell->exposay.column_current);
5565 break;
5566 case KEY_DOWN:
5567 /* Special case for trying to move to the bottom row when it
5568 * has fewer items than all the others. */
5569 if (!exposay_maybe_move(shell, shell->exposay.row_current + 1,
5570 shell->exposay.column_current) &&
5571 shell->exposay.row_current < (shell->exposay.grid_size - 1)) {
5572 exposay_maybe_move(shell, shell->exposay.row_current + 1,
5573 (shell->exposay.num_surfaces %
5574 shell->exposay.grid_size) - 1);
5575 }
5576 break;
5577 case KEY_LEFT:
5578 exposay_maybe_move(shell, shell->exposay.row_current,
5579 shell->exposay.column_current - 1);
5580 break;
5581 case KEY_RIGHT:
5582 exposay_maybe_move(shell, shell->exposay.row_current,
5583 shell->exposay.column_current + 1);
5584 break;
5585 case KEY_TAB:
5586 /* Try to move right, then down (and to the leftmost column),
5587 * then if all else fails, to the top left. */
5588 if (!exposay_maybe_move(shell, shell->exposay.row_current,
5589 shell->exposay.column_current + 1) &&
5590 !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0))
5591 exposay_maybe_move(shell, 0, 0);
5592 break;
5593 default:
5594 break;
5595 }
5596}
5597
5598static void
5599exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
5600 uint32_t mods_depressed, uint32_t mods_latched,
5601 uint32_t mods_locked, uint32_t group)
5602{
Emilio Pozuelo Monforteed93442013-11-27 10:49:08 +01005603 struct desktop_shell *shell =
5604 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5605 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
5606
5607 /* We want to know when mod has been pressed and released.
5608 * FIXME: There is a problem here: if mod is pressed, then a key
5609 * is pressed and released, then mod is released, we will treat that
5610 * as if only mod had been pressed and released. */
5611 if (seat->modifier_state) {
5612 if (seat->modifier_state == shell->binding_modifier) {
5613 shell->exposay.mod_pressed = true;
5614 } else {
5615 shell->exposay.mod_invalid = true;
5616 }
5617 } else {
5618 if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid)
5619 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5620
5621 shell->exposay.mod_invalid = false;
5622 shell->exposay.mod_pressed = false;
5623 }
5624
5625 return;
Daniel Stonedf8133b2013-11-19 11:37:14 +01005626}
5627
Emilio Pozuelo Monfort82243092013-11-19 11:37:17 +01005628static void
5629exposay_cancel(struct weston_keyboard_grab *grab)
5630{
5631 struct desktop_shell *shell =
5632 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5633
5634 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5635}
5636
Daniel Stonedf8133b2013-11-19 11:37:14 +01005637static const struct weston_keyboard_grab_interface exposay_kbd_grab = {
5638 exposay_key,
5639 exposay_modifier,
Emilio Pozuelo Monfort82243092013-11-19 11:37:17 +01005640 exposay_cancel,
Daniel Stonedf8133b2013-11-19 11:37:14 +01005641};
5642
5643/**
5644 * Called when the transition from overview -> inactive has completed.
5645 */
5646static enum exposay_layout_state
5647exposay_set_inactive(struct desktop_shell *shell)
5648{
5649 struct weston_seat *seat = shell->exposay.seat;
5650
5651 weston_keyboard_end_grab(seat->keyboard);
5652 weston_pointer_end_grab(seat->pointer);
5653 if (seat->keyboard->input_method_resource)
5654 seat->keyboard->grab = &seat->keyboard->input_method_grab;
5655
5656 return EXPOSAY_LAYOUT_INACTIVE;
5657}
5658
5659/**
5660 * Begins the transition from overview to inactive. */
5661static enum exposay_layout_state
5662exposay_transition_inactive(struct desktop_shell *shell, int switch_focus)
5663{
5664 struct exposay_surface *esurface;
5665
5666 /* Call activate() before we start the animations to avoid
5667 * animating back the old state and then immediately transitioning
5668 * to the new. */
5669 if (switch_focus && shell->exposay.focus_current)
5670 activate(shell, shell->exposay.focus_current->surface,
5671 shell->exposay.seat);
5672 else if (shell->exposay.focus_prev)
5673 activate(shell, shell->exposay.focus_prev->surface,
5674 shell->exposay.seat);
5675
5676 wl_list_for_each(esurface, &shell->exposay.surface_list, link)
5677 exposay_animate_out(esurface);
5678 weston_compositor_schedule_repaint(shell->compositor);
5679
5680 return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE;
5681}
5682
5683static enum exposay_layout_state
5684exposay_transition_active(struct desktop_shell *shell)
5685{
5686 struct weston_seat *seat = shell->exposay.seat;
5687
5688 shell->exposay.workspace = get_current_workspace(shell);
5689 shell->exposay.focus_prev = get_default_view (seat->keyboard->focus);
5690 shell->exposay.focus_current = get_default_view (seat->keyboard->focus);
5691 shell->exposay.clicked = NULL;
5692 wl_list_init(&shell->exposay.surface_list);
5693
5694 lower_fullscreen_layer(shell);
5695 shell->exposay.grab_kbd.interface = &exposay_kbd_grab;
5696 weston_keyboard_start_grab(seat->keyboard,
5697 &shell->exposay.grab_kbd);
5698 weston_keyboard_set_focus(seat->keyboard, NULL);
5699
5700 shell->exposay.grab_ptr.interface = &exposay_ptr_grab;
5701 weston_pointer_start_grab(seat->pointer,
5702 &shell->exposay.grab_ptr);
5703 weston_pointer_set_focus(seat->pointer, NULL,
5704 seat->pointer->x, seat->pointer->y);
5705
5706 return exposay_layout(shell);
5707}
5708
5709static void
5710exposay_check_state(struct desktop_shell *shell)
5711{
5712 enum exposay_layout_state state_new = shell->exposay.state_cur;
5713 int do_switch = 0;
5714
5715 /* Don't do anything whilst animations are running, just store up
5716 * target state changes and only act on them when the animations have
5717 * completed. */
5718 if (exposay_is_animating(shell))
5719 return;
5720
5721 switch (shell->exposay.state_target) {
5722 case EXPOSAY_TARGET_OVERVIEW:
5723 switch (shell->exposay.state_cur) {
5724 case EXPOSAY_LAYOUT_OVERVIEW:
5725 goto out;
5726 case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW:
5727 state_new = EXPOSAY_LAYOUT_OVERVIEW;
5728 break;
5729 default:
5730 state_new = exposay_transition_active(shell);
5731 break;
5732 }
5733 break;
5734
5735 case EXPOSAY_TARGET_SWITCH:
5736 do_switch = 1; /* fallthrough */
5737 case EXPOSAY_TARGET_CANCEL:
5738 switch (shell->exposay.state_cur) {
5739 case EXPOSAY_LAYOUT_INACTIVE:
5740 goto out;
5741 case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE:
5742 state_new = exposay_set_inactive(shell);
5743 break;
5744 default:
5745 state_new = exposay_transition_inactive(shell, do_switch);
5746 break;
5747 }
5748
5749 break;
5750 }
5751
5752out:
5753 shell->exposay.state_cur = state_new;
5754}
5755
5756static void
5757exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state,
5758 struct weston_seat *seat)
5759{
5760 shell->exposay.state_target = state;
5761 shell->exposay.seat = seat;
5762 exposay_check_state(shell);
5763}
5764
5765static void
5766exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier,
5767 void *data)
5768{
5769 struct desktop_shell *shell = data;
5770
Emilio Pozuelo Monforteed93442013-11-27 10:49:08 +01005771 exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat);
Daniel Stonedf8133b2013-11-19 11:37:14 +01005772}
5773
Pekka Paalanen3c647232011-12-22 13:43:43 +02005774static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005775backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005776 void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005777{
5778 struct weston_compositor *compositor = data;
5779 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005780 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005781
5782 /* TODO: we're limiting to simple use cases, where we assume just
5783 * control on the primary display. We'd have to extend later if we
5784 * ever get support for setting backlights on random desktop LCD
5785 * panels though */
5786 output = get_default_output(compositor);
5787 if (!output)
5788 return;
5789
5790 if (!output->set_backlight)
5791 return;
5792
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005793 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
5794 backlight_new = output->backlight_current - 25;
5795 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
5796 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005797
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005798 if (backlight_new < 5)
5799 backlight_new = 5;
5800 if (backlight_new > 255)
5801 backlight_new = 255;
5802
5803 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005804 output->set_backlight(output, output->backlight_current);
5805}
5806
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005807struct debug_binding_grab {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005808 struct weston_keyboard_grab grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005809 struct weston_seat *seat;
5810 uint32_t key[2];
5811 int key_released[2];
5812};
5813
5814static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005815debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005816 uint32_t key, uint32_t state)
5817{
5818 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
Rob Bradford880ebc72013-07-22 17:31:38 +01005819 struct weston_compositor *ec = db->seat->compositor;
5820 struct wl_display *display = ec->wl_display;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005821 struct wl_resource *resource;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005822 uint32_t serial;
5823 int send = 0, terminate = 0;
5824 int check_binding = 1;
5825 int i;
Neil Roberts96d790e2013-09-19 17:32:00 +01005826 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005827
5828 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
5829 /* Do not run bindings on key releases */
5830 check_binding = 0;
5831
5832 for (i = 0; i < 2; i++)
5833 if (key == db->key[i])
5834 db->key_released[i] = 1;
5835
5836 if (db->key_released[0] && db->key_released[1]) {
5837 /* All key releases been swalled so end the grab */
5838 terminate = 1;
5839 } else if (key != db->key[0] && key != db->key[1]) {
5840 /* Should not swallow release of other keys */
5841 send = 1;
5842 }
5843 } else if (key == db->key[0] && !db->key_released[0]) {
5844 /* Do not check bindings for the first press of the binding
5845 * key. This allows it to be used as a debug shortcut.
5846 * We still need to swallow this event. */
5847 check_binding = 0;
5848 } else if (db->key[1]) {
5849 /* If we already ran a binding don't process another one since
5850 * we can't keep track of all the binding keys that were
5851 * pressed in order to swallow the release events. */
5852 send = 1;
5853 check_binding = 0;
5854 }
5855
5856 if (check_binding) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005857 if (weston_compositor_run_debug_binding(ec, db->seat, time,
5858 key, state)) {
5859 /* We ran a binding so swallow the press and keep the
5860 * grab to swallow the released too. */
5861 send = 0;
5862 terminate = 0;
5863 db->key[1] = key;
5864 } else {
5865 /* Terminate the grab since the key pressed is not a
5866 * debug binding key. */
5867 send = 1;
5868 terminate = 1;
5869 }
5870 }
5871
5872 if (send) {
Neil Roberts96d790e2013-09-19 17:32:00 +01005873 serial = wl_display_next_serial(display);
5874 resource_list = &grab->keyboard->focus_resource_list;
5875 wl_resource_for_each(resource, resource_list) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005876 wl_keyboard_send_key(resource, serial, time, key, state);
5877 }
5878 }
5879
5880 if (terminate) {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005881 weston_keyboard_end_grab(grab->keyboard);
5882 if (grab->keyboard->input_method_resource)
5883 grab->keyboard->grab = &grab->keyboard->input_method_grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005884 free(db);
5885 }
5886}
5887
5888static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005889debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005890 uint32_t mods_depressed, uint32_t mods_latched,
5891 uint32_t mods_locked, uint32_t group)
5892{
5893 struct wl_resource *resource;
Neil Roberts96d790e2013-09-19 17:32:00 +01005894 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005895
Neil Roberts96d790e2013-09-19 17:32:00 +01005896 resource_list = &grab->keyboard->focus_resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005897
Neil Roberts96d790e2013-09-19 17:32:00 +01005898 wl_resource_for_each(resource, resource_list) {
5899 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
5900 mods_latched, mods_locked, group);
5901 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005902}
5903
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005904static void
5905debug_binding_cancel(struct weston_keyboard_grab *grab)
5906{
5907 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
5908
5909 weston_keyboard_end_grab(grab->keyboard);
5910 free(db);
5911}
5912
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005913struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005914 debug_binding_key,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005915 debug_binding_modifiers,
5916 debug_binding_cancel,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005917};
5918
5919static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005920debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005921{
5922 struct debug_binding_grab *grab;
5923
5924 grab = calloc(1, sizeof *grab);
5925 if (!grab)
5926 return;
5927
5928 grab->seat = (struct weston_seat *) seat;
5929 grab->key[0] = key;
5930 grab->grab.interface = &debug_binding_keyboard_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005931 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005932}
5933
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05005934static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005935force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005936 void *data)
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005937{
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04005938 struct weston_surface *focus_surface;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005939 struct wl_client *client;
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005940 struct desktop_shell *shell = data;
5941 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005942 pid_t pid;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005943
Philipp Brüschweiler6cef0092012-08-13 21:27:27 +02005944 focus_surface = seat->keyboard->focus;
5945 if (!focus_surface)
5946 return;
5947
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005948 wl_signal_emit(&compositor->kill_signal, focus_surface);
5949
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005950 client = wl_resource_get_client(focus_surface->resource);
Tiago Vignatti920f1972012-09-27 17:48:35 +03005951 wl_client_get_credentials(client, &pid, NULL, NULL);
5952
5953 /* Skip clients that we launched ourselves (the credentials of
5954 * the socketpair is ours) */
5955 if (pid == getpid())
5956 return;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005957
Daniel Stone325fc2d2012-05-30 16:31:58 +01005958 kill(pid, SIGKILL);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005959}
5960
5961static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005962workspace_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005963 uint32_t key, void *data)
5964{
5965 struct desktop_shell *shell = data;
5966 unsigned int new_index = shell->workspaces.current;
5967
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005968 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005969 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005970 if (new_index != 0)
5971 new_index--;
5972
5973 change_workspace(shell, new_index);
5974}
5975
5976static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005977workspace_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005978 uint32_t key, void *data)
5979{
5980 struct desktop_shell *shell = data;
5981 unsigned int new_index = shell->workspaces.current;
5982
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005983 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005984 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005985 if (new_index < shell->workspaces.num - 1)
5986 new_index++;
5987
5988 change_workspace(shell, new_index);
5989}
5990
5991static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005992workspace_f_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005993 uint32_t key, void *data)
5994{
5995 struct desktop_shell *shell = data;
5996 unsigned int new_index;
5997
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005998 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005999 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006000 new_index = key - KEY_F1;
6001 if (new_index >= shell->workspaces.num)
6002 new_index = shell->workspaces.num - 1;
6003
6004 change_workspace(shell, new_index);
6005}
6006
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006007static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04006008workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006009 uint32_t key, void *data)
6010{
6011 struct desktop_shell *shell = data;
6012 unsigned int new_index = shell->workspaces.current;
6013
6014 if (shell->locked)
6015 return;
6016
6017 if (new_index != 0)
6018 new_index--;
6019
6020 take_surface_to_workspace_by_seat(shell, seat, new_index);
6021}
6022
6023static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04006024workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006025 uint32_t key, void *data)
6026{
6027 struct desktop_shell *shell = data;
6028 unsigned int new_index = shell->workspaces.current;
6029
6030 if (shell->locked)
6031 return;
6032
6033 if (new_index < shell->workspaces.num - 1)
6034 new_index++;
6035
6036 take_surface_to_workspace_by_seat(shell, seat, new_index);
6037}
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006038
6039static void
Xiong Zhang6b481422013-10-23 13:58:32 +08006040handle_output_destroy(struct wl_listener *listener, void *data)
6041{
6042 struct shell_output *output_listener =
6043 container_of(listener, struct shell_output, destroy_listener);
6044
6045 wl_list_remove(&output_listener->destroy_listener.link);
6046 wl_list_remove(&output_listener->link);
6047 free(output_listener);
6048}
6049
6050static void
6051create_shell_output(struct desktop_shell *shell,
6052 struct weston_output *output)
6053{
6054 struct shell_output *shell_output;
6055
6056 shell_output = zalloc(sizeof *shell_output);
6057 if (shell_output == NULL)
6058 return;
6059
6060 shell_output->output = output;
6061 shell_output->shell = shell;
6062 shell_output->destroy_listener.notify = handle_output_destroy;
6063 wl_signal_add(&output->destroy_signal,
6064 &shell_output->destroy_listener);
Kristian Høgsberga3a0e182013-10-23 23:36:04 -07006065 wl_list_insert(shell->output_list.prev, &shell_output->link);
Xiong Zhang6b481422013-10-23 13:58:32 +08006066}
6067
6068static void
6069handle_output_create(struct wl_listener *listener, void *data)
6070{
6071 struct desktop_shell *shell =
6072 container_of(listener, struct desktop_shell, output_create_listener);
6073 struct weston_output *output = (struct weston_output *)data;
6074
6075 create_shell_output(shell, output);
6076}
6077
6078static void
6079setup_output_destroy_handler(struct weston_compositor *ec,
6080 struct desktop_shell *shell)
6081{
6082 struct weston_output *output;
6083
6084 wl_list_init(&shell->output_list);
6085 wl_list_for_each(output, &ec->output_list, link)
6086 create_shell_output(shell, output);
6087
6088 shell->output_create_listener.notify = handle_output_create;
6089 wl_signal_add(&ec->output_created_signal,
6090 &shell->output_create_listener);
6091}
6092
6093static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04006094shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02006095{
Tiago Vignattibe143262012-04-16 17:31:41 +03006096 struct desktop_shell *shell =
6097 container_of(listener, struct desktop_shell, destroy_listener);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006098 struct workspace **ws;
Xiong Zhang6b481422013-10-23 13:58:32 +08006099 struct shell_output *shell_output, *tmp;
Pekka Paalanen3c647232011-12-22 13:43:43 +02006100
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02006101 if (shell->child.client)
6102 wl_client_destroy(shell->child.client);
6103
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02006104 wl_list_remove(&shell->idle_listener.link);
6105 wl_list_remove(&shell->wake_listener.link);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006106 wl_list_remove(&shell->show_input_panel_listener.link);
6107 wl_list_remove(&shell->hide_input_panel_listener.link);
Kristian Høgsberg88c16072012-05-16 08:04:19 -04006108
Xiong Zhang6b481422013-10-23 13:58:32 +08006109 wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) {
6110 wl_list_remove(&shell_output->destroy_listener.link);
6111 wl_list_remove(&shell_output->link);
6112 free(shell_output);
6113 }
6114
6115 wl_list_remove(&shell->output_create_listener.link);
6116
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006117 wl_array_for_each(ws, &shell->workspaces.array)
6118 workspace_destroy(*ws);
6119 wl_array_release(&shell->workspaces.array);
6120
Pekka Paalanen3c647232011-12-22 13:43:43 +02006121 free(shell->screensaver.path);
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01006122 free(shell->client);
Pekka Paalanen3c647232011-12-22 13:43:43 +02006123 free(shell);
6124}
6125
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006126static void
6127shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
6128{
6129 uint32_t mod;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006130 int i, num_workspace_bindings;
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006131
6132 /* fixed bindings */
Daniel Stone325fc2d2012-05-30 16:31:58 +01006133 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
6134 MODIFIER_CTRL | MODIFIER_ALT,
6135 terminate_binding, ec);
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01006136 weston_compositor_add_key_binding(ec, KEY_TAB,
6137 MODIFIER_ALT,
6138 alt_tab_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006139 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
6140 click_to_activate_binding,
6141 shell);
Neil Robertsa28c6932013-10-03 16:43:04 +01006142 weston_compositor_add_touch_binding(ec, 0,
6143 touch_to_activate_binding,
6144 shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006145 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6146 MODIFIER_SUPER | MODIFIER_ALT,
6147 surface_opacity_binding, NULL);
6148 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6149 MODIFIER_SUPER, zoom_axis_binding,
6150 NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006151
6152 /* configurable bindings */
6153 mod = shell->binding_modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +01006154 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
6155 zoom_key_binding, NULL);
6156 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
6157 zoom_key_binding, NULL);
6158 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
6159 shell);
Neil Robertsaba0f252013-10-03 16:43:05 +01006160 weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006161 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
6162 resize_binding, shell);
Pekka Paalanen7bb65102013-05-22 18:03:04 +03006163
6164 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
6165 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
6166 rotate_binding, NULL);
6167
Daniel Stone325fc2d2012-05-30 16:31:58 +01006168 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
6169 shell);
6170 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
6171 ec);
6172 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
6173 backlight_binding, ec);
6174 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
6175 ec);
6176 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
6177 backlight_binding, ec);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006178 weston_compositor_add_key_binding(ec, KEY_K, mod,
6179 force_kill_binding, shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006180 weston_compositor_add_key_binding(ec, KEY_UP, mod,
6181 workspace_up_binding, shell);
6182 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
6183 workspace_down_binding, shell);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006184 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
6185 workspace_move_surface_up_binding,
6186 shell);
6187 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
6188 workspace_move_surface_down_binding,
6189 shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006190
Daniel Stonedf8133b2013-11-19 11:37:14 +01006191 weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell);
6192
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006193 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
6194 if (shell->workspaces.num > 1) {
6195 num_workspace_bindings = shell->workspaces.num;
6196 if (num_workspace_bindings > 6)
6197 num_workspace_bindings = 6;
6198 for (i = 0; i < num_workspace_bindings; i++)
6199 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
6200 workspace_f_binding,
6201 shell);
6202 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02006203
6204 /* Debug bindings */
6205 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
6206 debug_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006207}
6208
Kristian Høgsberg1c562182011-05-02 22:09:20 -04006209WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -05006210module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -07006211 int *argc, char *argv[])
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006212{
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04006213 struct weston_seat *seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03006214 struct desktop_shell *shell;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006215 struct workspace **pws;
6216 unsigned int i;
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006217 struct wl_event_loop *loop;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04006218
Peter Huttererf3d62272013-08-08 11:57:05 +10006219 shell = zalloc(sizeof *shell);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04006220 if (shell == NULL)
6221 return -1;
6222
Kristian Høgsberg75840622011-09-06 13:48:16 -04006223 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04006224
6225 shell->destroy_listener.notify = shell_destroy;
6226 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02006227 shell->idle_listener.notify = idle_handler;
6228 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
6229 shell->wake_listener.notify = wake_handler;
6230 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006231 shell->show_input_panel_listener.notify = show_input_panels;
6232 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
6233 shell->hide_input_panel_listener.notify = hide_input_panels;
6234 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02006235 shell->update_input_panel_listener.notify = update_input_panels;
6236 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06006237 ec->ping_handler = ping_handler;
Kristian Høgsberg82a1d112012-07-19 14:02:00 -04006238 ec->shell_interface.shell = shell;
Tiago Vignattibc052c92012-04-19 16:18:18 +03006239 ec->shell_interface.create_shell_surface = create_shell_surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05006240 ec->shell_interface.get_primary_view = get_primary_view;
Tiago Vignattibc052c92012-04-19 16:18:18 +03006241 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04006242 ec->shell_interface.set_transient = set_transient;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05006243 ec->shell_interface.set_fullscreen = set_fullscreen;
Tiago Vignattifb2adba2013-06-12 15:43:21 -03006244 ec->shell_interface.set_xwayland = set_xwayland;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04006245 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04006246 ec->shell_interface.resize = surface_resize;
Giulio Camuffo62942ad2013-09-11 18:20:47 +02006247 ec->shell_interface.set_title = set_title;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006248
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006249 wl_list_init(&shell->input_panel.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02006250
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05006251 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
6252 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006253 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
6254 weston_layer_init(&shell->lock_layer, NULL);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02006255 weston_layer_init(&shell->input_panel_layer, NULL);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006256
6257 wl_array_init(&shell->workspaces.array);
Jonas Ådahle9d22502012-08-29 22:13:01 +02006258 wl_list_init(&shell->workspaces.client_list);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05006259
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04006260 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02006261
Daniel Stonedf8133b2013-11-19 11:37:14 +01006262 shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE;
6263 shell->exposay.state_target = EXPOSAY_TARGET_CANCEL;
6264
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006265 for (i = 0; i < shell->workspaces.num; i++) {
6266 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
6267 if (pws == NULL)
6268 return -1;
6269
6270 *pws = workspace_create();
6271 if (*pws == NULL)
6272 return -1;
6273 }
6274 activate_workspace(shell, 0);
6275
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006276 wl_list_init(&shell->workspaces.anim_sticky_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02006277 wl_list_init(&shell->workspaces.animation.link);
6278 shell->workspaces.animation.frame = animate_workspace_change_frame;
6279
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006280 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04006281 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006282 return -1;
6283
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006284 if (wl_global_create(ec->wl_display,
6285 &desktop_shell_interface, 2,
6286 shell, bind_desktop_shell) == NULL)
Kristian Høgsberg75840622011-09-06 13:48:16 -04006287 return -1;
6288
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006289 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
6290 shell, bind_screensaver) == NULL)
Pekka Paalanen6e168112011-11-24 11:34:05 +02006291 return -1;
6292
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006293 if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1,
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006294 shell, bind_input_panel) == NULL)
6295 return -1;
6296
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006297 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
6298 shell, bind_workspace_manager) == NULL)
Jonas Ådahle9d22502012-08-29 22:13:01 +02006299 return -1;
6300
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05006301 shell->child.deathstamp = weston_compositor_get_time();
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006302
Xiong Zhang6b481422013-10-23 13:58:32 +08006303 setup_output_destroy_handler(ec, shell);
6304
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006305 loop = wl_display_get_event_loop(ec->wl_display);
6306 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02006307
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02006308 shell->screensaver.timer =
6309 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
6310
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04006311 wl_list_for_each(seat, &ec->seat_list, link)
6312 create_pointer_focus_listener(seat);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04006313
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006314 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04006315
Pekka Paalanen79346ab2013-05-22 18:03:09 +03006316 shell_fade_init(shell);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02006317
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006318 return 0;
6319}