blob: 7ee462fc54b70c517508d675cebd08d93c855fbe [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>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050029#include <string.h>
30#include <unistd.h>
Kristian Høgsberg07937562011-04-12 17:25:42 -040031#include <linux/input.h>
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +020032#include <assert.h>
Pekka Paalanen18027e52011-12-02 16:31:49 +020033#include <signal.h>
Pekka Paalanen460099f2012-01-20 16:48:25 +020034#include <math.h>
Kristian Høgsberg92a57db2012-05-26 13:41:06 -040035#include <sys/types.h>
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050036
Kristian Høgsberg1ef23132013-12-04 00:20:01 -080037#include "shell.h"
Kristian Høgsberg75840622011-09-06 13:48:16 -040038#include "desktop-shell-server-protocol.h"
Jonas Ådahle9d22502012-08-29 22:13:01 +020039#include "workspaces-server-protocol.h"
Pekka Paalanene955f1e2011-12-07 11:49:52 +020040#include "../shared/config-parser.h"
Rafael Antognollie2a34552013-12-03 15:35:45 -020041#include "xdg-shell-server-protocol.h"
Kristian Høgsberg4cca3492011-01-18 07:53:49 -050042
Jonas Ådahle3cddce2012-06-13 00:01:22 +020043#define DEFAULT_NUM_WORKSPACES 1
Jonas Ådahl62fcd042012-06-13 00:01:23 +020044#define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
Jonas Ådahle3cddce2012-06-13 00:01:22 +020045
Giulio Camuffo1aaf3e42013-12-09 22:47:58 +010046#ifndef static_assert
47#define static_assert(cond, msg)
48#endif
49
Jonas Ådahl04769742012-06-13 00:01:24 +020050struct focus_state {
51 struct weston_seat *seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -040052 struct workspace *ws;
Jonas Ådahl04769742012-06-13 00:01:24 +020053 struct weston_surface *keyboard_focus;
54 struct wl_list link;
55 struct wl_listener seat_destroy_listener;
56 struct wl_listener surface_destroy_listener;
57};
58
Xiong Zhang6b481422013-10-23 13:58:32 +080059struct shell_output {
60 struct desktop_shell *shell;
61 struct weston_output *output;
62 struct wl_listener destroy_listener;
63 struct wl_list link;
64};
65
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050066enum shell_surface_type {
Pekka Paalanen98262232011-12-01 10:42:22 +020067 SHELL_SURFACE_NONE,
Kristian Høgsbergd2abb832011-11-23 10:52:40 -050068 SHELL_SURFACE_TOPLEVEL,
Tiago Vignattifb2adba2013-06-12 15:43:21 -030069 SHELL_SURFACE_POPUP,
70 SHELL_SURFACE_XWAYLAND
Pekka Paalanen57da4a82011-11-23 16:42:16 +020071};
72
Scott Moreauff1db4a2012-04-17 19:06:18 -060073struct ping_timer {
74 struct wl_event_source *source;
Scott Moreauff1db4a2012-04-17 19:06:18 -060075 uint32_t serial;
76};
77
Philip Withnall648a4dd2013-11-25 18:01:44 +000078/*
79 * Surface stacking and ordering.
80 *
81 * This is handled using several linked lists of surfaces, organised into
82 * ‘layers’. The layers are ordered, and each of the surfaces in one layer are
83 * above all of the surfaces in the layer below. The set of layers is static and
84 * in the following order (top-most first):
85 * • Lock layer (only ever displayed on its own)
86 * • Cursor layer
87 * • Fullscreen layer
88 * • Panel layer
89 * • Input panel layer
90 * • Workspace layers
91 * • Background layer
92 *
93 * The list of layers may be manipulated to remove whole layers of surfaces from
94 * display. For example, when locking the screen, all layers except the lock
95 * layer are removed.
96 *
97 * A surface’s layer is modified on configuring the surface, in
98 * set_surface_type() (which is only called when the surface’s type change is
99 * _committed_). If a surface’s type changes (e.g. when making a window
100 * fullscreen) its layer changes too.
101 *
102 * In order to allow popup and transient surfaces to be correctly stacked above
103 * their parent surfaces, each surface tracks both its parent surface, and a
104 * linked list of its children. When a surface’s layer is updated, so are the
105 * layers of its children. Note that child surfaces are *not* the same as
106 * subsurfaces — child/parent surfaces are purely for maintaining stacking
107 * order.
108 *
109 * The children_link list of siblings of a surface (i.e. those surfaces which
110 * have the same parent) only contains weston_surfaces which have a
111 * shell_surface. Stacking is not implemented for non-shell_surface
112 * weston_surfaces. This means that the following implication does *not* hold:
113 * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link)
114 */
115
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200116struct shell_surface {
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500117 struct wl_resource *resource;
118 struct wl_signal destroy_signal;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200119
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500120 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500121 struct weston_view *view;
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600122 int32_t last_width, last_height;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200123 struct wl_listener surface_destroy_listener;
Kristian Høgsberg8150b192012-06-27 10:22:58 -0400124 struct weston_surface *parent;
Philip Withnall648a4dd2013-11-25 18:01:44 +0000125 struct wl_list children_list; /* child surfaces of this one */
126 struct wl_list children_link; /* sibling surfaces of this one */
Tiago Vignattibe143262012-04-16 17:31:41 +0300127 struct desktop_shell *shell;
Pekka Paalanen57da4a82011-11-23 16:42:16 +0200128
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -0800129 enum shell_surface_type type;
Kristian Høgsberge7afd912012-05-02 09:47:44 -0400130 char *title, *class;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -0500131 int32_t saved_x, saved_y;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -0200132 int32_t saved_width, saved_height;
Alex Wu4539b082012-03-01 12:57:46 +0800133 bool saved_position_valid;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -0200134 bool saved_size_valid;
Alex Wu7bcb8bd2012-04-27 09:07:24 +0800135 bool saved_rotation_valid;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700136 int unresponsive, grabbed;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100137
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500138 struct {
Pekka Paalanen460099f2012-01-20 16:48:25 +0200139 struct weston_transform transform;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500140 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200141 } rotation;
142
143 struct {
Giulio Camuffo5085a752013-03-25 21:42:45 +0100144 struct wl_list grab_link;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500145 int32_t x, y;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100146 struct shell_seat *shseat;
Kristian Høgsberg3730f362012-04-13 12:40:07 -0400147 uint32_t serial;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500148 } popup;
149
Alex Wu4539b082012-03-01 12:57:46 +0800150 struct {
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300151 int32_t x, y;
Tiago Vignatti491bac12012-05-18 16:37:43 -0400152 uint32_t flags;
Tiago Vignatti52e598c2012-05-07 15:23:08 +0300153 } transient;
154
155 struct {
Alex Wu4539b082012-03-01 12:57:46 +0800156 enum wl_shell_surface_fullscreen_method type;
157 struct weston_transform transform; /* matrix from x, y */
158 uint32_t framerate;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500159 struct weston_view *black_view;
Alex Wu4539b082012-03-01 12:57:46 +0800160 } fullscreen;
161
Scott Moreauff1db4a2012-04-17 19:06:18 -0600162 struct ping_timer *ping_timer;
163
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200164 struct weston_transform workspace_transform;
165
Kristian Høgsberg1cbf3262012-02-17 23:49:07 -0500166 struct weston_output *fullscreen_output;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500167 struct weston_output *output;
Rafael Antognolli65f98d82013-12-03 15:35:47 -0200168 struct weston_output *recommended_output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100169 struct wl_list link;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400170
171 const struct weston_shell_client *client;
Rafael Antognolli03b16592013-12-03 15:35:42 -0200172
173 struct {
174 bool maximized;
175 bool fullscreen;
Rafael Antognollied207b42013-12-03 15:35:43 -0200176 bool relative;
Rafael Antognolli03b16592013-12-03 15:35:42 -0200177 } state, next_state; /* surface states */
178 bool state_changed;
Pekka Paalanen56cdea92011-11-23 16:14:12 +0200179};
180
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300181struct shell_grab {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400182 struct weston_pointer_grab grab;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300183 struct shell_surface *shsurf;
184 struct wl_listener shsurf_destroy_listener;
185};
186
Rusty Lynch1084da52013-08-15 09:10:08 -0700187struct shell_touch_grab {
188 struct weston_touch_grab grab;
189 struct shell_surface *shsurf;
190 struct wl_listener shsurf_destroy_listener;
191 struct weston_touch *touch;
192};
193
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300194struct weston_move_grab {
195 struct shell_grab base;
Daniel Stone103db7f2012-05-08 17:17:55 +0100196 wl_fixed_t dx, dy;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -0500197};
198
Rusty Lynch1084da52013-08-15 09:10:08 -0700199struct weston_touch_move_grab {
200 struct shell_touch_grab base;
201 wl_fixed_t dx, dy;
202};
203
Pekka Paalanen460099f2012-01-20 16:48:25 +0200204struct rotate_grab {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300205 struct shell_grab base;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -0500206 struct weston_matrix rotation;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200207 struct {
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200208 float x;
209 float y;
Pekka Paalanen460099f2012-01-20 16:48:25 +0200210 } center;
211};
212
Giulio Camuffo5085a752013-03-25 21:42:45 +0100213struct shell_seat {
214 struct weston_seat *seat;
215 struct wl_listener seat_destroy_listener;
216
217 struct {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400218 struct weston_pointer_grab grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +0100219 struct wl_list surfaces_list;
220 struct wl_client *client;
221 int32_t initial_up;
222 } popup_grab;
223};
224
Alex Wubd3354b2012-04-17 17:20:49 +0800225static struct desktop_shell *
226shell_surface_get_shell(struct shell_surface *shsurf);
227
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500228static void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400229surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -0500230
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300231static void
232shell_fade_startup(struct desktop_shell *shell);
233
Philip Withnallbecb77e2013-11-25 18:01:30 +0000234static struct shell_seat *
235get_shell_seat(struct weston_seat *seat);
236
Philip Withnall648a4dd2013-11-25 18:01:44 +0000237static void
238shell_surface_update_child_surface_layers(struct shell_surface *shsurf);
239
Alex Wubd3354b2012-04-17 17:20:49 +0800240static bool
Rafael Antognollie2a34552013-12-03 15:35:45 -0200241shell_surface_is_wl_shell_surface(struct shell_surface *shsurf);
242
243static bool
244shell_surface_is_xdg_surface(struct shell_surface *shsurf);
245
246static bool
247shell_surface_is_xdg_popup(struct shell_surface *shsurf);
248
249static void
250shell_surface_set_parent(struct shell_surface *shsurf,
251 struct weston_surface *parent);
252
253static bool
Alex Wubd3354b2012-04-17 17:20:49 +0800254shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
255{
256 struct desktop_shell *shell;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500257 struct weston_view *top_fs_ev;
Alex Wubd3354b2012-04-17 17:20:49 +0800258
259 shell = shell_surface_get_shell(shsurf);
Quentin Glidicc0d79ce2013-01-29 14:16:13 +0100260
Jason Ekstranda7af7042013-10-12 22:38:11 -0500261 if (wl_list_empty(&shell->fullscreen_layer.view_list))
Alex Wubd3354b2012-04-17 17:20:49 +0800262 return false;
263
Jason Ekstranda7af7042013-10-12 22:38:11 -0500264 top_fs_ev = container_of(shell->fullscreen_layer.view_list.next,
265 struct weston_view,
Alex Wubd3354b2012-04-17 17:20:49 +0800266 layer_link);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500267 return (shsurf == get_shell_surface(top_fs_ev->surface));
Alex Wubd3354b2012-04-17 17:20:49 +0800268}
269
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -0500270static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400271destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300272{
273 struct shell_grab *grab;
274
275 grab = container_of(listener, struct shell_grab,
276 shsurf_destroy_listener);
277
278 grab->shsurf = NULL;
279}
280
Kristian Høgsberg1ef23132013-12-04 00:20:01 -0800281struct weston_view *
Jason Ekstranda7af7042013-10-12 22:38:11 -0500282get_default_view(struct weston_surface *surface)
283{
284 struct shell_surface *shsurf;
285 struct weston_view *view;
286
287 if (!surface || wl_list_empty(&surface->views))
288 return NULL;
289
290 shsurf = get_shell_surface(surface);
291 if (shsurf)
292 return shsurf->view;
293
294 wl_list_for_each(view, &surface->views, surface_link)
295 if (weston_view_is_mapped(view))
296 return view;
297
298 return container_of(surface->views.next, struct weston_view, surface_link);
299}
300
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300301static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400302popup_grab_end(struct weston_pointer *pointer);
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400303
304static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300305shell_grab_start(struct shell_grab *grab,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400306 const struct weston_pointer_grab_interface *interface,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300307 struct shell_surface *shsurf,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400308 struct weston_pointer *pointer,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300309 enum desktop_shell_cursor cursor)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300310{
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300311 struct desktop_shell *shell = shsurf->shell;
312
Kristian Høgsberg57e09072012-10-30 14:07:27 -0400313 popup_grab_end(pointer);
314
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300315 grab->grab.interface = interface;
316 grab->shsurf = shsurf;
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400317 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500318 wl_signal_add(&shsurf->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400319 &grab->shsurf_destroy_listener);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300320
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700321 shsurf->grabbed = 1;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400322 weston_pointer_start_grab(pointer, &grab->grab);
Kristian Høgsbergc9974a02013-07-03 19:24:57 -0400323 if (shell->child.desktop_shell) {
324 desktop_shell_send_grab_cursor(shell->child.desktop_shell,
325 cursor);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500326 weston_pointer_set_focus(pointer,
327 get_default_view(shell->grab_surface),
Kristian Høgsbergc9974a02013-07-03 19:24:57 -0400328 wl_fixed_from_int(0),
329 wl_fixed_from_int(0));
330 }
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300331}
332
333static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300334shell_grab_end(struct shell_grab *grab)
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300335{
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700336 if (grab->shsurf) {
Kristian Høgsberg47b5dca2012-06-07 18:08:04 -0400337 wl_list_remove(&grab->shsurf_destroy_listener.link);
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700338 grab->shsurf->grabbed = 0;
339 }
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300340
Kristian Høgsberg9e5d7d12013-07-22 16:31:53 -0700341 weston_pointer_end_grab(grab->grab.pointer);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +0300342}
343
344static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700345shell_touch_grab_start(struct shell_touch_grab *grab,
346 const struct weston_touch_grab_interface *interface,
347 struct shell_surface *shsurf,
348 struct weston_touch *touch)
349{
350 struct desktop_shell *shell = shsurf->shell;
351
352 grab->grab.interface = interface;
353 grab->shsurf = shsurf;
354 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
355 wl_signal_add(&shsurf->destroy_signal,
356 &grab->shsurf_destroy_listener);
357
358 grab->touch = touch;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700359 shsurf->grabbed = 1;
Rusty Lynch1084da52013-08-15 09:10:08 -0700360
361 weston_touch_start_grab(touch, &grab->grab);
362 if (shell->child.desktop_shell)
Jason Ekstranda7af7042013-10-12 22:38:11 -0500363 weston_touch_set_focus(touch->seat,
364 get_default_view(shell->grab_surface));
Rusty Lynch1084da52013-08-15 09:10:08 -0700365}
366
367static void
368shell_touch_grab_end(struct shell_touch_grab *grab)
369{
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700370 if (grab->shsurf) {
Rusty Lynch1084da52013-08-15 09:10:08 -0700371 wl_list_remove(&grab->shsurf_destroy_listener.link);
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -0700372 grab->shsurf->grabbed = 0;
373 }
Rusty Lynch1084da52013-08-15 09:10:08 -0700374
375 weston_touch_end_grab(grab->touch);
376}
377
378static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500379center_on_output(struct weston_view *view,
Alex Wu4539b082012-03-01 12:57:46 +0800380 struct weston_output *output);
381
Daniel Stone496ca172012-05-30 16:31:42 +0100382static enum weston_keyboard_modifier
Tiago Vignatti0b52d482012-04-20 18:54:25 +0300383get_modifier(char *modifier)
384{
385 if (!modifier)
386 return MODIFIER_SUPER;
387
388 if (!strcmp("ctrl", modifier))
389 return MODIFIER_CTRL;
390 else if (!strcmp("alt", modifier))
391 return MODIFIER_ALT;
392 else if (!strcmp("super", modifier))
393 return MODIFIER_SUPER;
394 else
395 return MODIFIER_SUPER;
396}
397
Juan Zhaoe10d2792012-04-25 19:09:52 +0800398static enum animation_type
399get_animation_type(char *animation)
400{
Juan Zhaoe10d2792012-04-25 19:09:52 +0800401 if (!strcmp("zoom", animation))
402 return ANIMATION_ZOOM;
403 else if (!strcmp("fade", animation))
404 return ANIMATION_FADE;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100405 else if (!strcmp("dim-layer", animation))
406 return ANIMATION_DIM_LAYER;
Juan Zhaoe10d2792012-04-25 19:09:52 +0800407 else
408 return ANIMATION_NONE;
409}
410
Alex Wu4539b082012-03-01 12:57:46 +0800411static void
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400412shell_configuration(struct desktop_shell *shell)
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200413{
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400414 struct weston_config_section *section;
415 int duration;
416 char *s;
Pekka Paalanene955f1e2011-12-07 11:49:52 +0200417
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400418 section = weston_config_get_section(shell->compositor->config,
419 "screensaver", NULL, NULL);
420 weston_config_section_get_string(section,
421 "path", &shell->screensaver.path, NULL);
422 weston_config_section_get_int(section, "duration", &duration, 60);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +0200423 shell->screensaver.duration = duration * 1000;
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400424
425 section = weston_config_get_section(shell->compositor->config,
426 "shell", NULL, NULL);
427 weston_config_section_get_string(section,
Emilio Pozuelo Monfort8a81b832013-12-02 12:53:32 +0100428 "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT);
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +0100429 shell->client = s;
430 weston_config_section_get_string(section,
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400431 "binding-modifier", &s, "super");
432 shell->binding_modifier = get_modifier(s);
Quentin Glidic8418c292013-06-18 09:11:03 +0200433 free(s);
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400434 weston_config_section_get_string(section, "animation", &s, "none");
435 shell->win_animation_type = get_animation_type(s);
Quentin Glidic8418c292013-06-18 09:11:03 +0200436 free(s);
Kristian Høgsberg724c8d92013-10-16 11:38:24 -0700437 weston_config_section_get_string(section,
438 "startup-animation", &s, "fade");
439 shell->startup_animation_type = get_animation_type(s);
440 free(s);
Kristian Høgsberg912e0a12013-10-30 08:59:55 -0700441 if (shell->startup_animation_type == ANIMATION_ZOOM)
442 shell->startup_animation_type = ANIMATION_NONE;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100443 weston_config_section_get_string(section, "focus-animation", &s, "none");
444 shell->focus_animation_type = get_animation_type(s);
445 free(s);
Kristian Høgsberg673a8892013-05-23 21:40:56 -0400446 weston_config_section_get_uint(section, "num-workspaces",
447 &shell->workspaces.num,
448 DEFAULT_NUM_WORKSPACES);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200449}
450
Kristian Høgsberg1ef23132013-12-04 00:20:01 -0800451struct weston_output *
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100452get_default_output(struct weston_compositor *compositor)
453{
454 return container_of(compositor->output_list.next,
455 struct weston_output, link);
456}
457
458
459/* no-op func for checking focus surface */
460static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600461focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100462{
463}
464
465static struct focus_surface *
466get_focus_surface(struct weston_surface *surface)
467{
468 if (surface->configure == focus_surface_configure)
469 return surface->configure_private;
470 else
471 return NULL;
472}
473
474static bool
475is_focus_surface (struct weston_surface *es)
476{
477 return (es->configure == focus_surface_configure);
478}
479
480static bool
481is_focus_view (struct weston_view *view)
482{
483 return is_focus_surface (view->surface);
484}
485
486static struct focus_surface *
487create_focus_surface(struct weston_compositor *ec,
488 struct weston_output *output)
489{
490 struct focus_surface *fsurf = NULL;
491 struct weston_surface *surface = NULL;
492
493 fsurf = malloc(sizeof *fsurf);
494 if (!fsurf)
495 return NULL;
496
497 fsurf->surface = weston_surface_create(ec);
498 surface = fsurf->surface;
499 if (surface == NULL) {
500 free(fsurf);
501 return NULL;
502 }
503
504 surface->configure = focus_surface_configure;
505 surface->output = output;
506 surface->configure_private = fsurf;
507
508 fsurf->view = weston_view_create (surface);
Emilio Pozuelo Monfortda644262013-11-19 11:37:19 +0100509 fsurf->view->output = output;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100510
Jason Ekstrand5c11a332013-12-04 20:32:03 -0600511 weston_surface_set_size(surface, output->width, output->height);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600512 weston_view_set_position(fsurf->view, output->x, output->y);
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100513 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
514 pixman_region32_fini(&surface->opaque);
515 pixman_region32_init_rect(&surface->opaque, output->x, output->y,
516 output->width, output->height);
517 pixman_region32_fini(&surface->input);
518 pixman_region32_init(&surface->input);
519
520 wl_list_init(&fsurf->workspace_transform.link);
521
522 return fsurf;
523}
524
525static void
526focus_surface_destroy(struct focus_surface *fsurf)
527{
528 weston_surface_destroy(fsurf->surface);
529 free(fsurf);
530}
531
532static void
533focus_animation_done(struct weston_view_animation *animation, void *data)
534{
535 struct workspace *ws = data;
536
537 ws->focus_animation = NULL;
538}
539
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200540static void
Jonas Ådahl04769742012-06-13 00:01:24 +0200541focus_state_destroy(struct focus_state *state)
542{
543 wl_list_remove(&state->seat_destroy_listener.link);
544 wl_list_remove(&state->surface_destroy_listener.link);
545 free(state);
546}
547
548static void
549focus_state_seat_destroy(struct wl_listener *listener, void *data)
550{
551 struct focus_state *state = container_of(listener,
552 struct focus_state,
553 seat_destroy_listener);
554
555 wl_list_remove(&state->link);
556 focus_state_destroy(state);
557}
558
559static void
560focus_state_surface_destroy(struct wl_listener *listener, void *data)
561{
562 struct focus_state *state = container_of(listener,
563 struct focus_state,
Kristian Høgsbergb8e0d0f2012-07-31 10:30:26 -0400564 surface_destroy_listener);
Kristian Høgsberge3778222012-07-31 17:29:30 -0400565 struct desktop_shell *shell;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500566 struct weston_surface *main_surface, *next;
567 struct weston_view *view;
Jonas Ådahl04769742012-06-13 00:01:24 +0200568
Pekka Paalanen01388e22013-04-25 13:57:44 +0300569 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
570
Kristian Høgsberge3778222012-07-31 17:29:30 -0400571 next = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500572 wl_list_for_each(view, &state->ws->layer.view_list, layer_link) {
573 if (view->surface == main_surface)
Kristian Høgsberge3778222012-07-31 17:29:30 -0400574 continue;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100575 if (is_focus_view(view))
576 continue;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400577
Jason Ekstranda7af7042013-10-12 22:38:11 -0500578 next = view->surface;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400579 break;
580 }
581
Pekka Paalanen01388e22013-04-25 13:57:44 +0300582 /* if the focus was a sub-surface, activate its main surface */
583 if (main_surface != state->keyboard_focus)
584 next = main_surface;
585
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100586 shell = state->seat->compositor->shell_interface.shell;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400587 if (next) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100588 state->keyboard_focus = NULL;
Kristian Høgsberge3778222012-07-31 17:29:30 -0400589 activate(shell, next, state->seat);
590 } else {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100591 if (shell->focus_animation_type == ANIMATION_DIM_LAYER) {
592 if (state->ws->focus_animation)
593 weston_view_animation_destroy(state->ws->focus_animation);
594
595 state->ws->focus_animation = weston_fade_run(
596 state->ws->fsurf_front->view,
597 state->ws->fsurf_front->view->alpha, 0.0, 300,
598 focus_animation_done, state->ws);
599 }
600
Kristian Høgsberge3778222012-07-31 17:29:30 -0400601 wl_list_remove(&state->link);
602 focus_state_destroy(state);
603 }
Jonas Ådahl04769742012-06-13 00:01:24 +0200604}
605
606static struct focus_state *
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400607focus_state_create(struct weston_seat *seat, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200608{
Jonas Ådahl04769742012-06-13 00:01:24 +0200609 struct focus_state *state;
Jonas Ådahl04769742012-06-13 00:01:24 +0200610
611 state = malloc(sizeof *state);
612 if (state == NULL)
613 return NULL;
614
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100615 state->keyboard_focus = NULL;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400616 state->ws = ws;
Jonas Ådahl04769742012-06-13 00:01:24 +0200617 state->seat = seat;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400618 wl_list_insert(&ws->focus_list, &state->link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200619
620 state->seat_destroy_listener.notify = focus_state_seat_destroy;
621 state->surface_destroy_listener.notify = focus_state_surface_destroy;
Kristian Høgsberg49124542013-05-06 22:27:40 -0400622 wl_signal_add(&seat->destroy_signal,
Jonas Ådahl04769742012-06-13 00:01:24 +0200623 &state->seat_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400624 wl_list_init(&state->surface_destroy_listener.link);
Jonas Ådahl04769742012-06-13 00:01:24 +0200625
626 return state;
627}
628
Jonas Ådahl8538b222012-08-29 22:13:03 +0200629static struct focus_state *
630ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
631{
632 struct workspace *ws = get_current_workspace(shell);
633 struct focus_state *state;
634
635 wl_list_for_each(state, &ws->focus_list, link)
636 if (state->seat == seat)
637 break;
638
639 if (&state->link == &ws->focus_list)
640 state = focus_state_create(seat, ws);
641
642 return state;
643}
644
Jonas Ådahl04769742012-06-13 00:01:24 +0200645static void
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -0400646restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
Jonas Ådahl04769742012-06-13 00:01:24 +0200647{
648 struct focus_state *state, *next;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400649 struct weston_surface *surface;
Jonas Ådahl04769742012-06-13 00:01:24 +0200650
651 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400652 surface = state->keyboard_focus;
Jonas Ådahl56899442012-08-29 22:12:59 +0200653
Kristian Høgsberge3148752013-05-06 23:19:49 -0400654 weston_keyboard_set_focus(state->seat->keyboard, surface);
Jonas Ådahl04769742012-06-13 00:01:24 +0200655 }
656}
657
658static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200659replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
660 struct weston_seat *seat)
661{
662 struct focus_state *state;
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -0400663 struct weston_surface *surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200664
665 wl_list_for_each(state, &ws->focus_list, link) {
666 if (state->seat == seat) {
Kristian Høgsberge3148752013-05-06 23:19:49 -0400667 surface = seat->keyboard->focus;
Jason Ekstrand651f00e2013-06-14 10:07:54 -0500668 state->keyboard_focus = surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200669 return;
670 }
671 }
672}
673
674static void
675drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
676 struct weston_surface *surface)
677{
678 struct focus_state *state;
679
680 wl_list_for_each(state, &ws->focus_list, link)
681 if (state->keyboard_focus == surface)
682 state->keyboard_focus = NULL;
683}
684
685static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100686animate_focus_change(struct desktop_shell *shell, struct workspace *ws,
687 struct weston_view *from, struct weston_view *to)
688{
689 struct weston_output *output;
690 bool focus_surface_created = false;
691
692 /* FIXME: Only support dim animation using two layers */
693 if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER)
694 return;
695
696 output = get_default_output(shell->compositor);
697 if (ws->fsurf_front == NULL && (from || to)) {
698 ws->fsurf_front = create_focus_surface(shell->compositor, output);
699 ws->fsurf_back = create_focus_surface(shell->compositor, output);
700 ws->fsurf_front->view->alpha = 0.0;
701 ws->fsurf_back->view->alpha = 0.0;
702 focus_surface_created = true;
703 } else {
704 wl_list_remove(&ws->fsurf_front->view->layer_link);
705 wl_list_remove(&ws->fsurf_back->view->layer_link);
706 }
707
708 if (ws->focus_animation) {
709 weston_view_animation_destroy(ws->focus_animation);
710 ws->focus_animation = NULL;
711 }
712
713 if (to)
714 wl_list_insert(&to->layer_link,
715 &ws->fsurf_front->view->layer_link);
716 else if (from)
717 wl_list_insert(&ws->layer.view_list,
718 &ws->fsurf_front->view->layer_link);
719
720 if (focus_surface_created) {
721 ws->focus_animation = weston_fade_run(
722 ws->fsurf_front->view,
723 ws->fsurf_front->view->alpha, 0.6, 300,
724 focus_animation_done, ws);
725 } else if (from) {
726 wl_list_insert(&from->layer_link,
727 &ws->fsurf_back->view->layer_link);
728 ws->focus_animation = weston_stable_fade_run(
729 ws->fsurf_front->view, 0.0,
730 ws->fsurf_back->view, 0.6,
731 focus_animation_done, ws);
732 } else if (to) {
733 wl_list_insert(&ws->layer.view_list,
734 &ws->fsurf_back->view->layer_link);
735 ws->focus_animation = weston_stable_fade_run(
736 ws->fsurf_front->view, 0.0,
737 ws->fsurf_back->view, 0.6,
738 focus_animation_done, ws);
739 }
740}
741
742static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200743workspace_destroy(struct workspace *ws)
744{
Jonas Ådahl04769742012-06-13 00:01:24 +0200745 struct focus_state *state, *next;
746
747 wl_list_for_each_safe(state, next, &ws->focus_list, link)
748 focus_state_destroy(state);
749
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100750 if (ws->fsurf_front)
751 focus_surface_destroy(ws->fsurf_front);
752 if (ws->fsurf_back)
753 focus_surface_destroy(ws->fsurf_back);
754
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200755 free(ws);
756}
757
Jonas Ådahl04769742012-06-13 00:01:24 +0200758static void
759seat_destroyed(struct wl_listener *listener, void *data)
760{
761 struct weston_seat *seat = data;
762 struct focus_state *state, *next;
763 struct workspace *ws = container_of(listener,
764 struct workspace,
765 seat_destroyed_listener);
766
767 wl_list_for_each_safe(state, next, &ws->focus_list, link)
768 if (state->seat == seat)
769 wl_list_remove(&state->link);
770}
771
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200772static struct workspace *
773workspace_create(void)
774{
775 struct workspace *ws = malloc(sizeof *ws);
776 if (ws == NULL)
777 return NULL;
778
779 weston_layer_init(&ws->layer, NULL);
780
Jonas Ådahl04769742012-06-13 00:01:24 +0200781 wl_list_init(&ws->focus_list);
782 wl_list_init(&ws->seat_destroyed_listener.link);
783 ws->seat_destroyed_listener.notify = seat_destroyed;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100784 ws->fsurf_front = NULL;
785 ws->fsurf_back = NULL;
786 ws->focus_animation = NULL;
Jonas Ådahl04769742012-06-13 00:01:24 +0200787
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200788 return ws;
789}
790
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200791static int
792workspace_is_empty(struct workspace *ws)
793{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500794 return wl_list_empty(&ws->layer.view_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200795}
796
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200797static struct workspace *
798get_workspace(struct desktop_shell *shell, unsigned int index)
799{
800 struct workspace **pws = shell->workspaces.array.data;
Philipp Brüschweiler067abf62012-09-01 16:03:05 +0200801 assert(index < shell->workspaces.num);
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200802 pws += index;
803 return *pws;
804}
805
Kristian Høgsberg1ef23132013-12-04 00:20:01 -0800806struct workspace *
Jonas Ådahle3cddce2012-06-13 00:01:22 +0200807get_current_workspace(struct desktop_shell *shell)
808{
809 return get_workspace(shell, shell->workspaces.current);
810}
811
812static void
813activate_workspace(struct desktop_shell *shell, unsigned int index)
814{
815 struct workspace *ws;
816
817 ws = get_workspace(shell, index);
818 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
819
820 shell->workspaces.current = index;
821}
822
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200823static unsigned int
824get_output_height(struct weston_output *output)
825{
826 return abs(output->region.extents.y1 - output->region.extents.y2);
827}
828
829static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100830view_translate(struct workspace *ws, struct weston_view *view, double d)
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200831{
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200832 struct weston_transform *transform;
833
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100834 if (is_focus_view(view)) {
835 struct focus_surface *fsurf = get_focus_surface(view->surface);
836 transform = &fsurf->workspace_transform;
837 } else {
838 struct shell_surface *shsurf = get_shell_surface(view->surface);
839 transform = &shsurf->workspace_transform;
840 }
841
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200842 if (wl_list_empty(&transform->link))
Jason Ekstranda7af7042013-10-12 22:38:11 -0500843 wl_list_insert(view->geometry.transformation_list.prev,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100844 &transform->link);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200845
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100846 weston_matrix_init(&transform->matrix);
847 weston_matrix_translate(&transform->matrix,
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200848 0.0, d, 0.0);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500849 weston_view_geometry_dirty(view);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200850}
851
852static void
853workspace_translate_out(struct workspace *ws, double fraction)
854{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500855 struct weston_view *view;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200856 unsigned int height;
857 double d;
858
Jason Ekstranda7af7042013-10-12 22:38:11 -0500859 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
860 height = get_output_height(view->surface->output);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200861 d = height * fraction;
862
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100863 view_translate(ws, view, d);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200864 }
865}
866
867static void
868workspace_translate_in(struct workspace *ws, double fraction)
869{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500870 struct weston_view *view;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200871 unsigned int height;
872 double d;
873
Jason Ekstranda7af7042013-10-12 22:38:11 -0500874 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
875 height = get_output_height(view->surface->output);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200876
877 if (fraction > 0)
878 d = -(height - height * fraction);
879 else
880 d = height + height * fraction;
881
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100882 view_translate(ws, view, d);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200883 }
884}
885
886static void
Jonas Ådahle9d22502012-08-29 22:13:01 +0200887broadcast_current_workspace_state(struct desktop_shell *shell)
888{
Kristian Høgsberg2e3c3962013-09-11 12:00:47 -0700889 struct wl_resource *resource;
Jonas Ådahle9d22502012-08-29 22:13:01 +0200890
Kristian Høgsberg2e3c3962013-09-11 12:00:47 -0700891 wl_resource_for_each(resource, &shell->workspaces.client_list)
892 workspace_manager_send_state(resource,
Jonas Ådahle9d22502012-08-29 22:13:01 +0200893 shell->workspaces.current,
894 shell->workspaces.num);
895}
896
897static void
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200898reverse_workspace_change_animation(struct desktop_shell *shell,
899 unsigned int index,
900 struct workspace *from,
901 struct workspace *to)
902{
903 shell->workspaces.current = index;
904
905 shell->workspaces.anim_to = to;
906 shell->workspaces.anim_from = from;
907 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
908 shell->workspaces.anim_timestamp = 0;
909
Scott Moreau4272e632012-08-13 09:58:41 -0600910 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200911}
912
913static void
914workspace_deactivate_transforms(struct workspace *ws)
915{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500916 struct weston_view *view;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100917 struct weston_transform *transform;
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200918
Jason Ekstranda7af7042013-10-12 22:38:11 -0500919 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100920 if (is_focus_view(view)) {
921 struct focus_surface *fsurf = get_focus_surface(view->surface);
922 transform = &fsurf->workspace_transform;
923 } else {
924 struct shell_surface *shsurf = get_shell_surface(view->surface);
925 transform = &shsurf->workspace_transform;
926 }
927
928 if (!wl_list_empty(&transform->link)) {
929 wl_list_remove(&transform->link);
930 wl_list_init(&transform->link);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +0200931 }
Jason Ekstranda7af7042013-10-12 22:38:11 -0500932 weston_view_geometry_dirty(view);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200933 }
934}
935
936static void
937finish_workspace_change_animation(struct desktop_shell *shell,
938 struct workspace *from,
939 struct workspace *to)
940{
Scott Moreau4272e632012-08-13 09:58:41 -0600941 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200942
943 wl_list_remove(&shell->workspaces.animation.link);
944 workspace_deactivate_transforms(from);
945 workspace_deactivate_transforms(to);
946 shell->workspaces.anim_to = NULL;
947
948 wl_list_remove(&shell->workspaces.anim_from->layer.link);
949}
950
951static void
952animate_workspace_change_frame(struct weston_animation *animation,
953 struct weston_output *output, uint32_t msecs)
954{
955 struct desktop_shell *shell =
956 container_of(animation, struct desktop_shell,
957 workspaces.animation);
958 struct workspace *from = shell->workspaces.anim_from;
959 struct workspace *to = shell->workspaces.anim_to;
960 uint32_t t;
961 double x, y;
962
963 if (workspace_is_empty(from) && workspace_is_empty(to)) {
964 finish_workspace_change_animation(shell, from, to);
965 return;
966 }
967
968 if (shell->workspaces.anim_timestamp == 0) {
969 if (shell->workspaces.anim_current == 0.0)
970 shell->workspaces.anim_timestamp = msecs;
971 else
972 shell->workspaces.anim_timestamp =
973 msecs -
974 /* Invers of movement function 'y' below. */
975 (asin(1.0 - shell->workspaces.anim_current) *
976 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
977 M_2_PI);
978 }
979
980 t = msecs - shell->workspaces.anim_timestamp;
981
982 /*
983 * x = [0, π/2]
984 * y(x) = sin(x)
985 */
986 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
987 y = sin(x);
988
989 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
Scott Moreau4272e632012-08-13 09:58:41 -0600990 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200991
992 workspace_translate_out(from, shell->workspaces.anim_dir * y);
993 workspace_translate_in(to, shell->workspaces.anim_dir * y);
994 shell->workspaces.anim_current = y;
995
Scott Moreau4272e632012-08-13 09:58:41 -0600996 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200997 }
Jonas Ådahl04769742012-06-13 00:01:24 +0200998 else
Jonas Ådahl62fcd042012-06-13 00:01:23 +0200999 finish_workspace_change_animation(shell, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001000}
1001
1002static void
1003animate_workspace_change(struct desktop_shell *shell,
1004 unsigned int index,
1005 struct workspace *from,
1006 struct workspace *to)
1007{
1008 struct weston_output *output;
1009
1010 int dir;
1011
1012 if (index > shell->workspaces.current)
1013 dir = -1;
1014 else
1015 dir = 1;
1016
1017 shell->workspaces.current = index;
1018
1019 shell->workspaces.anim_dir = dir;
1020 shell->workspaces.anim_from = from;
1021 shell->workspaces.anim_to = to;
1022 shell->workspaces.anim_current = 0.0;
1023 shell->workspaces.anim_timestamp = 0;
1024
1025 output = container_of(shell->compositor->output_list.next,
1026 struct weston_output, link);
1027 wl_list_insert(&output->animation_list,
1028 &shell->workspaces.animation.link);
1029
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001030 wl_list_insert(from->layer.link.prev, &to->layer.link);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001031
1032 workspace_translate_in(to, 0);
1033
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04001034 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +02001035
Scott Moreau4272e632012-08-13 09:58:41 -06001036 weston_compositor_schedule_repaint(shell->compositor);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001037}
1038
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001039static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001040update_workspace(struct desktop_shell *shell, unsigned int index,
1041 struct workspace *from, struct workspace *to)
1042{
1043 shell->workspaces.current = index;
1044 wl_list_insert(&from->layer.link, &to->layer.link);
1045 wl_list_remove(&from->layer.link);
1046}
1047
1048static void
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001049change_workspace(struct desktop_shell *shell, unsigned int index)
1050{
1051 struct workspace *from;
1052 struct workspace *to;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001053 struct focus_state *state;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001054
1055 if (index == shell->workspaces.current)
1056 return;
1057
1058 /* Don't change workspace when there is any fullscreen surfaces. */
Jason Ekstranda7af7042013-10-12 22:38:11 -05001059 if (!wl_list_empty(&shell->fullscreen_layer.view_list))
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001060 return;
1061
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001062 from = get_current_workspace(shell);
1063 to = get_workspace(shell, index);
1064
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001065 if (shell->workspaces.anim_from == to &&
1066 shell->workspaces.anim_to == from) {
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001067 restore_focus_state(shell, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001068 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001069 broadcast_current_workspace_state(shell);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001070 return;
1071 }
Jonas Ådahle3cddce2012-06-13 00:01:22 +02001072
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001073 if (shell->workspaces.anim_to != NULL)
1074 finish_workspace_change_animation(shell,
1075 shell->workspaces.anim_from,
1076 shell->workspaces.anim_to);
1077
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001078 restore_focus_state(shell, to);
Jonas Ådahl04769742012-06-13 00:01:24 +02001079
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001080 if (shell->focus_animation_type != ANIMATION_NONE) {
1081 wl_list_for_each(state, &from->focus_list, link)
1082 if (state->keyboard_focus)
1083 animate_focus_change(shell, from,
1084 get_default_view(state->keyboard_focus), NULL);
1085
1086 wl_list_for_each(state, &to->focus_list, link)
1087 if (state->keyboard_focus)
1088 animate_focus_change(shell, to,
1089 NULL, get_default_view(state->keyboard_focus));
1090 }
1091
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001092 if (workspace_is_empty(to) && workspace_is_empty(from))
1093 update_workspace(shell, index, from, to);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02001094 else
1095 animate_workspace_change(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001096
1097 broadcast_current_workspace_state(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02001098}
1099
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001100static bool
1101workspace_has_only(struct workspace *ws, struct weston_surface *surface)
1102{
Jason Ekstranda7af7042013-10-12 22:38:11 -05001103 struct wl_list *list = &ws->layer.view_list;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001104 struct wl_list *e;
1105
1106 if (wl_list_empty(list))
1107 return false;
1108
1109 e = list->next;
1110
1111 if (e->next != list)
1112 return false;
1113
Jason Ekstranda7af7042013-10-12 22:38:11 -05001114 return container_of(e, struct weston_view, layer_link)->surface == surface;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001115}
1116
1117static void
Philip Withnall659163d2013-11-25 18:01:36 +00001118move_surface_to_workspace(struct desktop_shell *shell,
1119 struct shell_surface *shsurf,
1120 uint32_t workspace)
Jonas Ådahle9d22502012-08-29 22:13:01 +02001121{
1122 struct workspace *from;
1123 struct workspace *to;
1124 struct weston_seat *seat;
Pekka Paalanen01388e22013-04-25 13:57:44 +03001125 struct weston_surface *focus;
Philip Withnall659163d2013-11-25 18:01:36 +00001126 struct weston_view *view;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001127
1128 if (workspace == shell->workspaces.current)
1129 return;
1130
Philip Withnall659163d2013-11-25 18:01:36 +00001131 view = get_default_view(shsurf->surface);
1132 if (!view)
1133 return;
1134
1135 assert(weston_surface_get_main_surface(view->surface) == view->surface);
1136
Philipp Brüschweiler067abf62012-09-01 16:03:05 +02001137 if (workspace >= shell->workspaces.num)
1138 workspace = shell->workspaces.num - 1;
1139
Jonas Ådahle9d22502012-08-29 22:13:01 +02001140 from = get_current_workspace(shell);
1141 to = get_workspace(shell, workspace);
1142
Jason Ekstranda7af7042013-10-12 22:38:11 -05001143 wl_list_remove(&view->layer_link);
1144 wl_list_insert(&to->layer.view_list, &view->layer_link);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001145
Philip Withnall648a4dd2013-11-25 18:01:44 +00001146 shell_surface_update_child_surface_layers(shsurf);
1147
Jason Ekstranda7af7042013-10-12 22:38:11 -05001148 drop_focus_state(shell, from, view->surface);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001149 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1150 if (!seat->keyboard)
1151 continue;
1152
1153 focus = weston_surface_get_main_surface(seat->keyboard->focus);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001154 if (focus == view->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001155 weston_keyboard_set_focus(seat->keyboard, NULL);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001156 }
Jonas Ådahle9d22502012-08-29 22:13:01 +02001157
Jason Ekstranda7af7042013-10-12 22:38:11 -05001158 weston_view_damage_below(view);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001159}
1160
1161static void
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001162take_surface_to_workspace_by_seat(struct desktop_shell *shell,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001163 struct weston_seat *seat,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001164 unsigned int index)
1165{
Pekka Paalanen01388e22013-04-25 13:57:44 +03001166 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001167 struct weston_view *view;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001168 struct shell_surface *shsurf;
1169 struct workspace *from;
1170 struct workspace *to;
Jonas Ådahl8538b222012-08-29 22:13:03 +02001171 struct focus_state *state;
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001172
Pekka Paalanen01388e22013-04-25 13:57:44 +03001173 surface = weston_surface_get_main_surface(seat->keyboard->focus);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001174 view = get_default_view(surface);
1175 if (view == NULL ||
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01001176 index == shell->workspaces.current ||
1177 is_focus_view(view))
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001178 return;
1179
1180 from = get_current_workspace(shell);
1181 to = get_workspace(shell, index);
1182
Jason Ekstranda7af7042013-10-12 22:38:11 -05001183 wl_list_remove(&view->layer_link);
1184 wl_list_insert(&to->layer.view_list, &view->layer_link);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001185
Philip Withnall659163d2013-11-25 18:01:36 +00001186 shsurf = get_shell_surface(surface);
Philip Withnall648a4dd2013-11-25 18:01:44 +00001187 if (shsurf != NULL)
1188 shell_surface_update_child_surface_layers(shsurf);
Philip Withnall659163d2013-11-25 18:01:36 +00001189
Jonas Ådahle9d22502012-08-29 22:13:01 +02001190 replace_focus_state(shell, to, seat);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001191 drop_focus_state(shell, from, surface);
1192
1193 if (shell->workspaces.anim_from == to &&
1194 shell->workspaces.anim_to == from) {
Jonas Ådahle9d22502012-08-29 22:13:01 +02001195 wl_list_remove(&to->layer.link);
1196 wl_list_insert(from->layer.link.prev, &to->layer.link);
1197
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001198 reverse_workspace_change_animation(shell, index, from, to);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001199 broadcast_current_workspace_state(shell);
1200
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001201 return;
1202 }
1203
1204 if (shell->workspaces.anim_to != NULL)
1205 finish_workspace_change_animation(shell,
1206 shell->workspaces.anim_from,
1207 shell->workspaces.anim_to);
1208
1209 if (workspace_is_empty(from) &&
1210 workspace_has_only(to, surface))
1211 update_workspace(shell, index, from, to);
1212 else {
Philip Withnall2c3849b2013-11-25 18:01:45 +00001213 if (shsurf != NULL &&
1214 wl_list_empty(&shsurf->workspace_transform.link))
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001215 wl_list_insert(&shell->workspaces.anim_sticky_list,
1216 &shsurf->workspace_transform.link);
1217
1218 animate_workspace_change(shell, index, from, to);
1219 }
Jonas Ådahle9d22502012-08-29 22:13:01 +02001220
1221 broadcast_current_workspace_state(shell);
Jonas Ådahl8538b222012-08-29 22:13:03 +02001222
1223 state = ensure_focus_state(shell, seat);
1224 if (state != NULL)
1225 state->keyboard_focus = surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001226}
1227
1228static void
1229workspace_manager_move_surface(struct wl_client *client,
1230 struct wl_resource *resource,
1231 struct wl_resource *surface_resource,
1232 uint32_t workspace)
1233{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001234 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001235 struct weston_surface *surface =
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05001236 wl_resource_get_user_data(surface_resource);
Pekka Paalanen01388e22013-04-25 13:57:44 +03001237 struct weston_surface *main_surface;
Philip Withnall659163d2013-11-25 18:01:36 +00001238 struct shell_surface *shell_surface;
Jonas Ådahle9d22502012-08-29 22:13:01 +02001239
Pekka Paalanen01388e22013-04-25 13:57:44 +03001240 main_surface = weston_surface_get_main_surface(surface);
Philip Withnall659163d2013-11-25 18:01:36 +00001241 shell_surface = get_shell_surface(main_surface);
1242 if (shell_surface == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05001243 return;
Philip Withnall659163d2013-11-25 18:01:36 +00001244
1245 move_surface_to_workspace(shell, shell_surface, workspace);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001246}
1247
1248static const struct workspace_manager_interface workspace_manager_implementation = {
1249 workspace_manager_move_surface,
1250};
1251
1252static void
1253unbind_resource(struct wl_resource *resource)
1254{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001255 wl_list_remove(wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001256}
1257
1258static void
1259bind_workspace_manager(struct wl_client *client,
1260 void *data, uint32_t version, uint32_t id)
1261{
1262 struct desktop_shell *shell = data;
1263 struct wl_resource *resource;
1264
Jason Ekstranda85118c2013-06-27 20:17:02 -05001265 resource = wl_resource_create(client,
1266 &workspace_manager_interface, 1, id);
Jonas Ådahle9d22502012-08-29 22:13:01 +02001267
1268 if (resource == NULL) {
1269 weston_log("couldn't add workspace manager object");
1270 return;
1271 }
1272
Jason Ekstranda85118c2013-06-27 20:17:02 -05001273 wl_resource_set_implementation(resource,
1274 &workspace_manager_implementation,
1275 shell, unbind_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001276 wl_list_insert(&shell->workspaces.client_list,
1277 wl_resource_get_link(resource));
Jonas Ådahle9d22502012-08-29 22:13:01 +02001278
1279 workspace_manager_send_state(resource,
1280 shell->workspaces.current,
1281 shell->workspaces.num);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02001282}
1283
Pekka Paalanen56cdea92011-11-23 16:14:12 +02001284static void
Rusty Lynch1084da52013-08-15 09:10:08 -07001285touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1286 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1287{
1288}
1289
1290static void
1291touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1292{
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001293 struct weston_touch_move_grab *move =
1294 (struct weston_touch_move_grab *) container_of(
1295 grab, struct shell_touch_grab, grab);
Neil Robertse14aa4f2013-10-03 16:43:07 +01001296
Jonas Ådahl9484b692013-12-02 22:05:03 +01001297 if (grab->touch->num_tp == 0) {
Jonas Ådahl1c6e63e2013-10-25 23:18:04 +02001298 shell_touch_grab_end(&move->base);
1299 free(move);
1300 }
Rusty Lynch1084da52013-08-15 09:10:08 -07001301}
1302
1303static void
1304touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1305 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1306{
1307 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1308 struct shell_surface *shsurf = move->base.shsurf;
1309 struct weston_surface *es;
1310 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1311 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1312
1313 if (!shsurf)
1314 return;
1315
1316 es = shsurf->surface;
1317
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06001318 weston_view_set_position(shsurf->view, dx, dy);
Rusty Lynch1084da52013-08-15 09:10:08 -07001319
1320 weston_compositor_schedule_repaint(es->compositor);
1321}
1322
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001323static void
1324touch_move_grab_cancel(struct weston_touch_grab *grab)
1325{
1326 struct weston_touch_move_grab *move =
1327 (struct weston_touch_move_grab *) container_of(
1328 grab, struct shell_touch_grab, grab);
1329
1330 shell_touch_grab_end(&move->base);
1331 free(move);
1332}
1333
Rusty Lynch1084da52013-08-15 09:10:08 -07001334static const struct weston_touch_grab_interface touch_move_grab_interface = {
1335 touch_move_grab_down,
1336 touch_move_grab_up,
1337 touch_move_grab_motion,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001338 touch_move_grab_cancel,
Rusty Lynch1084da52013-08-15 09:10:08 -07001339};
1340
1341static int
1342surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1343{
1344 struct weston_touch_move_grab *move;
1345
1346 if (!shsurf)
1347 return -1;
1348
Rafael Antognolli03b16592013-12-03 15:35:42 -02001349 if (shsurf->state.fullscreen)
Rusty Lynch1084da52013-08-15 09:10:08 -07001350 return 0;
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001351 if (shsurf->grabbed)
1352 return 0;
Rusty Lynch1084da52013-08-15 09:10:08 -07001353
1354 move = malloc(sizeof *move);
1355 if (!move)
1356 return -1;
1357
Jason Ekstranda7af7042013-10-12 22:38:11 -05001358 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001359 seat->touch->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001360 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Rusty Lynch1084da52013-08-15 09:10:08 -07001361 seat->touch->grab_y;
1362
1363 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1364 seat->touch);
1365
1366 return 0;
1367}
1368
1369static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001370noop_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001371{
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001372}
1373
1374static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001375move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1376 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001377{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001378 struct weston_move_grab *move = (struct weston_move_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001379 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001380 struct shell_surface *shsurf = move->base.shsurf;
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001381 int dx, dy;
1382
1383 weston_pointer_move(pointer, x, y);
1384 dx = wl_fixed_to_int(pointer->x + move->dx);
1385 dy = wl_fixed_to_int(pointer->y + move->dy);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001386
1387 if (!shsurf)
1388 return;
1389
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06001390 weston_view_set_position(shsurf->view, dx, dy);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001391
Jason Ekstranda7af7042013-10-12 22:38:11 -05001392 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001393}
1394
1395static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001396move_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001397 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001398{
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03001399 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1400 grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001401 struct weston_pointer *pointer = grab->pointer;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001402 enum wl_pointer_button_state state = state_w;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001403
Daniel Stone4dbadb12012-05-30 16:31:51 +01001404 if (pointer->button_count == 0 &&
1405 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001406 shell_grab_end(shell_grab);
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001407 free(grab);
1408 }
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001409}
1410
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001411static void
1412move_grab_cancel(struct weston_pointer_grab *grab)
1413{
1414 struct shell_grab *shell_grab =
1415 container_of(grab, struct shell_grab, grab);
1416
1417 shell_grab_end(shell_grab);
1418 free(grab);
1419}
1420
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001421static const struct weston_pointer_grab_interface move_grab_interface = {
Kristian Høgsberg9ddb8262012-01-04 21:30:29 -05001422 noop_grab_focus,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001423 move_grab_motion,
1424 move_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001425 move_grab_cancel,
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05001426};
1427
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001428static int
Kristian Høgsberge3148752013-05-06 23:19:49 -04001429surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001430{
1431 struct weston_move_grab *move;
1432
1433 if (!shsurf)
1434 return -1;
1435
Kristian Høgsbergc85f1d42013-10-24 16:52:00 -07001436 if (shsurf->grabbed)
1437 return 0;
Rafael Antognolli03b16592013-12-03 15:35:42 -02001438 if (shsurf->state.fullscreen)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001439 return 0;
1440
1441 move = malloc(sizeof *move);
1442 if (!move)
1443 return -1;
1444
Jason Ekstranda7af7042013-10-12 22:38:11 -05001445 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001446 seat->pointer->grab_x;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001447 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
Kristian Høgsberge3148752013-05-06 23:19:49 -04001448 seat->pointer->grab_y;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001449
1450 shell_grab_start(&move->base, &move_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001451 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001452
1453 return 0;
1454}
1455
1456static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02001457common_surface_move(struct wl_resource *resource,
1458 struct wl_resource *seat_resource, uint32_t serial)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001459{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001460 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001461 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001462 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001463
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001464 if (seat->pointer &&
1465 seat->pointer->button_count > 0 &&
1466 seat->pointer->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001467 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001468 if ((surface == shsurf->surface) &&
1469 (surface_move(shsurf, seat) < 0))
1470 wl_resource_post_no_memory(resource);
Kristian Høgsberge1b655d2013-08-28 23:16:20 -07001471 } else if (seat->touch &&
1472 seat->touch->grab_serial == serial) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05001473 surface = weston_surface_get_main_surface(seat->touch->focus->surface);
Rusty Lynch1084da52013-08-15 09:10:08 -07001474 if ((surface == shsurf->surface) &&
1475 (surface_touch_move(shsurf, seat) < 0))
1476 wl_resource_post_no_memory(resource);
1477 }
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001478}
1479
Rafael Antognollie2a34552013-12-03 15:35:45 -02001480static void
1481shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1482 struct wl_resource *seat_resource, uint32_t serial)
1483{
1484 common_surface_move(resource, seat_resource, serial);
1485}
1486
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001487struct weston_resize_grab {
1488 struct shell_grab base;
1489 uint32_t edges;
1490 int32_t width, height;
1491};
1492
1493static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001494resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1495 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001496{
1497 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001498 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001499 struct shell_surface *shsurf = resize->base.shsurf;
1500 int32_t width, height;
1501 wl_fixed_t from_x, from_y;
1502 wl_fixed_t to_x, to_y;
1503
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001504 weston_pointer_move(pointer, x, y);
1505
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001506 if (!shsurf)
1507 return;
1508
Jason Ekstranda7af7042013-10-12 22:38:11 -05001509 weston_view_from_global_fixed(shsurf->view,
1510 pointer->grab_x, pointer->grab_y,
1511 &from_x, &from_y);
1512 weston_view_from_global_fixed(shsurf->view,
1513 pointer->x, pointer->y, &to_x, &to_y);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001514
1515 width = resize->width;
1516 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1517 width += wl_fixed_to_int(from_x - to_x);
1518 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1519 width += wl_fixed_to_int(to_x - from_x);
1520 }
1521
1522 height = resize->height;
1523 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1524 height += wl_fixed_to_int(from_y - to_y);
1525 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1526 height += wl_fixed_to_int(to_y - from_y);
1527 }
1528
1529 shsurf->client->send_configure(shsurf->surface,
1530 resize->edges, width, height);
1531}
1532
1533static void
1534send_configure(struct weston_surface *surface,
1535 uint32_t edges, int32_t width, int32_t height)
1536{
1537 struct shell_surface *shsurf = get_shell_surface(surface);
1538
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001539 wl_shell_surface_send_configure(shsurf->resource,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001540 edges, width, height);
1541}
1542
1543static const struct weston_shell_client shell_client = {
1544 send_configure
1545};
1546
1547static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001548resize_grab_button(struct weston_pointer_grab *grab,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001549 uint32_t time, uint32_t button, uint32_t state_w)
1550{
1551 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001552 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001553 enum wl_pointer_button_state state = state_w;
1554
1555 if (pointer->button_count == 0 &&
1556 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1557 shell_grab_end(&resize->base);
1558 free(grab);
1559 }
1560}
1561
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001562static void
1563resize_grab_cancel(struct weston_pointer_grab *grab)
1564{
1565 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1566
1567 shell_grab_end(&resize->base);
1568 free(grab);
1569}
1570
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001571static const struct weston_pointer_grab_interface resize_grab_interface = {
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001572 noop_grab_focus,
1573 resize_grab_motion,
1574 resize_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001575 resize_grab_cancel,
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001576};
1577
Giulio Camuffob8366642013-04-25 13:57:46 +03001578/*
1579 * Returns the bounding box of a surface and all its sub-surfaces,
1580 * in the surface coordinates system. */
1581static void
1582surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1583 int32_t *y, int32_t *w, int32_t *h) {
1584 pixman_region32_t region;
1585 pixman_box32_t *box;
1586 struct weston_subsurface *subsurface;
1587
1588 pixman_region32_init_rect(&region, 0, 0,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001589 surface->width,
1590 surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001591
1592 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1593 pixman_region32_union_rect(&region, &region,
1594 subsurface->position.x,
1595 subsurface->position.y,
Jason Ekstranda7af7042013-10-12 22:38:11 -05001596 subsurface->surface->width,
1597 subsurface->surface->height);
Giulio Camuffob8366642013-04-25 13:57:46 +03001598 }
1599
1600 box = pixman_region32_extents(&region);
1601 if (x)
1602 *x = box->x1;
1603 if (y)
1604 *y = box->y1;
1605 if (w)
1606 *w = box->x2 - box->x1;
1607 if (h)
1608 *h = box->y2 - box->y1;
1609
1610 pixman_region32_fini(&region);
1611}
1612
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001613static int
1614surface_resize(struct shell_surface *shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001615 struct weston_seat *seat, uint32_t edges)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001616{
1617 struct weston_resize_grab *resize;
1618
Rafael Antognolli03b16592013-12-03 15:35:42 -02001619 if (shsurf->state.fullscreen || shsurf->state.maximized)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001620 return 0;
1621
1622 if (edges == 0 || edges > 15 ||
1623 (edges & 3) == 3 || (edges & 12) == 12)
1624 return 0;
1625
1626 resize = malloc(sizeof *resize);
1627 if (!resize)
1628 return -1;
1629
1630 resize->edges = edges;
Giulio Camuffob8366642013-04-25 13:57:46 +03001631 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1632 &resize->width, &resize->height);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001633
1634 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001635 seat->pointer, edges);
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001636
1637 return 0;
1638}
1639
1640static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02001641common_surface_resize(struct wl_resource *resource,
1642 struct wl_resource *seat_resource, uint32_t serial,
1643 uint32_t edges)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001644{
Jason Ekstrand44a38632013-06-14 10:08:00 -05001645 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001646 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001647 struct weston_surface *surface;
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001648
Rafael Antognolli03b16592013-12-03 15:35:42 -02001649 if (shsurf->state.fullscreen)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001650 return;
1651
Jason Ekstranda7af7042013-10-12 22:38:11 -05001652 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001653 if (seat->pointer->button_count == 0 ||
1654 seat->pointer->grab_serial != serial ||
Giulio Camuffo61da3fc2013-04-25 13:57:45 +03001655 surface != shsurf->surface)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001656 return;
1657
Kristian Høgsberge3148752013-05-06 23:19:49 -04001658 if (surface_resize(shsurf, seat, edges) < 0)
Kristian Høgsberg9e31bff2012-08-01 00:08:07 -04001659 wl_resource_post_no_memory(resource);
1660}
1661
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001662static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02001663shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1664 struct wl_resource *seat_resource, uint32_t serial,
1665 uint32_t edges)
1666{
1667 common_surface_resize(resource, seat_resource, serial, edges);
1668}
1669
1670static void
Kristian Høgsberg67800732013-07-04 01:12:17 -04001671end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1672
1673static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001674busy_cursor_grab_focus(struct weston_pointer_grab *base)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001675{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001676 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001677 struct weston_pointer *pointer = base->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001678 struct weston_view *view;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04001679 wl_fixed_t sx, sy;
1680
Jason Ekstranda7af7042013-10-12 22:38:11 -05001681 view = weston_compositor_pick_view(pointer->seat->compositor,
1682 pointer->x, pointer->y,
1683 &sx, &sy);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001684
Jason Ekstranda7af7042013-10-12 22:38:11 -05001685 if (!grab->shsurf || grab->shsurf->surface != view->surface)
Kristian Høgsberg67800732013-07-04 01:12:17 -04001686 end_busy_cursor(grab->shsurf, pointer);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001687}
1688
1689static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001690busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1691 wl_fixed_t x, wl_fixed_t y)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001692{
Giulio Camuffo1959ab82013-11-14 23:42:52 +01001693 weston_pointer_move(grab->pointer, x, y);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001694}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001695
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001696static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001697busy_cursor_grab_button(struct weston_pointer_grab *base,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001698 uint32_t time, uint32_t button, uint32_t state)
1699{
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001700 struct shell_grab *grab = (struct shell_grab *) base;
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001701 struct shell_surface *shsurf = grab->shsurf;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001702 struct weston_seat *seat = grab->grab.pointer->seat;
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001703
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001704 if (shsurf && button == BTN_LEFT && state) {
1705 activate(shsurf->shell, shsurf->surface, seat);
1706 surface_move(shsurf, seat);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05001707 } else if (shsurf && button == BTN_RIGHT && state) {
1708 activate(shsurf->shell, shsurf->surface, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001709 surface_rotate(shsurf, seat);
Kristian Høgsbergbbe98392012-08-01 00:20:21 -04001710 }
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001711}
1712
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001713static void
1714busy_cursor_grab_cancel(struct weston_pointer_grab *base)
1715{
1716 struct shell_grab *grab = (struct shell_grab *) base;
1717
1718 shell_grab_end(grab);
1719 free(grab);
1720}
1721
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001722static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001723 busy_cursor_grab_focus,
1724 busy_cursor_grab_motion,
1725 busy_cursor_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02001726 busy_cursor_grab_cancel,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001727};
1728
1729static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001730set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001731{
1732 struct shell_grab *grab;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001733
1734 grab = malloc(sizeof *grab);
1735 if (!grab)
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001736 return;
1737
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001738 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1739 DESKTOP_SHELL_CURSOR_BUSY);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001740}
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001741
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001742static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001743end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001744{
1745 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1746
Kristian Høgsberge122b7b2013-05-08 16:47:00 -04001747 if (grab->grab.interface == &busy_cursor_grab_interface &&
1748 grab->shsurf == shsurf) {
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001749 shell_grab_end(grab);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001750 free(grab);
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001751 }
Scott Moreauc3e54eb2012-04-17 19:06:20 -06001752}
1753
Scott Moreau9521d5e2012-04-19 13:06:17 -06001754static void
1755ping_timer_destroy(struct shell_surface *shsurf)
1756{
1757 if (!shsurf || !shsurf->ping_timer)
1758 return;
1759
1760 if (shsurf->ping_timer->source)
1761 wl_event_source_remove(shsurf->ping_timer->source);
1762
1763 free(shsurf->ping_timer);
1764 shsurf->ping_timer = NULL;
1765}
1766
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04001767static int
Scott Moreauff1db4a2012-04-17 19:06:18 -06001768ping_timeout_handler(void *data)
1769{
1770 struct shell_surface *shsurf = data;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001771 struct weston_seat *seat;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001772
Scott Moreau9521d5e2012-04-19 13:06:17 -06001773 /* Client is not responding */
1774 shsurf->unresponsive = 1;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001775
1776 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
Emilio Pozuelo Monfort3d0fc762013-11-22 16:21:20 +01001777 if (seat->pointer->focus &&
1778 seat->pointer->focus->surface == shsurf->surface)
Kristian Høgsberge3148752013-05-06 23:19:49 -04001779 set_busy_cursor(shsurf, seat->pointer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001780
1781 return 1;
1782}
1783
1784static void
1785ping_handler(struct weston_surface *surface, uint32_t serial)
1786{
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04001787 struct shell_surface *shsurf = get_shell_surface(surface);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001788 struct wl_event_loop *loop;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001789 int ping_timeout = 200;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001790
1791 if (!shsurf)
1792 return;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001793 if (!shsurf->resource)
Kristian Høgsbergca535c12012-04-21 23:20:07 -04001794 return;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001795
Ander Conselvan de Oliveiraeac9a462012-07-16 14:15:48 +03001796 if (shsurf->surface == shsurf->shell->grab_surface)
1797 return;
1798
Scott Moreauff1db4a2012-04-17 19:06:18 -06001799 if (!shsurf->ping_timer) {
Ander Conselvan de Oliveirafb980892012-04-27 13:55:55 +03001800 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001801 if (!shsurf->ping_timer)
1802 return;
1803
1804 shsurf->ping_timer->serial = serial;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001805 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1806 shsurf->ping_timer->source =
1807 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1808 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1809
Rafael Antognollie2a34552013-12-03 15:35:45 -02001810 if (shell_surface_is_wl_shell_surface(shsurf))
1811 wl_shell_surface_send_ping(shsurf->resource, serial);
1812 else if (shell_surface_is_xdg_surface(shsurf))
1813 xdg_surface_send_ping(shsurf->resource, serial);
1814 else if (shell_surface_is_xdg_popup(shsurf))
1815 xdg_popup_send_ping(shsurf->resource, serial);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001816 }
1817}
1818
1819static void
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001820handle_pointer_focus(struct wl_listener *listener, void *data)
1821{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001822 struct weston_pointer *pointer = data;
Jason Ekstranda7af7042013-10-12 22:38:11 -05001823 struct weston_view *view = pointer->focus;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001824 struct weston_compositor *compositor;
1825 struct shell_surface *shsurf;
1826 uint32_t serial;
1827
Jason Ekstranda7af7042013-10-12 22:38:11 -05001828 if (!view)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001829 return;
1830
Jason Ekstranda7af7042013-10-12 22:38:11 -05001831 compositor = view->surface->compositor;
1832 shsurf = get_shell_surface(view->surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001833
Pekka Paalanen4e1f2ff2012-06-06 16:59:45 +03001834 if (shsurf && shsurf->unresponsive) {
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001835 set_busy_cursor(shsurf, pointer);
1836 } else {
1837 serial = wl_display_next_serial(compositor->wl_display);
Jason Ekstranda7af7042013-10-12 22:38:11 -05001838 ping_handler(view->surface, serial);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001839 }
1840}
1841
1842static void
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001843create_pointer_focus_listener(struct weston_seat *seat)
1844{
1845 struct wl_listener *listener;
1846
Kristian Høgsberge3148752013-05-06 23:19:49 -04001847 if (!seat->pointer)
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001848 return;
1849
1850 listener = malloc(sizeof *listener);
1851 listener->notify = handle_pointer_focus;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001852 wl_signal_add(&seat->pointer->focus_signal, listener);
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04001853}
1854
1855static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02001856xdg_surface_set_transient_for(struct wl_client *client,
1857 struct wl_resource *resource,
1858 struct wl_resource *parent_resource)
Scott Moreauff1db4a2012-04-17 19:06:18 -06001859{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001860 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Jasper St. Pierre8f180d42013-12-07 13:49:28 -05001861 struct weston_surface *parent;
1862
1863 if (parent_resource)
1864 parent = wl_resource_get_user_data(parent_resource);
1865 else
1866 parent = NULL;
Rafael Antognollie2a34552013-12-03 15:35:45 -02001867
1868 shell_surface_set_parent(shsurf, parent);
1869}
1870
1871static void
1872surface_pong(struct shell_surface *shsurf, uint32_t serial)
1873{
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001874 struct weston_compositor *ec = shsurf->surface->compositor;
Rafael Antognollie2a34552013-12-03 15:35:45 -02001875 struct weston_seat *seat;
Scott Moreauff1db4a2012-04-17 19:06:18 -06001876
Kristian Høgsberg92374e12012-08-11 22:39:12 -04001877 if (shsurf->ping_timer == NULL)
1878 /* Just ignore unsolicited pong. */
1879 return;
1880
Scott Moreauff1db4a2012-04-17 19:06:18 -06001881 if (shsurf->ping_timer->serial == serial) {
Scott Moreauff1db4a2012-04-17 19:06:18 -06001882 shsurf->unresponsive = 0;
Hardeningeb1e1302013-05-17 18:07:41 +02001883 wl_list_for_each(seat, &ec->seat_list, link) {
1884 if(seat->pointer)
1885 end_busy_cursor(shsurf, seat->pointer);
1886 }
Scott Moreau9521d5e2012-04-19 13:06:17 -06001887 ping_timer_destroy(shsurf);
Scott Moreauff1db4a2012-04-17 19:06:18 -06001888 }
1889}
1890
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001891static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02001892shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1893 uint32_t serial)
1894{
1895 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1896
1897 surface_pong(shsurf, serial);
1898
1899}
1900
1901static void
Giulio Camuffo62942ad2013-09-11 18:20:47 +02001902set_title(struct shell_surface *shsurf, const char *title)
1903{
1904 free(shsurf->title);
1905 shsurf->title = strdup(title);
1906}
1907
1908static void
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001909shell_surface_set_title(struct wl_client *client,
1910 struct wl_resource *resource, const char *title)
1911{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001912 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001913
Giulio Camuffo62942ad2013-09-11 18:20:47 +02001914 set_title(shsurf, title);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001915}
1916
1917static void
1918shell_surface_set_class(struct wl_client *client,
1919 struct wl_resource *resource, const char *class)
1920{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05001921 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Kristian Høgsberge7afd912012-05-02 09:47:44 -04001922
1923 free(shsurf->class);
1924 shsurf->class = strdup(class);
1925}
1926
Alex Wu4539b082012-03-01 12:57:46 +08001927static void
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02001928restore_output_mode(struct weston_output *output)
1929{
Hardening57388e42013-09-18 23:56:36 +02001930 if (output->current_mode != output->original_mode ||
1931 (int32_t)output->current_scale != output->original_scale)
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02001932 weston_output_switch_mode(output,
Hardening57388e42013-09-18 23:56:36 +02001933 output->original_mode,
1934 output->original_scale,
1935 WESTON_MODE_SWITCH_RESTORE_NATIVE);
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02001936}
1937
1938static void
1939restore_all_output_modes(struct weston_compositor *compositor)
1940{
1941 struct weston_output *output;
1942
1943 wl_list_for_each(output, &compositor->output_list, link)
1944 restore_output_mode(output);
1945}
1946
Philip Withnallbecb77e2013-11-25 18:01:30 +00001947static int
1948get_output_panel_height(struct desktop_shell *shell,
1949 struct weston_output *output)
1950{
1951 struct weston_view *view;
1952 int panel_height = 0;
1953
1954 if (!output)
1955 return 0;
1956
1957 wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
1958 if (view->surface->output == output) {
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06001959 panel_height = view->surface->height;
Philip Withnallbecb77e2013-11-25 18:01:30 +00001960 break;
1961 }
1962 }
1963
1964 return panel_height;
1965}
1966
Philip Withnall07926d92013-11-25 18:01:40 +00001967/* The surface will be inserted into the list immediately after the link
1968 * returned by this function (i.e. will be stacked immediately above the
1969 * returned link). */
1970static struct wl_list *
1971shell_surface_calculate_layer_link (struct shell_surface *shsurf)
1972{
1973 struct workspace *ws;
1974
1975 switch (shsurf->type) {
Philip Withnallda704d92013-11-25 18:01:46 +00001976 case SHELL_SURFACE_POPUP: {
1977 /* Popups should go at the front of the workspace of their
1978 * parent surface, rather than just in front of the parent. This
1979 * fixes the situation where there are two top-level windows:
1980 * - Above
1981 * - Below
1982 * and a pop-up menu is created for 'Below'. We want:
1983 * - Popup
1984 * - Above
1985 * - Below
1986 * not:
1987 * - Above
1988 * - Popup
1989 * - Below
1990 */
1991 struct shell_surface *parent_shsurf;
1992
1993 parent_shsurf = get_shell_surface(shsurf->parent);
1994 if (parent_shsurf != NULL)
1995 return shell_surface_calculate_layer_link(parent_shsurf);
1996
1997 break;
1998 }
1999
Rafael Antognolli03b16592013-12-03 15:35:42 -02002000 case SHELL_SURFACE_TOPLEVEL: {
Rafael Antognollied207b42013-12-03 15:35:43 -02002001 if (shsurf->state.fullscreen) {
Rafael Antognolli03b16592013-12-03 15:35:42 -02002002 return &shsurf->shell->fullscreen_layer.view_list;
Rafael Antognollied207b42013-12-03 15:35:43 -02002003 } else if (shsurf->parent) {
2004 /* Move the surface to its parent layer so that
2005 * surfaces which are transient for fullscreen surfaces
2006 * don't get hidden by the fullscreen surfaces.
2007 * However, unlike popups, transient surfaces are
2008 * stacked in front of their parent but not in front of
2009 * other surfaces of the same type. */
2010 struct weston_view *parent;
2011
2012 /* TODO: Handle a parent with multiple views */
2013 parent = get_default_view(shsurf->parent);
2014 if (parent)
2015 return parent->layer_link.prev;
2016 }
Rafael Antognolli03b16592013-12-03 15:35:42 -02002017 break;
2018 }
Philip Withnall07926d92013-11-25 18:01:40 +00002019
2020 case SHELL_SURFACE_XWAYLAND:
Kristian Høgsberg4804a302013-12-05 22:43:03 -08002021 return &shsurf->shell->fullscreen_layer.view_list;
2022
Philip Withnall07926d92013-11-25 18:01:40 +00002023 case SHELL_SURFACE_NONE:
2024 default:
2025 /* Go to the fallback, below. */
2026 break;
2027 }
2028
2029 /* Move the surface to a normal workspace layer so that surfaces
2030 * which were previously fullscreen or transient are no longer
2031 * rendered on top. */
2032 ws = get_current_workspace(shsurf->shell);
2033 return &ws->layer.view_list;
2034}
2035
Philip Withnall648a4dd2013-11-25 18:01:44 +00002036static void
2037shell_surface_update_child_surface_layers (struct shell_surface *shsurf)
2038{
2039 struct shell_surface *child;
2040
2041 /* Move the child layers to the same workspace as shsurf. They will be
2042 * stacked above shsurf. */
2043 wl_list_for_each_reverse(child, &shsurf->children_list, children_link) {
2044 if (shsurf->view->layer_link.prev != &child->view->layer_link) {
2045 weston_view_geometry_dirty(child->view);
2046 wl_list_remove(&child->view->layer_link);
2047 wl_list_insert(shsurf->view->layer_link.prev,
2048 &child->view->layer_link);
2049 weston_view_geometry_dirty(child->view);
2050 weston_surface_damage(child->surface);
2051
2052 /* Recurse. We don’t expect this to recurse very far (if
2053 * at all) because that would imply we have transient
2054 * (or popup) children of transient surfaces, which
2055 * would be unusual. */
2056 shell_surface_update_child_surface_layers(child);
2057 }
2058 }
2059}
2060
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002061/* Update the surface’s layer. Mark both the old and new views as having dirty
Philip Withnall648a4dd2013-11-25 18:01:44 +00002062 * geometry to ensure the changes are redrawn.
2063 *
2064 * If any child surfaces exist and are mapped, ensure they’re in the same layer
2065 * as this surface. */
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002066static void
2067shell_surface_update_layer(struct shell_surface *shsurf)
2068{
2069 struct wl_list *new_layer_link;
2070
2071 new_layer_link = shell_surface_calculate_layer_link(shsurf);
2072
2073 if (new_layer_link == &shsurf->view->layer_link)
2074 return;
2075
2076 weston_view_geometry_dirty(shsurf->view);
2077 wl_list_remove(&shsurf->view->layer_link);
2078 wl_list_insert(new_layer_link, &shsurf->view->layer_link);
2079 weston_view_geometry_dirty(shsurf->view);
2080 weston_surface_damage(shsurf->surface);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002081
2082 shell_surface_update_child_surface_layers(shsurf);
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002083}
2084
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002085static void
Philip Withnalldc4332f2013-11-25 18:01:38 +00002086shell_surface_set_parent(struct shell_surface *shsurf,
2087 struct weston_surface *parent)
2088{
2089 shsurf->parent = parent;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002090
2091 wl_list_remove(&shsurf->children_link);
2092 wl_list_init(&shsurf->children_link);
2093
2094 /* Insert into the parent surface’s child list. */
2095 if (parent != NULL) {
2096 struct shell_surface *parent_shsurf = get_shell_surface(parent);
2097 if (parent_shsurf != NULL)
2098 wl_list_insert(&parent_shsurf->children_list,
2099 &shsurf->children_link);
2100 }
Philip Withnalldc4332f2013-11-25 18:01:38 +00002101}
2102
2103static void
Philip Withnall352e7ed2013-11-25 18:01:35 +00002104shell_surface_set_output(struct shell_surface *shsurf,
2105 struct weston_output *output)
2106{
2107 struct weston_surface *es = shsurf->surface;
2108
2109 /* get the default output, if the client set it as NULL
2110 check whether the ouput is available */
2111 if (output)
2112 shsurf->output = output;
2113 else if (es->output)
2114 shsurf->output = es->output;
2115 else
2116 shsurf->output = get_default_output(es->compositor);
2117}
2118
2119static void
Rafael Antognolli03b16592013-12-03 15:35:42 -02002120surface_clear_next_states(struct shell_surface *shsurf)
2121{
2122 shsurf->next_state.maximized = false;
2123 shsurf->next_state.fullscreen = false;
2124
2125 if ((shsurf->next_state.maximized != shsurf->state.maximized) ||
2126 (shsurf->next_state.fullscreen != shsurf->state.fullscreen))
2127 shsurf->state_changed = true;
2128}
2129
2130static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002131set_toplevel(struct shell_surface *shsurf)
2132{
Kristian Høgsberg41fbf6f2013-12-05 22:31:25 -08002133 shell_surface_set_parent(shsurf, NULL);
2134 surface_clear_next_states(shsurf);
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002135 shsurf->type = SHELL_SURFACE_TOPLEVEL;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002136
2137 /* The layer_link is updated in set_surface_type(),
2138 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002139}
2140
2141static void
2142shell_surface_set_toplevel(struct wl_client *client,
2143 struct wl_resource *resource)
2144{
2145 struct shell_surface *surface = wl_resource_get_user_data(resource);
2146
2147 set_toplevel(surface);
2148}
2149
2150static void
2151set_transient(struct shell_surface *shsurf,
2152 struct weston_surface *parent, int x, int y, uint32_t flags)
2153{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002154 assert(parent != NULL);
2155
Philip Withnallbecb77e2013-11-25 18:01:30 +00002156 shsurf->transient.x = x;
2157 shsurf->transient.y = y;
2158 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002159
Rafael Antognollied207b42013-12-03 15:35:43 -02002160 shsurf->next_state.relative = true;
Kristian Høgsberga1df7ac2013-12-31 15:01:01 -08002161 shsurf->state_changed = true;
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002162 shsurf->type = SHELL_SURFACE_TOPLEVEL;
Philip Withnall648a4dd2013-11-25 18:01:44 +00002163
2164 /* The layer_link is updated in set_surface_type(),
2165 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002166}
2167
2168static void
2169shell_surface_set_transient(struct wl_client *client,
2170 struct wl_resource *resource,
2171 struct wl_resource *parent_resource,
2172 int x, int y, uint32_t flags)
2173{
2174 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2175 struct weston_surface *parent =
2176 wl_resource_get_user_data(parent_resource);
2177
Rafael Antognolli4b99a402013-12-03 15:35:44 -02002178 shell_surface_set_parent(shsurf, parent);
2179
Rafael Antognolli03b16592013-12-03 15:35:42 -02002180 surface_clear_next_states(shsurf);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002181 set_transient(shsurf, parent, x, y, flags);
2182}
2183
2184static void
2185set_fullscreen(struct shell_surface *shsurf,
2186 uint32_t method,
2187 uint32_t framerate,
2188 struct weston_output *output)
2189{
Philip Withnall352e7ed2013-11-25 18:01:35 +00002190 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002191
2192 shsurf->fullscreen_output = shsurf->output;
2193 shsurf->fullscreen.type = method;
2194 shsurf->fullscreen.framerate = framerate;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002195
Kristian Høgsberge960b3f2013-12-05 22:04:42 -08002196 shsurf->next_state.fullscreen = true;
2197 shsurf->state_changed = true;
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002198 shsurf->type = SHELL_SURFACE_TOPLEVEL;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002199
2200 shsurf->client->send_configure(shsurf->surface, 0,
2201 shsurf->output->width,
2202 shsurf->output->height);
Philip Withnall648a4dd2013-11-25 18:01:44 +00002203
2204 /* The layer_link is updated in set_surface_type(),
2205 * called from configure. */
Philip Withnallbecb77e2013-11-25 18:01:30 +00002206}
2207
2208static void
Zhang, Xiong Y31236932013-12-13 22:10:57 +02002209weston_view_set_initial_position(struct weston_view *view,
2210 struct desktop_shell *shell);
2211
2212static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002213unset_fullscreen(struct shell_surface *shsurf)
Alex Wu4539b082012-03-01 12:57:46 +08002214{
Philip Withnallf85fe842013-11-25 18:01:37 +00002215 /* Unset the fullscreen output, driver configuration and transforms. */
Alex Wubd3354b2012-04-17 17:20:49 +08002216 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2217 shell_surface_is_top_fullscreen(shsurf)) {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002218 restore_output_mode(shsurf->fullscreen_output);
Alex Wubd3354b2012-04-17 17:20:49 +08002219 }
Philip Withnallf85fe842013-11-25 18:01:37 +00002220 shsurf->fullscreen_output = NULL;
2221
Alex Wu4539b082012-03-01 12:57:46 +08002222 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2223 shsurf->fullscreen.framerate = 0;
Philip Withnallf85fe842013-11-25 18:01:37 +00002224
Alex Wu4539b082012-03-01 12:57:46 +08002225 wl_list_remove(&shsurf->fullscreen.transform.link);
2226 wl_list_init(&shsurf->fullscreen.transform.link);
Philip Withnallf85fe842013-11-25 18:01:37 +00002227
Jason Ekstranda7af7042013-10-12 22:38:11 -05002228 if (shsurf->fullscreen.black_view)
2229 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
2230 shsurf->fullscreen.black_view = NULL;
Philip Withnallf85fe842013-11-25 18:01:37 +00002231
Zhang, Xiong Y31236932013-12-13 22:10:57 +02002232 if (shsurf->saved_position_valid)
2233 weston_view_set_position(shsurf->view,
2234 shsurf->saved_x, shsurf->saved_y);
2235 else
2236 weston_view_set_initial_position(shsurf->view, shsurf->shell);
2237
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002238 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002239 wl_list_insert(&shsurf->view->geometry.transformation_list,
Philip Withnallbecb77e2013-11-25 18:01:30 +00002240 &shsurf->rotation.transform.link);
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002241 shsurf->saved_rotation_valid = false;
2242 }
Rafal Mielniczuk3e3862c2012-10-07 20:25:36 +02002243
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002244 /* Layer is updated in set_surface_type(). */
Alex Wu4539b082012-03-01 12:57:46 +08002245}
2246
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002247static void
Philip Withnallbecb77e2013-11-25 18:01:30 +00002248shell_surface_set_fullscreen(struct wl_client *client,
2249 struct wl_resource *resource,
2250 uint32_t method,
2251 uint32_t framerate,
2252 struct wl_resource *output_resource)
2253{
2254 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2255 struct weston_output *output;
2256
2257 if (output_resource)
2258 output = wl_resource_get_user_data(output_resource);
2259 else
2260 output = NULL;
2261
Rafael Antognolli4b99a402013-12-03 15:35:44 -02002262 shell_surface_set_parent(shsurf, NULL);
2263
Rafael Antognolli03b16592013-12-03 15:35:42 -02002264 surface_clear_next_states(shsurf);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002265 set_fullscreen(shsurf, method, framerate, output);
2266}
2267
2268static void
2269set_popup(struct shell_surface *shsurf,
2270 struct weston_surface *parent,
2271 struct weston_seat *seat,
2272 uint32_t serial,
2273 int32_t x,
2274 int32_t y)
2275{
Philip Withnalldc4332f2013-11-25 18:01:38 +00002276 assert(parent != NULL);
2277
Philip Withnallbecb77e2013-11-25 18:01:30 +00002278 shsurf->popup.shseat = get_shell_seat(seat);
2279 shsurf->popup.serial = serial;
2280 shsurf->popup.x = x;
2281 shsurf->popup.y = y;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002282
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002283 shsurf->type = SHELL_SURFACE_POPUP;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002284}
2285
2286static void
2287shell_surface_set_popup(struct wl_client *client,
2288 struct wl_resource *resource,
2289 struct wl_resource *seat_resource,
2290 uint32_t serial,
2291 struct wl_resource *parent_resource,
2292 int32_t x, int32_t y, uint32_t flags)
2293{
2294 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Rafael Antognolli4b99a402013-12-03 15:35:44 -02002295 struct weston_surface *parent =
2296 wl_resource_get_user_data(parent_resource);
2297
2298 shell_surface_set_parent(shsurf, parent);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002299
Rafael Antognolli03b16592013-12-03 15:35:42 -02002300 surface_clear_next_states(shsurf);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002301 set_popup(shsurf,
Rafael Antognolli4b99a402013-12-03 15:35:44 -02002302 parent,
Philip Withnallbecb77e2013-11-25 18:01:30 +00002303 wl_resource_get_user_data(seat_resource),
2304 serial, x, y);
2305}
2306
2307static void
2308set_maximized(struct shell_surface *shsurf,
2309 struct weston_output *output)
2310{
2311 struct desktop_shell *shell;
2312 uint32_t edges = 0, panel_height = 0;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002313
Philip Withnall352e7ed2013-11-25 18:01:35 +00002314 shell_surface_set_output(shsurf, output);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002315
2316 shell = shell_surface_get_shell(shsurf);
2317 panel_height = get_output_panel_height(shell, shsurf->output);
2318 edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT;
2319
2320 shsurf->client->send_configure(shsurf->surface, edges,
2321 shsurf->output->width,
2322 shsurf->output->height - panel_height);
2323
Kristian Høgsbergc2745b12013-12-05 22:00:40 -08002324 shsurf->next_state.maximized = true;
2325 shsurf->state_changed = true;
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002326 shsurf->type = SHELL_SURFACE_TOPLEVEL;
Philip Withnallbecb77e2013-11-25 18:01:30 +00002327}
2328
2329static void
2330unset_maximized(struct shell_surface *shsurf)
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002331{
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002332 /* undo all maximized things here */
2333 shsurf->output = get_default_output(shsurf->surface->compositor);
Zhang, Xiong Y31236932013-12-13 22:10:57 +02002334
2335 if (shsurf->saved_position_valid)
2336 weston_view_set_position(shsurf->view,
2337 shsurf->saved_x, shsurf->saved_y);
2338 else
2339 weston_view_set_initial_position(shsurf->view, shsurf->shell);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002340
2341 if (shsurf->saved_rotation_valid) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002342 wl_list_insert(&shsurf->view->geometry.transformation_list,
2343 &shsurf->rotation.transform.link);
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002344 shsurf->saved_rotation_valid = false;
2345 }
2346
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002347 /* Layer is updated in set_surface_type(). */
Rafal Mielniczukfffdcdd2013-03-11 19:26:54 +01002348}
2349
Philip Withnallbecb77e2013-11-25 18:01:30 +00002350static void
2351shell_surface_set_maximized(struct wl_client *client,
2352 struct wl_resource *resource,
2353 struct wl_resource *output_resource)
2354{
2355 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2356 struct weston_output *output;
2357
2358 if (output_resource)
2359 output = wl_resource_get_user_data(output_resource);
2360 else
2361 output = NULL;
2362
Rafael Antognolli4b99a402013-12-03 15:35:44 -02002363 shell_surface_set_parent(shsurf, NULL);
2364
Rafael Antognolli03b16592013-12-03 15:35:42 -02002365 surface_clear_next_states(shsurf);
Philip Withnallbecb77e2013-11-25 18:01:30 +00002366 set_maximized(shsurf, output);
2367}
2368
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002369/* This is only ever called from set_surface_type(), so there’s no need to
2370 * update layer_links here, since they’ll be updated when we return. */
Pekka Paalanen98262232011-12-01 10:42:22 +02002371static int
Philip Withnallbecb77e2013-11-25 18:01:30 +00002372reset_surface_type(struct shell_surface *surface)
Pekka Paalanen98262232011-12-01 10:42:22 +02002373{
Rafael Antognolli03b16592013-12-03 15:35:42 -02002374 if (surface->state.fullscreen)
Philip Withnallbecb77e2013-11-25 18:01:30 +00002375 unset_fullscreen(surface);
Rafael Antognolli03b16592013-12-03 15:35:42 -02002376 if (surface->state.maximized)
Philip Withnallbecb77e2013-11-25 18:01:30 +00002377 unset_maximized(surface);
Pekka Paalanen98262232011-12-01 10:42:22 +02002378
Pekka Paalanen98262232011-12-01 10:42:22 +02002379 return 0;
2380}
2381
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05002382static void
Rafael Antognolli03b16592013-12-03 15:35:42 -02002383set_full_output(struct shell_surface *shsurf)
2384{
2385 shsurf->saved_x = shsurf->view->geometry.x;
2386 shsurf->saved_y = shsurf->view->geometry.y;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02002387 shsurf->saved_width = shsurf->surface->width;
2388 shsurf->saved_height = shsurf->surface->height;
2389 shsurf->saved_size_valid = true;
Rafael Antognolli03b16592013-12-03 15:35:42 -02002390 shsurf->saved_position_valid = true;
2391
2392 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
2393 wl_list_remove(&shsurf->rotation.transform.link);
2394 wl_list_init(&shsurf->rotation.transform.link);
2395 weston_view_geometry_dirty(shsurf->view);
2396 shsurf->saved_rotation_valid = true;
2397 }
2398}
2399
2400static void
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002401set_surface_type(struct shell_surface *shsurf)
2402{
Kristian Høgsberg8150b192012-06-27 10:22:58 -04002403 struct weston_surface *pes = shsurf->parent;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002404 struct weston_view *pev = get_default_view(pes);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002405
Philip Withnallbecb77e2013-11-25 18:01:30 +00002406 reset_surface_type(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002407
Rafael Antognolli03b16592013-12-03 15:35:42 -02002408 shsurf->state = shsurf->next_state;
Rafael Antognolli03b16592013-12-03 15:35:42 -02002409 shsurf->state_changed = false;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002410
2411 switch (shsurf->type) {
2412 case SHELL_SURFACE_TOPLEVEL:
Rafael Antognollied207b42013-12-03 15:35:43 -02002413 if (shsurf->state.maximized || shsurf->state.fullscreen) {
Rafael Antognolli03b16592013-12-03 15:35:42 -02002414 set_full_output(shsurf);
Rafael Antognollied207b42013-12-03 15:35:43 -02002415 } else if (shsurf->state.relative && pev) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002416 weston_view_set_position(shsurf->view,
2417 pev->geometry.x + shsurf->transient.x,
2418 pev->geometry.y + shsurf->transient.y);
Rafael Antognollied207b42013-12-03 15:35:43 -02002419 }
Rafael Antognolli44a31622013-12-04 18:37:16 -02002420 break;
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002421
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002422 case SHELL_SURFACE_XWAYLAND:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002423 weston_view_set_position(shsurf->view, shsurf->transient.x,
2424 shsurf->transient.y);
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002425 break;
2426
Philip Withnall0f640e22013-11-25 18:01:31 +00002427 case SHELL_SURFACE_POPUP:
2428 case SHELL_SURFACE_NONE:
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002429 default:
2430 break;
2431 }
Philip Withnalle1d75ae2013-11-25 18:01:41 +00002432
2433 /* Update the surface’s layer. */
2434 shell_surface_update_layer(shsurf);
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04002435}
2436
Tiago Vignattibe143262012-04-16 17:31:41 +03002437static struct desktop_shell *
Juan Zhao96879df2012-02-07 08:45:41 +08002438shell_surface_get_shell(struct shell_surface *shsurf)
Pekka Paalanenaf0e34c2011-12-02 10:59:17 +02002439{
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04002440 return shsurf->shell;
Juan Zhao96879df2012-02-07 08:45:41 +08002441}
2442
Alex Wu21858432012-04-01 20:13:08 +08002443static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06002444black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
Alex Wu21858432012-04-01 20:13:08 +08002445
Jason Ekstranda7af7042013-10-12 22:38:11 -05002446static struct weston_view *
Alex Wu4539b082012-03-01 12:57:46 +08002447create_black_surface(struct weston_compositor *ec,
Alex Wu21858432012-04-01 20:13:08 +08002448 struct weston_surface *fs_surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02002449 float x, float y, int w, int h)
Alex Wu4539b082012-03-01 12:57:46 +08002450{
2451 struct weston_surface *surface = NULL;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002452 struct weston_view *view;
Alex Wu4539b082012-03-01 12:57:46 +08002453
2454 surface = weston_surface_create(ec);
2455 if (surface == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02002456 weston_log("no memory\n");
Alex Wu4539b082012-03-01 12:57:46 +08002457 return NULL;
2458 }
Jason Ekstranda7af7042013-10-12 22:38:11 -05002459 view = weston_view_create(surface);
2460 if (surface == NULL) {
2461 weston_log("no memory\n");
2462 weston_surface_destroy(surface);
2463 return NULL;
2464 }
Alex Wu4539b082012-03-01 12:57:46 +08002465
Alex Wu21858432012-04-01 20:13:08 +08002466 surface->configure = black_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002467 surface->configure_private = fs_surface;
Alex Wu4539b082012-03-01 12:57:46 +08002468 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
Pekka Paalanen71f6f3b2012-10-10 12:49:26 +03002469 pixman_region32_fini(&surface->opaque);
Kristian Høgsberg61f00f52012-08-03 16:31:36 -04002470 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
Jonas Ådahl33619a42013-01-15 21:25:55 +01002471 pixman_region32_fini(&surface->input);
2472 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06002473
Jason Ekstrand5c11a332013-12-04 20:32:03 -06002474 weston_surface_set_size(surface, w, y);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06002475 weston_view_set_position(view, x, y);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002476
2477 return view;
Alex Wu4539b082012-03-01 12:57:46 +08002478}
2479
Philip Withnalled8f1a92013-11-25 18:01:43 +00002480static void
2481shell_ensure_fullscreen_black_view(struct shell_surface *shsurf)
2482{
2483 struct weston_output *output = shsurf->fullscreen_output;
2484
Rafael Antognolli03b16592013-12-03 15:35:42 -02002485 assert(shsurf->state.fullscreen);
Philip Withnalled8f1a92013-11-25 18:01:43 +00002486
2487 if (!shsurf->fullscreen.black_view)
2488 shsurf->fullscreen.black_view =
2489 create_black_surface(shsurf->surface->compositor,
2490 shsurf->surface,
2491 output->x, output->y,
2492 output->width,
2493 output->height);
2494
2495 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2496 wl_list_remove(&shsurf->fullscreen.black_view->layer_link);
2497 wl_list_insert(&shsurf->view->layer_link,
2498 &shsurf->fullscreen.black_view->layer_link);
2499 weston_view_geometry_dirty(shsurf->fullscreen.black_view);
2500 weston_surface_damage(shsurf->surface);
2501}
2502
Alex Wu4539b082012-03-01 12:57:46 +08002503/* Create black surface and append it to the associated fullscreen surface.
2504 * Handle size dismatch and positioning according to the method. */
2505static void
2506shell_configure_fullscreen(struct shell_surface *shsurf)
2507{
2508 struct weston_output *output = shsurf->fullscreen_output;
2509 struct weston_surface *surface = shsurf->surface;
2510 struct weston_matrix *matrix;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002511 float scale, output_aspect, surface_aspect, x, y;
Giulio Camuffob8366642013-04-25 13:57:46 +03002512 int32_t surf_x, surf_y, surf_width, surf_height;
Alex Wu4539b082012-03-01 12:57:46 +08002513
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002514 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
2515 restore_output_mode(output);
2516
Philip Withnalled8f1a92013-11-25 18:01:43 +00002517 shell_ensure_fullscreen_black_view(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002518
Jason Ekstranda7af7042013-10-12 22:38:11 -05002519 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
Giulio Camuffob8366642013-04-25 13:57:46 +03002520 &surf_width, &surf_height);
2521
Alex Wu4539b082012-03-01 12:57:46 +08002522 switch (shsurf->fullscreen.type) {
2523 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
Pekka Paalanende685b82012-12-04 15:58:12 +02002524 if (surface->buffer_ref.buffer)
Jason Ekstranda7af7042013-10-12 22:38:11 -05002525 center_on_output(shsurf->view, shsurf->fullscreen_output);
Alex Wu4539b082012-03-01 12:57:46 +08002526 break;
2527 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
Rob Bradford9f3dd152013-02-12 11:53:47 +00002528 /* 1:1 mapping between surface and output dimensions */
Giulio Camuffob8366642013-04-25 13:57:46 +03002529 if (output->width == surf_width &&
2530 output->height == surf_height) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002531 weston_view_set_position(shsurf->view,
2532 output->x - surf_x,
2533 output->y - surf_y);
Rob Bradford9f3dd152013-02-12 11:53:47 +00002534 break;
2535 }
2536
Alex Wu4539b082012-03-01 12:57:46 +08002537 matrix = &shsurf->fullscreen.transform.matrix;
2538 weston_matrix_init(matrix);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002539
Scott Moreau1bad5db2012-08-18 01:04:05 -06002540 output_aspect = (float) output->width /
2541 (float) output->height;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002542 /* XXX: Use surf_width and surf_height here? */
2543 surface_aspect = (float) surface->width /
2544 (float) surface->height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002545 if (output_aspect < surface_aspect)
Scott Moreau1bad5db2012-08-18 01:04:05 -06002546 scale = (float) output->width /
Giulio Camuffob8366642013-04-25 13:57:46 +03002547 (float) surf_width;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002548 else
Scott Moreau1bad5db2012-08-18 01:04:05 -06002549 scale = (float) output->height /
Giulio Camuffob8366642013-04-25 13:57:46 +03002550 (float) surf_height;
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002551
Alex Wu4539b082012-03-01 12:57:46 +08002552 weston_matrix_scale(matrix, scale, scale, 1);
2553 wl_list_remove(&shsurf->fullscreen.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002554 wl_list_insert(&shsurf->view->geometry.transformation_list,
Alex Wu4539b082012-03-01 12:57:46 +08002555 &shsurf->fullscreen.transform.link);
Giulio Camuffob8366642013-04-25 13:57:46 +03002556 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2557 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002558 weston_view_set_position(shsurf->view, x, y);
Kristian Høgsberg240dfeb2012-07-12 12:32:31 -04002559
Alex Wu4539b082012-03-01 12:57:46 +08002560 break;
2561 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
Alex Wubd3354b2012-04-17 17:20:49 +08002562 if (shell_surface_is_top_fullscreen(shsurf)) {
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01002563 struct weston_mode mode = {0,
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002564 surf_width * surface->buffer_viewport.scale,
2565 surf_height * surface->buffer_viewport.scale,
Alex Wubd3354b2012-04-17 17:20:49 +08002566 shsurf->fullscreen.framerate};
2567
Pekka Paalanen1fd9c0f2013-11-26 18:19:41 +01002568 if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
Hardening57388e42013-09-18 23:56:36 +02002569 WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002570 weston_view_set_position(shsurf->view,
2571 output->x - surf_x,
2572 output->y - surf_y);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06002573 shsurf->fullscreen.black_view->surface->width = output->width;
2574 shsurf->fullscreen.black_view->surface->height = output->height;
2575 weston_view_set_position(shsurf->fullscreen.black_view,
2576 output->x - surf_x,
2577 output->y - surf_y);
Alex Wubd3354b2012-04-17 17:20:49 +08002578 break;
Alexander Larssond622ed32013-05-28 16:23:40 +02002579 } else {
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002580 restore_output_mode(output);
Jason Ekstranda7af7042013-10-12 22:38:11 -05002581 center_on_output(shsurf->view, output);
Alexander Larssond622ed32013-05-28 16:23:40 +02002582 }
Alex Wubd3354b2012-04-17 17:20:49 +08002583 }
Alex Wu4539b082012-03-01 12:57:46 +08002584 break;
2585 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
Jason Ekstranda7af7042013-10-12 22:38:11 -05002586 center_on_output(shsurf->view, output);
Alex Wu4539b082012-03-01 12:57:46 +08002587 break;
2588 default:
2589 break;
2590 }
2591}
2592
Alex Wu4539b082012-03-01 12:57:46 +08002593static void
2594shell_map_fullscreen(struct shell_surface *shsurf)
2595{
Alex Wubd3354b2012-04-17 17:20:49 +08002596 shell_configure_fullscreen(shsurf);
Alex Wu4539b082012-03-01 12:57:46 +08002597}
2598
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04002599static void
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002600set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2601{
2602 /* XXX: using the same fields for transient type */
Rafael Antognolli03b16592013-12-03 15:35:42 -02002603 surface_clear_next_states(shsurf);
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002604 shsurf->transient.x = x;
2605 shsurf->transient.y = y;
2606 shsurf->transient.flags = flags;
Philip Withnalldc4332f2013-11-25 18:01:38 +00002607
2608 shell_surface_set_parent(shsurf, NULL);
2609
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08002610 shsurf->type = SHELL_SURFACE_XWAYLAND;
Tiago Vignattifb2adba2013-06-12 15:43:21 -03002611}
2612
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002613static const struct weston_pointer_grab_interface popup_grab_interface;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002614
2615static void
2616destroy_shell_seat(struct wl_listener *listener, void *data)
2617{
2618 struct shell_seat *shseat =
2619 container_of(listener,
2620 struct shell_seat, seat_destroy_listener);
2621 struct shell_surface *shsurf, *prev = NULL;
2622
2623 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002624 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002625 shseat->popup_grab.client = NULL;
2626
2627 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2628 shsurf->popup.shseat = NULL;
2629 if (prev) {
2630 wl_list_init(&prev->popup.grab_link);
2631 }
2632 prev = shsurf;
2633 }
2634 wl_list_init(&prev->popup.grab_link);
2635 }
2636
2637 wl_list_remove(&shseat->seat_destroy_listener.link);
2638 free(shseat);
2639}
2640
2641static struct shell_seat *
2642create_shell_seat(struct weston_seat *seat)
2643{
2644 struct shell_seat *shseat;
2645
2646 shseat = calloc(1, sizeof *shseat);
2647 if (!shseat) {
2648 weston_log("no memory to allocate shell seat\n");
2649 return NULL;
2650 }
2651
2652 shseat->seat = seat;
2653 wl_list_init(&shseat->popup_grab.surfaces_list);
2654
2655 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2656 wl_signal_add(&seat->destroy_signal,
2657 &shseat->seat_destroy_listener);
2658
2659 return shseat;
2660}
2661
2662static struct shell_seat *
2663get_shell_seat(struct weston_seat *seat)
2664{
2665 struct wl_listener *listener;
2666
2667 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2668 if (listener == NULL)
2669 return create_shell_seat(seat);
2670
2671 return container_of(listener,
2672 struct shell_seat, seat_destroy_listener);
2673}
2674
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002675static void
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002676popup_grab_focus(struct weston_pointer_grab *grab)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002677{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002678 struct weston_pointer *pointer = grab->pointer;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002679 struct weston_view *view;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002680 struct shell_seat *shseat =
2681 container_of(grab, struct shell_seat, popup_grab.grab);
2682 struct wl_client *client = shseat->popup_grab.client;
Kristian Høgsberg6848c252013-05-08 22:02:59 -04002683 wl_fixed_t sx, sy;
2684
Jason Ekstranda7af7042013-10-12 22:38:11 -05002685 view = weston_compositor_pick_view(pointer->seat->compositor,
2686 pointer->x, pointer->y,
2687 &sx, &sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002688
Jason Ekstranda7af7042013-10-12 22:38:11 -05002689 if (view && view->surface->resource &&
2690 wl_resource_get_client(view->surface->resource) == client) {
2691 weston_pointer_set_focus(pointer, view, sx, sy);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002692 } else {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002693 weston_pointer_set_focus(pointer, NULL,
2694 wl_fixed_from_int(0),
2695 wl_fixed_from_int(0));
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002696 }
2697}
2698
2699static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002700popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
2701 wl_fixed_t x, wl_fixed_t y)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002702{
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002703 struct weston_pointer *pointer = grab->pointer;
Neil Roberts96d790e2013-09-19 17:32:00 +01002704 struct wl_resource *resource;
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002705 wl_fixed_t sx, sy;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002706
Giulio Camuffo1959ab82013-11-14 23:42:52 +01002707 weston_pointer_move(pointer, x, y);
2708
Neil Roberts96d790e2013-09-19 17:32:00 +01002709 wl_resource_for_each(resource, &pointer->focus_resource_list) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05002710 weston_view_from_global_fixed(pointer->focus,
2711 pointer->x, pointer->y,
2712 &sx, &sy);
Neil Roberts96d790e2013-09-19 17:32:00 +01002713 wl_pointer_send_motion(resource, time, sx, sy);
Kristian Høgsbergbe6403e2013-05-08 21:03:21 -04002714 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002715}
2716
2717static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002718popup_grab_button(struct weston_pointer_grab *grab,
Daniel Stone4dbadb12012-05-30 16:31:51 +01002719 uint32_t time, uint32_t button, uint32_t state_w)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002720{
2721 struct wl_resource *resource;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002722 struct shell_seat *shseat =
2723 container_of(grab, struct shell_seat, popup_grab.grab);
Rob Bradford880ebc72013-07-22 17:31:38 +01002724 struct wl_display *display = shseat->seat->compositor->wl_display;
Daniel Stone4dbadb12012-05-30 16:31:51 +01002725 enum wl_pointer_button_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002726 uint32_t serial;
Neil Roberts96d790e2013-09-19 17:32:00 +01002727 struct wl_list *resource_list;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002728
Neil Roberts96d790e2013-09-19 17:32:00 +01002729 resource_list = &grab->pointer->focus_resource_list;
2730 if (!wl_list_empty(resource_list)) {
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04002731 serial = wl_display_get_serial(display);
Neil Roberts96d790e2013-09-19 17:32:00 +01002732 wl_resource_for_each(resource, resource_list) {
2733 wl_pointer_send_button(resource, serial,
2734 time, button, state);
2735 }
Daniel Stone4dbadb12012-05-30 16:31:51 +01002736 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
Giulio Camuffo5085a752013-03-25 21:42:45 +01002737 (shseat->popup_grab.initial_up ||
Kristian Høgsberge3148752013-05-06 23:19:49 -04002738 time - shseat->seat->pointer->grab_time > 500)) {
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002739 popup_grab_end(grab->pointer);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002740 }
2741
Daniel Stone4dbadb12012-05-30 16:31:51 +01002742 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Giulio Camuffo5085a752013-03-25 21:42:45 +01002743 shseat->popup_grab.initial_up = 1;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002744}
2745
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002746static void
2747popup_grab_cancel(struct weston_pointer_grab *grab)
2748{
2749 popup_grab_end(grab->pointer);
2750}
2751
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002752static const struct weston_pointer_grab_interface popup_grab_interface = {
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002753 popup_grab_focus,
2754 popup_grab_motion,
2755 popup_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02002756 popup_grab_cancel,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002757};
2758
2759static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02002760shell_surface_send_popup_done(struct shell_surface *shsurf)
2761{
2762 if (shell_surface_is_wl_shell_surface(shsurf))
2763 wl_shell_surface_send_popup_done(shsurf->resource);
2764 else if (shell_surface_is_xdg_popup(shsurf))
2765 xdg_popup_send_popup_done(shsurf->resource,
2766 shsurf->popup.serial);
2767}
2768
2769static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002770popup_grab_end(struct weston_pointer *pointer)
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002771{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002772 struct weston_pointer_grab *grab = pointer->grab;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002773 struct shell_seat *shseat =
2774 container_of(grab, struct shell_seat, popup_grab.grab);
2775 struct shell_surface *shsurf;
2776 struct shell_surface *prev = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002777
2778 if (pointer->grab->interface == &popup_grab_interface) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002779 weston_pointer_end_grab(grab->pointer);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002780 shseat->popup_grab.client = NULL;
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002781 shseat->popup_grab.grab.interface = NULL;
2782 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
Giulio Camuffo5085a752013-03-25 21:42:45 +01002783 /* Send the popup_done event to all the popups open */
2784 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
Rafael Antognollie2a34552013-12-03 15:35:45 -02002785 shell_surface_send_popup_done(shsurf);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002786 shsurf->popup.shseat = NULL;
2787 if (prev) {
2788 wl_list_init(&prev->popup.grab_link);
2789 }
2790 prev = shsurf;
2791 }
2792 wl_list_init(&prev->popup.grab_link);
2793 wl_list_init(&shseat->popup_grab.surfaces_list);
2794 }
2795}
2796
2797static void
2798add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2799{
Kristian Høgsberge3148752013-05-06 23:19:49 -04002800 struct weston_seat *seat = shseat->seat;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002801
2802 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002803 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002804 shseat->popup_grab.grab.interface = &popup_grab_interface;
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002805 /* We must make sure here that this popup was opened after
2806 * a mouse press, and not just by moving around with other
2807 * popups already open. */
Kristian Høgsberge3148752013-05-06 23:19:49 -04002808 if (shseat->seat->pointer->button_count > 0)
Giulio Camuffo1b4b61a2013-03-27 18:05:26 +01002809 shseat->popup_grab.initial_up = 0;
Giulio Camuffo5085a752013-03-25 21:42:45 +01002810
Rob Bradforddfe31052013-06-26 19:49:11 +01002811 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002812 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
Rob Bradforddfe31052013-06-26 19:49:11 +01002813 } else {
2814 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002815 }
Giulio Camuffo5085a752013-03-25 21:42:45 +01002816}
2817
2818static void
2819remove_popup_grab(struct shell_surface *shsurf)
2820{
2821 struct shell_seat *shseat = shsurf->popup.shseat;
2822
2823 wl_list_remove(&shsurf->popup.grab_link);
2824 wl_list_init(&shsurf->popup.grab_link);
2825 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04002826 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
Philipp Brüschweiler63e7be62013-04-15 21:09:54 +02002827 shseat->popup_grab.grab.interface = NULL;
Kristian Høgsberg57e09072012-10-30 14:07:27 -04002828 }
2829}
2830
2831static void
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002832shell_map_popup(struct shell_surface *shsurf)
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002833{
Giulio Camuffo5085a752013-03-25 21:42:45 +01002834 struct shell_seat *shseat = shsurf->popup.shseat;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002835 struct weston_view *parent_view = get_default_view(shsurf->parent);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002836
Jason Ekstranda7af7042013-10-12 22:38:11 -05002837 shsurf->surface->output = parent_view->output;
2838 shsurf->view->output = parent_view->output;
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002839
Jason Ekstranda7af7042013-10-12 22:38:11 -05002840 weston_view_set_transform_parent(shsurf->view, parent_view);
2841 weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y);
2842 weston_view_update_transform(shsurf->view);
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002843
Kristian Høgsberge3148752013-05-06 23:19:49 -04002844 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01002845 add_popup_grab(shsurf, shseat);
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002846 } else {
Rafael Antognollie2a34552013-12-03 15:35:45 -02002847 shell_surface_send_popup_done(shsurf);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002848 shseat->popup_grab.client = NULL;
Kristian Høgsberg3730f362012-04-13 12:40:07 -04002849 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002850}
2851
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002852static const struct wl_shell_surface_interface shell_surface_implementation = {
Scott Moreauff1db4a2012-04-17 19:06:18 -06002853 shell_surface_pong,
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002854 shell_surface_move,
2855 shell_surface_resize,
2856 shell_surface_set_toplevel,
2857 shell_surface_set_transient,
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002858 shell_surface_set_fullscreen,
Juan Zhao96879df2012-02-07 08:45:41 +08002859 shell_surface_set_popup,
Kristian Høgsberge7afd912012-05-02 09:47:44 -04002860 shell_surface_set_maximized,
2861 shell_surface_set_title,
2862 shell_surface_set_class
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002863};
2864
2865static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002866destroy_shell_surface(struct shell_surface *shsurf)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002867{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002868 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2869
Giulio Camuffo5085a752013-03-25 21:42:45 +01002870 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2871 remove_popup_grab(shsurf);
2872 }
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -05002873
Alex Wubd3354b2012-04-17 17:20:49 +08002874 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02002875 shell_surface_is_top_fullscreen(shsurf))
2876 restore_output_mode (shsurf->fullscreen_output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002877
Jason Ekstranda7af7042013-10-12 22:38:11 -05002878 if (shsurf->fullscreen.black_view)
2879 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
Alex Wuaa08e2d2012-03-05 11:01:40 +08002880
Alex Wubd3354b2012-04-17 17:20:49 +08002881 /* As destroy_resource() use wl_list_for_each_safe(),
2882 * we can always remove the listener.
2883 */
2884 wl_list_remove(&shsurf->surface_destroy_listener.link);
2885 shsurf->surface->configure = NULL;
Scott Moreau9521d5e2012-04-19 13:06:17 -06002886 ping_timer_destroy(shsurf);
Scott Moreau976a0502013-03-07 10:15:17 -07002887 free(shsurf->title);
Alex Wubd3354b2012-04-17 17:20:49 +08002888
Jason Ekstranda7af7042013-10-12 22:38:11 -05002889 weston_view_destroy(shsurf->view);
2890
Philip Withnall648a4dd2013-11-25 18:01:44 +00002891 wl_list_remove(&shsurf->children_link);
2892
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002893 wl_list_remove(&shsurf->link);
2894 free(shsurf);
2895}
2896
2897static void
Tiago Vignattibc052c92012-04-19 16:18:18 +03002898shell_destroy_shell_surface(struct wl_resource *resource)
2899{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002900 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03002901
2902 destroy_shell_surface(shsurf);
2903}
2904
2905static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002906shell_handle_surface_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002907{
2908 struct shell_surface *shsurf = container_of(listener,
2909 struct shell_surface,
2910 surface_destroy_listener);
2911
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002912 if (shsurf->resource)
2913 wl_resource_destroy(shsurf->resource);
2914 else
Tiago Vignattibc052c92012-04-19 16:18:18 +03002915 destroy_shell_surface(shsurf);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002916}
2917
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002918static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06002919shell_surface_configure(struct weston_surface *, int32_t, int32_t);
Zhang, Xiong Y31236932013-12-13 22:10:57 +02002920static void
2921shell_surface_output_destroyed(struct weston_surface *);
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002922
Kristian Høgsberg1ef23132013-12-04 00:20:01 -08002923struct shell_surface *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002924get_shell_surface(struct weston_surface *surface)
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002925{
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002926 if (surface->configure == shell_surface_configure)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002927 return surface->configure_private;
Kristian Høgsbergd8134452012-06-21 12:49:02 -04002928 else
2929 return NULL;
Pekka Paalanenec2b32f2011-11-28 15:12:34 +02002930}
2931
Rafael Antognollie2a34552013-12-03 15:35:45 -02002932static struct shell_surface *
2933create_common_surface(void *shell, struct weston_surface *surface,
2934 const struct weston_shell_client *client)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002935{
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002936 struct shell_surface *shsurf;
2937
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002938 if (surface->configure) {
Martin Minarik6d118362012-06-07 18:01:59 +02002939 weston_log("surface->configure already set\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002940 return NULL;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002941 }
2942
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002943 shsurf = calloc(1, sizeof *shsurf);
2944 if (!shsurf) {
Martin Minarik6d118362012-06-07 18:01:59 +02002945 weston_log("no memory to allocate shell surface\n");
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002946 return NULL;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002947 }
2948
Jason Ekstranda7af7042013-10-12 22:38:11 -05002949 shsurf->view = weston_view_create(surface);
2950 if (!shsurf->view) {
2951 weston_log("no memory to allocate shell surface\n");
2952 free(shsurf);
2953 return NULL;
2954 }
2955
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002956 surface->configure = shell_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01002957 surface->configure_private = shsurf;
Zhang, Xiong Y31236932013-12-13 22:10:57 +02002958 surface->output_destroyed = shell_surface_output_destroyed;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03002959
Tiago Vignattibc052c92012-04-19 16:18:18 +03002960 shsurf->shell = (struct desktop_shell *) shell;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002961 shsurf->unresponsive = 0;
Alex Wu4539b082012-03-01 12:57:46 +08002962 shsurf->saved_position_valid = false;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02002963 shsurf->saved_size_valid = false;
Alex Wu7bcb8bd2012-04-27 09:07:24 +08002964 shsurf->saved_rotation_valid = false;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002965 shsurf->surface = surface;
Alex Wu4539b082012-03-01 12:57:46 +08002966 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2967 shsurf->fullscreen.framerate = 0;
Jason Ekstranda7af7042013-10-12 22:38:11 -05002968 shsurf->fullscreen.black_view = NULL;
Scott Moreauff1db4a2012-04-17 19:06:18 -06002969 shsurf->ping_timer = NULL;
Alex Wu4539b082012-03-01 12:57:46 +08002970 wl_list_init(&shsurf->fullscreen.transform.link);
2971
Jason Ekstrand651f00e2013-06-14 10:07:54 -05002972 wl_signal_init(&shsurf->destroy_signal);
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002973 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05002974 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04002975 &shsurf->surface_destroy_listener);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002976
2977 /* init link so its safe to always remove it in destroy_shell_surface */
2978 wl_list_init(&shsurf->link);
Giulio Camuffo5085a752013-03-25 21:42:45 +01002979 wl_list_init(&shsurf->popup.grab_link);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002980
Pekka Paalanen460099f2012-01-20 16:48:25 +02002981 /* empty when not in use */
2982 wl_list_init(&shsurf->rotation.transform.link);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05002983 weston_matrix_init(&shsurf->rotation.rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02002984
Jonas Ådahl62fcd042012-06-13 00:01:23 +02002985 wl_list_init(&shsurf->workspace_transform.link);
2986
Philip Withnall648a4dd2013-11-25 18:01:44 +00002987 wl_list_init(&shsurf->children_link);
2988 wl_list_init(&shsurf->children_list);
2989 shsurf->parent = NULL;
2990
Pekka Paalanen98262232011-12-01 10:42:22 +02002991 shsurf->type = SHELL_SURFACE_NONE;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02002992
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002993 shsurf->client = client;
2994
Kristian Høgsberg45ba8692012-05-21 14:27:33 -04002995 return shsurf;
Tiago Vignattibc052c92012-04-19 16:18:18 +03002996}
2997
Rafael Antognollie2a34552013-12-03 15:35:45 -02002998static struct shell_surface *
2999create_shell_surface(void *shell, struct weston_surface *surface,
3000 const struct weston_shell_client *client)
3001{
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08003002 return create_common_surface(shell, surface, client);
Rafael Antognollie2a34552013-12-03 15:35:45 -02003003}
3004
Jason Ekstranda7af7042013-10-12 22:38:11 -05003005static struct weston_view *
3006get_primary_view(void *shell, struct shell_surface *shsurf)
3007{
3008 return shsurf->view;
3009}
3010
Tiago Vignattibc052c92012-04-19 16:18:18 +03003011static void
3012shell_get_shell_surface(struct wl_client *client,
3013 struct wl_resource *resource,
3014 uint32_t id,
3015 struct wl_resource *surface_resource)
3016{
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003017 struct weston_surface *surface =
3018 wl_resource_get_user_data(surface_resource);
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003019 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Tiago Vignattibc052c92012-04-19 16:18:18 +03003020 struct shell_surface *shsurf;
3021
3022 if (get_shell_surface(surface)) {
3023 wl_resource_post_error(surface_resource,
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003024 WL_DISPLAY_ERROR_INVALID_OBJECT,
3025 "desktop_shell::get_shell_surface already requested");
Tiago Vignattibc052c92012-04-19 16:18:18 +03003026 return;
3027 }
3028
Kristian Høgsberga61ca062012-05-22 16:05:52 -04003029 shsurf = create_shell_surface(shell, surface, &shell_client);
Kristian Høgsberg9540ea62012-05-21 14:28:57 -04003030 if (!shsurf) {
3031 wl_resource_post_error(surface_resource,
3032 WL_DISPLAY_ERROR_INVALID_OBJECT,
3033 "surface->configure already set");
3034 return;
3035 }
Tiago Vignattibc052c92012-04-19 16:18:18 +03003036
Jason Ekstranda85118c2013-06-27 20:17:02 -05003037 shsurf->resource =
3038 wl_resource_create(client,
3039 &wl_shell_surface_interface, 1, id);
3040 wl_resource_set_implementation(shsurf->resource,
3041 &shell_surface_implementation,
3042 shsurf, shell_destroy_shell_surface);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003043}
3044
Rafael Antognollie2a34552013-12-03 15:35:45 -02003045static bool
3046shell_surface_is_wl_shell_surface(struct shell_surface *shsurf)
3047{
3048 return wl_resource_instance_of(shsurf->resource,
3049 &wl_shell_surface_interface,
3050 &shell_surface_implementation);
3051}
3052
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003053static const struct wl_shell_interface shell_implementation = {
Pekka Paalanen46229672011-11-29 15:49:31 +02003054 shell_get_shell_surface
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05003055};
3056
Rafael Antognollie2a34552013-12-03 15:35:45 -02003057/****************************
3058 * xdg-shell implementation */
3059
3060static void
3061xdg_surface_destroy(struct wl_client *client,
3062 struct wl_resource *resource)
3063{
3064 wl_resource_destroy(resource);
3065}
3066
3067static void
3068xdg_surface_pong(struct wl_client *client,
3069 struct wl_resource *resource,
3070 uint32_t serial)
3071{
3072 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3073
3074 surface_pong(shsurf, serial);
3075}
3076
3077static void
3078xdg_surface_set_app_id(struct wl_client *client,
3079 struct wl_resource *resource,
3080 const char *app_id)
3081{
3082 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3083
3084 free(shsurf->class);
3085 shsurf->class = strdup(app_id);
3086}
3087
3088static void
3089xdg_surface_set_title(struct wl_client *client,
3090 struct wl_resource *resource, const char *title)
3091{
3092 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3093
3094 set_title(shsurf, title);
3095}
3096
3097static void
3098xdg_surface_move(struct wl_client *client, struct wl_resource *resource,
3099 struct wl_resource *seat_resource, uint32_t serial)
3100{
3101 common_surface_move(resource, seat_resource, serial);
3102}
3103
3104static void
3105xdg_surface_resize(struct wl_client *client, struct wl_resource *resource,
3106 struct wl_resource *seat_resource, uint32_t serial,
3107 uint32_t edges)
3108{
3109 common_surface_resize(resource, seat_resource, serial, edges);
3110}
3111
3112static void
3113xdg_surface_set_output(struct wl_client *client,
3114 struct wl_resource *resource,
3115 struct wl_resource *output_resource)
3116{
3117 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3118 struct weston_output *output;
3119
3120 if (output_resource)
3121 output = wl_resource_get_user_data(output_resource);
3122 else
3123 output = NULL;
3124
Rafael Antognolli65f98d82013-12-03 15:35:47 -02003125 shsurf->recommended_output = output;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003126}
3127
3128static void
3129xdg_surface_set_fullscreen(struct wl_client *client,
3130 struct wl_resource *resource)
3131{
3132 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3133
3134 if (shsurf->type != SHELL_SURFACE_TOPLEVEL)
3135 return;
3136
Kristian Høgsberge960b3f2013-12-05 22:04:42 -08003137 if (!shsurf->next_state.fullscreen)
Rafael Antognollie2a34552013-12-03 15:35:45 -02003138 set_fullscreen(shsurf,
3139 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
Rafael Antognolli65f98d82013-12-03 15:35:47 -02003140 0, shsurf->recommended_output);
Rafael Antognollie2a34552013-12-03 15:35:45 -02003141}
3142
3143static void
3144xdg_surface_unset_fullscreen(struct wl_client *client,
3145 struct wl_resource *resource)
3146{
3147 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003148 int32_t width, height;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003149
3150 if (shsurf->type != SHELL_SURFACE_TOPLEVEL)
3151 return;
3152
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003153 if (!shsurf->next_state.fullscreen)
3154 return;
3155
Rafael Antognollie2a34552013-12-03 15:35:45 -02003156 shsurf->next_state.fullscreen = false;
3157 shsurf->state_changed = true;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003158
3159 if (shsurf->saved_size_valid) {
3160 width = shsurf->saved_width;
3161 height = shsurf->saved_height;
3162 shsurf->saved_size_valid = false;
3163 } else {
3164 width = shsurf->surface->width;
3165 height = shsurf->surface->height;
3166 }
3167
3168 shsurf->client->send_configure(shsurf->surface, 0, width, height);
Rafael Antognollie2a34552013-12-03 15:35:45 -02003169}
3170
3171static void
3172xdg_surface_set_maximized(struct wl_client *client,
3173 struct wl_resource *resource)
3174{
3175 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3176
3177 if (shsurf->type != SHELL_SURFACE_TOPLEVEL)
3178 return;
3179
Kristian Høgsbergc2745b12013-12-05 22:00:40 -08003180 if (!shsurf->next_state.maximized)
Rafael Antognolli65f98d82013-12-03 15:35:47 -02003181 set_maximized(shsurf, NULL);
Rafael Antognollie2a34552013-12-03 15:35:45 -02003182}
3183
3184static void
3185xdg_surface_unset_maximized(struct wl_client *client,
3186 struct wl_resource *resource)
3187{
3188 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003189 int32_t width, height;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003190
3191 if (shsurf->type != SHELL_SURFACE_TOPLEVEL)
3192 return;
3193
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003194 if (!shsurf->next_state.maximized)
3195 return;
3196
Rafael Antognollie2a34552013-12-03 15:35:45 -02003197 shsurf->next_state.maximized = false;
3198 shsurf->state_changed = true;
Rafael Antognolli3c4e3f72013-12-03 15:35:46 -02003199
3200 if (shsurf->saved_size_valid) {
3201 width = shsurf->saved_width;
3202 height = shsurf->saved_height;
3203 shsurf->saved_size_valid = false;
3204 } else {
3205 width = shsurf->surface->width;
3206 height = shsurf->surface->height;
3207 }
3208
3209 shsurf->client->send_configure(shsurf->surface, 0, width, height);
Rafael Antognollie2a34552013-12-03 15:35:45 -02003210}
3211
3212static const struct xdg_surface_interface xdg_surface_implementation = {
3213 xdg_surface_destroy,
3214 xdg_surface_set_transient_for,
3215 xdg_surface_set_title,
3216 xdg_surface_set_app_id,
3217 xdg_surface_pong,
3218 xdg_surface_move,
3219 xdg_surface_resize,
3220 xdg_surface_set_output,
3221 xdg_surface_set_fullscreen,
3222 xdg_surface_unset_fullscreen,
3223 xdg_surface_set_maximized,
3224 xdg_surface_unset_maximized,
3225 NULL /* set_minimized */
3226};
3227
3228static void
3229xdg_send_configure(struct weston_surface *surface,
3230 uint32_t edges, int32_t width, int32_t height)
3231{
3232 struct shell_surface *shsurf = get_shell_surface(surface);
3233
3234 xdg_surface_send_configure(shsurf->resource, edges, width, height);
3235}
3236
3237static const struct weston_shell_client xdg_client = {
3238 xdg_send_configure
3239};
3240
3241static void
3242xdg_use_unstable_version(struct wl_client *client,
3243 struct wl_resource *resource,
3244 int32_t version)
3245{
3246 if (version > 1) {
3247 wl_resource_post_error(resource,
3248 1,
3249 "xdg-shell:: version not implemented yet.");
3250 return;
3251 }
3252}
3253
3254static struct shell_surface *
3255create_xdg_surface(void *shell, struct weston_surface *surface,
3256 const struct weston_shell_client *client)
3257{
3258 struct shell_surface *shsurf;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003259
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08003260 shsurf = create_common_surface(shell, surface, client);
3261 shsurf->type = SHELL_SURFACE_TOPLEVEL;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003262
3263 return shsurf;
3264}
3265
3266static void
3267xdg_get_xdg_surface(struct wl_client *client,
3268 struct wl_resource *resource,
3269 uint32_t id,
3270 struct wl_resource *surface_resource)
3271{
3272 struct weston_surface *surface =
3273 wl_resource_get_user_data(surface_resource);
3274 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3275 struct shell_surface *shsurf;
3276
3277 if (get_shell_surface(surface)) {
3278 wl_resource_post_error(surface_resource,
3279 WL_DISPLAY_ERROR_INVALID_OBJECT,
3280 "desktop_shell::get_shell_surface already requested");
3281 return;
3282 }
3283
3284 shsurf = create_xdg_surface(shell, surface, &xdg_client);
3285 if (!shsurf) {
3286 wl_resource_post_error(surface_resource,
3287 WL_DISPLAY_ERROR_INVALID_OBJECT,
3288 "surface->configure already set");
3289 return;
3290 }
3291
3292 shsurf->resource =
3293 wl_resource_create(client,
3294 &xdg_surface_interface, 1, id);
3295 wl_resource_set_implementation(shsurf->resource,
3296 &xdg_surface_implementation,
3297 shsurf, shell_destroy_shell_surface);
3298}
3299
3300static bool
3301shell_surface_is_xdg_surface(struct shell_surface *shsurf)
3302{
3303 return wl_resource_instance_of(shsurf->resource,
3304 &xdg_surface_interface,
3305 &xdg_surface_implementation);
3306}
3307
3308/* xdg-popup implementation */
3309
3310static void
3311xdg_popup_destroy(struct wl_client *client,
3312 struct wl_resource *resource)
3313{
3314 wl_resource_destroy(resource);
3315}
3316
3317static void
3318xdg_popup_pong(struct wl_client *client,
3319 struct wl_resource *resource,
3320 uint32_t serial)
3321{
3322 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
3323
3324 surface_pong(shsurf, serial);
3325}
3326
3327static const struct xdg_popup_interface xdg_popup_implementation = {
3328 xdg_popup_destroy,
3329 xdg_popup_pong
3330};
3331
3332static void
3333xdg_popup_send_configure(struct weston_surface *surface,
3334 uint32_t edges, int32_t width, int32_t height)
3335{
3336}
3337
3338static const struct weston_shell_client xdg_popup_client = {
3339 xdg_popup_send_configure
3340};
3341
3342static struct shell_surface *
3343create_xdg_popup(void *shell, struct weston_surface *surface,
3344 const struct weston_shell_client *client,
3345 struct weston_surface *parent,
3346 struct shell_seat *seat,
3347 uint32_t serial,
3348 int32_t x, int32_t y)
3349{
3350 struct shell_surface *shsurf;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003351
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08003352 shsurf = create_common_surface(shell, surface, client);
3353 shsurf->type = SHELL_SURFACE_POPUP;
Rafael Antognollie2a34552013-12-03 15:35:45 -02003354 shsurf->popup.shseat = seat;
3355 shsurf->popup.serial = serial;
3356 shsurf->popup.x = x;
3357 shsurf->popup.y = y;
3358 shell_surface_set_parent(shsurf, parent);
3359
3360 return shsurf;
3361}
3362
3363static void
3364xdg_get_xdg_popup(struct wl_client *client,
3365 struct wl_resource *resource,
3366 uint32_t id,
3367 struct wl_resource *surface_resource,
3368 struct wl_resource *parent_resource,
3369 struct wl_resource *seat_resource,
3370 uint32_t serial,
3371 int32_t x, int32_t y, uint32_t flags)
3372{
3373 struct weston_surface *surface =
3374 wl_resource_get_user_data(surface_resource);
3375 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3376 struct shell_surface *shsurf;
3377 struct weston_surface *parent;
3378 struct shell_seat *seat;
3379
3380 if (get_shell_surface(surface)) {
3381 wl_resource_post_error(surface_resource,
3382 WL_DISPLAY_ERROR_INVALID_OBJECT,
3383 "desktop_shell::get_shell_surface already requested");
3384 return;
3385 }
3386
3387 if (!parent_resource) {
3388 wl_resource_post_error(surface_resource,
3389 WL_DISPLAY_ERROR_INVALID_OBJECT,
3390 "xdg_shell::get_xdg_popup requires a parent shell surface");
3391 }
3392
3393 parent = wl_resource_get_user_data(parent_resource);
3394 seat = get_shell_seat(wl_resource_get_user_data(seat_resource));;
3395
3396 shsurf = create_xdg_popup(shell, surface, &xdg_popup_client,
3397 parent, seat, serial, x, y);
3398 if (!shsurf) {
3399 wl_resource_post_error(surface_resource,
3400 WL_DISPLAY_ERROR_INVALID_OBJECT,
3401 "surface->configure already set");
3402 return;
3403 }
3404
3405 shsurf->resource =
3406 wl_resource_create(client,
3407 &xdg_popup_interface, 1, id);
3408 wl_resource_set_implementation(shsurf->resource,
3409 &xdg_popup_implementation,
3410 shsurf, shell_destroy_shell_surface);
3411}
3412
3413static bool
3414shell_surface_is_xdg_popup(struct shell_surface *shsurf)
3415{
3416 return wl_resource_instance_of(shsurf->resource,
3417 &xdg_popup_interface,
3418 &xdg_popup_implementation);
3419}
3420
3421static const struct xdg_shell_interface xdg_implementation = {
3422 xdg_use_unstable_version,
3423 xdg_get_xdg_surface,
3424 xdg_get_xdg_popup
3425};
3426
3427static int
3428xdg_shell_unversioned_dispatch(const void *implementation,
3429 void *_target, uint32_t opcode,
3430 const struct wl_message *message,
3431 union wl_argument *args)
3432{
3433 struct wl_resource *resource = _target;
3434 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3435
3436 if (opcode != 0) {
3437 wl_resource_post_error(resource,
3438 WL_DISPLAY_ERROR_INVALID_OBJECT,
3439 "must call use_unstable_version first");
3440 return 0;
3441 }
3442
3443#define XDG_SERVER_VERSION 1
3444
Kristian Høgsberg8d344a02013-12-08 22:27:11 -08003445 static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT,
3446 "shell implementation doesn't match protocol version");
3447
Rafael Antognollie2a34552013-12-03 15:35:45 -02003448 if (args[0].i != XDG_SERVER_VERSION) {
3449 wl_resource_post_error(resource,
3450 WL_DISPLAY_ERROR_INVALID_OBJECT,
3451 "incompatible version, server is %d "
3452 "client wants %d",
3453 XDG_SERVER_VERSION, args[0].i);
3454 return 0;
3455 }
3456
3457 wl_resource_set_implementation(resource, &xdg_implementation,
3458 shell, NULL);
3459
3460 return 1;
3461}
3462
3463/* end of xdg-shell implementation */
3464/***********************************/
3465
Kristian Høgsberg07937562011-04-12 17:25:42 -04003466static void
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02003467shell_fade(struct desktop_shell *shell, enum fade_type type);
3468
3469static int
3470screensaver_timeout(void *data)
3471{
3472 struct desktop_shell *shell = data;
3473
3474 shell_fade(shell, FADE_OUT);
3475
3476 return 1;
3477}
3478
3479static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003480handle_screensaver_sigchld(struct weston_process *proc, int status)
Pekka Paalanen18027e52011-12-02 16:31:49 +02003481{
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003482 struct desktop_shell *shell =
3483 container_of(proc, struct desktop_shell, screensaver.process);
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003484
Pekka Paalanen18027e52011-12-02 16:31:49 +02003485 proc->pid = 0;
Ander Conselvan de Oliveira18639f82013-02-15 18:44:19 +02003486
3487 if (shell->locked)
Ander Conselvan de Oliveirab17537e2013-02-22 14:16:18 +02003488 weston_compositor_sleep(shell->compositor);
Pekka Paalanen18027e52011-12-02 16:31:49 +02003489}
3490
3491static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003492launch_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003493{
3494 if (shell->screensaver.binding)
3495 return;
3496
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003497 if (!shell->screensaver.path) {
3498 weston_compositor_sleep(shell->compositor);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003499 return;
Ander Conselvan de Oliveiradda9d782013-02-22 14:16:19 +02003500 }
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003501
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003502 if (shell->screensaver.process.pid != 0) {
Martin Minarik6d118362012-06-07 18:01:59 +02003503 weston_log("old screensaver still running\n");
Kristian Høgsberg32bed572012-03-01 17:11:36 -05003504 return;
3505 }
3506
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003507 weston_client_launch(shell->compositor,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003508 &shell->screensaver.process,
Pekka Paalanene955f1e2011-12-07 11:49:52 +02003509 shell->screensaver.path,
Pekka Paalanen18027e52011-12-02 16:31:49 +02003510 handle_screensaver_sigchld);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003511}
3512
3513static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003514terminate_screensaver(struct desktop_shell *shell)
Pekka Paalanen77346a62011-11-30 16:26:35 +02003515{
Pekka Paalanen18027e52011-12-02 16:31:49 +02003516 if (shell->screensaver.process.pid == 0)
3517 return;
3518
3519 kill(shell->screensaver.process.pid, SIGTERM);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003520}
3521
3522static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003523configure_static_view(struct weston_view *ev, struct weston_layer *layer)
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003524{
Jason Ekstranda7af7042013-10-12 22:38:11 -05003525 struct weston_view *v, *next;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003526
Jason Ekstranda7af7042013-10-12 22:38:11 -05003527 wl_list_for_each_safe(v, next, &layer->view_list, layer_link) {
3528 if (v->output == ev->output && v != ev) {
3529 weston_view_unmap(v);
3530 v->surface->configure = NULL;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003531 }
3532 }
3533
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003534 weston_view_set_position(ev, ev->output->x, ev->output->y);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003535
Jason Ekstranda7af7042013-10-12 22:38:11 -05003536 if (wl_list_empty(&ev->layer_link)) {
3537 wl_list_insert(&layer->view_list, &ev->layer_link);
3538 weston_compositor_schedule_repaint(ev->surface->compositor);
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003539 }
3540}
3541
3542static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003543background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003544{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003545 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003546 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003547
Jason Ekstranda7af7042013-10-12 22:38:11 -05003548 view = container_of(es->views.next, struct weston_view, surface_link);
3549
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003550 configure_static_view(view, &shell->background_layer);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003551}
3552
3553static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003554desktop_shell_set_background(struct wl_client *client,
3555 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003556 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003557 struct wl_resource *surface_resource)
3558{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003559 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003560 struct weston_surface *surface =
3561 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003562 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003563
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003564 if (surface->configure) {
3565 wl_resource_post_error(surface_resource,
3566 WL_DISPLAY_ERROR_INVALID_OBJECT,
3567 "surface role already assigned");
3568 return;
3569 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003570
Jason Ekstranda7af7042013-10-12 22:38:11 -05003571 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3572 weston_view_destroy(view);
3573 view = weston_view_create(surface);
3574
Kristian Høgsberg962342c2012-06-26 16:29:50 -04003575 surface->configure = background_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003576 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003577 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003578 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003579 desktop_shell_send_configure(resource, 0,
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05003580 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003581 surface->output->width,
3582 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003583}
3584
3585static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003586panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003587{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003588 struct desktop_shell *shell = es->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003589 struct weston_view *view;
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003590
Jason Ekstranda7af7042013-10-12 22:38:11 -05003591 view = container_of(es->views.next, struct weston_view, surface_link);
3592
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003593 configure_static_view(view, &shell->panel_layer);
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003594}
3595
3596static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04003597desktop_shell_set_panel(struct wl_client *client,
3598 struct wl_resource *resource,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003599 struct wl_resource *output_resource,
Kristian Høgsberg75840622011-09-06 13:48:16 -04003600 struct wl_resource *surface_resource)
3601{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003602 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003603 struct weston_surface *surface =
3604 wl_resource_get_user_data(surface_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003605 struct weston_view *view, *next;
Kristian Høgsberg75840622011-09-06 13:48:16 -04003606
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003607 if (surface->configure) {
3608 wl_resource_post_error(surface_resource,
3609 WL_DISPLAY_ERROR_INVALID_OBJECT,
3610 "surface role already assigned");
3611 return;
3612 }
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003613
Jason Ekstranda7af7042013-10-12 22:38:11 -05003614 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3615 weston_view_destroy(view);
3616 view = weston_view_create(surface);
3617
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003618 surface->configure = panel_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003619 surface->configure_private = shell;
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05003620 surface->output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05003621 view->output = surface->output;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04003622 desktop_shell_send_configure(resource, 0,
Kristian Høgsbergaf7b1ff2012-06-26 21:19:23 -04003623 surface_resource,
Scott Moreau1bad5db2012-08-18 01:04:05 -06003624 surface->output->width,
3625 surface->output->height);
Kristian Høgsberg75840622011-09-06 13:48:16 -04003626}
3627
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003628static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003629lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003630{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003631 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05003632 struct weston_view *view;
3633
3634 view = container_of(surface->views.next, struct weston_view, surface_link);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003635
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003636 if (surface->width == 0)
Giulio Camuffo184df502013-02-21 11:29:21 +01003637 return;
3638
Jason Ekstranda7af7042013-10-12 22:38:11 -05003639 center_on_output(view, get_default_output(shell->compositor));
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003640
3641 if (!weston_surface_is_mapped(surface)) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05003642 wl_list_insert(&shell->lock_layer.view_list,
3643 &view->layer_link);
3644 weston_view_update_transform(view);
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003645 shell_fade(shell, FADE_IN);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003646 }
3647}
3648
3649static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003650handle_lock_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003651{
Tiago Vignattibe143262012-04-16 17:31:41 +03003652 struct desktop_shell *shell =
3653 container_of(listener, struct desktop_shell, lock_surface_listener);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003654
Martin Minarik6d118362012-06-07 18:01:59 +02003655 weston_log("lock surface gone\n");
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05003656 shell->lock_surface = NULL;
3657}
3658
3659static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003660desktop_shell_set_lock_surface(struct wl_client *client,
3661 struct wl_resource *resource,
3662 struct wl_resource *surface_resource)
3663{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003664 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003665 struct weston_surface *surface =
3666 wl_resource_get_user_data(surface_resource);
Pekka Paalanen98262232011-12-01 10:42:22 +02003667
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003668 shell->prepare_event_sent = false;
Kristian Høgsbergaf867cc2011-11-15 13:34:49 +02003669
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003670 if (!shell->locked)
3671 return;
3672
Pekka Paalanen98262232011-12-01 10:42:22 +02003673 shell->lock_surface = surface;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003674
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003675 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003676 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg27e30522012-04-11 23:18:23 -04003677 &shell->lock_surface_listener);
Pekka Paalanen57da4a82011-11-23 16:42:16 +02003678
Kristian Høgsbergaa2ee8b2013-10-30 15:49:45 -07003679 weston_view_create(surface);
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04003680 surface->configure = lock_surface_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01003681 surface->configure_private = shell;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003682}
3683
3684static void
Tiago Vignattibe143262012-04-16 17:31:41 +03003685resume_desktop(struct desktop_shell *shell)
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003686{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04003687 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanen77346a62011-11-30 16:26:35 +02003688
Pekka Paalanen77346a62011-11-30 16:26:35 +02003689 terminate_screensaver(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003690
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05003691 wl_list_remove(&shell->lock_layer.link);
3692 wl_list_insert(&shell->compositor->cursor_layer.link,
3693 &shell->fullscreen_layer.link);
3694 wl_list_insert(&shell->fullscreen_layer.link,
3695 &shell->panel_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02003696 if (shell->showing_input_panels) {
3697 wl_list_insert(&shell->panel_layer.link,
3698 &shell->input_panel_layer.link);
3699 wl_list_insert(&shell->input_panel_layer.link,
3700 &ws->layer.link);
3701 } else {
3702 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
3703 }
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003704
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04003705 restore_focus_state(shell, get_current_workspace(shell));
Jonas Ådahl04769742012-06-13 00:01:24 +02003706
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003707 shell->locked = false;
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02003708 shell_fade(shell, FADE_IN);
Pekka Paalanenfc6d91a2012-02-10 15:33:10 +02003709 weston_compositor_damage_all(shell->compositor);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003710}
3711
3712static void
3713desktop_shell_unlock(struct wl_client *client,
3714 struct wl_resource *resource)
3715{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003716 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003717
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003718 shell->prepare_event_sent = false;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02003719
3720 if (shell->locked)
3721 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003722}
3723
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003724static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03003725desktop_shell_set_grab_surface(struct wl_client *client,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003726 struct wl_resource *resource,
3727 struct wl_resource *surface_resource)
3728{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003729 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003730
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05003731 shell->grab_surface = wl_resource_get_user_data(surface_resource);
Kristian Høgsberg48588f82013-10-24 15:51:35 -07003732 weston_view_create(shell->grab_surface);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003733}
3734
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003735static void
3736desktop_shell_desktop_ready(struct wl_client *client,
3737 struct wl_resource *resource)
3738{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05003739 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003740
3741 shell_fade_startup(shell);
3742}
3743
Kristian Høgsberg75840622011-09-06 13:48:16 -04003744static const struct desktop_shell_interface desktop_shell_implementation = {
3745 desktop_shell_set_background,
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02003746 desktop_shell_set_panel,
3747 desktop_shell_set_lock_surface,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04003748 desktop_shell_unlock,
Pekka Paalanen79346ab2013-05-22 18:03:09 +03003749 desktop_shell_set_grab_surface,
3750 desktop_shell_desktop_ready
Kristian Høgsberg75840622011-09-06 13:48:16 -04003751};
3752
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003753static enum shell_surface_type
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003754get_shell_surface_type(struct weston_surface *surface)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003755{
3756 struct shell_surface *shsurf;
3757
3758 shsurf = get_shell_surface(surface);
3759 if (!shsurf)
Pekka Paalanen98262232011-12-01 10:42:22 +02003760 return SHELL_SURFACE_NONE;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003761 return shsurf->type;
3762}
3763
Kristian Høgsberg75840622011-09-06 13:48:16 -04003764static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003765move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003766{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003767 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003768 struct weston_surface *surface;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003769 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003770
Pekka Paalanen01388e22013-04-25 13:57:44 +03003771 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003772 if (surface == NULL)
3773 return;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003774
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003775 shsurf = get_shell_surface(surface);
Rafael Antognolli03b16592013-12-03 15:35:42 -02003776 if (shsurf == NULL || shsurf->state.fullscreen ||
3777 shsurf->state.maximized)
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003778 return;
3779
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04003780 surface_move(shsurf, (struct weston_seat *) seat);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003781}
3782
3783static void
Rafael Antognolliea997ac2013-12-03 15:35:48 -02003784maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
3785{
3786 struct weston_surface *focus = seat->pointer->focus->surface;
3787 struct weston_surface *surface;
3788 struct shell_surface *shsurf;
3789
3790 surface = weston_surface_get_main_surface(focus);
3791 if (surface == NULL)
3792 return;
3793
3794 shsurf = get_shell_surface(surface);
3795 if (shsurf == NULL)
3796 return;
3797
3798 if (!shell_surface_is_xdg_surface(shsurf))
3799 return;
3800
3801 if (shsurf->state.maximized)
3802 xdg_surface_send_request_unset_maximized(shsurf->resource);
3803 else
3804 xdg_surface_send_request_set_maximized(shsurf->resource);
3805}
3806
3807static void
3808fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
3809{
3810 struct weston_surface *focus = seat->pointer->focus->surface;
3811 struct weston_surface *surface;
3812 struct shell_surface *shsurf;
3813
3814 surface = weston_surface_get_main_surface(focus);
3815 if (surface == NULL)
3816 return;
3817
3818 shsurf = get_shell_surface(surface);
3819 if (shsurf == NULL)
3820 return;
3821
3822 if (!shell_surface_is_xdg_surface(shsurf))
3823 return;
3824
3825 if (shsurf->state.fullscreen)
3826 xdg_surface_send_request_unset_fullscreen(shsurf->resource);
3827 else
3828 xdg_surface_send_request_set_fullscreen(shsurf->resource);
3829}
3830
3831static void
Neil Robertsaba0f252013-10-03 16:43:05 +01003832touch_move_binding(struct weston_seat *seat, uint32_t time, void *data)
3833{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003834 struct weston_surface *focus = seat->touch->focus->surface;
Neil Robertsaba0f252013-10-03 16:43:05 +01003835 struct weston_surface *surface;
3836 struct shell_surface *shsurf;
3837
3838 surface = weston_surface_get_main_surface(focus);
3839 if (surface == NULL)
3840 return;
3841
3842 shsurf = get_shell_surface(surface);
Rafael Antognolli03b16592013-12-03 15:35:42 -02003843 if (shsurf == NULL || shsurf->state.fullscreen ||
3844 shsurf->state.maximized)
Neil Robertsaba0f252013-10-03 16:43:05 +01003845 return;
3846
3847 surface_touch_move(shsurf, (struct weston_seat *) seat);
3848}
3849
3850static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003851resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003852{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003853 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003854 struct weston_surface *surface;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003855 uint32_t edges = 0;
3856 int32_t x, y;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003857 struct shell_surface *shsurf;
Kristian Høgsbergd2abb832011-11-23 10:52:40 -05003858
Pekka Paalanen01388e22013-04-25 13:57:44 +03003859 surface = weston_surface_get_main_surface(focus);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01003860 if (surface == NULL)
3861 return;
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003862
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003863 shsurf = get_shell_surface(surface);
Rafael Antognolli03b16592013-12-03 15:35:42 -02003864 if (shsurf == NULL || shsurf->state.fullscreen ||
3865 shsurf->state.maximized)
Pekka Paalanen92a0dc42011-11-28 15:34:13 +02003866 return;
3867
Jason Ekstranda7af7042013-10-12 22:38:11 -05003868 weston_view_from_global(shsurf->view,
3869 wl_fixed_to_int(seat->pointer->grab_x),
3870 wl_fixed_to_int(seat->pointer->grab_y),
3871 &x, &y);
Kristian Høgsberg07937562011-04-12 17:25:42 -04003872
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003873 if (x < shsurf->surface->width / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003874 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003875 else if (x < 2 * shsurf->surface->width / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003876 edges |= 0;
3877 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003878 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003879
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003880 if (y < shsurf->surface->height / 3)
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003881 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06003882 else if (y < 2 * shsurf->surface->height / 3)
Kristian Høgsberg07937562011-04-12 17:25:42 -04003883 edges |= 0;
3884 else
Pekka Paalanen9d1613e2011-11-25 12:09:16 +02003885 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
Kristian Høgsberg07937562011-04-12 17:25:42 -04003886
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04003887 surface_resize(shsurf, (struct weston_seat *) seat, edges);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04003888}
3889
3890static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003891surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003892 wl_fixed_t value, void *data)
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003893{
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003894 float step = 0.005;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003895 struct shell_surface *shsurf;
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07003896 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03003897 struct weston_surface *surface;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003898
Pekka Paalanen01388e22013-04-25 13:57:44 +03003899 /* XXX: broken for windows containing sub-surfaces */
3900 surface = weston_surface_get_main_surface(focus);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003901 if (surface == NULL)
3902 return;
3903
3904 shsurf = get_shell_surface(surface);
3905 if (!shsurf)
3906 return;
3907
Jason Ekstranda7af7042013-10-12 22:38:11 -05003908 shsurf->view->alpha -= wl_fixed_to_double(value) * step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003909
Jason Ekstranda7af7042013-10-12 22:38:11 -05003910 if (shsurf->view->alpha > 1.0)
3911 shsurf->view->alpha = 1.0;
3912 if (shsurf->view->alpha < step)
3913 shsurf->view->alpha = step;
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003914
Jason Ekstranda7af7042013-10-12 22:38:11 -05003915 weston_view_geometry_dirty(shsurf->view);
Scott Moreaua3aa9c92012-03-22 11:01:03 -06003916 weston_surface_damage(surface);
3917}
3918
3919static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003920do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003921 wl_fixed_t value)
Scott Moreauccbf29d2012-02-22 14:21:41 -07003922{
Daniel Stone37816df2012-05-16 18:45:18 +01003923 struct weston_seat *ws = (struct weston_seat *) seat;
3924 struct weston_compositor *compositor = ws->compositor;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003925 struct weston_output *output;
Scott Moreaue6603982012-06-11 13:07:51 -06003926 float increment;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003927
3928 wl_list_for_each(output, &compositor->output_list, link) {
3929 if (pixman_region32_contains_point(&output->region,
Daniel Stone37816df2012-05-16 18:45:18 +01003930 wl_fixed_to_double(seat->pointer->x),
3931 wl_fixed_to_double(seat->pointer->y),
Daniel Stone103db7f2012-05-08 17:17:55 +01003932 NULL)) {
Daniel Stone325fc2d2012-05-30 16:31:58 +01003933 if (key == KEY_PAGEUP)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003934 increment = output->zoom.increment;
Daniel Stone325fc2d2012-05-30 16:31:58 +01003935 else if (key == KEY_PAGEDOWN)
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003936 increment = -output->zoom.increment;
3937 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003938 /* For every pixel zoom 20th of a step */
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003939 increment = output->zoom.increment *
Jonas Ådahlb0b87ba2012-09-27 18:40:42 +02003940 -wl_fixed_to_double(value) / 20.0;
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003941 else
3942 increment = 0;
3943
Kristian Høgsberg9b68af02012-05-22 12:55:18 -04003944 output->zoom.level += increment;
Scott Moreauc6d7f602012-02-23 22:28:37 -07003945
Scott Moreaue6603982012-06-11 13:07:51 -06003946 if (output->zoom.level < 0.0)
Scott Moreau850ca422012-05-21 15:21:25 -06003947 output->zoom.level = 0.0;
Scott Moreaue6603982012-06-11 13:07:51 -06003948 else if (output->zoom.level > output->zoom.max_level)
3949 output->zoom.level = output->zoom.max_level;
Ville Syrjäläaa628d02012-11-16 11:48:47 +02003950 else if (!output->zoom.active) {
Giulio Camuffo412b0242013-11-14 23:42:51 +01003951 weston_output_activate_zoom(output);
Kristian Høgsberg79af73e2012-08-03 15:45:23 -04003952 }
Scott Moreauccbf29d2012-02-22 14:21:41 -07003953
Scott Moreaue6603982012-06-11 13:07:51 -06003954 output->zoom.spring_z.target = output->zoom.level;
Scott Moreauccbf29d2012-02-22 14:21:41 -07003955
Jason Ekstranda7af7042013-10-12 22:38:11 -05003956 weston_output_update_zoom(output);
Scott Moreauccbf29d2012-02-22 14:21:41 -07003957 }
3958 }
3959}
3960
Scott Moreauccbf29d2012-02-22 14:21:41 -07003961static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003962zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +01003963 wl_fixed_t value, void *data)
Daniel Stone325fc2d2012-05-30 16:31:58 +01003964{
3965 do_zoom(seat, time, 0, axis, value);
3966}
3967
3968static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003969zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003970 void *data)
3971{
3972 do_zoom(seat, time, key, 0, 0);
3973}
3974
3975static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04003976terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01003977 void *data)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003978{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05003979 struct weston_compositor *compositor = data;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003980
Daniel Stone325fc2d2012-05-30 16:31:58 +01003981 wl_display_terminate(compositor->wl_display);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05003982}
3983
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01003984struct alt_tab {
3985 struct desktop_shell *shell;
3986 struct weston_keyboard_grab grab;
3987
3988 struct wl_list *current;
3989
3990 struct wl_list preview_list;
3991};
3992
3993struct alt_tab_preview {
3994 struct alt_tab *alt_tab;
3995
3996 struct weston_view *view;
3997 struct weston_transform transform;
3998
3999 struct wl_listener listener;
4000
4001 struct wl_list link;
4002};
4003
4004static void
4005alt_tab_next(struct alt_tab *alt_tab)
4006{
4007 alt_tab->current = alt_tab->current->next;
4008
4009 /* Make sure we're not pointing to the list header e.g. after
4010 * cycling through the whole list. */
4011 if (alt_tab->current->next == alt_tab->preview_list.next)
4012 alt_tab->current = alt_tab->current->next;
4013}
4014
4015static void
4016alt_tab_destroy(struct alt_tab *alt_tab)
4017{
4018 struct alt_tab_preview *preview, *next;
4019 struct weston_keyboard *keyboard = alt_tab->grab.keyboard;
4020
4021 if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) {
4022 preview = wl_container_of(alt_tab->current, preview, link);
4023
4024 activate(alt_tab->shell, preview->view->surface,
4025 (struct weston_seat *) keyboard->seat);
4026 }
4027
4028 wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) {
4029 wl_list_remove(&preview->link);
4030 wl_list_remove(&preview->listener.link);
4031 weston_view_destroy(preview->view);
4032 free(preview);
4033 }
4034
4035 weston_keyboard_end_grab(keyboard);
4036 if (keyboard->input_method_resource)
4037 keyboard->grab = &keyboard->input_method_grab;
4038
4039 free(alt_tab);
4040}
4041
4042static void
4043alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data)
4044{
4045 struct alt_tab_preview *preview =
4046 container_of(listener, struct alt_tab_preview, listener);
4047 struct alt_tab *alt_tab = preview->alt_tab;
4048 int advance = 0;
4049
4050 /* If the preview that we're removing is the currently selected one,
4051 * we want to move to the next one. So we move to ->prev and then
4052 * call _next() after removing the preview. */
4053 if (alt_tab->current == &preview->link) {
4054 alt_tab->current = alt_tab->current->prev;
4055 advance = 1;
4056 }
4057
4058 wl_list_remove(&preview->listener.link);
4059 wl_list_remove(&preview->link);
4060
4061 free(preview);
4062
4063 if (advance)
4064 alt_tab_next(alt_tab);
4065
4066 /* If the last preview goes away, stop the alt-tab */
4067 if (wl_list_empty(alt_tab->current))
4068 alt_tab_destroy(alt_tab);
4069}
4070
4071static void
4072alt_tab_key(struct weston_keyboard_grab *grab,
4073 uint32_t time, uint32_t key, uint32_t state_w)
4074{
4075 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
4076 enum wl_keyboard_key_state state = state_w;
4077
4078 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
4079 alt_tab_next(alt_tab);
4080}
4081
4082static void
4083alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
4084 uint32_t mods_depressed, uint32_t mods_latched,
4085 uint32_t mods_locked, uint32_t group)
4086{
4087 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
4088 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
4089
4090 if ((seat->modifier_state & MODIFIER_ALT) == 0)
4091 alt_tab_destroy(alt_tab);
4092}
4093
4094static void
4095alt_tab_cancel(struct weston_keyboard_grab *grab)
4096{
4097 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
4098
4099 alt_tab_destroy(alt_tab);
4100}
4101
4102static const struct weston_keyboard_grab_interface alt_tab_grab = {
4103 alt_tab_key,
4104 alt_tab_modifier,
4105 alt_tab_cancel,
4106};
4107
4108static int
4109view_for_alt_tab(struct weston_view *view)
4110{
Rafael Antognollied207b42013-12-03 15:35:43 -02004111 struct shell_surface *shsurf = get_shell_surface(view->surface);
4112 if (!shsurf)
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01004113 return 0;
4114
Rafael Antognollied207b42013-12-03 15:35:43 -02004115 if (shsurf->parent)
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01004116 return 0;
4117
4118 if (view != get_default_view(view->surface))
4119 return 0;
4120
4121 return 1;
4122}
4123
4124static void
4125alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4126 void *data)
4127{
4128 struct alt_tab *alt_tab;
4129 struct desktop_shell *shell = data;
4130 struct weston_output *output = get_default_output(shell->compositor);
4131 struct workspace *ws;
4132 struct weston_view *view;
4133 int num_surfaces = 0;
4134 int x, y, side, margin;
4135
4136 wl_list_for_each(view, &shell->compositor->view_list, link) {
4137
4138 if (view_for_alt_tab(view))
4139 num_surfaces++;
4140 }
4141
4142 if (!num_surfaces)
4143 return;
4144
4145 alt_tab = malloc(sizeof *alt_tab);
4146 if (!alt_tab)
4147 return;
4148
4149 alt_tab->shell = shell;
4150 wl_list_init(&alt_tab->preview_list);
4151 alt_tab->current = &alt_tab->preview_list;
4152
4153 restore_all_output_modes(shell->compositor);
4154 lower_fullscreen_layer(alt_tab->shell);
4155
4156 alt_tab->grab.interface = &alt_tab_grab;
4157 weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab);
4158 weston_keyboard_set_focus(seat->keyboard, NULL);
4159
4160 ws = get_current_workspace(shell);
4161
4162 /* FIXME: add some visual candy e.g. prelight the selected view
4163 * and/or add a black surrounding background à la gnome-shell */
4164
4165 /* Determine the size for each preview */
4166 side = output->width / num_surfaces;
4167 if (side > 200)
4168 side = 200;
4169 margin = side / 4;
4170 side -= margin;
4171
4172 x = margin;
4173 y = (output->height - side) / 2;
4174
4175 /* Create a view for each surface */
4176 wl_list_for_each(view, &shell->compositor->view_list, link) {
4177 struct alt_tab_preview *preview;
4178 struct weston_view *v;
4179 float scale;
4180
4181 if (!view_for_alt_tab(view))
4182 continue;
4183
4184 preview = malloc(sizeof *preview);
4185 if (!preview) {
4186 alt_tab_destroy(alt_tab);
4187 return;
4188 }
4189
4190 preview->alt_tab = alt_tab;
4191
4192 preview->view = v = weston_view_create(view->surface);
4193 v->output = view->output;
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004194
4195 wl_list_remove(&v->layer_link);
4196 wl_list_insert(&ws->layer.view_list, &v->layer_link);
4197 weston_view_damage_below(v);
4198 weston_surface_damage(v->surface);
4199
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004200 weston_view_set_position(v, x, y);
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01004201
4202 preview->listener.notify = alt_tab_handle_surface_destroy;
4203 wl_signal_add(&v->destroy_signal, &preview->listener);
4204
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004205 if (view->surface->width > view->surface->height)
4206 scale = side / (float) view->surface->width;
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01004207 else
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004208 scale = side / (float) view->surface->height;
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01004209
4210 wl_list_insert(&v->geometry.transformation_list,
4211 &preview->transform.link);
4212 weston_matrix_init(&preview->transform.matrix);
4213 weston_matrix_scale(&preview->transform.matrix,
4214 scale, scale, 1.0f);
4215
4216 weston_view_geometry_dirty(v);
4217 weston_compositor_schedule_repaint(v->surface->compositor);
4218
4219 /* Insert at the end of the list */
4220 wl_list_insert(alt_tab->preview_list.prev, &preview->link);
4221
4222 x += side + margin;
4223 }
4224
4225 /* Start at the second preview so a simple <alt>tab changes window.
4226 * We set `current' to the first preview and not the second because
4227 * we're going to receive a key press callback for the initial
4228 * <alt>tab which will make `current' point to the second element. */
4229 alt_tab_next(alt_tab);
4230}
4231
4232static void
Giulio Camuffo1959ab82013-11-14 23:42:52 +01004233rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
4234 wl_fixed_t x, wl_fixed_t y)
Pekka Paalanen460099f2012-01-20 16:48:25 +02004235{
4236 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004237 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04004238 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004239 struct shell_surface *shsurf = rotate->base.shsurf;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004240 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004241
Giulio Camuffo1959ab82013-11-14 23:42:52 +01004242 weston_pointer_move(pointer, x, y);
4243
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004244 if (!shsurf)
4245 return;
4246
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004247 cx = 0.5f * shsurf->surface->width;
4248 cy = 0.5f * shsurf->surface->height;
Pekka Paalanen460099f2012-01-20 16:48:25 +02004249
Daniel Stone37816df2012-05-16 18:45:18 +01004250 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
4251 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
Pekka Paalanen460099f2012-01-20 16:48:25 +02004252 r = sqrtf(dx * dx + dy * dy);
4253
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004254 wl_list_remove(&shsurf->rotation.transform.link);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004255 weston_view_geometry_dirty(shsurf->view);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004256
4257 if (r > 20.0f) {
Pekka Paalanen460099f2012-01-20 16:48:25 +02004258 struct weston_matrix *matrix =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004259 &shsurf->rotation.transform.matrix;
Pekka Paalanen460099f2012-01-20 16:48:25 +02004260
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004261 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03004262 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004263
4264 weston_matrix_init(matrix);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02004265 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004266 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004267 weston_matrix_multiply(matrix, &rotate->rotation);
Pekka Paalanen7b3bd3d2012-01-30 14:16:34 +02004268 weston_matrix_translate(matrix, cx, cy, 0.0f);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004269
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +02004270 wl_list_insert(
Jason Ekstranda7af7042013-10-12 22:38:11 -05004271 &shsurf->view->geometry.transformation_list,
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004272 &shsurf->rotation.transform.link);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004273 } else {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004274 wl_list_init(&shsurf->rotation.transform.link);
4275 weston_matrix_init(&shsurf->rotation.rotation);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004276 weston_matrix_init(&rotate->rotation);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004277 }
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02004278
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01004279 /* We need to adjust the position of the surface
4280 * in case it was resized in a rotated state before */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004281 cposx = shsurf->view->geometry.x + cx;
4282 cposy = shsurf->view->geometry.y + cy;
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01004283 dposx = rotate->center.x - cposx;
4284 dposy = rotate->center.y - cposy;
4285 if (dposx != 0.0f || dposy != 0.0f) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004286 weston_view_set_position(shsurf->view,
4287 shsurf->view->geometry.x + dposx,
4288 shsurf->view->geometry.y + dposy);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01004289 }
4290
Pekka Paalanenb45ac5e2012-02-09 15:58:44 +02004291 /* Repaint implies weston_surface_update_transform(), which
4292 * lazily applies the damage due to rotation update.
4293 */
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004294 weston_compositor_schedule_repaint(shsurf->surface->compositor);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004295}
4296
4297static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04004298rotate_grab_button(struct weston_pointer_grab *grab,
4299 uint32_t time, uint32_t button, uint32_t state_w)
Pekka Paalanen460099f2012-01-20 16:48:25 +02004300{
4301 struct rotate_grab *rotate =
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004302 container_of(grab, struct rotate_grab, base.grab);
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04004303 struct weston_pointer *pointer = grab->pointer;
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004304 struct shell_surface *shsurf = rotate->base.shsurf;
Daniel Stone4dbadb12012-05-30 16:31:51 +01004305 enum wl_pointer_button_state state = state_w;
Pekka Paalanen460099f2012-01-20 16:48:25 +02004306
Daniel Stone4dbadb12012-05-30 16:31:51 +01004307 if (pointer->button_count == 0 &&
4308 state == WL_POINTER_BUTTON_STATE_RELEASED) {
Ander Conselvan de Oliveirafe0444a2012-04-04 17:48:05 +03004309 if (shsurf)
4310 weston_matrix_multiply(&shsurf->rotation.rotation,
4311 &rotate->rotation);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03004312 shell_grab_end(&rotate->base);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004313 free(rotate);
4314 }
4315}
4316
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02004317static void
4318rotate_grab_cancel(struct weston_pointer_grab *grab)
4319{
4320 struct rotate_grab *rotate =
4321 container_of(grab, struct rotate_grab, base.grab);
4322
4323 shell_grab_end(&rotate->base);
4324 free(rotate);
4325}
4326
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04004327static const struct weston_pointer_grab_interface rotate_grab_interface = {
Pekka Paalanen460099f2012-01-20 16:48:25 +02004328 noop_grab_focus,
4329 rotate_grab_motion,
4330 rotate_grab_button,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02004331 rotate_grab_cancel,
Pekka Paalanen460099f2012-01-20 16:48:25 +02004332};
4333
4334static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004335surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
Pekka Paalanen460099f2012-01-20 16:48:25 +02004336{
Pekka Paalanen460099f2012-01-20 16:48:25 +02004337 struct rotate_grab *rotate;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004338 float dx, dy;
4339 float r;
Pekka Paalanen460099f2012-01-20 16:48:25 +02004340
Pekka Paalanen460099f2012-01-20 16:48:25 +02004341 rotate = malloc(sizeof *rotate);
4342 if (!rotate)
4343 return;
4344
Jason Ekstranda7af7042013-10-12 22:38:11 -05004345 weston_view_to_global_float(surface->view,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004346 surface->surface->width * 0.5f,
4347 surface->surface->height * 0.5f,
Jason Ekstranda7af7042013-10-12 22:38:11 -05004348 &rotate->center.x, &rotate->center.y);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004349
Daniel Stone37816df2012-05-16 18:45:18 +01004350 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
4351 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004352 r = sqrtf(dx * dx + dy * dy);
4353 if (r > 20.0f) {
4354 struct weston_matrix inverse;
4355
4356 weston_matrix_init(&inverse);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03004357 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004358 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
Rafal Mielniczuk2d7ab822012-03-22 22:22:04 +01004359
4360 weston_matrix_init(&rotate->rotation);
Vasily Khoruzhick1bbf3722013-01-28 22:40:28 +03004361 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
Kristian Høgsberg765e27b2012-01-27 13:36:13 -05004362 } else {
4363 weston_matrix_init(&surface->rotation.rotation);
4364 weston_matrix_init(&rotate->rotation);
4365 }
4366
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03004367 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
4368 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
Pekka Paalanen460099f2012-01-20 16:48:25 +02004369}
4370
4371static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04004372rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
Kristian Høgsberg0c369032013-02-14 21:31:44 -05004373 void *data)
4374{
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004375 struct weston_surface *focus = seat->pointer->focus->surface;
Pekka Paalanen01388e22013-04-25 13:57:44 +03004376 struct weston_surface *base_surface;
Kristian Høgsberg0c369032013-02-14 21:31:44 -05004377 struct shell_surface *surface;
4378
Pekka Paalanen01388e22013-04-25 13:57:44 +03004379 base_surface = weston_surface_get_main_surface(focus);
Kristian Høgsberg0c369032013-02-14 21:31:44 -05004380 if (base_surface == NULL)
4381 return;
4382
4383 surface = get_shell_surface(base_surface);
Rafael Antognolli03b16592013-12-03 15:35:42 -02004384 if (surface == NULL || surface->state.fullscreen ||
4385 surface->state.maximized)
Kristian Høgsberg0c369032013-02-14 21:31:44 -05004386 return;
4387
4388 surface_rotate(surface, seat);
4389}
4390
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004391/* Move all fullscreen layers down to the current workspace in a non-reversible
4392 * manner. This should be used when implementing shell-wide overlays, such as
4393 * the alt-tab switcher, which need to de-promote fullscreen layers. */
Kristian Høgsberg1ef23132013-12-04 00:20:01 -08004394void
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04004395lower_fullscreen_layer(struct desktop_shell *shell)
4396{
4397 struct workspace *ws;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004398 struct weston_view *view, *prev;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04004399
4400 ws = get_current_workspace(shell);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004401 wl_list_for_each_reverse_safe(view, prev,
4402 &shell->fullscreen_layer.view_list,
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004403 layer_link) {
4404 wl_list_remove(&view->layer_link);
4405 wl_list_insert(&ws->layer.view_list, &view->layer_link);
4406 weston_view_damage_below(view);
4407 weston_surface_damage(view->surface);
4408 }
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04004409}
4410
Kristian Høgsberg1ef23132013-12-04 00:20:01 -08004411void
Tiago Vignattibe143262012-04-16 17:31:41 +03004412activate(struct desktop_shell *shell, struct weston_surface *es,
Daniel Stone37816df2012-05-16 18:45:18 +01004413 struct weston_seat *seat)
Kristian Høgsberg75840622011-09-06 13:48:16 -04004414{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004415 struct weston_surface *main_surface;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004416 struct focus_state *state;
Jonas Ådahl8538b222012-08-29 22:13:03 +02004417 struct workspace *ws;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004418 struct weston_surface *old_es;
Rafael Antognolli03b16592013-12-03 15:35:42 -02004419 struct shell_surface *shsurf;
Kristian Høgsberg75840622011-09-06 13:48:16 -04004420
Pekka Paalanen01388e22013-04-25 13:57:44 +03004421 main_surface = weston_surface_get_main_surface(es);
4422
Daniel Stone37816df2012-05-16 18:45:18 +01004423 weston_surface_activate(es, seat);
Kristian Høgsberg75840622011-09-06 13:48:16 -04004424
Jonas Ådahl8538b222012-08-29 22:13:03 +02004425 state = ensure_focus_state(shell, seat);
4426 if (state == NULL)
4427 return;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004428
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004429 old_es = state->keyboard_focus;
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004430 state->keyboard_focus = es;
4431 wl_list_remove(&state->surface_destroy_listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05004432 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
Kristian Høgsberg2f5faff2012-07-31 16:36:34 -04004433
Rafael Antognolli03b16592013-12-03 15:35:42 -02004434 shsurf = get_shell_surface(main_surface);
4435 if (shsurf->state.fullscreen)
4436 shell_configure_fullscreen(shsurf);
4437 else
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02004438 restore_all_output_modes(shell->compositor);
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004439
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004440 if (shell->focus_animation_type != ANIMATION_NONE) {
4441 ws = get_current_workspace(shell);
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01004442 animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es));
Philip Withnall83ffd9d2013-11-25 18:01:42 +00004443 }
4444
4445 /* Update the surface’s layer. This brings it to the top of the stacking
4446 * order as appropriate. */
4447 shell_surface_update_layer(get_shell_surface(main_surface));
Kristian Høgsberg75840622011-09-06 13:48:16 -04004448}
4449
Alex Wu21858432012-04-01 20:13:08 +08004450/* no-op func for checking black surface */
4451static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004452black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
Alex Wu21858432012-04-01 20:13:08 +08004453{
4454}
4455
Quentin Glidicc0d79ce2013-01-29 14:16:13 +01004456static bool
Alex Wu21858432012-04-01 20:13:08 +08004457is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
4458{
4459 if (es->configure == black_surface_configure) {
4460 if (fs_surface)
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01004461 *fs_surface = (struct weston_surface *)es->configure_private;
Alex Wu21858432012-04-01 20:13:08 +08004462 return true;
4463 }
4464 return false;
4465}
4466
Kristian Høgsberg75840622011-09-06 13:48:16 -04004467static void
Neil Robertsa28c6932013-10-03 16:43:04 +01004468activate_binding(struct weston_seat *seat,
4469 struct desktop_shell *shell,
4470 struct weston_surface *focus)
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004471{
Pekka Paalanen01388e22013-04-25 13:57:44 +03004472 struct weston_surface *main_surface;
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004473
Alex Wu9c35e6b2012-03-05 14:13:13 +08004474 if (!focus)
4475 return;
4476
Pekka Paalanen01388e22013-04-25 13:57:44 +03004477 if (is_black_surface(focus, &main_surface))
4478 focus = main_surface;
Alex Wu4539b082012-03-01 12:57:46 +08004479
Pekka Paalanen01388e22013-04-25 13:57:44 +03004480 main_surface = weston_surface_get_main_surface(focus);
4481 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
Kristian Høgsberg0636ac32012-06-27 10:22:15 -04004482 return;
Kristian Høgsberg85b2e4b2012-06-21 16:49:42 -04004483
Neil Robertsa28c6932013-10-03 16:43:04 +01004484 activate(shell, focus, seat);
4485}
4486
4487static void
4488click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
4489 void *data)
4490{
4491 if (seat->pointer->grab != &seat->pointer->default_grab)
4492 return;
4493
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004494 activate_binding(seat, data, seat->pointer->focus->surface);
Neil Robertsa28c6932013-10-03 16:43:04 +01004495}
4496
4497static void
4498touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
4499{
4500 if (seat->touch->grab != &seat->touch->default_grab)
4501 return;
4502
Kristian Høgsberg7ab139c2013-10-24 16:21:39 -07004503 activate_binding(seat, data, seat->touch->focus->surface);
Kristian Høgsberge1a850e2011-12-19 15:18:05 -05004504}
4505
4506static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004507lock(struct desktop_shell *shell)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004508{
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004509 struct workspace *ws = get_current_workspace(shell);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004510
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004511 if (shell->locked) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004512 weston_compositor_sleep(shell->compositor);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004513 return;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02004514 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004515
4516 shell->locked = true;
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004517
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004518 /* Hide all surfaces by removing the fullscreen, panel and
4519 * toplevel layers. This way nothing else can show or receive
4520 * input events while we are locked. */
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004521
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004522 wl_list_remove(&shell->panel_layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004523 wl_list_remove(&shell->fullscreen_layer.link);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02004524 if (shell->showing_input_panels)
4525 wl_list_remove(&shell->input_panel_layer.link);
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04004526 wl_list_remove(&ws->layer.link);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05004527 wl_list_insert(&shell->compositor->cursor_layer.link,
4528 &shell->lock_layer.link);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004529
Pekka Paalanen77346a62011-11-30 16:26:35 +02004530 launch_screensaver(shell);
4531
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004532 /* TODO: disable bindings that should not work while locked. */
4533
4534 /* All this must be undone in resume_desktop(). */
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004535}
4536
4537static void
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004538unlock(struct desktop_shell *shell)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004539{
Pekka Paalanend81c2162011-11-16 13:47:34 +02004540 if (!shell->locked || shell->lock_surface) {
Ander Conselvan de Oliveira87524b62013-02-21 18:35:22 +02004541 shell_fade(shell, FADE_IN);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004542 return;
4543 }
4544
4545 /* If desktop-shell client has gone away, unlock immediately. */
4546 if (!shell->child.desktop_shell) {
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004547 resume_desktop(shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004548 return;
4549 }
4550
4551 if (shell->prepare_event_sent)
4552 return;
4553
Kristian Høgsberg0b5cd0c2012-03-04 21:57:37 -05004554 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02004555 shell->prepare_event_sent = true;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004556}
4557
4558static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004559shell_fade_done(struct weston_view_animation *animation, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004560{
4561 struct desktop_shell *shell = data;
4562
4563 shell->fade.animation = NULL;
4564
4565 switch (shell->fade.type) {
4566 case FADE_IN:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004567 weston_surface_destroy(shell->fade.view->surface);
4568 shell->fade.view = NULL;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004569 break;
4570 case FADE_OUT:
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004571 lock(shell);
4572 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004573 default:
4574 break;
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004575 }
4576}
4577
Jason Ekstranda7af7042013-10-12 22:38:11 -05004578static struct weston_view *
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004579shell_fade_create_surface(struct desktop_shell *shell)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004580{
4581 struct weston_compositor *compositor = shell->compositor;
4582 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004583 struct weston_view *view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004584
4585 surface = weston_surface_create(compositor);
4586 if (!surface)
4587 return NULL;
4588
Jason Ekstranda7af7042013-10-12 22:38:11 -05004589 view = weston_view_create(surface);
4590 if (!view) {
4591 weston_surface_destroy(surface);
4592 return NULL;
4593 }
4594
Jason Ekstrand5c11a332013-12-04 20:32:03 -06004595 weston_surface_set_size(surface, 8192, 8192);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004596 weston_view_set_position(view, 0, 0);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004597 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
Jason Ekstranda7af7042013-10-12 22:38:11 -05004598 wl_list_insert(&compositor->fade_layer.view_list,
4599 &view->layer_link);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004600 pixman_region32_init(&surface->input);
4601
Jason Ekstranda7af7042013-10-12 22:38:11 -05004602 return view;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004603}
4604
4605static void
4606shell_fade(struct desktop_shell *shell, enum fade_type type)
4607{
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004608 float tint;
4609
4610 switch (type) {
4611 case FADE_IN:
4612 tint = 0.0;
4613 break;
4614 case FADE_OUT:
4615 tint = 1.0;
4616 break;
4617 default:
4618 weston_log("shell: invalid fade type\n");
4619 return;
4620 }
4621
4622 shell->fade.type = type;
4623
Jason Ekstranda7af7042013-10-12 22:38:11 -05004624 if (shell->fade.view == NULL) {
4625 shell->fade.view = shell_fade_create_surface(shell);
4626 if (!shell->fade.view)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004627 return;
4628
Jason Ekstranda7af7042013-10-12 22:38:11 -05004629 shell->fade.view->alpha = 1.0 - tint;
4630 weston_view_update_transform(shell->fade.view);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004631 }
4632
4633 if (shell->fade.animation)
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004634 weston_fade_update(shell->fade.animation, tint);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004635 else
4636 shell->fade.animation =
Jason Ekstranda7af7042013-10-12 22:38:11 -05004637 weston_fade_run(shell->fade.view,
Kristian Høgsberg5281fb12013-06-17 10:10:28 -04004638 1.0 - tint, tint, 300.0,
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004639 shell_fade_done, shell);
4640}
4641
4642static void
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004643do_shell_fade_startup(void *data)
4644{
4645 struct desktop_shell *shell = data;
4646
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004647 if (shell->startup_animation_type == ANIMATION_FADE)
4648 shell_fade(shell, FADE_IN);
4649 else if (shell->startup_animation_type == ANIMATION_NONE) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004650 weston_surface_destroy(shell->fade.view->surface);
4651 shell->fade.view = NULL;
Kristian Høgsberg724c8d92013-10-16 11:38:24 -07004652 }
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004653}
4654
4655static void
4656shell_fade_startup(struct desktop_shell *shell)
4657{
4658 struct wl_event_loop *loop;
4659
4660 if (!shell->fade.startup_timer)
4661 return;
4662
4663 wl_event_source_remove(shell->fade.startup_timer);
4664 shell->fade.startup_timer = NULL;
4665
4666 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4667 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
4668}
4669
4670static int
4671fade_startup_timeout(void *data)
4672{
4673 struct desktop_shell *shell = data;
4674
4675 shell_fade_startup(shell);
4676 return 0;
4677}
4678
4679static void
4680shell_fade_init(struct desktop_shell *shell)
4681{
4682 /* Make compositor output all black, and wait for the desktop-shell
4683 * client to signal it is ready, then fade in. The timer triggers a
4684 * fade-in, in case the desktop-shell client takes too long.
4685 */
4686
4687 struct wl_event_loop *loop;
4688
Jason Ekstranda7af7042013-10-12 22:38:11 -05004689 if (shell->fade.view != NULL) {
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004690 weston_log("%s: warning: fade surface already exists\n",
4691 __func__);
4692 return;
4693 }
4694
Jason Ekstranda7af7042013-10-12 22:38:11 -05004695 shell->fade.view = shell_fade_create_surface(shell);
4696 if (!shell->fade.view)
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004697 return;
4698
Jason Ekstranda7af7042013-10-12 22:38:11 -05004699 weston_view_update_transform(shell->fade.view);
4700 weston_surface_damage(shell->fade.view->surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03004701
4702 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4703 shell->fade.startup_timer =
4704 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
4705 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
4706}
4707
4708static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004709idle_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004710{
4711 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004712 container_of(listener, struct desktop_shell, idle_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004713
4714 shell_fade(shell, FADE_OUT);
4715 /* lock() is called from shell_fade_done() */
4716}
4717
4718static void
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004719wake_handler(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004720{
4721 struct desktop_shell *shell =
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02004722 container_of(listener, struct desktop_shell, wake_listener);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004723
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02004724 unlock(shell);
4725}
4726
4727static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004728center_on_output(struct weston_view *view, struct weston_output *output)
Pekka Paalanen77346a62011-11-30 16:26:35 +02004729{
Giulio Camuffob8366642013-04-25 13:57:46 +03004730 int32_t surf_x, surf_y, width, height;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004731 float x, y;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004732
Jason Ekstranda7af7042013-10-12 22:38:11 -05004733 surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height);
Giulio Camuffob8366642013-04-25 13:57:46 +03004734
4735 x = output->x + (output->width - width) / 2 - surf_x / 2;
4736 y = output->y + (output->height - height) / 2 - surf_y / 2;
Ander Conselvan de Oliveira012b4c72012-11-27 17:03:42 +02004737
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004738 weston_view_set_position(view, x, y);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004739}
4740
4741static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004742weston_view_set_initial_position(struct weston_view *view,
4743 struct desktop_shell *shell)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004744{
4745 struct weston_compositor *compositor = shell->compositor;
4746 int ix = 0, iy = 0;
4747 int range_x, range_y;
4748 int dx, dy, x, y, panel_height;
4749 struct weston_output *output, *target_output = NULL;
4750 struct weston_seat *seat;
4751
4752 /* As a heuristic place the new window on the same output as the
4753 * pointer. Falling back to the output containing 0, 0.
4754 *
4755 * TODO: Do something clever for touch too?
4756 */
4757 wl_list_for_each(seat, &compositor->seat_list, link) {
Kristian Høgsberg2bf87622013-05-07 23:17:41 -04004758 if (seat->pointer) {
Kristian Høgsberge3148752013-05-06 23:19:49 -04004759 ix = wl_fixed_to_int(seat->pointer->x);
4760 iy = wl_fixed_to_int(seat->pointer->y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004761 break;
4762 }
4763 }
4764
4765 wl_list_for_each(output, &compositor->output_list, link) {
4766 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
4767 target_output = output;
4768 break;
4769 }
4770 }
4771
4772 if (!target_output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004773 weston_view_set_position(view, 10 + random() % 400,
4774 10 + random() % 400);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004775 return;
4776 }
4777
4778 /* Valid range within output where the surface will still be onscreen.
4779 * If this is negative it means that the surface is bigger than
4780 * output.
4781 */
4782 panel_height = get_output_panel_height(shell, target_output);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004783 range_x = target_output->width - view->surface->width;
Scott Moreau1bad5db2012-08-18 01:04:05 -06004784 range_y = (target_output->height - panel_height) -
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004785 view->surface->height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004786
Rob Bradford4cb88c72012-08-13 15:18:44 +01004787 if (range_x > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004788 dx = random() % range_x;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004789 else
Rob Bradford4cb88c72012-08-13 15:18:44 +01004790 dx = 0;
4791
4792 if (range_y > 0)
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004793 dy = panel_height + random() % range_y;
Rob Bradford4cb88c72012-08-13 15:18:44 +01004794 else
4795 dy = panel_height;
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004796
4797 x = target_output->x + dx;
4798 y = target_output->y + dy;
4799
Jason Ekstranda7af7042013-10-12 22:38:11 -05004800 weston_view_set_position(view, x, y);
Rob Bradfordac63e5b2012-08-13 14:07:52 +01004801}
4802
4803static void
Jason Ekstranda7af7042013-10-12 22:38:11 -05004804map(struct desktop_shell *shell, struct shell_surface *shsurf,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004805 int32_t sx, int32_t sy)
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04004806{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004807 struct weston_compositor *compositor = shell->compositor;
Daniel Stoneb2104682012-05-30 16:31:56 +01004808 struct weston_seat *seat;
Juan Zhao96879df2012-02-07 08:45:41 +08004809 int panel_height = 0;
Giulio Camuffob8366642013-04-25 13:57:46 +03004810 int32_t surf_x, surf_y;
Pekka Paalanen57da4a82011-11-23 16:42:16 +02004811
Pekka Paalanen77346a62011-11-30 16:26:35 +02004812 /* initial positioning, see also configure() */
Jason Ekstranda7af7042013-10-12 22:38:11 -05004813 switch (shsurf->type) {
Rafael Antognollied207b42013-12-03 15:35:43 -02004814 case SHELL_SURFACE_TOPLEVEL:
Rafael Antognolli03b16592013-12-03 15:35:42 -02004815 if (shsurf->state.fullscreen) {
4816 center_on_output(shsurf->view, shsurf->fullscreen_output);
4817 shell_map_fullscreen(shsurf);
4818 } else if (shsurf->state.maximized) {
4819 /* use surface configure to set the geometry */
4820 panel_height = get_output_panel_height(shell, shsurf->output);
4821 surface_subsurfaces_boundingbox(shsurf->surface,
4822 &surf_x, &surf_y, NULL, NULL);
4823 weston_view_set_position(shsurf->view,
4824 shsurf->output->x - surf_x,
4825 shsurf->output->y +
4826 panel_height - surf_y);
Rafael Antognollied207b42013-12-03 15:35:43 -02004827 } else if (!shsurf->state.relative) {
Rafael Antognolli03b16592013-12-03 15:35:42 -02004828 weston_view_set_initial_position(shsurf->view, shell);
4829 }
Juan Zhao96879df2012-02-07 08:45:41 +08004830 break;
Tiago Vignatti0f997012012-02-10 16:17:23 +02004831 case SHELL_SURFACE_POPUP:
Kristian Høgsberg3730f362012-04-13 12:40:07 -04004832 shell_map_popup(shsurf);
Rob Bradforddb999382012-12-06 12:07:48 +00004833 break;
Ander Conselvan de Oliveirae9e05152012-02-15 17:02:56 +02004834 case SHELL_SURFACE_NONE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004835 weston_view_set_position(shsurf->view,
4836 shsurf->view->geometry.x + sx,
4837 shsurf->view->geometry.y + sy);
Tiago Vignatti0f997012012-02-10 16:17:23 +02004838 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004839 case SHELL_SURFACE_XWAYLAND:
Pekka Paalanen77346a62011-11-30 16:26:35 +02004840 default:
4841 ;
4842 }
Kristian Høgsberg75840622011-09-06 13:48:16 -04004843
Philip Withnalle1d75ae2013-11-25 18:01:41 +00004844 /* Surface stacking order, see also activate(). */
4845 shell_surface_update_layer(shsurf);
Pekka Paalanenf0fc70d2011-11-15 13:34:54 +02004846
Jason Ekstranda7af7042013-10-12 22:38:11 -05004847 if (shsurf->type != SHELL_SURFACE_NONE) {
4848 weston_view_update_transform(shsurf->view);
Rafael Antognolli03b16592013-12-03 15:35:42 -02004849 if (shsurf->state.maximized) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004850 shsurf->surface->output = shsurf->output;
4851 shsurf->view->output = shsurf->output;
4852 }
Ander Conselvan de Oliveirade56c312012-03-05 15:39:23 +02004853 }
Kristian Høgsberg2f88a402011-12-04 15:32:59 -05004854
Rafael Antognollied207b42013-12-03 15:35:43 -02004855 if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) &&
4856 shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) {
4857 }
4858
Jason Ekstranda7af7042013-10-12 22:38:11 -05004859 switch (shsurf->type) {
Tiago Vignattifb2adba2013-06-12 15:43:21 -03004860 /* XXX: xwayland's using the same fields for transient type */
4861 case SHELL_SURFACE_XWAYLAND:
Tiago Vignatti99aeb1e2012-05-23 22:06:26 +03004862 if (shsurf->transient.flags ==
4863 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
4864 break;
4865 case SHELL_SURFACE_TOPLEVEL:
Rafael Antognollied207b42013-12-03 15:35:43 -02004866 if (shsurf->state.relative &&
4867 shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
4868 break;
Rafael Antognolliba5d2d72013-12-04 17:49:55 -02004869 if (shell->locked)
Rafael Antognollied207b42013-12-03 15:35:43 -02004870 break;
4871 wl_list_for_each(seat, &compositor->seat_list, link)
4872 activate(shell, shsurf->surface, seat);
Juan Zhao7bb92f02011-12-15 11:31:51 -05004873 break;
Philip Withnall0f640e22013-11-25 18:01:31 +00004874 case SHELL_SURFACE_POPUP:
4875 case SHELL_SURFACE_NONE:
Juan Zhao7bb92f02011-12-15 11:31:51 -05004876 default:
4877 break;
4878 }
4879
Rafael Antognolli03b16592013-12-03 15:35:42 -02004880 if (shsurf->type == SHELL_SURFACE_TOPLEVEL &&
4881 !shsurf->state.maximized && !shsurf->state.fullscreen)
Juan Zhaoe10d2792012-04-25 19:09:52 +08004882 {
4883 switch (shell->win_animation_type) {
4884 case ANIMATION_FADE:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004885 weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004886 break;
4887 case ANIMATION_ZOOM:
Jason Ekstranda7af7042013-10-12 22:38:11 -05004888 weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL);
Juan Zhaoe10d2792012-04-25 19:09:52 +08004889 break;
Philip Withnall4a86a0a2013-11-25 18:01:32 +00004890 case ANIMATION_NONE:
Juan Zhaoe10d2792012-04-25 19:09:52 +08004891 default:
4892 break;
4893 }
4894 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004895}
4896
4897static void
Tiago Vignattibe143262012-04-16 17:31:41 +03004898configure(struct desktop_shell *shell, struct weston_surface *surface,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004899 float x, float y)
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004900{
Pekka Paalanen77346a62011-11-30 16:26:35 +02004901 struct shell_surface *shsurf;
Jason Ekstranda7af7042013-10-12 22:38:11 -05004902 struct weston_view *view;
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004903 int32_t mx, my, surf_x, surf_y;
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004904
Pekka Paalanen77346a62011-11-30 16:26:35 +02004905 shsurf = get_shell_surface(surface);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004906
Rafael Antognolli03b16592013-12-03 15:35:42 -02004907 if (shsurf->state.fullscreen)
Alex Wu4539b082012-03-01 12:57:46 +08004908 shell_configure_fullscreen(shsurf);
Rafael Antognolli03b16592013-12-03 15:35:42 -02004909 else if (shsurf->state.maximized) {
Alex Wu4539b082012-03-01 12:57:46 +08004910 /* setting x, y and using configure to change that geometry */
Giulio Camuffob8366642013-04-25 13:57:46 +03004911 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
4912 NULL, NULL);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004913 mx = shsurf->output->x - surf_x;
4914 my = shsurf->output->y +
4915 get_output_panel_height(shell,shsurf->output) - surf_y;
4916 weston_view_set_position(shsurf->view, mx, my);
Rafael Antognolli03b16592013-12-03 15:35:42 -02004917 } else {
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004918 weston_view_set_position(shsurf->view, x, y);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -04004919 }
Kristian Høgsberg32e24cc2011-11-09 12:07:35 -05004920
Alex Wu4539b082012-03-01 12:57:46 +08004921 /* XXX: would a fullscreen surface need the same handling? */
Kristian Høgsberg6a8b5532012-02-16 23:43:59 -05004922 if (surface->output) {
Jason Ekstranda7af7042013-10-12 22:38:11 -05004923 wl_list_for_each(view, &surface->views, surface_link)
4924 weston_view_update_transform(view);
Pekka Paalanen77346a62011-11-30 16:26:35 +02004925
Rafael Antognolli03b16592013-12-03 15:35:42 -02004926 if (shsurf->state.maximized)
Juan Zhao96879df2012-02-07 08:45:41 +08004927 surface->output = shsurf->output;
Pekka Paalanen77346a62011-11-30 16:26:35 +02004928 }
Kristian Høgsberg07937562011-04-12 17:25:42 -04004929}
4930
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004931static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004932shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004933{
Ander Conselvan de Oliveira7fb9f952012-03-27 17:36:42 +03004934 struct shell_surface *shsurf = get_shell_surface(es);
Tiago Vignattibe143262012-04-16 17:31:41 +03004935 struct desktop_shell *shell = shsurf->shell;
Giulio Camuffo184df502013-02-21 11:29:21 +01004936
Tiago Vignatti70e5c9c2012-05-07 15:23:07 +03004937 int type_changed = 0;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004938
Kristian Høgsberg8eb0f4f2013-06-17 10:33:14 -04004939 if (!weston_surface_is_mapped(es) &&
4940 !wl_list_empty(&shsurf->popup.grab_link)) {
Giulio Camuffo5085a752013-03-25 21:42:45 +01004941 remove_popup_grab(shsurf);
4942 }
4943
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004944 if (es->width == 0)
Giulio Camuffo184df502013-02-21 11:29:21 +01004945 return;
4946
Kristian Høgsbergc8f8dd82013-12-05 23:20:33 -08004947 if (shsurf->state_changed) {
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004948 set_surface_type(shsurf);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004949 type_changed = 1;
4950 }
Kristian Høgsberg7f366e72012-04-27 17:20:01 -04004951
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004952 if (!weston_surface_is_mapped(es)) {
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004953 map(shell, shsurf, sx, sy);
Kristian Høgsbergf7e23d52012-04-27 17:51:59 -04004954 } else if (type_changed || sx != 0 || sy != 0 ||
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004955 shsurf->last_width != es->width ||
4956 shsurf->last_height != es->height) {
4957 shsurf->last_width = es->width;
4958 shsurf->last_height = es->height;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +02004959 float from_x, from_y;
4960 float to_x, to_y;
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004961
Jason Ekstranda7af7042013-10-12 22:38:11 -05004962 weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y);
4963 weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004964 configure(shell, es,
Jason Ekstranda7af7042013-10-12 22:38:11 -05004965 shsurf->view->geometry.x + to_x - from_x,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06004966 shsurf->view->geometry.y + to_y - from_y);
Ander Conselvan de Oliveira093bfa32012-03-27 17:36:41 +03004967 }
4968}
4969
Zhang, Xiong Y31236932013-12-13 22:10:57 +02004970static void
4971shell_surface_output_destroyed(struct weston_surface *es)
4972{
4973 struct shell_surface *shsurf = get_shell_surface(es);
4974
4975 shsurf->saved_position_valid = false;
Ander Conselvan de Oliveirafc63fdd2013-12-13 22:10:58 +02004976 shsurf->next_state.maximized = false;
4977 shsurf->next_state.fullscreen = false;
4978 shsurf->state_changed = true;
Zhang, Xiong Y31236932013-12-13 22:10:57 +02004979}
4980
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03004981static void launch_desktop_shell_process(void *data);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004982
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04004983static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05004984desktop_shell_sigchld(struct weston_process *process, int status)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004985{
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004986 uint32_t time;
Tiago Vignattibe143262012-04-16 17:31:41 +03004987 struct desktop_shell *shell =
4988 container_of(process, struct desktop_shell, child.process);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02004989
4990 shell->child.process.pid = 0;
4991 shell->child.client = NULL; /* already destroyed by wayland */
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004992
4993 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
4994 time = weston_compositor_get_time();
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05004995 if (time - shell->child.deathstamp > 30000) {
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02004996 shell->child.deathstamp = time;
4997 shell->child.deathcount = 0;
4998 }
4999
5000 shell->child.deathcount++;
5001 if (shell->child.deathcount > 5) {
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01005002 weston_log("%s died, giving up.\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02005003 return;
5004 }
5005
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01005006 weston_log("%s died, respawning...\n", shell->client);
Pekka Paalanen4d733ee2012-01-17 14:36:27 +02005007 launch_desktop_shell_process(shell);
Pekka Paalanen79346ab2013-05-22 18:03:09 +03005008 shell_fade_startup(shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02005009}
5010
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005011static void
Ander Conselvan de Oliveira312ea4c2013-12-20 21:07:01 +02005012desktop_shell_client_destroy(struct wl_listener *listener, void *data)
5013{
5014 struct desktop_shell *shell;
5015
5016 shell = container_of(listener, struct desktop_shell,
5017 child.client_destroy_listener);
5018
5019 shell->child.client = NULL;
5020}
5021
5022static void
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005023launch_desktop_shell_process(void *data)
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02005024{
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005025 struct desktop_shell *shell = data;
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02005026
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05005027 shell->child.client = weston_client_launch(shell->compositor,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02005028 &shell->child.process,
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01005029 shell->client,
Pekka Paalanen409ef0a2011-12-02 15:30:21 +02005030 desktop_shell_sigchld);
5031
5032 if (!shell->child.client)
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01005033 weston_log("not able to start %s\n", shell->client);
Ander Conselvan de Oliveira312ea4c2013-12-20 21:07:01 +02005034
5035 shell->child.client_destroy_listener.notify =
5036 desktop_shell_client_destroy;
5037 wl_client_add_destroy_listener(shell->child.client,
5038 &shell->child.client_destroy_listener);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02005039}
5040
5041static void
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04005042bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
5043{
Tiago Vignattibe143262012-04-16 17:31:41 +03005044 struct desktop_shell *shell = data;
Jason Ekstranda85118c2013-06-27 20:17:02 -05005045 struct wl_resource *resource;
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04005046
Jason Ekstranda85118c2013-06-27 20:17:02 -05005047 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
5048 if (resource)
5049 wl_resource_set_implementation(resource, &shell_implementation,
5050 shell, NULL);
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04005051}
5052
Kristian Høgsberg75840622011-09-06 13:48:16 -04005053static void
Rafael Antognollie2a34552013-12-03 15:35:45 -02005054bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
5055{
5056 struct desktop_shell *shell = data;
5057 struct wl_resource *resource;
5058
5059 resource = wl_resource_create(client, &xdg_shell_interface, 1, id);
5060 if (resource)
5061 wl_resource_set_dispatcher(resource,
5062 xdg_shell_unversioned_dispatch,
5063 NULL, shell, NULL);
5064}
5065
5066static void
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005067unbind_desktop_shell(struct wl_resource *resource)
5068{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05005069 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05005070
5071 if (shell->locked)
5072 resume_desktop(shell);
5073
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005074 shell->child.desktop_shell = NULL;
5075 shell->prepare_event_sent = false;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005076}
5077
5078static void
Kristian Høgsberg75840622011-09-06 13:48:16 -04005079bind_desktop_shell(struct wl_client *client,
5080 void *data, uint32_t version, uint32_t id)
5081{
Tiago Vignattibe143262012-04-16 17:31:41 +03005082 struct desktop_shell *shell = data;
Pekka Paalanenbbe60522011-11-03 14:11:33 +02005083 struct wl_resource *resource;
Kristian Høgsberg75840622011-09-06 13:48:16 -04005084
Jason Ekstranda85118c2013-06-27 20:17:02 -05005085 resource = wl_resource_create(client, &desktop_shell_interface,
5086 MIN(version, 2), id);
Pekka Paalanenbbe60522011-11-03 14:11:33 +02005087
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005088 if (client == shell->child.client) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05005089 wl_resource_set_implementation(resource,
5090 &desktop_shell_implementation,
5091 shell, unbind_desktop_shell);
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005092 shell->child.desktop_shell = resource;
Pekka Paalanen79346ab2013-05-22 18:03:09 +03005093
5094 if (version < 2)
5095 shell_fade_startup(shell);
5096
Pekka Paalanenbbe60522011-11-03 14:11:33 +02005097 return;
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02005098 }
Pekka Paalanenbbe60522011-11-03 14:11:33 +02005099
5100 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
5101 "permission to bind desktop_shell denied");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04005102 wl_resource_destroy(resource);
Kristian Høgsberg75840622011-09-06 13:48:16 -04005103}
5104
Pekka Paalanen6e168112011-11-24 11:34:05 +02005105static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06005106screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005107{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01005108 struct desktop_shell *shell = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -05005109 struct weston_view *view;
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005110
Jason Ekstrand918f2dd2013-12-02 21:01:53 -06005111 if (surface->width == 0)
Giulio Camuffo184df502013-02-21 11:29:21 +01005112 return;
5113
Pekka Paalanen3a1d07d2012-12-20 14:02:13 +02005114 /* XXX: starting weston-screensaver beforehand does not work */
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005115 if (!shell->locked)
5116 return;
5117
Jason Ekstranda7af7042013-10-12 22:38:11 -05005118 view = container_of(surface->views.next, struct weston_view, surface_link);
5119 center_on_output(view, surface->output);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005120
Jason Ekstranda7af7042013-10-12 22:38:11 -05005121 if (wl_list_empty(&view->layer_link)) {
5122 wl_list_insert(shell->lock_layer.view_list.prev,
5123 &view->layer_link);
5124 weston_view_update_transform(view);
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02005125 wl_event_source_timer_update(shell->screensaver.timer,
5126 shell->screensaver.duration);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02005127 shell_fade(shell, FADE_IN);
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005128 }
5129}
5130
5131static void
Pekka Paalanen6e168112011-11-24 11:34:05 +02005132screensaver_set_surface(struct wl_client *client,
5133 struct wl_resource *resource,
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005134 struct wl_resource *surface_resource,
Pekka Paalanen6e168112011-11-24 11:34:05 +02005135 struct wl_resource *output_resource)
5136{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05005137 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Jason Ekstrand0f2ef7e2013-06-14 10:07:53 -05005138 struct weston_surface *surface =
5139 wl_resource_get_user_data(surface_resource);
Jason Ekstranda0d2dde2013-06-14 10:08:01 -05005140 struct weston_output *output = wl_resource_get_user_data(output_resource);
Jason Ekstranda7af7042013-10-12 22:38:11 -05005141 struct weston_view *view, *next;
5142
5143 /* Make sure we only have one view */
5144 wl_list_for_each_safe(view, next, &surface->views, surface_link)
5145 weston_view_destroy(view);
5146 weston_view_create(surface);
Pekka Paalanen6e168112011-11-24 11:34:05 +02005147
Kristian Høgsberg1a73a632012-06-26 22:15:53 -04005148 surface->configure = screensaver_configure;
Giulio Camuffo7fe01b12013-03-28 18:02:42 +01005149 surface->configure_private = shell;
Pekka Paalanen77346a62011-11-30 16:26:35 +02005150 surface->output = output;
Pekka Paalanen6e168112011-11-24 11:34:05 +02005151}
5152
5153static const struct screensaver_interface screensaver_implementation = {
5154 screensaver_set_surface
5155};
5156
5157static void
5158unbind_screensaver(struct wl_resource *resource)
5159{
Jason Ekstrand651f00e2013-06-14 10:07:54 -05005160 struct desktop_shell *shell = wl_resource_get_user_data(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02005161
Pekka Paalanen77346a62011-11-30 16:26:35 +02005162 shell->screensaver.binding = NULL;
Pekka Paalanen6e168112011-11-24 11:34:05 +02005163}
5164
5165static void
5166bind_screensaver(struct wl_client *client,
5167 void *data, uint32_t version, uint32_t id)
5168{
Tiago Vignattibe143262012-04-16 17:31:41 +03005169 struct desktop_shell *shell = data;
Pekka Paalanen6e168112011-11-24 11:34:05 +02005170 struct wl_resource *resource;
5171
Jason Ekstranda85118c2013-06-27 20:17:02 -05005172 resource = wl_resource_create(client, &screensaver_interface, 1, id);
Pekka Paalanen6e168112011-11-24 11:34:05 +02005173
Pekka Paalanen77346a62011-11-30 16:26:35 +02005174 if (shell->screensaver.binding == NULL) {
Jason Ekstranda85118c2013-06-27 20:17:02 -05005175 wl_resource_set_implementation(resource,
5176 &screensaver_implementation,
5177 shell, unbind_screensaver);
Pekka Paalanen77346a62011-11-30 16:26:35 +02005178 shell->screensaver.binding = resource;
Pekka Paalanen6e168112011-11-24 11:34:05 +02005179 return;
5180 }
5181
5182 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
5183 "interface object already bound");
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04005184 wl_resource_destroy(resource);
Pekka Paalanen6e168112011-11-24 11:34:05 +02005185}
5186
Kristian Høgsberg07045392012-02-19 18:52:44 -05005187struct switcher {
Tiago Vignattibe143262012-04-16 17:31:41 +03005188 struct desktop_shell *shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005189 struct weston_surface *current;
5190 struct wl_listener listener;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005191 struct weston_keyboard_grab grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005192};
5193
5194static void
5195switcher_next(struct switcher *switcher)
5196{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005197 struct weston_view *view;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005198 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005199 struct shell_surface *shsurf;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005200 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005201
Jason Ekstranda7af7042013-10-12 22:38:11 -05005202 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Rafael Antognollied207b42013-12-03 15:35:43 -02005203 shsurf = get_shell_surface(view->surface);
Rafael Antognolli5031cbe2013-12-05 19:01:21 -02005204 if (shsurf &&
5205 shsurf->type == SHELL_SURFACE_TOPLEVEL &&
5206 shsurf->parent == NULL) {
Kristian Høgsberg07045392012-02-19 18:52:44 -05005207 if (first == NULL)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005208 first = view->surface;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005209 if (prev == switcher->current)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005210 next = view->surface;
5211 prev = view->surface;
5212 view->alpha = 0.25;
5213 weston_view_geometry_dirty(view);
5214 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005215 }
Alex Wu1659daa2012-04-01 20:13:09 +08005216
Jason Ekstranda7af7042013-10-12 22:38:11 -05005217 if (is_black_surface(view->surface, NULL)) {
5218 view->alpha = 0.25;
5219 weston_view_geometry_dirty(view);
5220 weston_surface_damage(view->surface);
Alex Wu1659daa2012-04-01 20:13:09 +08005221 }
Kristian Høgsberg07045392012-02-19 18:52:44 -05005222 }
5223
5224 if (next == NULL)
5225 next = first;
5226
Alex Wu07b26062012-03-12 16:06:01 +08005227 if (next == NULL)
5228 return;
5229
Kristian Høgsberg07045392012-02-19 18:52:44 -05005230 wl_list_remove(&switcher->listener.link);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005231 wl_signal_add(&next->destroy_signal, &switcher->listener);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005232
5233 switcher->current = next;
Jason Ekstranda7af7042013-10-12 22:38:11 -05005234 wl_list_for_each(view, &next->views, surface_link)
5235 view->alpha = 1.0;
Alex Wu1659daa2012-04-01 20:13:09 +08005236
Kristian Høgsberg32e56862012-04-02 22:18:58 -04005237 shsurf = get_shell_surface(switcher->current);
Rafael Antognolli03b16592013-12-03 15:35:42 -02005238 if (shsurf && shsurf->state.fullscreen)
Jason Ekstranda7af7042013-10-12 22:38:11 -05005239 shsurf->fullscreen.black_view->alpha = 1.0;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005240}
5241
5242static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005243switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005244{
5245 struct switcher *switcher =
5246 container_of(listener, struct switcher, listener);
5247
5248 switcher_next(switcher);
5249}
5250
5251static void
Daniel Stone351eb612012-05-31 15:27:47 -04005252switcher_destroy(struct switcher *switcher)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005253{
Jason Ekstranda7af7042013-10-12 22:38:11 -05005254 struct weston_view *view;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005255 struct weston_keyboard *keyboard = switcher->grab.keyboard;
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005256 struct workspace *ws = get_current_workspace(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005257
Jason Ekstranda7af7042013-10-12 22:38:11 -05005258 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +01005259 if (is_focus_view(view))
5260 continue;
5261
Jason Ekstranda7af7042013-10-12 22:38:11 -05005262 view->alpha = 1.0;
5263 weston_surface_damage(view->surface);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005264 }
5265
Alex Wu07b26062012-03-12 16:06:01 +08005266 if (switcher->current)
Daniel Stone37816df2012-05-16 18:45:18 +01005267 activate(switcher->shell, switcher->current,
5268 (struct weston_seat *) keyboard->seat);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005269 wl_list_remove(&switcher->listener.link);
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005270 weston_keyboard_end_grab(keyboard);
5271 if (keyboard->input_method_resource)
5272 keyboard->grab = &keyboard->input_method_grab;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005273 free(switcher);
5274}
5275
5276static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005277switcher_key(struct weston_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +01005278 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005279{
5280 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stonec9785ea2012-05-30 16:31:52 +01005281 enum wl_keyboard_key_state state = state_w;
Daniel Stone351eb612012-05-31 15:27:47 -04005282
Daniel Stonec9785ea2012-05-30 16:31:52 +01005283 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
Daniel Stone351eb612012-05-31 15:27:47 -04005284 switcher_next(switcher);
5285}
5286
5287static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005288switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
Daniel Stone351eb612012-05-31 15:27:47 -04005289 uint32_t mods_depressed, uint32_t mods_latched,
5290 uint32_t mods_locked, uint32_t group)
5291{
5292 struct switcher *switcher = container_of(grab, struct switcher, grab);
Daniel Stone37816df2012-05-16 18:45:18 +01005293 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005294
Daniel Stone351eb612012-05-31 15:27:47 -04005295 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
5296 switcher_destroy(switcher);
Kristian Høgsbergb71302e2012-05-10 12:28:35 -04005297}
Kristian Høgsberg07045392012-02-19 18:52:44 -05005298
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005299static void
5300switcher_cancel(struct weston_keyboard_grab *grab)
5301{
5302 struct switcher *switcher = container_of(grab, struct switcher, grab);
5303
5304 switcher_destroy(switcher);
5305}
5306
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005307static const struct weston_keyboard_grab_interface switcher_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -04005308 switcher_key,
5309 switcher_modifier,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005310 switcher_cancel,
Kristian Høgsberg07045392012-02-19 18:52:44 -05005311};
5312
5313static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005314switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005315 void *data)
Kristian Høgsberg07045392012-02-19 18:52:44 -05005316{
Tiago Vignattibe143262012-04-16 17:31:41 +03005317 struct desktop_shell *shell = data;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005318 struct switcher *switcher;
5319
5320 switcher = malloc(sizeof *switcher);
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04005321 switcher->shell = shell;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005322 switcher->current = NULL;
Kristian Høgsberg27e30522012-04-11 23:18:23 -04005323 switcher->listener.notify = switcher_handle_surface_destroy;
Kristian Høgsberg07045392012-02-19 18:52:44 -05005324 wl_list_init(&switcher->listener.link);
5325
Alexander Larssonf82b6ca2013-05-28 16:23:39 +02005326 restore_all_output_modes(shell->compositor);
Kristian Høgsbergb0d8e772012-06-18 16:34:58 -04005327 lower_fullscreen_layer(switcher->shell);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005328 switcher->grab.interface = &switcher_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005329 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
5330 weston_keyboard_set_focus(seat->keyboard, NULL);
Kristian Høgsberg07045392012-02-19 18:52:44 -05005331 switcher_next(switcher);
5332}
5333
Pekka Paalanen3c647232011-12-22 13:43:43 +02005334static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005335backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005336 void *data)
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005337{
5338 struct weston_compositor *compositor = data;
5339 struct weston_output *output;
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005340 long backlight_new = 0;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005341
5342 /* TODO: we're limiting to simple use cases, where we assume just
5343 * control on the primary display. We'd have to extend later if we
5344 * ever get support for setting backlights on random desktop LCD
5345 * panels though */
5346 output = get_default_output(compositor);
5347 if (!output)
5348 return;
5349
5350 if (!output->set_backlight)
5351 return;
5352
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005353 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
5354 backlight_new = output->backlight_current - 25;
5355 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
5356 backlight_new = output->backlight_current + 25;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005357
Tiago Vignatti5ab91ad2012-03-12 19:40:09 -03005358 if (backlight_new < 5)
5359 backlight_new = 5;
5360 if (backlight_new > 255)
5361 backlight_new = 255;
5362
5363 output->backlight_current = backlight_new;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02005364 output->set_backlight(output, output->backlight_current);
5365}
5366
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005367struct debug_binding_grab {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005368 struct weston_keyboard_grab grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005369 struct weston_seat *seat;
5370 uint32_t key[2];
5371 int key_released[2];
5372};
5373
5374static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005375debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005376 uint32_t key, uint32_t state)
5377{
5378 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
Rob Bradford880ebc72013-07-22 17:31:38 +01005379 struct weston_compositor *ec = db->seat->compositor;
5380 struct wl_display *display = ec->wl_display;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005381 struct wl_resource *resource;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005382 uint32_t serial;
5383 int send = 0, terminate = 0;
5384 int check_binding = 1;
5385 int i;
Neil Roberts96d790e2013-09-19 17:32:00 +01005386 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005387
5388 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
5389 /* Do not run bindings on key releases */
5390 check_binding = 0;
5391
5392 for (i = 0; i < 2; i++)
5393 if (key == db->key[i])
5394 db->key_released[i] = 1;
5395
5396 if (db->key_released[0] && db->key_released[1]) {
5397 /* All key releases been swalled so end the grab */
5398 terminate = 1;
5399 } else if (key != db->key[0] && key != db->key[1]) {
5400 /* Should not swallow release of other keys */
5401 send = 1;
5402 }
5403 } else if (key == db->key[0] && !db->key_released[0]) {
5404 /* Do not check bindings for the first press of the binding
5405 * key. This allows it to be used as a debug shortcut.
5406 * We still need to swallow this event. */
5407 check_binding = 0;
5408 } else if (db->key[1]) {
5409 /* If we already ran a binding don't process another one since
5410 * we can't keep track of all the binding keys that were
5411 * pressed in order to swallow the release events. */
5412 send = 1;
5413 check_binding = 0;
5414 }
5415
5416 if (check_binding) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005417 if (weston_compositor_run_debug_binding(ec, db->seat, time,
5418 key, state)) {
5419 /* We ran a binding so swallow the press and keep the
5420 * grab to swallow the released too. */
5421 send = 0;
5422 terminate = 0;
5423 db->key[1] = key;
5424 } else {
5425 /* Terminate the grab since the key pressed is not a
5426 * debug binding key. */
5427 send = 1;
5428 terminate = 1;
5429 }
5430 }
5431
5432 if (send) {
Neil Roberts96d790e2013-09-19 17:32:00 +01005433 serial = wl_display_next_serial(display);
5434 resource_list = &grab->keyboard->focus_resource_list;
5435 wl_resource_for_each(resource, resource_list) {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005436 wl_keyboard_send_key(resource, serial, time, key, state);
5437 }
5438 }
5439
5440 if (terminate) {
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005441 weston_keyboard_end_grab(grab->keyboard);
5442 if (grab->keyboard->input_method_resource)
5443 grab->keyboard->grab = &grab->keyboard->input_method_grab;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005444 free(db);
5445 }
5446}
5447
5448static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005449debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005450 uint32_t mods_depressed, uint32_t mods_latched,
5451 uint32_t mods_locked, uint32_t group)
5452{
5453 struct wl_resource *resource;
Neil Roberts96d790e2013-09-19 17:32:00 +01005454 struct wl_list *resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005455
Neil Roberts96d790e2013-09-19 17:32:00 +01005456 resource_list = &grab->keyboard->focus_resource_list;
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005457
Neil Roberts96d790e2013-09-19 17:32:00 +01005458 wl_resource_for_each(resource, resource_list) {
5459 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
5460 mods_latched, mods_locked, group);
5461 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005462}
5463
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005464static void
5465debug_binding_cancel(struct weston_keyboard_grab *grab)
5466{
5467 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
5468
5469 weston_keyboard_end_grab(grab->keyboard);
5470 free(db);
5471}
5472
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005473struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005474 debug_binding_key,
Jonas Ådahl1ea343e2013-10-25 23:18:05 +02005475 debug_binding_modifiers,
5476 debug_binding_cancel,
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005477};
5478
5479static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005480debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005481{
5482 struct debug_binding_grab *grab;
5483
5484 grab = calloc(1, sizeof *grab);
5485 if (!grab)
5486 return;
5487
5488 grab->seat = (struct weston_seat *) seat;
5489 grab->key[0] = key;
5490 grab->grab.interface = &debug_binding_keyboard_grab;
Kristian Høgsberg29139d42013-04-18 15:25:39 -04005491 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005492}
5493
Kristian Høgsbergb41c0812012-03-04 14:53:40 -05005494static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005495force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
Daniel Stone325fc2d2012-05-30 16:31:58 +01005496 void *data)
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005497{
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04005498 struct weston_surface *focus_surface;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005499 struct wl_client *client;
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005500 struct desktop_shell *shell = data;
5501 struct weston_compositor *compositor = shell->compositor;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005502 pid_t pid;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005503
Philipp Brüschweiler6cef0092012-08-13 21:27:27 +02005504 focus_surface = seat->keyboard->focus;
5505 if (!focus_surface)
5506 return;
5507
Tiago Vignatti1d01b012012-09-27 17:48:36 +03005508 wl_signal_emit(&compositor->kill_signal, focus_surface);
5509
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05005510 client = wl_resource_get_client(focus_surface->resource);
Tiago Vignatti920f1972012-09-27 17:48:35 +03005511 wl_client_get_credentials(client, &pid, NULL, NULL);
5512
5513 /* Skip clients that we launched ourselves (the credentials of
5514 * the socketpair is ours) */
5515 if (pid == getpid())
5516 return;
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005517
Daniel Stone325fc2d2012-05-30 16:31:58 +01005518 kill(pid, SIGKILL);
Kristian Høgsberg92a57db2012-05-26 13:41:06 -04005519}
5520
5521static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005522workspace_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005523 uint32_t key, void *data)
5524{
5525 struct desktop_shell *shell = data;
5526 unsigned int new_index = shell->workspaces.current;
5527
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005528 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005529 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005530 if (new_index != 0)
5531 new_index--;
5532
5533 change_workspace(shell, new_index);
5534}
5535
5536static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005537workspace_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005538 uint32_t key, void *data)
5539{
5540 struct desktop_shell *shell = data;
5541 unsigned int new_index = shell->workspaces.current;
5542
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005543 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005544 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005545 if (new_index < shell->workspaces.num - 1)
5546 new_index++;
5547
5548 change_workspace(shell, new_index);
5549}
5550
5551static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005552workspace_f_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005553 uint32_t key, void *data)
5554{
5555 struct desktop_shell *shell = data;
5556 unsigned int new_index;
5557
Kristian Høgsbergce345b02012-06-25 21:35:29 -04005558 if (shell->locked)
Kristian Høgsberg4476aaf2012-06-25 14:03:13 -04005559 return;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005560 new_index = key - KEY_F1;
5561 if (new_index >= shell->workspaces.num)
5562 new_index = shell->workspaces.num - 1;
5563
5564 change_workspace(shell, new_index);
5565}
5566
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02005567static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005568workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02005569 uint32_t key, void *data)
5570{
5571 struct desktop_shell *shell = data;
5572 unsigned int new_index = shell->workspaces.current;
5573
5574 if (shell->locked)
5575 return;
5576
5577 if (new_index != 0)
5578 new_index--;
5579
5580 take_surface_to_workspace_by_seat(shell, seat, new_index);
5581}
5582
5583static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04005584workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02005585 uint32_t key, void *data)
5586{
5587 struct desktop_shell *shell = data;
5588 unsigned int new_index = shell->workspaces.current;
5589
5590 if (shell->locked)
5591 return;
5592
5593 if (new_index < shell->workspaces.num - 1)
5594 new_index++;
5595
5596 take_surface_to_workspace_by_seat(shell, seat, new_index);
5597}
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005598
5599static void
Xiong Zhang6b481422013-10-23 13:58:32 +08005600handle_output_destroy(struct wl_listener *listener, void *data)
5601{
5602 struct shell_output *output_listener =
5603 container_of(listener, struct shell_output, destroy_listener);
5604
5605 wl_list_remove(&output_listener->destroy_listener.link);
5606 wl_list_remove(&output_listener->link);
5607 free(output_listener);
5608}
5609
5610static void
5611create_shell_output(struct desktop_shell *shell,
5612 struct weston_output *output)
5613{
5614 struct shell_output *shell_output;
5615
5616 shell_output = zalloc(sizeof *shell_output);
5617 if (shell_output == NULL)
5618 return;
5619
5620 shell_output->output = output;
5621 shell_output->shell = shell;
5622 shell_output->destroy_listener.notify = handle_output_destroy;
5623 wl_signal_add(&output->destroy_signal,
5624 &shell_output->destroy_listener);
Kristian Høgsberga3a0e182013-10-23 23:36:04 -07005625 wl_list_insert(shell->output_list.prev, &shell_output->link);
Xiong Zhang6b481422013-10-23 13:58:32 +08005626}
5627
5628static void
5629handle_output_create(struct wl_listener *listener, void *data)
5630{
5631 struct desktop_shell *shell =
5632 container_of(listener, struct desktop_shell, output_create_listener);
5633 struct weston_output *output = (struct weston_output *)data;
5634
5635 create_shell_output(shell, output);
5636}
5637
5638static void
5639setup_output_destroy_handler(struct weston_compositor *ec,
5640 struct desktop_shell *shell)
5641{
5642 struct weston_output *output;
5643
5644 wl_list_init(&shell->output_list);
5645 wl_list_for_each(output, &ec->output_list, link)
5646 create_shell_output(shell, output);
5647
5648 shell->output_create_listener.notify = handle_output_create;
5649 wl_signal_add(&ec->output_created_signal,
5650 &shell->output_create_listener);
5651}
5652
5653static void
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04005654shell_destroy(struct wl_listener *listener, void *data)
Pekka Paalanen3c647232011-12-22 13:43:43 +02005655{
Tiago Vignattibe143262012-04-16 17:31:41 +03005656 struct desktop_shell *shell =
5657 container_of(listener, struct desktop_shell, destroy_listener);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005658 struct workspace **ws;
Xiong Zhang6b481422013-10-23 13:58:32 +08005659 struct shell_output *shell_output, *tmp;
Pekka Paalanen3c647232011-12-22 13:43:43 +02005660
Pekka Paalanen9cf5cc82012-01-02 16:00:24 +02005661 if (shell->child.client)
5662 wl_client_destroy(shell->child.client);
5663
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02005664 wl_list_remove(&shell->idle_listener.link);
5665 wl_list_remove(&shell->wake_listener.link);
Kristian Høgsberg677a5f52013-12-04 11:00:19 -08005666
5667 input_panel_destroy(shell);
Kristian Høgsberg88c16072012-05-16 08:04:19 -04005668
Xiong Zhang6b481422013-10-23 13:58:32 +08005669 wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) {
5670 wl_list_remove(&shell_output->destroy_listener.link);
5671 wl_list_remove(&shell_output->link);
5672 free(shell_output);
5673 }
5674
5675 wl_list_remove(&shell->output_create_listener.link);
5676
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005677 wl_array_for_each(ws, &shell->workspaces.array)
5678 workspace_destroy(*ws);
5679 wl_array_release(&shell->workspaces.array);
5680
Pekka Paalanen3c647232011-12-22 13:43:43 +02005681 free(shell->screensaver.path);
Emilio Pozuelo Monfort46ce7982013-11-20 13:22:29 +01005682 free(shell->client);
Pekka Paalanen3c647232011-12-22 13:43:43 +02005683 free(shell);
5684}
5685
Tiago Vignatti0b52d482012-04-20 18:54:25 +03005686static void
5687shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
5688{
5689 uint32_t mod;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005690 int i, num_workspace_bindings;
Tiago Vignatti0b52d482012-04-20 18:54:25 +03005691
5692 /* fixed bindings */
Daniel Stone325fc2d2012-05-30 16:31:58 +01005693 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
5694 MODIFIER_CTRL | MODIFIER_ALT,
5695 terminate_binding, ec);
Emilio Pozuelo Monfort03251b62013-11-19 11:37:16 +01005696 weston_compositor_add_key_binding(ec, KEY_TAB,
5697 MODIFIER_ALT,
5698 alt_tab_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01005699 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
5700 click_to_activate_binding,
5701 shell);
Neil Robertsa28c6932013-10-03 16:43:04 +01005702 weston_compositor_add_touch_binding(ec, 0,
5703 touch_to_activate_binding,
5704 shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01005705 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
5706 MODIFIER_SUPER | MODIFIER_ALT,
5707 surface_opacity_binding, NULL);
5708 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
5709 MODIFIER_SUPER, zoom_axis_binding,
5710 NULL);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03005711
5712 /* configurable bindings */
5713 mod = shell->binding_modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +01005714 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
5715 zoom_key_binding, NULL);
5716 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
5717 zoom_key_binding, NULL);
Rafael Antognolliea997ac2013-12-03 15:35:48 -02005718 weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding,
5719 NULL);
5720 weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding,
5721 NULL);
Daniel Stone325fc2d2012-05-30 16:31:58 +01005722 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
5723 shell);
Neil Robertsaba0f252013-10-03 16:43:05 +01005724 weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell);
Daniel Stone325fc2d2012-05-30 16:31:58 +01005725 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
5726 resize_binding, shell);
Pekka Paalanen7bb65102013-05-22 18:03:04 +03005727
5728 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
5729 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
5730 rotate_binding, NULL);
5731
Daniel Stone325fc2d2012-05-30 16:31:58 +01005732 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
5733 shell);
5734 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
5735 ec);
5736 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
5737 backlight_binding, ec);
5738 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
5739 ec);
5740 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
5741 backlight_binding, ec);
Daniel Stone325fc2d2012-05-30 16:31:58 +01005742 weston_compositor_add_key_binding(ec, KEY_K, mod,
5743 force_kill_binding, shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005744 weston_compositor_add_key_binding(ec, KEY_UP, mod,
5745 workspace_up_binding, shell);
5746 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
5747 workspace_down_binding, shell);
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02005748 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
5749 workspace_move_surface_up_binding,
5750 shell);
5751 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
5752 workspace_move_surface_down_binding,
5753 shell);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005754
Daniel Stonedf8133b2013-11-19 11:37:14 +01005755 weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell);
5756
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005757 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
5758 if (shell->workspaces.num > 1) {
5759 num_workspace_bindings = shell->workspaces.num;
5760 if (num_workspace_bindings > 6)
5761 num_workspace_bindings = 6;
5762 for (i = 0; i < num_workspace_bindings; i++)
5763 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
5764 workspace_f_binding,
5765 shell);
5766 }
Ander Conselvan de Oliveirac509d2b2012-11-08 17:20:45 +02005767
5768 /* Debug bindings */
5769 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
5770 debug_binding, shell);
Tiago Vignatti0b52d482012-04-20 18:54:25 +03005771}
5772
Kristian Høgsberg1c562182011-05-02 22:09:20 -04005773WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -05005774module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -07005775 int *argc, char *argv[])
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05005776{
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04005777 struct weston_seat *seat;
Tiago Vignattibe143262012-04-16 17:31:41 +03005778 struct desktop_shell *shell;
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005779 struct workspace **pws;
5780 unsigned int i;
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005781 struct wl_event_loop *loop;
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04005782
Peter Huttererf3d62272013-08-08 11:57:05 +10005783 shell = zalloc(sizeof *shell);
Kristian Høgsberg02ec0a52011-04-23 13:04:11 -04005784 if (shell == NULL)
5785 return -1;
5786
Kristian Høgsberg75840622011-09-06 13:48:16 -04005787 shell->compositor = ec;
Kristian Høgsberg02e79dc2012-04-12 09:55:26 -04005788
5789 shell->destroy_listener.notify = shell_destroy;
5790 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
Ander Conselvan de Oliveiraa4575632013-02-21 18:35:23 +02005791 shell->idle_listener.notify = idle_handler;
5792 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
5793 shell->wake_listener.notify = wake_handler;
5794 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
Kristian Høgsberg677a5f52013-12-04 11:00:19 -08005795
Scott Moreauff1db4a2012-04-17 19:06:18 -06005796 ec->ping_handler = ping_handler;
Kristian Høgsberg82a1d112012-07-19 14:02:00 -04005797 ec->shell_interface.shell = shell;
Tiago Vignattibc052c92012-04-19 16:18:18 +03005798 ec->shell_interface.create_shell_surface = create_shell_surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -05005799 ec->shell_interface.get_primary_view = get_primary_view;
Tiago Vignattibc052c92012-04-19 16:18:18 +03005800 ec->shell_interface.set_toplevel = set_toplevel;
Tiago Vignatti491bac12012-05-18 16:37:43 -04005801 ec->shell_interface.set_transient = set_transient;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05005802 ec->shell_interface.set_fullscreen = set_fullscreen;
Tiago Vignattifb2adba2013-06-12 15:43:21 -03005803 ec->shell_interface.set_xwayland = set_xwayland;
Kristian Høgsberg938b8fa2012-05-18 13:46:27 -04005804 ec->shell_interface.move = surface_move;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04005805 ec->shell_interface.resize = surface_resize;
Giulio Camuffo62942ad2013-09-11 18:20:47 +02005806 ec->shell_interface.set_title = set_title;
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05005807
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05005808 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
5809 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005810 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
5811 weston_layer_init(&shell->lock_layer, NULL);
Philipp Brüschweiler711fda82012-08-09 18:50:43 +02005812 weston_layer_init(&shell->input_panel_layer, NULL);
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005813
5814 wl_array_init(&shell->workspaces.array);
Jonas Ådahle9d22502012-08-29 22:13:01 +02005815 wl_list_init(&shell->workspaces.client_list);
Kristian Høgsberg3be2ce92012-02-29 12:42:35 -05005816
Kristian Høgsberg677a5f52013-12-04 11:00:19 -08005817 if (input_panel_setup(shell) < 0)
5818 return -1;
5819
Kristian Høgsberg14e438c2013-05-26 21:48:14 -04005820 shell_configuration(shell);
Pekka Paalanene955f1e2011-12-07 11:49:52 +02005821
Daniel Stonedf8133b2013-11-19 11:37:14 +01005822 shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE;
5823 shell->exposay.state_target = EXPOSAY_TARGET_CANCEL;
5824
Jonas Ådahle3cddce2012-06-13 00:01:22 +02005825 for (i = 0; i < shell->workspaces.num; i++) {
5826 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
5827 if (pws == NULL)
5828 return -1;
5829
5830 *pws = workspace_create();
5831 if (*pws == NULL)
5832 return -1;
5833 }
5834 activate_workspace(shell, 0);
5835
Jonas Ådahl8de6a1d2012-08-29 22:13:00 +02005836 wl_list_init(&shell->workspaces.anim_sticky_list);
Jonas Ådahl62fcd042012-06-13 00:01:23 +02005837 wl_list_init(&shell->workspaces.animation.link);
5838 shell->workspaces.animation.frame = animate_workspace_change_frame;
5839
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04005840 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
Kristian Høgsberg97d44aa2011-08-26 17:21:20 -04005841 shell, bind_shell) == NULL)
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05005842 return -1;
5843
Rafael Antognollie2a34552013-12-03 15:35:45 -02005844 if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1,
5845 shell, bind_xdg_shell) == NULL)
5846 return -1;
5847
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04005848 if (wl_global_create(ec->wl_display,
5849 &desktop_shell_interface, 2,
5850 shell, bind_desktop_shell) == NULL)
Kristian Høgsberg75840622011-09-06 13:48:16 -04005851 return -1;
5852
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04005853 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
5854 shell, bind_screensaver) == NULL)
Pekka Paalanen6e168112011-11-24 11:34:05 +02005855 return -1;
5856
Kristian Høgsberg919cddb2013-07-08 19:03:57 -04005857 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
5858 shell, bind_workspace_manager) == NULL)
Jonas Ådahle9d22502012-08-29 22:13:01 +02005859 return -1;
5860
Kristian Høgsbergf03a6162012-01-17 11:07:42 -05005861 shell->child.deathstamp = weston_compositor_get_time();
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005862
Xiong Zhang6b481422013-10-23 13:58:32 +08005863 setup_output_destroy_handler(ec, shell);
5864
Tiago Vignattib7dbbd62012-09-25 17:57:01 +03005865 loop = wl_display_get_event_loop(ec->wl_display);
5866 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
Pekka Paalanen6cd281a2011-11-03 14:11:32 +02005867
Ander Conselvan de Oliveira859e8852013-02-21 18:35:21 +02005868 shell->screensaver.timer =
5869 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
5870
Kristian Høgsbergf4d2f232012-08-10 10:05:39 -04005871 wl_list_for_each(seat, &ec->seat_list, link)
5872 create_pointer_focus_listener(seat);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04005873
Tiago Vignatti0b52d482012-04-20 18:54:25 +03005874 shell_add_bindings(ec, shell);
Kristian Høgsberg07937562011-04-12 17:25:42 -04005875
Pekka Paalanen79346ab2013-05-22 18:03:09 +03005876 shell_fade_init(shell);
Ander Conselvan de Oliveira19d10ef2013-02-21 18:35:20 +02005877
Kristian Høgsberg4cca3492011-01-18 07:53:49 -05005878 return 0;
5879}