blob: abed1c7e3ae003dc65fa7460ff0d37a0401014df [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 {
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001376 if (wl_list_empty(&shsurf->workspace_transform.link))
1377 wl_list_insert(&shell->workspaces.anim_sticky_list,
1378 &shsurf->workspace_transform.link);
1379
1380 animate_workspace_change(shell, index, from, to);
1381 }
Jonas Ådahle9d22502012-08-29 22:13:01 +02001382
1383 broadcast_current_workspace_state(shell);
Jonas Ådahl8538b222012-08-29 22:13:03 +02001384
1385 state = ensure_focus_state(shell, seat);
1386 if (state != NULL)
1387 state->keyboard_focus = surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001388}
1389
1390static void
1391workspace_manager_move_surface(struct wl_client *client,
1392 struct wl_resource *resource,
1393 struct wl_resource *surface_resource,
1394 uint32_t workspace)
1395{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001396 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001397 struct weston_surface *surface =
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05001398 wl_resource_get_user_data(surface_resource);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001399 struct weston_surface *main_surface;
Philip Withnall659163d2013-11-25 18:01:36 +00001400 struct shell_surface *shell_surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001401
Pekka Paalanen01388e22013-04-25 13:57:44 +03001402 main_surface = weston_surface_get_main_surface(surface);
Philip Withnall659163d2013-11-25 18:01:36 +00001403 shell_surface = get_shell_surface(main_surface);
1404 if (shell_surface == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05001405 return;
Philip Withnall659163d2013-11-25 18:01:36 +00001406
1407 move_surface_to_workspace(shell, shell_surface, workspace);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001408}
1409
1410static const struct workspace_manager_interface workspace_manager_implementation = {
1411 workspace_manager_move_surface,
1412};
1413
1414static void
1415unbind_resource(struct wl_resource *resource)
1416{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001417 wl_list_remove(wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001418}
1419
1420static void
1421bind_workspace_manager(struct wl_client *client,
1422 void *data, uint32_t version, uint32_t id)
1423{
1424 struct desktop_shell *shell = data;
1425 struct wl_resource *resource;
1426
Jason Ekstranda85118c2013-06-27 20:17:02 -05001427 resource = wl_resource_create(client,
1428 &workspace_manager_interface, 1, id);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001429
1430 if (resource == NULL) {
1431 weston_log("couldn't add workspace manager object");
1432 return;
1433 }
1434
Jason Ekstranda85118c2013-06-27 20:17:02 -05001435 wl_resource_set_implementation(resource,
1436 &workspace_manager_implementation,
1437 shell, unbind_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001438 wl_list_insert(&shell->workspaces.client_list,
1439 wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001440
1441 workspace_manager_send_state(resource,
1442 shell->workspaces.current,
1443 shell->workspaces.num);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001444}
1445
Pekka Paalanen56cdea92011-11-23 16:14:12 +02001446static void
Rusty Lynch1084da52013-08-15 09:10:08 -07001447touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1448 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1449{
1450}
1451
1452static void
1453touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1454{
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001455 struct weston_touch_move_grab *move =
1456 (struct weston_touch_move_grab *) container_of(
1457 grab, struct shell_touch_grab, grab);
Neil Robertse14aa4f2013-10-03 16:43:07 +01001458
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001459 if (grab->touch->seat->num_tp == 0) {
1460 shell_touch_grab_end(&move->base);
1461 free(move);
1462 }
Rusty Lynch1084da52013-08-15 09:10:08 -07001463}
1464
1465static void
1466touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1467 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1468{
1469 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1470 struct shell_surface *shsurf = move->base.shsurf;
1471 struct weston_surface *es;
1472 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1473 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1474
1475 if (!shsurf)
1476 return;
1477
1478 es = shsurf->surface;
1479
Jason Ekstranda7af7042013-10-12 22:38:11 -05001480 weston_view_configure(shsurf->view, dx, dy,
1481 shsurf->view->geometry.width,
1482 shsurf->view->geometry.height);
Rusty Lynch1084da52013-08-15 09:10:08 -07001483
1484 weston_compositor_schedule_repaint(es->compositor);
1485}
1486
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001487static void
1488touch_move_grab_cancel(struct weston_touch_grab *grab)
1489{
1490 struct weston_touch_move_grab *move =
1491 (struct weston_touch_move_grab *) container_of(
1492 grab, struct shell_touch_grab, grab);
1493
1494 shell_touch_grab_end(&move->base);
1495 free(move);
1496}
1497
Rusty Lynch1084da52013-08-15 09:10:08 -07001498static const struct weston_touch_grab_interface touch_move_grab_interface = {
1499 touch_move_grab_down,
1500 touch_move_grab_up,
1501 touch_move_grab_motion,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001502 touch_move_grab_cancel,
Rusty Lynch1084da52013-08-15 09:10:08 -07001503};
1504
1505static int
1506surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1507{
1508 struct weston_touch_move_grab *move;
1509
1510 if (!shsurf)
1511 return -1;
1512
1513 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1514 return 0;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001515 if (shsurf->grabbed)
1516 return 0;
Rusty Lynch1084da52013-08-15 09:10:08 -07001517
1518 move = malloc(sizeof *move);
1519 if (!move)
1520 return -1;
1521
Jason Ekstranda7af7042013-10-12 22:38:11 -05001522 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001523 seat->touch->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001524 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001525 seat->touch->grab_y;
1526
1527 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1528 seat->touch);
1529
1530 return 0;
1531}
1532
1533static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001534noop_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001535{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001536}
1537
1538static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001539move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1540 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001541{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001542 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001543 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001544 struct shell_surface *shsurf = move->base.shsurf;
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001545 int dx, dy;
1546
1547 weston_pointer_move(pointer, x, y);
1548 dx = wl_fixed_to_int(pointer->x + move->dx);
1549 dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001550
1551 if (!shsurf)
1552 return;
1553
Jason Ekstranda7af7042013-10-12 22:38:11 -05001554 weston_view_configure(shsurf->view, dx, dy,
1555 shsurf->view->geometry.width,
1556 shsurf->view->geometry.height);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001557
Jason Ekstranda7af7042013-10-12 22:38:11 -05001558 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001559}
1560
1561static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001562move_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001563 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001564{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001565 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1566 grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001567 struct weston_pointer *pointer = grab->pointer;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001568 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001569
Daniel Stone4dbadb12012-05-30 16:31:51 +01001570 if (pointer->button_count == 0 &&
1571 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001572 shell_grab_end(shell_grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001573 free(grab);
1574 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001575}
1576
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001577static void
1578move_grab_cancel(struct weston_pointer_grab *grab)
1579{
1580 struct shell_grab *shell_grab =
1581 container_of(grab, struct shell_grab, grab);
1582
1583 shell_grab_end(shell_grab);
1584 free(grab);
1585}
1586
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001587static const struct weston_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001588 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001589 move_grab_motion,
1590 move_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001591 move_grab_cancel,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001592};
1593
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001594static int
Kristian Høgsberge3148752013-05-06 23:19:49 -04001595surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001596{
1597 struct weston_move_grab *move;
1598
1599 if (!shsurf)
1600 return -1;
1601
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001602 if (shsurf->grabbed)
1603 return 0;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001604 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1605 return 0;
1606
1607 move = malloc(sizeof *move);
1608 if (!move)
1609 return -1;
1610
Jason Ekstranda7af7042013-10-12 22:38:11 -05001611 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001612 seat->pointer->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001613 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001614 seat->pointer->grab_y;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001615
1616 shell_grab_start(&move->base, &move_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001617 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001618
1619 return 0;
1620}
1621
1622static void
1623shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1624 struct wl_resource *seat_resource, uint32_t serial)
1625{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001626 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001627 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001628 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001629
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001630 if (seat->pointer &&
1631 seat->pointer->button_count > 0 &&
1632 seat->pointer->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001633 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001634 if ((surface == shsurf->surface) &&
1635 (surface_move(shsurf, seat) < 0))
1636 wl_resource_post_no_memory(resource);
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001637 } else if (seat->touch &&
1638 seat->touch->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001639 surface = weston_surface_get_main_surface(seat->touch->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001640 if ((surface == shsurf->surface) &&
1641 (surface_touch_move(shsurf, seat) < 0))
1642 wl_resource_post_no_memory(resource);
1643 }
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001644}
1645
1646struct weston_resize_grab {
1647 struct shell_grab base;
1648 uint32_t edges;
1649 int32_t width, height;
1650};
1651
1652static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001653resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1654 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001655{
1656 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001657 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001658 struct shell_surface *shsurf = resize->base.shsurf;
1659 int32_t width, height;
1660 wl_fixed_t from_x, from_y;
1661 wl_fixed_t to_x, to_y;
1662
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001663 weston_pointer_move(pointer, x, y);
1664
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001665 if (!shsurf)
1666 return;
1667
Jason Ekstranda7af7042013-10-12 22:38:11 -05001668 weston_view_from_global_fixed(shsurf->view,
1669 pointer->grab_x, pointer->grab_y,
1670 &from_x, &from_y);
1671 weston_view_from_global_fixed(shsurf->view,
1672 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001673
1674 width = resize->width;
1675 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1676 width += wl_fixed_to_int(from_x - to_x);
1677 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1678 width += wl_fixed_to_int(to_x - from_x);
1679 }
1680
1681 height = resize->height;
1682 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1683 height += wl_fixed_to_int(from_y - to_y);
1684 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1685 height += wl_fixed_to_int(to_y - from_y);
1686 }
1687
1688 shsurf->client->send_configure(shsurf->surface,
1689 resize->edges, width, height);
1690}
1691
1692static void
1693send_configure(struct weston_surface *surface,
1694 uint32_t edges, int32_t width, int32_t height)
1695{
1696 struct shell_surface *shsurf = get_shell_surface(surface);
1697
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001698 wl_shell_surface_send_configure(shsurf->resource,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001699 edges, width, height);
1700}
1701
1702static const struct weston_shell_client shell_client = {
1703 send_configure
1704};
1705
1706static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001707resize_grab_button(struct weston_pointer_grab *grab,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001708 uint32_t time, uint32_t button, uint32_t state_w)
1709{
1710 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001711 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001712 enum wl_pointer_button_state state = state_w;
1713
1714 if (pointer->button_count == 0 &&
1715 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1716 shell_grab_end(&resize->base);
1717 free(grab);
1718 }
1719}
1720
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001721static void
1722resize_grab_cancel(struct weston_pointer_grab *grab)
1723{
1724 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1725
1726 shell_grab_end(&resize->base);
1727 free(grab);
1728}
1729
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001730static const struct weston_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001731 noop_grab_focus,
1732 resize_grab_motion,
1733 resize_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001734 resize_grab_cancel,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001735};
1736
Giulio Camuffob8366642013-04-25 13:57:46 +03001737/*
1738 * Returns the bounding box of a surface and all its sub-surfaces,
1739 * in the surface coordinates system. */
1740static void
1741surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1742 int32_t *y, int32_t *w, int32_t *h) {
1743 pixman_region32_t region;
1744 pixman_box32_t *box;
1745 struct weston_subsurface *subsurface;
1746
1747 pixman_region32_init_rect(&region, 0, 0,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001748 surface->width,
1749 surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001750
1751 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1752 pixman_region32_union_rect(&region, &region,
1753 subsurface->position.x,
1754 subsurface->position.y,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001755 subsurface->surface->width,
1756 subsurface->surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001757 }
1758
1759 box = pixman_region32_extents(&region);
1760 if (x)
1761 *x = box->x1;
1762 if (y)
1763 *y = box->y1;
1764 if (w)
1765 *w = box->x2 - box->x1;
1766 if (h)
1767 *h = box->y2 - box->y1;
1768
1769 pixman_region32_fini(&region);
1770}
1771
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001772static int
1773surface_resize(struct shell_surface *shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001774 struct weston_seat *seat, uint32_t edges)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001775{
1776 struct weston_resize_grab *resize;
1777
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01001778 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1779 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001780 return 0;
1781
1782 if (edges == 0 || edges > 15 ||
1783 (edges & 3) == 3 || (edges & 12) == 12)
1784 return 0;
1785
1786 resize = malloc(sizeof *resize);
1787 if (!resize)
1788 return -1;
1789
1790 resize->edges = edges;
Giulio Camuffob8366642013-04-25 13:57:46 +03001791 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1792 &resize->width, &resize->height);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001793
1794 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001795 seat->pointer, edges);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001796
1797 return 0;
1798}
1799
1800static void
1801shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1802 struct wl_resource *seat_resource, uint32_t serial,
1803 uint32_t edges)
1804{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001805 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001806 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001807 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001808
1809 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1810 return;
1811
Jason Ekstranda7af7042013-10-12 22:38:11 -05001812 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001813 if (seat->pointer->button_count == 0 ||
1814 seat->pointer->grab_serial != serial ||
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001815 surface != shsurf->surface)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001816 return;
1817
Kristian Høgsberge3148752013-05-06 23:19:49 -04001818 if (surface_resize(shsurf, seat, edges) < 0)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001819 wl_resource_post_no_memory(resource);
1820}
1821
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001822static void
Kristian Høgsberg67800732013-07-04 01:12:17 -04001823end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1824
1825static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001826busy_cursor_grab_focus(struct weston_pointer_grab *base)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001827{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001828 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001829 struct weston_pointer *pointer = base->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001830 struct weston_view *view;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001831 wl_fixed_t sx, sy;
1832
Jason Ekstranda7af7042013-10-12 22:38:11 -05001833 view = weston_compositor_pick_view(pointer->seat->compositor,
1834 pointer->x, pointer->y,
1835 &sx, &sy);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001836
Jason Ekstranda7af7042013-10-12 22:38:11 -05001837 if (!grab->shsurf || grab->shsurf->surface != view->surface)
Kristian Høgsberg67800732013-07-04 01:12:17 -04001838 end_busy_cursor(grab->shsurf, pointer);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001839}
1840
1841static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001842busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1843 wl_fixed_t x, wl_fixed_t y)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001844{
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001845 weston_pointer_move(grab->pointer, x, y);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001846}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001847
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001848static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001849busy_cursor_grab_button(struct weston_pointer_grab *base,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001850 uint32_t time, uint32_t button, uint32_t state)
1851{
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001852 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001853 struct shell_surface *shsurf = grab->shsurf;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001854 struct weston_seat *seat = grab->grab.pointer->seat;
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001855
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001856 if (shsurf && button == BTN_LEFT && state) {
1857 activate(shsurf->shell, shsurf->surface, seat);
1858 surface_move(shsurf, seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05001859 } else if (shsurf && button == BTN_RIGHT && state) {
1860 activate(shsurf->shell, shsurf->surface, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001861 surface_rotate(shsurf, seat);
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001862 }
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001863}
1864
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001865static void
1866busy_cursor_grab_cancel(struct weston_pointer_grab *base)
1867{
1868 struct shell_grab *grab = (struct shell_grab *) base;
1869
1870 shell_grab_end(grab);
1871 free(grab);
1872}
1873
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001874static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001875 busy_cursor_grab_focus,
1876 busy_cursor_grab_motion,
1877 busy_cursor_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001878 busy_cursor_grab_cancel,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001879};
1880
1881static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001882set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001883{
1884 struct shell_grab *grab;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001885
1886 grab = malloc(sizeof *grab);
1887 if (!grab)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001888 return;
1889
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001890 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1891 DESKTOP_SHELL_CURSOR_BUSY);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001892}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001893
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001894static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001895end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001896{
1897 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1898
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001899 if (grab->grab.interface == &busy_cursor_grab_interface &&
1900 grab->shsurf == shsurf) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001901 shell_grab_end(grab);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001902 free(grab);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001903 }
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001904}
1905
Scott Moreau9521d5e2012-04-19 13:06:17 -06001906static void
1907ping_timer_destroy(struct shell_surface *shsurf)
1908{
1909 if (!shsurf || !shsurf->ping_timer)
1910 return;
1911
1912 if (shsurf->ping_timer->source)
1913 wl_event_source_remove(shsurf->ping_timer->source);
1914
1915 free(shsurf->ping_timer);
1916 shsurf->ping_timer = NULL;
1917}
1918
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001919static int
Scott Moreauff1db4a2012-04-17 19:06:18 -06001920ping_timeout_handler(void *data)
1921{
1922 struct shell_surface *shsurf = data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001923 struct weston_seat *seat;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001924
Scott Moreau9521d5e2012-04-19 13:06:17 -06001925 /* Client is not responding */
1926 shsurf->unresponsive = 1;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001927
1928 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
Emilio Pozuelo Monfort3d0fc762013-11-22 16:21:20 +01001929 if (seat->pointer->focus &&
1930 seat->pointer->focus->surface == shsurf->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001931 set_busy_cursor(shsurf, seat->pointer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001932
1933 return 1;
1934}
1935
1936static void
1937ping_handler(struct weston_surface *surface, uint32_t serial)
1938{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04001939 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001940 struct wl_event_loop *loop;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001941 int ping_timeout = 200;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001942
1943 if (!shsurf)
1944 return;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001945 if (!shsurf->resource)
Kristian Høgsbergca535c12012-04-21 23:20:07 -04001946 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001947
Ander Conselvan de Oliveiraeac9a462012-07-16 14:15:48 +03001948 if (shsurf->surface == shsurf->shell->grab_surface)
1949 return;
1950
Scott Moreauff1db4a2012-04-17 19:06:18 -06001951 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +03001952 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001953 if (!shsurf->ping_timer)
1954 return;
1955
1956 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001957 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1958 shsurf->ping_timer->source =
1959 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1960 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1961
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001962 wl_shell_surface_send_ping(shsurf->resource, serial);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001963 }
1964}
1965
1966static void
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001967handle_pointer_focus(struct wl_listener *listener, void *data)
1968{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001969 struct weston_pointer *pointer = data;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001970 struct weston_view *view = pointer->focus;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001971 struct weston_compositor *compositor;
1972 struct shell_surface *shsurf;
1973 uint32_t serial;
1974
Jason Ekstranda7af7042013-10-12 22:38:11 -05001975 if (!view)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001976 return;
1977
Jason Ekstranda7af7042013-10-12 22:38:11 -05001978 compositor = view->surface->compositor;
1979 shsurf = get_shell_surface(view->surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001980
Pekka Paalanen4e1f2ff2012-06-06 16:59:45 +03001981 if (shsurf && shsurf->unresponsive) {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001982 set_busy_cursor(shsurf, pointer);
1983 } else {
1984 serial = wl_display_next_serial(compositor->wl_display);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001985 ping_handler(view->surface, serial);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001986 }
1987}
1988
1989static void
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001990create_pointer_focus_listener(struct weston_seat *seat)
1991{
1992 struct wl_listener *listener;
1993
Kristian Høgsberge3148752013-05-06 23:19:49 -04001994 if (!seat->pointer)
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001995 return;
1996
1997 listener = malloc(sizeof *listener);
1998 listener->notify = handle_pointer_focus;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001999 wl_signal_add(&seat->pointer->focus_signal, listener);
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04002000}
2001
2002static void
Scott Moreauff1db4a2012-04-17 19:06:18 -06002003shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
2004 uint32_t serial)
2005{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002006 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04002007 struct weston_seat *seat;
2008 struct weston_compositor *ec = shsurf->surface->compositor;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002009
Kristian Høgsberg92374e12012-08-11 22:39:12 -04002010 if (shsurf->ping_timer == NULL)
2011 /* Just ignore unsolicited pong. */
2012 return;
2013
Scott Moreauff1db4a2012-04-17 19:06:18 -06002014 if (shsurf->ping_timer->serial == serial) {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002015 shsurf->unresponsive = 0;
Hardeningeb1e1302013-05-17 18:07:41 +02002016 wl_list_for_each(seat, &ec->seat_list, link) {
2017 if(seat->pointer)
2018 end_busy_cursor(shsurf, seat->pointer);
2019 }
Scott Moreau9521d5e2012-04-19 13:06:17 -06002020 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -06002021 }
2022}
2023
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002024static void
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002025set_title(struct shell_surface *shsurf, const char *title)
2026{
2027 free(shsurf->title);
2028 shsurf->title = strdup(title);
2029}
2030
2031static void
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002032shell_surface_set_title(struct wl_client *client,
2033 struct wl_resource *resource, const char *title)
2034{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002035 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002036
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002037 set_title(shsurf, title);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002038}
2039
2040static void
2041shell_surface_set_class(struct wl_client *client,
2042 struct wl_resource *resource, const char *class)
2043{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002044 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002045
2046 free(shsurf->class);
2047 shsurf->class = strdup(class);
2048}
2049
Alex Wu4539b082012-03-01 12:57:46 +08002050static void
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002051restore_output_mode(struct weston_output *output)
2052{
Hardening57388e42013-09-18 23:56:36 +02002053 if (output->current_mode != output->original_mode ||
2054 (int32_t)output->current_scale != output->original_scale)
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002055 weston_output_switch_mode(output,
Hardening57388e42013-09-18 23:56:36 +02002056 output->original_mode,
2057 output->original_scale,
2058 WESTON_MODE_SWITCH_RESTORE_NATIVE);
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002059}
2060
2061static void
2062restore_all_output_modes(struct weston_compositor *compositor)
2063{
2064 struct weston_output *output;
2065
2066 wl_list_for_each(output, &compositor->output_list, link)
2067 restore_output_mode(output);
2068}
2069
Philip Withnallbecb77e2013-11-25 18:01:30 +00002070static int
2071get_output_panel_height(struct desktop_shell *shell,
2072 struct weston_output *output)
2073{
2074 struct weston_view *view;
2075 int panel_height = 0;
2076
2077 if (!output)
2078 return 0;
2079
2080 wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
2081 if (view->surface->output == output) {
2082 panel_height = view->geometry.height;
2083 break;
2084 }
2085 }
2086
2087 return panel_height;
2088}
2089
Philip Withnall07926d92013-11-25 18:01:40 +00002090/* The surface will be inserted into the list immediately after the link
2091 * returned by this function (i.e. will be stacked immediately above the
2092 * returned link). */
2093static struct wl_list *
2094shell_surface_calculate_layer_link (struct shell_surface *shsurf)
2095{
2096 struct workspace *ws;
2097
2098 switch (shsurf->type) {
2099 case SHELL_SURFACE_POPUP:
2100 case SHELL_SURFACE_TRANSIENT: {
2101 /* Move the surface to its parent layer so that surfaces which
2102 * are transient for fullscreen surfaces don't get hidden by the
2103 * fullscreen surfaces. */
2104 struct weston_view *parent;
2105
2106 /* TODO: Handle a parent with multiple views */
2107 parent = get_default_view(shsurf->parent);
2108 if (parent)
2109 return parent->layer_link.prev;
2110
2111 break;
2112 }
2113
2114 case SHELL_SURFACE_FULLSCREEN:
2115 return &shsurf->shell->fullscreen_layer.view_list;
2116
2117 case SHELL_SURFACE_XWAYLAND:
2118 case SHELL_SURFACE_TOPLEVEL:
2119 case SHELL_SURFACE_MAXIMIZED:
2120 case SHELL_SURFACE_NONE:
2121 default:
2122 /* Go to the fallback, below. */
2123 break;
2124 }
2125
2126 /* Move the surface to a normal workspace layer so that surfaces
2127 * which were previously fullscreen or transient are no longer
2128 * rendered on top. */
2129 ws = get_current_workspace(shsurf->shell);
2130 return &ws->layer.view_list;
2131}
2132
Philip Withnall648a4dd2013-11-25 18:01:44 +00002133static void
2134shell_surface_update_child_surface_layers (struct shell_surface *shsurf)
2135{
2136 struct shell_surface *child;
2137
2138 /* Move the child layers to the same workspace as shsurf. They will be
2139 * stacked above shsurf. */
2140 wl_list_for_each_reverse(child, &shsurf->children_list, children_link) {
2141 if (shsurf->view->layer_link.prev != &child->view->layer_link) {
2142 weston_view_geometry_dirty(child->view);
2143 wl_list_remove(&child->view->layer_link);
2144 wl_list_insert(shsurf->view->layer_link.prev,
2145 &child->view->layer_link);
2146 weston_view_geometry_dirty(child->view);
2147 weston_surface_damage(child->surface);
2148
2149 /* Recurse. We don’t expect this to recurse very far (if
2150 * at all) because that would imply we have transient
2151 * (or popup) children of transient surfaces, which
2152 * would be unusual. */
2153 shell_surface_update_child_surface_layers(child);
2154 }
2155 }
2156}
2157
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002158/* Update the surface’s layer. Mark both the old and new views as having dirty
Philip Withnall648a4dd2013-11-25 18:01:44 +00002159 * geometry to ensure the changes are redrawn.
2160 *
2161 * If any child surfaces exist and are mapped, ensure they’re in the same layer
2162 * as this surface. */
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002163static void
2164shell_surface_update_layer(struct shell_surface *shsurf)
2165{
2166 struct wl_list *new_layer_link;
2167
2168 new_layer_link = shell_surface_calculate_layer_link(shsurf);
2169
2170 if (new_layer_link == &shsurf->view->layer_link)
2171 return;
2172
2173 weston_view_geometry_dirty(shsurf->view);
2174 wl_list_remove(&shsurf->view->layer_link);
2175 wl_list_insert(new_layer_link, &shsurf->view->layer_link);
2176 weston_view_geometry_dirty(shsurf->view);
2177 weston_surface_damage(shsurf->surface);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002178
2179 shell_surface_update_child_surface_layers(shsurf);
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002180}
2181
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002182static void
Philip Withnalldc4332f2013-11-25 18:01:38 +00002183shell_surface_set_parent(struct shell_surface *shsurf,
2184 struct weston_surface *parent)
2185{
2186 shsurf->parent = parent;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002187
2188 wl_list_remove(&shsurf->children_link);
2189 wl_list_init(&shsurf->children_link);
2190
2191 /* Insert into the parent surface’s child list. */
2192 if (parent != NULL) {
2193 struct shell_surface *parent_shsurf = get_shell_surface(parent);
2194 if (parent_shsurf != NULL)
2195 wl_list_insert(&parent_shsurf->children_list,
2196 &shsurf->children_link);
2197 }
Philip Withnalldc4332f2013-11-25 18:01:38 +00002198}
2199
2200static void
Philip Withnall352e7ed2013-11-25 18:01:35 +00002201shell_surface_set_output(struct shell_surface *shsurf,
2202 struct weston_output *output)
2203{
2204 struct weston_surface *es = shsurf->surface;
2205
2206 /* get the default output, if the client set it as NULL
2207 check whether the ouput is available */
2208 if (output)
2209 shsurf->output = output;
2210 else if (es->output)
2211 shsurf->output = es->output;
2212 else
2213 shsurf->output = get_default_output(es->compositor);
2214}
2215
2216static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002217set_toplevel(struct shell_surface *shsurf)
2218{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002219 shell_surface_set_parent(shsurf, NULL);
2220
Philip Withnallbecb77e2013-11-25 18:01:30 +00002221 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002222
2223 /* The layer_link is updated in set_surface_type(),
2224 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002225}
2226
2227static void
2228shell_surface_set_toplevel(struct wl_client *client,
2229 struct wl_resource *resource)
2230{
2231 struct shell_surface *surface = wl_resource_get_user_data(resource);
2232
2233 set_toplevel(surface);
2234}
2235
2236static void
2237set_transient(struct shell_surface *shsurf,
2238 struct weston_surface *parent, int x, int y, uint32_t flags)
2239{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002240 assert(parent != NULL);
2241
Philip Withnallbecb77e2013-11-25 18:01:30 +00002242 shsurf->transient.x = x;
2243 shsurf->transient.y = y;
2244 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002245
2246 shell_surface_set_parent(shsurf, parent);
2247
Philip Withnallbecb77e2013-11-25 18:01:30 +00002248 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002249
2250 /* The layer_link is updated in set_surface_type(),
2251 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002252}
2253
2254static void
2255shell_surface_set_transient(struct wl_client *client,
2256 struct wl_resource *resource,
2257 struct wl_resource *parent_resource,
2258 int x, int y, uint32_t flags)
2259{
2260 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2261 struct weston_surface *parent =
2262 wl_resource_get_user_data(parent_resource);
2263
2264 set_transient(shsurf, parent, x, y, flags);
2265}
2266
2267static void
2268set_fullscreen(struct shell_surface *shsurf,
2269 uint32_t method,
2270 uint32_t framerate,
2271 struct weston_output *output)
2272{
Philip Withnall352e7ed2013-11-25 18:01:35 +00002273 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002274
2275 shsurf->fullscreen_output = shsurf->output;
2276 shsurf->fullscreen.type = method;
2277 shsurf->fullscreen.framerate = framerate;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002278
2279 shell_surface_set_parent(shsurf, NULL);
2280
Philip Withnallbecb77e2013-11-25 18:01:30 +00002281 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
2282
2283 shsurf->client->send_configure(shsurf->surface, 0,
2284 shsurf->output->width,
2285 shsurf->output->height);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002286
2287 /* The layer_link is updated in set_surface_type(),
2288 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002289}
2290
2291static void
2292unset_fullscreen(struct shell_surface *shsurf)
Alex Wu4539b082012-03-01 12:57:46 +08002293{
Philip Withnallf85fe842013-11-25 18:01:37 +00002294 /* Unset the fullscreen output, driver configuration and transforms. */
Alex Wubd3354b2012-04-17 17:20:49 +08002295 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2296 shell_surface_is_top_fullscreen(shsurf)) {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002297 restore_output_mode(shsurf->fullscreen_output);
Alex Wubd3354b2012-04-17 17:20:49 +08002298 }
Philip Withnallf85fe842013-11-25 18:01:37 +00002299 shsurf->fullscreen_output = NULL;
2300
Alex Wu4539b082012-03-01 12:57:46 +08002301 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2302 shsurf->fullscreen.framerate = 0;
Philip Withnallf85fe842013-11-25 18:01:37 +00002303
Alex Wu4539b082012-03-01 12:57:46 +08002304 wl_list_remove(&shsurf->fullscreen.transform.link);
2305 wl_list_init(&shsurf->fullscreen.transform.link);
Philip Withnallf85fe842013-11-25 18:01:37 +00002306
Jason Ekstranda7af7042013-10-12 22:38:11 -05002307 if (shsurf->fullscreen.black_view)
2308 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
2309 shsurf->fullscreen.black_view = NULL;
Philip Withnallf85fe842013-11-25 18:01:37 +00002310
Jason Ekstranda7af7042013-10-12 22:38:11 -05002311 weston_view_set_position(shsurf->view,
2312 shsurf->saved_x, shsurf->saved_y);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002313 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002314 wl_list_insert(&shsurf->view->geometry.transformation_list,
Philip Withnallbecb77e2013-11-25 18:01:30 +00002315 &shsurf->rotation.transform.link);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002316 shsurf->saved_rotation_valid = false;
2317 }
Rafal Mielniczuk3e3862c2012-10-07 20:25:36 +02002318
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002319 /* Layer is updated in set_surface_type(). */
Alex Wu4539b082012-03-01 12:57:46 +08002320}
2321
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002322static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002323shell_surface_set_fullscreen(struct wl_client *client,
2324 struct wl_resource *resource,
2325 uint32_t method,
2326 uint32_t framerate,
2327 struct wl_resource *output_resource)
2328{
2329 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2330 struct weston_output *output;
2331
2332 if (output_resource)
2333 output = wl_resource_get_user_data(output_resource);
2334 else
2335 output = NULL;
2336
2337 set_fullscreen(shsurf, method, framerate, output);
2338}
2339
2340static void
2341set_popup(struct shell_surface *shsurf,
2342 struct weston_surface *parent,
2343 struct weston_seat *seat,
2344 uint32_t serial,
2345 int32_t x,
2346 int32_t y)
2347{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002348 assert(parent != NULL);
2349
Philip Withnallbecb77e2013-11-25 18:01:30 +00002350 shsurf->popup.shseat = get_shell_seat(seat);
2351 shsurf->popup.serial = serial;
2352 shsurf->popup.x = x;
2353 shsurf->popup.y = y;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002354
2355 shell_surface_set_parent(shsurf, parent);
Philip Withnallb995e1d2013-11-25 18:01:39 +00002356
2357 shsurf->next_type = SHELL_SURFACE_POPUP;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002358}
2359
2360static void
2361shell_surface_set_popup(struct wl_client *client,
2362 struct wl_resource *resource,
2363 struct wl_resource *seat_resource,
2364 uint32_t serial,
2365 struct wl_resource *parent_resource,
2366 int32_t x, int32_t y, uint32_t flags)
2367{
2368 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2369
2370 set_popup(shsurf,
2371 wl_resource_get_user_data(parent_resource),
2372 wl_resource_get_user_data(seat_resource),
2373 serial, x, y);
2374}
2375
2376static void
2377set_maximized(struct shell_surface *shsurf,
2378 struct weston_output *output)
2379{
2380 struct desktop_shell *shell;
2381 uint32_t edges = 0, panel_height = 0;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002382
Philip Withnall352e7ed2013-11-25 18:01:35 +00002383 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002384
2385 shell = shell_surface_get_shell(shsurf);
2386 panel_height = get_output_panel_height(shell, shsurf->output);
2387 edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT;
2388
2389 shsurf->client->send_configure(shsurf->surface, edges,
2390 shsurf->output->width,
2391 shsurf->output->height - panel_height);
2392
Philip Withnalldc4332f2013-11-25 18:01:38 +00002393 shell_surface_set_parent(shsurf, NULL);
2394
Philip Withnallbecb77e2013-11-25 18:01:30 +00002395 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
2396}
2397
2398static void
2399unset_maximized(struct shell_surface *shsurf)
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002400{
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002401 /* undo all maximized things here */
2402 shsurf->output = get_default_output(shsurf->surface->compositor);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002403 weston_view_set_position(shsurf->view,
2404 shsurf->saved_x,
2405 shsurf->saved_y);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002406
2407 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002408 wl_list_insert(&shsurf->view->geometry.transformation_list,
2409 &shsurf->rotation.transform.link);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002410 shsurf->saved_rotation_valid = false;
2411 }
2412
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002413 /* Layer is updated in set_surface_type(). */
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002414}
2415
Philip Withnallbecb77e2013-11-25 18:01:30 +00002416static void
2417shell_surface_set_maximized(struct wl_client *client,
2418 struct wl_resource *resource,
2419 struct wl_resource *output_resource)
2420{
2421 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2422 struct weston_output *output;
2423
2424 if (output_resource)
2425 output = wl_resource_get_user_data(output_resource);
2426 else
2427 output = NULL;
2428
2429 set_maximized(shsurf, output);
2430}
2431
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002432/* This is only ever called from set_surface_type(), so there’s no need to
2433 * update layer_links here, since they’ll be updated when we return. */
Pekka Paalanen98262232011-12-01 10:42:22 +02002434static int
Philip Withnallbecb77e2013-11-25 18:01:30 +00002435reset_surface_type(struct shell_surface *surface)
Pekka Paalanen98262232011-12-01 10:42:22 +02002436{
2437 switch (surface->type) {
2438 case SHELL_SURFACE_FULLSCREEN:
Philip Withnallbecb77e2013-11-25 18:01:30 +00002439 unset_fullscreen(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +02002440 break;
Juan Zhao96879df2012-02-07 08:45:41 +08002441 case SHELL_SURFACE_MAXIMIZED:
Philip Withnallbecb77e2013-11-25 18:01:30 +00002442 unset_maximized(surface);
Juan Zhao96879df2012-02-07 08:45:41 +08002443 break;
Pekka Paalanen98262232011-12-01 10:42:22 +02002444 case SHELL_SURFACE_NONE:
2445 case SHELL_SURFACE_TOPLEVEL:
2446 case SHELL_SURFACE_TRANSIENT:
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002447 case SHELL_SURFACE_POPUP:
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002448 case SHELL_SURFACE_XWAYLAND:
Philip Withnall0f640e22013-11-25 18:01:31 +00002449 default:
Pekka Paalanen98262232011-12-01 10:42:22 +02002450 break;
2451 }
2452
2453 surface->type = SHELL_SURFACE_NONE;
2454 return 0;
2455}
2456
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002457static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002458set_surface_type(struct shell_surface *shsurf)
2459{
Kristian Høgsberg8150b192012-06-27 10:22:58 -04002460 struct weston_surface *pes = shsurf->parent;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002461 struct weston_view *pev = get_default_view(pes);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002462
Philip Withnallbecb77e2013-11-25 18:01:30 +00002463 reset_surface_type(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002464
2465 shsurf->type = shsurf->next_type;
2466 shsurf->next_type = SHELL_SURFACE_NONE;
2467
2468 switch (shsurf->type) {
2469 case SHELL_SURFACE_TOPLEVEL:
2470 break;
2471 case SHELL_SURFACE_TRANSIENT:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002472 if (pev)
2473 weston_view_set_position(shsurf->view,
2474 pev->geometry.x + shsurf->transient.x,
2475 pev->geometry.y + shsurf->transient.y);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002476 break;
2477
2478 case SHELL_SURFACE_MAXIMIZED:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002479 case SHELL_SURFACE_FULLSCREEN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002480 shsurf->saved_x = shsurf->view->geometry.x;
2481 shsurf->saved_y = shsurf->view->geometry.y;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002482 shsurf->saved_position_valid = true;
2483
2484 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
2485 wl_list_remove(&shsurf->rotation.transform.link);
2486 wl_list_init(&shsurf->rotation.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002487 weston_view_geometry_dirty(shsurf->view);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002488 shsurf->saved_rotation_valid = true;
2489 }
2490 break;
2491
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002492 case SHELL_SURFACE_XWAYLAND:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002493 weston_view_set_position(shsurf->view, shsurf->transient.x,
2494 shsurf->transient.y);
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002495 break;
2496
Philip Withnall0f640e22013-11-25 18:01:31 +00002497 case SHELL_SURFACE_POPUP:
2498 case SHELL_SURFACE_NONE:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002499 default:
2500 break;
2501 }
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002502
2503 /* Update the surface’s layer. */
2504 shell_surface_update_layer(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002505}
2506
Tiago Vignattibe143262012-04-16 17:31:41 +03002507static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +08002508shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002509{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002510 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +08002511}
2512
Alex Wu21858432012-04-01 20:13:08 +08002513static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002514black_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 +08002515
Jason Ekstranda7af7042013-10-12 22:38:11 -05002516static struct weston_view *
Alex Wu4539b082012-03-01 12:57:46 +08002517create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +08002518 struct weston_surface *fs_surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02002519 float x, float y, int w, int h)
Alex Wu4539b082012-03-01 12:57:46 +08002520{
2521 struct weston_surface *surface = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002522 struct weston_view *view;
Alex Wu4539b082012-03-01 12:57:46 +08002523
2524 surface = weston_surface_create(ec);
2525 if (surface == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02002526 weston_log("no memory\n");
Alex Wu4539b082012-03-01 12:57:46 +08002527 return NULL;
2528 }
Jason Ekstranda7af7042013-10-12 22:38:11 -05002529 view = weston_view_create(surface);
2530 if (surface == NULL) {
2531 weston_log("no memory\n");
2532 weston_surface_destroy(surface);
2533 return NULL;
2534 }
Alex Wu4539b082012-03-01 12:57:46 +08002535
Alex Wu21858432012-04-01 20:13:08 +08002536 surface->configure = black_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002537 surface->configure_private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +08002538 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
Pekka Paalanen71f6f3b2012-10-10 12:49:26 +03002539 pixman_region32_fini(&surface->opaque);
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04002540 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
Jonas Ådahl33619a42013-01-15 21:25:55 +01002541 pixman_region32_fini(&surface->input);
2542 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
Xiong Zhangbecf5a32013-11-29 11:18:14 +08002543 surface->width = w;
2544 surface->height = h;
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04002545
Jason Ekstranda7af7042013-10-12 22:38:11 -05002546 weston_view_configure(view, x, y, w, h);
2547
2548 return view;
Alex Wu4539b082012-03-01 12:57:46 +08002549}
2550
Philip Withnalled8f1a92013-11-25 18:01:43 +00002551static void
2552shell_ensure_fullscreen_black_view(struct shell_surface *shsurf)
2553{
2554 struct weston_output *output = shsurf->fullscreen_output;
2555
2556 assert(shsurf->type == SHELL_SURFACE_FULLSCREEN);
2557
2558 if (!shsurf->fullscreen.black_view)
2559 shsurf->fullscreen.black_view =
2560 create_black_surface(shsurf->surface->compositor,
2561 shsurf->surface,
2562 output->x, output->y,
2563 output->width,
2564 output->height);
2565
2566 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2567 wl_list_remove(&shsurf->fullscreen.black_view->layer_link);
2568 wl_list_insert(&shsurf->view->layer_link,
2569 &shsurf->fullscreen.black_view->layer_link);
2570 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2571 weston_surface_damage(shsurf->surface);
2572}
2573
Alex Wu4539b082012-03-01 12:57:46 +08002574/* Create black surface and append it to the associated fullscreen surface.
2575 * Handle size dismatch and positioning according to the method. */
2576static void
2577shell_configure_fullscreen(struct shell_surface *shsurf)
2578{
2579 struct weston_output *output = shsurf->fullscreen_output;
2580 struct weston_surface *surface = shsurf->surface;
2581 struct weston_matrix *matrix;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002582 float scale, output_aspect, surface_aspect, x, y;
Giulio Camuffob8366642013-04-25 13:57:46 +03002583 int32_t surf_x, surf_y, surf_width, surf_height;
Alex Wu4539b082012-03-01 12:57:46 +08002584
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002585 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
2586 restore_output_mode(output);
2587
Philip Withnalled8f1a92013-11-25 18:01:43 +00002588 shell_ensure_fullscreen_black_view(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002589
Jason Ekstranda7af7042013-10-12 22:38:11 -05002590 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
Giulio Camuffob8366642013-04-25 13:57:46 +03002591 &surf_width, &surf_height);
2592
Alex Wu4539b082012-03-01 12:57:46 +08002593 switch (shsurf->fullscreen.type) {
2594 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
Pekka Paalanende685b82012-12-04 15:58:12 +02002595 if (surface->buffer_ref.buffer)
Jason Ekstranda7af7042013-10-12 22:38:11 -05002596 center_on_output(shsurf->view, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08002597 break;
2598 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
Rob Bradford9f3dd152013-02-12 11:53:47 +00002599 /* 1:1 mapping between surface and output dimensions */
Giulio Camuffob8366642013-04-25 13:57:46 +03002600 if (output->width == surf_width &&
2601 output->height == surf_height) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002602 weston_view_set_position(shsurf->view,
2603 output->x - surf_x,
2604 output->y - surf_y);
Rob Bradford9f3dd152013-02-12 11:53:47 +00002605 break;
2606 }
2607
Alex Wu4539b082012-03-01 12:57:46 +08002608 matrix = &shsurf->fullscreen.transform.matrix;
2609 weston_matrix_init(matrix);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002610
Scott Moreau1bad5db2012-08-18 01:04:05 -06002611 output_aspect = (float) output->width /
2612 (float) output->height;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002613 /* XXX: Use surf_width and surf_height here? */
2614 surface_aspect = (float) surface->width /
2615 (float) surface->height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002616 if (output_aspect < surface_aspect)
Scott Moreau1bad5db2012-08-18 01:04:05 -06002617 scale = (float) output->width /
Giulio Camuffob8366642013-04-25 13:57:46 +03002618 (float) surf_width;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002619 else
Scott Moreau1bad5db2012-08-18 01:04:05 -06002620 scale = (float) output->height /
Giulio Camuffob8366642013-04-25 13:57:46 +03002621 (float) surf_height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002622
Alex Wu4539b082012-03-01 12:57:46 +08002623 weston_matrix_scale(matrix, scale, scale, 1);
2624 wl_list_remove(&shsurf->fullscreen.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002625 wl_list_insert(&shsurf->view->geometry.transformation_list,
Alex Wu4539b082012-03-01 12:57:46 +08002626 &shsurf->fullscreen.transform.link);
Giulio Camuffob8366642013-04-25 13:57:46 +03002627 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2628 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002629 weston_view_set_position(shsurf->view, x, y);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002630
Alex Wu4539b082012-03-01 12:57:46 +08002631 break;
2632 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +08002633 if (shell_surface_is_top_fullscreen(shsurf)) {
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01002634 struct weston_mode mode = {0,
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002635 surf_width * surface->buffer_viewport.scale,
2636 surf_height * surface->buffer_viewport.scale,
Alex Wubd3354b2012-04-17 17:20:49 +08002637 shsurf->fullscreen.framerate};
2638
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002639 if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
Hardening57388e42013-09-18 23:56:36 +02002640 WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002641 weston_view_set_position(shsurf->view,
2642 output->x - surf_x,
2643 output->y - surf_y);
2644 weston_view_configure(shsurf->fullscreen.black_view,
2645 output->x - surf_x,
2646 output->y - surf_y,
2647 output->width,
2648 output->height);
Alex Wubd3354b2012-04-17 17:20:49 +08002649 break;
Alexander Larssond622ed32013-05-28 16:23:40 +02002650 } else {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002651 restore_output_mode(output);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002652 center_on_output(shsurf->view, output);
Alexander Larssond622ed32013-05-28 16:23:40 +02002653 }
Alex Wubd3354b2012-04-17 17:20:49 +08002654 }
Alex Wu4539b082012-03-01 12:57:46 +08002655 break;
2656 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002657 center_on_output(shsurf->view, output);
Alex Wu4539b082012-03-01 12:57:46 +08002658 break;
2659 default:
2660 break;
2661 }
2662}
2663
Alex Wu4539b082012-03-01 12:57:46 +08002664static void
2665shell_map_fullscreen(struct shell_surface *shsurf)
2666{
Alex Wubd3354b2012-04-17 17:20:49 +08002667 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002668}
2669
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002670static void
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002671set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2672{
2673 /* XXX: using the same fields for transient type */
2674 shsurf->transient.x = x;
2675 shsurf->transient.y = y;
2676 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002677
2678 shell_surface_set_parent(shsurf, NULL);
2679
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002680 shsurf->next_type = SHELL_SURFACE_XWAYLAND;
2681}
2682
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002683static const struct weston_pointer_grab_interface popup_grab_interface;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002684
2685static void
2686destroy_shell_seat(struct wl_listener *listener, void *data)
2687{
2688 struct shell_seat *shseat =
2689 container_of(listener,
2690 struct shell_seat, seat_destroy_listener);
2691 struct shell_surface *shsurf, *prev = NULL;
2692
2693 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002694 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002695 shseat->popup_grab.client = NULL;
2696
2697 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2698 shsurf->popup.shseat = NULL;
2699 if (prev) {
2700 wl_list_init(&prev->popup.grab_link);
2701 }
2702 prev = shsurf;
2703 }
2704 wl_list_init(&prev->popup.grab_link);
2705 }
2706
2707 wl_list_remove(&shseat->seat_destroy_listener.link);
2708 free(shseat);
2709}
2710
2711static struct shell_seat *
2712create_shell_seat(struct weston_seat *seat)
2713{
2714 struct shell_seat *shseat;
2715
2716 shseat = calloc(1, sizeof *shseat);
2717 if (!shseat) {
2718 weston_log("no memory to allocate shell seat\n");
2719 return NULL;
2720 }
2721
2722 shseat->seat = seat;
2723 wl_list_init(&shseat->popup_grab.surfaces_list);
2724
2725 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2726 wl_signal_add(&seat->destroy_signal,
2727 &shseat->seat_destroy_listener);
2728
2729 return shseat;
2730}
2731
2732static struct shell_seat *
2733get_shell_seat(struct weston_seat *seat)
2734{
2735 struct wl_listener *listener;
2736
2737 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2738 if (listener == NULL)
2739 return create_shell_seat(seat);
2740
2741 return container_of(listener,
2742 struct shell_seat, seat_destroy_listener);
2743}
2744
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002745static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002746popup_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002747{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002748 struct weston_pointer *pointer = grab->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002749 struct weston_view *view;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002750 struct shell_seat *shseat =
2751 container_of(grab, struct shell_seat, popup_grab.grab);
2752 struct wl_client *client = shseat->popup_grab.client;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002753 wl_fixed_t sx, sy;
2754
Jason Ekstranda7af7042013-10-12 22:38:11 -05002755 view = weston_compositor_pick_view(pointer->seat->compositor,
2756 pointer->x, pointer->y,
2757 &sx, &sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002758
Jason Ekstranda7af7042013-10-12 22:38:11 -05002759 if (view && view->surface->resource &&
2760 wl_resource_get_client(view->surface->resource) == client) {
2761 weston_pointer_set_focus(pointer, view, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002762 } else {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002763 weston_pointer_set_focus(pointer, NULL,
2764 wl_fixed_from_int(0),
2765 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002766 }
2767}
2768
2769static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002770popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
2771 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002772{
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002773 struct weston_pointer *pointer = grab->pointer;
Neil Roberts96d790e2013-09-19 17:32:00 +01002774 struct wl_resource *resource;
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002775 wl_fixed_t sx, sy;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002776
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002777 weston_pointer_move(pointer, x, y);
2778
Neil Roberts96d790e2013-09-19 17:32:00 +01002779 wl_resource_for_each(resource, &pointer->focus_resource_list) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002780 weston_view_from_global_fixed(pointer->focus,
2781 pointer->x, pointer->y,
2782 &sx, &sy);
Neil Roberts96d790e2013-09-19 17:32:00 +01002783 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002784 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002785}
2786
2787static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002788popup_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01002789 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002790{
2791 struct wl_resource *resource;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002792 struct shell_seat *shseat =
2793 container_of(grab, struct shell_seat, popup_grab.grab);
Rob Bradford880ebc72013-07-22 17:31:38 +01002794 struct wl_display *display = shseat->seat->compositor->wl_display;
Daniel Stone4dbadb12012-05-30 16:31:51 +01002795 enum wl_pointer_button_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002796 uint32_t serial;
Neil Roberts96d790e2013-09-19 17:32:00 +01002797 struct wl_list *resource_list;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002798
Neil Roberts96d790e2013-09-19 17:32:00 +01002799 resource_list = &grab->pointer->focus_resource_list;
2800 if (!wl_list_empty(resource_list)) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002801 serial = wl_display_get_serial(display);
Neil Roberts96d790e2013-09-19 17:32:00 +01002802 wl_resource_for_each(resource, resource_list) {
2803 wl_pointer_send_button(resource, serial,
2804 time, button, state);
2805 }
Daniel Stone4dbadb12012-05-30 16:31:51 +01002806 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
Giulio Camuffo5085a752013-03-25 21:42:45 +01002807 (shseat->popup_grab.initial_up ||
Kristian Høgsberge3148752013-05-06 23:19:49 -04002808 time - shseat->seat->pointer->grab_time > 500)) {
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002809 popup_grab_end(grab->pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002810 }
2811
Daniel Stone4dbadb12012-05-30 16:31:51 +01002812 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Giulio Camuffo5085a752013-03-25 21:42:45 +01002813 shseat->popup_grab.initial_up = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002814}
2815
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002816static void
2817popup_grab_cancel(struct weston_pointer_grab *grab)
2818{
2819 popup_grab_end(grab->pointer);
2820}
2821
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002822static const struct weston_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002823 popup_grab_focus,
2824 popup_grab_motion,
2825 popup_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002826 popup_grab_cancel,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002827};
2828
2829static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002830popup_grab_end(struct weston_pointer *pointer)
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002831{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002832 struct weston_pointer_grab *grab = pointer->grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002833 struct shell_seat *shseat =
2834 container_of(grab, struct shell_seat, popup_grab.grab);
2835 struct shell_surface *shsurf;
2836 struct shell_surface *prev = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002837
2838 if (pointer->grab->interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002839 weston_pointer_end_grab(grab->pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002840 shseat->popup_grab.client = NULL;
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002841 shseat->popup_grab.grab.interface = NULL;
2842 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
Giulio Camuffo5085a752013-03-25 21:42:45 +01002843 /* Send the popup_done event to all the popups open */
2844 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002845 wl_shell_surface_send_popup_done(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002846 shsurf->popup.shseat = NULL;
2847 if (prev) {
2848 wl_list_init(&prev->popup.grab_link);
2849 }
2850 prev = shsurf;
2851 }
2852 wl_list_init(&prev->popup.grab_link);
2853 wl_list_init(&shseat->popup_grab.surfaces_list);
2854 }
2855}
2856
2857static void
2858add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2859{
Kristian Høgsberge3148752013-05-06 23:19:49 -04002860 struct weston_seat *seat = shseat->seat;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002861
2862 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002863 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002864 shseat->popup_grab.grab.interface = &popup_grab_interface;
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002865 /* We must make sure here that this popup was opened after
2866 * a mouse press, and not just by moving around with other
2867 * popups already open. */
Kristian Høgsberge3148752013-05-06 23:19:49 -04002868 if (shseat->seat->pointer->button_count > 0)
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002869 shseat->popup_grab.initial_up = 0;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002870
Rob Bradforddfe31052013-06-26 19:49:11 +01002871 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002872 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
Rob Bradforddfe31052013-06-26 19:49:11 +01002873 } else {
2874 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002875 }
Giulio Camuffo5085a752013-03-25 21:42:45 +01002876}
2877
2878static void
2879remove_popup_grab(struct shell_surface *shsurf)
2880{
2881 struct shell_seat *shseat = shsurf->popup.shseat;
2882
2883 wl_list_remove(&shsurf->popup.grab_link);
2884 wl_list_init(&shsurf->popup.grab_link);
2885 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002886 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002887 shseat->popup_grab.grab.interface = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002888 }
2889}
2890
2891static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002892shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002893{
Giulio Camuffo5085a752013-03-25 21:42:45 +01002894 struct shell_seat *shseat = shsurf->popup.shseat;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002895 struct weston_view *parent_view = get_default_view(shsurf->parent);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002896
Jason Ekstranda7af7042013-10-12 22:38:11 -05002897 shsurf->surface->output = parent_view->output;
2898 shsurf->view->output = parent_view->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002899
Jason Ekstranda7af7042013-10-12 22:38:11 -05002900 weston_view_set_transform_parent(shsurf->view, parent_view);
2901 weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y);
2902 weston_view_update_transform(shsurf->view);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002903
Kristian Høgsberge3148752013-05-06 23:19:49 -04002904 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01002905 add_popup_grab(shsurf, shseat);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002906 } else {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002907 wl_shell_surface_send_popup_done(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002908 shseat->popup_grab.client = NULL;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002909 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002910}
2911
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002912static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002913 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002914 shell_surface_move,
2915 shell_surface_resize,
2916 shell_surface_set_toplevel,
2917 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002918 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08002919 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002920 shell_surface_set_maximized,
2921 shell_surface_set_title,
2922 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002923};
2924
2925static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002926destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002927{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002928 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2929
Giulio Camuffo5085a752013-03-25 21:42:45 +01002930 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2931 remove_popup_grab(shsurf);
2932 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002933
Alex Wubd3354b2012-04-17 17:20:49 +08002934 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002935 shell_surface_is_top_fullscreen(shsurf))
2936 restore_output_mode (shsurf->fullscreen_output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002937
Jason Ekstranda7af7042013-10-12 22:38:11 -05002938 if (shsurf->fullscreen.black_view)
2939 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
Alex Wuaa08e2d2012-03-05 11:01:40 +08002940
Alex Wubd3354b2012-04-17 17:20:49 +08002941 /* As destroy_resource() use wl_list_for_each_safe(),
2942 * we can always remove the listener.
2943 */
2944 wl_list_remove(&shsurf->surface_destroy_listener.link);
2945 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06002946 ping_timer_destroy(shsurf);
Scott Moreau976a0502013-03-07 10:15:17 -07002947 free(shsurf->title);
Alex Wubd3354b2012-04-17 17:20:49 +08002948
Jason Ekstranda7af7042013-10-12 22:38:11 -05002949 weston_view_destroy(shsurf->view);
2950
Philip Withnall648a4dd2013-11-25 18:01:44 +00002951 wl_list_remove(&shsurf->children_link);
2952
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002953 wl_list_remove(&shsurf->link);
2954 free(shsurf);
2955}
2956
2957static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002958shell_destroy_shell_surface(struct wl_resource *resource)
2959{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002960 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03002961
2962 destroy_shell_surface(shsurf);
2963}
2964
2965static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002966shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002967{
2968 struct shell_surface *shsurf = container_of(listener,
2969 struct shell_surface,
2970 surface_destroy_listener);
2971
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002972 if (shsurf->resource)
2973 wl_resource_destroy(shsurf->resource);
2974 else
Tiago Vignattibc052c92012-04-19 16:18:18 +03002975 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002976}
2977
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002978static void
Giulio Camuffo184df502013-02-21 11:29:21 +01002979shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002980
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002981static struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002982get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002983{
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002984 if (surface->configure == shell_surface_configure)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002985 return surface->configure_private;
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002986 else
2987 return NULL;
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002988}
2989
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002990static struct shell_surface *
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002991create_shell_surface(void *shell, struct weston_surface *surface,
2992 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002993{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002994 struct shell_surface *shsurf;
2995
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002996 if (surface->configure) {
Martin Minarik6d118362012-06-07 18:01:59 +02002997 weston_log("surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002998 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002999 }
3000
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003001 shsurf = calloc(1, sizeof *shsurf);
3002 if (!shsurf) {
Martin Minarik6d118362012-06-07 18:01:59 +02003003 weston_log("no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04003004 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003005 }
3006
Jason Ekstranda7af7042013-10-12 22:38:11 -05003007 shsurf->view = weston_view_create(surface);
3008 if (!shsurf->view) {
3009 weston_log("no memory to allocate shell surface\n");
3010 free(shsurf);
3011 return NULL;
3012 }
3013
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003014 surface->configure = shell_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003015 surface->configure_private = shsurf;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03003016
Tiago Vignattibc052c92012-04-19 16:18:18 +03003017 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06003018 shsurf->unresponsive = 0;
Alex Wu4539b082012-03-01 12:57:46 +08003019 shsurf->saved_position_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08003020 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003021 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08003022 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
3023 shsurf->fullscreen.framerate = 0;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003024 shsurf->fullscreen.black_view = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06003025 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08003026 wl_list_init(&shsurf->fullscreen.transform.link);
3027
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003028 wl_signal_init(&shsurf->destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003029 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05003030 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003031 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003032
3033 /* init link so its safe to always remove it in destroy_shell_surface */
3034 wl_list_init(&shsurf->link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01003035 wl_list_init(&shsurf->popup.grab_link);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003036
Pekka Paalanen460099f2012-01-20 16:48:25 +02003037 /* empty when not in use */
3038 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003039 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003040
Jonas Ådahl62fcd042012-06-13 00:01:23 +02003041 wl_list_init(&shsurf->workspace_transform.link);
3042
Philip Withnall648a4dd2013-11-25 18:01:44 +00003043 wl_list_init(&shsurf->children_link);
3044 wl_list_init(&shsurf->children_list);
3045 shsurf->parent = NULL;
3046
Pekka Paalanen98262232011-12-01 10:42:22 +02003047 shsurf->type = SHELL_SURFACE_NONE;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04003048 shsurf->next_type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003049
Kristian Høgsberga61ca062012-05-22 16:05:52 -04003050 shsurf->client = client;
3051
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04003052 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03003053}
3054
Jason Ekstranda7af7042013-10-12 22:38:11 -05003055static struct weston_view *
3056get_primary_view(void *shell, struct shell_surface *shsurf)
3057{
3058 return shsurf->view;
3059}
3060
Tiago Vignattibc052c92012-04-19 16:18:18 +03003061static void
3062shell_get_shell_surface(struct wl_client *client,
3063 struct wl_resource *resource,
3064 uint32_t id,
3065 struct wl_resource *surface_resource)
3066{
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003067 struct weston_surface *surface =
3068 wl_resource_get_user_data(surface_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003069 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03003070 struct shell_surface *shsurf;
3071
3072 if (get_shell_surface(surface)) {
3073 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003074 WL_DISPLAY_ERROR_INVALID_OBJECT,
3075 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03003076 return;
3077 }
3078
Kristian Høgsberga61ca062012-05-22 16:05:52 -04003079 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003080 if (!shsurf) {
3081 wl_resource_post_error(surface_resource,
3082 WL_DISPLAY_ERROR_INVALID_OBJECT,
3083 "surface->configure already set");
3084 return;
3085 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03003086
Jason Ekstranda85118c2013-06-27 20:17:02 -05003087 shsurf->resource =
3088 wl_resource_create(client,
3089 &wl_shell_surface_interface, 1, id);
3090 wl_resource_set_implementation(shsurf->resource,
3091 &shell_surface_implementation,
3092 shsurf, shell_destroy_shell_surface);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003093}
3094
3095static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02003096 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05003097};
3098
Kristian Høgsberg07937562011-04-12 17:25:42 -04003099static void
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02003100shell_fade(struct desktop_shell *shell, enum fade_type type);
3101
3102static int
3103screensaver_timeout(void *data)
3104{
3105 struct desktop_shell *shell = data;
3106
3107 shell_fade(shell, FADE_OUT);
3108
3109 return 1;
3110}
3111
3112static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003113handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02003114{
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003115 struct desktop_shell *shell =
3116 container_of(proc, struct desktop_shell, screensaver.process);
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003117
Pekka Paalanen18027e52011-12-02 16:31:49 +02003118 proc->pid = 0;
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003119
3120 if (shell->locked)
Ander Conselvan de Oliveirab17537e2013-02-22 14:16:18 +02003121 weston_compositor_sleep(shell->compositor);
Pekka Paalanen18027e52011-12-02 16:31:49 +02003122}
3123
3124static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003125launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003126{
3127 if (shell->screensaver.binding)
3128 return;
3129
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003130 if (!shell->screensaver.path) {
3131 weston_compositor_sleep(shell->compositor);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003132 return;
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003133 }
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003134
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003135 if (shell->screensaver.process.pid != 0) {
Martin Minarik6d118362012-06-07 18:01:59 +02003136 weston_log("old screensaver still running\n");
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003137 return;
3138 }
3139
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003140 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003141 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003142 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003143 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003144}
3145
3146static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003147terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003148{
Pekka Paalanen18027e52011-12-02 16:31:49 +02003149 if (shell->screensaver.process.pid == 0)
3150 return;
3151
3152 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003153}
3154
3155static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05003156configure_static_view(struct weston_view *ev, struct weston_layer *layer, int32_t width, int32_t height)
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003157{
Jason Ekstranda7af7042013-10-12 22:38:11 -05003158 struct weston_view *v, *next;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003159
Giulio Camuffo184df502013-02-21 11:29:21 +01003160 if (width == 0)
3161 return;
3162
Jason Ekstranda7af7042013-10-12 22:38:11 -05003163 wl_list_for_each_safe(v, next, &layer->view_list, layer_link) {
3164 if (v->output == ev->output && v != ev) {
3165 weston_view_unmap(v);
3166 v->surface->configure = NULL;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003167 }
3168 }
3169
Jason Ekstranda7af7042013-10-12 22:38:11 -05003170 weston_view_configure(ev, ev->output->x, ev->output->y, width, height);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003171
Jason Ekstranda7af7042013-10-12 22:38:11 -05003172 if (wl_list_empty(&ev->layer_link)) {
3173 wl_list_insert(&layer->view_list, &ev->layer_link);
3174 weston_compositor_schedule_repaint(ev->surface->compositor);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003175 }
3176}
3177
3178static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003179background_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 -04003180{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003181 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003182 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003183
Jason Ekstranda7af7042013-10-12 22:38:11 -05003184 view = container_of(es->views.next, struct weston_view, surface_link);
3185
3186 configure_static_view(view, &shell->background_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003187}
3188
3189static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003190desktop_shell_set_background(struct wl_client *client,
3191 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003192 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003193 struct wl_resource *surface_resource)
3194{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003195 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003196 struct weston_surface *surface =
3197 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003198 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003199
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003200 if (surface->configure) {
3201 wl_resource_post_error(surface_resource,
3202 WL_DISPLAY_ERROR_INVALID_OBJECT,
3203 "surface role already assigned");
3204 return;
3205 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003206
Jason Ekstranda7af7042013-10-12 22:38:11 -05003207 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3208 weston_view_destroy(view);
3209 view = weston_view_create(surface);
3210
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003211 surface->configure = background_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003212 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003213 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003214 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003215 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05003216 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003217 surface->output->width,
3218 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003219}
3220
3221static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003222panel_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 -04003223{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003224 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003225 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003226
Jason Ekstranda7af7042013-10-12 22:38:11 -05003227 view = container_of(es->views.next, struct weston_view, surface_link);
3228
3229 configure_static_view(view, &shell->panel_layer, width, height);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003230}
3231
3232static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003233desktop_shell_set_panel(struct wl_client *client,
3234 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003235 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003236 struct wl_resource *surface_resource)
3237{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003238 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003239 struct weston_surface *surface =
3240 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003241 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003242
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003243 if (surface->configure) {
3244 wl_resource_post_error(surface_resource,
3245 WL_DISPLAY_ERROR_INVALID_OBJECT,
3246 "surface role already assigned");
3247 return;
3248 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003249
Jason Ekstranda7af7042013-10-12 22:38:11 -05003250 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3251 weston_view_destroy(view);
3252 view = weston_view_create(surface);
3253
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003254 surface->configure = panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003255 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003256 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003257 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003258 desktop_shell_send_configure(resource, 0,
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003259 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003260 surface->output->width,
3261 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003262}
3263
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003264static void
Giulio Camuffo184df502013-02-21 11:29:21 +01003265lock_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 -04003266{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003267 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003268 struct weston_view *view;
3269
3270 view = container_of(surface->views.next, struct weston_view, surface_link);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003271
Giulio Camuffo184df502013-02-21 11:29:21 +01003272 if (width == 0)
3273 return;
3274
Jason Ekstranda7af7042013-10-12 22:38:11 -05003275 surface->width = width;
3276 surface->height = height;
3277 view->geometry.width = width;
3278 view->geometry.height = height;
3279 center_on_output(view, get_default_output(shell->compositor));
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003280
3281 if (!weston_surface_is_mapped(surface)) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05003282 wl_list_insert(&shell->lock_layer.view_list,
3283 &view->layer_link);
3284 weston_view_update_transform(view);
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003285 shell_fade(shell, FADE_IN);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003286 }
3287}
3288
3289static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003290handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003291{
Tiago Vignattibe143262012-04-16 17:31:41 +03003292 struct desktop_shell *shell =
3293 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003294
Martin Minarik6d118362012-06-07 18:01:59 +02003295 weston_log("lock surface gone\n");
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003296 shell->lock_surface = NULL;
3297}
3298
3299static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003300desktop_shell_set_lock_surface(struct wl_client *client,
3301 struct wl_resource *resource,
3302 struct wl_resource *surface_resource)
3303{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003304 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003305 struct weston_surface *surface =
3306 wl_resource_get_user_data(surface_resource);
Pekka Paalanen98262232011-12-01 10:42:22 +02003307
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003308 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02003309
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003310 if (!shell->locked)
3311 return;
3312
Pekka Paalanen98262232011-12-01 10:42:22 +02003313 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003314
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003315 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003316 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003317 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02003318
Kristian Høgsbergaa2ee8b2013-10-30 15:49:45 -07003319 weston_view_create(surface);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003320 surface->configure = lock_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003321 surface->configure_private = shell;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003322}
3323
3324static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003325resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003326{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04003327 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003328
Pekka Paalanen77346a62011-11-30 16:26:35 +02003329 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003330
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05003331 wl_list_remove(&shell->lock_layer.link);
3332 wl_list_insert(&shell->compositor->cursor_layer.link,
3333 &shell->fullscreen_layer.link);
3334 wl_list_insert(&shell->fullscreen_layer.link,
3335 &shell->panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003336 if (shell->showing_input_panels) {
3337 wl_list_insert(&shell->panel_layer.link,
3338 &shell->input_panel_layer.link);
3339 wl_list_insert(&shell->input_panel_layer.link,
3340 &ws->layer.link);
3341 } else {
3342 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
3343 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003344
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04003345 restore_focus_state(shell, get_current_workspace(shell));
Jonas Ådahl04769742012-06-13 00:01:24 +02003346
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003347 shell->locked = false;
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003348 shell_fade(shell, FADE_IN);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02003349 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003350}
3351
3352static void
3353desktop_shell_unlock(struct wl_client *client,
3354 struct wl_resource *resource)
3355{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003356 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003357
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003358 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003359
3360 if (shell->locked)
3361 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003362}
3363
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003364static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003365desktop_shell_set_grab_surface(struct wl_client *client,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003366 struct wl_resource *resource,
3367 struct wl_resource *surface_resource)
3368{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003369 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003370
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003371 shell->grab_surface = wl_resource_get_user_data(surface_resource);
Kristian Høgsberg48588f82013-10-24 15:51:35 -07003372 weston_view_create(shell->grab_surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003373}
3374
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003375static void
3376desktop_shell_desktop_ready(struct wl_client *client,
3377 struct wl_resource *resource)
3378{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003379 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003380
3381 shell_fade_startup(shell);
3382}
3383
Kristian Høgsberg75840622011-09-06 13:48:16 -04003384static const struct desktop_shell_interface desktop_shell_implementation = {
3385 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003386 desktop_shell_set_panel,
3387 desktop_shell_set_lock_surface,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003388 desktop_shell_unlock,
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003389 desktop_shell_set_grab_surface,
3390 desktop_shell_desktop_ready
Kristian Høgsberg75840622011-09-06 13:48:16 -04003391};
3392
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003393static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003394get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003395{
3396 struct shell_surface *shsurf;
3397
3398 shsurf = get_shell_surface(surface);
3399 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02003400 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003401 return shsurf->type;
3402}
3403
Kristian Høgsberg75840622011-09-06 13:48:16 -04003404static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003405move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003406{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003407 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003408 struct weston_surface *surface;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003409 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003410
Pekka Paalanen01388e22013-04-25 13:57:44 +03003411 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003412 if (surface == NULL)
3413 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003414
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003415 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003416 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3417 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003418 return;
3419
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003420 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003421}
3422
3423static void
Neil Robertsaba0f252013-10-03 16:43:05 +01003424touch_move_binding(struct weston_seat *seat, uint32_t time, void *data)
3425{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003426 struct weston_surface *focus = seat->touch->focus->surface;
Neil Robertsaba0f252013-10-03 16:43:05 +01003427 struct weston_surface *surface;
3428 struct shell_surface *shsurf;
3429
3430 surface = weston_surface_get_main_surface(focus);
3431 if (surface == NULL)
3432 return;
3433
3434 shsurf = get_shell_surface(surface);
3435 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3436 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3437 return;
3438
3439 surface_touch_move(shsurf, (struct weston_seat *) seat);
3440}
3441
3442static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003443resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003444{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003445 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003446 struct weston_surface *surface;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003447 uint32_t edges = 0;
3448 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003449 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003450
Pekka Paalanen01388e22013-04-25 13:57:44 +03003451 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003452 if (surface == NULL)
3453 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003454
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003455 shsurf = get_shell_surface(surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003456 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3457 shsurf->type == SHELL_SURFACE_MAXIMIZED)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003458 return;
3459
Jason Ekstranda7af7042013-10-12 22:38:11 -05003460 weston_view_from_global(shsurf->view,
3461 wl_fixed_to_int(seat->pointer->grab_x),
3462 wl_fixed_to_int(seat->pointer->grab_y),
3463 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003464
Jason Ekstranda7af7042013-10-12 22:38:11 -05003465 if (x < shsurf->view->geometry.width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003466 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003467 else if (x < 2 * shsurf->view->geometry.width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003468 edges |= 0;
3469 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003470 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003471
Jason Ekstranda7af7042013-10-12 22:38:11 -05003472 if (y < shsurf->view->geometry.height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003473 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003474 else if (y < 2 * shsurf->view->geometry.height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003475 edges |= 0;
3476 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003477 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003478
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04003479 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04003480}
3481
3482static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003483surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003484 wl_fixed_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003485{
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003486 float step = 0.005;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003487 struct shell_surface *shsurf;
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003488 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003489 struct weston_surface *surface;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003490
Pekka Paalanen01388e22013-04-25 13:57:44 +03003491 /* XXX: broken for windows containing sub-surfaces */
3492 surface = weston_surface_get_main_surface(focus);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003493 if (surface == NULL)
3494 return;
3495
3496 shsurf = get_shell_surface(surface);
3497 if (!shsurf)
3498 return;
3499
Jason Ekstranda7af7042013-10-12 22:38:11 -05003500 shsurf->view->alpha -= wl_fixed_to_double(value) * step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003501
Jason Ekstranda7af7042013-10-12 22:38:11 -05003502 if (shsurf->view->alpha > 1.0)
3503 shsurf->view->alpha = 1.0;
3504 if (shsurf->view->alpha < step)
3505 shsurf->view->alpha = step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003506
Jason Ekstranda7af7042013-10-12 22:38:11 -05003507 weston_view_geometry_dirty(shsurf->view);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003508 weston_surface_damage(surface);
3509}
3510
3511static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003512do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003513 wl_fixed_t value)
Scott Moreauccbf29d2012-02-22 14:21:41 -07003514{
Daniel Stone37816df2012-05-16 18:45:18 +01003515 struct weston_seat *ws = (struct weston_seat *) seat;
3516 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003517 struct weston_output *output;
Scott Moreaue6603982012-06-11 13:07:51 -06003518 float increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003519
3520 wl_list_for_each(output, &compositor->output_list, link) {
3521 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01003522 wl_fixed_to_double(seat->pointer->x),
3523 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01003524 NULL)) {
Daniel Stone325fc2d2012-05-30 16:31:58 +01003525 if (key == KEY_PAGEUP)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003526 increment = output->zoom.increment;
Daniel Stone325fc2d2012-05-30 16:31:58 +01003527 else if (key == KEY_PAGEDOWN)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003528 increment = -output->zoom.increment;
3529 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003530 /* For every pixel zoom 20th of a step */
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003531 increment = output->zoom.increment *
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003532 -wl_fixed_to_double(value) / 20.0;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003533 else
3534 increment = 0;
3535
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003536 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07003537
Scott Moreaue6603982012-06-11 13:07:51 -06003538 if (output->zoom.level < 0.0)
Scott Moreau850ca422012-05-21 15:21:25 -06003539 output->zoom.level = 0.0;
Scott Moreaue6603982012-06-11 13:07:51 -06003540 else if (output->zoom.level > output->zoom.max_level)
3541 output->zoom.level = output->zoom.max_level;
Ville Syrjäläaa628d02012-11-16 11:48:47 +02003542 else if (!output->zoom.active) {
Giulio Camuffo412b0242013-11-14 23:42:51 +01003543 weston_output_activate_zoom(output);
Kristian Høgsberg79af73e2012-08-03 15:45:23 -04003544 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07003545
Scott Moreaue6603982012-06-11 13:07:51 -06003546 output->zoom.spring_z.target = output->zoom.level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003547
Jason Ekstranda7af7042013-10-12 22:38:11 -05003548 weston_output_update_zoom(output);
Scott Moreauccbf29d2012-02-22 14:21:41 -07003549 }
3550 }
3551}
3552
Scott Moreauccbf29d2012-02-22 14:21:41 -07003553static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003554zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003555 wl_fixed_t value, void *data)
Daniel Stone325fc2d2012-05-30 16:31:58 +01003556{
3557 do_zoom(seat, time, 0, axis, value);
3558}
3559
3560static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003561zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003562 void *data)
3563{
3564 do_zoom(seat, time, key, 0, 0);
3565}
3566
3567static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003568terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003569 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003570{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003571 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003572
Daniel Stone325fc2d2012-05-30 16:31:58 +01003573 wl_display_terminate(compositor->wl_display);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003574}
3575
3576static void
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01003577lower_fullscreen_layer(struct desktop_shell *shell);
3578
3579struct alt_tab {
3580 struct desktop_shell *shell;
3581 struct weston_keyboard_grab grab;
3582
3583 struct wl_list *current;
3584
3585 struct wl_list preview_list;
3586};
3587
3588struct alt_tab_preview {
3589 struct alt_tab *alt_tab;
3590
3591 struct weston_view *view;
3592 struct weston_transform transform;
3593
3594 struct wl_listener listener;
3595
3596 struct wl_list link;
3597};
3598
3599static void
3600alt_tab_next(struct alt_tab *alt_tab)
3601{
3602 alt_tab->current = alt_tab->current->next;
3603
3604 /* Make sure we're not pointing to the list header e.g. after
3605 * cycling through the whole list. */
3606 if (alt_tab->current->next == alt_tab->preview_list.next)
3607 alt_tab->current = alt_tab->current->next;
3608}
3609
3610static void
3611alt_tab_destroy(struct alt_tab *alt_tab)
3612{
3613 struct alt_tab_preview *preview, *next;
3614 struct weston_keyboard *keyboard = alt_tab->grab.keyboard;
3615
3616 if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) {
3617 preview = wl_container_of(alt_tab->current, preview, link);
3618
3619 activate(alt_tab->shell, preview->view->surface,
3620 (struct weston_seat *) keyboard->seat);
3621 }
3622
3623 wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) {
3624 wl_list_remove(&preview->link);
3625 wl_list_remove(&preview->listener.link);
3626 weston_view_destroy(preview->view);
3627 free(preview);
3628 }
3629
3630 weston_keyboard_end_grab(keyboard);
3631 if (keyboard->input_method_resource)
3632 keyboard->grab = &keyboard->input_method_grab;
3633
3634 free(alt_tab);
3635}
3636
3637static void
3638alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data)
3639{
3640 struct alt_tab_preview *preview =
3641 container_of(listener, struct alt_tab_preview, listener);
3642 struct alt_tab *alt_tab = preview->alt_tab;
3643 int advance = 0;
3644
3645 /* If the preview that we're removing is the currently selected one,
3646 * we want to move to the next one. So we move to ->prev and then
3647 * call _next() after removing the preview. */
3648 if (alt_tab->current == &preview->link) {
3649 alt_tab->current = alt_tab->current->prev;
3650 advance = 1;
3651 }
3652
3653 wl_list_remove(&preview->listener.link);
3654 wl_list_remove(&preview->link);
3655
3656 free(preview);
3657
3658 if (advance)
3659 alt_tab_next(alt_tab);
3660
3661 /* If the last preview goes away, stop the alt-tab */
3662 if (wl_list_empty(alt_tab->current))
3663 alt_tab_destroy(alt_tab);
3664}
3665
3666static void
3667alt_tab_key(struct weston_keyboard_grab *grab,
3668 uint32_t time, uint32_t key, uint32_t state_w)
3669{
3670 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3671 enum wl_keyboard_key_state state = state_w;
3672
3673 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3674 alt_tab_next(alt_tab);
3675}
3676
3677static void
3678alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
3679 uint32_t mods_depressed, uint32_t mods_latched,
3680 uint32_t mods_locked, uint32_t group)
3681{
3682 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3683 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3684
3685 if ((seat->modifier_state & MODIFIER_ALT) == 0)
3686 alt_tab_destroy(alt_tab);
3687}
3688
3689static void
3690alt_tab_cancel(struct weston_keyboard_grab *grab)
3691{
3692 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3693
3694 alt_tab_destroy(alt_tab);
3695}
3696
3697static const struct weston_keyboard_grab_interface alt_tab_grab = {
3698 alt_tab_key,
3699 alt_tab_modifier,
3700 alt_tab_cancel,
3701};
3702
3703static int
3704view_for_alt_tab(struct weston_view *view)
3705{
3706 if (!get_shell_surface(view->surface))
3707 return 0;
3708
3709 if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT)
3710 return 0;
3711
3712 if (view != get_default_view(view->surface))
3713 return 0;
3714
3715 return 1;
3716}
3717
3718static void
3719alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3720 void *data)
3721{
3722 struct alt_tab *alt_tab;
3723 struct desktop_shell *shell = data;
3724 struct weston_output *output = get_default_output(shell->compositor);
3725 struct workspace *ws;
3726 struct weston_view *view;
3727 int num_surfaces = 0;
3728 int x, y, side, margin;
3729
3730 wl_list_for_each(view, &shell->compositor->view_list, link) {
3731
3732 if (view_for_alt_tab(view))
3733 num_surfaces++;
3734 }
3735
3736 if (!num_surfaces)
3737 return;
3738
3739 alt_tab = malloc(sizeof *alt_tab);
3740 if (!alt_tab)
3741 return;
3742
3743 alt_tab->shell = shell;
3744 wl_list_init(&alt_tab->preview_list);
3745 alt_tab->current = &alt_tab->preview_list;
3746
3747 restore_all_output_modes(shell->compositor);
3748 lower_fullscreen_layer(alt_tab->shell);
3749
3750 alt_tab->grab.interface = &alt_tab_grab;
3751 weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab);
3752 weston_keyboard_set_focus(seat->keyboard, NULL);
3753
3754 ws = get_current_workspace(shell);
3755
3756 /* FIXME: add some visual candy e.g. prelight the selected view
3757 * and/or add a black surrounding background à la gnome-shell */
3758
3759 /* Determine the size for each preview */
3760 side = output->width / num_surfaces;
3761 if (side > 200)
3762 side = 200;
3763 margin = side / 4;
3764 side -= margin;
3765
3766 x = margin;
3767 y = (output->height - side) / 2;
3768
3769 /* Create a view for each surface */
3770 wl_list_for_each(view, &shell->compositor->view_list, link) {
3771 struct alt_tab_preview *preview;
3772 struct weston_view *v;
3773 float scale;
3774
3775 if (!view_for_alt_tab(view))
3776 continue;
3777
3778 preview = malloc(sizeof *preview);
3779 if (!preview) {
3780 alt_tab_destroy(alt_tab);
3781 return;
3782 }
3783
3784 preview->alt_tab = alt_tab;
3785
3786 preview->view = v = weston_view_create(view->surface);
3787 v->output = view->output;
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003788
3789 wl_list_remove(&v->layer_link);
3790 wl_list_insert(&ws->layer.view_list, &v->layer_link);
3791 weston_view_damage_below(v);
3792 weston_surface_damage(v->surface);
3793
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01003794 weston_view_configure(v, x, y, view->geometry.width, view->geometry.height);
3795
3796 preview->listener.notify = alt_tab_handle_surface_destroy;
3797 wl_signal_add(&v->destroy_signal, &preview->listener);
3798
3799 if (view->geometry.width > view->geometry.height)
3800 scale = side / (float) view->geometry.width;
3801 else
3802 scale = side / (float) view->geometry.height;
3803
3804 wl_list_insert(&v->geometry.transformation_list,
3805 &preview->transform.link);
3806 weston_matrix_init(&preview->transform.matrix);
3807 weston_matrix_scale(&preview->transform.matrix,
3808 scale, scale, 1.0f);
3809
3810 weston_view_geometry_dirty(v);
3811 weston_compositor_schedule_repaint(v->surface->compositor);
3812
3813 /* Insert at the end of the list */
3814 wl_list_insert(alt_tab->preview_list.prev, &preview->link);
3815
3816 x += side + margin;
3817 }
3818
3819 /* Start at the second preview so a simple <alt>tab changes window.
3820 * We set `current' to the first preview and not the second because
3821 * we're going to receive a key press callback for the initial
3822 * <alt>tab which will make `current' point to the second element. */
3823 alt_tab_next(alt_tab);
3824}
3825
3826static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01003827rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
3828 wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003829{
3830 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003831 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003832 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003833 struct shell_surface *shsurf = rotate->base.shsurf;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003834 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003835
Giulio Camuffo1959ab82013-11-14 23:42:52 +01003836 weston_pointer_move(pointer, x, y);
3837
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003838 if (!shsurf)
3839 return;
3840
Jason Ekstranda7af7042013-10-12 22:38:11 -05003841 cx = 0.5f * shsurf->view->geometry.width;
3842 cy = 0.5f * shsurf->view->geometry.height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003843
Daniel Stone37816df2012-05-16 18:45:18 +01003844 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
3845 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003846 r = sqrtf(dx * dx + dy * dy);
3847
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003848 wl_list_remove(&shsurf->rotation.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003849 weston_view_geometry_dirty(shsurf->view);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003850
3851 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02003852 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003853 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003854
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003855 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003856 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003857
3858 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02003859 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003860 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003861 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02003862 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003863
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02003864 wl_list_insert(
Jason Ekstranda7af7042013-10-12 22:38:11 -05003865 &shsurf->view->geometry.transformation_list,
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003866 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003867 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003868 wl_list_init(&shsurf->rotation.transform.link);
3869 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003870 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003871 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02003872
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003873 /* We need to adjust the position of the surface
3874 * in case it was resized in a rotated state before */
Jason Ekstranda7af7042013-10-12 22:38:11 -05003875 cposx = shsurf->view->geometry.x + cx;
3876 cposy = shsurf->view->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003877 dposx = rotate->center.x - cposx;
3878 dposy = rotate->center.y - cposy;
3879 if (dposx != 0.0f || dposy != 0.0f) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05003880 weston_view_set_position(shsurf->view,
3881 shsurf->view->geometry.x + dposx,
3882 shsurf->view->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003883 }
3884
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02003885 /* Repaint implies weston_surface_update_transform(), which
3886 * lazily applies the damage due to rotation update.
3887 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003888 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003889}
3890
3891static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003892rotate_grab_button(struct weston_pointer_grab *grab,
3893 uint32_t time, uint32_t button, uint32_t state_w)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003894{
3895 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003896 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003897 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003898 struct shell_surface *shsurf = rotate->base.shsurf;
Daniel Stone4dbadb12012-05-30 16:31:51 +01003899 enum wl_pointer_button_state state = state_w;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003900
Daniel Stone4dbadb12012-05-30 16:31:51 +01003901 if (pointer->button_count == 0 &&
3902 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03003903 if (shsurf)
3904 weston_matrix_multiply(&shsurf->rotation.rotation,
3905 &rotate->rotation);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003906 shell_grab_end(&rotate->base);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003907 free(rotate);
3908 }
3909}
3910
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02003911static void
3912rotate_grab_cancel(struct weston_pointer_grab *grab)
3913{
3914 struct rotate_grab *rotate =
3915 container_of(grab, struct rotate_grab, base.grab);
3916
3917 shell_grab_end(&rotate->base);
3918 free(rotate);
3919}
3920
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04003921static const struct weston_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02003922 noop_grab_focus,
3923 rotate_grab_motion,
3924 rotate_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02003925 rotate_grab_cancel,
Pekka Paalanen460099f2012-01-20 16:48:25 +02003926};
3927
3928static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003929surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
Pekka Paalanen460099f2012-01-20 16:48:25 +02003930{
Pekka Paalanen460099f2012-01-20 16:48:25 +02003931 struct rotate_grab *rotate;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02003932 float dx, dy;
3933 float r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02003934
Pekka Paalanen460099f2012-01-20 16:48:25 +02003935 rotate = malloc(sizeof *rotate);
3936 if (!rotate)
3937 return;
3938
Jason Ekstranda7af7042013-10-12 22:38:11 -05003939 weston_view_to_global_float(surface->view,
3940 surface->view->geometry.width * 0.5f,
3941 surface->view->geometry.height * 0.5f,
3942 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003943
Daniel Stone37816df2012-05-16 18:45:18 +01003944 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
3945 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003946 r = sqrtf(dx * dx + dy * dy);
3947 if (r > 20.0f) {
3948 struct weston_matrix inverse;
3949
3950 weston_matrix_init(&inverse);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003951 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003952 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01003953
3954 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03003955 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05003956 } else {
3957 weston_matrix_init(&surface->rotation.rotation);
3958 weston_matrix_init(&rotate->rotation);
3959 }
3960
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003961 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
3962 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
Pekka Paalanen460099f2012-01-20 16:48:25 +02003963}
3964
3965static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003966rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003967 void *data)
3968{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003969 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003970 struct weston_surface *base_surface;
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003971 struct shell_surface *surface;
3972
Pekka Paalanen01388e22013-04-25 13:57:44 +03003973 base_surface = weston_surface_get_main_surface(focus);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003974 if (base_surface == NULL)
3975 return;
3976
3977 surface = get_shell_surface(base_surface);
Rafal Mielniczuk23c67592013-03-11 19:26:53 +01003978 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
3979 surface->type == SHELL_SURFACE_MAXIMIZED)
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003980 return;
3981
3982 surface_rotate(surface, seat);
3983}
3984
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003985/* Move all fullscreen layers down to the current workspace in a non-reversible
3986 * manner. This should be used when implementing shell-wide overlays, such as
3987 * the alt-tab switcher, which need to de-promote fullscreen layers. */
Kristian Høgsberg0c369032013-02-14 21:31:44 -05003988static void
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003989lower_fullscreen_layer(struct desktop_shell *shell)
3990{
3991 struct workspace *ws;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003992 struct weston_view *view, *prev;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04003993
3994 ws = get_current_workspace(shell);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003995 wl_list_for_each_reverse_safe(view, prev,
3996 &shell->fullscreen_layer.view_list,
Philip Withnall83ffd9d2013-11-25 18:01:42 +00003997 layer_link) {
3998 wl_list_remove(&view->layer_link);
3999 wl_list_insert(&ws->layer.view_list, &view->layer_link);
4000 weston_view_damage_below(view);
4001 weston_surface_damage(view->surface);
4002 }
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04004003}
4004
4005static void
Tiago Vignattibe143262012-04-16 17:31:41 +03004006activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01004007 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04004008{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004009 struct weston_surface *main_surface;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004010 struct focus_state *state;
Jonas Ådahl8538b222012-08-29 22:13:03 +02004011 struct workspace *ws;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004012 struct weston_surface *old_es;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004013
Pekka Paalanen01388e22013-04-25 13:57:44 +03004014 main_surface = weston_surface_get_main_surface(es);
4015
Daniel Stone37816df2012-05-16 18:45:18 +01004016 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004017
Jonas Ådahl8538b222012-08-29 22:13:03 +02004018 state = ensure_focus_state(shell, seat);
4019 if (state == NULL)
4020 return;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004021
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004022 old_es = state->keyboard_focus;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004023 state->keyboard_focus = es;
4024 wl_list_remove(&state->surface_destroy_listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05004025 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004026
Pekka Paalanen01388e22013-04-25 13:57:44 +03004027 switch (get_shell_surface_type(main_surface)) {
Alex Wu4539b082012-03-01 12:57:46 +08004028 case SHELL_SURFACE_FULLSCREEN:
4029 /* should on top of panels */
Pekka Paalanen01388e22013-04-25 13:57:44 +03004030 shell_configure_fullscreen(get_shell_surface(main_surface));
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004031 return;
Philip Withnall0f640e22013-11-25 18:01:31 +00004032 case SHELL_SURFACE_TOPLEVEL:
4033 case SHELL_SURFACE_TRANSIENT:
4034 case SHELL_SURFACE_MAXIMIZED:
4035 case SHELL_SURFACE_POPUP:
4036 case SHELL_SURFACE_XWAYLAND:
4037 case SHELL_SURFACE_NONE:
Pekka Paalanen57da4a82011-11-23 16:42:16 +02004038 default:
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02004039 restore_all_output_modes(shell->compositor);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004040 break;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004041 }
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004042
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004043 if (shell->focus_animation_type != ANIMATION_NONE) {
4044 ws = get_current_workspace(shell);
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004045 animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es));
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004046 }
4047
4048 /* Update the surface’s layer. This brings it to the top of the stacking
4049 * order as appropriate. */
4050 shell_surface_update_layer(get_shell_surface(main_surface));
Kristian Høgsberg75840622011-09-06 13:48:16 -04004051}
4052
Alex Wu21858432012-04-01 20:13:08 +08004053/* no-op func for checking black surface */
4054static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004055black_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 +08004056{
4057}
4058
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01004059static bool
Alex Wu21858432012-04-01 20:13:08 +08004060is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
4061{
4062 if (es->configure == black_surface_configure) {
4063 if (fs_surface)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004064 *fs_surface = (struct weston_surface *)es->configure_private;
Alex Wu21858432012-04-01 20:13:08 +08004065 return true;
4066 }
4067 return false;
4068}
4069
Kristian Høgsberg75840622011-09-06 13:48:16 -04004070static void
Neil Robertsa28c6932013-10-03 16:43:04 +01004071activate_binding(struct weston_seat *seat,
4072 struct desktop_shell *shell,
4073 struct weston_surface *focus)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004074{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004075 struct weston_surface *main_surface;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004076
Alex Wu9c35e6b2012-03-05 14:13:13 +08004077 if (!focus)
4078 return;
4079
Pekka Paalanen01388e22013-04-25 13:57:44 +03004080 if (is_black_surface(focus, &main_surface))
4081 focus = main_surface;
Alex Wu4539b082012-03-01 12:57:46 +08004082
Pekka Paalanen01388e22013-04-25 13:57:44 +03004083 main_surface = weston_surface_get_main_surface(focus);
4084 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004085 return;
Kristian Høgsberg85b2e4b2012-06-21 16:49:42 -04004086
Neil Robertsa28c6932013-10-03 16:43:04 +01004087 activate(shell, focus, seat);
4088}
4089
4090static void
4091click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
4092 void *data)
4093{
4094 if (seat->pointer->grab != &seat->pointer->default_grab)
4095 return;
4096
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004097 activate_binding(seat, data, seat->pointer->focus->surface);
Neil Robertsa28c6932013-10-03 16:43:04 +01004098}
4099
4100static void
4101touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
4102{
4103 if (seat->touch->grab != &seat->touch->default_grab)
4104 return;
4105
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004106 activate_binding(seat, data, seat->touch->focus->surface);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004107}
4108
4109static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004110lock(struct desktop_shell *shell)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004111{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004112 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004113
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004114 if (shell->locked) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004115 weston_compositor_sleep(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004116 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004117 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004118
4119 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004120
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004121 /* Hide all surfaces by removing the fullscreen, panel and
4122 * toplevel layers. This way nothing else can show or receive
4123 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004124
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004125 wl_list_remove(&shell->panel_layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004126 wl_list_remove(&shell->fullscreen_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004127 if (shell->showing_input_panels)
4128 wl_list_remove(&shell->input_panel_layer.link);
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004129 wl_list_remove(&ws->layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004130 wl_list_insert(&shell->compositor->cursor_layer.link,
4131 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004132
Pekka Paalanen77346a62011-11-30 16:26:35 +02004133 launch_screensaver(shell);
4134
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004135 /* TODO: disable bindings that should not work while locked. */
4136
4137 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004138}
4139
4140static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004141unlock(struct desktop_shell *shell)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004142{
Pekka Paalanend81c2162011-11-16 13:47:34 +02004143 if (!shell->locked || shell->lock_surface) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004144 shell_fade(shell, FADE_IN);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004145 return;
4146 }
4147
4148 /* If desktop-shell client has gone away, unlock immediately. */
4149 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004150 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004151 return;
4152 }
4153
4154 if (shell->prepare_event_sent)
4155 return;
4156
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05004157 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004158 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004159}
4160
4161static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004162shell_fade_done(struct weston_view_animation *animation, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004163{
4164 struct desktop_shell *shell = data;
4165
4166 shell->fade.animation = NULL;
4167
4168 switch (shell->fade.type) {
4169 case FADE_IN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004170 weston_surface_destroy(shell->fade.view->surface);
4171 shell->fade.view = NULL;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004172 break;
4173 case FADE_OUT:
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004174 lock(shell);
4175 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004176 default:
4177 break;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004178 }
4179}
4180
Jason Ekstranda7af7042013-10-12 22:38:11 -05004181static struct weston_view *
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004182shell_fade_create_surface(struct desktop_shell *shell)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004183{
4184 struct weston_compositor *compositor = shell->compositor;
4185 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004186 struct weston_view *view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004187
4188 surface = weston_surface_create(compositor);
4189 if (!surface)
4190 return NULL;
4191
Jason Ekstranda7af7042013-10-12 22:38:11 -05004192 view = weston_view_create(surface);
4193 if (!view) {
4194 weston_surface_destroy(surface);
4195 return NULL;
4196 }
4197
4198 weston_view_configure(view, 0, 0, 8192, 8192);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004199 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004200 wl_list_insert(&compositor->fade_layer.view_list,
4201 &view->layer_link);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004202 pixman_region32_init(&surface->input);
4203
Jason Ekstranda7af7042013-10-12 22:38:11 -05004204 return view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004205}
4206
4207static void
4208shell_fade(struct desktop_shell *shell, enum fade_type type)
4209{
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004210 float tint;
4211
4212 switch (type) {
4213 case FADE_IN:
4214 tint = 0.0;
4215 break;
4216 case FADE_OUT:
4217 tint = 1.0;
4218 break;
4219 default:
4220 weston_log("shell: invalid fade type\n");
4221 return;
4222 }
4223
4224 shell->fade.type = type;
4225
Jason Ekstranda7af7042013-10-12 22:38:11 -05004226 if (shell->fade.view == NULL) {
4227 shell->fade.view = shell_fade_create_surface(shell);
4228 if (!shell->fade.view)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004229 return;
4230
Jason Ekstranda7af7042013-10-12 22:38:11 -05004231 shell->fade.view->alpha = 1.0 - tint;
4232 weston_view_update_transform(shell->fade.view);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004233 }
4234
4235 if (shell->fade.animation)
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004236 weston_fade_update(shell->fade.animation, tint);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004237 else
4238 shell->fade.animation =
Jason Ekstranda7af7042013-10-12 22:38:11 -05004239 weston_fade_run(shell->fade.view,
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004240 1.0 - tint, tint, 300.0,
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004241 shell_fade_done, shell);
4242}
4243
4244static void
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004245do_shell_fade_startup(void *data)
4246{
4247 struct desktop_shell *shell = data;
4248
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004249 if (shell->startup_animation_type == ANIMATION_FADE)
4250 shell_fade(shell, FADE_IN);
4251 else if (shell->startup_animation_type == ANIMATION_NONE) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004252 weston_surface_destroy(shell->fade.view->surface);
4253 shell->fade.view = NULL;
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004254 }
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004255}
4256
4257static void
4258shell_fade_startup(struct desktop_shell *shell)
4259{
4260 struct wl_event_loop *loop;
4261
4262 if (!shell->fade.startup_timer)
4263 return;
4264
4265 wl_event_source_remove(shell->fade.startup_timer);
4266 shell->fade.startup_timer = NULL;
4267
4268 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4269 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
4270}
4271
4272static int
4273fade_startup_timeout(void *data)
4274{
4275 struct desktop_shell *shell = data;
4276
4277 shell_fade_startup(shell);
4278 return 0;
4279}
4280
4281static void
4282shell_fade_init(struct desktop_shell *shell)
4283{
4284 /* Make compositor output all black, and wait for the desktop-shell
4285 * client to signal it is ready, then fade in. The timer triggers a
4286 * fade-in, in case the desktop-shell client takes too long.
4287 */
4288
4289 struct wl_event_loop *loop;
4290
Jason Ekstranda7af7042013-10-12 22:38:11 -05004291 if (shell->fade.view != NULL) {
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004292 weston_log("%s: warning: fade surface already exists\n",
4293 __func__);
4294 return;
4295 }
4296
Jason Ekstranda7af7042013-10-12 22:38:11 -05004297 shell->fade.view = shell_fade_create_surface(shell);
4298 if (!shell->fade.view)
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004299 return;
4300
Jason Ekstranda7af7042013-10-12 22:38:11 -05004301 weston_view_update_transform(shell->fade.view);
4302 weston_surface_damage(shell->fade.view->surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004303
4304 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4305 shell->fade.startup_timer =
4306 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
4307 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
4308}
4309
4310static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004311idle_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004312{
4313 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004314 container_of(listener, struct desktop_shell, idle_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004315
4316 shell_fade(shell, FADE_OUT);
4317 /* lock() is called from shell_fade_done() */
4318}
4319
4320static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004321wake_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004322{
4323 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004324 container_of(listener, struct desktop_shell, wake_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004325
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004326 unlock(shell);
4327}
4328
4329static void
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004330show_input_panels(struct wl_listener *listener, void *data)
4331{
4332 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004333 container_of(listener, struct desktop_shell,
4334 show_input_panel_listener);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004335 struct input_panel_surface *ipsurf, *next;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004336
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004337 shell->text_input.surface = (struct weston_surface*)data;
4338
Jan Arne Petersen451a9712013-02-11 15:10:11 +01004339 if (shell->showing_input_panels)
4340 return;
4341
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004342 shell->showing_input_panels = true;
4343
Jan Arne Petersencf18a322012-11-07 15:32:54 +01004344 if (!shell->locked)
4345 wl_list_insert(&shell->panel_layer.link,
4346 &shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004347
Jason Ekstranda7af7042013-10-12 22:38:11 -05004348 wl_list_for_each_safe(ipsurf, next,
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004349 &shell->input_panel.surfaces, link) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004350 if (!ipsurf->surface->buffer_ref.buffer)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004351 continue;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004352 wl_list_insert(&shell->input_panel_layer.view_list,
4353 &ipsurf->view->layer_link);
4354 weston_view_geometry_dirty(ipsurf->view);
4355 weston_view_update_transform(ipsurf->view);
4356 weston_surface_damage(ipsurf->surface);
4357 weston_slide_run(ipsurf->view, ipsurf->view->geometry.height,
4358 0, NULL, NULL);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004359 }
4360}
4361
4362static void
4363hide_input_panels(struct wl_listener *listener, void *data)
4364{
4365 struct desktop_shell *shell =
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004366 container_of(listener, struct desktop_shell,
4367 hide_input_panel_listener);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004368 struct weston_view *view, *next;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004369
Jan Arne Petersen61381972013-01-31 15:52:21 +01004370 if (!shell->showing_input_panels)
4371 return;
4372
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004373 shell->showing_input_panels = false;
4374
Jan Arne Petersen82ec9092012-12-03 15:36:02 +01004375 if (!shell->locked)
4376 wl_list_remove(&shell->input_panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004377
Jason Ekstranda7af7042013-10-12 22:38:11 -05004378 wl_list_for_each_safe(view, next,
4379 &shell->input_panel_layer.view_list, layer_link)
4380 weston_view_unmap(view);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004381}
4382
4383static void
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004384update_input_panels(struct wl_listener *listener, void *data)
4385{
4386 struct desktop_shell *shell =
4387 container_of(listener, struct desktop_shell,
4388 update_input_panel_listener);
4389
4390 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
4391}
4392
4393static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004394center_on_output(struct weston_view *view, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02004395{
Giulio Camuffob8366642013-04-25 13:57:46 +03004396 int32_t surf_x, surf_y, width, height;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004397 float x, y;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004398
Jason Ekstranda7af7042013-10-12 22:38:11 -05004399 surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height);
Giulio Camuffob8366642013-04-25 13:57:46 +03004400
4401 x = output->x + (output->width - width) / 2 - surf_x / 2;
4402 y = output->y + (output->height - height) / 2 - surf_y / 2;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004403
Jason Ekstranda7af7042013-10-12 22:38:11 -05004404 weston_view_configure(view, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004405}
4406
4407static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004408weston_view_set_initial_position(struct weston_view *view,
4409 struct desktop_shell *shell)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004410{
4411 struct weston_compositor *compositor = shell->compositor;
4412 int ix = 0, iy = 0;
4413 int range_x, range_y;
4414 int dx, dy, x, y, panel_height;
4415 struct weston_output *output, *target_output = NULL;
4416 struct weston_seat *seat;
4417
4418 /* As a heuristic place the new window on the same output as the
4419 * pointer. Falling back to the output containing 0, 0.
4420 *
4421 * TODO: Do something clever for touch too?
4422 */
4423 wl_list_for_each(seat, &compositor->seat_list, link) {
Kristian Høgsberg2bf87622013-05-07 23:17:41 -04004424 if (seat->pointer) {
Kristian Høgsberge3148752013-05-06 23:19:49 -04004425 ix = wl_fixed_to_int(seat->pointer->x);
4426 iy = wl_fixed_to_int(seat->pointer->y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004427 break;
4428 }
4429 }
4430
4431 wl_list_for_each(output, &compositor->output_list, link) {
4432 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
4433 target_output = output;
4434 break;
4435 }
4436 }
4437
4438 if (!target_output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004439 weston_view_set_position(view, 10 + random() % 400,
4440 10 + random() % 400);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004441 return;
4442 }
4443
4444 /* Valid range within output where the surface will still be onscreen.
4445 * If this is negative it means that the surface is bigger than
4446 * output.
4447 */
4448 panel_height = get_output_panel_height(shell, target_output);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004449 range_x = target_output->width - view->geometry.width;
Scott Moreau1bad5db2012-08-18 01:04:05 -06004450 range_y = (target_output->height - panel_height) -
Jason Ekstranda7af7042013-10-12 22:38:11 -05004451 view->geometry.height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004452
Rob Bradford4cb88c72012-08-13 15:18:44 +01004453 if (range_x > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004454 dx = random() % range_x;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004455 else
Rob Bradford4cb88c72012-08-13 15:18:44 +01004456 dx = 0;
4457
4458 if (range_y > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004459 dy = panel_height + random() % range_y;
Rob Bradford4cb88c72012-08-13 15:18:44 +01004460 else
4461 dy = panel_height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004462
4463 x = target_output->x + dx;
4464 y = target_output->y + dy;
4465
Jason Ekstranda7af7042013-10-12 22:38:11 -05004466 weston_view_set_position(view, x, y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004467}
4468
4469static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004470map(struct desktop_shell *shell, struct shell_surface *shsurf,
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02004471 int32_t width, int32_t height, int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004472{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004473 struct weston_compositor *compositor = shell->compositor;
Daniel Stoneb2104682012-05-30 16:31:56 +01004474 struct weston_seat *seat;
Juan Zhao96879df2012-02-07 08:45:41 +08004475 int panel_height = 0;
Giulio Camuffob8366642013-04-25 13:57:46 +03004476 int32_t surf_x, surf_y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02004477
Jason Ekstranda7af7042013-10-12 22:38:11 -05004478 shsurf->view->geometry.width = width;
4479 shsurf->view->geometry.height = height;
4480 weston_view_geometry_dirty(shsurf->view);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004481
4482 /* initial positioning, see also configure() */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004483 switch (shsurf->type) {
Pekka Paalanen77346a62011-11-30 16:26:35 +02004484 case SHELL_SURFACE_TOPLEVEL:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004485 weston_view_set_initial_position(shsurf->view, shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004486 break;
Alex Wu4539b082012-03-01 12:57:46 +08004487 case SHELL_SURFACE_FULLSCREEN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004488 center_on_output(shsurf->view, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08004489 shell_map_fullscreen(shsurf);
4490 break;
Juan Zhao96879df2012-02-07 08:45:41 +08004491 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08004492 /* use surface configure to set the geometry */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004493 panel_height = get_output_panel_height(shell, shsurf->output);
4494 surface_subsurfaces_boundingbox(shsurf->surface,
4495 &surf_x, &surf_y, NULL, NULL);
4496 weston_view_set_position(shsurf->view,
4497 shsurf->output->x - surf_x,
4498 shsurf->output->y + panel_height - surf_y);
Juan Zhao96879df2012-02-07 08:45:41 +08004499 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02004500 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04004501 shell_map_popup(shsurf);
Rob Bradforddb999382012-12-06 12:07:48 +00004502 break;
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02004503 case SHELL_SURFACE_NONE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004504 weston_view_set_position(shsurf->view,
4505 shsurf->view->geometry.x + sx,
4506 shsurf->view->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02004507 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004508 case SHELL_SURFACE_TRANSIENT:
4509 case SHELL_SURFACE_XWAYLAND:
Pekka Paalanen77346a62011-11-30 16:26:35 +02004510 default:
4511 ;
4512 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04004513
Philip Withnalle1d75ae2013-11-25 18:01:41 +00004514 /* Surface stacking order, see also activate(). */
4515 shell_surface_update_layer(shsurf);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004516
Jason Ekstranda7af7042013-10-12 22:38:11 -05004517 if (shsurf->type != SHELL_SURFACE_NONE) {
4518 weston_view_update_transform(shsurf->view);
4519 if (shsurf->type == SHELL_SURFACE_MAXIMIZED) {
4520 shsurf->surface->output = shsurf->output;
4521 shsurf->view->output = shsurf->output;
4522 }
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02004523 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05004524
Jason Ekstranda7af7042013-10-12 22:38:11 -05004525 switch (shsurf->type) {
Tiago Vignattifb2adba2013-06-12 15:43:21 -03004526 /* XXX: xwayland's using the same fields for transient type */
4527 case SHELL_SURFACE_XWAYLAND:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004528 case SHELL_SURFACE_TRANSIENT:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03004529 if (shsurf->transient.flags ==
4530 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
4531 break;
4532 case SHELL_SURFACE_TOPLEVEL:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004533 case SHELL_SURFACE_FULLSCREEN:
Juan Zhao96879df2012-02-07 08:45:41 +08004534 case SHELL_SURFACE_MAXIMIZED:
Daniel Stoneb2104682012-05-30 16:31:56 +01004535 if (!shell->locked) {
4536 wl_list_for_each(seat, &compositor->seat_list, link)
Jason Ekstranda7af7042013-10-12 22:38:11 -05004537 activate(shell, shsurf->surface, seat);
Daniel Stoneb2104682012-05-30 16:31:56 +01004538 }
Juan Zhao7bb92f02011-12-15 11:31:51 -05004539 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004540 case SHELL_SURFACE_POPUP:
4541 case SHELL_SURFACE_NONE:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004542 default:
4543 break;
4544 }
4545
Jason Ekstranda7af7042013-10-12 22:38:11 -05004546 if (shsurf->type == SHELL_SURFACE_TOPLEVEL)
Juan Zhaoe10d2792012-04-25 19:09:52 +08004547 {
4548 switch (shell->win_animation_type) {
4549 case ANIMATION_FADE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004550 weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004551 break;
4552 case ANIMATION_ZOOM:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004553 weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004554 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004555 case ANIMATION_NONE:
Juan Zhaoe10d2792012-04-25 19:09:52 +08004556 default:
4557 break;
4558 }
4559 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004560}
4561
4562static void
Tiago Vignattibe143262012-04-16 17:31:41 +03004563configure(struct desktop_shell *shell, struct weston_surface *surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004564 float x, float y, int32_t width, int32_t height)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004565{
Pekka Paalanen77346a62011-11-30 16:26:35 +02004566 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
4567 struct shell_surface *shsurf;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004568 struct weston_view *view;
Giulio Camuffob8366642013-04-25 13:57:46 +03004569 int32_t surf_x, surf_y;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004570
Pekka Paalanen77346a62011-11-30 16:26:35 +02004571 shsurf = get_shell_surface(surface);
4572 if (shsurf)
4573 surface_type = shsurf->type;
4574
Jason Ekstranda7af7042013-10-12 22:38:11 -05004575 /* TODO:
4576 * This should probably be changed to be more shell_surface
4577 * dependent
4578 */
4579 wl_list_for_each(view, &surface->views, surface_link)
4580 weston_view_configure(view, x, y, width, height);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004581
4582 switch (surface_type) {
Alex Wu4539b082012-03-01 12:57:46 +08004583 case SHELL_SURFACE_FULLSCREEN:
4584 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08004585 break;
Juan Zhao96879df2012-02-07 08:45:41 +08004586 case SHELL_SURFACE_MAXIMIZED:
Alex Wu4539b082012-03-01 12:57:46 +08004587 /* setting x, y and using configure to change that geometry */
Giulio Camuffob8366642013-04-25 13:57:46 +03004588 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
4589 NULL, NULL);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004590 shsurf->view->geometry.x = shsurf->output->x - surf_x;
4591 shsurf->view->geometry.y = shsurf->output->y +
4592 get_output_panel_height(shell,shsurf->output) - surf_y;
Juan Zhao96879df2012-02-07 08:45:41 +08004593 break;
Alex Wu4539b082012-03-01 12:57:46 +08004594 case SHELL_SURFACE_TOPLEVEL:
Philip Withnall0f640e22013-11-25 18:01:31 +00004595 case SHELL_SURFACE_TRANSIENT:
4596 case SHELL_SURFACE_POPUP:
4597 case SHELL_SURFACE_XWAYLAND:
4598 case SHELL_SURFACE_NONE:
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05004599 default:
4600 break;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04004601 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004602
Alex Wu4539b082012-03-01 12:57:46 +08004603 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05004604 if (surface->output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004605 wl_list_for_each(view, &surface->views, surface_link)
4606 weston_view_update_transform(view);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004607
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004608 if (surface_type == SHELL_SURFACE_MAXIMIZED)
Juan Zhao96879df2012-02-07 08:45:41 +08004609 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004610 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04004611}
4612
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004613static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004614shell_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 +03004615{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03004616 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03004617 struct desktop_shell *shell = shsurf->shell;
Giulio Camuffo184df502013-02-21 11:29:21 +01004618
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03004619 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004620
Kristian Høgsberg8eb0f4f2013-06-17 10:33:14 -04004621 if (!weston_surface_is_mapped(es) &&
4622 !wl_list_empty(&shsurf->popup.grab_link)) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01004623 remove_popup_grab(shsurf);
4624 }
4625
Giulio Camuffo184df502013-02-21 11:29:21 +01004626 if (width == 0)
4627 return;
4628
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004629 if (shsurf->next_type != SHELL_SURFACE_NONE &&
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004630 shsurf->type != shsurf->next_type) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004631 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004632 type_changed = 1;
4633 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004634
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004635 if (!weston_surface_is_mapped(es)) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004636 map(shell, shsurf, width, height, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004637 } else if (type_changed || sx != 0 || sy != 0 ||
Jason Ekstranda7af7042013-10-12 22:38:11 -05004638 shsurf->view->geometry.width != width ||
4639 shsurf->view->geometry.height != height) {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004640 float from_x, from_y;
4641 float to_x, to_y;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004642
Jason Ekstranda7af7042013-10-12 22:38:11 -05004643 weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y);
4644 weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004645 configure(shell, es,
Jason Ekstranda7af7042013-10-12 22:38:11 -05004646 shsurf->view->geometry.x + to_x - from_x,
4647 shsurf->view->geometry.y + to_y - from_y,
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004648 width, height);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004649 }
4650}
4651
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004652static void launch_desktop_shell_process(void *data);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004653
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004654static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004655desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004656{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004657 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03004658 struct desktop_shell *shell =
4659 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004660
4661 shell->child.process.pid = 0;
4662 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004663
4664 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
4665 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05004666 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004667 shell->child.deathstamp = time;
4668 shell->child.deathcount = 0;
4669 }
4670
4671 shell->child.deathcount++;
4672 if (shell->child.deathcount > 5) {
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004673 weston_log("%s died, giving up.\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004674 return;
4675 }
4676
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004677 weston_log("%s died, respawning...\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004678 launch_desktop_shell_process(shell);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004679 shell_fade_startup(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004680}
4681
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004682static void
4683launch_desktop_shell_process(void *data)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004684{
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004685 struct desktop_shell *shell = data;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004686
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004687 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02004688 &shell->child.process,
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004689 shell->client,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02004690 desktop_shell_sigchld);
4691
4692 if (!shell->child.client)
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01004693 weston_log("not able to start %s\n", shell->client);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004694}
4695
4696static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004697bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
4698{
Tiago Vignattibe143262012-04-16 17:31:41 +03004699 struct desktop_shell *shell = data;
Jason Ekstranda85118c2013-06-27 20:17:02 -05004700 struct wl_resource *resource;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004701
Jason Ekstranda85118c2013-06-27 20:17:02 -05004702 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
4703 if (resource)
4704 wl_resource_set_implementation(resource, &shell_implementation,
4705 shell, NULL);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004706}
4707
Kristian Høgsberg75840622011-09-06 13:48:16 -04004708static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004709unbind_desktop_shell(struct wl_resource *resource)
4710{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004711 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05004712
4713 if (shell->locked)
4714 resume_desktop(shell);
4715
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004716 shell->child.desktop_shell = NULL;
4717 shell->prepare_event_sent = false;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004718}
4719
4720static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04004721bind_desktop_shell(struct wl_client *client,
4722 void *data, uint32_t version, uint32_t id)
4723{
Tiago Vignattibe143262012-04-16 17:31:41 +03004724 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004725 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004726
Jason Ekstranda85118c2013-06-27 20:17:02 -05004727 resource = wl_resource_create(client, &desktop_shell_interface,
4728 MIN(version, 2), id);
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004729
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004730 if (client == shell->child.client) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05004731 wl_resource_set_implementation(resource,
4732 &desktop_shell_implementation,
4733 shell, unbind_desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004734 shell->child.desktop_shell = resource;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004735
4736 if (version < 2)
4737 shell_fade_startup(shell);
4738
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004739 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004740 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02004741
4742 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4743 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04004744 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004745}
4746
Pekka Paalanen6e168112011-11-24 11:34:05 +02004747static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004748screensaver_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 -04004749{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004750 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004751 struct weston_view *view;
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004752
Giulio Camuffo184df502013-02-21 11:29:21 +01004753 if (width == 0)
4754 return;
4755
Pekka Paalanen3a1d07d2012-12-20 14:02:13 +02004756 /* XXX: starting weston-screensaver beforehand does not work */
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004757 if (!shell->locked)
4758 return;
4759
Jason Ekstranda7af7042013-10-12 22:38:11 -05004760 view = container_of(surface->views.next, struct weston_view, surface_link);
4761 center_on_output(view, surface->output);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004762
Jason Ekstranda7af7042013-10-12 22:38:11 -05004763 if (wl_list_empty(&view->layer_link)) {
4764 wl_list_insert(shell->lock_layer.view_list.prev,
4765 &view->layer_link);
4766 weston_view_update_transform(view);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02004767 wl_event_source_timer_update(shell->screensaver.timer,
4768 shell->screensaver.duration);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004769 shell_fade(shell, FADE_IN);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004770 }
4771}
4772
4773static void
Pekka Paalanen6e168112011-11-24 11:34:05 +02004774screensaver_set_surface(struct wl_client *client,
4775 struct wl_resource *resource,
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004776 struct wl_resource *surface_resource,
Pekka Paalanen6e168112011-11-24 11:34:05 +02004777 struct wl_resource *output_resource)
4778{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004779 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05004780 struct weston_surface *surface =
4781 wl_resource_get_user_data(surface_resource);
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05004782 struct weston_output *output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004783 struct weston_view *view, *next;
4784
4785 /* Make sure we only have one view */
4786 wl_list_for_each_safe(view, next, &surface->views, surface_link)
4787 weston_view_destroy(view);
4788 weston_view_create(surface);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004789
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04004790 surface->configure = screensaver_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004791 surface->configure_private = shell;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004792 surface->output = output;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004793}
4794
4795static const struct screensaver_interface screensaver_implementation = {
4796 screensaver_set_surface
4797};
4798
4799static void
4800unbind_screensaver(struct wl_resource *resource)
4801{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004802 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004803
Pekka Paalanen77346a62011-11-30 16:26:35 +02004804 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004805}
4806
4807static void
4808bind_screensaver(struct wl_client *client,
4809 void *data, uint32_t version, uint32_t id)
4810{
Tiago Vignattibe143262012-04-16 17:31:41 +03004811 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004812 struct wl_resource *resource;
4813
Jason Ekstranda85118c2013-06-27 20:17:02 -05004814 resource = wl_resource_create(client, &screensaver_interface, 1, id);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004815
Pekka Paalanen77346a62011-11-30 16:26:35 +02004816 if (shell->screensaver.binding == NULL) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05004817 wl_resource_set_implementation(resource,
4818 &screensaver_implementation,
4819 shell, unbind_screensaver);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004820 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02004821 return;
4822 }
4823
4824 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4825 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04004826 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02004827}
4828
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004829static void
Giulio Camuffo184df502013-02-21 11:29:21 +01004830input_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 -04004831{
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004832 struct input_panel_surface *ip_surface = surface->configure_private;
4833 struct desktop_shell *shell = ip_surface->shell;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004834 float x, y;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004835 uint32_t show_surface = 0;
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004836
Giulio Camuffo184df502013-02-21 11:29:21 +01004837 if (width == 0)
4838 return;
4839
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004840 if (!weston_surface_is_mapped(surface)) {
4841 if (!shell->showing_input_panels)
4842 return;
4843
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004844 show_surface = 1;
4845 }
Jan Arne Petersenaf7b6c92013-01-16 21:26:53 +01004846
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004847 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004848
4849 if (ip_surface->panel) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004850 x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2;
4851 y = get_default_view(shell->text_input.surface)->geometry.y + shell->text_input.cursor_rectangle.y2;
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004852 } else {
Rob Bradfordbdeb5d22013-07-11 13:20:53 +01004853 x = ip_surface->output->x + (ip_surface->output->width - width) / 2;
4854 y = ip_surface->output->y + ip_surface->output->height - height;
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004855 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004856
Jason Ekstranda7af7042013-10-12 22:38:11 -05004857 weston_view_configure(ip_surface->view, x, y, width, height);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004858
4859 if (show_surface) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004860 wl_list_insert(&shell->input_panel_layer.view_list,
4861 &ip_surface->view->layer_link);
4862 weston_view_update_transform(ip_surface->view);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004863 weston_surface_damage(surface);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004864 weston_slide_run(ip_surface->view, ip_surface->view->geometry.height, 0, NULL, NULL);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004865 }
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004866}
4867
4868static void
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004869destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004870{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004871 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
4872
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004873 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004874 wl_list_remove(&input_panel_surface->link);
4875
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004876 input_panel_surface->surface->configure = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004877 weston_view_destroy(input_panel_surface->view);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004878
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004879 free(input_panel_surface);
4880}
4881
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004882static struct input_panel_surface *
4883get_input_panel_surface(struct weston_surface *surface)
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004884{
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004885 if (surface->configure == input_panel_configure) {
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004886 return surface->configure_private;
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004887 } else {
4888 return NULL;
4889 }
4890}
4891
4892static void
4893input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
4894{
4895 struct input_panel_surface *ipsurface = container_of(listener,
4896 struct input_panel_surface,
4897 surface_destroy_listener);
4898
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004899 if (ipsurface->resource) {
4900 wl_resource_destroy(ipsurface->resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004901 } else {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004902 destroy_input_panel_surface(ipsurface);
4903 }
4904}
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004905
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004906static struct input_panel_surface *
4907create_input_panel_surface(struct desktop_shell *shell,
4908 struct weston_surface *surface)
4909{
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004910 struct input_panel_surface *input_panel_surface;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004911
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004912 input_panel_surface = calloc(1, sizeof *input_panel_surface);
4913 if (!input_panel_surface)
4914 return NULL;
4915
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004916 surface->configure = input_panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004917 surface->configure_private = input_panel_surface;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004918
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004919 input_panel_surface->shell = shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004920
4921 input_panel_surface->surface = surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004922 input_panel_surface->view = weston_view_create(surface);
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004923
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004924 wl_signal_init(&input_panel_surface->destroy_signal);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004925 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05004926 wl_signal_add(&surface->destroy_signal,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004927 &input_panel_surface->surface_destroy_listener);
4928
4929 wl_list_init(&input_panel_surface->link);
4930
4931 return input_panel_surface;
4932}
4933
4934static void
4935input_panel_surface_set_toplevel(struct wl_client *client,
4936 struct wl_resource *resource,
Jan Arne Petersen7cd29e12013-04-18 16:47:29 +02004937 struct wl_resource *output_resource,
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004938 uint32_t position)
4939{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004940 struct input_panel_surface *input_panel_surface =
4941 wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004942 struct desktop_shell *shell = input_panel_surface->shell;
Philipp Brüschweiler88013572012-08-06 13:44:42 +02004943
4944 wl_list_insert(&shell->input_panel.surfaces,
4945 &input_panel_surface->link);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004946
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05004947 input_panel_surface->output = wl_resource_get_user_data(output_resource);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004948 input_panel_surface->panel = 0;
4949}
4950
4951static void
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02004952input_panel_surface_set_overlay_panel(struct wl_client *client,
4953 struct wl_resource *resource)
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004954{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004955 struct input_panel_surface *input_panel_surface =
4956 wl_resource_get_user_data(resource);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004957 struct desktop_shell *shell = input_panel_surface->shell;
4958
4959 wl_list_insert(&shell->input_panel.surfaces,
4960 &input_panel_surface->link);
4961
4962 input_panel_surface->panel = 1;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02004963}
4964
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02004965static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02004966 input_panel_surface_set_toplevel,
Jan Arne Petersen70d942b2013-04-18 16:47:37 +02004967 input_panel_surface_set_overlay_panel
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004968};
4969
4970static void
4971destroy_input_panel_surface_resource(struct wl_resource *resource)
4972{
Jason Ekstrand51e5b142013-06-14 10:07:58 -05004973 struct input_panel_surface *ipsurf =
4974 wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004975
4976 destroy_input_panel_surface(ipsurf);
4977}
4978
4979static void
4980input_panel_get_input_panel_surface(struct wl_client *client,
4981 struct wl_resource *resource,
4982 uint32_t id,
4983 struct wl_resource *surface_resource)
4984{
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05004985 struct weston_surface *surface =
4986 wl_resource_get_user_data(surface_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05004987 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004988 struct input_panel_surface *ipsurf;
4989
4990 if (get_input_panel_surface(surface)) {
4991 wl_resource_post_error(surface_resource,
4992 WL_DISPLAY_ERROR_INVALID_OBJECT,
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02004993 "wl_input_panel::get_input_panel_surface already requested");
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01004994 return;
4995 }
4996
4997 ipsurf = create_input_panel_surface(shell, surface);
4998 if (!ipsurf) {
4999 wl_resource_post_error(surface_resource,
5000 WL_DISPLAY_ERROR_INVALID_OBJECT,
5001 "surface->configure already set");
5002 return;
5003 }
5004
Jason Ekstranda85118c2013-06-27 20:17:02 -05005005 ipsurf->resource =
5006 wl_resource_create(client,
5007 &wl_input_panel_surface_interface, 1, id);
5008 wl_resource_set_implementation(ipsurf->resource,
5009 &input_panel_surface_implementation,
5010 ipsurf,
5011 destroy_input_panel_surface_resource);
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01005012}
5013
Jan Arne Petersencc75ec12013-04-18 16:47:39 +02005014static const struct wl_input_panel_interface input_panel_implementation = {
Jan Arne Petersenffbb20f2013-01-16 21:26:55 +01005015 input_panel_get_input_panel_surface
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005016};
5017
5018static void
5019unbind_input_panel(struct wl_resource *resource)
5020{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05005021 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005022
5023 shell->input_panel.binding = NULL;
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005024}
5025
5026static void
5027bind_input_panel(struct wl_client *client,
5028 void *data, uint32_t version, uint32_t id)
5029{
5030 struct desktop_shell *shell = data;
5031 struct wl_resource *resource;
5032
Jason Ekstranda85118c2013-06-27 20:17:02 -05005033 resource = wl_resource_create(client,
5034 &wl_input_panel_interface, 1, id);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005035
5036 if (shell->input_panel.binding == NULL) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05005037 wl_resource_set_implementation(resource,
5038 &input_panel_implementation,
5039 shell, unbind_input_panel);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02005040 shell->input_panel.binding = resource;
5041 return;
5042 }
5043
5044 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
5045 "interface object already bound");
5046 wl_resource_destroy(resource);
5047}
5048
Kristian Høgsberg07045392012-02-19 18:52:44 -05005049struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03005050 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005051 struct weston_surface *current;
5052 struct wl_listener listener;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005053 struct weston_keyboard_grab grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005054};
5055
5056static void
5057switcher_next(struct switcher *switcher)
5058{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005059 struct weston_view *view;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005060 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005061 struct shell_surface *shsurf;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005062 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005063
Jason Ekstranda7af7042013-10-12 22:38:11 -05005064 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
5065 switch (get_shell_surface_type(view->surface)) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05005066 case SHELL_SURFACE_TOPLEVEL:
5067 case SHELL_SURFACE_FULLSCREEN:
5068 case SHELL_SURFACE_MAXIMIZED:
5069 if (first == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005070 first = view->surface;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005071 if (prev == switcher->current)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005072 next = view->surface;
5073 prev = view->surface;
5074 view->alpha = 0.25;
5075 weston_view_geometry_dirty(view);
5076 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005077 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00005078 case SHELL_SURFACE_TRANSIENT:
5079 case SHELL_SURFACE_POPUP:
5080 case SHELL_SURFACE_XWAYLAND:
5081 case SHELL_SURFACE_NONE:
Kristian Høgsberg07045392012-02-19 18:52:44 -05005082 default:
5083 break;
5084 }
Alex Wu1659daa2012-04-01 20:13:09 +08005085
Jason Ekstranda7af7042013-10-12 22:38:11 -05005086 if (is_black_surface(view->surface, NULL)) {
5087 view->alpha = 0.25;
5088 weston_view_geometry_dirty(view);
5089 weston_surface_damage(view->surface);
Alex Wu1659daa2012-04-01 20:13:09 +08005090 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05005091 }
5092
5093 if (next == NULL)
5094 next = first;
5095
Alex Wu07b26062012-03-12 16:06:01 +08005096 if (next == NULL)
5097 return;
5098
Kristian Høgsberg07045392012-02-19 18:52:44 -05005099 wl_list_remove(&switcher->listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005100 wl_signal_add(&next->destroy_signal, &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005101
5102 switcher->current = next;
Jason Ekstranda7af7042013-10-12 22:38:11 -05005103 wl_list_for_each(view, &next->views, surface_link)
5104 view->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08005105
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005106 shsurf = get_shell_surface(switcher->current);
5107 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005108 shsurf->fullscreen.black_view->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005109}
5110
5111static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005112switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005113{
5114 struct switcher *switcher =
5115 container_of(listener, struct switcher, listener);
5116
5117 switcher_next(switcher);
5118}
5119
5120static void
Daniel Stone351eb612012-05-31 15:27:47 -04005121switcher_destroy(struct switcher *switcher)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005122{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005123 struct weston_view *view;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005124 struct weston_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005125 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005126
Jason Ekstranda7af7042013-10-12 22:38:11 -05005127 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01005128 if (is_focus_view(view))
5129 continue;
5130
Jason Ekstranda7af7042013-10-12 22:38:11 -05005131 view->alpha = 1.0;
5132 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005133 }
5134
Alex Wu07b26062012-03-12 16:06:01 +08005135 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01005136 activate(switcher->shell, switcher->current,
5137 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005138 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005139 weston_keyboard_end_grab(keyboard);
5140 if (keyboard->input_method_resource)
5141 keyboard->grab = &keyboard->input_method_grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005142 free(switcher);
5143}
5144
5145static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005146switcher_key(struct weston_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +01005147 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005148{
5149 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stonec9785ea2012-05-30 16:31:52 +01005150 enum wl_keyboard_key_state state = state_w;
Daniel Stone351eb612012-05-31 15:27:47 -04005151
Daniel Stonec9785ea2012-05-30 16:31:52 +01005152 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
Daniel Stone351eb612012-05-31 15:27:47 -04005153 switcher_next(switcher);
5154}
5155
5156static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005157switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
Daniel Stone351eb612012-05-31 15:27:47 -04005158 uint32_t mods_depressed, uint32_t mods_latched,
5159 uint32_t mods_locked, uint32_t group)
5160{
5161 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01005162 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005163
Daniel Stone351eb612012-05-31 15:27:47 -04005164 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
5165 switcher_destroy(switcher);
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04005166}
Kristian Høgsberg07045392012-02-19 18:52:44 -05005167
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005168static void
5169switcher_cancel(struct weston_keyboard_grab *grab)
5170{
5171 struct switcher *switcher = container_of(grab, struct switcher, grab);
5172
5173 switcher_destroy(switcher);
5174}
5175
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005176static const struct weston_keyboard_grab_interface switcher_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -04005177 switcher_key,
5178 switcher_modifier,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005179 switcher_cancel,
Kristian Høgsberg07045392012-02-19 18:52:44 -05005180};
5181
5182static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005183switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005184 void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005185{
Tiago Vignattibe143262012-04-16 17:31:41 +03005186 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005187 struct switcher *switcher;
5188
5189 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04005190 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005191 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005192 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005193 wl_list_init(&switcher->listener.link);
5194
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02005195 restore_all_output_modes(shell->compositor);
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005196 lower_fullscreen_layer(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005197 switcher->grab.interface = &switcher_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005198 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
5199 weston_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005200 switcher_next(switcher);
5201}
5202
Daniel Stonedf8133b2013-11-19 11:37:14 +01005203struct exposay_surface {
5204 struct desktop_shell *shell;
5205 struct weston_surface *surface;
5206 struct weston_view *view;
5207 struct wl_list link;
5208
5209 int x;
5210 int y;
5211 int width;
5212 int height;
5213 double scale;
5214
5215 int row;
5216 int column;
5217
5218 /* The animations only apply a transformation for their own lifetime,
5219 * and don't have an option to indefinitely maintain the
5220 * transformation in a steady state - so, we apply our own once the
5221 * animation has finished. */
5222 struct weston_transform transform;
5223};
5224
5225static void exposay_set_state(struct desktop_shell *shell,
5226 enum exposay_target_state state,
5227 struct weston_seat *seat);
5228static void exposay_check_state(struct desktop_shell *shell);
5229
5230static void
5231exposay_in_flight_inc(struct desktop_shell *shell)
5232{
5233 shell->exposay.in_flight++;
5234}
5235
5236static void
5237exposay_in_flight_dec(struct desktop_shell *shell)
5238{
5239 if (--shell->exposay.in_flight > 0)
5240 return;
5241
5242 exposay_check_state(shell);
5243}
5244
5245static void
5246exposay_animate_in_done(struct weston_view_animation *animation, void *data)
5247{
5248 struct exposay_surface *esurface = data;
5249
5250 wl_list_insert(&esurface->view->geometry.transformation_list,
5251 &esurface->transform.link);
5252 weston_matrix_init(&esurface->transform.matrix);
5253 weston_matrix_scale(&esurface->transform.matrix,
5254 esurface->scale, esurface->scale, 1.0f);
5255 weston_matrix_translate(&esurface->transform.matrix,
5256 esurface->x - esurface->view->geometry.x,
5257 esurface->y - esurface->view->geometry.y,
5258 0);
5259
5260 weston_view_geometry_dirty(esurface->view);
5261 weston_compositor_schedule_repaint(esurface->view->surface->compositor);
5262
5263 exposay_in_flight_dec(esurface->shell);
5264}
5265
5266static void
5267exposay_animate_in(struct exposay_surface *esurface)
5268{
5269 exposay_in_flight_inc(esurface->shell);
5270
5271 weston_move_scale_run(esurface->view,
5272 esurface->x - esurface->view->geometry.x,
5273 esurface->y - esurface->view->geometry.y,
5274 1.0, esurface->scale, 0,
5275 exposay_animate_in_done, esurface);
5276}
5277
5278static void
5279exposay_animate_out_done(struct weston_view_animation *animation, void *data)
5280{
5281 struct exposay_surface *esurface = data;
5282 struct desktop_shell *shell = esurface->shell;
5283
5284 wl_list_remove(&esurface->link);
5285 free(esurface);
5286
5287 exposay_in_flight_dec(shell);
5288}
5289
5290static void
5291exposay_animate_out(struct exposay_surface *esurface)
5292{
5293 exposay_in_flight_inc(esurface->shell);
5294
5295 /* Remove the static transformation set up by
5296 * exposay_transform_in_done(). */
5297 wl_list_remove(&esurface->transform.link);
5298 weston_view_geometry_dirty(esurface->view);
5299
5300 weston_move_scale_run(esurface->view,
5301 esurface->x - esurface->view->geometry.x,
5302 esurface->y - esurface->view->geometry.y,
5303 1.0, esurface->scale, 1,
5304 exposay_animate_out_done, esurface);
5305}
5306
5307static void
5308exposay_highlight_surface(struct desktop_shell *shell,
5309 struct exposay_surface *esurface)
5310{
5311 struct weston_view *view = NULL;
5312
5313 if (esurface) {
5314 shell->exposay.row_current = esurface->row;
5315 shell->exposay.column_current = esurface->column;
5316 view = esurface->view;
5317 }
5318
Emilio Pozuelo Monfort5c22ce62013-11-19 11:37:18 +01005319 activate(shell, view->surface, shell->exposay.seat);
Daniel Stonedf8133b2013-11-19 11:37:14 +01005320 shell->exposay.focus_current = view;
5321}
5322
5323static int
5324exposay_is_animating(struct desktop_shell *shell)
5325{
5326 if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE ||
5327 shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW)
5328 return 0;
5329
5330 return (shell->exposay.in_flight > 0);
5331}
5332
5333static void
5334exposay_pick(struct desktop_shell *shell, int x, int y)
5335{
5336 struct exposay_surface *esurface;
5337
5338 if (exposay_is_animating(shell))
5339 return;
5340
5341 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5342 if (x < esurface->x || x > esurface->x + esurface->width)
5343 continue;
5344 if (y < esurface->y || y > esurface->y + esurface->height)
5345 continue;
5346
5347 exposay_highlight_surface(shell, esurface);
5348 return;
5349 }
5350}
5351
5352/* Pretty lame layout for now; just tries to make a square. Should take
5353 * aspect ratio into account really. Also needs to be notified of surface
5354 * addition and removal and adjust layout/animate accordingly. */
5355static enum exposay_layout_state
5356exposay_layout(struct desktop_shell *shell)
5357{
5358 struct workspace *workspace = shell->exposay.workspace;
5359 struct weston_compositor *compositor = shell->compositor;
5360 struct weston_output *output = get_default_output(compositor);
5361 struct weston_view *view;
5362 struct exposay_surface *esurface;
5363 int w, h;
5364 int i;
5365 int last_row_removed = 0;
5366
5367 wl_list_init(&shell->exposay.surface_list);
5368
5369 shell->exposay.num_surfaces = 0;
5370 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5371 if (!get_shell_surface(view->surface))
5372 continue;
5373 shell->exposay.num_surfaces++;
5374 }
5375
5376 if (shell->exposay.num_surfaces == 0) {
5377 shell->exposay.grid_size = 0;
5378 shell->exposay.hpadding_outer = 0;
5379 shell->exposay.vpadding_outer = 0;
5380 shell->exposay.padding_inner = 0;
5381 shell->exposay.surface_size = 0;
5382 return EXPOSAY_LAYOUT_OVERVIEW;
5383 }
5384
5385 /* Lay the grid out as square as possible, losing surfaces from the
5386 * bottom row if required. Start with fixed padding of a 10% margin
5387 * around the outside and 80px internal padding between surfaces, and
5388 * maximise the area made available to surfaces after this, but only
5389 * to a maximum of 1/3rd the total output size.
5390 *
5391 * If we can't make a square grid, add one extra row at the bottom
5392 * which will have a smaller number of columns.
5393 *
5394 * XXX: Surely there has to be a better way to express this maths,
5395 * right?!
5396 */
5397 shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces));
5398 if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces)
5399 shell->exposay.grid_size++;
5400 last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces;
5401
5402 shell->exposay.hpadding_outer = (output->width / 10);
5403 shell->exposay.vpadding_outer = (output->height / 10);
5404 shell->exposay.padding_inner = 80;
5405
5406 w = output->width - (shell->exposay.hpadding_outer * 2);
5407 w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5408 w /= shell->exposay.grid_size;
5409
5410 h = output->height - (shell->exposay.vpadding_outer * 2);
5411 h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5412 h /= shell->exposay.grid_size;
5413
5414 shell->exposay.surface_size = (w < h) ? w : h;
5415 if (shell->exposay.surface_size > (output->width / 2))
5416 shell->exposay.surface_size = output->width / 2;
5417 if (shell->exposay.surface_size > (output->height / 2))
5418 shell->exposay.surface_size = output->height / 2;
5419
5420 i = 0;
5421 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5422 int pad;
5423
5424 pad = shell->exposay.surface_size + shell->exposay.padding_inner;
5425
5426 if (!get_shell_surface(view->surface))
5427 continue;
5428
5429 esurface = malloc(sizeof(*esurface));
5430 if (!esurface) {
5431 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL,
5432 shell->exposay.seat);
5433 break;
5434 }
5435
5436 wl_list_insert(&shell->exposay.surface_list, &esurface->link);
5437 esurface->shell = shell;
5438 esurface->view = view;
5439
5440 esurface->row = i / shell->exposay.grid_size;
5441 esurface->column = i % shell->exposay.grid_size;
5442
5443 esurface->x = shell->exposay.hpadding_outer;
5444 esurface->x += pad * esurface->column;
5445 esurface->y = shell->exposay.vpadding_outer;
5446 esurface->y += pad * esurface->row;
5447
5448 if (esurface->row == shell->exposay.grid_size - 1)
5449 esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2;
5450
5451 if (view->geometry.width > view->geometry.height)
5452 esurface->scale = shell->exposay.surface_size / (float) view->geometry.width;
5453 else
5454 esurface->scale = shell->exposay.surface_size / (float) view->geometry.height;
5455 esurface->width = view->geometry.width * esurface->scale;
5456 esurface->height = view->geometry.height * esurface->scale;
5457
5458 if (shell->exposay.focus_current == esurface->view)
5459 exposay_highlight_surface(shell, esurface);
5460
5461 exposay_animate_in(esurface);
5462
5463 i++;
5464 }
5465
5466 weston_compositor_schedule_repaint(shell->compositor);
5467
5468 return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW;
5469}
5470
5471static void
Emilio Pozuelo Monfort17467d62013-11-19 12:14:53 +01005472exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
5473 wl_fixed_t x, wl_fixed_t y)
Daniel Stonedf8133b2013-11-19 11:37:14 +01005474{
5475 struct desktop_shell *shell =
5476 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5477
Emilio Pozuelo Monfort17467d62013-11-19 12:14:53 +01005478 weston_pointer_move(grab->pointer, x, y);
5479
Daniel Stonedf8133b2013-11-19 11:37:14 +01005480 exposay_pick(shell,
5481 wl_fixed_to_int(grab->pointer->x),
5482 wl_fixed_to_int(grab->pointer->y));
5483}
5484
5485static void
5486exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button,
5487 uint32_t state_w)
5488{
5489 struct desktop_shell *shell =
5490 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5491 struct weston_seat *seat = grab->pointer->seat;
5492 enum wl_pointer_button_state state = state_w;
5493
5494 if (button != BTN_LEFT)
5495 return;
5496
5497 /* Store the surface we clicked on, and don't do anything if we end up
5498 * releasing on a different surface. */
5499 if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
5500 shell->exposay.clicked = shell->exposay.focus_current;
5501 return;
5502 }
5503
5504 if (shell->exposay.focus_current == shell->exposay.clicked)
5505 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5506 else
5507 shell->exposay.clicked = NULL;
5508}
5509
Emilio Pozuelo Monfort234c5242013-11-26 13:32:08 +01005510static void
5511exposay_pointer_grab_cancel(struct weston_pointer_grab *grab)
5512{
5513 struct desktop_shell *shell =
5514 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5515
5516 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5517}
5518
Daniel Stonedf8133b2013-11-19 11:37:14 +01005519static const struct weston_pointer_grab_interface exposay_ptr_grab = {
5520 noop_grab_focus,
5521 exposay_motion,
5522 exposay_button,
Emilio Pozuelo Monfort234c5242013-11-26 13:32:08 +01005523 exposay_pointer_grab_cancel,
Daniel Stonedf8133b2013-11-19 11:37:14 +01005524};
5525
5526static int
5527exposay_maybe_move(struct desktop_shell *shell, int row, int column)
5528{
5529 struct exposay_surface *esurface;
5530
5531 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5532 if (esurface->row != row || esurface->column != column)
5533 continue;
5534
5535 exposay_highlight_surface(shell, esurface);
5536 return 1;
5537 }
5538
5539 return 0;
5540}
5541
5542static void
5543exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key,
5544 uint32_t state_w)
5545{
5546 struct weston_seat *seat = grab->keyboard->seat;
5547 struct desktop_shell *shell =
5548 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5549 enum wl_keyboard_key_state state = state_w;
5550
5551 if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
5552 return;
5553
5554 switch (key) {
5555 case KEY_ESC:
5556 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5557 break;
5558 case KEY_ENTER:
5559 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5560 break;
5561 case KEY_UP:
5562 exposay_maybe_move(shell, shell->exposay.row_current - 1,
5563 shell->exposay.column_current);
5564 break;
5565 case KEY_DOWN:
5566 /* Special case for trying to move to the bottom row when it
5567 * has fewer items than all the others. */
5568 if (!exposay_maybe_move(shell, shell->exposay.row_current + 1,
5569 shell->exposay.column_current) &&
5570 shell->exposay.row_current < (shell->exposay.grid_size - 1)) {
5571 exposay_maybe_move(shell, shell->exposay.row_current + 1,
5572 (shell->exposay.num_surfaces %
5573 shell->exposay.grid_size) - 1);
5574 }
5575 break;
5576 case KEY_LEFT:
5577 exposay_maybe_move(shell, shell->exposay.row_current,
5578 shell->exposay.column_current - 1);
5579 break;
5580 case KEY_RIGHT:
5581 exposay_maybe_move(shell, shell->exposay.row_current,
5582 shell->exposay.column_current + 1);
5583 break;
5584 case KEY_TAB:
5585 /* Try to move right, then down (and to the leftmost column),
5586 * then if all else fails, to the top left. */
5587 if (!exposay_maybe_move(shell, shell->exposay.row_current,
5588 shell->exposay.column_current + 1) &&
5589 !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0))
5590 exposay_maybe_move(shell, 0, 0);
5591 break;
5592 default:
5593 break;
5594 }
5595}
5596
5597static void
5598exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
5599 uint32_t mods_depressed, uint32_t mods_latched,
5600 uint32_t mods_locked, uint32_t group)
5601{
Emilio Pozuelo Monforteed93442013-11-27 10:49:08 +01005602 struct desktop_shell *shell =
5603 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5604 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
5605
5606 /* We want to know when mod has been pressed and released.
5607 * FIXME: There is a problem here: if mod is pressed, then a key
5608 * is pressed and released, then mod is released, we will treat that
5609 * as if only mod had been pressed and released. */
5610 if (seat->modifier_state) {
5611 if (seat->modifier_state == shell->binding_modifier) {
5612 shell->exposay.mod_pressed = true;
5613 } else {
5614 shell->exposay.mod_invalid = true;
5615 }
5616 } else {
5617 if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid)
5618 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5619
5620 shell->exposay.mod_invalid = false;
5621 shell->exposay.mod_pressed = false;
5622 }
5623
5624 return;
Daniel Stonedf8133b2013-11-19 11:37:14 +01005625}
5626
Emilio Pozuelo Monfort82243092013-11-19 11:37:17 +01005627static void
5628exposay_cancel(struct weston_keyboard_grab *grab)
5629{
5630 struct desktop_shell *shell =
5631 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5632
5633 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5634}
5635
Daniel Stonedf8133b2013-11-19 11:37:14 +01005636static const struct weston_keyboard_grab_interface exposay_kbd_grab = {
5637 exposay_key,
5638 exposay_modifier,
Emilio Pozuelo Monfort82243092013-11-19 11:37:17 +01005639 exposay_cancel,
Daniel Stonedf8133b2013-11-19 11:37:14 +01005640};
5641
5642/**
5643 * Called when the transition from overview -> inactive has completed.
5644 */
5645static enum exposay_layout_state
5646exposay_set_inactive(struct desktop_shell *shell)
5647{
5648 struct weston_seat *seat = shell->exposay.seat;
5649
5650 weston_keyboard_end_grab(seat->keyboard);
5651 weston_pointer_end_grab(seat->pointer);
5652 if (seat->keyboard->input_method_resource)
5653 seat->keyboard->grab = &seat->keyboard->input_method_grab;
5654
5655 return EXPOSAY_LAYOUT_INACTIVE;
5656}
5657
5658/**
5659 * Begins the transition from overview to inactive. */
5660static enum exposay_layout_state
5661exposay_transition_inactive(struct desktop_shell *shell, int switch_focus)
5662{
5663 struct exposay_surface *esurface;
5664
5665 /* Call activate() before we start the animations to avoid
5666 * animating back the old state and then immediately transitioning
5667 * to the new. */
5668 if (switch_focus && shell->exposay.focus_current)
5669 activate(shell, shell->exposay.focus_current->surface,
5670 shell->exposay.seat);
5671 else if (shell->exposay.focus_prev)
5672 activate(shell, shell->exposay.focus_prev->surface,
5673 shell->exposay.seat);
5674
5675 wl_list_for_each(esurface, &shell->exposay.surface_list, link)
5676 exposay_animate_out(esurface);
5677 weston_compositor_schedule_repaint(shell->compositor);
5678
5679 return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE;
5680}
5681
5682static enum exposay_layout_state
5683exposay_transition_active(struct desktop_shell *shell)
5684{
5685 struct weston_seat *seat = shell->exposay.seat;
5686
5687 shell->exposay.workspace = get_current_workspace(shell);
5688 shell->exposay.focus_prev = get_default_view (seat->keyboard->focus);
5689 shell->exposay.focus_current = get_default_view (seat->keyboard->focus);
5690 shell->exposay.clicked = NULL;
5691 wl_list_init(&shell->exposay.surface_list);
5692
5693 lower_fullscreen_layer(shell);
5694 shell->exposay.grab_kbd.interface = &exposay_kbd_grab;
5695 weston_keyboard_start_grab(seat->keyboard,
5696 &shell->exposay.grab_kbd);
5697 weston_keyboard_set_focus(seat->keyboard, NULL);
5698
5699 shell->exposay.grab_ptr.interface = &exposay_ptr_grab;
5700 weston_pointer_start_grab(seat->pointer,
5701 &shell->exposay.grab_ptr);
5702 weston_pointer_set_focus(seat->pointer, NULL,
5703 seat->pointer->x, seat->pointer->y);
5704
5705 return exposay_layout(shell);
5706}
5707
5708static void
5709exposay_check_state(struct desktop_shell *shell)
5710{
5711 enum exposay_layout_state state_new = shell->exposay.state_cur;
5712 int do_switch = 0;
5713
5714 /* Don't do anything whilst animations are running, just store up
5715 * target state changes and only act on them when the animations have
5716 * completed. */
5717 if (exposay_is_animating(shell))
5718 return;
5719
5720 switch (shell->exposay.state_target) {
5721 case EXPOSAY_TARGET_OVERVIEW:
5722 switch (shell->exposay.state_cur) {
5723 case EXPOSAY_LAYOUT_OVERVIEW:
5724 goto out;
5725 case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW:
5726 state_new = EXPOSAY_LAYOUT_OVERVIEW;
5727 break;
5728 default:
5729 state_new = exposay_transition_active(shell);
5730 break;
5731 }
5732 break;
5733
5734 case EXPOSAY_TARGET_SWITCH:
5735 do_switch = 1; /* fallthrough */
5736 case EXPOSAY_TARGET_CANCEL:
5737 switch (shell->exposay.state_cur) {
5738 case EXPOSAY_LAYOUT_INACTIVE:
5739 goto out;
5740 case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE:
5741 state_new = exposay_set_inactive(shell);
5742 break;
5743 default:
5744 state_new = exposay_transition_inactive(shell, do_switch);
5745 break;
5746 }
5747
5748 break;
5749 }
5750
5751out:
5752 shell->exposay.state_cur = state_new;
5753}
5754
5755static void
5756exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state,
5757 struct weston_seat *seat)
5758{
5759 shell->exposay.state_target = state;
5760 shell->exposay.seat = seat;
5761 exposay_check_state(shell);
5762}
5763
5764static void
5765exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier,
5766 void *data)
5767{
5768 struct desktop_shell *shell = data;
5769
Emilio Pozuelo Monforteed93442013-11-27 10:49:08 +01005770 exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat);
Daniel Stonedf8133b2013-11-19 11:37:14 +01005771}
5772
Pekka Paalanen3c647232011-12-22 13:43:43 +02005773static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005774backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005775 void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005776{
5777 struct weston_compositor *compositor = data;
5778 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005779 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005780
5781 /* TODO: we're limiting to simple use cases, where we assume just
5782 * control on the primary display. We'd have to extend later if we
5783 * ever get support for setting backlights on random desktop LCD
5784 * panels though */
5785 output = get_default_output(compositor);
5786 if (!output)
5787 return;
5788
5789 if (!output->set_backlight)
5790 return;
5791
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005792 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
5793 backlight_new = output->backlight_current - 25;
5794 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
5795 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005796
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005797 if (backlight_new < 5)
5798 backlight_new = 5;
5799 if (backlight_new > 255)
5800 backlight_new = 255;
5801
5802 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005803 output->set_backlight(output, output->backlight_current);
5804}
5805
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005806struct debug_binding_grab {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005807 struct weston_keyboard_grab grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005808 struct weston_seat *seat;
5809 uint32_t key[2];
5810 int key_released[2];
5811};
5812
5813static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005814debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005815 uint32_t key, uint32_t state)
5816{
5817 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
Rob Bradford880ebc72013-07-22 17:31:38 +01005818 struct weston_compositor *ec = db->seat->compositor;
5819 struct wl_display *display = ec->wl_display;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005820 struct wl_resource *resource;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005821 uint32_t serial;
5822 int send = 0, terminate = 0;
5823 int check_binding = 1;
5824 int i;
Neil Roberts96d790e2013-09-19 17:32:00 +01005825 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005826
5827 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
5828 /* Do not run bindings on key releases */
5829 check_binding = 0;
5830
5831 for (i = 0; i < 2; i++)
5832 if (key == db->key[i])
5833 db->key_released[i] = 1;
5834
5835 if (db->key_released[0] && db->key_released[1]) {
5836 /* All key releases been swalled so end the grab */
5837 terminate = 1;
5838 } else if (key != db->key[0] && key != db->key[1]) {
5839 /* Should not swallow release of other keys */
5840 send = 1;
5841 }
5842 } else if (key == db->key[0] && !db->key_released[0]) {
5843 /* Do not check bindings for the first press of the binding
5844 * key. This allows it to be used as a debug shortcut.
5845 * We still need to swallow this event. */
5846 check_binding = 0;
5847 } else if (db->key[1]) {
5848 /* If we already ran a binding don't process another one since
5849 * we can't keep track of all the binding keys that were
5850 * pressed in order to swallow the release events. */
5851 send = 1;
5852 check_binding = 0;
5853 }
5854
5855 if (check_binding) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005856 if (weston_compositor_run_debug_binding(ec, db->seat, time,
5857 key, state)) {
5858 /* We ran a binding so swallow the press and keep the
5859 * grab to swallow the released too. */
5860 send = 0;
5861 terminate = 0;
5862 db->key[1] = key;
5863 } else {
5864 /* Terminate the grab since the key pressed is not a
5865 * debug binding key. */
5866 send = 1;
5867 terminate = 1;
5868 }
5869 }
5870
5871 if (send) {
Neil Roberts96d790e2013-09-19 17:32:00 +01005872 serial = wl_display_next_serial(display);
5873 resource_list = &grab->keyboard->focus_resource_list;
5874 wl_resource_for_each(resource, resource_list) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005875 wl_keyboard_send_key(resource, serial, time, key, state);
5876 }
5877 }
5878
5879 if (terminate) {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005880 weston_keyboard_end_grab(grab->keyboard);
5881 if (grab->keyboard->input_method_resource)
5882 grab->keyboard->grab = &grab->keyboard->input_method_grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005883 free(db);
5884 }
5885}
5886
5887static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005888debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005889 uint32_t mods_depressed, uint32_t mods_latched,
5890 uint32_t mods_locked, uint32_t group)
5891{
5892 struct wl_resource *resource;
Neil Roberts96d790e2013-09-19 17:32:00 +01005893 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005894
Neil Roberts96d790e2013-09-19 17:32:00 +01005895 resource_list = &grab->keyboard->focus_resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005896
Neil Roberts96d790e2013-09-19 17:32:00 +01005897 wl_resource_for_each(resource, resource_list) {
5898 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
5899 mods_latched, mods_locked, group);
5900 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005901}
5902
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005903static void
5904debug_binding_cancel(struct weston_keyboard_grab *grab)
5905{
5906 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
5907
5908 weston_keyboard_end_grab(grab->keyboard);
5909 free(db);
5910}
5911
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005912struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005913 debug_binding_key,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005914 debug_binding_modifiers,
5915 debug_binding_cancel,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005916};
5917
5918static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005919debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005920{
5921 struct debug_binding_grab *grab;
5922
5923 grab = calloc(1, sizeof *grab);
5924 if (!grab)
5925 return;
5926
5927 grab->seat = (struct weston_seat *) seat;
5928 grab->key[0] = key;
5929 grab->grab.interface = &debug_binding_keyboard_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005930 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005931}
5932
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05005933static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005934force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005935 void *data)
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005936{
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04005937 struct weston_surface *focus_surface;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005938 struct wl_client *client;
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005939 struct desktop_shell *shell = data;
5940 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005941 pid_t pid;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005942
Philipp Brüschweiler6cef0092012-08-13 21:27:27 +02005943 focus_surface = seat->keyboard->focus;
5944 if (!focus_surface)
5945 return;
5946
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005947 wl_signal_emit(&compositor->kill_signal, focus_surface);
5948
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005949 client = wl_resource_get_client(focus_surface->resource);
Tiago Vignatti920f1972012-09-27 17:48:35 +03005950 wl_client_get_credentials(client, &pid, NULL, NULL);
5951
5952 /* Skip clients that we launched ourselves (the credentials of
5953 * the socketpair is ours) */
5954 if (pid == getpid())
5955 return;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005956
Daniel Stone325fc2d2012-05-30 16:31:58 +01005957 kill(pid, SIGKILL);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005958}
5959
5960static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005961workspace_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005962 uint32_t key, void *data)
5963{
5964 struct desktop_shell *shell = data;
5965 unsigned int new_index = shell->workspaces.current;
5966
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005967 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005968 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005969 if (new_index != 0)
5970 new_index--;
5971
5972 change_workspace(shell, new_index);
5973}
5974
5975static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005976workspace_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005977 uint32_t key, void *data)
5978{
5979 struct desktop_shell *shell = data;
5980 unsigned int new_index = shell->workspaces.current;
5981
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005982 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005983 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005984 if (new_index < shell->workspaces.num - 1)
5985 new_index++;
5986
5987 change_workspace(shell, new_index);
5988}
5989
5990static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005991workspace_f_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005992 uint32_t key, void *data)
5993{
5994 struct desktop_shell *shell = data;
5995 unsigned int new_index;
5996
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005997 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005998 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005999 new_index = key - KEY_F1;
6000 if (new_index >= shell->workspaces.num)
6001 new_index = shell->workspaces.num - 1;
6002
6003 change_workspace(shell, new_index);
6004}
6005
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006006static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04006007workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006008 uint32_t key, void *data)
6009{
6010 struct desktop_shell *shell = data;
6011 unsigned int new_index = shell->workspaces.current;
6012
6013 if (shell->locked)
6014 return;
6015
6016 if (new_index != 0)
6017 new_index--;
6018
6019 take_surface_to_workspace_by_seat(shell, seat, new_index);
6020}
6021
6022static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04006023workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006024 uint32_t key, void *data)
6025{
6026 struct desktop_shell *shell = data;
6027 unsigned int new_index = shell->workspaces.current;
6028
6029 if (shell->locked)
6030 return;
6031
6032 if (new_index < shell->workspaces.num - 1)
6033 new_index++;
6034
6035 take_surface_to_workspace_by_seat(shell, seat, new_index);
6036}
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006037
6038static void
Xiong Zhang6b481422013-10-23 13:58:32 +08006039handle_output_destroy(struct wl_listener *listener, void *data)
6040{
6041 struct shell_output *output_listener =
6042 container_of(listener, struct shell_output, destroy_listener);
6043
6044 wl_list_remove(&output_listener->destroy_listener.link);
6045 wl_list_remove(&output_listener->link);
6046 free(output_listener);
6047}
6048
6049static void
6050create_shell_output(struct desktop_shell *shell,
6051 struct weston_output *output)
6052{
6053 struct shell_output *shell_output;
6054
6055 shell_output = zalloc(sizeof *shell_output);
6056 if (shell_output == NULL)
6057 return;
6058
6059 shell_output->output = output;
6060 shell_output->shell = shell;
6061 shell_output->destroy_listener.notify = handle_output_destroy;
6062 wl_signal_add(&output->destroy_signal,
6063 &shell_output->destroy_listener);
Kristian Høgsberga3a0e182013-10-23 23:36:04 -07006064 wl_list_insert(shell->output_list.prev, &shell_output->link);
Xiong Zhang6b481422013-10-23 13:58:32 +08006065}
6066
6067static void
6068handle_output_create(struct wl_listener *listener, void *data)
6069{
6070 struct desktop_shell *shell =
6071 container_of(listener, struct desktop_shell, output_create_listener);
6072 struct weston_output *output = (struct weston_output *)data;
6073
6074 create_shell_output(shell, output);
6075}
6076
6077static void
6078setup_output_destroy_handler(struct weston_compositor *ec,
6079 struct desktop_shell *shell)
6080{
6081 struct weston_output *output;
6082
6083 wl_list_init(&shell->output_list);
6084 wl_list_for_each(output, &ec->output_list, link)
6085 create_shell_output(shell, output);
6086
6087 shell->output_create_listener.notify = handle_output_create;
6088 wl_signal_add(&ec->output_created_signal,
6089 &shell->output_create_listener);
6090}
6091
6092static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04006093shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02006094{
Tiago Vignattibe143262012-04-16 17:31:41 +03006095 struct desktop_shell *shell =
6096 container_of(listener, struct desktop_shell, destroy_listener);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006097 struct workspace **ws;
Xiong Zhang6b481422013-10-23 13:58:32 +08006098 struct shell_output *shell_output, *tmp;
Pekka Paalanen3c647232011-12-22 13:43:43 +02006099
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02006100 if (shell->child.client)
6101 wl_client_destroy(shell->child.client);
6102
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02006103 wl_list_remove(&shell->idle_listener.link);
6104 wl_list_remove(&shell->wake_listener.link);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006105 wl_list_remove(&shell->show_input_panel_listener.link);
6106 wl_list_remove(&shell->hide_input_panel_listener.link);
Kristian Høgsberg88c16072012-05-16 08:04:19 -04006107
Xiong Zhang6b481422013-10-23 13:58:32 +08006108 wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) {
6109 wl_list_remove(&shell_output->destroy_listener.link);
6110 wl_list_remove(&shell_output->link);
6111 free(shell_output);
6112 }
6113
6114 wl_list_remove(&shell->output_create_listener.link);
6115
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006116 wl_array_for_each(ws, &shell->workspaces.array)
6117 workspace_destroy(*ws);
6118 wl_array_release(&shell->workspaces.array);
6119
Pekka Paalanen3c647232011-12-22 13:43:43 +02006120 free(shell->screensaver.path);
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01006121 free(shell->client);
Pekka Paalanen3c647232011-12-22 13:43:43 +02006122 free(shell);
6123}
6124
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006125static void
6126shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
6127{
6128 uint32_t mod;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006129 int i, num_workspace_bindings;
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006130
6131 /* fixed bindings */
Daniel Stone325fc2d2012-05-30 16:31:58 +01006132 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
6133 MODIFIER_CTRL | MODIFIER_ALT,
6134 terminate_binding, ec);
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01006135 weston_compositor_add_key_binding(ec, KEY_TAB,
6136 MODIFIER_ALT,
6137 alt_tab_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006138 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
6139 click_to_activate_binding,
6140 shell);
Neil Robertsa28c6932013-10-03 16:43:04 +01006141 weston_compositor_add_touch_binding(ec, 0,
6142 touch_to_activate_binding,
6143 shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006144 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6145 MODIFIER_SUPER | MODIFIER_ALT,
6146 surface_opacity_binding, NULL);
6147 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6148 MODIFIER_SUPER, zoom_axis_binding,
6149 NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006150
6151 /* configurable bindings */
6152 mod = shell->binding_modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +01006153 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
6154 zoom_key_binding, NULL);
6155 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
6156 zoom_key_binding, NULL);
6157 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
6158 shell);
Neil Robertsaba0f252013-10-03 16:43:05 +01006159 weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006160 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
6161 resize_binding, shell);
Pekka Paalanen7bb65102013-05-22 18:03:04 +03006162
6163 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
6164 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
6165 rotate_binding, NULL);
6166
Daniel Stone325fc2d2012-05-30 16:31:58 +01006167 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
6168 shell);
6169 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
6170 ec);
6171 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
6172 backlight_binding, ec);
6173 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
6174 ec);
6175 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
6176 backlight_binding, ec);
Daniel Stone325fc2d2012-05-30 16:31:58 +01006177 weston_compositor_add_key_binding(ec, KEY_K, mod,
6178 force_kill_binding, shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006179 weston_compositor_add_key_binding(ec, KEY_UP, mod,
6180 workspace_up_binding, shell);
6181 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
6182 workspace_down_binding, shell);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006183 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
6184 workspace_move_surface_up_binding,
6185 shell);
6186 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
6187 workspace_move_surface_down_binding,
6188 shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006189
Daniel Stonedf8133b2013-11-19 11:37:14 +01006190 weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell);
6191
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006192 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
6193 if (shell->workspaces.num > 1) {
6194 num_workspace_bindings = shell->workspaces.num;
6195 if (num_workspace_bindings > 6)
6196 num_workspace_bindings = 6;
6197 for (i = 0; i < num_workspace_bindings; i++)
6198 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
6199 workspace_f_binding,
6200 shell);
6201 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02006202
6203 /* Debug bindings */
6204 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
6205 debug_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006206}
6207
Kristian Høgsberg1c562182011-05-02 22:09:20 -04006208WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -05006209module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -07006210 int *argc, char *argv[])
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006211{
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04006212 struct weston_seat *seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03006213 struct desktop_shell *shell;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006214 struct workspace **pws;
6215 unsigned int i;
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006216 struct wl_event_loop *loop;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04006217
Peter Huttererf3d62272013-08-08 11:57:05 +10006218 shell = zalloc(sizeof *shell);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04006219 if (shell == NULL)
6220 return -1;
6221
Kristian Høgsberg75840622011-09-06 13:48:16 -04006222 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04006223
6224 shell->destroy_listener.notify = shell_destroy;
6225 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02006226 shell->idle_listener.notify = idle_handler;
6227 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
6228 shell->wake_listener.notify = wake_handler;
6229 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006230 shell->show_input_panel_listener.notify = show_input_panels;
6231 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
6232 shell->hide_input_panel_listener.notify = hide_input_panels;
6233 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
Jan Arne Petersen14da96b2013-04-18 16:47:28 +02006234 shell->update_input_panel_listener.notify = update_input_panels;
6235 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
Scott Moreauff1db4a2012-04-17 19:06:18 -06006236 ec->ping_handler = ping_handler;
Kristian Høgsberg82a1d112012-07-19 14:02:00 -04006237 ec->shell_interface.shell = shell;
Tiago Vignattibc052c92012-04-19 16:18:18 +03006238 ec->shell_interface.create_shell_surface = create_shell_surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05006239 ec->shell_interface.get_primary_view = get_primary_view;
Tiago Vignattibc052c92012-04-19 16:18:18 +03006240 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04006241 ec->shell_interface.set_transient = set_transient;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05006242 ec->shell_interface.set_fullscreen = set_fullscreen;
Tiago Vignattifb2adba2013-06-12 15:43:21 -03006243 ec->shell_interface.set_xwayland = set_xwayland;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04006244 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04006245 ec->shell_interface.resize = surface_resize;
Giulio Camuffo62942ad2013-09-11 18:20:47 +02006246 ec->shell_interface.set_title = set_title;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006247
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006248 wl_list_init(&shell->input_panel.surfaces);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02006249
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05006250 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
6251 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006252 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
6253 weston_layer_init(&shell->lock_layer, NULL);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02006254 weston_layer_init(&shell->input_panel_layer, NULL);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006255
6256 wl_array_init(&shell->workspaces.array);
Jonas Ådahle9d22502012-08-29 22:13:01 +02006257 wl_list_init(&shell->workspaces.client_list);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05006258
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04006259 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02006260
Daniel Stonedf8133b2013-11-19 11:37:14 +01006261 shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE;
6262 shell->exposay.state_target = EXPOSAY_TARGET_CANCEL;
6263
Jonas Ådahle3cddce2012-06-13 00:01:22 +02006264 for (i = 0; i < shell->workspaces.num; i++) {
6265 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
6266 if (pws == NULL)
6267 return -1;
6268
6269 *pws = workspace_create();
6270 if (*pws == NULL)
6271 return -1;
6272 }
6273 activate_workspace(shell, 0);
6274
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02006275 wl_list_init(&shell->workspaces.anim_sticky_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02006276 wl_list_init(&shell->workspaces.animation.link);
6277 shell->workspaces.animation.frame = animate_workspace_change_frame;
6278
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006279 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04006280 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006281 return -1;
6282
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006283 if (wl_global_create(ec->wl_display,
6284 &desktop_shell_interface, 2,
6285 shell, bind_desktop_shell) == NULL)
Kristian Høgsberg75840622011-09-06 13:48:16 -04006286 return -1;
6287
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006288 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
6289 shell, bind_screensaver) == NULL)
Pekka Paalanen6e168112011-11-24 11:34:05 +02006290 return -1;
6291
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006292 if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1,
Jan Arne Petersen42feced2012-06-21 21:52:17 +02006293 shell, bind_input_panel) == NULL)
6294 return -1;
6295
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04006296 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
6297 shell, bind_workspace_manager) == NULL)
Jonas Ådahle9d22502012-08-29 22:13:01 +02006298 return -1;
6299
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05006300 shell->child.deathstamp = weston_compositor_get_time();
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006301
Xiong Zhang6b481422013-10-23 13:58:32 +08006302 setup_output_destroy_handler(ec, shell);
6303
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03006304 loop = wl_display_get_event_loop(ec->wl_display);
6305 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02006306
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02006307 shell->screensaver.timer =
6308 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
6309
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04006310 wl_list_for_each(seat, &ec->seat_list, link)
6311 create_pointer_focus_listener(seat);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04006312
Tiago Vignatti0b52d482012-04-20 18:54:25 +03006313 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04006314
Pekka Paalanen79346ab2013-05-22 18:03:09 +03006315 shell_fade_init(shell);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02006316
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05006317 return 0;
6318}