Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 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 Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 32 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 33 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 34 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 35 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 37 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 38 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 41 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 42 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 44 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 46 | #ifndef static_assert |
| 47 | #define static_assert(cond, msg) |
| 48 | #endif |
| 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
| 51 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 52 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | 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 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 59 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 60 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 62 | SHELL_SURFACE_POPUP, |
| 63 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 66 | struct shell_client; |
| 67 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Surface stacking and ordering. |
| 70 | * |
| 71 | * This is handled using several linked lists of surfaces, organised into |
| 72 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 73 | * above all of the surfaces in the layer below. The set of layers is static and |
| 74 | * in the following order (top-most first): |
| 75 | * • Lock layer (only ever displayed on its own) |
| 76 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 77 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | * • Fullscreen layer |
| 79 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Workspace layers |
| 81 | * • Background layer |
| 82 | * |
| 83 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 84 | * display. For example, when locking the screen, all layers except the lock |
| 85 | * layer are removed. |
| 86 | * |
| 87 | * A surface’s layer is modified on configuring the surface, in |
| 88 | * set_surface_type() (which is only called when the surface’s type change is |
| 89 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 90 | * fullscreen) its layer changes too. |
| 91 | * |
| 92 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 93 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 94 | * linked list of its children. When a surface’s layer is updated, so are the |
| 95 | * layers of its children. Note that child surfaces are *not* the same as |
| 96 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 97 | * order. |
| 98 | * |
| 99 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 100 | * have the same parent) only contains weston_surfaces which have a |
| 101 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 102 | * weston_surfaces. This means that the following implication does *not* hold: |
| 103 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 104 | */ |
| 105 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 106 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 107 | struct wl_resource *resource; |
| 108 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 109 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 110 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 111 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 112 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 113 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 114 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 115 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 116 | struct wl_listener resource_destroy_listener; |
| 117 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 118 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 119 | struct wl_list children_list; /* child surfaces of this one */ |
| 120 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 121 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 122 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 123 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 124 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 125 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 126 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 127 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 129 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 130 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 131 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 132 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 133 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 134 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 135 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | } rotation; |
| 137 | |
| 138 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 139 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 140 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 142 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 143 | } popup; |
| 144 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 145 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 146 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 147 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | } transient; |
| 149 | |
| 150 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 151 | enum wl_shell_surface_fullscreen_method type; |
| 152 | struct weston_transform transform; /* matrix from x, y */ |
| 153 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 154 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 155 | } fullscreen; |
| 156 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 157 | struct weston_transform workspace_transform; |
| 158 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 159 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 160 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 161 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 162 | |
| 163 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 164 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 165 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | bool maximized; |
| 167 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 168 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 169 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 170 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 171 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 173 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 174 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 175 | int32_t x, y, width, height; |
| 176 | } geometry, next_geometry; |
| 177 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 178 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 179 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame^] | 180 | |
| 181 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 182 | }; |
| 183 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 184 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 185 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_surface *shsurf; |
| 187 | struct wl_listener shsurf_destroy_listener; |
| 188 | }; |
| 189 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 190 | struct shell_touch_grab { |
| 191 | struct weston_touch_grab grab; |
| 192 | struct shell_surface *shsurf; |
| 193 | struct wl_listener shsurf_destroy_listener; |
| 194 | struct weston_touch *touch; |
| 195 | }; |
| 196 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 197 | struct weston_move_grab { |
| 198 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 199 | wl_fixed_t dx, dy; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 200 | int client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 201 | }; |
| 202 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | struct weston_touch_move_grab { |
| 204 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 205 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 206 | wl_fixed_t dx, dy; |
| 207 | }; |
| 208 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 210 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 211 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 213 | float x; |
| 214 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 215 | } center; |
| 216 | }; |
| 217 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 218 | struct shell_seat { |
| 219 | struct weston_seat *seat; |
| 220 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 221 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 222 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 223 | struct wl_listener caps_changed_listener; |
| 224 | struct wl_listener pointer_focus_listener; |
| 225 | struct wl_listener keyboard_focus_listener; |
| 226 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 227 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 228 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 229 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 230 | struct wl_list surfaces_list; |
| 231 | struct wl_client *client; |
| 232 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 233 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 234 | } popup_grab; |
| 235 | }; |
| 236 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 237 | struct shell_client { |
| 238 | struct wl_resource *resource; |
| 239 | struct wl_client *client; |
| 240 | struct desktop_shell *shell; |
| 241 | struct wl_listener destroy_listener; |
| 242 | struct wl_event_source *ping_timer; |
| 243 | uint32_t ping_serial; |
| 244 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 245 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 248 | static struct desktop_shell * |
| 249 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 250 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 251 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 252 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 254 | static void |
| 255 | shell_fade_startup(struct desktop_shell *shell); |
| 256 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 257 | static struct shell_seat * |
| 258 | get_shell_seat(struct weston_seat *seat); |
| 259 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 260 | static void |
| 261 | get_output_panel_size(struct desktop_shell *shell, |
| 262 | struct weston_output *output, |
| 263 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 264 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 265 | static void |
| 266 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 267 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 268 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 269 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 270 | |
| 271 | static bool |
| 272 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 273 | |
| 274 | static bool |
| 275 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 276 | |
| 277 | static void |
| 278 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 279 | struct weston_surface *parent); |
| 280 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 281 | static int |
| 282 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 283 | { |
| 284 | struct shell_surface *shsurf; |
| 285 | const char *typestr[] = { |
| 286 | [SHELL_SURFACE_NONE] = "unidentified", |
| 287 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 288 | [SHELL_SURFACE_POPUP] = "popup", |
| 289 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 290 | }; |
| 291 | const char *t, *c; |
| 292 | |
| 293 | shsurf = get_shell_surface(surface); |
| 294 | if (!shsurf) |
| 295 | return snprintf(buf, len, "unidentified window"); |
| 296 | |
| 297 | t = shsurf->title; |
| 298 | c = shsurf->class; |
| 299 | |
| 300 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 301 | typestr[shsurf->type], |
| 302 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 303 | c ? " of " : "", c ?: ""); |
| 304 | } |
| 305 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 306 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 307 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 308 | { |
| 309 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 310 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 311 | |
| 312 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 313 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 314 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 315 | return false; |
| 316 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 317 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.link.next, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 318 | struct weston_view, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 319 | layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 320 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 321 | } |
| 322 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 323 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 324 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 325 | { |
| 326 | struct shell_grab *grab; |
| 327 | |
| 328 | grab = container_of(listener, struct shell_grab, |
| 329 | shsurf_destroy_listener); |
| 330 | |
| 331 | grab->shsurf = NULL; |
| 332 | } |
| 333 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 334 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 335 | get_default_view(struct weston_surface *surface) |
| 336 | { |
| 337 | struct shell_surface *shsurf; |
| 338 | struct weston_view *view; |
| 339 | |
| 340 | if (!surface || wl_list_empty(&surface->views)) |
| 341 | return NULL; |
| 342 | |
| 343 | shsurf = get_shell_surface(surface); |
| 344 | if (shsurf) |
| 345 | return shsurf->view; |
| 346 | |
| 347 | wl_list_for_each(view, &surface->views, surface_link) |
| 348 | if (weston_view_is_mapped(view)) |
| 349 | return view; |
| 350 | |
| 351 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 352 | } |
| 353 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 354 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 355 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 356 | static void |
| 357 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 358 | |
| 359 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 360 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 361 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 362 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 363 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 364 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 365 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 366 | struct desktop_shell *shell = shsurf->shell; |
| 367 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 368 | popup_grab_end(pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 369 | if (pointer->seat->touch) |
| 370 | touch_popup_grab_end(pointer->seat->touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 371 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 372 | grab->grab.interface = interface; |
| 373 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 374 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 375 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 376 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 377 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 378 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 379 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 380 | if (shell->child.desktop_shell) { |
| 381 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 382 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 383 | weston_pointer_set_focus(pointer, |
| 384 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 385 | wl_fixed_from_int(0), |
| 386 | wl_fixed_from_int(0)); |
| 387 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 388 | } |
| 389 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 390 | static void |
| 391 | get_output_panel_size(struct desktop_shell *shell, |
| 392 | struct weston_output *output, |
| 393 | int *width, |
| 394 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 395 | { |
| 396 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 397 | |
| 398 | *width = 0; |
| 399 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 400 | |
| 401 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 402 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 403 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 404 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 405 | float x, y; |
| 406 | |
| 407 | if (view->surface->output != output) |
| 408 | continue; |
| 409 | |
| 410 | switch (shell->panel_position) { |
| 411 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 412 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 413 | |
| 414 | weston_view_to_global_float(view, |
| 415 | view->surface->width, 0, |
| 416 | &x, &y); |
| 417 | |
| 418 | *width = (int) x; |
| 419 | *height = view->surface->height + (int) y; |
| 420 | return; |
| 421 | |
| 422 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 423 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 424 | weston_view_to_global_float(view, |
| 425 | 0, view->surface->height, |
| 426 | &x, &y); |
| 427 | |
| 428 | *width = view->surface->width + (int) x; |
| 429 | *height = (int) y; |
| 430 | return; |
| 431 | |
| 432 | default: |
| 433 | /* we've already set width and height to |
| 434 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 435 | break; |
| 436 | } |
| 437 | } |
| 438 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 439 | /* the correct view wasn't found */ |
| 440 | } |
| 441 | |
| 442 | static void |
| 443 | get_output_work_area(struct desktop_shell *shell, |
| 444 | struct weston_output *output, |
| 445 | pixman_rectangle32_t *area) |
| 446 | { |
| 447 | int32_t panel_width = 0, panel_height = 0; |
| 448 | |
| 449 | area->x = 0; |
| 450 | area->y = 0; |
| 451 | |
| 452 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
| 453 | |
| 454 | switch (shell->panel_position) { |
| 455 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 456 | default: |
| 457 | area->y = panel_height; |
| 458 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 459 | area->width = output->width; |
| 460 | area->height = output->height - panel_height; |
| 461 | break; |
| 462 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 463 | area->x = panel_width; |
| 464 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 465 | area->width = output->width - panel_width; |
| 466 | area->height = output->height; |
| 467 | break; |
| 468 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static void |
| 472 | send_configure_for_surface(struct shell_surface *shsurf) |
| 473 | { |
| 474 | int32_t width, height; |
| 475 | struct surface_state *state; |
| 476 | |
| 477 | if (shsurf->state_requested) |
| 478 | state = &shsurf->requested_state; |
| 479 | else if (shsurf->state_changed) |
| 480 | state = &shsurf->next_state; |
| 481 | else |
| 482 | state = &shsurf->state; |
| 483 | |
| 484 | if (state->fullscreen) { |
| 485 | width = shsurf->output->width; |
| 486 | height = shsurf->output->height; |
| 487 | } else if (state->maximized) { |
| 488 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 489 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 490 | |
| 491 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 492 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 493 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 494 | width = area.width; |
| 495 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 496 | } else if (shsurf->resize_edges) { |
| 497 | width = shsurf->geometry.width; |
| 498 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 499 | } else { |
| 500 | width = 0; |
| 501 | height = 0; |
| 502 | } |
| 503 | |
| 504 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 505 | } |
| 506 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 507 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 508 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 509 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 510 | if (shell_surface_is_xdg_surface(shsurf)) |
| 511 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 515 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 516 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 517 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 518 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 519 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 520 | |
| 521 | if (grab->shsurf->resize_edges) { |
| 522 | grab->shsurf->resize_edges = 0; |
| 523 | shell_surface_state_changed(grab->shsurf); |
| 524 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 525 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 526 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 527 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 531 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 532 | const struct weston_touch_grab_interface *interface, |
| 533 | struct shell_surface *shsurf, |
| 534 | struct weston_touch *touch) |
| 535 | { |
| 536 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 537 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 538 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 539 | if (touch->seat->pointer) |
| 540 | popup_grab_end(touch->seat->pointer); |
| 541 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 542 | grab->grab.interface = interface; |
| 543 | grab->shsurf = shsurf; |
| 544 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 545 | wl_signal_add(&shsurf->destroy_signal, |
| 546 | &grab->shsurf_destroy_listener); |
| 547 | |
| 548 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 549 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 550 | |
| 551 | weston_touch_start_grab(touch, &grab->grab); |
| 552 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 553 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 554 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static void |
| 558 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 559 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 560 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 561 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 562 | grab->shsurf->grabbed = 0; |
| 563 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 564 | |
| 565 | weston_touch_end_grab(grab->touch); |
| 566 | } |
| 567 | |
| 568 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 569 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 570 | struct weston_output *output); |
| 571 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 572 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 573 | get_modifier(char *modifier) |
| 574 | { |
| 575 | if (!modifier) |
| 576 | return MODIFIER_SUPER; |
| 577 | |
| 578 | if (!strcmp("ctrl", modifier)) |
| 579 | return MODIFIER_CTRL; |
| 580 | else if (!strcmp("alt", modifier)) |
| 581 | return MODIFIER_ALT; |
| 582 | else if (!strcmp("super", modifier)) |
| 583 | return MODIFIER_SUPER; |
| 584 | else |
| 585 | return MODIFIER_SUPER; |
| 586 | } |
| 587 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 588 | static enum animation_type |
| 589 | get_animation_type(char *animation) |
| 590 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 591 | if (!animation) |
| 592 | return ANIMATION_NONE; |
| 593 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 594 | if (!strcmp("zoom", animation)) |
| 595 | return ANIMATION_ZOOM; |
| 596 | else if (!strcmp("fade", animation)) |
| 597 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 598 | else if (!strcmp("dim-layer", animation)) |
| 599 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 600 | else |
| 601 | return ANIMATION_NONE; |
| 602 | } |
| 603 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 604 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 605 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 606 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 607 | struct weston_config_section *section; |
| 608 | int duration; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 609 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 610 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 611 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 612 | section = weston_config_get_section(shell->compositor->config, |
| 613 | "screensaver", NULL, NULL); |
| 614 | weston_config_section_get_string(section, |
| 615 | "path", &shell->screensaver.path, NULL); |
| 616 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 617 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 618 | |
| 619 | section = weston_config_get_section(shell->compositor->config, |
| 620 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 621 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 622 | WESTON_SHELL_CLIENT); |
| 623 | if (ret < 0) |
| 624 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 625 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 626 | "client", &s, client); |
| 627 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 628 | shell->client = s; |
| 629 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 630 | "binding-modifier", &s, "super"); |
| 631 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 632 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 633 | |
| 634 | weston_config_section_get_string(section, |
| 635 | "exposay-modifier", &s, "none"); |
| 636 | if (strcmp(s, "none") == 0) |
| 637 | shell->exposay_modifier = 0; |
| 638 | else |
| 639 | shell->exposay_modifier = get_modifier(s); |
| 640 | free(s); |
| 641 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 642 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 643 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 644 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 645 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 646 | shell->win_close_animation_type = get_animation_type(s); |
| 647 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 648 | weston_config_section_get_string(section, |
| 649 | "startup-animation", &s, "fade"); |
| 650 | shell->startup_animation_type = get_animation_type(s); |
| 651 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 652 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 653 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 654 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 655 | shell->focus_animation_type = get_animation_type(s); |
| 656 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 657 | weston_config_section_get_uint(section, "num-workspaces", |
| 658 | &shell->workspaces.num, |
| 659 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 662 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 663 | get_default_output(struct weston_compositor *compositor) |
| 664 | { |
| 665 | return container_of(compositor->output_list.next, |
| 666 | struct weston_output, link); |
| 667 | } |
| 668 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 669 | static int |
| 670 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 671 | { |
| 672 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 673 | surface->output->name); |
| 674 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 675 | |
| 676 | /* no-op func for checking focus surface */ |
| 677 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 678 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 679 | { |
| 680 | } |
| 681 | |
| 682 | static struct focus_surface * |
| 683 | get_focus_surface(struct weston_surface *surface) |
| 684 | { |
| 685 | if (surface->configure == focus_surface_configure) |
| 686 | return surface->configure_private; |
| 687 | else |
| 688 | return NULL; |
| 689 | } |
| 690 | |
| 691 | static bool |
| 692 | is_focus_surface (struct weston_surface *es) |
| 693 | { |
| 694 | return (es->configure == focus_surface_configure); |
| 695 | } |
| 696 | |
| 697 | static bool |
| 698 | is_focus_view (struct weston_view *view) |
| 699 | { |
| 700 | return is_focus_surface (view->surface); |
| 701 | } |
| 702 | |
| 703 | static struct focus_surface * |
| 704 | create_focus_surface(struct weston_compositor *ec, |
| 705 | struct weston_output *output) |
| 706 | { |
| 707 | struct focus_surface *fsurf = NULL; |
| 708 | struct weston_surface *surface = NULL; |
| 709 | |
| 710 | fsurf = malloc(sizeof *fsurf); |
| 711 | if (!fsurf) |
| 712 | return NULL; |
| 713 | |
| 714 | fsurf->surface = weston_surface_create(ec); |
| 715 | surface = fsurf->surface; |
| 716 | if (surface == NULL) { |
| 717 | free(fsurf); |
| 718 | return NULL; |
| 719 | } |
| 720 | |
| 721 | surface->configure = focus_surface_configure; |
| 722 | surface->output = output; |
| 723 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 724 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 725 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 726 | fsurf->view = weston_view_create(surface); |
| 727 | if (fsurf->view == NULL) { |
| 728 | weston_surface_destroy(surface); |
| 729 | free(fsurf); |
| 730 | return NULL; |
| 731 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 732 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 733 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 734 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 735 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 736 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 737 | pixman_region32_fini(&surface->opaque); |
| 738 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 739 | output->width, output->height); |
| 740 | pixman_region32_fini(&surface->input); |
| 741 | pixman_region32_init(&surface->input); |
| 742 | |
| 743 | wl_list_init(&fsurf->workspace_transform.link); |
| 744 | |
| 745 | return fsurf; |
| 746 | } |
| 747 | |
| 748 | static void |
| 749 | focus_surface_destroy(struct focus_surface *fsurf) |
| 750 | { |
| 751 | weston_surface_destroy(fsurf->surface); |
| 752 | free(fsurf); |
| 753 | } |
| 754 | |
| 755 | static void |
| 756 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 757 | { |
| 758 | struct workspace *ws = data; |
| 759 | |
| 760 | ws->focus_animation = NULL; |
| 761 | } |
| 762 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 763 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 764 | focus_state_destroy(struct focus_state *state) |
| 765 | { |
| 766 | wl_list_remove(&state->seat_destroy_listener.link); |
| 767 | wl_list_remove(&state->surface_destroy_listener.link); |
| 768 | free(state); |
| 769 | } |
| 770 | |
| 771 | static void |
| 772 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 773 | { |
| 774 | struct focus_state *state = container_of(listener, |
| 775 | struct focus_state, |
| 776 | seat_destroy_listener); |
| 777 | |
| 778 | wl_list_remove(&state->link); |
| 779 | focus_state_destroy(state); |
| 780 | } |
| 781 | |
| 782 | static void |
| 783 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 784 | { |
| 785 | struct focus_state *state = container_of(listener, |
| 786 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 787 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 788 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 789 | struct weston_surface *main_surface, *next; |
| 790 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 792 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 793 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 794 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 795 | wl_list_for_each(view, |
| 796 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 797 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 798 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 799 | if (is_focus_view(view)) |
| 800 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 801 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 802 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 806 | /* if the focus was a sub-surface, activate its main surface */ |
| 807 | if (main_surface != state->keyboard_focus) |
| 808 | next = main_surface; |
| 809 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 810 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 811 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 812 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 813 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 814 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 815 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 816 | if (state->ws->focus_animation) |
| 817 | weston_view_animation_destroy(state->ws->focus_animation); |
| 818 | |
| 819 | state->ws->focus_animation = weston_fade_run( |
| 820 | state->ws->fsurf_front->view, |
| 821 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 822 | focus_animation_done, state->ws); |
| 823 | } |
| 824 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 825 | wl_list_remove(&state->link); |
| 826 | focus_state_destroy(state); |
| 827 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 831 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 832 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 833 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 834 | |
| 835 | state = malloc(sizeof *state); |
| 836 | if (state == NULL) |
| 837 | return NULL; |
| 838 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 839 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 840 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 841 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 842 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 843 | |
| 844 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 845 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 846 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 847 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 848 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 849 | |
| 850 | return state; |
| 851 | } |
| 852 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 853 | static struct focus_state * |
| 854 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 855 | { |
| 856 | struct workspace *ws = get_current_workspace(shell); |
| 857 | struct focus_state *state; |
| 858 | |
| 859 | wl_list_for_each(state, &ws->focus_list, link) |
| 860 | if (state->seat == seat) |
| 861 | break; |
| 862 | |
| 863 | if (&state->link == &ws->focus_list) |
| 864 | state = focus_state_create(seat, ws); |
| 865 | |
| 866 | return state; |
| 867 | } |
| 868 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 870 | focus_state_set_focus(struct focus_state *state, |
| 871 | struct weston_surface *surface) |
| 872 | { |
| 873 | if (state->keyboard_focus) { |
| 874 | wl_list_remove(&state->surface_destroy_listener.link); |
| 875 | wl_list_init(&state->surface_destroy_listener.link); |
| 876 | } |
| 877 | |
| 878 | state->keyboard_focus = surface; |
| 879 | if (surface) |
| 880 | wl_signal_add(&surface->destroy_signal, |
| 881 | &state->surface_destroy_listener); |
| 882 | } |
| 883 | |
| 884 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 885 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 886 | { |
| 887 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 888 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 889 | struct wl_list pending_seat_list; |
| 890 | struct weston_seat *seat, *next_seat; |
| 891 | |
| 892 | /* Temporarily steal the list of seats so that we can keep |
| 893 | * track of the seats we've already processed */ |
| 894 | wl_list_init(&pending_seat_list); |
| 895 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 896 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 897 | |
| 898 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 899 | wl_list_remove(&state->seat->link); |
| 900 | wl_list_insert(&shell->compositor->seat_list, |
| 901 | &state->seat->link); |
| 902 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 903 | if (state->seat->keyboard == NULL) |
| 904 | continue; |
| 905 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 906 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 907 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 908 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 909 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 910 | |
| 911 | /* For any remaining seats that we don't have a focus state |
| 912 | * for we'll reset the keyboard focus to NULL */ |
| 913 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 914 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 915 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 916 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 917 | continue; |
| 918 | |
| 919 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 920 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 924 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 925 | struct weston_seat *seat) |
| 926 | { |
| 927 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 928 | |
| 929 | wl_list_for_each(state, &ws->focus_list, link) { |
| 930 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 931 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 932 | return; |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | static void |
| 938 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 939 | struct weston_surface *surface) |
| 940 | { |
| 941 | struct focus_state *state; |
| 942 | |
| 943 | wl_list_for_each(state, &ws->focus_list, link) |
| 944 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 945 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 949 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 950 | struct weston_view *from, struct weston_view *to) |
| 951 | { |
| 952 | struct weston_output *output; |
| 953 | bool focus_surface_created = false; |
| 954 | |
| 955 | /* FIXME: Only support dim animation using two layers */ |
| 956 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 957 | return; |
| 958 | |
| 959 | output = get_default_output(shell->compositor); |
| 960 | if (ws->fsurf_front == NULL && (from || to)) { |
| 961 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 962 | if (ws->fsurf_front == NULL) |
| 963 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 964 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 965 | |
| 966 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 967 | if (ws->fsurf_back == NULL) { |
| 968 | focus_surface_destroy(ws->fsurf_front); |
| 969 | return; |
| 970 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 971 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 972 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 973 | focus_surface_created = true; |
| 974 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 975 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 976 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | if (ws->focus_animation) { |
| 980 | weston_view_animation_destroy(ws->focus_animation); |
| 981 | ws->focus_animation = NULL; |
| 982 | } |
| 983 | |
| 984 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 985 | weston_layer_entry_insert(&to->layer_link, |
| 986 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 987 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 988 | weston_layer_entry_insert(&ws->layer.view_list, |
| 989 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 990 | |
| 991 | if (focus_surface_created) { |
| 992 | ws->focus_animation = weston_fade_run( |
| 993 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 994 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 995 | focus_animation_done, ws); |
| 996 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 997 | weston_layer_entry_insert(&from->layer_link, |
| 998 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | ws->focus_animation = weston_stable_fade_run( |
| 1000 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1001 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | focus_animation_done, ws); |
| 1003 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1004 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1005 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | ws->focus_animation = weston_stable_fade_run( |
| 1007 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1008 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1009 | focus_animation_done, ws); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1014 | workspace_destroy(struct workspace *ws) |
| 1015 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1016 | struct focus_state *state, *next; |
| 1017 | |
| 1018 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1019 | focus_state_destroy(state); |
| 1020 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1021 | if (ws->fsurf_front) |
| 1022 | focus_surface_destroy(ws->fsurf_front); |
| 1023 | if (ws->fsurf_back) |
| 1024 | focus_surface_destroy(ws->fsurf_back); |
| 1025 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1026 | free(ws); |
| 1027 | } |
| 1028 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1029 | static void |
| 1030 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1031 | { |
| 1032 | struct weston_seat *seat = data; |
| 1033 | struct focus_state *state, *next; |
| 1034 | struct workspace *ws = container_of(listener, |
| 1035 | struct workspace, |
| 1036 | seat_destroyed_listener); |
| 1037 | |
| 1038 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1039 | if (state->seat == seat) |
| 1040 | wl_list_remove(&state->link); |
| 1041 | } |
| 1042 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1043 | static struct workspace * |
| 1044 | workspace_create(void) |
| 1045 | { |
| 1046 | struct workspace *ws = malloc(sizeof *ws); |
| 1047 | if (ws == NULL) |
| 1048 | return NULL; |
| 1049 | |
| 1050 | weston_layer_init(&ws->layer, NULL); |
| 1051 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1052 | wl_list_init(&ws->focus_list); |
| 1053 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1054 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1055 | ws->fsurf_front = NULL; |
| 1056 | ws->fsurf_back = NULL; |
| 1057 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1058 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1059 | return ws; |
| 1060 | } |
| 1061 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | static int |
| 1063 | workspace_is_empty(struct workspace *ws) |
| 1064 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1065 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1066 | } |
| 1067 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1068 | static struct workspace * |
| 1069 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1070 | { |
| 1071 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1072 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1073 | pws += index; |
| 1074 | return *pws; |
| 1075 | } |
| 1076 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1077 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1078 | get_current_workspace(struct desktop_shell *shell) |
| 1079 | { |
| 1080 | return get_workspace(shell, shell->workspaces.current); |
| 1081 | } |
| 1082 | |
| 1083 | static void |
| 1084 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1085 | { |
| 1086 | struct workspace *ws; |
| 1087 | |
| 1088 | ws = get_workspace(shell, index); |
| 1089 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1090 | |
| 1091 | shell->workspaces.current = index; |
| 1092 | } |
| 1093 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1094 | static unsigned int |
| 1095 | get_output_height(struct weston_output *output) |
| 1096 | { |
| 1097 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1098 | } |
| 1099 | |
| 1100 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1101 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1102 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1103 | struct weston_transform *transform; |
| 1104 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1105 | if (is_focus_view(view)) { |
| 1106 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1107 | transform = &fsurf->workspace_transform; |
| 1108 | } else { |
| 1109 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1110 | transform = &shsurf->workspace_transform; |
| 1111 | } |
| 1112 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1113 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1114 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1115 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1116 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1117 | weston_matrix_init(&transform->matrix); |
| 1118 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1119 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1120 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static void |
| 1124 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1125 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1126 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1127 | unsigned int height; |
| 1128 | double d; |
| 1129 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1130 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1131 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1132 | d = height * fraction; |
| 1133 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1134 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | static void |
| 1139 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1140 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1141 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1142 | unsigned int height; |
| 1143 | double d; |
| 1144 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1145 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1146 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1147 | |
| 1148 | if (fraction > 0) |
| 1149 | d = -(height - height * fraction); |
| 1150 | else |
| 1151 | d = height + height * fraction; |
| 1152 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1153 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1158 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1159 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1160 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1161 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1162 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1163 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1164 | shell->workspaces.current, |
| 1165 | shell->workspaces.num); |
| 1166 | } |
| 1167 | |
| 1168 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1169 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1170 | unsigned int index, |
| 1171 | struct workspace *from, |
| 1172 | struct workspace *to) |
| 1173 | { |
| 1174 | shell->workspaces.current = index; |
| 1175 | |
| 1176 | shell->workspaces.anim_to = to; |
| 1177 | shell->workspaces.anim_from = from; |
| 1178 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1179 | shell->workspaces.anim_timestamp = 0; |
| 1180 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1181 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | workspace_deactivate_transforms(struct workspace *ws) |
| 1186 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1188 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1189 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1190 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1191 | if (is_focus_view(view)) { |
| 1192 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1193 | transform = &fsurf->workspace_transform; |
| 1194 | } else { |
| 1195 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1196 | transform = &shsurf->workspace_transform; |
| 1197 | } |
| 1198 | |
| 1199 | if (!wl_list_empty(&transform->link)) { |
| 1200 | wl_list_remove(&transform->link); |
| 1201 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1202 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1203 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | static void |
| 1208 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1209 | struct workspace *from, |
| 1210 | struct workspace *to) |
| 1211 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1212 | struct weston_view *view; |
| 1213 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1214 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1215 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1216 | /* Views that extend past the bottom of the output are still |
| 1217 | * visible after the workspace animation ends but before its layer |
| 1218 | * is hidden. In that case, we need to damage below those views so |
| 1219 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1220 | wl_list_for_each(view, &from->layer.view_list.link, layer_link.link) |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1221 | weston_view_damage_below(view); |
| 1222 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1223 | wl_list_remove(&shell->workspaces.animation.link); |
| 1224 | workspace_deactivate_transforms(from); |
| 1225 | workspace_deactivate_transforms(to); |
| 1226 | shell->workspaces.anim_to = NULL; |
| 1227 | |
| 1228 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1229 | } |
| 1230 | |
| 1231 | static void |
| 1232 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1233 | struct weston_output *output, uint32_t msecs) |
| 1234 | { |
| 1235 | struct desktop_shell *shell = |
| 1236 | container_of(animation, struct desktop_shell, |
| 1237 | workspaces.animation); |
| 1238 | struct workspace *from = shell->workspaces.anim_from; |
| 1239 | struct workspace *to = shell->workspaces.anim_to; |
| 1240 | uint32_t t; |
| 1241 | double x, y; |
| 1242 | |
| 1243 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1244 | finish_workspace_change_animation(shell, from, to); |
| 1245 | return; |
| 1246 | } |
| 1247 | |
| 1248 | if (shell->workspaces.anim_timestamp == 0) { |
| 1249 | if (shell->workspaces.anim_current == 0.0) |
| 1250 | shell->workspaces.anim_timestamp = msecs; |
| 1251 | else |
| 1252 | shell->workspaces.anim_timestamp = |
| 1253 | msecs - |
| 1254 | /* Invers of movement function 'y' below. */ |
| 1255 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1256 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1257 | M_2_PI); |
| 1258 | } |
| 1259 | |
| 1260 | t = msecs - shell->workspaces.anim_timestamp; |
| 1261 | |
| 1262 | /* |
| 1263 | * x = [0, π/2] |
| 1264 | * y(x) = sin(x) |
| 1265 | */ |
| 1266 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1267 | y = sin(x); |
| 1268 | |
| 1269 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1270 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1271 | |
| 1272 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1273 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1274 | shell->workspaces.anim_current = y; |
| 1275 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1276 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1277 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1278 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1279 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void |
| 1283 | animate_workspace_change(struct desktop_shell *shell, |
| 1284 | unsigned int index, |
| 1285 | struct workspace *from, |
| 1286 | struct workspace *to) |
| 1287 | { |
| 1288 | struct weston_output *output; |
| 1289 | |
| 1290 | int dir; |
| 1291 | |
| 1292 | if (index > shell->workspaces.current) |
| 1293 | dir = -1; |
| 1294 | else |
| 1295 | dir = 1; |
| 1296 | |
| 1297 | shell->workspaces.current = index; |
| 1298 | |
| 1299 | shell->workspaces.anim_dir = dir; |
| 1300 | shell->workspaces.anim_from = from; |
| 1301 | shell->workspaces.anim_to = to; |
| 1302 | shell->workspaces.anim_current = 0.0; |
| 1303 | shell->workspaces.anim_timestamp = 0; |
| 1304 | |
| 1305 | output = container_of(shell->compositor->output_list.next, |
| 1306 | struct weston_output, link); |
| 1307 | wl_list_insert(&output->animation_list, |
| 1308 | &shell->workspaces.animation.link); |
| 1309 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1310 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1311 | |
| 1312 | workspace_translate_in(to, 0); |
| 1313 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1314 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1315 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1316 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1317 | } |
| 1318 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1319 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1320 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1321 | struct workspace *from, struct workspace *to) |
| 1322 | { |
| 1323 | shell->workspaces.current = index; |
| 1324 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1325 | wl_list_remove(&from->layer.link); |
| 1326 | } |
| 1327 | |
| 1328 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1329 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1330 | { |
| 1331 | struct workspace *from; |
| 1332 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1333 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1334 | |
| 1335 | if (index == shell->workspaces.current) |
| 1336 | return; |
| 1337 | |
| 1338 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1339 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1340 | return; |
| 1341 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1342 | from = get_current_workspace(shell); |
| 1343 | to = get_workspace(shell, index); |
| 1344 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1345 | if (shell->workspaces.anim_from == to && |
| 1346 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1347 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1348 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1349 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1350 | return; |
| 1351 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1352 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1353 | if (shell->workspaces.anim_to != NULL) |
| 1354 | finish_workspace_change_animation(shell, |
| 1355 | shell->workspaces.anim_from, |
| 1356 | shell->workspaces.anim_to); |
| 1357 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1358 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1359 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1360 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1361 | wl_list_for_each(state, &from->focus_list, link) |
| 1362 | if (state->keyboard_focus) |
| 1363 | animate_focus_change(shell, from, |
| 1364 | get_default_view(state->keyboard_focus), NULL); |
| 1365 | |
| 1366 | wl_list_for_each(state, &to->focus_list, link) |
| 1367 | if (state->keyboard_focus) |
| 1368 | animate_focus_change(shell, to, |
| 1369 | NULL, get_default_view(state->keyboard_focus)); |
| 1370 | } |
| 1371 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1372 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1373 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1374 | else |
| 1375 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1376 | |
| 1377 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1378 | } |
| 1379 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1380 | static bool |
| 1381 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1382 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1383 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1384 | struct wl_list *e; |
| 1385 | |
| 1386 | if (wl_list_empty(list)) |
| 1387 | return false; |
| 1388 | |
| 1389 | e = list->next; |
| 1390 | |
| 1391 | if (e->next != list) |
| 1392 | return false; |
| 1393 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1394 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1398 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1399 | struct shell_surface *shsurf, |
| 1400 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1401 | { |
| 1402 | struct workspace *from; |
| 1403 | struct workspace *to; |
| 1404 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1405 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1406 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1407 | |
| 1408 | if (workspace == shell->workspaces.current) |
| 1409 | return; |
| 1410 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1411 | view = get_default_view(shsurf->surface); |
| 1412 | if (!view) |
| 1413 | return; |
| 1414 | |
| 1415 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1416 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1417 | if (workspace >= shell->workspaces.num) |
| 1418 | workspace = shell->workspaces.num - 1; |
| 1419 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1420 | from = get_current_workspace(shell); |
| 1421 | to = get_workspace(shell, workspace); |
| 1422 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1423 | weston_layer_entry_remove(&view->layer_link); |
| 1424 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1425 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1426 | shell_surface_update_child_surface_layers(shsurf); |
| 1427 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1428 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1429 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1430 | if (!seat->keyboard) |
| 1431 | continue; |
| 1432 | |
| 1433 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1434 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1435 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1436 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1437 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1438 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1442 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1443 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1444 | unsigned int index) |
| 1445 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1446 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1447 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1448 | struct shell_surface *shsurf; |
| 1449 | struct workspace *from; |
| 1450 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1451 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1452 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1453 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1454 | view = get_default_view(surface); |
| 1455 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1456 | index == shell->workspaces.current || |
| 1457 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1458 | return; |
| 1459 | |
| 1460 | from = get_current_workspace(shell); |
| 1461 | to = get_workspace(shell, index); |
| 1462 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1463 | weston_layer_entry_remove(&view->layer_link); |
| 1464 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1465 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1466 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1467 | if (shsurf != NULL) |
| 1468 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1469 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1470 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1471 | drop_focus_state(shell, from, surface); |
| 1472 | |
| 1473 | if (shell->workspaces.anim_from == to && |
| 1474 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1475 | wl_list_remove(&to->layer.link); |
| 1476 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1477 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1478 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1479 | broadcast_current_workspace_state(shell); |
| 1480 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1481 | return; |
| 1482 | } |
| 1483 | |
| 1484 | if (shell->workspaces.anim_to != NULL) |
| 1485 | finish_workspace_change_animation(shell, |
| 1486 | shell->workspaces.anim_from, |
| 1487 | shell->workspaces.anim_to); |
| 1488 | |
| 1489 | if (workspace_is_empty(from) && |
| 1490 | workspace_has_only(to, surface)) |
| 1491 | update_workspace(shell, index, from, to); |
| 1492 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1493 | if (shsurf != NULL && |
| 1494 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1495 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1496 | &shsurf->workspace_transform.link); |
| 1497 | |
| 1498 | animate_workspace_change(shell, index, from, to); |
| 1499 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1500 | |
| 1501 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1502 | |
| 1503 | state = ensure_focus_state(shell, seat); |
| 1504 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1505 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | static void |
| 1509 | workspace_manager_move_surface(struct wl_client *client, |
| 1510 | struct wl_resource *resource, |
| 1511 | struct wl_resource *surface_resource, |
| 1512 | uint32_t workspace) |
| 1513 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1514 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1515 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1516 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1517 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1518 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1519 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1520 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1521 | shell_surface = get_shell_surface(main_surface); |
| 1522 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1523 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1524 | |
| 1525 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1529 | workspace_manager_move_surface, |
| 1530 | }; |
| 1531 | |
| 1532 | static void |
| 1533 | unbind_resource(struct wl_resource *resource) |
| 1534 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1535 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void |
| 1539 | bind_workspace_manager(struct wl_client *client, |
| 1540 | void *data, uint32_t version, uint32_t id) |
| 1541 | { |
| 1542 | struct desktop_shell *shell = data; |
| 1543 | struct wl_resource *resource; |
| 1544 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1545 | resource = wl_resource_create(client, |
| 1546 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1547 | |
| 1548 | if (resource == NULL) { |
| 1549 | weston_log("couldn't add workspace manager object"); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1553 | wl_resource_set_implementation(resource, |
| 1554 | &workspace_manager_implementation, |
| 1555 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1556 | wl_list_insert(&shell->workspaces.client_list, |
| 1557 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1558 | |
| 1559 | workspace_manager_send_state(resource, |
| 1560 | shell->workspaces.current, |
| 1561 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1564 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1565 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1566 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1567 | { |
| 1568 | } |
| 1569 | |
| 1570 | static void |
| 1571 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1572 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1573 | struct weston_touch_move_grab *move = |
| 1574 | (struct weston_touch_move_grab *) container_of( |
| 1575 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1576 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1577 | if (touch_id == 0) |
| 1578 | move->active = 0; |
| 1579 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1580 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1581 | shell_touch_grab_end(&move->base); |
| 1582 | free(move); |
| 1583 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | static void |
| 1587 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1588 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1589 | { |
| 1590 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1591 | struct shell_surface *shsurf = move->base.shsurf; |
| 1592 | struct weston_surface *es; |
| 1593 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1594 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1595 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1596 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1597 | return; |
| 1598 | |
| 1599 | es = shsurf->surface; |
| 1600 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1601 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1602 | |
| 1603 | weston_compositor_schedule_repaint(es->compositor); |
| 1604 | } |
| 1605 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1606 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1607 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1608 | { |
| 1609 | } |
| 1610 | |
| 1611 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1612 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1613 | { |
| 1614 | struct weston_touch_move_grab *move = |
| 1615 | (struct weston_touch_move_grab *) container_of( |
| 1616 | grab, struct shell_touch_grab, grab); |
| 1617 | |
| 1618 | shell_touch_grab_end(&move->base); |
| 1619 | free(move); |
| 1620 | } |
| 1621 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1622 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1623 | touch_move_grab_down, |
| 1624 | touch_move_grab_up, |
| 1625 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1626 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1627 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1628 | }; |
| 1629 | |
| 1630 | static int |
| 1631 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1632 | { |
| 1633 | struct weston_touch_move_grab *move; |
| 1634 | |
| 1635 | if (!shsurf) |
| 1636 | return -1; |
| 1637 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1638 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1639 | return 0; |
| 1640 | |
| 1641 | move = malloc(sizeof *move); |
| 1642 | if (!move) |
| 1643 | return -1; |
| 1644 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1645 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1646 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1647 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1648 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1649 | seat->touch->grab_y; |
| 1650 | |
| 1651 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1652 | seat->touch); |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
| 1657 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1658 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1659 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1663 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1664 | { |
| 1665 | struct shell_surface *shsurf = move->base.shsurf; |
| 1666 | struct weston_pointer *pointer = move->base.grab.pointer; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1667 | int x, y, panel_width, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1668 | const int safety = 50; |
| 1669 | |
| 1670 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1671 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1672 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1673 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
| 1674 | get_output_panel_size(shsurf->shell, shsurf->surface->output, |
| 1675 | &panel_width, &panel_height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1676 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1677 | bottom = y + shsurf->geometry.height; |
| 1678 | if (bottom - panel_height < safety) |
| 1679 | y = panel_height + safety - |
| 1680 | shsurf->geometry.height; |
| 1681 | |
| 1682 | if (move->client_initiated && |
| 1683 | y + shsurf->geometry.y < panel_height) |
| 1684 | y = panel_height - shsurf->geometry.y; |
| 1685 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1686 | |
| 1687 | *cx = x; |
| 1688 | *cy = y; |
| 1689 | } |
| 1690 | |
| 1691 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1692 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1693 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1694 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1695 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1696 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1697 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1698 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1699 | |
| 1700 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1701 | if (!shsurf) |
| 1702 | return; |
| 1703 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1704 | constrain_position(move, &cx, &cy); |
| 1705 | |
| 1706 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1707 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1708 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1712 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1713 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1714 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1715 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1716 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1717 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1718 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1719 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1720 | if (pointer->button_count == 0 && |
| 1721 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1722 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1723 | free(grab); |
| 1724 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1725 | } |
| 1726 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1727 | static void |
| 1728 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1729 | { |
| 1730 | struct shell_grab *shell_grab = |
| 1731 | container_of(grab, struct shell_grab, grab); |
| 1732 | |
| 1733 | shell_grab_end(shell_grab); |
| 1734 | free(grab); |
| 1735 | } |
| 1736 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1737 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1738 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1739 | move_grab_motion, |
| 1740 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1741 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1742 | }; |
| 1743 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1745 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1746 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1747 | { |
| 1748 | struct weston_move_grab *move; |
| 1749 | |
| 1750 | if (!shsurf) |
| 1751 | return -1; |
| 1752 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1753 | if (shsurf->grabbed || |
| 1754 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1755 | return 0; |
| 1756 | |
| 1757 | move = malloc(sizeof *move); |
| 1758 | if (!move) |
| 1759 | return -1; |
| 1760 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1761 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1762 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1763 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1764 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1765 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1766 | |
| 1767 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1768 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1769 | |
| 1770 | return 0; |
| 1771 | } |
| 1772 | |
| 1773 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1774 | common_surface_move(struct wl_resource *resource, |
| 1775 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1776 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1777 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1778 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1779 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1780 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1781 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1782 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1783 | seat->pointer->button_count > 0 && |
| 1784 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1785 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1786 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1787 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1788 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1789 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1790 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1791 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1792 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1793 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1794 | (surface_touch_move(shsurf, seat) < 0)) |
| 1795 | wl_resource_post_no_memory(resource); |
| 1796 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1797 | } |
| 1798 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1799 | static void |
| 1800 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1801 | struct wl_resource *seat_resource, uint32_t serial) |
| 1802 | { |
| 1803 | common_surface_move(resource, seat_resource, serial); |
| 1804 | } |
| 1805 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1806 | struct weston_resize_grab { |
| 1807 | struct shell_grab base; |
| 1808 | uint32_t edges; |
| 1809 | int32_t width, height; |
| 1810 | }; |
| 1811 | |
| 1812 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1813 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1814 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1815 | { |
| 1816 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1817 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1819 | int32_t width, height; |
| 1820 | wl_fixed_t from_x, from_y; |
| 1821 | wl_fixed_t to_x, to_y; |
| 1822 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1823 | weston_pointer_move(pointer, x, y); |
| 1824 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1825 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1826 | return; |
| 1827 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1828 | weston_view_from_global_fixed(shsurf->view, |
| 1829 | pointer->grab_x, pointer->grab_y, |
| 1830 | &from_x, &from_y); |
| 1831 | weston_view_from_global_fixed(shsurf->view, |
| 1832 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1833 | |
| 1834 | width = resize->width; |
| 1835 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1836 | width += wl_fixed_to_int(from_x - to_x); |
| 1837 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1838 | width += wl_fixed_to_int(to_x - from_x); |
| 1839 | } |
| 1840 | |
| 1841 | height = resize->height; |
| 1842 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1843 | height += wl_fixed_to_int(from_y - to_y); |
| 1844 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1845 | height += wl_fixed_to_int(to_y - from_y); |
| 1846 | } |
| 1847 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1848 | if (width < 1) |
| 1849 | width = 1; |
| 1850 | if (height < 1) |
| 1851 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1852 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1856 | send_configure(struct weston_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1857 | { |
| 1858 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1859 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1860 | assert(shsurf); |
| 1861 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1862 | if (shsurf->resource) |
| 1863 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1864 | shsurf->resize_edges, |
| 1865 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static const struct weston_shell_client shell_client = { |
| 1869 | send_configure |
| 1870 | }; |
| 1871 | |
| 1872 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1873 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1874 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1875 | { |
| 1876 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1877 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1878 | enum wl_pointer_button_state state = state_w; |
| 1879 | |
| 1880 | if (pointer->button_count == 0 && |
| 1881 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1882 | shell_grab_end(&resize->base); |
| 1883 | free(grab); |
| 1884 | } |
| 1885 | } |
| 1886 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1887 | static void |
| 1888 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1889 | { |
| 1890 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1891 | |
| 1892 | shell_grab_end(&resize->base); |
| 1893 | free(grab); |
| 1894 | } |
| 1895 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1896 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1897 | noop_grab_focus, |
| 1898 | resize_grab_motion, |
| 1899 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1900 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1901 | }; |
| 1902 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1903 | /* |
| 1904 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1905 | * in the surface coordinates system. */ |
| 1906 | static void |
| 1907 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1908 | int32_t *y, int32_t *w, int32_t *h) { |
| 1909 | pixman_region32_t region; |
| 1910 | pixman_box32_t *box; |
| 1911 | struct weston_subsurface *subsurface; |
| 1912 | |
| 1913 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1914 | surface->width, |
| 1915 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1916 | |
| 1917 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1918 | pixman_region32_union_rect(®ion, ®ion, |
| 1919 | subsurface->position.x, |
| 1920 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1921 | subsurface->surface->width, |
| 1922 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | box = pixman_region32_extents(®ion); |
| 1926 | if (x) |
| 1927 | *x = box->x1; |
| 1928 | if (y) |
| 1929 | *y = box->y1; |
| 1930 | if (w) |
| 1931 | *w = box->x2 - box->x1; |
| 1932 | if (h) |
| 1933 | *h = box->y2 - box->y1; |
| 1934 | |
| 1935 | pixman_region32_fini(®ion); |
| 1936 | } |
| 1937 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1938 | static int |
| 1939 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1940 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1941 | { |
| 1942 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1943 | const unsigned resize_topbottom = |
| 1944 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1945 | const unsigned resize_leftright = |
| 1946 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1947 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1948 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1949 | if (shsurf->grabbed || |
| 1950 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1951 | return 0; |
| 1952 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1953 | /* Check for invalid edge combinations. */ |
| 1954 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1955 | (edges & resize_topbottom) == resize_topbottom || |
| 1956 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1957 | return 0; |
| 1958 | |
| 1959 | resize = malloc(sizeof *resize); |
| 1960 | if (!resize) |
| 1961 | return -1; |
| 1962 | |
| 1963 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1964 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1965 | resize->width = shsurf->geometry.width; |
| 1966 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1967 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1968 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1969 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1970 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1971 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1972 | |
| 1973 | return 0; |
| 1974 | } |
| 1975 | |
| 1976 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1977 | common_surface_resize(struct wl_resource *resource, |
| 1978 | struct wl_resource *seat_resource, uint32_t serial, |
| 1979 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1980 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1981 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1982 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1983 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1984 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1985 | if (seat->pointer == NULL || |
| 1986 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1987 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1988 | seat->pointer->focus == NULL) |
| 1989 | return; |
| 1990 | |
| 1991 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1992 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1993 | return; |
| 1994 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1995 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1996 | wl_resource_post_no_memory(resource); |
| 1997 | } |
| 1998 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1999 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2000 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2001 | struct wl_resource *seat_resource, uint32_t serial, |
| 2002 | uint32_t edges) |
| 2003 | { |
| 2004 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2005 | } |
| 2006 | |
| 2007 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2008 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2009 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2010 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2011 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2012 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2013 | wl_fixed_t sx, sy; |
| 2014 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2015 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2016 | pointer->x, pointer->y, |
| 2017 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2018 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2019 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2020 | shell_grab_end(grab); |
| 2021 | free(grab); |
| 2022 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2026 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2027 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2028 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2029 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2030 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2031 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2032 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2033 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2034 | uint32_t time, uint32_t button, uint32_t state) |
| 2035 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2036 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2037 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2038 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2039 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2040 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2041 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2042 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2043 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2044 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2045 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2046 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2047 | } |
| 2048 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2049 | static void |
| 2050 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2051 | { |
| 2052 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2053 | |
| 2054 | shell_grab_end(grab); |
| 2055 | free(grab); |
| 2056 | } |
| 2057 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2058 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2059 | busy_cursor_grab_focus, |
| 2060 | busy_cursor_grab_motion, |
| 2061 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2062 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2063 | }; |
| 2064 | |
| 2065 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2066 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2067 | { |
| 2068 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2069 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2070 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2071 | return; |
| 2072 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2073 | grab = malloc(sizeof *grab); |
| 2074 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2075 | return; |
| 2076 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2077 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2078 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2079 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2080 | * to move it. */ |
| 2081 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2082 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2083 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2084 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2085 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2086 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2087 | struct shell_grab *grab; |
| 2088 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2089 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2090 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2091 | if (seat->pointer == NULL) |
| 2092 | continue; |
| 2093 | |
| 2094 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2095 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2096 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2097 | shell_grab_end(grab); |
| 2098 | free(grab); |
| 2099 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2100 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2101 | } |
| 2102 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2103 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2104 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2105 | |
| 2106 | static int |
| 2107 | xdg_ping_timeout_handler(void *data) |
| 2108 | { |
| 2109 | struct shell_client *sc = data; |
| 2110 | struct weston_seat *seat; |
| 2111 | struct shell_surface *shsurf; |
| 2112 | |
| 2113 | /* Client is not responding */ |
| 2114 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2115 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2116 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2117 | continue; |
| 2118 | if (seat->pointer->focus->surface->resource == NULL) |
| 2119 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2120 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2121 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2122 | if (shsurf && |
| 2123 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2124 | set_busy_cursor(shsurf, seat->pointer); |
| 2125 | } |
| 2126 | |
| 2127 | return 1; |
| 2128 | } |
| 2129 | |
| 2130 | static void |
| 2131 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2132 | { |
| 2133 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2134 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2135 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2136 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2137 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2138 | if (sc->unresponsive) { |
| 2139 | xdg_ping_timeout_handler(sc); |
| 2140 | return; |
| 2141 | } |
| 2142 | |
| 2143 | sc->ping_serial = serial; |
| 2144 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2145 | if (sc->ping_timer == NULL) |
| 2146 | sc->ping_timer = |
| 2147 | wl_event_loop_add_timer(loop, |
| 2148 | xdg_ping_timeout_handler, sc); |
| 2149 | if (sc->ping_timer == NULL) |
| 2150 | return; |
| 2151 | |
| 2152 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2153 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2154 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2155 | shell_surface_is_xdg_popup(shsurf)) |
| 2156 | xdg_shell_send_ping(sc->resource, serial); |
| 2157 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2158 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2161 | static void |
| 2162 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2163 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2164 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2165 | |
| 2166 | if (!shsurf) |
| 2167 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2168 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2169 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2170 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2171 | return; |
| 2172 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2173 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2177 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2178 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2179 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2180 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2181 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2182 | uint32_t serial; |
| 2183 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2184 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2185 | return; |
| 2186 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2187 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2188 | serial = wl_display_next_serial(compositor->wl_display); |
| 2189 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2193 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2194 | { |
| 2195 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2196 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | static void |
| 2200 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2201 | { |
| 2202 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2203 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | static void |
| 2207 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2208 | { |
| 2209 | struct weston_keyboard *keyboard = data; |
| 2210 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2211 | |
| 2212 | if (seat->focused_surface) { |
| 2213 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2214 | if (shsurf) |
| 2215 | shell_surface_lose_keyboard_focus(shsurf); |
| 2216 | } |
| 2217 | |
| 2218 | seat->focused_surface = keyboard->focus; |
| 2219 | |
| 2220 | if (seat->focused_surface) { |
| 2221 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2222 | if (shsurf) |
| 2223 | shell_surface_gain_keyboard_focus(shsurf); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2228 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2229 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2230 | if (sc->ping_serial != serial) |
| 2231 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2232 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2233 | sc->unresponsive = 0; |
| 2234 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2235 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2236 | if (sc->ping_timer) { |
| 2237 | wl_event_source_remove(sc->ping_timer); |
| 2238 | sc->ping_timer = NULL; |
| 2239 | } |
| 2240 | |
| 2241 | } |
| 2242 | |
| 2243 | static void |
| 2244 | shell_surface_pong(struct wl_client *client, |
| 2245 | struct wl_resource *resource, uint32_t serial) |
| 2246 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2247 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2248 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2249 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2250 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2254 | set_title(struct shell_surface *shsurf, const char *title) |
| 2255 | { |
| 2256 | free(shsurf->title); |
| 2257 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2258 | shsurf->surface->timeline.force_refresh = 1; |
| 2259 | } |
| 2260 | |
| 2261 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2262 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2263 | { |
| 2264 | /* We have no use for it */ |
| 2265 | } |
| 2266 | |
| 2267 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2268 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2269 | { |
| 2270 | shsurf->type = t; |
| 2271 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2275 | set_window_geometry(struct shell_surface *shsurf, |
| 2276 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2277 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2278 | shsurf->next_geometry.x = x; |
| 2279 | shsurf->next_geometry.y = y; |
| 2280 | shsurf->next_geometry.width = width; |
| 2281 | shsurf->next_geometry.height = height; |
| 2282 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2286 | shell_surface_set_title(struct wl_client *client, |
| 2287 | struct wl_resource *resource, const char *title) |
| 2288 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2289 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2290 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2291 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | static void |
| 2295 | shell_surface_set_class(struct wl_client *client, |
| 2296 | struct wl_resource *resource, const char *class) |
| 2297 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2298 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2299 | |
| 2300 | free(shsurf->class); |
| 2301 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2302 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2303 | } |
| 2304 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2305 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2306 | restore_output_mode(struct weston_output *output) |
| 2307 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2308 | if (output->original_mode) |
| 2309 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | static void |
| 2313 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2314 | { |
| 2315 | struct weston_output *output; |
| 2316 | |
| 2317 | wl_list_for_each(output, &compositor->output_list, link) |
| 2318 | restore_output_mode(output); |
| 2319 | } |
| 2320 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2321 | /* The surface will be inserted into the list immediately after the link |
| 2322 | * returned by this function (i.e. will be stacked immediately above the |
| 2323 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2324 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2325 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2326 | { |
| 2327 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2328 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2329 | |
| 2330 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2331 | case SHELL_SURFACE_XWAYLAND: |
| 2332 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2333 | |
| 2334 | case SHELL_SURFACE_NONE: |
| 2335 | return NULL; |
| 2336 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2337 | case SHELL_SURFACE_POPUP: |
| 2338 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2339 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2340 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2341 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2342 | /* Move the surface to its parent layer so |
| 2343 | * that surfaces which are transient for |
| 2344 | * fullscreen surfaces don't get hidden by the |
| 2345 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2346 | |
| 2347 | /* TODO: Handle a parent with multiple views */ |
| 2348 | parent = get_default_view(shsurf->parent); |
| 2349 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2350 | return container_of(parent->layer_link.link.prev, |
| 2351 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2352 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2353 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2354 | /* Move the surface to a normal workspace layer so that surfaces |
| 2355 | * which were previously fullscreen or transient are no longer |
| 2356 | * rendered on top. */ |
| 2357 | ws = get_current_workspace(shsurf->shell); |
| 2358 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2361 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2364 | static void |
| 2365 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2366 | { |
| 2367 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2368 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2369 | |
| 2370 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2371 | * stacked above shsurf. */ |
| 2372 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2373 | if (shsurf->view->layer_link.link.prev != &child->view->layer_link.link) { |
Ander Conselvan de Oliveira | facc0cc | 2014-04-10 15:35:58 +0300 | [diff] [blame] | 2374 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2375 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2376 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2377 | struct weston_layer_entry, link); |
| 2378 | weston_layer_entry_remove(&child->view->layer_link); |
| 2379 | weston_layer_entry_insert(prev, |
| 2380 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2381 | weston_view_geometry_dirty(child->view); |
| 2382 | weston_surface_damage(child->surface); |
| 2383 | |
| 2384 | /* Recurse. We don’t expect this to recurse very far (if |
| 2385 | * at all) because that would imply we have transient |
| 2386 | * (or popup) children of transient surfaces, which |
| 2387 | * would be unusual. */ |
| 2388 | shell_surface_update_child_surface_layers(child); |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2393 | /* Update the surface’s layer. Mark both the old and new views as having dirty |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2394 | * geometry to ensure the changes are redrawn. |
| 2395 | * |
| 2396 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2397 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2398 | static void |
| 2399 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2400 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2401 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2402 | |
| 2403 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2404 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2405 | if (new_layer_link == NULL) |
| 2406 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2407 | if (new_layer_link == &shsurf->view->layer_link) |
| 2408 | return; |
| 2409 | |
| 2410 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2411 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2412 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2413 | weston_view_geometry_dirty(shsurf->view); |
| 2414 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2415 | |
| 2416 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2419 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2420 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2421 | struct weston_surface *parent) |
| 2422 | { |
| 2423 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2424 | |
| 2425 | wl_list_remove(&shsurf->children_link); |
| 2426 | wl_list_init(&shsurf->children_link); |
| 2427 | |
| 2428 | /* Insert into the parent surface’s child list. */ |
| 2429 | if (parent != NULL) { |
| 2430 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2431 | if (parent_shsurf != NULL) |
| 2432 | wl_list_insert(&parent_shsurf->children_list, |
| 2433 | &shsurf->children_link); |
| 2434 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2438 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2439 | struct weston_output *output) |
| 2440 | { |
| 2441 | struct weston_surface *es = shsurf->surface; |
| 2442 | |
| 2443 | /* get the default output, if the client set it as NULL |
| 2444 | check whether the ouput is available */ |
| 2445 | if (output) |
| 2446 | shsurf->output = output; |
| 2447 | else if (es->output) |
| 2448 | shsurf->output = es->output; |
| 2449 | else |
| 2450 | shsurf->output = get_default_output(es->compositor); |
| 2451 | } |
| 2452 | |
| 2453 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2454 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2455 | { |
| 2456 | shsurf->next_state.maximized = false; |
| 2457 | shsurf->next_state.fullscreen = false; |
| 2458 | |
| 2459 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2460 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2461 | shsurf->state_changed = true; |
| 2462 | } |
| 2463 | |
| 2464 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2465 | set_toplevel(struct shell_surface *shsurf) |
| 2466 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2467 | shell_surface_set_parent(shsurf, NULL); |
| 2468 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2469 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2470 | |
| 2471 | /* The layer_link is updated in set_surface_type(), |
| 2472 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | static void |
| 2476 | shell_surface_set_toplevel(struct wl_client *client, |
| 2477 | struct wl_resource *resource) |
| 2478 | { |
| 2479 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2480 | |
| 2481 | set_toplevel(surface); |
| 2482 | } |
| 2483 | |
| 2484 | static void |
| 2485 | set_transient(struct shell_surface *shsurf, |
| 2486 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2487 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2488 | assert(parent != NULL); |
| 2489 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2490 | shell_surface_set_parent(shsurf, parent); |
| 2491 | |
| 2492 | surface_clear_next_states(shsurf); |
| 2493 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2494 | shsurf->transient.x = x; |
| 2495 | shsurf->transient.y = y; |
| 2496 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2497 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2498 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2499 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2500 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2501 | |
| 2502 | /* The layer_link is updated in set_surface_type(), |
| 2503 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | static void |
| 2507 | shell_surface_set_transient(struct wl_client *client, |
| 2508 | struct wl_resource *resource, |
| 2509 | struct wl_resource *parent_resource, |
| 2510 | int x, int y, uint32_t flags) |
| 2511 | { |
| 2512 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2513 | struct weston_surface *parent = |
| 2514 | wl_resource_get_user_data(parent_resource); |
| 2515 | |
| 2516 | set_transient(shsurf, parent, x, y, flags); |
| 2517 | } |
| 2518 | |
| 2519 | static void |
| 2520 | set_fullscreen(struct shell_surface *shsurf, |
| 2521 | uint32_t method, |
| 2522 | uint32_t framerate, |
| 2523 | struct weston_output *output) |
| 2524 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2525 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2526 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2527 | |
| 2528 | shsurf->fullscreen_output = shsurf->output; |
| 2529 | shsurf->fullscreen.type = method; |
| 2530 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2531 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2532 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2536 | weston_view_set_initial_position(struct weston_view *view, |
| 2537 | struct desktop_shell *shell); |
| 2538 | |
| 2539 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2540 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2541 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2542 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2543 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2544 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2545 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2546 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2547 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2548 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2549 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2550 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2551 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2552 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2554 | if (shsurf->fullscreen.black_view) |
| 2555 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2556 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2557 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2558 | if (shsurf->saved_position_valid) |
| 2559 | weston_view_set_position(shsurf->view, |
| 2560 | shsurf->saved_x, shsurf->saved_y); |
| 2561 | else |
| 2562 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2563 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2564 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2565 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2566 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2567 | shsurf->saved_rotation_valid = false; |
| 2568 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2569 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2570 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2571 | } |
| 2572 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2573 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2574 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2575 | struct wl_resource *resource, |
| 2576 | uint32_t method, |
| 2577 | uint32_t framerate, |
| 2578 | struct wl_resource *output_resource) |
| 2579 | { |
| 2580 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2581 | struct weston_output *output; |
| 2582 | |
| 2583 | if (output_resource) |
| 2584 | output = wl_resource_get_user_data(output_resource); |
| 2585 | else |
| 2586 | output = NULL; |
| 2587 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2588 | shell_surface_set_parent(shsurf, NULL); |
| 2589 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2590 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2591 | shsurf->next_state.fullscreen = true; |
| 2592 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2593 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | static void |
| 2597 | set_popup(struct shell_surface *shsurf, |
| 2598 | struct weston_surface *parent, |
| 2599 | struct weston_seat *seat, |
| 2600 | uint32_t serial, |
| 2601 | int32_t x, |
| 2602 | int32_t y) |
| 2603 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2604 | assert(parent != NULL); |
| 2605 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2606 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2607 | shsurf->popup.serial = serial; |
| 2608 | shsurf->popup.x = x; |
| 2609 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2610 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2611 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | static void |
| 2615 | shell_surface_set_popup(struct wl_client *client, |
| 2616 | struct wl_resource *resource, |
| 2617 | struct wl_resource *seat_resource, |
| 2618 | uint32_t serial, |
| 2619 | struct wl_resource *parent_resource, |
| 2620 | int32_t x, int32_t y, uint32_t flags) |
| 2621 | { |
| 2622 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2623 | struct weston_surface *parent = |
| 2624 | wl_resource_get_user_data(parent_resource); |
| 2625 | |
| 2626 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2627 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2628 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2629 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2630 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2631 | wl_resource_get_user_data(seat_resource), |
| 2632 | serial, x, y); |
| 2633 | } |
| 2634 | |
| 2635 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2636 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2637 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2638 | /* undo all maximized things here */ |
| 2639 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2640 | |
| 2641 | if (shsurf->saved_position_valid) |
| 2642 | weston_view_set_position(shsurf->view, |
| 2643 | shsurf->saved_x, shsurf->saved_y); |
| 2644 | else |
| 2645 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2646 | |
| 2647 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2648 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2649 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2650 | shsurf->saved_rotation_valid = false; |
| 2651 | } |
| 2652 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2653 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2656 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2657 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2658 | { |
| 2659 | struct shell_surface *shsurf; |
| 2660 | struct workspace *current_ws; |
| 2661 | struct weston_seat *seat; |
| 2662 | struct weston_surface *focus; |
| 2663 | struct weston_view *view; |
| 2664 | |
| 2665 | view = get_default_view(surface); |
| 2666 | if (!view) |
| 2667 | return; |
| 2668 | |
| 2669 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2670 | |
| 2671 | shsurf = get_shell_surface(surface); |
| 2672 | current_ws = get_current_workspace(shsurf->shell); |
| 2673 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2674 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2675 | weston_layer_entry_insert(&shsurf->shell->minimized_layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2676 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2677 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2678 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2679 | if (!seat->keyboard) |
| 2680 | continue; |
| 2681 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2682 | if (focus == view->surface) |
| 2683 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2687 | weston_view_damage_below(view); |
| 2688 | } |
| 2689 | |
| 2690 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2691 | shell_surface_set_maximized(struct wl_client *client, |
| 2692 | struct wl_resource *resource, |
| 2693 | struct wl_resource *output_resource) |
| 2694 | { |
| 2695 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2696 | struct weston_output *output; |
| 2697 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2698 | surface_clear_next_states(shsurf); |
| 2699 | shsurf->next_state.maximized = true; |
| 2700 | shsurf->state_changed = true; |
| 2701 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2702 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2703 | shell_surface_set_parent(shsurf, NULL); |
| 2704 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2705 | if (output_resource) |
| 2706 | output = wl_resource_get_user_data(output_resource); |
| 2707 | else |
| 2708 | output = NULL; |
| 2709 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2710 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2711 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2712 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2715 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2716 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2717 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2718 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2719 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2720 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2721 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2722 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2723 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2724 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2725 | return 0; |
| 2726 | } |
| 2727 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2728 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2729 | set_full_output(struct shell_surface *shsurf) |
| 2730 | { |
| 2731 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2732 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2733 | shsurf->saved_width = shsurf->surface->width; |
| 2734 | shsurf->saved_height = shsurf->surface->height; |
| 2735 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2736 | shsurf->saved_position_valid = true; |
| 2737 | |
| 2738 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2739 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2740 | wl_list_init(&shsurf->rotation.transform.link); |
| 2741 | weston_view_geometry_dirty(shsurf->view); |
| 2742 | shsurf->saved_rotation_valid = true; |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2747 | set_surface_type(struct shell_surface *shsurf) |
| 2748 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2749 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2750 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2751 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2752 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2753 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2754 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2755 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2756 | |
| 2757 | switch (shsurf->type) { |
| 2758 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2759 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2760 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2761 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2762 | weston_view_set_position(shsurf->view, |
| 2763 | pev->geometry.x + shsurf->transient.x, |
| 2764 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2765 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2766 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2767 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2768 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2769 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2770 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2771 | break; |
| 2772 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2773 | case SHELL_SURFACE_POPUP: |
| 2774 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2775 | default: |
| 2776 | break; |
| 2777 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2778 | |
| 2779 | /* Update the surface’s layer. */ |
| 2780 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2781 | } |
| 2782 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2783 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2784 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2785 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2786 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2787 | } |
| 2788 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2789 | static int |
| 2790 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2791 | { |
| 2792 | struct weston_surface *fs_surface = surface->configure_private; |
| 2793 | int n; |
| 2794 | int rem; |
| 2795 | int ret; |
| 2796 | |
| 2797 | n = snprintf(buf, len, "black background surface for "); |
| 2798 | if (n < 0) |
| 2799 | return n; |
| 2800 | |
| 2801 | rem = (int)len - n; |
| 2802 | if (rem < 0) |
| 2803 | rem = 0; |
| 2804 | |
| 2805 | if (fs_surface->get_label) |
| 2806 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2807 | else |
| 2808 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2809 | |
| 2810 | if (ret < 0) |
| 2811 | return n; |
| 2812 | |
| 2813 | return n + ret; |
| 2814 | } |
| 2815 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2816 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2817 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2818 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2819 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2820 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2821 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2822 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2823 | { |
| 2824 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2825 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2826 | |
| 2827 | surface = weston_surface_create(ec); |
| 2828 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2829 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2830 | return NULL; |
| 2831 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2832 | view = weston_view_create(surface); |
| 2833 | if (surface == NULL) { |
| 2834 | weston_log("no memory\n"); |
| 2835 | weston_surface_destroy(surface); |
| 2836 | return NULL; |
| 2837 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2838 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2839 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2840 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2841 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2842 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2843 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2844 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2845 | pixman_region32_fini(&surface->input); |
| 2846 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2847 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2848 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2849 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2850 | |
| 2851 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2852 | } |
| 2853 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2854 | static void |
| 2855 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2856 | { |
| 2857 | struct weston_output *output = shsurf->fullscreen_output; |
| 2858 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2859 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2860 | |
| 2861 | if (!shsurf->fullscreen.black_view) |
| 2862 | shsurf->fullscreen.black_view = |
| 2863 | create_black_surface(shsurf->surface->compositor, |
| 2864 | shsurf->surface, |
| 2865 | output->x, output->y, |
| 2866 | output->width, |
| 2867 | output->height); |
| 2868 | |
| 2869 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2870 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2871 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2872 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2873 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2874 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2875 | |
| 2876 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2879 | /* Create black surface and append it to the associated fullscreen surface. |
| 2880 | * Handle size dismatch and positioning according to the method. */ |
| 2881 | static void |
| 2882 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2883 | { |
| 2884 | struct weston_output *output = shsurf->fullscreen_output; |
| 2885 | struct weston_surface *surface = shsurf->surface; |
| 2886 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2887 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2888 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2889 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2890 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2891 | restore_output_mode(output); |
| 2892 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2893 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2894 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2895 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2896 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2897 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2898 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2899 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2900 | &surf_width, &surf_height); |
| 2901 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2902 | switch (shsurf->fullscreen.type) { |
| 2903 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2904 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2905 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2906 | break; |
| 2907 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2908 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2909 | if (output->width == surf_width && |
| 2910 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2911 | weston_view_set_position(shsurf->view, |
| 2912 | output->x - surf_x, |
| 2913 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | } |
| 2916 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2917 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2918 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2919 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2920 | output_aspect = (float) output->width / |
| 2921 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2922 | /* XXX: Use surf_width and surf_height here? */ |
| 2923 | surface_aspect = (float) surface->width / |
| 2924 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2925 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2926 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2927 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2928 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2929 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2930 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2931 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2932 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2933 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2934 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2935 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2936 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2937 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2938 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2939 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2940 | break; |
| 2941 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2942 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2943 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2944 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2945 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2946 | shsurf->fullscreen.framerate}; |
| 2947 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2948 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2949 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2950 | weston_view_set_position(shsurf->view, |
| 2951 | output->x - surf_x, |
| 2952 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2953 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2954 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2955 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2956 | output->x - surf_x, |
| 2957 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2958 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2959 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2960 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2961 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2962 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2963 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2964 | break; |
| 2965 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2966 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2967 | break; |
| 2968 | default: |
| 2969 | break; |
| 2970 | } |
| 2971 | } |
| 2972 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2973 | static void |
| 2974 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2975 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2976 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2977 | } |
| 2978 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2979 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2980 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2981 | { |
| 2982 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2983 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2984 | shsurf->transient.x = x; |
| 2985 | shsurf->transient.y = y; |
| 2986 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2987 | |
| 2988 | shell_surface_set_parent(shsurf, NULL); |
| 2989 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2990 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2991 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2992 | } |
| 2993 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2994 | static void |
| 2995 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2996 | uint32_t method, |
| 2997 | uint32_t framerate, |
| 2998 | struct weston_output *output) |
| 2999 | { |
| 3000 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3001 | shsurf->next_state.fullscreen = true; |
| 3002 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3003 | |
| 3004 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3007 | static struct weston_output * |
| 3008 | get_focused_output(struct weston_compositor *compositor) |
| 3009 | { |
| 3010 | struct weston_seat *seat; |
| 3011 | struct weston_output *output = NULL; |
| 3012 | |
| 3013 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 3014 | /* Priority has touch focus, then pointer and |
| 3015 | * then keyboard focus. We should probably have |
| 3016 | * three for loops and check frist for touch, |
| 3017 | * then for pointer, etc. but unless somebody has some |
| 3018 | * objections, I think this is sufficient. */ |
| 3019 | if (seat->touch && seat->touch->focus) |
| 3020 | output = seat->touch->focus->output; |
| 3021 | else if (seat->pointer && seat->pointer->focus) |
| 3022 | output = seat->pointer->focus->output; |
| 3023 | else if (seat->keyboard && seat->keyboard->focus) |
| 3024 | output = seat->keyboard->focus->output; |
| 3025 | |
| 3026 | if (output) |
| 3027 | break; |
| 3028 | } |
| 3029 | |
| 3030 | return output; |
| 3031 | } |
| 3032 | |
| 3033 | static void |
| 3034 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3035 | { |
| 3036 | struct weston_output *output; |
| 3037 | |
| 3038 | surface_clear_next_states(shsurf); |
| 3039 | shsurf->next_state.maximized = true; |
| 3040 | shsurf->state_changed = true; |
| 3041 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3042 | |
| 3043 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3044 | output = get_focused_output(shsurf->surface->compositor); |
| 3045 | else |
| 3046 | output = shsurf->surface->output; |
| 3047 | |
| 3048 | shell_surface_set_output(shsurf, output); |
| 3049 | send_configure_for_surface(shsurf); |
| 3050 | } |
| 3051 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3052 | static int |
| 3053 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 3054 | { |
| 3055 | return surface_move(shsurf, ws, 1); |
| 3056 | } |
| 3057 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3058 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3059 | |
| 3060 | static void |
| 3061 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3062 | { |
| 3063 | struct shell_seat *shseat = |
| 3064 | container_of(listener, |
| 3065 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3066 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3067 | |
| 3068 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3069 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3070 | shseat->popup_grab.client = NULL; |
| 3071 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3072 | wl_list_for_each_safe(shsurf, next, |
| 3073 | &shseat->popup_grab.surfaces_list, |
| 3074 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3075 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3076 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3077 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3081 | free(shseat); |
| 3082 | } |
| 3083 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3084 | static void |
| 3085 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3086 | { |
| 3087 | struct shell_seat *seat; |
| 3088 | |
| 3089 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 3090 | |
| 3091 | if (seat->seat->keyboard && |
| 3092 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 3093 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 3094 | &seat->keyboard_focus_listener); |
| 3095 | } else if (!seat->seat->keyboard) { |
| 3096 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3097 | } |
| 3098 | |
| 3099 | if (seat->seat->pointer && |
| 3100 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 3101 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 3102 | &seat->pointer_focus_listener); |
| 3103 | } else if (!seat->seat->pointer) { |
| 3104 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3105 | } |
| 3106 | } |
| 3107 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3108 | static struct shell_seat * |
| 3109 | create_shell_seat(struct weston_seat *seat) |
| 3110 | { |
| 3111 | struct shell_seat *shseat; |
| 3112 | |
| 3113 | shseat = calloc(1, sizeof *shseat); |
| 3114 | if (!shseat) { |
| 3115 | weston_log("no memory to allocate shell seat\n"); |
| 3116 | return NULL; |
| 3117 | } |
| 3118 | |
| 3119 | shseat->seat = seat; |
| 3120 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3121 | |
| 3122 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3123 | wl_signal_add(&seat->destroy_signal, |
| 3124 | &shseat->seat_destroy_listener); |
| 3125 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3126 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3127 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3128 | |
| 3129 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3130 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3131 | |
| 3132 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3133 | wl_signal_add(&seat->updated_caps_signal, |
| 3134 | &shseat->caps_changed_listener); |
| 3135 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3136 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3137 | return shseat; |
| 3138 | } |
| 3139 | |
| 3140 | static struct shell_seat * |
| 3141 | get_shell_seat(struct weston_seat *seat) |
| 3142 | { |
| 3143 | struct wl_listener *listener; |
| 3144 | |
| 3145 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3146 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3147 | |
| 3148 | return container_of(listener, |
| 3149 | struct shell_seat, seat_destroy_listener); |
| 3150 | } |
| 3151 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3152 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3153 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3154 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3155 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3156 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3157 | struct shell_seat *shseat = |
| 3158 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3159 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3160 | wl_fixed_t sx, sy; |
| 3161 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3162 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3163 | pointer->x, pointer->y, |
| 3164 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3165 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3166 | if (view && view->surface->resource && |
| 3167 | wl_resource_get_client(view->surface->resource) == client) { |
| 3168 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3169 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3170 | weston_pointer_set_focus(pointer, NULL, |
| 3171 | wl_fixed_from_int(0), |
| 3172 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3177 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3178 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3179 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3180 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3181 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3182 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3183 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3184 | if (pointer->focus) { |
| 3185 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3186 | &pointer->sx, &pointer->sy); |
| 3187 | } |
| 3188 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3189 | weston_pointer_move(pointer, x, y); |
| 3190 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3191 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3192 | weston_view_from_global_fixed(pointer->focus, |
| 3193 | pointer->x, pointer->y, |
| 3194 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3195 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3196 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3200 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3201 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3202 | { |
| 3203 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3204 | struct shell_seat *shseat = |
| 3205 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3206 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3207 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3208 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3209 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3210 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3211 | resource_list = &grab->pointer->focus_resource_list; |
| 3212 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3213 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3214 | wl_resource_for_each(resource, resource_list) { |
| 3215 | wl_pointer_send_button(resource, serial, |
| 3216 | time, button, state); |
| 3217 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3218 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3219 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3220 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3221 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3222 | } |
| 3223 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3224 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3225 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3226 | } |
| 3227 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3228 | static void |
| 3229 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3230 | { |
| 3231 | popup_grab_end(grab->pointer); |
| 3232 | } |
| 3233 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3234 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3235 | popup_grab_focus, |
| 3236 | popup_grab_motion, |
| 3237 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3238 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3239 | }; |
| 3240 | |
| 3241 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3242 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 3243 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3244 | { |
| 3245 | struct wl_resource *resource; |
| 3246 | struct shell_seat *shseat = |
| 3247 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3248 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3249 | uint32_t serial; |
| 3250 | struct wl_list *resource_list; |
| 3251 | |
| 3252 | resource_list = &grab->touch->focus_resource_list; |
| 3253 | if (!wl_list_empty(resource_list)) { |
| 3254 | serial = wl_display_get_serial(display); |
| 3255 | wl_resource_for_each(resource, resource_list) { |
| 3256 | wl_touch_send_down(resource, serial, time, |
| 3257 | grab->touch->focus->surface->resource, |
| 3258 | touch_id, sx, sy); |
| 3259 | } |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | static void |
| 3264 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3265 | { |
| 3266 | struct wl_resource *resource; |
| 3267 | struct shell_seat *shseat = |
| 3268 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3269 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3270 | uint32_t serial; |
| 3271 | struct wl_list *resource_list; |
| 3272 | |
| 3273 | resource_list = &grab->touch->focus_resource_list; |
| 3274 | if (!wl_list_empty(resource_list)) { |
| 3275 | serial = wl_display_get_serial(display); |
| 3276 | wl_resource_for_each(resource, resource_list) { |
| 3277 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3278 | } |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | static void |
| 3283 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 3284 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3285 | { |
| 3286 | struct wl_resource *resource; |
| 3287 | struct wl_list *resource_list; |
| 3288 | |
| 3289 | resource_list = &grab->touch->focus_resource_list; |
| 3290 | if (!wl_list_empty(resource_list)) { |
| 3291 | wl_resource_for_each(resource, resource_list) { |
| 3292 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3293 | } |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | static void |
| 3298 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3299 | { |
| 3300 | } |
| 3301 | |
| 3302 | static void |
| 3303 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3304 | { |
| 3305 | touch_popup_grab_end(grab->touch); |
| 3306 | } |
| 3307 | |
| 3308 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3309 | touch_popup_grab_down, |
| 3310 | touch_popup_grab_up, |
| 3311 | touch_popup_grab_motion, |
| 3312 | touch_popup_grab_frame, |
| 3313 | touch_popup_grab_cancel, |
| 3314 | }; |
| 3315 | |
| 3316 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3317 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3318 | { |
| 3319 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3320 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3321 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3322 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3326 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3327 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3328 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3329 | struct shell_seat *shseat = |
| 3330 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3331 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3332 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3333 | |
| 3334 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3335 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3336 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3337 | shseat->popup_grab.grab.interface = NULL; |
| 3338 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3339 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3340 | wl_list_for_each_safe(shsurf, next, |
| 3341 | &shseat->popup_grab.surfaces_list, |
| 3342 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3343 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3344 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3345 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3346 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3347 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3352 | touch_popup_grab_end(struct weston_touch *touch) |
| 3353 | { |
| 3354 | struct weston_touch_grab *grab = touch->grab; |
| 3355 | struct shell_seat *shseat = |
| 3356 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3357 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3358 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3359 | |
| 3360 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3361 | weston_touch_end_grab(grab->touch); |
| 3362 | shseat->popup_grab.client = NULL; |
| 3363 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3364 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3365 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3366 | wl_list_for_each_safe(shsurf, next, |
| 3367 | &shseat->popup_grab.surfaces_list, |
| 3368 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3369 | shell_surface_send_popup_done(shsurf); |
| 3370 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3371 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3372 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3373 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3374 | } |
| 3375 | } |
| 3376 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3377 | static struct shell_surface * |
| 3378 | get_top_popup(struct shell_seat *shseat) |
| 3379 | { |
| 3380 | struct shell_surface *shsurf; |
| 3381 | |
| 3382 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3383 | return NULL; |
| 3384 | } else { |
| 3385 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3386 | struct shell_surface, |
| 3387 | popup.grab_link); |
| 3388 | return shsurf; |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3393 | add_popup_grab(struct shell_surface *shsurf, |
| 3394 | struct shell_seat *shseat, |
| 3395 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3396 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3397 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3398 | struct shell_surface *parent, *top_surface; |
| 3399 | |
| 3400 | parent = get_shell_surface(shsurf->parent); |
| 3401 | top_surface = get_top_popup(shseat); |
| 3402 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3403 | (!parent || |
| 3404 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3405 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3406 | wl_resource_post_error(shsurf->owner_resource, |
| 3407 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3408 | "xdg_popup was not created on the " |
| 3409 | "topmost popup"); |
| 3410 | return -1; |
| 3411 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3412 | |
| 3413 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3414 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3415 | shseat->popup_grab.client = |
| 3416 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3417 | |
| 3418 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3419 | shseat->popup_grab.grab.interface = |
| 3420 | &popup_grab_interface; |
| 3421 | |
| 3422 | /* We must make sure here that this popup was opened |
| 3423 | * after a mouse press, and not just by moving around |
| 3424 | * with other popups already open. */ |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3425 | if (shseat->seat->pointer->button_count > 0) |
| 3426 | shseat->popup_grab.initial_up = 0; |
| 3427 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3428 | shseat->popup_grab.touch_grab.interface = |
| 3429 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3430 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3431 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3432 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3433 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3434 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3435 | if (type == POINTER) { |
| 3436 | weston_pointer_start_grab(seat->pointer, |
| 3437 | &shseat->popup_grab.grab); |
| 3438 | } else if (type == TOUCH) { |
| 3439 | weston_touch_start_grab(seat->touch, |
| 3440 | &shseat->popup_grab.touch_grab); |
| 3441 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3442 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3443 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3444 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3445 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3446 | |
| 3447 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | static void |
| 3451 | remove_popup_grab(struct shell_surface *shsurf) |
| 3452 | { |
| 3453 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3454 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3455 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3456 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3457 | wl_resource_post_error(shsurf->owner_resource, |
| 3458 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3459 | "xdg_popup was destroyed while it was " |
| 3460 | "not the topmost popup."); |
| 3461 | return; |
| 3462 | } |
| 3463 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3464 | wl_list_remove(&shsurf->popup.grab_link); |
| 3465 | wl_list_init(&shsurf->popup.grab_link); |
| 3466 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3467 | if (shseat->popup_grab.type == POINTER) { |
| 3468 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3469 | shseat->popup_grab.grab.interface = NULL; |
| 3470 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3471 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3472 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3473 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3474 | } |
| 3475 | } |
| 3476 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3477 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3478 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3479 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3480 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3481 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3482 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3483 | shsurf->surface->output = parent_view->output; |
| 3484 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3485 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3486 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3487 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3488 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3489 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3490 | if (shseat->seat->pointer && |
| 3491 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3492 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3493 | return -1; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3494 | } else if (shseat->seat->touch && |
| 3495 | shseat->seat->touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3496 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3497 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3498 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3499 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3500 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3501 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3502 | |
| 3503 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3504 | } |
| 3505 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3506 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3507 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3508 | shell_surface_move, |
| 3509 | shell_surface_resize, |
| 3510 | shell_surface_set_toplevel, |
| 3511 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3512 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3513 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3514 | shell_surface_set_maximized, |
| 3515 | shell_surface_set_title, |
| 3516 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3517 | }; |
| 3518 | |
| 3519 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3520 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3521 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3522 | struct shell_surface *child, *next; |
| 3523 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3524 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3525 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3526 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3527 | remove_popup_grab(shsurf); |
| 3528 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3529 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3530 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3531 | shell_surface_is_top_fullscreen(shsurf)) |
| 3532 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3534 | if (shsurf->fullscreen.black_view) |
| 3535 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3536 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3537 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3538 | * we can always remove the listener. |
| 3539 | */ |
| 3540 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3541 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3542 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3543 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3544 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3545 | weston_view_destroy(shsurf->view); |
| 3546 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3547 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3548 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3549 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3550 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3551 | wl_list_remove(&shsurf->link); |
| 3552 | free(shsurf); |
| 3553 | } |
| 3554 | |
| 3555 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3556 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3557 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3558 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3559 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3560 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3561 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3562 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3563 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3567 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3568 | { |
| 3569 | struct shell_surface *shsurf = container_of(listener, |
| 3570 | struct shell_surface, |
| 3571 | surface_destroy_listener); |
| 3572 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3573 | if (shsurf->resource) |
| 3574 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3575 | |
| 3576 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3577 | } |
| 3578 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3579 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame^] | 3580 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3581 | { |
| 3582 | struct shell_surface *shsurf = data; |
| 3583 | |
| 3584 | weston_surface_destroy(shsurf->surface); |
| 3585 | } |
| 3586 | |
| 3587 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame^] | 3588 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3589 | { |
| 3590 | struct shell_surface *shsurf = data; |
| 3591 | struct wl_event_loop *loop; |
| 3592 | |
| 3593 | loop = wl_display_get_event_loop( |
| 3594 | shsurf->surface->compositor->wl_display); |
| 3595 | |
| 3596 | if (!shsurf->destroying) { |
| 3597 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3598 | shsurf->destroying = true; |
| 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3603 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3604 | { |
| 3605 | struct shell_surface *shsurf = |
| 3606 | container_of(listener, struct shell_surface, |
| 3607 | resource_destroy_listener); |
| 3608 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3609 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3610 | return; |
| 3611 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3612 | shsurf->surface->ref_count++; |
| 3613 | |
| 3614 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3615 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3616 | pixman_region32_fini(&shsurf->surface->input); |
| 3617 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3618 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3619 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3620 | fade_out_done, shsurf); |
| 3621 | } else { |
| 3622 | weston_surface_destroy(shsurf->surface); |
| 3623 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3627 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3628 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3629 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3630 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3631 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3632 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3633 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3634 | else |
| 3635 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3636 | } |
| 3637 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3638 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3639 | create_common_surface(struct shell_client *owner, void *shell, |
| 3640 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3641 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3642 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3643 | struct shell_surface *shsurf; |
| 3644 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3645 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3646 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3647 | shsurf = calloc(1, sizeof *shsurf); |
| 3648 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3649 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3650 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3651 | } |
| 3652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3653 | shsurf->view = weston_view_create(surface); |
| 3654 | if (!shsurf->view) { |
| 3655 | weston_log("no memory to allocate shell surface\n"); |
| 3656 | free(shsurf); |
| 3657 | return NULL; |
| 3658 | } |
| 3659 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3660 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3661 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3662 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3663 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3664 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3665 | wl_resource_add_destroy_listener(surface->resource, |
| 3666 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3667 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3668 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3669 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3670 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3671 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3672 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3673 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3674 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3675 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3676 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3677 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3678 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3679 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3680 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3681 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3682 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3683 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3684 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3685 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3686 | |
| 3687 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3688 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3689 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3690 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3691 | /* empty when not in use */ |
| 3692 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3693 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3694 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3695 | wl_list_init(&shsurf->workspace_transform.link); |
| 3696 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3697 | wl_list_init(&shsurf->children_link); |
| 3698 | wl_list_init(&shsurf->children_list); |
| 3699 | shsurf->parent = NULL; |
| 3700 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3701 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3702 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3703 | shsurf->client = client; |
| 3704 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3705 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3706 | } |
| 3707 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3708 | static struct shell_surface * |
| 3709 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3710 | const struct weston_shell_client *client) |
| 3711 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3712 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3713 | } |
| 3714 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3715 | static struct weston_view * |
| 3716 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3717 | { |
| 3718 | return shsurf->view; |
| 3719 | } |
| 3720 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3721 | static void |
| 3722 | shell_get_shell_surface(struct wl_client *client, |
| 3723 | struct wl_resource *resource, |
| 3724 | uint32_t id, |
| 3725 | struct wl_resource *surface_resource) |
| 3726 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3727 | struct weston_surface *surface = |
| 3728 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3729 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3730 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3731 | struct shell_surface *shsurf; |
| 3732 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3733 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3734 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3735 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3736 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3737 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3738 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3739 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3740 | return; |
| 3741 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3742 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3743 | shsurf->resource = |
| 3744 | wl_resource_create(client, |
| 3745 | &wl_shell_surface_interface, 1, id); |
| 3746 | wl_resource_set_implementation(shsurf->resource, |
| 3747 | &shell_surface_implementation, |
| 3748 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3749 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3750 | } |
| 3751 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3752 | static bool |
| 3753 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3754 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3755 | /* A shell surface without a resource is created from xwayland |
| 3756 | * and is considered a wl_shell surface for now. */ |
| 3757 | |
| 3758 | return shsurf->resource == NULL || |
| 3759 | wl_resource_instance_of(shsurf->resource, |
| 3760 | &wl_shell_surface_interface, |
| 3761 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3762 | } |
| 3763 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3764 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3765 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3766 | }; |
| 3767 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3768 | /**************************** |
| 3769 | * xdg-shell implementation */ |
| 3770 | |
| 3771 | static void |
| 3772 | xdg_surface_destroy(struct wl_client *client, |
| 3773 | struct wl_resource *resource) |
| 3774 | { |
| 3775 | wl_resource_destroy(resource); |
| 3776 | } |
| 3777 | |
| 3778 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3779 | xdg_surface_set_parent(struct wl_client *client, |
| 3780 | struct wl_resource *resource, |
| 3781 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3782 | { |
| 3783 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3784 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3785 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3786 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3787 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3788 | shell_surface_set_parent(shsurf, parent->surface); |
| 3789 | } else { |
| 3790 | shell_surface_set_parent(shsurf, NULL); |
| 3791 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3795 | xdg_surface_set_app_id(struct wl_client *client, |
| 3796 | struct wl_resource *resource, |
| 3797 | const char *app_id) |
| 3798 | { |
| 3799 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3800 | |
| 3801 | free(shsurf->class); |
| 3802 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3803 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3807 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3808 | struct wl_resource *surface_resource, |
| 3809 | struct wl_resource *seat_resource, |
| 3810 | uint32_t serial, |
| 3811 | int32_t x, |
| 3812 | int32_t y) |
| 3813 | { |
| 3814 | /* TODO */ |
| 3815 | } |
| 3816 | |
| 3817 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3818 | xdg_surface_set_title(struct wl_client *client, |
| 3819 | struct wl_resource *resource, const char *title) |
| 3820 | { |
| 3821 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3822 | |
| 3823 | set_title(shsurf, title); |
| 3824 | } |
| 3825 | |
| 3826 | static void |
| 3827 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3828 | struct wl_resource *seat_resource, uint32_t serial) |
| 3829 | { |
| 3830 | common_surface_move(resource, seat_resource, serial); |
| 3831 | } |
| 3832 | |
| 3833 | static void |
| 3834 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3835 | struct wl_resource *seat_resource, uint32_t serial, |
| 3836 | uint32_t edges) |
| 3837 | { |
| 3838 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3839 | } |
| 3840 | |
| 3841 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3842 | xdg_surface_ack_configure(struct wl_client *client, |
| 3843 | struct wl_resource *resource, |
| 3844 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3845 | { |
| 3846 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3847 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3848 | if (shsurf->state_requested) { |
| 3849 | shsurf->next_state = shsurf->requested_state; |
| 3850 | shsurf->state_changed = true; |
| 3851 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3852 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3853 | } |
| 3854 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3855 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3856 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3857 | struct wl_resource *resource, |
| 3858 | int32_t x, |
| 3859 | int32_t y, |
| 3860 | int32_t width, |
| 3861 | int32_t height) |
| 3862 | { |
| 3863 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3864 | |
| 3865 | set_window_geometry(shsurf, x, y, width, height); |
| 3866 | } |
| 3867 | |
| 3868 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3869 | xdg_surface_set_maximized(struct wl_client *client, |
| 3870 | struct wl_resource *resource) |
| 3871 | { |
| 3872 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3873 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3874 | |
| 3875 | shsurf->state_requested = true; |
| 3876 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3877 | |
| 3878 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3879 | output = get_focused_output(shsurf->surface->compositor); |
| 3880 | else |
| 3881 | output = shsurf->surface->output; |
| 3882 | |
| 3883 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3884 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | static void |
| 3888 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3889 | struct wl_resource *resource) |
| 3890 | { |
| 3891 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3892 | |
| 3893 | shsurf->state_requested = true; |
| 3894 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3895 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | static void |
| 3899 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3900 | struct wl_resource *resource, |
| 3901 | struct wl_resource *output_resource) |
| 3902 | { |
| 3903 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3904 | struct weston_output *output; |
| 3905 | |
| 3906 | shsurf->state_requested = true; |
| 3907 | shsurf->requested_state.fullscreen = true; |
| 3908 | |
| 3909 | if (output_resource) |
| 3910 | output = wl_resource_get_user_data(output_resource); |
| 3911 | else |
| 3912 | output = NULL; |
| 3913 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3914 | /* handle clients launching in fullscreen */ |
| 3915 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3916 | /* Set the output to the one that has focus currently. */ |
| 3917 | assert(shsurf->surface); |
| 3918 | output = get_focused_output(shsurf->surface->compositor); |
| 3919 | } |
| 3920 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3921 | shell_surface_set_output(shsurf, output); |
| 3922 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3923 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3924 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | static void |
| 3928 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3929 | struct wl_resource *resource) |
| 3930 | { |
| 3931 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3932 | |
| 3933 | shsurf->state_requested = true; |
| 3934 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3935 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3939 | xdg_surface_set_minimized(struct wl_client *client, |
| 3940 | struct wl_resource *resource) |
| 3941 | { |
| 3942 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3943 | |
| 3944 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3945 | return; |
| 3946 | |
| 3947 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3948 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3949 | } |
| 3950 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3951 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3952 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3953 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3954 | xdg_surface_set_title, |
| 3955 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3956 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3957 | xdg_surface_move, |
| 3958 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3959 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3960 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3961 | xdg_surface_set_maximized, |
| 3962 | xdg_surface_unset_maximized, |
| 3963 | xdg_surface_set_fullscreen, |
| 3964 | xdg_surface_unset_fullscreen, |
| 3965 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3966 | }; |
| 3967 | |
| 3968 | static void |
| 3969 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3970 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3971 | { |
| 3972 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3973 | uint32_t *s; |
| 3974 | struct wl_array states; |
| 3975 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3976 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3977 | assert(shsurf); |
| 3978 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3979 | if (!shsurf->resource) |
| 3980 | return; |
| 3981 | |
| 3982 | wl_array_init(&states); |
| 3983 | if (shsurf->requested_state.fullscreen) { |
| 3984 | s = wl_array_add(&states, sizeof *s); |
| 3985 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3986 | } else if (shsurf->requested_state.maximized) { |
| 3987 | s = wl_array_add(&states, sizeof *s); |
| 3988 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3989 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3990 | if (shsurf->resize_edges != 0) { |
| 3991 | s = wl_array_add(&states, sizeof *s); |
| 3992 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3993 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3994 | if (shsurf->focus_count > 0) { |
| 3995 | s = wl_array_add(&states, sizeof *s); |
| 3996 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3997 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3998 | |
| 3999 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4000 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4001 | |
| 4002 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | static const struct weston_shell_client xdg_client = { |
| 4006 | xdg_send_configure |
| 4007 | }; |
| 4008 | |
| 4009 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4010 | xdg_shell_destroy(struct wl_client *client, |
| 4011 | struct wl_resource *resource) |
| 4012 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4013 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4014 | struct wl_resource *shsurf_resource; |
| 4015 | struct shell_surface *shsurf; |
| 4016 | |
| 4017 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4018 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4019 | if (shsurf->owner_resource == resource) { |
| 4020 | wl_resource_post_error( |
| 4021 | resource, |
| 4022 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4023 | "not all child surface objects destroyed"); |
| 4024 | return; |
| 4025 | } |
| 4026 | } |
| 4027 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4028 | wl_resource_destroy(resource); |
| 4029 | } |
| 4030 | |
| 4031 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | xdg_use_unstable_version(struct wl_client *client, |
| 4033 | struct wl_resource *resource, |
| 4034 | int32_t version) |
| 4035 | { |
| 4036 | if (version > 1) { |
| 4037 | wl_resource_post_error(resource, |
| 4038 | 1, |
| 4039 | "xdg-shell:: version not implemented yet."); |
| 4040 | return; |
| 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4045 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4046 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4047 | const struct weston_shell_client *client) |
| 4048 | { |
| 4049 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4050 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4051 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4052 | if (!shsurf) |
| 4053 | return NULL; |
| 4054 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4055 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4056 | |
| 4057 | return shsurf; |
| 4058 | } |
| 4059 | |
| 4060 | static void |
| 4061 | xdg_get_xdg_surface(struct wl_client *client, |
| 4062 | struct wl_resource *resource, |
| 4063 | uint32_t id, |
| 4064 | struct wl_resource *surface_resource) |
| 4065 | { |
| 4066 | struct weston_surface *surface = |
| 4067 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4068 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4069 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4070 | struct shell_surface *shsurf; |
| 4071 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4072 | shsurf = get_shell_surface(surface); |
| 4073 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4074 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4075 | "This wl_surface is already an " |
| 4076 | "xdg_surface"); |
| 4077 | return; |
| 4078 | } |
| 4079 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4080 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4081 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4082 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4083 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4084 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4085 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4086 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4087 | return; |
| 4088 | } |
| 4089 | |
| 4090 | shsurf->resource = |
| 4091 | wl_resource_create(client, |
| 4092 | &xdg_surface_interface, 1, id); |
| 4093 | wl_resource_set_implementation(shsurf->resource, |
| 4094 | &xdg_surface_implementation, |
| 4095 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4096 | shsurf->owner_resource = resource; |
| 4097 | wl_list_insert(&sc->surface_list, |
| 4098 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | static bool |
| 4102 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4103 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4104 | return shsurf->resource && |
| 4105 | wl_resource_instance_of(shsurf->resource, |
| 4106 | &xdg_surface_interface, |
| 4107 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | /* xdg-popup implementation */ |
| 4111 | |
| 4112 | static void |
| 4113 | xdg_popup_destroy(struct wl_client *client, |
| 4114 | struct wl_resource *resource) |
| 4115 | { |
| 4116 | wl_resource_destroy(resource); |
| 4117 | } |
| 4118 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4119 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4120 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4121 | }; |
| 4122 | |
| 4123 | static void |
| 4124 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4125 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4126 | { |
| 4127 | } |
| 4128 | |
| 4129 | static const struct weston_shell_client xdg_popup_client = { |
| 4130 | xdg_popup_send_configure |
| 4131 | }; |
| 4132 | |
| 4133 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4134 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4135 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4136 | const struct weston_shell_client *client, |
| 4137 | struct weston_surface *parent, |
| 4138 | struct shell_seat *seat, |
| 4139 | uint32_t serial, |
| 4140 | int32_t x, int32_t y) |
| 4141 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4142 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4143 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4144 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4145 | if (!shsurf) |
| 4146 | return NULL; |
| 4147 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4148 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4149 | shsurf->popup.shseat = seat; |
| 4150 | shsurf->popup.serial = serial; |
| 4151 | shsurf->popup.x = x; |
| 4152 | shsurf->popup.y = y; |
| 4153 | shell_surface_set_parent(shsurf, parent); |
| 4154 | |
| 4155 | return shsurf; |
| 4156 | } |
| 4157 | |
| 4158 | static void |
| 4159 | xdg_get_xdg_popup(struct wl_client *client, |
| 4160 | struct wl_resource *resource, |
| 4161 | uint32_t id, |
| 4162 | struct wl_resource *surface_resource, |
| 4163 | struct wl_resource *parent_resource, |
| 4164 | struct wl_resource *seat_resource, |
| 4165 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4166 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4167 | { |
| 4168 | struct weston_surface *surface = |
| 4169 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4170 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4171 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4172 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4173 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4174 | struct weston_surface *parent; |
| 4175 | struct shell_seat *seat; |
| 4176 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4177 | shsurf = get_shell_surface(surface); |
| 4178 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4179 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4180 | "This wl_surface is already an " |
| 4181 | "xdg_popup"); |
| 4182 | return; |
| 4183 | } |
| 4184 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4185 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4186 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4187 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4188 | |
| 4189 | if (!parent_resource) { |
| 4190 | wl_resource_post_error(surface_resource, |
| 4191 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4192 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4193 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | parent = wl_resource_get_user_data(parent_resource); |
| 4197 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4198 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4199 | /* Verify that we are creating the top most popup when mapping, |
| 4200 | * as it's not until then we know whether it was mapped as most |
| 4201 | * top level or not. */ |
| 4202 | |
| 4203 | parent_shsurf = get_shell_surface(parent); |
| 4204 | if (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4205 | !shell_surface_is_xdg_surface(parent_shsurf)) { |
| 4206 | wl_resource_post_error(resource, |
| 4207 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4208 | "xdg_popup parent was invalid"); |
| 4209 | return; |
| 4210 | } |
| 4211 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4212 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4213 | parent, seat, serial, x, y); |
| 4214 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4215 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4216 | return; |
| 4217 | } |
| 4218 | |
| 4219 | shsurf->resource = |
| 4220 | wl_resource_create(client, |
| 4221 | &xdg_popup_interface, 1, id); |
| 4222 | wl_resource_set_implementation(shsurf->resource, |
| 4223 | &xdg_popup_implementation, |
| 4224 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4225 | shsurf->owner_resource = resource; |
| 4226 | wl_list_insert(&sc->surface_list, |
| 4227 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4228 | } |
| 4229 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4230 | static void |
| 4231 | xdg_pong(struct wl_client *client, |
| 4232 | struct wl_resource *resource, uint32_t serial) |
| 4233 | { |
| 4234 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4235 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4236 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4237 | } |
| 4238 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4239 | static bool |
| 4240 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4241 | { |
| 4242 | return wl_resource_instance_of(shsurf->resource, |
| 4243 | &xdg_popup_interface, |
| 4244 | &xdg_popup_implementation); |
| 4245 | } |
| 4246 | |
| 4247 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4248 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4249 | xdg_use_unstable_version, |
| 4250 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4251 | xdg_get_xdg_popup, |
| 4252 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4253 | }; |
| 4254 | |
| 4255 | static int |
| 4256 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4257 | void *_target, uint32_t opcode, |
| 4258 | const struct wl_message *message, |
| 4259 | union wl_argument *args) |
| 4260 | { |
| 4261 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4262 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4263 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4264 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4265 | wl_resource_post_error(resource, |
| 4266 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4267 | "must call use_unstable_version first"); |
| 4268 | return 0; |
| 4269 | } |
| 4270 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4271 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4272 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4273 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4274 | "shell implementation doesn't match protocol version"); |
| 4275 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4276 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4277 | wl_resource_post_error(resource, |
| 4278 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4279 | "incompatible version, server is %d " |
| 4280 | "client wants %d", |
| 4281 | XDG_SERVER_VERSION, args[0].i); |
| 4282 | return 0; |
| 4283 | } |
| 4284 | |
| 4285 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4286 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4287 | |
| 4288 | return 1; |
| 4289 | } |
| 4290 | |
| 4291 | /* end of xdg-shell implementation */ |
| 4292 | /***********************************/ |
| 4293 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4294 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4295 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4296 | |
| 4297 | static int |
| 4298 | screensaver_timeout(void *data) |
| 4299 | { |
| 4300 | struct desktop_shell *shell = data; |
| 4301 | |
| 4302 | shell_fade(shell, FADE_OUT); |
| 4303 | |
| 4304 | return 1; |
| 4305 | } |
| 4306 | |
| 4307 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4308 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4309 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4310 | struct desktop_shell *shell = |
| 4311 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4312 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4313 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4314 | |
| 4315 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 4316 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4320 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4321 | { |
| 4322 | if (shell->screensaver.binding) |
| 4323 | return; |
| 4324 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4325 | if (!shell->screensaver.path) { |
| 4326 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4327 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4328 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4329 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4330 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4331 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4332 | return; |
| 4333 | } |
| 4334 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4335 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4336 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4337 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4338 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4342 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4343 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4344 | if (shell->screensaver.process.pid == 0) |
| 4345 | return; |
| 4346 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 4347 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 4348 | * compositor is not in the idle state. In that case, the screen will |
| 4349 | * be locked, but the wake_signal won't fire on user input, making the |
| 4350 | * system unresponsive. */ |
| 4351 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 4352 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4353 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4357 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4358 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4359 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4360 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4361 | wl_list_for_each_safe(v, next, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4362 | if (v->output == ev->output && v != ev) { |
| 4363 | weston_view_unmap(v); |
| 4364 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4365 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4369 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4370 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4371 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4372 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4373 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4374 | } |
| 4375 | } |
| 4376 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4377 | static int |
| 4378 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4379 | { |
| 4380 | return snprintf(buf, len, "background for output %s", |
| 4381 | surface->output->name); |
| 4382 | } |
| 4383 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4384 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4385 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4386 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4387 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4388 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4389 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4390 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4391 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4392 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4396 | desktop_shell_set_background(struct wl_client *client, |
| 4397 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4398 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4399 | struct wl_resource *surface_resource) |
| 4400 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4401 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4402 | struct weston_surface *surface = |
| 4403 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4405 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4406 | if (surface->configure) { |
| 4407 | wl_resource_post_error(surface_resource, |
| 4408 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4409 | "surface role already assigned"); |
| 4410 | return; |
| 4411 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4412 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4413 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4414 | weston_view_destroy(view); |
| 4415 | view = weston_view_create(surface); |
| 4416 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4417 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4418 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4419 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4420 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4421 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4422 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4423 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4424 | surface->output->width, |
| 4425 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4426 | } |
| 4427 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4428 | static int |
| 4429 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4430 | { |
| 4431 | return snprintf(buf, len, "panel for output %s", |
| 4432 | surface->output->name); |
| 4433 | } |
| 4434 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4435 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4436 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4437 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4438 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4439 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4440 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4441 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4442 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4443 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4447 | desktop_shell_set_panel(struct wl_client *client, |
| 4448 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4449 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4450 | struct wl_resource *surface_resource) |
| 4451 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4452 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4453 | struct weston_surface *surface = |
| 4454 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4455 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4456 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4457 | if (surface->configure) { |
| 4458 | wl_resource_post_error(surface_resource, |
| 4459 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4460 | "surface role already assigned"); |
| 4461 | return; |
| 4462 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4463 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4464 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4465 | weston_view_destroy(view); |
| 4466 | view = weston_view_create(surface); |
| 4467 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4468 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4469 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4470 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4471 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4472 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4473 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4474 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4475 | surface->output->width, |
| 4476 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4477 | } |
| 4478 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4479 | static int |
| 4480 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4481 | { |
| 4482 | return snprintf(buf, len, "lock window"); |
| 4483 | } |
| 4484 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4485 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4486 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4487 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4488 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4489 | struct weston_view *view; |
| 4490 | |
| 4491 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4492 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4493 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4494 | return; |
| 4495 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4496 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4497 | |
| 4498 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4499 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4500 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4501 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4502 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4507 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4508 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4509 | struct desktop_shell *shell = |
| 4510 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4511 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4512 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4513 | shell->lock_surface = NULL; |
| 4514 | } |
| 4515 | |
| 4516 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4517 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4518 | struct wl_resource *resource, |
| 4519 | struct wl_resource *surface_resource) |
| 4520 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4521 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4522 | struct weston_surface *surface = |
| 4523 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4524 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4525 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4526 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4527 | if (!shell->locked) |
| 4528 | return; |
| 4529 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4530 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4531 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4532 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4533 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4534 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4535 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4536 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4537 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4538 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4539 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4543 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4544 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4545 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4546 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4547 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4548 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4549 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4550 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4551 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4552 | &shell->input_panel_layer.link); |
| 4553 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4554 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4555 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4556 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4557 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4558 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4559 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4560 | &shell->panel_layer.link); |
| 4561 | wl_list_insert(&shell->panel_layer.link, |
| 4562 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4563 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4564 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4565 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4566 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4567 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4568 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | static void |
| 4572 | desktop_shell_unlock(struct wl_client *client, |
| 4573 | struct wl_resource *resource) |
| 4574 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4575 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4576 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4577 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4578 | |
| 4579 | if (shell->locked) |
| 4580 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4581 | } |
| 4582 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4583 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4584 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4585 | struct wl_resource *resource, |
| 4586 | struct wl_resource *surface_resource) |
| 4587 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4588 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4589 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4590 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4591 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4592 | } |
| 4593 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4594 | static void |
| 4595 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4596 | struct wl_resource *resource) |
| 4597 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4598 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4599 | |
| 4600 | shell_fade_startup(shell); |
| 4601 | } |
| 4602 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4603 | static void |
| 4604 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4605 | struct wl_resource *resource, |
| 4606 | uint32_t position) |
| 4607 | { |
| 4608 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4609 | |
| 4610 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4611 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4612 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4613 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4614 | wl_resource_post_error(resource, |
| 4615 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4616 | "bad position argument"); |
| 4617 | return; |
| 4618 | } |
| 4619 | |
| 4620 | shell->panel_position = position; |
| 4621 | } |
| 4622 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4623 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4624 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4625 | desktop_shell_set_panel, |
| 4626 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4627 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4628 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4629 | desktop_shell_desktop_ready, |
| 4630 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4631 | }; |
| 4632 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4633 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4634 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4635 | { |
| 4636 | struct shell_surface *shsurf; |
| 4637 | |
| 4638 | shsurf = get_shell_surface(surface); |
| 4639 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4640 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4641 | return shsurf->type; |
| 4642 | } |
| 4643 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4644 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4645 | move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4646 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4647 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4648 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4649 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4650 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4651 | if (seat->pointer->focus == NULL) |
| 4652 | return; |
| 4653 | |
| 4654 | focus = seat->pointer->focus->surface; |
| 4655 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4656 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4657 | if (surface == NULL) |
| 4658 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4659 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4660 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4661 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4662 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4663 | return; |
| 4664 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4665 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4669 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4670 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4671 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4672 | struct weston_surface *surface; |
| 4673 | struct shell_surface *shsurf; |
| 4674 | |
| 4675 | surface = weston_surface_get_main_surface(focus); |
| 4676 | if (surface == NULL) |
| 4677 | return; |
| 4678 | |
| 4679 | shsurf = get_shell_surface(surface); |
| 4680 | if (shsurf == NULL) |
| 4681 | return; |
| 4682 | |
| 4683 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4684 | return; |
| 4685 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4686 | shsurf->state_requested = true; |
| 4687 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4688 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | static void |
| 4692 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4693 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4694 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4695 | struct weston_surface *surface; |
| 4696 | struct shell_surface *shsurf; |
| 4697 | |
| 4698 | surface = weston_surface_get_main_surface(focus); |
| 4699 | if (surface == NULL) |
| 4700 | return; |
| 4701 | |
| 4702 | shsurf = get_shell_surface(surface); |
| 4703 | if (shsurf == NULL) |
| 4704 | return; |
| 4705 | |
| 4706 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4707 | return; |
| 4708 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4709 | shsurf->state_requested = true; |
| 4710 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4711 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4712 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4716 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4717 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4718 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4719 | struct weston_surface *surface; |
| 4720 | struct shell_surface *shsurf; |
| 4721 | |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4722 | if (seat->touch->focus == NULL) |
| 4723 | return; |
| 4724 | |
| 4725 | focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4726 | surface = weston_surface_get_main_surface(focus); |
| 4727 | if (surface == NULL) |
| 4728 | return; |
| 4729 | |
| 4730 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4731 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4732 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4733 | return; |
| 4734 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4735 | surface_touch_move(shsurf, seat); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4739 | resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4740 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4741 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4742 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4743 | uint32_t edges = 0; |
| 4744 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4745 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4746 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4747 | if (seat->pointer->focus == NULL) |
| 4748 | return; |
| 4749 | |
| 4750 | focus = seat->pointer->focus->surface; |
| 4751 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4752 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4753 | if (surface == NULL) |
| 4754 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4755 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4756 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4757 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4758 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4759 | return; |
| 4760 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4761 | weston_view_from_global(shsurf->view, |
| 4762 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4763 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4764 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4765 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4766 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4767 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4768 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4769 | edges |= 0; |
| 4770 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4771 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4772 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4773 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4774 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4775 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4776 | edges |= 0; |
| 4777 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4778 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4779 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4780 | surface_resize(shsurf, seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4784 | surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4785 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4786 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4787 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4788 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4789 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4790 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4791 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4792 | /* XXX: broken for windows containing sub-surfaces */ |
| 4793 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4794 | if (surface == NULL) |
| 4795 | return; |
| 4796 | |
| 4797 | shsurf = get_shell_surface(surface); |
| 4798 | if (!shsurf) |
| 4799 | return; |
| 4800 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4801 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4802 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4803 | if (shsurf->view->alpha > 1.0) |
| 4804 | shsurf->view->alpha = 1.0; |
| 4805 | if (shsurf->view->alpha < step) |
| 4806 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4807 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4808 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4809 | weston_surface_damage(surface); |
| 4810 | } |
| 4811 | |
| 4812 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4813 | do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4814 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4815 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4816 | struct weston_compositor *compositor = seat->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4817 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4818 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4819 | |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4820 | if (!seat->pointer) { |
| 4821 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4822 | return; |
| 4823 | } |
| 4824 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4825 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4826 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4827 | wl_fixed_to_double(seat->pointer->x), |
| 4828 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4829 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4830 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4831 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4832 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4833 | increment = -output->zoom.increment; |
| 4834 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4835 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4836 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4837 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4838 | else |
| 4839 | increment = 0; |
| 4840 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4841 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4842 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4843 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4844 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4845 | else if (output->zoom.level > output->zoom.max_level) |
| 4846 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4847 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4848 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4849 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4850 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4851 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4853 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | } |
| 4857 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4858 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4859 | zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4860 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4861 | { |
| 4862 | do_zoom(seat, time, 0, axis, value); |
| 4863 | } |
| 4864 | |
| 4865 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4866 | zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4867 | void *data) |
| 4868 | { |
| 4869 | do_zoom(seat, time, key, 0, 0); |
| 4870 | } |
| 4871 | |
| 4872 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4873 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4874 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4875 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4876 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4877 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4878 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4879 | } |
| 4880 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4881 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4882 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4883 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4884 | { |
| 4885 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4886 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4887 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4888 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4889 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4890 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4891 | weston_pointer_move(pointer, x, y); |
| 4892 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4893 | if (!shsurf) |
| 4894 | return; |
| 4895 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4896 | cx = 0.5f * shsurf->surface->width; |
| 4897 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4898 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4899 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4900 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4901 | r = sqrtf(dx * dx + dy * dy); |
| 4902 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4903 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4904 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4905 | |
| 4906 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4907 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4908 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4909 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4910 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4911 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4912 | |
| 4913 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4914 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4915 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4916 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4917 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4918 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4919 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4920 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4921 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4922 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4923 | wl_list_init(&shsurf->rotation.transform.link); |
| 4924 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4925 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4926 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4927 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4928 | /* We need to adjust the position of the surface |
| 4929 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4930 | cposx = shsurf->view->geometry.x + cx; |
| 4931 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4932 | dposx = rotate->center.x - cposx; |
| 4933 | dposy = rotate->center.y - cposy; |
| 4934 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4935 | weston_view_set_position(shsurf->view, |
| 4936 | shsurf->view->geometry.x + dposx, |
| 4937 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4938 | } |
| 4939 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4940 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4941 | * lazily applies the damage due to rotation update. |
| 4942 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4943 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4947 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4948 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4949 | { |
| 4950 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4951 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4952 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4953 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4954 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4955 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4956 | if (pointer->button_count == 0 && |
| 4957 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4958 | if (shsurf) |
| 4959 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4960 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4961 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4962 | free(rotate); |
| 4963 | } |
| 4964 | } |
| 4965 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4966 | static void |
| 4967 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4968 | { |
| 4969 | struct rotate_grab *rotate = |
| 4970 | container_of(grab, struct rotate_grab, base.grab); |
| 4971 | |
| 4972 | shell_grab_end(&rotate->base); |
| 4973 | free(rotate); |
| 4974 | } |
| 4975 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4976 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4977 | noop_grab_focus, |
| 4978 | rotate_grab_motion, |
| 4979 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4980 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4981 | }; |
| 4982 | |
| 4983 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4984 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4985 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4986 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4987 | float dx, dy; |
| 4988 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4989 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4990 | rotate = malloc(sizeof *rotate); |
| 4991 | if (!rotate) |
| 4992 | return; |
| 4993 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4994 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4995 | surface->surface->width * 0.5f, |
| 4996 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4997 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4998 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4999 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 5000 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5001 | r = sqrtf(dx * dx + dy * dy); |
| 5002 | if (r > 20.0f) { |
| 5003 | struct weston_matrix inverse; |
| 5004 | |
| 5005 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5006 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5007 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5008 | |
| 5009 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5010 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5011 | } else { |
| 5012 | weston_matrix_init(&surface->rotation.rotation); |
| 5013 | weston_matrix_init(&rotate->rotation); |
| 5014 | } |
| 5015 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5016 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 5017 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5021 | rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5022 | void *data) |
| 5023 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5024 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5025 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5026 | struct shell_surface *surface; |
| 5027 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5028 | if (seat->pointer->focus == NULL) |
| 5029 | return; |
| 5030 | |
| 5031 | focus = seat->pointer->focus->surface; |
| 5032 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5033 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5034 | if (base_surface == NULL) |
| 5035 | return; |
| 5036 | |
| 5037 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5038 | if (surface == NULL || surface->state.fullscreen || |
| 5039 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5040 | return; |
| 5041 | |
| 5042 | surface_rotate(surface, seat); |
| 5043 | } |
| 5044 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5045 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5046 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5047 | * and this is reversed when such a surface is re-configured, see |
| 5048 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5049 | * |
| 5050 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5051 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5052 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5053 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 5054 | { |
| 5055 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5056 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5057 | |
| 5058 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5059 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5060 | &shell->fullscreen_layer.view_list.link, |
| 5061 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5062 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5063 | |
| 5064 | if (!shsurf) |
| 5065 | continue; |
| 5066 | |
| 5067 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5068 | * in the fullscreen layer. */ |
| 5069 | if (shsurf->state.fullscreen) { |
| 5070 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5071 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5072 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5073 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5074 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5078 | weston_layer_entry_remove(&view->layer_link); |
| 5079 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5080 | weston_view_damage_below(view); |
| 5081 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5082 | |
| 5083 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5084 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5085 | } |
| 5086 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5087 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5088 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5089 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5090 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5091 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5092 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5093 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5094 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5095 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5096 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 5097 | lower_fullscreen_layer(shell); |
| 5098 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5099 | main_surface = weston_surface_get_main_surface(es); |
| 5100 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5101 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5102 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5103 | state = ensure_focus_state(shell, seat); |
| 5104 | if (state == NULL) |
| 5105 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5106 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5107 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5108 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5109 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5110 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5111 | assert(shsurf); |
| 5112 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5113 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5114 | shell_configure_fullscreen(shsurf); |
| 5115 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5116 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5117 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5118 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5119 | * order as appropriate. */ |
| 5120 | shell_surface_update_layer(shsurf); |
| 5121 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5122 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5123 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5124 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5125 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5126 | } |
| 5127 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5128 | /* no-op func for checking black surface */ |
| 5129 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5130 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5131 | { |
| 5132 | } |
| 5133 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5134 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5135 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5136 | { |
| 5137 | if (es->configure == black_surface_configure) { |
| 5138 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5139 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5140 | return true; |
| 5141 | } |
| 5142 | return false; |
| 5143 | } |
| 5144 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5145 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5146 | activate_binding(struct weston_seat *seat, |
| 5147 | struct desktop_shell *shell, |
| 5148 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5149 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5150 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5151 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5152 | if (!focus) |
| 5153 | return; |
| 5154 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5155 | if (is_black_surface(focus, &main_surface)) |
| 5156 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5157 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5158 | main_surface = weston_surface_get_main_surface(focus); |
| 5159 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5160 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5161 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5162 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | static void |
| 5166 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 5167 | void *data) |
| 5168 | { |
| 5169 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 5170 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5171 | if (seat->pointer->focus == NULL) |
| 5172 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5173 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 5174 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | static void |
| 5178 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 5179 | { |
| 5180 | if (seat->touch->grab != &seat->touch->default_grab) |
| 5181 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5182 | if (seat->touch->focus == NULL) |
| 5183 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5184 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 5185 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5189 | unfocus_all_seats(struct desktop_shell *shell) |
| 5190 | { |
| 5191 | struct weston_seat *seat, *next; |
| 5192 | |
| 5193 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 5194 | if (seat->keyboard == NULL) |
| 5195 | continue; |
| 5196 | |
| 5197 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5202 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5203 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5204 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5205 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5206 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5207 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5208 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5209 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5210 | |
| 5211 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5212 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5213 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5214 | * toplevel layers. This way nothing else can show or receive |
| 5215 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5216 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5217 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5218 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5219 | if (shell->showing_input_panels) |
| 5220 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5221 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5222 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5223 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5224 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5225 | launch_screensaver(shell); |
| 5226 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5227 | /* Remove the keyboard focus on all seats. This will be |
| 5228 | * restored to the workspace's saved state via |
| 5229 | * restore_focus_state when the compositor is unlocked */ |
| 5230 | unfocus_all_seats(shell); |
| 5231 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5232 | /* TODO: disable bindings that should not work while locked. */ |
| 5233 | |
| 5234 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5238 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5239 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5240 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5241 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5242 | return; |
| 5243 | } |
| 5244 | |
| 5245 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5246 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5247 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5248 | return; |
| 5249 | } |
| 5250 | |
| 5251 | if (shell->prepare_event_sent) |
| 5252 | return; |
| 5253 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5254 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5255 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5259 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5260 | { |
| 5261 | struct desktop_shell *shell = data; |
| 5262 | |
| 5263 | shell->fade.animation = NULL; |
| 5264 | |
| 5265 | switch (shell->fade.type) { |
| 5266 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5267 | weston_surface_destroy(shell->fade.view->surface); |
| 5268 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5269 | break; |
| 5270 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5271 | lock(shell); |
| 5272 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5273 | default: |
| 5274 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5275 | } |
| 5276 | } |
| 5277 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5278 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5279 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5280 | { |
| 5281 | struct weston_compositor *compositor = shell->compositor; |
| 5282 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5283 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5284 | |
| 5285 | surface = weston_surface_create(compositor); |
| 5286 | if (!surface) |
| 5287 | return NULL; |
| 5288 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5289 | view = weston_view_create(surface); |
| 5290 | if (!view) { |
| 5291 | weston_surface_destroy(surface); |
| 5292 | return NULL; |
| 5293 | } |
| 5294 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5295 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5296 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5297 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5298 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5299 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5300 | pixman_region32_init(&surface->input); |
| 5301 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5302 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | static void |
| 5306 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5307 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5308 | float tint; |
| 5309 | |
| 5310 | switch (type) { |
| 5311 | case FADE_IN: |
| 5312 | tint = 0.0; |
| 5313 | break; |
| 5314 | case FADE_OUT: |
| 5315 | tint = 1.0; |
| 5316 | break; |
| 5317 | default: |
| 5318 | weston_log("shell: invalid fade type\n"); |
| 5319 | return; |
| 5320 | } |
| 5321 | |
| 5322 | shell->fade.type = type; |
| 5323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5324 | if (shell->fade.view == NULL) { |
| 5325 | shell->fade.view = shell_fade_create_surface(shell); |
| 5326 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5327 | return; |
| 5328 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5329 | shell->fade.view->alpha = 1.0 - tint; |
| 5330 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5331 | } |
| 5332 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5333 | if (shell->fade.view->output == NULL) { |
| 5334 | /* If the black view gets a NULL output, we lost the |
| 5335 | * last output and we'll just cancel the fade. This |
| 5336 | * happens when you close the last window under the |
| 5337 | * X11 or Wayland backends. */ |
| 5338 | shell->locked = false; |
| 5339 | weston_surface_destroy(shell->fade.view->surface); |
| 5340 | shell->fade.view = NULL; |
| 5341 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5342 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5343 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5344 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5345 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5346 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5347 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5348 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5352 | do_shell_fade_startup(void *data) |
| 5353 | { |
| 5354 | struct desktop_shell *shell = data; |
| 5355 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5356 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 5357 | shell_fade(shell, FADE_IN); |
| 5358 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5359 | weston_surface_destroy(shell->fade.view->surface); |
| 5360 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5361 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | static void |
| 5365 | shell_fade_startup(struct desktop_shell *shell) |
| 5366 | { |
| 5367 | struct wl_event_loop *loop; |
| 5368 | |
| 5369 | if (!shell->fade.startup_timer) |
| 5370 | return; |
| 5371 | |
| 5372 | wl_event_source_remove(shell->fade.startup_timer); |
| 5373 | shell->fade.startup_timer = NULL; |
| 5374 | |
| 5375 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5376 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5377 | } |
| 5378 | |
| 5379 | static int |
| 5380 | fade_startup_timeout(void *data) |
| 5381 | { |
| 5382 | struct desktop_shell *shell = data; |
| 5383 | |
| 5384 | shell_fade_startup(shell); |
| 5385 | return 0; |
| 5386 | } |
| 5387 | |
| 5388 | static void |
| 5389 | shell_fade_init(struct desktop_shell *shell) |
| 5390 | { |
| 5391 | /* Make compositor output all black, and wait for the desktop-shell |
| 5392 | * client to signal it is ready, then fade in. The timer triggers a |
| 5393 | * fade-in, in case the desktop-shell client takes too long. |
| 5394 | */ |
| 5395 | |
| 5396 | struct wl_event_loop *loop; |
| 5397 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5398 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5399 | weston_log("%s: warning: fade surface already exists\n", |
| 5400 | __func__); |
| 5401 | return; |
| 5402 | } |
| 5403 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5404 | shell->fade.view = shell_fade_create_surface(shell); |
| 5405 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5406 | return; |
| 5407 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5408 | weston_view_update_transform(shell->fade.view); |
| 5409 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5410 | |
| 5411 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5412 | shell->fade.startup_timer = |
| 5413 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5414 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5415 | } |
| 5416 | |
| 5417 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5418 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5419 | { |
| 5420 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5421 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5422 | struct weston_seat *seat; |
| 5423 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5424 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5425 | if (seat->pointer) |
| 5426 | popup_grab_end(seat->pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5427 | if (seat->touch) |
| 5428 | touch_popup_grab_end(seat->touch); |
| 5429 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5430 | |
| 5431 | shell_fade(shell, FADE_OUT); |
| 5432 | /* lock() is called from shell_fade_done() */ |
| 5433 | } |
| 5434 | |
| 5435 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5436 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5437 | { |
| 5438 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5439 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5440 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5441 | unlock(shell); |
| 5442 | } |
| 5443 | |
| 5444 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5445 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5446 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5447 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5448 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5449 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5450 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5451 | |
| 5452 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5453 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5454 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5455 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5459 | weston_view_set_initial_position(struct weston_view *view, |
| 5460 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5461 | { |
| 5462 | struct weston_compositor *compositor = shell->compositor; |
| 5463 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5464 | int32_t range_x, range_y; |
| 5465 | int32_t dx, dy, x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5466 | struct weston_output *output, *target_output = NULL; |
| 5467 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5468 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5469 | |
| 5470 | /* As a heuristic place the new window on the same output as the |
| 5471 | * pointer. Falling back to the output containing 0, 0. |
| 5472 | * |
| 5473 | * TODO: Do something clever for touch too? |
| 5474 | */ |
| 5475 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5476 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5477 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5478 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5479 | break; |
| 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5484 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5485 | target_output = output; |
| 5486 | break; |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5491 | weston_view_set_position(view, 10 + random() % 400, |
| 5492 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5493 | return; |
| 5494 | } |
| 5495 | |
| 5496 | /* Valid range within output where the surface will still be onscreen. |
| 5497 | * If this is negative it means that the surface is bigger than |
| 5498 | * output. |
| 5499 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5500 | get_output_work_area(shell, target_output, &area); |
| 5501 | |
| 5502 | dx = area.x; |
| 5503 | dy = area.y; |
| 5504 | range_x = area.width - view->surface->width; |
| 5505 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5506 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5507 | if (range_x > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5508 | dx += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5509 | |
| 5510 | if (range_y > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5511 | dy += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5512 | |
| 5513 | x = target_output->x + dx; |
| 5514 | y = target_output->y + dy; |
| 5515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5516 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5520 | set_maximized_position(struct desktop_shell *shell, |
| 5521 | struct shell_surface *shsurf) |
| 5522 | { |
| 5523 | int32_t surf_x, surf_y; |
| 5524 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5525 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5526 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5527 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5528 | if (shsurf->has_set_geometry) { |
| 5529 | surf_x = shsurf->geometry.x; |
| 5530 | surf_y = shsurf->geometry.y; |
| 5531 | } else { |
| 5532 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5533 | &surf_x, &surf_y, NULL, NULL); |
| 5534 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5535 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5536 | |
| 5537 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5538 | e->x1 + area.x - surf_x, |
| 5539 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5543 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5544 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5545 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5546 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5547 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5548 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5549 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5550 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5551 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5552 | if (shsurf->state.fullscreen) { |
| 5553 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5554 | shell_map_fullscreen(shsurf); |
| 5555 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5556 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5557 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5558 | weston_view_set_initial_position(shsurf->view, shell); |
| 5559 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5560 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5561 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5562 | if (shell_map_popup(shsurf) != 0) |
| 5563 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5564 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5565 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5566 | weston_view_set_position(shsurf->view, |
| 5567 | shsurf->view->geometry.x + sx, |
| 5568 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5569 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5570 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5571 | default: |
| 5572 | ; |
| 5573 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5574 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5575 | /* Surface stacking order, see also activate(). */ |
| 5576 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5577 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5578 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5579 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5580 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5581 | shsurf->surface->output = shsurf->output; |
| 5582 | shsurf->view->output = shsurf->output; |
| 5583 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5584 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5585 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5586 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5587 | /* XXX: xwayland's using the same fields for transient type */ |
| 5588 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5589 | if (shsurf->transient.flags == |
| 5590 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5591 | break; |
| 5592 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5593 | if (shsurf->state.relative && |
| 5594 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5595 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5596 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5597 | break; |
| 5598 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5599 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5600 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5601 | case SHELL_SURFACE_POPUP: |
| 5602 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5603 | default: |
| 5604 | break; |
| 5605 | } |
| 5606 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5607 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5608 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5609 | { |
| 5610 | switch (shell->win_animation_type) { |
| 5611 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5612 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5613 | break; |
| 5614 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5615 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5616 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5617 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5618 | default: |
| 5619 | break; |
| 5620 | } |
| 5621 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5625 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5626 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5627 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5628 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5629 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5630 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5631 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5632 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5633 | assert(shsurf); |
| 5634 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5635 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5636 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5637 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5638 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5639 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5640 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5641 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5642 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5643 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5644 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5645 | wl_list_for_each(view, &surface->views, surface_link) |
| 5646 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5647 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5648 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5649 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5650 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5651 | } |
| 5652 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5653 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5654 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5655 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5656 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5657 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5658 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5659 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5660 | assert(shsurf); |
| 5661 | |
| 5662 | shell = shsurf->shell; |
| 5663 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5664 | if (!weston_surface_is_mapped(es) && |
| 5665 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5666 | remove_popup_grab(shsurf); |
| 5667 | } |
| 5668 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5669 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5670 | return; |
| 5671 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5672 | if (shsurf->has_next_geometry) { |
| 5673 | shsurf->geometry = shsurf->next_geometry; |
| 5674 | shsurf->has_next_geometry = false; |
| 5675 | shsurf->has_set_geometry = true; |
| 5676 | } else if (!shsurf->has_set_geometry) { |
| 5677 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5678 | &shsurf->geometry.x, |
| 5679 | &shsurf->geometry.y, |
| 5680 | &shsurf->geometry.width, |
| 5681 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5682 | } |
| 5683 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5684 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5685 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5686 | type_changed = 1; |
| 5687 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5688 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5689 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5690 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5691 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5692 | shsurf->last_width != es->width || |
| 5693 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5694 | float from_x, from_y; |
| 5695 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5696 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5697 | if (shsurf->resize_edges) { |
| 5698 | sx = 0; |
| 5699 | sy = 0; |
| 5700 | } |
| 5701 | |
| 5702 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5703 | sx = shsurf->last_width - es->width; |
| 5704 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5705 | sy = shsurf->last_height - es->height; |
| 5706 | |
| 5707 | shsurf->last_width = es->width; |
| 5708 | shsurf->last_height = es->height; |
| 5709 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5710 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5711 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5712 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5713 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5714 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5715 | } |
| 5716 | } |
| 5717 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5718 | static bool |
| 5719 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5720 | { |
| 5721 | struct timespec now; |
| 5722 | |
| 5723 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5724 | return false; |
| 5725 | |
| 5726 | /* |
| 5727 | * If the shell helper client dies before the session has been |
| 5728 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5729 | * because the user likely has no way to interact with the desktop |
| 5730 | * anyway. |
| 5731 | */ |
| 5732 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5733 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5734 | shell->client); |
| 5735 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5736 | wl_display_terminate(shell->compositor->wl_display); |
| 5737 | |
| 5738 | return true; |
| 5739 | } |
| 5740 | |
| 5741 | return false; |
| 5742 | } |
| 5743 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5744 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5745 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5746 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5747 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5748 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5749 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5750 | |
| 5751 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5752 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5753 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5754 | shell->child.deathstamp = time; |
| 5755 | shell->child.deathcount = 0; |
| 5756 | } |
| 5757 | |
| 5758 | shell->child.deathcount++; |
| 5759 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5760 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5761 | return; |
| 5762 | } |
| 5763 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5764 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5765 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5766 | } |
| 5767 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5768 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5769 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5770 | { |
| 5771 | struct desktop_shell *shell; |
| 5772 | |
| 5773 | shell = container_of(listener, struct desktop_shell, |
| 5774 | child.client_destroy_listener); |
| 5775 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5776 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5777 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5778 | /* |
| 5779 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5780 | * before the respawned process has a chance to create a new |
| 5781 | * desktop_shell object, because we are being called from the |
| 5782 | * wl_client destructor which destroys all wl_resources before |
| 5783 | * returning. |
| 5784 | */ |
| 5785 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5786 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5787 | respawn_desktop_shell_process(shell); |
| 5788 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5789 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5793 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5794 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5795 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5796 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5797 | shell->child.client = weston_client_start(shell->compositor, |
| 5798 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5799 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5800 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5801 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5802 | return; |
| 5803 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5804 | |
| 5805 | shell->child.client_destroy_listener.notify = |
| 5806 | desktop_shell_client_destroy; |
| 5807 | wl_client_add_destroy_listener(shell->child.client, |
| 5808 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5812 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5813 | { |
| 5814 | struct shell_client *sc = |
| 5815 | container_of(listener, struct shell_client, destroy_listener); |
| 5816 | |
| 5817 | if (sc->ping_timer) |
| 5818 | wl_event_source_remove(sc->ping_timer); |
| 5819 | free(sc); |
| 5820 | } |
| 5821 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5822 | static struct shell_client * |
| 5823 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5824 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5825 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5826 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5827 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5828 | sc = zalloc(sizeof *sc); |
| 5829 | if (sc == NULL) { |
| 5830 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5831 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5832 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5833 | |
| 5834 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5835 | if (sc->resource == NULL) { |
| 5836 | free(sc); |
| 5837 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5838 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | sc->client = client; |
| 5842 | sc->shell = shell; |
| 5843 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5844 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5845 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5846 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5847 | return sc; |
| 5848 | } |
| 5849 | |
| 5850 | static void |
| 5851 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5852 | { |
| 5853 | struct desktop_shell *shell = data; |
| 5854 | struct shell_client *sc; |
| 5855 | |
| 5856 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5857 | if (sc) |
| 5858 | wl_resource_set_implementation(sc->resource, |
| 5859 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5860 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | static void |
| 5864 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5865 | { |
| 5866 | struct desktop_shell *shell = data; |
| 5867 | struct shell_client *sc; |
| 5868 | |
| 5869 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5870 | if (sc) |
| 5871 | wl_resource_set_dispatcher(sc->resource, |
| 5872 | xdg_shell_unversioned_dispatch, |
| 5873 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5877 | unbind_desktop_shell(struct wl_resource *resource) |
| 5878 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5879 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5880 | |
| 5881 | if (shell->locked) |
| 5882 | resume_desktop(shell); |
| 5883 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5884 | shell->child.desktop_shell = NULL; |
| 5885 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5889 | bind_desktop_shell(struct wl_client *client, |
| 5890 | void *data, uint32_t version, uint32_t id) |
| 5891 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5892 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5893 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5894 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5895 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5896 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5897 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5898 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5899 | wl_resource_set_implementation(resource, |
| 5900 | &desktop_shell_implementation, |
| 5901 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5902 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5903 | |
| 5904 | if (version < 2) |
| 5905 | shell_fade_startup(shell); |
| 5906 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5907 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5908 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5909 | |
| 5910 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5911 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5912 | } |
| 5913 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 5914 | static int |
| 5915 | screensaver_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 5916 | { |
| 5917 | return snprintf(buf, len, "screensaver for output %s", |
| 5918 | surface->output->name); |
| 5919 | } |
| 5920 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5921 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5922 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5923 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5924 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5925 | struct weston_view *view; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5926 | struct weston_layer_entry *prev; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5927 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5928 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5929 | return; |
| 5930 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5931 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5932 | if (!shell->locked) |
| 5933 | return; |
| 5934 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5935 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5936 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5937 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5938 | if (wl_list_empty(&view->layer_link.link)) { |
| 5939 | prev = container_of(shell->lock_layer.view_list.link.prev, |
| 5940 | struct weston_layer_entry, link); |
| 5941 | weston_layer_entry_insert(prev, &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5942 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5943 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5944 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5945 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5950 | screensaver_set_surface(struct wl_client *client, |
| 5951 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5952 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5953 | struct wl_resource *output_resource) |
| 5954 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5955 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5956 | struct weston_surface *surface = |
| 5957 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5958 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5959 | struct weston_view *view, *next; |
| 5960 | |
| 5961 | /* Make sure we only have one view */ |
| 5962 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5963 | weston_view_destroy(view); |
| 5964 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5965 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5966 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5967 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 5968 | weston_surface_set_label_func(surface, screensaver_get_label); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5969 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | static const struct screensaver_interface screensaver_implementation = { |
| 5973 | screensaver_set_surface |
| 5974 | }; |
| 5975 | |
| 5976 | static void |
| 5977 | unbind_screensaver(struct wl_resource *resource) |
| 5978 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5979 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5980 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5981 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | static void |
| 5985 | bind_screensaver(struct wl_client *client, |
| 5986 | void *data, uint32_t version, uint32_t id) |
| 5987 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5988 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5989 | struct wl_resource *resource; |
| 5990 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5991 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5992 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5993 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5994 | wl_resource_set_implementation(resource, |
| 5995 | &screensaver_implementation, |
| 5996 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5997 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5998 | return; |
| 5999 | } |
| 6000 | |
| 6001 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 6002 | "interface object already bound"); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6003 | } |
| 6004 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6005 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6006 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6007 | struct weston_surface *current; |
| 6008 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6009 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6010 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6011 | }; |
| 6012 | |
| 6013 | static void |
| 6014 | switcher_next(struct switcher *switcher) |
| 6015 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6016 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6017 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6018 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6019 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6020 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6021 | /* temporary re-display minimized surfaces */ |
| 6022 | struct weston_view *tmp; |
| 6023 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6024 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 6025 | weston_layer_entry_remove(&view->layer_link); |
| 6026 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6027 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 6028 | *minimized = view; |
| 6029 | } |
| 6030 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6031 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 6032 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 6033 | if (shsurf && |
| 6034 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 6035 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6036 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6037 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6038 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6039 | next = view->surface; |
| 6040 | prev = view->surface; |
| 6041 | view->alpha = 0.25; |
| 6042 | weston_view_geometry_dirty(view); |
| 6043 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6044 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6045 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6046 | if (is_black_surface(view->surface, NULL)) { |
| 6047 | view->alpha = 0.25; |
| 6048 | weston_view_geometry_dirty(view); |
| 6049 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6050 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | if (next == NULL) |
| 6054 | next = first; |
| 6055 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6056 | if (next == NULL) |
| 6057 | return; |
| 6058 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6059 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6060 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6061 | |
| 6062 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6063 | wl_list_for_each(view, &next->views, surface_link) |
| 6064 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6065 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6066 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6067 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6068 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6072 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6073 | { |
| 6074 | struct switcher *switcher = |
| 6075 | container_of(listener, struct switcher, listener); |
| 6076 | |
| 6077 | switcher_next(switcher); |
| 6078 | } |
| 6079 | |
| 6080 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6081 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6082 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6083 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6084 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6085 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6086 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6087 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 6088 | if (is_focus_view(view)) |
| 6089 | continue; |
| 6090 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6091 | view->alpha = 1.0; |
| 6092 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6093 | } |
| 6094 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6095 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 6096 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6097 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6098 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6099 | weston_keyboard_end_grab(keyboard); |
| 6100 | if (keyboard->input_method_resource) |
| 6101 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6102 | |
| 6103 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6104 | struct weston_view **minimized; |
| 6105 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6106 | /* with the exception of the current selected */ |
| 6107 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6108 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6109 | weston_layer_entry_insert(&switcher->shell->minimized_layer.view_list, &(*minimized)->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6110 | weston_view_damage_below(*minimized); |
| 6111 | } |
| 6112 | } |
| 6113 | wl_array_release(&switcher->minimized_array); |
| 6114 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6115 | free(switcher); |
| 6116 | } |
| 6117 | |
| 6118 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6119 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6120 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6121 | { |
| 6122 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6123 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6124 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6125 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6126 | switcher_next(switcher); |
| 6127 | } |
| 6128 | |
| 6129 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6130 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6131 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6132 | uint32_t mods_locked, uint32_t group) |
| 6133 | { |
| 6134 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6135 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6136 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6137 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6138 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6139 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6140 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6141 | static void |
| 6142 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6143 | { |
| 6144 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6145 | |
| 6146 | switcher_destroy(switcher); |
| 6147 | } |
| 6148 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6149 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6150 | switcher_key, |
| 6151 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6152 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6153 | }; |
| 6154 | |
| 6155 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6156 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6157 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6158 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6159 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6160 | struct switcher *switcher; |
| 6161 | |
| 6162 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6163 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6164 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6165 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6166 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6167 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6168 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6169 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6170 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6171 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6172 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 6173 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6174 | switcher_next(switcher); |
| 6175 | } |
| 6176 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6177 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6178 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6179 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6180 | { |
| 6181 | struct weston_compositor *compositor = data; |
| 6182 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6183 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6184 | |
| 6185 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6186 | * control on the primary display. We'd have to extend later if we |
| 6187 | * ever get support for setting backlights on random desktop LCD |
| 6188 | * panels though */ |
| 6189 | output = get_default_output(compositor); |
| 6190 | if (!output) |
| 6191 | return; |
| 6192 | |
| 6193 | if (!output->set_backlight) |
| 6194 | return; |
| 6195 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6196 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6197 | backlight_new = output->backlight_current - 25; |
| 6198 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6199 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6200 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6201 | if (backlight_new < 5) |
| 6202 | backlight_new = 5; |
| 6203 | if (backlight_new > 255) |
| 6204 | backlight_new = 255; |
| 6205 | |
| 6206 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6207 | output->set_backlight(output, output->backlight_current); |
| 6208 | } |
| 6209 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6210 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6211 | force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6212 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6213 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6214 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6215 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6216 | struct desktop_shell *shell = data; |
| 6217 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6218 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6219 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6220 | focus_surface = seat->keyboard->focus; |
| 6221 | if (!focus_surface) |
| 6222 | return; |
| 6223 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6224 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6225 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6226 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6227 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6228 | |
| 6229 | /* Skip clients that we launched ourselves (the credentials of |
| 6230 | * the socketpair is ours) */ |
| 6231 | if (pid == getpid()) |
| 6232 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6233 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6234 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6238 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6239 | uint32_t key, void *data) |
| 6240 | { |
| 6241 | struct desktop_shell *shell = data; |
| 6242 | unsigned int new_index = shell->workspaces.current; |
| 6243 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6244 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6245 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6246 | if (new_index != 0) |
| 6247 | new_index--; |
| 6248 | |
| 6249 | change_workspace(shell, new_index); |
| 6250 | } |
| 6251 | |
| 6252 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6253 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6254 | uint32_t key, void *data) |
| 6255 | { |
| 6256 | struct desktop_shell *shell = data; |
| 6257 | unsigned int new_index = shell->workspaces.current; |
| 6258 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6259 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6260 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6261 | if (new_index < shell->workspaces.num - 1) |
| 6262 | new_index++; |
| 6263 | |
| 6264 | change_workspace(shell, new_index); |
| 6265 | } |
| 6266 | |
| 6267 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6268 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6269 | uint32_t key, void *data) |
| 6270 | { |
| 6271 | struct desktop_shell *shell = data; |
| 6272 | unsigned int new_index; |
| 6273 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6274 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6275 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6276 | new_index = key - KEY_F1; |
| 6277 | if (new_index >= shell->workspaces.num) |
| 6278 | new_index = shell->workspaces.num - 1; |
| 6279 | |
| 6280 | change_workspace(shell, new_index); |
| 6281 | } |
| 6282 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6283 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6284 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6285 | uint32_t key, void *data) |
| 6286 | { |
| 6287 | struct desktop_shell *shell = data; |
| 6288 | unsigned int new_index = shell->workspaces.current; |
| 6289 | |
| 6290 | if (shell->locked) |
| 6291 | return; |
| 6292 | |
| 6293 | if (new_index != 0) |
| 6294 | new_index--; |
| 6295 | |
| 6296 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6297 | } |
| 6298 | |
| 6299 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6300 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6301 | uint32_t key, void *data) |
| 6302 | { |
| 6303 | struct desktop_shell *shell = data; |
| 6304 | unsigned int new_index = shell->workspaces.current; |
| 6305 | |
| 6306 | if (shell->locked) |
| 6307 | return; |
| 6308 | |
| 6309 | if (new_index < shell->workspaces.num - 1) |
| 6310 | new_index++; |
| 6311 | |
| 6312 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6313 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6314 | |
| 6315 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6316 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6317 | { |
| 6318 | struct weston_output *output, *first_output; |
| 6319 | struct weston_compositor *ec = view->surface->compositor; |
| 6320 | struct shell_surface *shsurf; |
| 6321 | float x, y; |
| 6322 | int visible; |
| 6323 | |
| 6324 | x = view->geometry.x; |
| 6325 | y = view->geometry.y; |
| 6326 | |
| 6327 | /* At this point the destroyed output is not in the list anymore. |
| 6328 | * If the view is still visible somewhere, we leave where it is, |
| 6329 | * otherwise, move it to the first output. */ |
| 6330 | visible = 0; |
| 6331 | wl_list_for_each(output, &ec->output_list, link) { |
| 6332 | if (pixman_region32_contains_point(&output->region, |
| 6333 | x, y, NULL)) { |
| 6334 | visible = 1; |
| 6335 | break; |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | if (!visible) { |
| 6340 | first_output = container_of(ec->output_list.next, |
| 6341 | struct weston_output, link); |
| 6342 | |
| 6343 | x = first_output->x + first_output->width / 4; |
| 6344 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6345 | |
| 6346 | weston_view_set_position(view, x, y); |
| 6347 | } else { |
| 6348 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6349 | } |
| 6350 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6351 | |
| 6352 | shsurf = get_shell_surface(view->surface); |
| 6353 | |
| 6354 | if (shsurf) { |
| 6355 | shsurf->saved_position_valid = false; |
| 6356 | shsurf->next_state.maximized = false; |
| 6357 | shsurf->next_state.fullscreen = false; |
| 6358 | shsurf->state_changed = true; |
| 6359 | } |
| 6360 | } |
| 6361 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6362 | void |
| 6363 | shell_for_each_layer(struct desktop_shell *shell, |
| 6364 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6365 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6366 | struct workspace **ws; |
| 6367 | |
| 6368 | func(shell, &shell->fullscreen_layer, data); |
| 6369 | func(shell, &shell->panel_layer, data); |
| 6370 | func(shell, &shell->background_layer, data); |
| 6371 | func(shell, &shell->lock_layer, data); |
| 6372 | func(shell, &shell->input_panel_layer, data); |
| 6373 | |
| 6374 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6375 | func(shell, &(*ws)->layer, data); |
| 6376 | } |
| 6377 | |
| 6378 | static void |
| 6379 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6380 | struct weston_layer *layer, |
| 6381 | void *data) |
| 6382 | { |
| 6383 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6384 | struct weston_view *view; |
| 6385 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6386 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6387 | if (view->output != output) |
| 6388 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6389 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6390 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6395 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6396 | { |
| 6397 | struct shell_output *output_listener = |
| 6398 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6399 | struct weston_output *output = output_listener->output; |
| 6400 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6401 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6402 | shell_for_each_layer(shell, shell_output_destroy_move_layer, output); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6403 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6404 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6405 | wl_list_remove(&output_listener->link); |
| 6406 | free(output_listener); |
| 6407 | } |
| 6408 | |
| 6409 | static void |
| 6410 | create_shell_output(struct desktop_shell *shell, |
| 6411 | struct weston_output *output) |
| 6412 | { |
| 6413 | struct shell_output *shell_output; |
| 6414 | |
| 6415 | shell_output = zalloc(sizeof *shell_output); |
| 6416 | if (shell_output == NULL) |
| 6417 | return; |
| 6418 | |
| 6419 | shell_output->output = output; |
| 6420 | shell_output->shell = shell; |
| 6421 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6422 | wl_signal_add(&output->destroy_signal, |
| 6423 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6424 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6425 | } |
| 6426 | |
| 6427 | static void |
| 6428 | handle_output_create(struct wl_listener *listener, void *data) |
| 6429 | { |
| 6430 | struct desktop_shell *shell = |
| 6431 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6432 | struct weston_output *output = (struct weston_output *)data; |
| 6433 | |
| 6434 | create_shell_output(shell, output); |
| 6435 | } |
| 6436 | |
| 6437 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6438 | handle_output_move_layer(struct desktop_shell *shell, |
| 6439 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6440 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6441 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6442 | struct weston_view *view; |
| 6443 | float x, y; |
| 6444 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6445 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6446 | if (view->output != output) |
| 6447 | continue; |
| 6448 | |
| 6449 | x = view->geometry.x + output->move_x; |
| 6450 | y = view->geometry.y + output->move_y; |
| 6451 | weston_view_set_position(view, x, y); |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | static void |
| 6456 | handle_output_move(struct wl_listener *listener, void *data) |
| 6457 | { |
| 6458 | struct desktop_shell *shell; |
| 6459 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6460 | shell = container_of(listener, struct desktop_shell, |
| 6461 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6462 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6463 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6467 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6468 | struct desktop_shell *shell) |
| 6469 | { |
| 6470 | struct weston_output *output; |
| 6471 | |
| 6472 | wl_list_init(&shell->output_list); |
| 6473 | wl_list_for_each(output, &ec->output_list, link) |
| 6474 | create_shell_output(shell, output); |
| 6475 | |
| 6476 | shell->output_create_listener.notify = handle_output_create; |
| 6477 | wl_signal_add(&ec->output_created_signal, |
| 6478 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6479 | |
| 6480 | shell->output_move_listener.notify = handle_output_move; |
| 6481 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6485 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6486 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6487 | struct desktop_shell *shell = |
| 6488 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6489 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6490 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6491 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6492 | /* Force state to unlocked so we don't try to fade */ |
| 6493 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6494 | |
| 6495 | if (shell->child.client) { |
| 6496 | /* disable respawn */ |
| 6497 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6498 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6499 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6500 | |
Ryo Munakata | 76fb7ec | 2015-03-08 19:17:06 +0900 | [diff] [blame] | 6501 | wl_event_source_remove(shell->screensaver.timer); |
| 6502 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6503 | wl_list_remove(&shell->idle_listener.link); |
| 6504 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6505 | |
| 6506 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6507 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6508 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6509 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6510 | wl_list_remove(&shell_output->link); |
| 6511 | free(shell_output); |
| 6512 | } |
| 6513 | |
| 6514 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6515 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6516 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6517 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6518 | workspace_destroy(*ws); |
| 6519 | wl_array_release(&shell->workspaces.array); |
| 6520 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6521 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6522 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6523 | free(shell); |
| 6524 | } |
| 6525 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6526 | static void |
| 6527 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6528 | { |
| 6529 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6530 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6531 | |
| 6532 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6533 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6534 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6535 | terminate_binding, ec); |
| 6536 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6537 | click_to_activate_binding, |
| 6538 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6539 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6540 | click_to_activate_binding, |
| 6541 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6542 | weston_compositor_add_touch_binding(ec, 0, |
| 6543 | touch_to_activate_binding, |
| 6544 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6545 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6546 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6547 | surface_opacity_binding, NULL); |
| 6548 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6549 | MODIFIER_SUPER, zoom_axis_binding, |
| 6550 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6551 | |
| 6552 | /* configurable bindings */ |
| 6553 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6554 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6555 | zoom_key_binding, NULL); |
| 6556 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6557 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6558 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6559 | maximize_binding, NULL); |
| 6560 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6561 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6562 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6563 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6564 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6565 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6566 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6567 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6568 | mod | MODIFIER_SHIFT, |
| 6569 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6570 | |
| 6571 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6572 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6573 | rotate_binding, NULL); |
| 6574 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6575 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6576 | shell); |
| 6577 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6578 | ec); |
| 6579 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6580 | backlight_binding, ec); |
| 6581 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6582 | ec); |
| 6583 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6584 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6585 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6586 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6587 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6588 | workspace_up_binding, shell); |
| 6589 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6590 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6591 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6592 | workspace_move_surface_up_binding, |
| 6593 | shell); |
| 6594 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6595 | workspace_move_surface_down_binding, |
| 6596 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6597 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6598 | if (shell->exposay_modifier) |
| 6599 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6600 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6601 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6602 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6603 | if (shell->workspaces.num > 1) { |
| 6604 | num_workspace_bindings = shell->workspaces.num; |
| 6605 | if (num_workspace_bindings > 6) |
| 6606 | num_workspace_bindings = 6; |
| 6607 | for (i = 0; i < num_workspace_bindings; i++) |
| 6608 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6609 | workspace_f_binding, |
| 6610 | shell); |
| 6611 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6612 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6613 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6614 | } |
| 6615 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6616 | static void |
| 6617 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6618 | { |
| 6619 | struct weston_seat *seat = data; |
| 6620 | |
| 6621 | create_shell_seat(seat); |
| 6622 | } |
| 6623 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6624 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6625 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6626 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6627 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6628 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6629 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6630 | struct workspace **pws; |
| 6631 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6632 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6633 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6634 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6635 | if (shell == NULL) |
| 6636 | return -1; |
| 6637 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6638 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6639 | |
| 6640 | shell->destroy_listener.notify = shell_destroy; |
| 6641 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6642 | shell->idle_listener.notify = idle_handler; |
| 6643 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6644 | shell->wake_listener.notify = wake_handler; |
| 6645 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6646 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6647 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6648 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6649 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6650 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6651 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6652 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6653 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6654 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6655 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6656 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6657 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6658 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6659 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6660 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6661 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6662 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6663 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6664 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6665 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6666 | |
| 6667 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6668 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6669 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6670 | if (input_panel_setup(shell) < 0) |
| 6671 | return -1; |
| 6672 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6673 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6674 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6675 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6676 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6677 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6678 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6679 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6680 | if (pws == NULL) |
| 6681 | return -1; |
| 6682 | |
| 6683 | *pws = workspace_create(); |
| 6684 | if (*pws == NULL) |
| 6685 | return -1; |
| 6686 | } |
| 6687 | activate_workspace(shell, 0); |
| 6688 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6689 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6690 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6691 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6692 | wl_list_init(&shell->workspaces.animation.link); |
| 6693 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6694 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6695 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6696 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6697 | return -1; |
| 6698 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6699 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6700 | shell, bind_xdg_shell) == NULL) |
| 6701 | return -1; |
| 6702 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6703 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6704 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6705 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6706 | return -1; |
| 6707 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6708 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6709 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6710 | return -1; |
| 6711 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6712 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6713 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6714 | return -1; |
| 6715 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6716 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6717 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6718 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6719 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6720 | setup_output_destroy_handler(ec, shell); |
| 6721 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6722 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6723 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6724 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6725 | shell->screensaver.timer = |
| 6726 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6727 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6728 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6729 | handle_seat_created(NULL, seat); |
| 6730 | shell->seat_create_listener.notify = handle_seat_created; |
| 6731 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6732 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6733 | screenshooter_create(ec); |
| 6734 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6735 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6736 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6737 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6738 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6739 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6740 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6741 | return 0; |
| 6742 | } |